Repeated Measures ANOVA
Calculator
Learn More
Repeated Measures ANOVA
Definition
Repeated Measures ANOVA analyzes the differences between three or more related measurements on the same subjects over time or under different conditions. It accounts for the correlation between repeated measurements on the same subject. It is commonly applied in within-subjects experimental designs where the same subjects are exposed to different treatments or conditions.
Formulas
F-statistic:
Sum of Squares:
Key Assumptions
Practical Example using rstatix
Step 1: Prepare Data
We’ll organize the scores data in a long format, which is required by rstatix. Each score will be associated with its respective student and teaching method.
library(tidyverse) library(rstatix) scores_long <- tibble( Student = rep(1:5, each = 3), Method = rep(c("A", "B", "C"), times = 5), Score = c(85, 90, 88, 78, 85, 82, 92, 95, 93, 88, 86, 89, 80, 84, 83) )
Step 2: Perform Repeated Measures ANOVA
Using rstatixwe will compute repeated measures ANOVA and summarize the results. Here’s the code:
# Perform repeated measures ANOVA res.aov <- scores_long |> anova_test(dv = Score, wid = Student, within = Method) # Get ANOVA table res.aov %>% get_anova_table()
Step 3: Interpret Results
The output provides the following key information:
- F-statistic:
- p-value:
Output:
# ANOVA Table (type III tests) # Effect DFn DFd F p p<.05 ges # 1 Method 2 8 4.925 0.04 * 0.094
- Effect: The within-subjects factor
- DFn: Degrees of freedom for the numerator
- DFd: Degrees of freedom for the denominator
- F: The F-statistic
- p: The p-value
- ges: The generalized eta-squared effect size
Step 4: Draw Conclusion
Since and , we reject . There is sufficient evidence to conclude that the teaching methods differ significantly.
Effect Size
Generalized Eta-squared ():
Interpretation guidelines:
- Small effect:
- Medium effect:
- Large effect:
For the example above, the generalized eta-squared effect size is , indicating a medium to large effect.
Code Examples
1library(tidyverse)
2library(rstatix)
3
4# Original Data
5scores <- tibble(
6 Student = 1:5,
7 Method_A = c(85, 78, 92, 88, 80),
8 Method_B = c(90, 85, 95, 86, 84),
9 Method_C = c(88, 82, 93, 89, 83)
10)
11
12# Convert to long format
13scores_long <- scores |>
14 pivot_longer(
15 cols = starts_with("Method"),
16 names_to = "Method",
17 values_to = "Score"
18 )
19
20res.aov <- scores_long %>%
21 anova_test(dv = Score, wid = Student, within = Method)
22
23# Get ANOVA table
24res.aov |>
25 get_anova_table()
1import pandas as pd
2from statsmodels.stats.anova import AnovaRM
3
4# Data
5data = pd.DataFrame({
6 'Student': [1, 2, 3, 4, 5],
7 'Method_A': [85, 78, 92, 88, 80],
8 'Method_B': [90, 85, 95, 86, 84],
9 'Method_C': [88, 82, 93, 89, 83]
10})
11
12# Reshape to long format
13data_long = pd.melt(data, id_vars=['Student'], var_name='Method', value_name='Score')
14
15# Repeated Measures ANOVA
16anova = AnovaRM(data_long, 'Score', 'Student', within=['Method'])
17res = anova.fit()
18print(res)
Alternative Tests
Consider these alternatives:
- Friedman Test: Non-parametric alternative when assumptions are violated
- Mixed Models: When dealing with missing data or unequal time points
Related Calculators
One-Way ANOVA Calculator
Two-Way ANOVA Calculator
Paired T-Test Calculator
Friedman Test Calculator
Help us improve
Found an error or have a suggestion? Let us know!