Repeated-measures ANOVA, also known as Within-Subjects ANOVA, is a statistical technique used when the same subjects are measured multiple times under different conditions or over time. This type of ANOVA accounts for the correlation between repeated measurements on the same subjects, making it suitable for experiments where each subject serves as their control.
What is Repeated-measures ANOVA?
Repeated-measures ANOVA extends the one-way ANOVA to situations where multiple measurements are taken from the same subjects. It tests whether there are significant differences in means across multiple conditions or time points, considering the within-subject correlation.
- Within-Subjects Factor: The factor with repeated measurements, such as time or condition.
- Between-Subjects Factor: The factor that varies between different subjects, though in many Repeated-Measures designs, this may not be present.
- Sphericity: An assumption of Repeated-Measures ANOVA that the variances of the differences between all combinations of related groups (levels) are equal. If this assumption is violated, corrections like the Greenhouse-Geisser or Huynh-Feldt adjustments are used.
We will use a simulated dataset to explain how to perform a Repeated-Measures ANOVA. In this example, we'll assume we have a dataset where subjects are measured at three different time points.
Step 1: Simulate Data
Now we will first Simulate Data.
# Set seed for reproducibility
set.seed(123)
# Simulate data for 10 subjects measured at 3 time points
subject <- factor(rep(1:10, each = 3))
time <- factor(rep(c("T1", "T2", "T3"), times = 10))
response <- c(
rnorm(10, mean = 50, sd = 5), # T1
rnorm(10, mean = 55, sd = 5), # T2
rnorm(10, mean = 60, sd = 5) # T3
)
# Create a data frame
data <- data.frame(subject, time, response)
Step 2: Fit the Repeated-Measures ANOVA Model
To perform the Repeated-Measures ANOVA, we use the aov() function with a formula that includes the within-subject factor (time) and subject as a random effect.
# Perform Repeated-Measures ANOVA
aov_model <- aov(response ~ time + Error(subject/time), data = data)
# View the summary of the ANOVA
summary(aov_model)
Output:
Error: subject
Df Sum Sq Mean Sq F value Pr(>F)
Residuals 9 336.2 37.36
Error: subject:time
Df Sum Sq Mean Sq F value Pr(>F)
time 2 44.2 22.11 0.701 0.509
Residuals 18 567.7 31.54
response ~ time: The dependent variableresponseis modeled as a function of the within-subject factortime.Error(subject/time): Specifies thatsubjectis a random effect andtimeis nested withinsubject.
The ANOVA summary provides F-values and p-values for the effect of time. A small p-value (e.g., < 0.05) for the time factor suggests significant differences in the response across different time points.
Conclusion
In this article, we covered the theory and implementation of Repeated-Measures ANOVA in R. We performed the following steps:
- Simulated data for repeated measures.
- Fitted a Repeated-Measures ANOVA model using the
aov()function.
Repeated-Measures ANOVA is a powerful tool for analyzing data with multiple measurements on the same subjects, allowing you to account for within-subject correlations and test for significant effects across different conditions or time points.