perform a repeated anova in r

To perform a repeated-measures ANOVA in R, we can use the aov() function, which performs a standard ANOVA, but can also handle within-subjects or repeated-measures designs.

Assuming we have a dataset called mydata that includes the dependent variable DV, the independent variable IV1, and a repeated-measures factor IV2 with 3 levels (level1, level2, level3), we can use the following code:

main.r
# Fit a repeated-measures ANOVA
my.anova <- aov(DV ~ IV1*IV2 + Error(Subject/IV2), data=mydata)

# View the ANOVA table
summary(my.anova)
138 chars
6 lines

In this code, the IV1*IV2 term specifies the main effects of IV1 and IV2, as well as their interaction. The Error() term is used to specify the repeated-measures factor, which in this case is IV2, nested within the Subject variable.

Note that we have to specify the data argument in the aov() function to tell R where to find the variables in our dataset.

The summary() function is then used to view the ANOVA table, which will show the main effects and interaction of IV1 and IV2, as well as the within-subjects effect of IV2.

gistlibby LogSnag