[R] Comparing each level of a factor to the global mean
sjackman at gmail.com
Fri Jun 28 00:47:25 CEST 2013
contr.treatment(4) shows what the default contrast matrix looks like
for a factor with 4 levels. What function do I use to create a
contrast matrix to compare each level with the global mean (four
comparisons in total), and produce a table similar to `summary.lm`?
On 26 June 2013 05:50, Adams, Jean <jvadams at usgs.gov> wrote:
> See the help on contrasts ...
> On Tue, Jun 25, 2013 at 7:07 PM, Shaun Jackman <sjackman at gmail.com> wrote:
>> I've used `lm` to create a linear model of a continuous variable
>> against a factor variable with four levels using an example R data set
>> (see below). By default, it uses a treatment contrast matrix that
>> compares each level of the factor variable with the first reference
>> level (three comparisons in total). I'd like to compare each level
>> with the global mean (four comparisons in total), and produce a table
>> similar to `summary.lm`. How do I go about this?
>> model <- lm(weight ~ Diet, ChickWeight)
>> R-help at r-project.org mailing list
>> PLEASE do read the posting guide
>> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help