I am trying to move from using the ez package to lme for repeated measures ANOVA (as I hope I will be able to use custom contrasts on with lme).
Following the advice from this blog post I was able to set up the same model using both aov (as does ez, when requested) and lme. However, whereas in the example given in that post the F-values do perfectly agree between aov and lme (I checked it, and they do), this is not the case for my data. Although the F-values are similar, they are not the same.
aov returns a f-value of 1.3399, lme returns 1.36264. I am willing to accept the aov result as the "correct" one as this is also what SPSS returns (and this is what counts for my field/supervisor).
Questions:
It would be great if someone could explain why this difference exists and how I can use
lmeto provide credible results. (I would also be willing to uselmerinstead oflmefor this type of stuff, if it gives the "correct" result. However, I haven't used it so far.)After solving this problem I would like to run a contrast analysis. Especially I would be interested in the contrast of pooling the first two levels of factor (i.e.,
c("MP", "MT")) and compare this with the third level of factor (i.e.,"AC"). Furthermore, testing the third versus the fourth level of factor (i.e.,"AC"versus"DA").
Data:
tau.base <- structure(list(id = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L,
9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L,
22L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L,
14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 1L, 2L, 3L, 4L,
5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L,
19L, 20L, 21L, 22L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L,
11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L), .Label = c("A18K",
"D21C", "F25E", "G25D", "H05M", "H07A", "H08H", "H25C", "H28E",
"H30D", "J10G", "J22J", "K20U", "M09M", "P20E", "P26G", "P28G",
"R03C", "U21S", "W08A", "W15V", "W18R"), class = "factor"), factor = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L), .Label = c("MP", "MT", "AC", "DA"
), class = "factor"), value = c(0.9648092876, 0.2128662077, 1,
0.0607615485, 0.9912814024, 3.22e-08, 0.8073856412, 0.1465590332,
0.9981672618, 1, 1, 1, 0.9794401938, 0.6102546108, 0.428651501,
1, 0.1710644881, 1, 0.7639763913, 1, 0.5298989196, 1, 1, 0.7162733447,
0.7871177434, 1, 1, 1, 0.8560509327, 0.3096989662, 1, 8.51e-08,
0.3278862311, 0.0953598576, 1, 1.38e-08, 1.07e-08, 0.545290432,
0.1305621416, 2.61e-08, 1, 0.9834051136, 0.8044114935, 0.7938839461,
0.9910112678, 2.58e-08, 0.5762677121, 0.4750002288, 1e-08, 0.8584252623,
1, 1, 0.6020385797, 8.51e-08, 0.7964935271, 0.2238374288, 0.263377904,
1, 1.07e-08, 0.3160751898, 5.8e-08, 0.3460325565, 0.6842217296,
1.01e-08, 0.9438301877, 0.5578367224, 2.18e-08, 1, 0.9161424562,
0.2924856039, 1e-08, 0.8672987992, 0.9266688748, 0.8356425464,
0.9988463913, 0.2960361777, 0.0285680426, 0.0969063841, 0.6947998266,
0.0138254805, 1, 0.3494775301, 1, 2.61e-08, 1.52e-08, 0.5393467752,
1, 0.9069223275)), .Names = c("id", "factor", "value"), class = "data.frame", row.names = c(1L,
6L, 10L, 13L, 16L, 17L, 18L, 22L, 23L, 24L, 27L, 29L, 31L, 33L,
42L, 43L, 44L, 45L, 54L, 56L, 58L, 61L, 64L, 69L, 73L, 76L, 79L,
80L, 81L, 85L, 86L, 87L, 90L, 92L, 94L, 96L, 105L, 106L, 107L,
108L, 117L, 119L, 121L, 124L, 127L, 132L, 136L, 139L, 142L, 143L,
144L, 148L, 149L, 150L, 153L, 155L, 157L, 159L, 168L, 169L, 170L,
171L, 180L, 182L, 184L, 187L, 190L, 195L, 199L, 202L, 205L, 206L,
207L, 211L, 212L, 213L, 216L, 218L, 220L, 222L, 231L, 232L, 233L,
234L, 243L, 245L, 247L, 250L))
And the code:
require(nlme)
summary(aov(value ~ factor+Error(id/factor), data = tau.base))
anova(lme(value ~ factor, data = tau.base, random = ~1|id))
lmeresults from standard textbook ANOVA (given byaov, and which is what I need), this is not an option for me. In my paper I want to report an ANOVA, not something like an ANOVA. Interestingly Venables & Ripley (2002, p. 285) show that both approaches lead to identical estimates. But the differences in F values leave me with a bad feeling. Furthermore,Anova()(fromcar) returns only Chi²-values forlmeobjects. Therefore for me, my first question is not answered yet. – Henrik Aug 11 '11 at 13:00lme; but for contrasts,glhtworks onlmfits too, not justlmefits. (Also, thelmeresults are standard textbook results too.) – Aaron left Stack Overflow Aug 11 '11 at 22:04lmfor a repeated measure analysis. Onlyaovcan deal with repeated measures but will return an object of classaovlistwhich is unfortunately not handled byglht. – Henrik Aug 12 '11 at 08:56aov? In general I am interested in a general solution with both between and within factors. But if there is another neat way for parts of this problem, I would be interested, too. – Henrik Aug 12 '11 at 14:29lmuses the residual error as the error term for all effects; when there are effects that should use a different error term,aovis necessary (or instead, using the results fromlmto compute the F-stats manually). In your example, the error term forfactoris theid:factorinteraction, which is the residual error term in an additive model. Compare your results toanova(lm(value~factor+id)). – Aaron left Stack Overflow Aug 12 '11 at 14:33