Chapter 5 · Comparing groups beyond the t-test

What if the same patients are measured again and again?

Repeated measures ANOVA, sphericity, Friedman test, crossover trials, linear mixed models and GEE.

Read first: Choosing a test, Clinical trials

The problem first

You are a second-year Medicine resident. Your thesis compares two oral drugs in type 2 diabetes: 8 patients on drug A and 8 on drug B, with HbA1c at 3, 6, 9 and 12 months. You enter 64 rows in the spreadsheet, run an unpaired t-test of drug B against drug A, and get p = 0.002.

Your guide looks at the spreadsheet and counts the patient numbers in the first column.

“You have 16 patients, not 64. Why does your t-test think you have 64?”

Start here

Why are measurements on the same patient not independent?

A patient with high pain at week 0 usually still has higher pain than most other patients at week 8. Each patient carries their own level through every visit, so their values are correlated.

Read as 40 separate patientsRead as 10 patients, 4 visits each2040608020406080wk 0wk 0wk 2wk 2wk 4wk 4wk 8wk 8one-way ANOVA p = 0.029repeated measures p < 0.001
Made-up teaching data used throughout this chapter: pain score (0 to 100) in 10 patients at weeks 0, 2, 4 and 8 of physiotherapy. The correlation between any two visits is between 0.83 and 0.95. Read as 40 patients, the spread between patients hides the fall. Read as 10 patients, every patient is compared with themselves.

Two errors follow from treating repeated values as separate patients. When groups of patients are compared, the analysis believes it has more independent information than it does, so its standard errors are too small and its p-values too small. When the same patients are compared across time, it leaves the variation between patients in the error term, so it can miss a real change. The figure shows the second error, and the interactive element below shows the first.

The amount of duplication is measured by the intraclass correlation (ICC): the share of the total variance that lies between patients. With m visits per patient, the variance of a group mean is inflated by the design effect, the same formula used for cluster samples.

design effect = 1 + (m − 1) × ICC · effective number of patients = number of values ÷ design effect

t-tests at each visit do not solve the problem. Matthews, Altman, Campbell and Royston (BMJ, 1990) described the common method that compares groups at a series of time points, possibly with t-tests, as flawed on two counts: it may not answer the clinical question, and it may be statistically invalid. Each extra test is another chance of a false positive, and the tests are correlated with each other because they use the same patients.

Interactive

Change how much patients differ and watch the standard error of the treatment difference

The unpaired t-test on all 64 values assumes 64 independent patients. The mixed model knows which values come from the same patient.

Try this: leave the between-patient SD at 0.8 and compare the two standard errors. Then move it down to 0.1. The two analyses agree only when patients hardly differ from each other.

Made-up teaching data: HbA1c at 3, 6, 9 and 12 months in 8 patients on drug A and 8 on drug B, 64 values in all. The true difference is 0.5 percentage points.

0.8

How much one patient's usual HbA1c differs from another's

0.3

How much one patient's value varies from visit to visit

Draw the data as
0.25SE if the 64 values are treated as 64 patients (t-test, p 0.002)
0.52SE from the mixed model with a random intercept (p 0.132)

Both analyses give the same difference, B − A = -0.83 percentage points. Treated as separate patients, its 95% CI is -1.34 to -0.32. The mixed model gives -1.94 to 0.28. The intraclass correlation is 0.93, so the 32 values in each group carry about as much information as 8.5 independent patients, not 32.

between-patient variance 1.053 · within-patient variance 0.083 · df 62 against 14

678910HbA1c, %3 months6 months9 months12 monthsA 7.99B 7.16
drug Adrug Bgroup mean

The method

How does repeated measures ANOVA use each patient as their own control?

It splits the variation into three parts: differences between patients, differences between visits, and what is left over. The differences between patients are removed before the visits are compared.

Repeated measures ANOVAbetween patientsSS 6635.1timeSS 2145.4errorSS 995.1F = 715.1 ÷ 36.86 = 19.40One-way ANOVA that ignores which values belong to which patienttimeSS 2145.4within groups (patients + error)SS 7630.2patients removed from the errorF = 715.1 ÷ 212.0 = 3.37
The same teaching data. The time effect (SS 2145.4, 3 df, mean square 715.1) is the same in both analyses. Repeated measures ANOVA takes the between-patient part (SS 6635.1) out of the error, leaving a mean square of 36.86 on 27 df. The one-way ANOVA keeps it, and its error mean square is 212.0 on 36 df.

F = mean square for time ÷ mean square for error · df = (k − 1) and (n − 1)(k − 1)

k
number of visits (4)
n
number of patients (10)
mean square
sum of squares ÷ its degrees of freedom

In the teaching data, F = 19.40 with 3 and 27 df (p < 0.001). The critical F at 5% is 2.96. Mean pain was 63.7 at week 0, 52.3 at week 2, 46.4 at week 4 and 45.2 at week 8.

With two or more groups of patients, for example physiotherapy against exercise at home, the design becomes a mixed (split-plot) ANOVA: group is a between-patient factor and time is a within-patient factor. The question that matters in a trial is usually the group × time interaction: does the change over time differ between the groups?

Assumptions: a measurement outcome, roughly normal residuals, every patient measured at every visit, and sphericity. A patient with one missing visit is dropped from a repeated measures ANOVA unless the value is imputed.

Assumption

What is sphericity, and what do Mauchly, Greenhouse-Geisser and Huynh-Feldt do?

Take every patient's change between two visits. Sphericity means that the variance of these changes is the same for every pair of visits. Then the F test gives correct p-values.

