Diff for "FAQ/anovaR" - CBU statistics Wiki
location: Diff for "FAQ/anovaR"
Differences between revisions 6 and 7
Revision 6 as of 2013-03-08 10:17:10
Size: 1984
Editor: localhost
Comment: converted to 1.6 markup
Revision 7 as of 2013-03-27 16:54:54
Size: 2063
Editor: PeterWatson
Comment:
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
There are rather confusingly at least three different procedures in R for performing repeated measures (including mixed anovas where one or more between subjects factors are present) analysis in R. These include aov(), anova and Anova(). Of these Anova() additionally produces output containing the Greenhouse-Geisser and Huynh-Feldt corrections for when the sphericity assumption (of equal correlations between pairs of combinations of within subjects factor levels) does not hold. More information on the sphericity assumption may be found [[FAQ/Mauchly|here.]] There are rather confusingly at least three different procedures in R for performing repeated measures (including mixed anovas where one or more between subjects factors are present) analysis in R. These include aov(), anova and Anova(). Of these Anova() additionally produces output containing the Greenhouse-Geisser and Huynh-Feldt corrections for when the sphericity assumption (of equal correlations between pairs of combinations of within subjects factor levels) does not hold. More information on the sphericity assumption, a particular example of a more general assumption known as compound symmtery, may be found [[FAQ/Mauchly|here.]]

How do I perform a repeated measures analysis of variance in R including the outputting of sphericity corrections?

There are rather confusingly at least three different procedures in R for performing repeated measures (including mixed anovas where one or more between subjects factors are present) analysis in R. These include aov(), anova and Anova(). Of these Anova() additionally produces output containing the Greenhouse-Geisser and Huynh-Feldt corrections for when the sphericity assumption (of equal correlations between pairs of combinations of within subjects factor levels) does not hold. More information on the sphericity assumption, a particular example of a more general assumption known as compound symmtery, may be found here.

The R syntax below if for two within subjects factors mood (which takes the values 'happy, 'sad' and 'angry') and time (2 time points). There is also a between subjects factor called group. The data is given in a SPSS data file here.

The R syntax for running the full model is given below. The sphericity correction factors and corrected p-values for the F ratios are given for each term involving a within subjects factor although the corrected degrees of freedom are not outputted and would need to be computed by multiplying the uncorrected values by the correction factors.

Note that you only need to run the first line once as this installs the Anova() procedure in your R library folder on your PC hard disk. It also assumes you have already got the foreign library on your hard drive.

install.packages(c('Anova','car'))
library(car)
library(foreign)
y <- read.spss('U:\\R_Work\\rep_meas_formatted.sav')
y <- data.frame(y)
mood <- factor(rep(c('happy', 'sad', 'angry'), c(2,2,2)), levels=c('happy', 'sad', 'angry'))
time <- ordered(rep(1:2,3))
idata <- data.frame(mood,time)
mod.ok <- lm(cbind(y1, y2, y3, y4, y5, y6) ~ group, data=y)
av.ok <- Anova(mod.ok, idata=idata, idesign=~mood*time, type='II')
summary(av.ok,multivariate=FALSE)

None: FAQ/anovaR (last edited 2014-05-30 13:02:15 by PeterWatson)