I am attempting to do a repeated measures anova using r with the aov() command from the {car} package. I wanted to be sure that I wrote my code for this approach correctly (see below), so I cross-checked the results against same repeated measures anova model using the ezANOVA() command from the {ez} package.
What I found was that the results from each anova were the same, but the residuals of each model using the respective packages were distributed differently. Using the aov() command, the residuals were non-normally distributed whereas using ezANOVA() they were normally distributed.
###############################
#aov() using the {car} package#
###############################
mod.aov <-aov(rating~(factor1*factor2) + Error(id/(factor1*factor2)), data=datalong)
shapiro.test(residuals(mod.aov))
Shapiro-Wilk normality test
data: residuals(mod.aov)
W = 0.9961, p-value = 0.036
pearson.test(residuals(mod.aov))
Pearson chi-square normality test
data: residuals(gain.aov)
P = 50.4, p-value = 0.004086
##################################
#ezANOVA() using the {ez} package#
##################################
mod.ez <- ezANOVA(data = datalong,
dv = .(rating),
wid = .(id),
within = .(factor1, factor2),
detailed = TRUE,
return_aov = TRUE)
shapiro.test(residuals(mod.ez$aov))
Shapiro-Wilk normality test
data: residuals(mod.ez$aov)
W = 0.9876, p-value = 0.449
pearson.test(residuals(mod.aov$aov))
Pearson chi-square normality test
data: residuals(mod.ez$aov)
P = 7.75, p-value = 0.6532
I do not understand whether the residuals of each model are different because of my code, or because of the differences between way the packages perform the analyses. Can anybody help? I can provide additional information if needed. Thanks.