average 73.712.7weeks 0–261.3weeks 0–4139.8weeks 0–838.5weeks 2–4121.2weeks 2–868.6weeks 4–8
Variance of each patient's change in the teaching data. Changes over long gaps (red bars) vary much more than changes between neighbouring visits, because measurements close in time are more alike. This pattern is common in repeated measures and breaks sphericity.
  1. Mauchly's test (1940) tests the null hypothesis that sphericity holds. Teaching data: W = 0.154, χ²(5) = 14.42, p = 0.01, so sphericity is rejected. IBM's documentation for SPSS notes that the test has little power in small samples and may be significant in large samples when the departure has little effect.
  2. Epsilon (ε) measures how far the data are from sphericity. It is 1 when sphericity holds, and its lowest possible value is 1 ÷ (k − 1), here 0.33. Both degrees of freedom of F are multiplied by ε, and F is compared with the new degrees of freedom.
  3. Greenhouse-Geisser (1959) described a degrees-of-freedom adjustment that gives conservative F tests. Teaching data: ε = 0.52, F(1.56, 14.04) = 19.40, p = 0.0002.
  4. Huynh-Feldt (1976) proposed a second estimate of ε because the first is seriously biased when ε is not low. Teaching data: ε = 0.61, F(1.83, 16.45) = 19.40, p = 0.00006.
  5. Lower bound: ε = 1 ÷ (k − 1) = 0.33, F(1, 9), p = 0.0017. It is the most conservative choice.

Sphericity is automatically true when there are only two visits, because there is only one pair of visits. A linear mixed model avoids the assumption by modelling the correlation between visits directly.

Interactive

Change how the visits are correlated and watch epsilon and the corrected p-value

Sphericity is a statement about the covariance matrix of the visits. Equal variances with equal correlations always satisfy it. Unequal variances, or correlations that fall with distance, usually do not.

Try this: with "Equal correlations" move the correlation: the six bars stay equal and epsilon stays at 1.00. Now move the SD ratio to 2.0, or choose "Correlation falls with distance" and set the correlation to 0.9. The bars become unequal, epsilon falls below 1, and the corrected p-value is larger than the uncorrected one.

Teaching example: 10 patients measured at weeks 0, 2, 4 and 8. The repeated measures ANOVA gave F = 4.0 with 3 and 27 degrees of freedom. The bars show the variance of each patient's change between two visits.

Correlation between visits
0.50

Every pair of visits has this correlation

1.0

1.0 means the spread is the same at every visit

1.00Greenhouse-Geisser epsilon
1.00Huynh-Feldt epsilon

Uncorrected p = 0.018. With the Greenhouse-Geisser correction both degrees of freedom are multiplied by 1.00, giving F(3.00, 27.00) and p = 0.018. Huynh-Feldt p = 0.018. The lower bound (epsilon 0.33) gives p = 0.077.

average of the six100weeks 0–2100weeks 0–4100weeks 0–8100weeks 2–4100weeks 2–8100weeks 4–8Sphericity: all six bars the same height

Non-parametric test

What if the scores are skewed or ordinal? The Friedman test

The Friedman test ranks each patient's own values from lowest to highest, then asks whether some visits collect higher ranks than others. It is the rank version of a one-way repeated measures ANOVA.

  1. Within each patient, rank the 4 visits (1 = lowest pain). Tied values share the average rank. Patient 5 scored 72 at weeks 2 and 4, so both get rank 1.5.
  2. Add the ranks for each visit over the 10 patients: 39, 25.5, 16.5 and 19. If the visits did not differ, each sum would be close to 10 × 2.5 = 25.
  3. Calculate the statistic (without the correction for ties):

χ²F = [12 ÷ (n k (k + 1))] × ΣR² − 3n(k + 1) = 0.06 × 2804.5 − 150 = 18.27

  1. The one tied pair gives a correction factor of 0.99, and software reports 18.27 ÷ 0.99 = 18.45.
  2. Compare with χ² on k − 1 = 3 df (critical value 7.81): p = 0.0004. Kendall's W = 18.45 ÷ (10 × 3) = 0.62.

The Friedman test needs every patient to have every visit, and it handles only one within-patient factor. If it is significant, compare pairs of visits with Wilcoxon signed-rank tests and a correction for multiple testing.

Crossover trials

How does a crossover trial make each patient their own control?

Each patient receives both treatments, one in each period, in a randomly allocated order. The comparison is within patients, so the variation between patients does not enter the treatment comparison.

randomiseSequence ABDrug AwashoutDrug BSequence BADrug BwashoutDrug Acarryoverperiod 1period 2period effect: period 2 differs from period 1 whatever the drug
The 2 × 2 (AB/BA) crossover. CONSORT's crossover extension defines a washout as a length of time between treatment periods when no treatment is received, to allow the treatment to wear off. Carryover is when the effect of the first intervention persists into the second period. A period effect is when the outcome changes with time irrespective of treatment.

ICH E9 says the design reduces the number of subjects needed for a given power, sometimes markedly. It also sets the conditions: the disease should be chronic and stable, the effects of the medication should develop fully within the treatment period, and the washout should be long enough for the drug effect to reverse completely. Crossover does not suit curable conditions, outcomes such as death, or trials in which many patients are expected to drop out.

Worked example: a 2 × 2 crossover

Made-up teaching data. Systolic BP (mmHg) at the end of each 4-week period in 12 patients with hypertension.

SequencePeriod 1Period 2d = period 1 − period 2Total
AB (A then B)145148-3293
AB (A then B)157166-9323
AB (A then B)160162-2322
AB (A then B)135145-10280
AB (A then B)135138-3273
AB (A then B)137139-2276
BA (B then A)1491445293
BA (B then A)14713512282
BA (B then A)1531494302
BA (B then A)13111714248
BA (B then A)1661606326
BA (B then A)15213814290
  1. In sequence AB, d = (A − B) + (period 1 − period 2). In sequence BA, d = (B − A) + (period 1 − period 2). Subtracting the two cancels the period effect.
  2. Mean d: AB −4.83 (SD 3.66), BA 9.17 (SD 4.67). Pooled variance 17.57.
  3. Treatment effect A − B = (−4.83 − 9.17) ÷ 2 = −7.0 mmHg. SE = √[17.57 × (1/6 + 1/6)] ÷ 2 = 1.21.
  4. t = −7.0 ÷ 1.21 = −5.79 with 10 df, p = 0.0002. 95% CI −9.7 to −4.3 mmHg (critical t 2.228).
  5. Period effect (period 2 − period 1) = −(−4.83 + 9.17) ÷ 2 = −2.17 mmHg, p = 0.10.
  6. Carryover: compare each patient's total. AB mean 294.5, BA mean 290.2, difference 4.3 mmHg (95% CI −26.8 to 35.5), p = 0.76.

