I am trying to run a repeated measures Anova in R followed by some specific
contrasts on that dataset. I think the correct approach would be to use
Anova()
from the car package.
Lets illustrate my question with the example taken from ?Anova
using the
OBrienKaiser
data (Note: I ommited the gender factor from the example):
We have a design with one between subjects factor, treatment (3 levels: control,
A, B), and 2 repeated-measures (within subjects) factors,
phase (3 levels: pretest, posttest, followup) and hour (5 levels: 1 to 5).
The standard ANOVA table is given by (in difference to example(Anova) I switched to Type 3 Sums of Squares, that is what my field wants):
require(car)
phase <- factor(rep(c("pretest", "posttest", "followup"), c(5, 5, 5)),
levels=c("pretest", "posttest", "followup"))
hour <- ordered(rep(1:5, 3))
idata <- data.frame(phase, hour)
mod.ok <- lm(cbind(pre.1, pre.2, pre.3, pre.4, pre.5, post.1, post.2, post.3, post.4, post.5, fup.1, fup.2, fup.3, fup.4, fup.5) ~ treatment, data=OBrienKaiser)
av.ok <- Anova(mod.ok, idata=idata, idesign=~phase*hour, type = 3)
summary(av.ok, multivariate=FALSE)
Now, imagine that the highest order interaction would have been significant
(which is not the case) and we would like to explore it further with the
following contrasts:
Is there a difference between hours 1&2 versus hours 3 (contrast 1) and between
hours 1&2 versus hours 4&5 (contrast 2) in the treatment conditions (A&B
together)?
In other words, how do I specify these contrasts:
((treatment %in% c("A", "B")) & (hour %in% 1:2))
versus((treatment %in% c("A", "B")) & (hour %in% 3))
((treatment %in% c("A", "B")) & (hour %in% 1:2))
versus((treatment %in% c("A", "B")) & (hour %in% 4:5))
My idea would be to run another ANOVA ommitting the non-needed treatment condition (control):
mod2 <- lm(cbind(pre.1, pre.2, pre.3, pre.4, pre.5, post.1, post.2, post.3, post.4, post.5, fup.1, fup.2, fup.3, fup.4, fup.5) ~ treatment, data=OBrienKaiser, subset = treatment != "control")
av2 <- Anova(mod2, idata=idata, idesign=~phase*hour, type = 3)
summary(av2, multivariate=FALSE)
However, I still have no idea how to set up the appropriate within-subject contrast matrix comparing hours 1&2 with 3 and 1&2 with 4&5. And I am not sure if omitting the non-needed treatment group is indeed a good idea as it changes the overall error term.
Before going for Anova()
I was also thinking going for lme
. However, there are
small differences in F and p values between textbook ANOVA and what is returned
from anove(lme)
due to possible negative variances in standard ANOVA (which are not allowed in lme
). Relatedly, somebody pointed me to gls
which allows for fitting repeated measures ANOVA, however, it has no contrast argument.
To clarify: I want an F or t test (using type III sums of squares) that answers whether or not the desired contrasts are significant or not.
Update:
I already asked a very similar question on R-help, there was no answer.
A similar questions was posed on R-help some time ago. However, the answers did also not solve the problem.
Update (2015):
As this question still generates some activity, specifying theses and basically all other contrasts can now be done relatively easy with the afex
package in combination with the lsmeans
package as described in the afex vignette.
treatment
, 3) for each person average over levels ofprePostFup
, 4) for each person average over hours 1,2 (= data group 1) as well as over hours 3,4 (= data group 2), 5) run t-test for 2 dependent groups. Since Maxwell & Delaney (2004) as well as Kirk (1995) discourage doing contrasts with a pooled error term in within-designs, this could be a simple alternative. $\endgroup$