Model library Repeated Measures ANOVA
Statistical model reference

Repeated Measures ANOVA

Review when to use this method, its data requirements, implementation patterns, and interpretation guidance.

Description

A specialized form of ANOVA designed for analyzing data when the same subjects are measured multiple times. It accounts for the correlation between repeated measurements on the same individuals, making it essential for longitudinal studies, time series experiments, or any design where measurements are taken from the same subjects across different conditions or time points.

Use Cases
  • longitudinal studies
  • within-subjects designs
  • pre-post intervention analysis
  • time series experiments
Requirements
  • Sample Size: small, medium, large
  • Missing Data: none, random, systematic
  • Data Distribution: normal
  • Relationship Type: linear
Variable Types
Dependent Variables
  • continuous
Independent Variables
  • categorical
  • time
Implementation
import pingouin as pg

# Using pingouin for repeated measures ANOVA
rm_anova = pg.rm_anova(data=df, dv='score', within='time', subject='subject_id')
print(rm_anova)

# Post-hoc pairwise comparisons
posthoc = pg.pairwise_ttests(data=df, dv='score', within='time', subject='subject_id', padjust='bonf')
Documentation
library(afex)

# Using afex package for repeated measures ANOVA
model <- aov_ez(
  id = "subject_id",
  dv = "score",
  within = c("time", "condition"),
  data = df
)

# Model summary
summary(model)

# Post-hoc tests with emmeans
library(emmeans)
emm <- emmeans(model, ~ time)
pairs(emm, adjust = "bonferroni")
Documentation
GLM time1 time2 time3
  /WSFACTOR=time 3 Polynomial
  /METHOD=SSTYPE(3)
  /PRINT=DESCRIPTIVE ETASQ
  /CRITERIA=ALPHA(.05)
  /WSDESIGN=time.
Documentation
PROC GLM DATA=dataset;
  CLASS subject_id;
  MODEL time1 time2 time3 = / NOUNI;
  REPEATED time 3 / PRINTE SUMMARY;
RUN;
Documentation
anova score subject_id / time#subject_id, repeated(time)
margins time
pwcompare time, mcompare(bonferroni)
Documentation
Synthetic Data Example

A longitudinal dataset suitable for Repeated Measures ANOVA analysis with three time points

R Code for Data Generation and Analysis
# Generate synthetic data for Repeated Measures ANOVA
set.seed(123)
library(tidyverse)

# Parameters
n_subjects <- 30
time_points <- 3
baseline_mean <- 50
treatment_effect <- 5
subject_variability <- 3
error_sd <- 2

# Create data frame
df <- expand.grid(
  subject_id = factor(1:n_subjects),
  time = factor(1:time_points, labels = c("Baseline", "Midpoint", "Post"))
) %>%
  mutate(
    # Subject-specific random intercept
    subject_effect = rep(rnorm(n_subjects, 0, subject_variability), each = time_points),
    # Time effect
    time_effect = case_when(
      time == "Baseline" ~ 0,
      time == "Midpoint" ~ treatment_effect * 0.6,
      time == "Post" ~ treatment_effect
    ),
    # Generate scores with random error
    score = baseline_mean + subject_effect + time_effect + rnorm(n_subjects * time_points, 0, error_sd)
  )

# Descriptive statistics
df %>%
  group_by(time) %>%
  summarise(
    mean = mean(score),
    sd = sd(score),
    min = min(score),
    max = max(score)
  )

# Visualization
ggplot(df, aes(x = time, y = score, group = subject_id)) +
  geom_line(alpha = 0.3) +
  geom_point() +
  stat_summary(aes(group = 1), fun = mean, geom = "line", color = "red", size = 1.5) +
  labs(title = "Repeated Measures Data with Individual Trajectories",
       subtitle = "Red line shows group mean at each time point")

# Fit repeated measures ANOVA
library(afex)
model <- aov_ez(
  id = "subject_id",
  dv = "score",
  within = "time",
  data = df
)

# Model summary
summary(model)

# Post-hoc tests
library(emmeans)
emm <- emmeans(model, ~ time)
pairs(emm, adjust = "bonferroni")
Copy this code into your R environment to generate synthetic data and perform analysis with this model.
Expected Analysis Results
Console Output

> # Model summary
> summary(model)

Univariate Type III Repeated-Measures ANOVA Assuming Sphericity

        Effect    df    MSE      F  ges p.value
1       time 2, 58 4.123 28.76 0.498  <.001
---
Sphericity correction method: GG

> # Post-hoc tests
> pairs(emm, adjust = "bonferroni")

 contrast           estimate    SE df t.ratio p.value
 Baseline - Midpoint    -3.12 0.42 58  -7.429  <.0001
 Baseline - Post        -5.01 0.45 58 -11.125  <.0001
 Midpoint - Post       -1.89 0.38 58  -4.973  0.0001

Results are averaged over the levels of: subject_id 
P value adjustment: bonferroni method for 3 tests
These results are from running the R code on synthetic data. Your actual results may vary depending on your data.
Interpretation Guide

Need help interpreting the results of your Repeated Measures ANOVA analysis? Our comprehensive interpretation guide explains:

  • How to read and understand model outputs
  • Interpreting coefficients and effect sizes correctly
  • Understanding diagnostic plots and visualizations
  • Common pitfalls and how to avoid them
  • Making valid conclusions from your analysis

Statistical assistant