BCompare groups · Guide test 160
Mauchly sphericity test
Tests the covariance restriction needed by conventional univariate repeated measures ANOVA.
Do it in CodeSplash
In the app, set it up in Analyze with one of these methods:
- Mixed (split-plot) ANOVA — one between, one within factor — Do groups differ, do conditions differ, and do the groups change differently across conditions?
- Repeated-measures ANOVA (one within factor) — Do the means differ across conditions measured on the same subjects?
Do it in CodeSplash Run this test on your own data, in Python or R.
Bench
Change the design, drag the data, move α. The statistic, its reference distribution and the verdict follow.
Bench · Mauchly sphericity test
1 keeps every difference between conditions equally variable (sphericity).
Your data
Drag a value; each column is a conditionIf H₀ were true
- The reference: how χ² varies across samples when H₀ is true (χ² approximation).
- Your statistic, from the data above.
- The p-value: the area at least as extreme as yours (p = .135).
- The hatched rejection region at α = .050: statistics landing here reject H₀.
The formula
With your numbers
- orthonormal contrasts between the k conditions
- covariance matrix of the conditions
- 1 under sphericity, smaller when it fails
- Box's correction factor
The verdict
χ²(5) = 8.43, p = .135, W = 0.52
p > α = .050: compatible with H₀
Effect size: Mauchly's W (1 = spherical) W = 0.515
Low power in small samples and oversensitive in large ones: many analysts apply a Greenhouse–Geisser correction whatever Mauchly says.
- Statistic
- 8.434
- p-value
- 0.1349
Mauchly sphericity test on Condition 1: n = 15; Condition 2: n = 15; Condition 3: n = 15; Condition 4: n = 15: χ²(5) = 8.43, p = .135, W = 0.52. The p-value is above α = .050, so the data are compatible with H₀.
Question and hypotheses
H0: covariance on the repeated-measures contrast space is proportional to identity (sphericity).
Assumptions
Independent multivariate normal subjects; covariance of orthonormal within-subject contrasts is estimable.
Formula
Parameters and notation
q is contrast-space dimension, Sc its covariance, ν covariance residual df; reference df=q(q+1)/2−1.
Structure of the method
Project repeated outcomes onto the intended within-subject contrast space, estimate covariance there and compare its determinant with the arithmetic mean of its eigenvalues raised to the contrast dimension. Sphericity requires equal contrast-space eigenvalues, not necessarily compound symmetry of raw outcomes.
Estimated and nuisance parameters
Estimate subject-level multivariate model coefficients and the covariance of orthonormal contrasts. The covariance residual degrees of freedom and contrast rank determine the correction; the common proportionality scale cancels from W.
Settings and design choices
Specify within-subject design, contrast space, covariance target, alpha and approximation order. The R implementation includes a higher-order correction, so its p-value need not equal a hand calculation using only the displayed first-order chi-square approximation.
Fitting and adaptation
Refit the multivariate model and contrast covariance when subjects or conditions change. Adaptation means redefining the estimable contrast space and recalibrating degrees of freedom, not neural fine-tuning. For outcome inference, consider a prespecified Greenhouse–Geisser/Huynh–Feldt correction or an appropriate covariance model rather than gating validity solely on this preliminary test.
Sensitivity and robustness
With only two repeated levels the one-dimensional contrast space is automatically spherical and the usual nontrivial test is unnecessary. Few subjects, missing data, nonnormality and dependence between subjects reduce validity. Nonsignificance has low evidential value in small samples and does not certify uncorrected repeated-measures ANOVA.
How to use and calibrate
Use the corrected chi square approximation. If sphericity is doubtful, use an appropriate df correction or covariance model for outcome tests.
Example application
Check the sphericity assumption for three or more repeated conditions.
Interpretation and pitfalls
Watch out
Low power is common in small samples. A preliminary nonsignificant Mauchly test is not proof that uncorrected repeated-measures ANOVA is safe.
What changed in edition 2
- New sections: structure of the method, estimated and nuisance parameters, settings and design choices, fitting and adaptation, sensitivity and robustness.
Python and R
Repeated-measures columns. Tests covariance sphericity in the contrast space; this is not Bartlett’s identity-correlation test.
Not run — Executed end to end through Rscript · needs Python standard library + Rscript; R packages: base R
# Python launcher for the complete R implementation below.
# Requires Rscript on PATH and the listed R packages.
import shutil
import subprocess
rscript = shutil.which("Rscript")
if rscript is None:
raise RuntimeError("Install R and make Rscript available on PATH.")
r_code = r"""
set.seed(2026)
b <- matrix(rnorm(36)+rep(c(0,.3,.7),each=12),nrow=12,ncol=3)
print(mauchly.test(lm(b~1),X=~1))
"""
# No shell interpolation. A failed R execution raises an error in Python.
result = subprocess.run([rscript, "--vanilla", "-"], input=r_code,
text=True, capture_output=True)
print(result.stdout)
if result.stderr:
print(result.stderr)
result.check_returncode()
Validated — Executed successfully in the validation environment · needs Base/standard library
set.seed(2026)
b <- matrix(rnorm(36)+rep(c(0,.3,.7),each=12),nrow=12,ncol=3)
print(mauchly.test(lm(b~1),X=~1))
Output
Mauchly's test of sphericity Contrasts orthogonal to ~1 data: SSD matrix from lm(formula = b ~ 1) W = 0.98443, p-value = 0.9246
Sources
- R Mauchly sphericity teststat.ethz.ch
- mauchly.teststat.ethz.ch
- Statistics guide v4 (historical):
- Python: Executed end to end through Rscript · R: Executed successfully in the validation environment
- Reference's record:
- Edition 2 review: Python: skip · R: not executed (Rscript unavailable); why not run: Python: Python-to-R bridge; Rscript is unavailable. R code was not executed. Python: Not run in the reference's review: Python-to-R bridge; Rscript is unavailable. R code was not executed. R: Reviewed but not run: R wasn't available to the reference's authors.
From the CodeSplash statistics guide (v4), entry 160, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT160.