[R] Contrast SS

Gabor Grothendieck ggrothendieck at gmail.com
Fri Nov 28 17:47:30 CET 2008


Is your objective to break down the sum of squares for x into one
for the group 1 vs group 3 contrast and another for the
group 2 vs group 3 contrast?

If that's it try this.  We create the model matrix, make the two columns
generated from x into separate explanatory variables, x1 and x2, and
then run the anova.

> m <- model.matrix(~ C(x, contr.treatment, base = 3))
> DF <- data.frame(y, x1 = m[,2], x2 = m[,3])
> anova(lm(y ~., DF))
Analysis of Variance Table

Response: y
          Df  Sum Sq Mean Sq F value Pr(>F)
x1         1  2.3389  2.3389  2.5072 0.1393
x2         1  0.1170  0.1170  0.1254 0.7294
Residuals 12 11.1947  0.9329

On Fri, Nov 28, 2008 at 11:24 AM, Ista Zahn <izahn at psych.rochester.edu> wrote:
> Hi all,
> Hopefully this is an easy question and I've overlooked something
> simple. I want to present specific contrasts in an ANOVA table. I can
> of course get the significance tests with summary.lm, but my adviser
> wants the results in ANOVA format. Here is a minimal example:
>
>> x <- factor(c(rep("condition.1", 5), rep("condition.2", 5), rep("condition.3", 5)))
>> y <- rnorm(15)
>
> I know there are all kinds of built-in contrasts, but I specifically
> want to contrast groups 1 and two with group 3, and  I'm more
> comfortable setting them by hand:
>
>> contrasts(x) <- matrix(c(-1,-1,2, -1,1,0), 3,2)
>> m.1 <- lm(y ~ x)
>
> I can test the contrasts with
>
>> summary(m.1)
>
> but the results are not formatted in an ANOVA table. I can format the
> results in an ANOVA table
>
>> anova(m.1)
>
> but this doesn't give me results for the contrast.
>
> Any help is greatly appreciated.
>
> -Ista
>
> ______________________________________________
> R-help at 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.
>



More information about the R-help mailing list