[R] planned comparisons for ANOVA

Darren Weber darrenleeweber at gmail.com
Mon Jul 17 19:46:00 CEST 2006


On 7/16/06, Simon Blomberg <blomsp at ozemail.com.au> wrote:
> Darren Weber wrote:
>
> [snip]
> > Our planned comparisons are:
> >
> > 1. test the group mean difference for S1 vs S2 (in the absence of S3)
> > 2. test the group mean difference for S2 vs S3 (in the absence of S1)
> >
> > This is the current form of the ANOVA specification for R:
> >
> > aov( Y ~ (Task*Hemisphere*Group) +
> >                 Error( Subject/(Task*Hemisphere) )
> >
> > How can we add planned comparisons to this specification?  Can we add
> > just one planned comparison matrix, with rows for 1 & 2 above, or do
> > we need to run the model twice, once for each planned comparison?
> >
> There are a couple of ways to do this in R. Perhaps the easiest is to
> use make.contrasts in the gmodels package.
>
> cmat <- rbind("S1 v S2" = c(1, -1, 0),
>                       "S2 v S3" = c(0, 1, -1))
> library(gmodels)
> fit <- aov( Y ~ Task*Hemisphere*Group + Error(
> Subject/(Task*Hemisphere), contrasts=list("Task"=make.contrasts(cmat )))
> summary(fit)
>
> > Alternatively, is there a function  to compute the planned comparisons
> > after running the full ANOVA model?
> >
> see ?fit.contrast in gmodels  for this.
>
> HTH,
>
> Simon.

Thanks, Simon.

In the summary(fit) display, it is difficult to identify the contrast
outputs.  There appears to be just one set of ANOVA results, eg:


Error: Subject
          Df  Sum Sq Mean Sq F value Pr(>F)
Group      1    7.04    7.04  0.1262 0.7265
Residuals 18 1004.00   55.78

Error: Subject:Cond
           Df Sum Sq Mean Sq F value    Pr(>F)
Cond        2 416.11  208.06 22.3016 5.001e-07 ***
Cond:Group  2  25.02   12.51  1.3409    0.2744
Residuals  36 335.85    9.33
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Error: Subject:Hemisphere
                 Df Sum Sq Mean Sq F value Pr(>F)
Hemisphere        1  3.666   3.666  1.6901 0.2100
Hemisphere:Group  1  1.804   1.804  0.8315 0.3739
Residuals        18 39.043   2.169

Error: Subject:Cond:Hemisphere
                      Df Sum Sq Mean Sq F value Pr(>F)
Cond:Hemisphere        2  6.328   3.164  2.0160 0.1480
Cond:Hemisphere:Group  2  0.786   0.393  0.2506 0.7797
Residuals             36 56.501   1.569


For some reason I expected to see two separate tests of the Task
"Cond"ition effect, one for the comparison of "S1 vs S2" and another
for the comparison of "S2 vs S3".  I seem to have missed something.

Also, I wanted to start with an easy example of using planned
comparisons with our experimental design.  In fact, our planned
comparisons involve the interaction of the group and task conditions.
How do we specify the planned comparisons for an interaction effect?
For example, we expect the task conditions to generate different brain
activity in controls and patients.  In our first planned comparison,
we actually expect "S2 > S1" for controls, but not for patients (they
have "S1 = S2").  What is the contrast matrix for this kind of
interaction effect and how do we specify it in the aov function?  Is
there some reading, with examples using R, on this topic?

Take care, Darren



More information about the R-help mailing list