EZ Statistics

Repeated Measures ANOVA

Calculator

2. Select Columns & Options

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:

F=MSTreatmentMSError=SSTreatment/(k1)SSError/((k1)(n1))F = \frac{MS_{Treatment}}{MS_{Error}} = \frac{SS_{Treatment}/(k-1)}{SS_{Error}/((k-1)(n-1))}

Sum of Squares:

SSTotal=SSTreatment+SSSubjects+SSErrorSS_{Total} = SS_{Treatment} + SS_{Subjects} + SS_{Error}

Key Assumptions

Sphericity: Equal variances of differences between all pairs of groups
Normality: Differences should be approximately normally distributed
No Outliers: No significant outliers in any level of the within-subjects factor

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: F=4.925F = 4.925
  • p-value: p=0.04p = 0.04

Output:


# ANOVA Table (type III tests)

#  Effect   DFn DFd     F    p  p<.05   ges
# 1 Method   2   8   4.925 0.04    *   0.094
          
where:
  • 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 F=7.19F = 7.19 and p=0.016<α=0.05p = 0.016 \lt \alpha = 0.05 , we reject H0H_0 . There is sufficient evidence to conclude that the teaching methods differ significantly.

Effect Size

Generalized Eta-squared (η2\eta^2):

ηg2=SStreatmentSStreatment+SSerror+SSsubjects\eta^2_g = \frac{SS_{treatment}}{SS_{treatment} + SS_{error} + SS_{subjects}}

Interpretation guidelines:

  • Small effect: ηp20.01\eta^2_p \approx 0.01
  • Medium effect: ηp20.06\eta^2_p \approx 0.06
  • Large effect: ηp20.14\eta^2_p \approx 0.14

For the example above, the generalized eta-squared effect size is 0.0940.094, indicating a medium to large effect.

Code Examples

R
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()
Python
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!