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.
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.
How much one patient's usual HbA1c differs from another's
How much one patient's value varies from visit to visit
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
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.
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.
- 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.
- 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.
- 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.
- 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.
- 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.
Every pair of visits has this correlation
1.0 means the spread is the same at every visit
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.
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.
- 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.
- 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.
- 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
- The one tied pair gives a correction factor of 0.99, and software reports 18.27 ÷ 0.99 = 18.45.
- 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.
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.
| Sequence | Period 1 | Period 2 | d = period 1 − period 2 | Total |
|---|---|---|---|---|
| AB (A then B) | 145 | 148 | -3 | 293 |
| AB (A then B) | 157 | 166 | -9 | 323 |
| AB (A then B) | 160 | 162 | -2 | 322 |
| AB (A then B) | 135 | 145 | -10 | 280 |
| AB (A then B) | 135 | 138 | -3 | 273 |
| AB (A then B) | 137 | 139 | -2 | 276 |
| BA (B then A) | 149 | 144 | 5 | 293 |
| BA (B then A) | 147 | 135 | 12 | 282 |
| BA (B then A) | 153 | 149 | 4 | 302 |
| BA (B then A) | 131 | 117 | 14 | 248 |
| BA (B then A) | 166 | 160 | 6 | 326 |
| BA (B then A) | 152 | 138 | 14 | 290 |
- 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.
- Mean d: AB −4.83 (SD 3.66), BA 9.17 (SD 4.67). Pooled variance 17.57.
- Treatment effect A − B = (−4.83 − 9.17) ÷ 2 = −7.0 mmHg. SE = √[17.57 × (1/6 + 1/6)] ÷ 2 = 1.21.
- 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).
- Period effect (period 2 − period 1) = −(−4.83 + 9.17) ÷ 2 = −2.17 mmHg, p = 0.10.
- 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.
Extra fall in BP during drug B in the AB sequence, because drug A has not fully worn off
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
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.
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.
Lower cut-off: more patients leave
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
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.
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.
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?
| Feature | Repeated measures ANOVA | Linear mixed model |
|---|---|---|
| Data it uses | Patients with every visit | Every recorded value |
| Missing visits | Patient dropped (or value imputed) | Used. Valid if missing at random |
| Visit times | Same planned visits for everyone | Can differ between patients. Time can be continuous |
| Correlation between visits | Assumes sphericity. Corrected with epsilon | Chosen structure: random intercept, AR(1), unstructured |
| Output | F tests for time, group and interaction | Estimates with 95% CIs for each effect, plus F tests |
| Complete, balanced data | Same answers as the mixed model with compound symmetry | Same answers as repeated measures ANOVA |
Parallel group trial or crossover trial?
| Feature | Parallel group trial | Crossover trial |
|---|---|---|
| Each patient receives | One treatment | Every treatment, in a random order |
| Comparison | Between different patients | Within each patient |
| Patients needed | More | Fewer for the same power (ICH E9) |
| Time per patient | One treatment period | Two or more periods plus washout |
| Suitable conditions | Any, including curable disease and outcomes such as death | Chronic, stable disease with a treatment effect that reverses |
| Special problems | Baseline imbalance by chance | Carryover, period effects, a dropout loses both periods |
| Analysis | Two-sample comparison or ANCOVA | Within-patient comparison with a period term |
GEE or mixed model?
| Feature | GEE | Mixed model |
|---|---|---|
| Question answered | Average effect in the population | Effect for a patient with a given underlying level |
| Correlation within patients | Working correlation plus corrected SEs | Random effects (and residual structure) |
| Yes/no outcome odds ratio | Closer to 1 (population-average) | Further from 1 (subject-specific) |
| Continuous outcome, identity link | Same fixed effects | Same fixed effects |
| Estimates patient variation | No | Yes, 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).
| Patient | Week 0 | Week 2 | Week 4 | Week 8 | Patient mean |
|---|---|---|---|---|---|
| 1 | 72 | 57 | 47 | 50 | 56.50 |
| 2 | 56 | 42 | 30 | 26 | 38.50 |
| 3 | 55 | 46 | 31 | 39 | 42.75 |
| 4 | 62 | 49 | 45 | 37 | 48.25 |
| 5 | 85 | 72 | 72 | 74 | 75.75 |
| 6 | 49 | 39 | 35 | 30 | 38.25 |
| 7 | 57 | 41 | 29 | 21 | 37.00 |
| 8 | 60 | 53 | 50 | 57 | 55.00 |
| 9 | 75 | 63 | 68 | 77 | 70.75 |
| 10 | 66 | 61 | 57 | 41 | 56.25 |
| Visit mean | 63.7 | 52.3 | 46.4 | 45.2 | 51.9 |
- Grand mean = 51.9. Total SS = Σ(value − 51.9)² = 9775.6.
- SS between patients = 4 × Σ(patient mean − 51.9)² = 6635.1, df 9.
- SS time = 10 × Σ(visit mean − 51.9)² = 2145.4, df 3, mean square 715.1.
- SS error = 9775.6 − 6635.1 − 2145.4 = 995.1, df 9 × 3 = 27, mean square 36.86.
- F = 715.1 ÷ 36.86 = 19.40 on (3, 27) df, p < 0.001.
- Mauchly W = 0.154, p = 0.01. Greenhouse-Geisser ε = 0.52: F(1.56, 14.04), p = 0.0002.
| Source | SS | df | Mean square | F | p |
|---|---|---|---|---|---|
| Between patients | 6635.1 | 9 | 737.2 | ||
| Time | 2145.4 | 3 | 715.1 | 19.40 | < 0.001 |
| Error | 995.1 | 27 | 36.86 | ||
| Total | 9775.6 | 39 |
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
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.
doi:10.1001/jamanetworkopen.2023.42482 · PMID 37962891 · Free full text (PMC10646731)
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.
“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.”
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.
| Reported | Value | What it means |
|---|---|---|
| Patients enrolled | 298 | Each 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 = .07 | The CI includes 0: no clear difference between the treatments |
- 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.
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.
doi:10.1001/jamanetworkopen.2021.35841 · PMID 34905009 · Free full text (PMC8672236)
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.
“As fixed effects we specified factor variables for treatment (acetyl-DL-leucine vs placebo), visit, and treatment period.”
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.
| Reported | Value | What it means |
|---|---|---|
| Randomised | 108 (54 per sequence) | Full analysis set 105 patients |
| Treatment difference in SARA change | 0.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 = .06 | Scores were slightly lower in period 2 whatever the treatment |
- 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."
"Statistical methods used to compare groups for primary and secondary outcomes which are appropriate for crossover design (that is, based on within participant comparison)."
"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."
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.
HbA1c every 3 months for a year on two oral drugs. Some patients miss the 9-month visit.
A repeated measures ANOVA drops every patient with a missed visit. A linear mixed model uses all recorded values.
A generic and a reference tablet compared in healthy volunteers, each volunteer taking both.
The standard bioequivalence design is a randomised two-period, two-sequence crossover, with a washout usually of at least 5 elimination half-lives (EMA, 2010).
HAM-D scores weekly for 8 weeks. Patients whose depression is not improving stop attending.
Dropout depends on earlier scores. A mixed model is valid if the data are missing at random. Analysing completers alone overstates improvement.
Height of children on growth hormone measured every 3 months, at slightly different ages.
Each child has a starting height and a growth rate. A mixed model with random intercepts and random slopes describes both.
Haemoglobin at 20, 28 and 36 weeks of pregnancy in women given oral or intravenous iron.
The question is whether the change over time differs between groups: the group × time interaction, not three separate t-tests.
Whether each child had diarrhoea in each month of a year, in villages with and without a water intervention.
For a population-level proportion, GEE gives the population-average odds ratio with standard errors that allow for repeated months per child.
Pain scores at 6, 12, 24 and 48 hours after two analgesic regimens, with no missing values.
If the question is total pain over 48 hours, compare each patient’s area under the curve between groups.
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
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.
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.
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.
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.
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
- 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.
- 1940
John W. Mauchly
Published a significance test for sphericity of a normal n-variate distribution in the Annals of Mathematical Statistics.
- 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.
- 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.
- 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 ε.
- 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.
- 1986
Kung-Yee Liang and Scott L. Zeger
Published "Longitudinal data analysis using generalized linear models" in Biometrika.
- 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.
- 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.
- 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.
- 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
"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."
Methods to avoid or reduce multiplicity include "the use of a summary measure such as ‘area under the curve’ (repeated measures)".
"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."
"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”
Haphazard, without a plan.
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”
Roundness, like a ball.
Equal variances of the differences between every pair of repeated measurements.
“Carryover”
Something left over from before.
The effect of the treatment in period 1 persisting into period 2 of a crossover trial.
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- 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 (AB/BA) design: randomise to sequence AB or BA, treatment period 1, washout, treatment period 2.
- 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).
- 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).
- Period effect: the outcome changes between periods whatever the treatment. It is removed by including period in the analysis.
- 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.
- 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.
- Suitable for: chronic stable conditions (hypertension, asthma, chronic pain, epilepsy), treatments with a rapid, reversible effect, bioequivalence studies.
- Advantages: variation between patients removed from the comparison, fewer patients for the same power, every patient receives the active treatment.
- Disadvantages: carryover, period effects, longer participation, a dropout loses data from both periods, unsuitable for curable or progressive diseases and outcomes such as death.
- 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| Feature | Parallel group trial | Crossover trial |
|---|---|---|
| Treatment per patient | One | All, in random sequence |
| Control | A different group of patients | The same patient in another period |
| Variation between patients | In the error | Removed from the comparison |
| Sample size | Larger | Smaller for the same power |
| Duration per patient | One period | Two periods plus washout |
| Conditions | Any, including acute and curable disease | Chronic, stable disease, reversible treatment effect |
| Outcomes such as death or cure | Possible | Not possible |
| Specific biases | Chance baseline imbalance | Carryover, period effect |
| Dropouts | Lose one patient's outcome | Lose both periods of that patient |
| Analysis | Two-sample t-test, ANCOVA | Within-patient analysis with a period term |
| Example | New anticoagulant against warfarin for stroke prevention | Two 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.
- ×2Cross over Trials
- ×1Cross-over study design
- ×1Explain the differences between ‘parallel trials’ and ‘cross-over trials’
- ×1Cross over design drug trials
- ×1Value of crossover design trials in drug trials