Skip to content

BCompare groups · Guide test 160

Mauchly sphericity test

Tests the covariance restriction needed by conventional univariate repeated measures ANOVA.

Runs in CodeSplashPython (calls R) example not runR example validated

Do it in CodeSplash

In the app, set it up in Analyze with one of these methods:

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

15
4
0.30
1.0
2.50

1 keeps every difference between conditions equally variable (sphericity).

0.050

Your data

Drag a value; each column is a condition
Condition 1mean 0.28Condition 2mean 0.05Condition 3mean 1.36Condition 4mean 1.68

If H₀ were true

χ² = 8.43
  1. The reference: how χ² varies across samples when H₀ is true (χ² approximation).
  2. Your statistic, from the data above.
  3. The p-value: the area at least as extreme as yours (p = .135).
  4. The hatched rejection region at α = .050: statistics landing here reject H₀.

The formula

W=∣C⊤SC∣(tr⁡(C⊤SC)/(k−1))k−1,χ2=−(n−1) ρ ln⁡WW = \dfrac{|\mathbf C^{\top}\mathbf S\mathbf C|}{\bigl(\operatorname{tr}(\mathbf C^{\top}\mathbf S\mathbf C)/(k-1)\bigr)^{k-1}},\qquad \chi^2 = -(n-1)\,\rho\,\ln W

With your numbers

W=0.52,χ2=8.43, df=5W = 0.52,\qquad \chi^2 = 8.43,\ df = 5
C\mathbf C
orthonormal contrasts between the k conditions
S\mathbf S
covariance matrix of the conditions
WW
1 under sphericity, smaller when it fails
ρ\rho
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 H0.

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

W=∣Sc∣[tr⁡(Sc)/q]qX2=−ν[1−2q2+q+26qν]log⁡W\begin{gathered}W=\frac{|S_c|}{[\operatorname{tr}(S_c)/q]^q}\\[5pt] X^2=-\nu\left[1-\frac{2q^2+q+2}{6q\nu}\right]\log W\end{gathered}

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.

Python · invokes R

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()
R

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

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.