FAQ/anovaR112014-05-30 13:02:15PeterWatson102014-05-30 13:01:55PeterWatson92014-05-30 13:00:36PeterWatson82013-03-27 16:55:13PeterWatson72013-03-27 16:54:54PeterWatson62013-03-08 10:17:10localhostconverted to 1.6 markup52012-07-11 16:34:05PeterWatson42010-07-20 13:52:59PeterWatson32010-07-20 13:51:16PeterWatson22010-07-20 13:50:44PeterWatson12010-07-20 13:47:38PeterWatsonHow 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 symmetry, 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. aov can also be used for doing a repeated measures ANOVA but does not perform a check for sphericity. Notice the 'reshape' function which converts the 'broad' format with one subject per row (as used in SPSS, for exmaple) to the required 'long' format where there is only one response per row. In the example below three columns are created called subject, pairs and corr creating 84 rows for each of the 3 observations on each of 28 subjects. You can also use EZANOVA to fit repeated measures ANOVAs using R on data with large numbers of degrees of freedom which may need a substantial sphericity correction. Free downloads and further information are available from here.