[R] Within-Subjects ANOVA & comparisons of individual means

Steffen Katzner steffen.katzner at mail.gwdg.de
Fri Jan 20 09:04:22 CET 2006


I am having problems with comparing individual means in a
within-subjects ANOVA. From my understanding, TukeyHSD is not
appropriate in this context. So I am trying to compute contrasts, as
follows:

seven subjects participated in each of 6 conditions (intervals).

> subject = factor(rep(c(1:7), each = 6))
> interval = factor(rep(c(1:6), 7))

and here is the dependent variable:

> dv = c(3.3868, 3.1068, 1.7261, 1.5415, 1.7356, 0.7538,
+ 2.5957, 1.5666, 1.1984, 1.2761, 1.0022, 0.8597,
+ 3.9819, 3.1506, 1.5824, 1.7400, 1.4248, 0.6519,
+ 2.2521, 1.5248, 1.1209, 1.2193, 1.1994, 2.0910,
+ 2.4661, 1.3863, 1.3591, 0.9163, 1.3976, 1.7471,
+ 3.2486, 1.9492, 2.4228, 1.1276, 1.2836, 0.9814,
+ 1.7148, 1.7278, 2.7433, 1.4924, 1.0992, 0.7821)

> d = data.frame(subject, interval, dv)

next I'm defining a contrast matrix:

> con = matrix(c(1, -1, 0, 0, 0, 0, 0, 1, -1, 0, 0, 0, 0, 0, 1, -1, 0, 
0, 0, 0, 0, 1, -1, 0, 0, 0, 0, 0, 1, -1), nrow=6, ncol=5, byrow=F)

> con
     [,1] [,2] [,3] [,4] [,5]
[1,]    1    0    0    0    0
[2,]   -1    1    0    0    0
[3,]    0   -1    1    0    0
[4,]    0    0   -1    1    0
[5,]    0    0    0   -1    1
[6,]    0    0    0    0   -1


> contrasts(d$interval)=con

and then I'm doing the ANOVA

> aovRes = aov(dv~interval+Error(subject/interval), data=d)

> summary(aovRes)

Error: subject
           Df  Sum Sq Mean Sq F value Pr(>F)
Residuals  6 2.48531 0.41422

Error: subject:interval
           Df  Sum Sq Mean Sq F value    Pr(>F)
interval   5 13.8174  2.7635  8.7178 3.417e-05 ***
Residuals 30  9.5098  0.3170
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1



but if I want to look at the contrasts, something has gone wrong:


summary.aov(aovRes, split=list(interval = list("i1 vs i2" = 1, "i2 vs
i3" = 2, "i3 vs i4" = 3, "i4 vs i5" = 4, "i5 vs i6" = 5)))

Error in 1:object$rank : NA/NaN argument

> aovRes$contrasts
NULL

Can anybody help?
Thank you very much,  -Steffen




More information about the R-help mailing list