I would like to run a simple repeated measures ANOVA with 2 factors (Food & Drink).
Let's have a dummy df:
nSubj = 10; nFood = 5; nDrnk = 2;
dummy <- data.frame(Subj = factor(rep(1:nSubj, each=nFood*nDrnk, time=1)),
Food = factor(rep(letters[1:nFood], each=nDrnk, time=nSubj)),
Drnk = factor(rep(c("water","beer"), each=1, time=nSubj*nFood)),
Like = sample(0:10, size=nSubj*nFood*nDrnk, replace=T))
Using ezANOVA:
library(ez)
m1 <- ezANOVA(data=dummy, dv=Like, wid=Subj, within=c(Food, Drnk), detailed=F, type=3); m1
Effect DFn DFd F p p<.05 ges
2 Food 4 36 0.3282034 0.85717626 0.01301648
3 Drnk 1 9 7.2461652 0.02472067 * 0.07354474
4 Food:Drnk 4 36 1.5834181 0.19974760 0.07367973
Using lme:
library(nlme)
m2 <- lme(Like ~ Food*Drnk, random = ~1|Subj/Food/Drnk, data=dummy, method = "ML"); anova(m2)
numDF denDF F-value p-value
(Intercept) 1 45 288.81124 <.0001
Food 4 36 0.29673 0.8781
Drnk 1 45 7.14446 0.0104
Food:Drnk 4 45 1.78966 0.1476
Using aov:
m3 <- aov(Like ~ Food*Drnk + Error(Subj/(Food*Drnk)),data=dummy); summary(m3)
Error: Subj
Df Sum Sq Mean Sq F value Pr(>F)
Residuals 9 72.45 8.05
Error: Subj:Food
Df Sum Sq Mean Sq F value Pr(>F)
Food 4 10.9 2.725 0.328 0.857
Residuals 36 298.9 8.303
Error: Subj:Drnk
Df Sum Sq Mean Sq F value Pr(>F)
Drnk 1 65.61 65.61 7.246 0.0247 *
Residuals 9 81.49 9.05
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Error: Subj:Food:Drnk
Df Sum Sq Mean Sq F value Pr(>F)
Food:Drnk 4 65.7 16.43 1.583 0.2
Residuals 36 373.7 10.38
The denDF in the lme is different: why? is my lme model correct?
EDIT: Since nSubj = 10; nFood = 5; nDrnk = 2 and it is a repeated measures, the dof should be: Food=(4,36); Drnk=(1,9); Food:Drnk=(4,36). Right? So, why does lme have different dof?
EDIT 2: following Sal's suggestion, I run aov with another error:
m4 <- aov(Like ~ Food*Drnk + Error(Subj/Food/Drnk),data=dummy); summary(m4)
Error: Subj
Df Sum Sq Mean Sq F value Pr(>F)
Residuals 9 100.4 11.16
Error: Subj:Food
Df Sum Sq Mean Sq F value Pr(>F)
Food 4 10.74 2.685 0.319 0.863
Residuals 36 302.66 8.407
Error: Subj:Food:Drnk
Df Sum Sq Mean Sq F value Pr(>F)
Drnk 1 54.8 54.76 7.267 0.00984 **
Food:Drnk 4 65.1 16.29 2.161 0.08875 .
Residuals 45 339.1 7.54
This is interesting, the results are the same of m2 with the Drnk variable ignored (?).
Next, Changing the order of the variables in the lme's random:
m5 <- lme(Like ~ Food*Drnk, random = ~1|Subj/Drnk/Food, data=dummy, method = "ML"); anova(m5)
numDF denDF F-value p-value
(Intercept) 1 72 117.06035 <.0001
Food 4 72 0.61245 0.6550
Drnk 1 9 0.36079 0.5629
Food:Drnk 4 72 0.21603 0.9287
The DenDFs of both Food and interaction are wrong... other combinations of lme's random are either wrong or gives error. Therefore, how can I model a 2-way Repeated Measures ANOVA using lme?
Any help is appreciated
Cheers
type="sequential"
default inanova.lme
. This may not match the marginal sums of squares used inezANOVA
whentype=3
. $\endgroup$lme
fromnlme
does not compute the denominator degrees of freedom correctly. If this is true, I get my answer :/ $\endgroup$Subj/Food/Drnk
, and see what happens. $\endgroup$