A − B = (mean dAB − mean dBA) ÷ 2 = −7.0 mmHg (95% CI −9.7 to −4.3)

A linear mixed model with treatment and period as fixed effects and a random intercept for each patient gives the same estimate and SE (−7.0, SE 1.21). The same 12 patients analysed with a paired t-test that ignores period also give −7.0 here, because both sequences have 6 patients, but the SE comes from 11 df and the period effect stays in the error. Analysing period 1 alone, as a parallel trial of 6 against 6 patients, gives −4.8 mmHg (95% CI −19.3 to 9.7), p = 0.48.

Why the carryover test cannot be relied on. Its CI above runs from −26.8 to 35.5 mmHg, because patient totals carry all the variation between patients. ICH E9 notes that in the 2 × 2 design carryover cannot be distinguished from the treatment × period interaction, and that the test for either lacks power. Freeman (1989) showed that the two-stage procedure (test for carryover, then use period 1 only if it is significant) gives actual significance levels higher than the nominal level, and concluded that it is too potentially misleading to be of practical use. Carryover is prevented by the design, with an adequate washout, not by a test.

Interactive

Add carryover and watch the treatment estimate and the carryover test

Carryover of drug A into period 2 biases the within-patient estimate by half the carryover. The test for carryover compares patient totals between the two sequences, so it has little power.

Try this: move the carryover to 8 mmHg. The within-patient estimate of drug A's effect moves from −7.0 towards zero, while the test for carryover stays far from significant.

Made-up teaching data from the worked example above: systolic BP in 12 patients with hypertension, 6 given drug A then drug B and 6 given drug B then drug A, 4 weeks each with a washout between. Negative numbers favour drug A.

0 mmHg

Extra fall in BP during drug B in the AB sequence, because drug A has not fully worn off

-7.0mmHg, A − B within patients (p < 0.001)
0.763p for the carryover test

Within-patient estimate -7.0 mmHg (95% CI -9.7 to -4.3). With no carryover this is the estimate from the worked example. The carryover test compares patient totals, which include all the variation between patients: difference +4.3 mmHg (95% CI -26.8 to 35.5). The first-period comparison is not affected by carryover, but it is a comparison between different patients: -4.8 mmHg, p = 0.475.

period effect (period 2 − period 1) -2.17 mmHg, p 0.104 · all tests 10 df

-20-15-10-50510−7.0 with no carryoverBoth periods,within each patient-7.0First period only(6 against 6 patients)-4.8Carryover test:patient totals, AB − BA4.3

Horizontal axis: mmHg. Bars: 95% confidence intervals.

Linear mixed models

What do random intercepts and random slopes mean?

A linear mixed model has fixed effects, which are the questions you ask (treatment, visit, their interaction), and random effects, which describe how patients differ from each other.

No patient effectone line for everyonevisitRandom interceptsown starting levelvisitIntercepts and slopesown level and own ratevisit
Middle: a random intercept gives each patient their own level. Right: random intercepts and random slopes. The model estimates the average line and the SD of patients around it. Adding a random slope also lets each patient change at their own rate. "Mixed" means the model contains both fixed and random effects.

Why a mixed model handles missing visits. It is fitted to every value that was recorded, one row per patient per visit. A patient seen at weeks 0 and 2 only still contributes those two values, and the random intercept links them to the rest of the patient's profile. The estimates are valid if the data are missing at random: whether a value is missing may depend on values already recorded (for example earlier pain), but not on the missing value itself after allowing for those. A repeated measures ANOVA keeps only patients with complete data, which is valid only if completers are a random subset of all patients.

The correlation between visits is chosen, not assumed away. A random intercept alone implies the same correlation between any two visits (compound symmetry). Other structures offered by software include first-order autoregressive, AR(1), where the correlation falls as visits get further apart, and unstructured, where every pair of visits has its own correlation.

Other advantages: visit times can differ between patients, time can be a continuous variable, baseline and other covariates can be added, and the output gives an estimate with a 95% CI for each effect. Laird and Ware (1982) described random-effects models that include both growth models and repeated-measures models as special cases, fitted to unbalanced data.

Interactive

Make patients with more pain leave early and compare completers with the mixed model

When dropout depends on earlier recorded values, the completers are no longer a random subset. The mixed model uses the earlier values of the patients who left.

Try this: move the cut-off to 100, where nobody leaves, and all three week 8 means agree. Move it back to 60. Patients with more pain leave, so the completers have less pain at week 8 than the whole group had. Compare how far the completers' mean and the mixed model's mean are from the true mean.

Made-up teaching data: pain score (0 to 100) in 20 patients at weeks 0, 2, 4 and 8. Rule: a patient whose pain is at or above the cut-off at week 2 or week 4 leaves the study before the next visit.

60

Lower cut-off: more patients leave

39.0week 8 mean, completers only (15 of 20)
42.9week 8 mean, mixed model (70 of 80 values)
43.1true week 8 mean of all 20

5 patients left early. A repeated measures ANOVA can use only the 15 completers, 60 values, and their week 8 mean is -4.1 points away from the true mean. The mixed model uses all 70 recorded values: patients who left still tell it how high their pain was at earlier visits, and its estimate is -0.2 points away.

mixed model: between-patient SD 9.7 · within-patient SD 5.7

020406080100week 0week 2week 4week 8painleave if at or above
true mean, all 20 patientscompleters onlymixed model

Thin lines: each patient's recorded values. Small open circles: values a patient would have had after leaving, which the study never sees. They are drawn only because the data are simulated.

GEE

