METHOD GUIDE
Repeated Measures ANOVA in R
Long Data, Corrections and Mixed Models
Three things decide whether the table can be trusted: data in long format, an error term that names the participant, and a package whose printout states which epsilon adjustment it applied. Each is checked before the F is read.
IN SHORT
What the Model Compares and Where R Needs a Package
Repeated measures ANOVA compares the mean of one continuous outcome across several conditions or occasions measured on the same participants, and removes stable differences between participants from the error term. To run repeated measures ANOVA in R, arrange the data in long format with a participant factor, fit the within-subjects ANOVA in R with aov() and an Error() term or with a package such as rstatix or afex that also reports sphericity, and read the corrected rows when sphericity is in doubt. The method needs complete data for each participant, and a mixed model is often the better choice when data are missing or unevenly timed. OnlineSPSS, a specialist statistical consultancy for academic, clinical and professional research, carries out and reviews this analysis through an in-house PhD-level statistician.
ANALYSIS SUPPORT
Analysis Support for This Method
The choice between this ANOVA, a rank-based alternative and a mixed model depends on the design and on missing data, and it is made before a package is chosen.
Repeated Measures ANOVA
The within-subjects comparison for your design, with the epsilon adjustment, the follow-up comparisons and the wording settled before the analysis starts.
Linear Mixed Models (Multilevel Modeling)
A model for repeated or clustered observations that keeps participants with incomplete data and allows uneven timing, for designs the ANOVA handles poorly.
BEFORE YOU RUN IT
Data Shape and Design Before the First aov() Call
Most trouble in R's repeated measures output starts upstream, where the layout, the participant identifier and the number of complete cases are set.
Long Format With a Participant Factor Each row is one participant at one level of the condition, with the identifier stored as a factor. A numeric identifier is read as a covariate and the error structure is then wrong.
A Condition, Not a Trend Variable A condition or time point stored as a number is fitted with one degree of freedom as a linear slope. Convert it with factor() when levels are compared, and use contrasts for a planned trend.
Complete Data per Participant Most repeated measures functions drop a participant who lacks any one level. Count how many were lost and whether the loss relates to the outcome, since a mixed model can use every available observation.
Outcome Scale and Order An ordinal outcome is better served by the Friedman Test. Conditions that were not counterbalanced confound order and practice with the condition.
IN R
How to Run a Repeated Measures ANOVA in R
The mean model is base R with aov(), but a sphericity correction in R comes from packages such as rstatix or afex, whose defaults differ, so the package, its version and the correction are named.
- Confirm the design: one continuous outcome measured at every level of a within-subjects factor.
- Check long format with table(d$id, d$cond), and convert id and cond with factor().
- Plot individual trajectories or the distribution at each level.
- Fit aov(y ~ cond + Error(id/cond), data = d), or rstatix::anova_test(data = d, dv = y, wid = id, within = cond) for the sphericity output.
- Read Mauchly’s test and the epsilon values, then take the corrected rows if sphericity is in doubt.
- Follow up with pairwise comparisons under a stated adjustment, and add an effect size such as generalized eta squared.
READING THE OUTPUT
Strata, Mauchly's Test and the Corrected Rows
Base aov() prints separate error strata without a sphericity test, whereas rstatix and afex print the tests and corrections that the report has to match.
| Output element | What it tells you | What to check |
|---|---|---|
| Error: id stratum (aov) | The variation between participants, with its own Residuals line | That it is not read as a test of the condition |
| Error: id:cond stratum (aov) | The condition effect tested against within-participant error, with Df, F value and Pr(>F) | That the residual Df equals levels minus 1 times participants minus 1 in a balanced design |
| ANOVA table (rstatix): Effect, DFn, DFd, F, p and ges | The uncorrected test, with generalized eta squared in the ges column | That ges is named and not described as partial eta squared |
| Mauchly’s Test for Sphericity | A test of equal variances of the differences between levels, with W and p | That it informs the choice and is not a switch, since its power depends on sample size |
| Sphericity Corrections: GGe and HFe | Epsilon estimates, where GGe is the Greenhouse-Geisser epsilon, with corrected p-values p[GG] and p[HF] | That epsilon multiplies both degrees of freedom and the corrected values are the ones reported |
| Package default correction | A correction applied without a request, which differs between packages and versions | That the correction actually used is read from the printout and named |
| Pairwise comparisons table | Differences between levels with adjusted p-values | That the comparisons are paired and the adjustment is named |
REPORTING
Reporting F, Corrected Degrees of Freedom and Effect
The report needs the correction as well as the F, because corrected and uncorrected degrees of freedom belong to different p-values.
Write F(df1, df2) = ___, p = ___, ges = ___, with the degrees of freedom exactly as printed after any correction, and say which correction was applied and the epsilon = ___ behind it. Give the mean and standard deviation at each level, the number of participants with complete data and the number dropped. Name the effect size, since generalized eta squared from rstatix and afex is not partial eta squared and the values differ. Report the follow-up as differences with 95% CI [___, ___] and an adjusted p, naming the adjustment. Describe a time effect as change within participants, and keep to that wording unless the design includes a comparison condition.
COMMON MISTAKES
Within-Subjects Reports That Draw Reviewer Queries
Several of these arise because a long-format data frame looks like ordinary cross-sectional data, and R fits it without complaint.
Uncorrected Rows Reported Base aov() prints no correction, so its table gets reported by default even when sphericity is doubtful. The report states which row was used and why.
Independent Tests as Follow-Up The function pairwise.t.test() treats levels as independent unless paired = TRUE is set. Ignoring the participant structure gives follow-up p-values that do not match the design.
Group Factor Left Out When participants belong to groups, fitting only the within-subjects factor ignores the question the study asked. A mixed design adds the between-subjects factor and its interaction with time.
Time Treated as Categories Only When occasions are spaced unevenly, unordered categories discard the spacing, and a mixed model with time as a numeric variable describes the trend more directly.
Rows Counted as Participants A pooled linear model fitted to long data treats each row as an independent case and inflates the apparent sample. Degrees of freedom follow participants, not rows.
Several Rows in One Cell When a participant has more than one row at a level, such as trials not yet averaged, some packages average them with only a warning and others fail or misread the design. The aggregation is done deliberately before fitting and reported.
Unsure which row of the table to quote? Independent Statistical Review checks which row is quoted, the epsilon and the follow-up against the printout.
FREQUENTLY ASKED QUESTIONS
Questions About Sphericity and Packages in R
The answers explain what aov() leaves out, which correction a package may have applied unasked, and how follow-up tests should treat the error term.
Why does aov() with Error() in R print no sphericity test?
Base aov() fits the error strata and reports the uncorrected F tests, and it has no sphericity test or correction built in. For Mauchly’s test and corrected rows, use a package such as rstatix or afex, or compare the model with a mixed model that does not rely on sphericity. Record the package and version, because the printed tables differ between them.
Which epsilon adjustment did my package apply without my asking?
Read it from the printout, because defaults differ between packages and versions. At the versions documented at the time of writing, afex applies a correction by default, and rstatix chooses automatically in get_anova_table() with correction = “auto”, correcting the factors for which Mauchly’s test is significant. Name the correction in the methods and quote its degrees of freedom.
Should follow-up tests use a pooled error term or separate paired tests?
When sphericity is doubtful, separate paired comparisons are usually the safer choice, because a pooled error term assumes that all the differences between levels have equal variance. Packages differ in which approach they take by default, so the choice is checked in the documentation and named in the methods with the adjustment used.
How would a mixed model be judged against the ANOVA for my incomplete data?
An in-house PhD-level statistician can assess the pattern of missing occasions and the timing of the measurements, advise which model fits the design, and carry out the analysis on your data. When the model is chosen and only the tables remain, Results Reporting & Interpretation is the service for setting them out. Conclusions stay with you.
How do you protect my research data and confidentiality?
Your data and project details are handled confidentially, and project information is not published. Researcher names and institutions are not used publicly without permission. An NDA is available where required and can be arranged before sensitive materials are shared. Read more about confidentiality and data security.
What happens when I request an assessment, and how long does it take?
You share your research question, design and relevant materials, such as the dataset or the output you have, and a statistically trained Research Coordinator reviews the request and responds the same day. The analysis, deliverables, timeline and one fixed project fee are then confirmed before any work begins, so the timeline follows from the agreed scope.
Still have a question? Find more answers in our full FAQ.
NEXT STEP
Not Sure the ANOVA
or a Mixed Model Fits Your Data?
Whether the ANOVA can stay, or a mixed model should replace it, depends on who is missing and at which occasion. A statistically trained Research Coordinator reads the request first, and the agreed analysis is carried out by an in-house statistician.
No Commitment Required
Strictly Confidential
Fixed Project Fee
In-House PhD-Level Statisticians
Same-Day Response
Serving Researchers Since 2014