Let's say I have an experiment with three within-subject factors, A, B, & C. The data looks like this.
s a b c 1 1 1 1 1 1 1 2 1 1 2 1 1 1 2 2 1 2 1 1 1 2 1 2 1 2 2 1 1 2 2 2
Simple enough. I have 49 subjects. Now, to do this ANOVA in R, I use
m1 <- aov(score ~ a*b*c + Error(subject/(a*b*c)), data) summary(m1, type=3) ... (clipped) ... Error: s:b:c Df Sum Sq Mean Sq F value Pr(>F) b:c 1 4.608 4.608 8.121 0.00643 ** Residuals 48 27.236 0.567
That looks fine, and matches SPSS's repeated measures GLM. All is well.
We can also do a mixed model in R using
lme4 and get the exact same results as this, as well as a mixed model done in JMP.
m2 <- lmer(score~a*b*c + (a*b*c|s), data) library(car); Anova(m2, type=3, test.statistic"F") ... (clipped) ... F Df Df.res Pr(>F) b:c 8.1206 1 48.000 0.006430 **
I can do the same thing in SAS and get similar results.
proc mixed data=mixedexample method=reml covtest; class a b c s; model score = a|b|c; random intercept a|b|c/sub=s; run;
I can do the ANOVA, by hand in Stata:
anova score a / s|a /// b / s#b /// c / s#c /// a#b / s#a#b /// a#c / s#a#c /// b#c / s#b#c /// a#b#c
I leave off the full interaction error term so it is the residual. Though, for some reason, the
df of the main effect of
a is twice the size of the others. But that's not the question I have.
My question is: how do I do the
proc mixed version of the full LMM in Stata? The simple version is
xtmixed score a##b##c || s:, reml
But how do I add the fully crossed error terms to
xtmixed in the same way I do in
lmer by adding
+ (a*b*c|s)? The data is balanced with no missing values, so the LMM should be the same as the repeated-measures ANOVA, right? Why can't I do this in Stata?
I barely know the basics of LMMs, but this is a Stata question. I'm just trying to figure out all the different ways of performing these two models. Also, if anyone knows a simpler way of doing the univariate ANOVA in Stata without specifying every single error term by hand? This may not even be the "right" way of doing this procedure, but because I get the same output everywhere else, how do I get Stata to do the same thing as R's
proc mixed, and JMP?