Population-average or subject-specific: what is the difference between GEE and a mixed model?

Generalized estimating equations (GEE) model the average outcome in the population and correct the standard errors for correlation within patients. A mixed model describes the outcome for an individual patient with a given underlying level.

00.250.50.751probabilitynot exposedexposedaverage patient: 0.27 → 0.62population: 0.35 → 0.58each patient: OR 4.48population average: OR 2.49
Made-up illustration for a yes/no outcome: an exposure multiplies every patient's odds by 4.48, and patients differ in underlying risk (SD 2 on the log-odds scale). Averaging probabilities over patients flattens the effect: the population-average odds ratio is 2.49. A logistic mixed model reports the first number and GEE the second. Both are correct answers to different questions.

Zeger, Liang and Albert (1988) described the two approaches as subject-specific models, in which heterogeneity between subjects is modelled explicitly, and population-averaged models, in which the aggregate response for the population is the focus. For a continuous outcome analysed on its own scale, the two give the same fixed-effect estimates. For yes/no outcomes and counts they differ, as the figure shows.

  • Working correlation: the analyst chooses a structure. SPSS offers independent, AR(1), exchangeable, M-dependent and unstructured.
  • Standard errors: IBM's documentation states that the robust estimator provides a consistent estimate of the covariance even when the working correlation matrix is misspecified.
  • Use GEE when the question is about the population, for example how much a water intervention changes the proportion of children with diarrhoea each month.
  • Use a mixed model when the question is about an individual patient, or when patient-level variation is itself of interest.

Summary measures

Can one number per patient replace all the visits?

Often yes. Choose the summary that answers the clinical question, calculate it for each patient, then compare the summaries between groups with a simple test.

02040608012910419472week 057week 247week 450week 8AUC = 129 + 104 + 194 = 427427 ÷ 8 weeks = 53.4, the time-averaged pain
Area under the curve (AUC) for patient 1 of the teaching data, by the trapezium rule: each segment is the average of two neighbouring scores × the gap in weeks. (72 + 57) ÷ 2 × 2 = 129, (57 + 47) ÷ 2 × 2 = 104, (47 + 50) ÷ 2 × 4 = 194. The mean AUC of the 10 patients is 397.9 point-weeks.

Matthews and colleagues (1990) proposed this two-stage method: first calculate a suitable summary for each subject, such as a rate of change or an area under a curve, then analyse those summaries with simple statistical techniques as though they were raw data. ICH E9 lists a summary measure such as area under the curve as a way to avoid multiplicity with repeated measures.

  • Total or average exposure: AUC, or AUC ÷ duration (time-averaged value).
  • Rate of change: each patient's regression slope over time (fall in eGFR per year).
  • Peak or time to peak: highest drug concentration, time to lowest pain.
  • Final value adjusted for baseline: see the ANCOVA chapter.

Choose the summary in the protocol, before seeing the data. A summary chosen after looking at the curves is exploratory.

Decide

Which method fits your repeated measurements?

Answer the questions in order.

How were the repeated measurements collected?

Which method: all possible answers
  • Within-patient analysis of a 2 × 2 crossover: Compare each patient on the two treatments, with a term for period. Equivalent to a mixed model with treatment and period as fixed effects and patient as a random intercept.
  • Linear mixed model for the crossover: Fixed effects for treatment and period, random intercept for patient. Patients with one missing period still contribute.
  • Friedman test: Ranks each patient’s values across the visits. Needs complete data for every patient. For a model with groups and missing visits, use a mixed model on a suitable scale.
  • Repeated measures ANOVA: Check sphericity and report the Greenhouse-Geisser or Huynh-Feldt correction. A mixed model gives the same answers here and extends to missing data.
  • Linear mixed model: Uses every recorded value, handles unequal visit times, and gives valid estimates if the missing values are missing at random.
  • Summary measure: Calculate one number per patient (area under the curve, slope, peak), then compare those numbers with a t-test or Mann-Whitney test.
  • GEE (population-average model): Estimates how the proportion with the outcome differs across the whole population, with standard errors that allow for correlation within patients.
  • Generalised linear mixed model (subject-specific): A logistic model with a random intercept for each patient. Its odds ratio applies to an individual patient and is further from 1 than the GEE odds ratio.

Comparison

Three pairs residents confuse

Repeated measures ANOVA or linear mixed model?

FeatureRepeated measures ANOVALinear mixed model
Data it usesPatients with every visitEvery recorded value
Missing visitsPatient dropped (or value imputed)Used. Valid if missing at random
Visit timesSame planned visits for everyoneCan differ between patients. Time can be continuous
Correlation between visitsAssumes sphericity. Corrected with epsilonChosen structure: random intercept, AR(1), unstructured
OutputF tests for time, group and interactionEstimates with 95% CIs for each effect, plus F tests
Complete, balanced dataSame answers as the mixed model with compound symmetrySame answers as repeated measures ANOVA

Parallel group trial or crossover trial?

FeatureParallel group trialCrossover trial
Each patient receivesOne treatmentEvery treatment, in a random order
ComparisonBetween different patientsWithin each patient
Patients neededMoreFewer for the same power (ICH E9)
Time per patientOne treatment periodTwo or more periods plus washout
Suitable conditionsAny, including curable disease and outcomes such as deathChronic, stable disease with a treatment effect that reverses
Special problemsBaseline imbalance by chanceCarryover, period effects, a dropout loses both periods
AnalysisTwo-sample comparison or ANCOVAWithin-patient comparison with a period term

GEE or mixed model?

FeatureGEEMixed model
Question answeredAverage effect in the populationEffect for a patient with a given underlying level
Correlation within patientsWorking correlation plus corrected SEsRandom effects (and residual structure)
Yes/no outcome odds ratioCloser to 1 (population-average)Further from 1 (subject-specific)
Continuous outcome, identity linkSame fixed effectsSame fixed effects
Estimates patient variationNoYes, as variance components

The formula

Worked example: repeated measures ANOVA step by step

