I am a refugee from SPSS in the process of re-learning how to do everything in R. Mostly it's been fun, as R is great for a lot of things but I've run into a snag that I can't seem to find a solution for; any help appreciated.
I want to run repeated-measures ANOVA with contrasts. I know linear mixed models are generally the better way to go but I work in a community where that is only just starting to catch on and my students need to understand what they're reading when they encounter older techniques. SPSS makes contrasts on repeated measures easy, but R does weird things I don't understand. Here's a sample:
df.wide = data.frame(Subj = 1:8, Day1 = c(6,5,5,6,7,4,4,5), Day2 = c(5,5,6,5,3,2,4,7), Day3 = c(2,4,3,4,3,1,1,2)) attach(df.wide) ## contrasts as t-tests Linear = -Day1 + 0*Day2 + Day3 Day1vs23 = -2*Day1 + Day2 + Day3 t.test(Linear) t.test(Day1vs23) ## repeated-measures with long-format data library(reshape2) df.long = melt(df.wide, id.vars="Subj", variable.name="Trial", value.name="DV") contrasts(df.long$Trial) = contr.poly(3) df.long$Subj = factor(df.long$Subj) Anv = aov(DV ~ Trial + Error(Subj/Trial), data=df.long) summary(Anv, split=list(Trial=list("Linear"=1, "Quad"=2)))
The t-tests show t-values of 7.51 for Linear and 1.27 for quadratic, but this does NOT match the
aov() output, which provides F-values of 25.28 and 2.51, and of course substantially different p-values. SPSS contrasts on the repeated measures yield t-values and F-values that match up.
It looks like R isn't partitioning the error term like SPSS does for contrasts, and both contrasts are being tested against a 14 d.f. error term, which is why it doesn't match the t-test. That seems wrong to me.
So, what am I doing wrong in R and how do I fix it?