##### Anova for (simple) within-subject designs. ##### Source: http://blog.gribblelab.org/2009/03/09/repeated-measures-anova-using-r/ ##### (This is a use of "ANOVA with repeated measures") ##### working with the following data: ### ## The data, unfortunately, has to be in a DIFFERENT FORMAT than for ## paired-t and so on. Paired-t tests wanted one row per subject ## with a column of the outcome for each treatment. ## But ANOVA wants one row per outcome. ## Here's some example data structured properly for ANOVA-within-subjects: > dv <- c(1,3,4,2,2,3,2,5,6,3,4,4,3,5,6) > subject <- factor(c("s1","s1","s1","s2","s2","s2","s3","s3","s3", + "s4","s4","s4","s5","s5","s5")) > myfactor <- factor(c("f1","f2","f3","f1","f2","f3","f1","f2","f3", + "f1","f2","f3","f1","f2","f3")) > mydata <- data.frame(dv, subject, myfactor) ## So your data will look like this: dv (ie, dependent variable) subject myfactor (ie, treatment) 1 s1 f1 3 s1 f2 4 s1 f3 2 s2 f1 2 s2 f2 3 s2 f3 ... ## Now you're ready to run the test: > am1 <- aov(dv ~ myfactor + Error(subject/myfactor), data=mydata) > summary(am1) ## You get: Error: subject Df Sum Sq Mean Sq F value Pr(>F) Residuals 4 12.4 3.1 Error: subject:myfactor Df Sum Sq Mean Sq F value Pr(>F) myfactor 2 14.9333 7.4667 13.576 0.002683 ** Residuals 8 4.4000 0.5500 --- Signif. codes: 0 Ô***Õ 0.001 Ô**Õ 0.01 Ô*Õ 0.05 Ô.Õ 0.1 Ô Õ 1