Made-up teaching data: pain score in 10 patients at weeks 0, 2, 4 and 8. Computed with Python (pingouin 0.6.1, SciPy 1.15.3).

PatientWeek 0Week 2Week 4Week 8Patient mean
17257475056.50
25642302638.50
35546313942.75
46249453748.25
58572727475.75
64939353038.25
75741292137.00
86053505755.00
97563687770.75
106661574156.25
Visit mean63.752.346.445.251.9
  1. Grand mean = 51.9. Total SS = Σ(value − 51.9)² = 9775.6.
  2. SS between patients = 4 × Σ(patient mean − 51.9)² = 6635.1, df 9.
  3. SS time = 10 × Σ(visit mean − 51.9)² = 2145.4, df 3, mean square 715.1.
  4. SS error = 9775.6 − 6635.1 − 2145.4 = 995.1, df 9 × 3 = 27, mean square 36.86.
  5. F = 715.1 ÷ 36.86 = 19.40 on (3, 27) df, p < 0.001.
  6. Mauchly W = 0.154, p = 0.01. Greenhouse-Geisser ε = 0.52: F(1.56, 14.04), p = 0.0002.
SourceSSdfMean squareFp
Between patients6635.19737.2
Time2145.43715.119.40< 0.001
Error995.12736.86
Total9775.639

The same scores in a one-way ANOVA that ignores patients: within-groups SS = 6635.1 + 995.1 = 7630.2 on 36 df, mean square 212.0, F = 3.37, p = 0.029. The Friedman test on the same data: χ²F = 18.45, 3 df, p = 0.0004.

In a real paper

Repeated measures in two published trials

Open-access paper · CC BY

Epstein AS, Liou KT, Romero SAD, Baser RE, Wong G, Xiao H, et al. Acupuncture vs massage for pain in patients living with advanced cancer: the IMPACT randomized clinical trial. JAMA Netw Open. 2023;6(11):e2342482.

The study: A pragmatic trial in 298 patients with advanced cancer and moderate to severe musculoskeletal pain, randomised to acupuncture or massage. Worst pain on the Brief Pain Inventory (0 to 10) was recorded at baseline and at weeks 4, 10, 14, 18, 22 and 26. Every patient contributed several correlated values, and some follow-up values were missing.

What the authors wrote
“A patient-level random intercept was included in the model to account for the repeated outcome measurements within patients. Linear mixed models provide valid inference under the reasonable assumption that missing follow-up data were missing at random.”
In plain words

Patient-level random intercept: each patient has their own usual pain level, so values from the same patient are linked. Repeated outcome measurements: up to seven pain scores per patient. Valid inference: correct estimates, CIs and p-values. Missing at random: whether a follow-up value is missing may depend on recorded information, such as earlier pain, but not on the missing value itself. That is why the authors did not impute missing values.

ReportedValueWhat it means
Patients enrolled298Each contributed up to 7 pain scores
Change to week 26, acupuncture−2.53 (95% CI −2.92 to −2.15)Worst pain fell by about 2.5 points
Change to week 26, massage−3.01 (95% CI −3.38 to −2.63)Worst pain fell by about 3 points
Difference between arms−0.48 (95% CI −0.98 to 0.03), P = .07The CI includes 0: no clear difference between the treatments
Check these when you read it
  • Is the model described fully: fixed effects (arm, week, arm × week) and random effects?
  • A random intercept alone assumes the same correlation between any two visits. Did the authors consider other structures?
  • How many patients had week 26 data, and is missing at random plausible for patients with advanced cancer?
  • The primary end point is the difference at week 26. Differences at other weeks are secondary.
Open-access paper · CC BY

Feil K, Adrion C, Boesch S, Doss S, Giordano I, Hengel H, et al. Safety and efficacy of acetyl-DL-leucine in certain types of cerebellar ataxia: the ALCAT randomized clinical crossover trial. JAMA Netw Open. 2021;4(12):e2135841.

The study: A double-blind, placebo-controlled 2-treatment, 2-period crossover trial in 108 patients with cerebellar ataxia, 54 per sequence: acetyl-DL-leucine then placebo, or placebo then the drug, 6 weeks each, separated by a 4-week washout. The outcome was the SARA ataxia score. The mixed model also had random intercepts for patients.

What the authors wrote
“As fixed effects we specified factor variables for treatment (acetyl-DL-leucine vs placebo), visit, and treatment period.”
In plain words

Fixed effects: the effects the model estimates and tests. Treatment: drug against placebo, the question of the trial. Visit: the scheduled assessments within each period. Treatment period: the term for period 1 against period 2, so that a change over time between periods is not mistaken for a drug effect.

ReportedValueWhat it means
Randomised108 (54 per sequence)Full analysis set 105 patients
Treatment difference in SARA change0.23 points (95% CI −0.40 to 0.85)No evidence that the drug was better than placebo
Period effect−0.25 points (95% CI −0.50 to 0.01), P = .06Scores were slightly lower in period 2 whatever the treatment
Check these when you read it
  • Is the washout (4 weeks here) justified from what is known about the drug?
  • Are results reported by period and sequence, with participant flow for each (CONSORT crossover items 13a and 15)?
  • Is the effect estimated within patients, with a period term?
  • Did the authors choose the analysis after a carryover test? That two-stage approach is not recommended.

Both articles: no retraction, correction or expression of concern found in PubMed, Europe PMC or scite (checked 15 September 2026). Europe PMC lists a commentary on ALCAT (J Neurol 2022).

Software

How to run it

Enter repeated measures in long format for mixed models and GEE (one row per patient per visit) and in wide format for SPSS GLM Repeated Measures (one row per patient, one column per visit).

