The Repeated Measures Analysis of Variance (ANOVA) is a powerful statistical technique used for analyzing the effects of time or conditions on a dependent variable when the same subjects are used for each condition (i.e., repeated measures). This guide will take you through the process of conducting a Repeated Measures ANOVA in R, covering everything from understanding the basics to interpreting and reporting your results.
Table of Contents
- Understanding Repeated Measures ANOVA
- Data Preparation
- Data Formatting
- Running a Repeated Measures ANOVA in R
- Checking Assumptions
- Interpreting Results
- Post-hoc Analysis
- Reporting Findings
- Conclusion
1. Understanding Repeated Measures ANOVA
A Repeated Measures ANOVA is particularly useful when you wish to compare means under different conditions and when these conditions are applied to the same subjects. Examples include studying the effects of different diets on the same group of individuals over time, or comparing the performance of the same athletes under different training regimens.
2. Data Preparation
The primary considerations for data preparation in Repeated Measures ANOVA are similar to those of a regular ANOVA:
- Dependent Variable: The variable you are interested in (e.g., weight, score).
- Within-Subject Factor: The variable that represents the different conditions (e.g., time, diet).
- Between-Subject Factors (optional): Additional categorical variables that separate the data into different groups (e.g., gender).
3. Data Formatting
In R, you can format your data either in “wide” or “long” format. Here’s how each looks:
3.1 Wide Format
In the wide format, each subject’s repeated measures are listed in a single row. For example:

3.2 Long Format
In the long format, each row is a single measure for a subject at a given time.

Either format can be used in R, but we’ll focus on the wide format for this guide.
4. Running a Repeated Measures ANOVA in R
To perform a Repeated Measures ANOVA, you’ll use the aov()
function.
With the aov()
function:
# Create data
subject <- c(1, 2, 3, 4)
time1 <- c(5, 4, 6, 7)
time2 <- c(6, 5, 7, 8)
time3 <- c(7, 6, 8, 9)
data <- data.frame(subject, time1, time2, time3)
# Run the ANOVA
result <- aov(cbind(time1, time2, time3) ~ subject, data=data)
summary(result)
5. Checking Assumptions
Repeated Measures ANOVA assumes:
- Sphericity: Mauchly’s Test can be used to test this.
- Normality: Check the distribution of residuals.
- Homogeneity of Variance: Levene’s Test can be used.
These assumptions need to be verified before interpreting the results.
6. Interpreting Results
You’ll receive an output with F-values and p-values for each factor and interaction. A significant p-value (usually < 0.05) means that there are statistically significant differences between the conditions.
7. Post-hoc Analysis
If the ANOVA indicates significant effects, post-hoc tests can be performed to find out which groups are different from each other. You can use the TukeyHSD()
function or pairwise.t.test()
for this.
8. Reporting Findings
When reporting your findings, be sure to include:
- The F-values and p-values for each main effect and interaction.
- The results of your assumption checks.
- Any post-hoc tests that were conducted.
9. Conclusion
Performing a Repeated Measures ANOVA in R provides you with a robust tool to analyze complex datasets involving repeated measures. This comprehensive guide should serve as a robust resource for both the beginner and the intermediate R user. By following these steps, you will be well on your way to mastering one of the most versatile statistical techniques available for analyzing repeated measures data.