Shaun Jackman
2013-Jun-26 00:07 UTC
[R] Comparing each level of a factor to the global mean
Hi, 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? ```r model <- lm(weight ~ Diet, ChickWeight) summary(model) ``` Thanks, Shaun
Shaun, See the help on contrasts ... ?contr.treatment Jean On Tue, Jun 25, 2013 at 7:07 PM, Shaun Jackman <sjackman@gmail.com> wrote:> Hi, > > 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? > > ```r > model <- lm(weight ~ Diet, ChickWeight) > summary(model) > ``` > > Thanks, > Shaun > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]