SPSS

  • Repeated measures ANOVA: Analyze > General Linear Model > Repeated Measures. Type a within-subject factor name (week) and the number of levels (4), click Add, then Define and select the four visit columns. Mauchly's test is displayed automatically, with epsilon adjustments for the F test.
  • Friedman test: Analyze > Nonparametric Tests > Legacy Dialogs > K Related Samples, test type Friedman (Kendall's W and Cochran's Q are also offered).
  • Linear mixed model: Analyze > Mixed Models > Linear. Put the patient ID in Subjects and, for a residual structure, the visit in Repeated with a covariance type (for example AR(1), compound symmetry or unstructured). Then choose the dependent variable, factors, and the Fixed and Random effects.
  • GEE: Analyze > Generalized Linear Models > Generalized Estimating Equations. Choose the subject and within-subject variables and a working correlation matrix (independent, AR(1), exchangeable, M-dependent or unstructured).

R

# d: long format with columns id, week, pain
library(afex)
aov_ez("id", "pain", d, within = "week")   # Greenhouse-Geisser correction by default
friedman.test(pain ~ week | id, data = d)  # stats package

library(lme4); library(lmerTest)           # lmerTest adds Satterthwaite p-values
m <- lmer(pain ~ factor(week) + (1 | id), data = d)
summary(m)

library(geepack)                           # rows for each patient must be contiguous
g <- geeglm(pain ~ factor(week), id = id, data = d, corstr = "exchangeable")
summary(g)

# 2 x 2 crossover: x has one row per patient per period
lm(sbp ~ drug + period + factor(id), data = x)

jamovi

  • Repeated Measures ANOVA (jmv function anovaRM): tick the sphericity tests, and choose the Greenhouse-Geisser or Huynh-Feldt sphericity correction.
  • Repeated Measures ANOVA (non-parametric) (anovaRMNP) runs the Friedman test.
  • Mixed models need the GAMLj module: put the patient ID in the cluster variable and choose the random coefficients.

Reporting

How to report it

State the design, the number of patients and of measurements, the model, how the correlation within patients was handled, how missing data were handled, and the estimates with 95% CIs.

Repeated measures ANOVA

"Pain was measured in 10 patients at weeks 0, 2, 4 and 8 and analysed with one-way repeated measures ANOVA. Mauchly's test indicated that sphericity was violated (W = 0.15, χ²(5) = 14.42, p = 0.01), so the Greenhouse-Geisser correction was applied (ε = 0.52). Mean pain fell from 63.7 at week 0 to 45.2 at week 8, F(1.56, 14.04) = 19.40, p < 0.001."

2 × 2 crossover trial

"In a 2 × 2 crossover trial, 12 patients were randomised to drug A then B (n = 6) or B then A (n = 6). The treatment effect was estimated within patients with a term for period. Systolic BP was 7.0 mmHg lower on drug A than on drug B (95% CI 4.3 to 9.7; p < 0.001). The period effect was −2.2 mmHg (p = 0.10)."

Linear mixed model

"HbA1c at 3, 6, 9 and 12 months was analysed with a linear mixed model with treatment, visit and treatment × visit as fixed effects and a random intercept for each patient, fitted by restricted maximum likelihood. All recorded values were included, assuming data missing at random."

CONSORT extension for randomised crossover trials (2019), item 12a

"Statistical methods used to compare groups for primary and secondary outcomes which are appropriate for crossover design (that is, based on within participant comparison)."

CONSORT crossover extension, item 17a

"For each primary and secondary outcome, results including estimated effect size and its precision (such as 95% confidence interval) should be based on within participant comparisons."

CONSORT 2025, item 21c

Added to the checklist: how missing data were handled in the analysis.

By specialty

Repeated measures problems by specialty

Heart rate recorded at 1, 5, 10, 15 and 30 minutes after induction with two induction agents. Readings close in time are more alike than readings far apart.

Sphericity is unlikely. Report the Greenhouse-Geisser correction, or use a mixed model with a correlation that falls with distance.

Common myths

Common mistaken beliefs

  • Myth: 40 measurements from 10 patients give a sample of 40.

    They give 10 patients. Values from one patient are correlated, and the effective sample size lies between 10 and 40, depending on the intraclass correlation.

  • Myth: A t-test at each visit shows when the groups start to differ.

    Matthews and colleagues (1990) called this approach flawed: it can fail to answer the clinical question and can be statistically invalid. Use one model with a group × time interaction, or a summary measure.

  • Myth: If Mauchly's test is not significant, sphericity holds.

    The test has low power in small samples. Report epsilon and the corrected p-value, whatever the test shows.

  • Myth: Test for carryover first, then choose the crossover analysis.

    Freeman (1989) showed that this two-stage analysis inflates the false-positive rate. The EMA bioequivalence guideline states that a test for carryover is not considered relevant. Prevent carryover with an adequate washout.

  • Myth: A mixed model makes missing data harmless.

    It gives valid estimates when data are missing at random. If patients drop out because of values that were never recorded, a mixed model is biased too. Plan sensitivity analyses.

  • Myth: GEE and a logistic mixed model estimate the same odds ratio.

    GEE estimates a population-average odds ratio, which is closer to 1. The mixed model estimates a subject-specific odds ratio. In the illustration above: 2.49 against 4.48.

Why this matters to you

Five consequences of analysing repeated measures wrongly

  1. A significant result that is not real

    Treating 64 values from 16 patients as 64 patients made p = 0.002 out of a difference the mixed model gives p = 0.13 for.

  2. A real change that is missed

    Ignoring the patients left 6635.1 of the 7630.2 error sum of squares in the one-way ANOVA, and F fell from 19.40 to 3.37.

  3. Patients lost from the analysis

    Repeated measures ANOVA drops everyone with a missed visit. In a thesis with dropouts, the completers may be the patients who did well.

  4. Questions at the viva

    "How did you handle sphericity?", "What was the washout?" and "Why did you not use a mixed model?" need answers written into the protocol.

  5. Misreading papers

    A crossover trial analysed as two independent groups, or a population-average odds ratio read as the effect in one patient, leads to wrong clinical conclusions.

History

History of repeated measures methods

  1. 1937

    Milton Friedman

    Published "The use of ranks to avoid the assumption of normality implicit in the analysis of variance" in the Journal of the American Statistical Association.

  2. 1940

    John W. Mauchly

    Published a significance test for sphericity of a normal n-variate distribution in the Annals of Mathematical Statistics.

  3. 1959

    Samuel W. Greenhouse and Seymour Geisser

    In "On methods in the analysis of profile data" (Psychometrika), presented approximate analysis of variance procedures, including an adjustment to the degrees of freedom resulting in conservative F tests.

  4. 1965

    J. E. Grizzle

    Published "The two-period change-over design and its use in clinical trials" (Biometrics), which first proposed a two-stage procedure for analysing such trials.

  5. 1976

    Huynh Huynh and Leonard S. Feldt

    Showed that the sample estimate of the Box correction factor ε is seriously biased when ε is not low, and proposed an alternative estimate that is less biased for moderately large ε.

  6. 1982

    N. M. Laird and J. H. Ware

    Described random-effects models for longitudinal data (Biometrics) that include growth models and repeated-measures models as special cases.

  7. 1986

    Kung-Yee Liang and Scott L. Zeger

    Published "Longitudinal data analysis using generalized linear models" in Biometrika.

  8. 1988

    S. L. Zeger, K. Y. Liang and P. S. Albert

    Distinguished subject-specific and population-averaged models for longitudinal data and fitted both with a generalized estimating equation approach.

  9. 1989

    P. R. Freeman

    Examined the two-stage analysis of two-treatment, two-period crossover trials and concluded that it is too potentially misleading to be of practical use.

  10. 1990

    J. N. S. Matthews, D. G. Altman, M. J. Campbell and P. Royston

    In the BMJ, recommended analysing serial measurements with summary measures, such as a rate of change or an area under a curve, calculated for each subject.

  11. 2019

    Kerry Dwan, Tianjing Li, Douglas G. Altman and Diana Elbourne

    Published the CONSORT extension for randomised crossover trials in the BMJ.

Guidelines

Repeated measures and crossover trials in guidelines

ICH E9 (1998), section 3.1.2, crossover design

"The chief difficulty concerns carryover, that is, the residual influence of treatments in subsequent treatment periods." "The washout periods should be sufficiently long for complete reversibility of drug effect." "The crossover design should generally be restricted to situations where losses of subjects from the trial are expected to be small."

ICH E9 (1998), section 5.6

Methods to avoid or reduce multiplicity include "the use of a summary measure such as ‘area under the curve’ (repeated measures)".

EMA Guideline on the investigation of bioequivalence (CPMP/EWP/QWP/1401/98 Rev. 1, 2010)

"If two formulations are compared, a randomised, two-period, two-sequence single dose crossover design is recommended." "Normally at least 5 elimination half-lives are necessary" for the washout. "A test for carry-over is not considered relevant and no decisions regarding the analysis (e.g. analysis of the first period only) should be made on the basis of such a test."

CONSORT crossover extension (2019), item 3a

"Rationale for a crossover design."

Reading a paper

Five checks on repeated measures in any paper

  • Do the authors state how many patients there were, and not only how many measurements?
  • For repeated measures ANOVA, is sphericity addressed and the corrected degrees of freedom or epsilon reported?
  • How were missing visits handled: complete cases, imputation, or a mixed model assuming missing at random?
  • In a crossover trial: is the washout justified, is the analysis within patients with a period term, and was the analysis chosen without a carryover pre-test?
  • For a yes/no outcome, is the odds ratio population-average (GEE) or subject-specific (mixed model), and is it interpreted accordingly?

Why is it called that?

Word surgery

“Random”

In everyday speech

Haphazard, without a plan.

In research

In a random effect, each patient’s own level is treated as drawn from a population of patients, and the model estimates how much patients vary.

“Sphericity”

In everyday speech

Roundness, like a ball.

In research

Equal variances of the differences between every pair of repeated measurements.

“Carryover”

In everyday speech

Something left over from before.

In research

The effect of the treatment in period 1 persisting into period 2 of a crossover trial.

Memory trick

Same patients, complete visits: repeated measures ANOVA with an epsilon correction. Missing visits: mixed model. Skewed scores: Friedman. Both treatments in each patient: crossover with a period term. Yes/no outcome for the population: GEE.

Sphericity

sphere: Latin sphaera, from Greek sphaira, "globe, ball"

When the variances of all the pairwise differences are equal, the transformed data have a round (spherical) spread, with no direction longer than another.

Variance

Latin variantia, from variare, "to change"

The average squared deviation from the mean. Repeated measures ANOVA divides it into between-patient, time and error parts.

Mixed model

mixed: Latin mixtus, past participle of miscere, "to mix, mingle, blend"

A model that contains both fixed effects and random effects.

Longitudinal

Medieval Latin longitudinalis, from Latin longitudo

A longitudinal study follows the same people over a length of time, so it produces repeated measures.

Crossover

everyday meaning: crossing from one side to the other

Patients cross from one treatment to the other at the end of the first period.

Exam answers

Model answer outlines

Crossover trials: design, washout, carryover, analysis, advantages and disadvantages

MD Community Medicine 2015 · DM Virology 2025 · MD Pharmacology 2015
  1. Definition: a randomised trial in which each participant receives two or more treatments in sequence, in a random order, so that each participant acts as their own control (ICH E9).
  2. 2 × 2 (AB/BA) design: randomise to sequence AB or BA, treatment period 1, washout, treatment period 2.
  3. Washout: a time between periods with no treatment, to let the first treatment wear off. For bioequivalence studies, normally at least 5 elimination half-lives (EMA, 2010).
  4. Carryover: the effect of the first treatment persists into period 2. It biases the treatment comparison and in the 2 × 2 design cannot be separated from the treatment × period interaction. Prevent it by design, not by a pre-test (Freeman, 1989).
  5. Period effect: the outcome changes between periods whatever the treatment. It is removed by including period in the analysis.
  6. Analysis: within-patient differences, d = period 1 − period 2. Treatment effect = (mean dAB − mean dBA) ÷ 2, two-sample t-test on the d values. Equivalent mixed model: treatment and period fixed, patient random.
  7. Worked example: 12 patients, systolic BP. A − B = −7.0 mmHg (95% CI −9.7 to −4.3), p = 0.0002. Period effect −2.2 mmHg, p = 0.10.
  8. Suitable for: chronic stable conditions (hypertension, asthma, chronic pain, epilepsy), treatments with a rapid, reversible effect, bioequivalence studies.
  9. Advantages: variation between patients removed from the comparison, fewer patients for the same power, every patient receives the active treatment.
  10. Disadvantages: carryover, period effects, longer participation, a dropout loses data from both periods, unsuitable for curable or progressive diseases and outcomes such as death.
  11. Reporting: CONSORT extension for crossover trials (2019): rationale for a crossover design (item 3a), within-participant analysis (12a, 17a), flow by sequence and period (13a).

Differences between parallel trials and crossover trials

MD Community Medicine 2021
FeatureParallel group trialCrossover trial
Treatment per patientOneAll, in random sequence
ControlA different group of patientsThe same patient in another period
Variation between patientsIn the errorRemoved from the comparison
Sample sizeLargerSmaller for the same power
Duration per patientOne periodTwo periods plus washout
ConditionsAny, including acute and curable diseaseChronic, stable disease, reversible treatment effect
Outcomes such as death or curePossibleNot possible
Specific biasesChance baseline imbalanceCarryover, period effect
DropoutsLose one patient's outcomeLose both periods of that patient
AnalysisTwo-sample t-test, ANCOVAWithin-patient analysis with a period term
ExampleNew anticoagulant against warfarin for stroke preventionTwo antihypertensives for 4 weeks each

Value of crossover designs in drug trials

MD Pharmacology 2011
  • Efficiency: each patient is their own control, so fewer patients are needed for a given power (ICH E9). Useful when patients are scarce, as in rare chronic diseases.
  • Bioequivalence: the standard design for comparing a generic and a reference formulation is a randomised two-period, two-sequence single-dose crossover (EMA, 2010), analysed by ANOVA with terms for sequence, subject within sequence, period and formulation.
  • Early-phase pharmacology: dose comparisons and pharmacokinetic studies in healthy volunteers, where carryover on the pharmacokinetic variable is unlikely with a sufficient washout (ICH E9).
  • Symptomatic treatment of chronic stable disease: analgesics, antihypertensives, bronchodilators, where the effect appears and disappears within the period.
  • Patient acceptability: every participant receives the active drug in one period.
  • Limits: not for curative drugs, drugs with long-lasting effects, progressive disease, or trials with many expected dropouts. Carryover must be avoided by design. Adverse events in period 2 can be hard to attribute (ICH E9).

The one thing to remember

Count patients, not measurements: analyse repeated values with a method that knows which values came from the same patient.

All worked examples and interactive elements use made-up numbers for teaching. Statistics were computed in Python (SciPy 1.15.3, statsmodels 0.14.5, pingouin 0.6.1). Software steps were checked against the IBM SPSS Statistics documentation, CRAN reference manuals (afex, lme4, lmerTest, geepack), the R stats documentation, and the jamovi and GAMLj documentation on 15 September 2026.

Sources: Epstein AS et al. JAMA Netw Open 2023;6(11):e2342482 (doi:10.1001/jamanetworkopen.2023.42482, PMID 37962891). Feil K et al. JAMA Netw Open 2021;4(12):e2135841 (doi:10.1001/jamanetworkopen.2021.35841, PMID 34905009). Matthews JNS, Altman DG, Campbell MJ, Royston P. BMJ 1990;300(6719):230–5 (doi:10.1136/bmj.300.6719.230, PMID 2106931). Friedman M. J Am Stat Assoc 1937;32(200):675–701 (doi:10.1080/01621459.1937.10503522). Mauchly JW. Ann Math Stat 1940;11(2):204–9 (doi:10.1214/aoms/1177731915). Greenhouse SW, Geisser S. Psychometrika 1959;24(2):95–112 (doi:10.1007/BF02289823). Grizzle JE. Biometrics 1965;21:467–80 (PMID 14338679). Huynh H, Feldt LS. J Educ Stat 1976;1(1):69–82 (doi:10.3102/10769986001001069). Laird NM, Ware JH. Biometrics 1982;38(4):963–74 (PMID 7168798). Liang KY, Zeger SL. Biometrika 1986;73(1):13–22 (doi:10.1093/biomet/73.1.13). Zeger SL, Liang KY, Albert PS. Biometrics 1988;44(4):1049–60 (PMID 3233245). Freeman PR. Stat Med 1989;8(12):1421–32 (doi:10.1002/sim.4780081202, PMID 2616932). Dwan K, Li T, Altman DG, Elbourne D. CONSORT 2010 statement: extension to randomised crossover trials. BMJ 2019;366:l4378 (doi:10.1136/bmj.l4378, PMID 31366597). Hopewell S et al. CONSORT 2025 statement. BMJ 2025;389:e081123. ICH E9 Statistical Principles for Clinical Trials, 1998. EMA Guideline on the investigation of bioequivalence, CPMP/EWP/QWP/1401/98 Rev. 1/Corr, 20 January 2010.

Past papers

TNMGRMU questions on repeated measures and mixed models

Questions from MD, MS, DM, MCh and Ph.D. papers that this chapter helps you answer. Tap a sitting to open the university's own question paper.

  1. ×2Cross over TrialsMD Community Medicine · Apr 2015MD Community Medicine · Apr 2015
  2. ×1Cross-over study designDM Virology · Feb 2025
  3. ×1Explain the differences between ‘parallel trials’ and ‘cross-over trials’MD Community Medicine · Jul 2021
  4. ×1Cross over design drug trialsMD Pharmacology · Apr 2015
  5. ×1Value of crossover design trials in drug trialsMD Pharmacology · May 2011