BCompare groups · Guide test 158
Box M test
Tests equality of covariance matrices across groups, usually under multivariate normality.
Do it in CodeSplash
In the app, set it up in Analyze with this method:
- Box's M test of equal covariance matrices — Do the groups share the same covariance matrix of several variables?
In Box's M test of equal covariance matrices, choose Reference distribution = F (Box 1949) or choose Reference distribution = χ² (Box 1949).
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 · Box M test
Above 1 the later groups are more spread out (unequal covariance matrices).
Your data
Simulated with known truth3 groups on two measurements; crosses mark the group means, dashed ellipses each group's 2-SD covariance.
If H₀ were true
- The reference: how χ² varies across samples when H₀ is true (Box's χ² approximation).
- Your statistic, from the data above.
- The p-value: the area at least as extreme as yours (p = .119).
- The hatched rejection region at α = .050: statistics landing here reject H₀.
The formula
With your numbers
- covariance matrix of group g
- pooled covariance matrix
- Box's small-sample correction
The verdict
χ²(6) = 10.13, p = .119
p > α = .050: compatible with H₀
Box's M is very sensitive to non-normality: with large groups it rejects for trivial differences. Pillai's trace is the usual remedy, not a decision rule.
- Statistic
- 10.134
- p-value
- 0.1191
Box M test on 3 groups of 20 rows on two variables: χ²(6) = 10.13, p = .119. The p-value is above α = .050, so the data are compatible with H₀.
Question and hypotheses
H0: k multivariate populations have identical covariance matrices.
Assumptions
Independent multivariate normal groups; each covariance estimable and nonsingular; adequate group sizes.
Formula
Parameters and notation
Sp=Σ(nj−1)Sj/(N−k); c=[Σ1/(nj−1)−1/(N−k)](2p²+3p−1)/[6(p+1)(k−1)].
Structure of the method
Estimate covariance matrices within groups and a pooled covariance, then contrast their log determinants with sample-size weights. Apply the stated finite-sample correction and chi-square or documented F approximation for covariance homogeneity.
Estimated and nuisance parameters
Each group mean and covariance is estimated; pooled covariance weights reflect group residual degrees of freedom. No mean-equality restriction is tested, and covariance differences are not neural hyperparameters.
Settings and design choices
Specify groups, response variables, correction method, alpha and missing-data handling. A tiny chosen alpha may reduce sensitivity to mild departures but does not make the normality-based test robust. Covariance regularization changes its distribution.
Fitting and adaptation
Refit group and pooled covariances for each dataset and ensure every group matrix is estimable and positive definite. If using simulation, reproduce group sizes and the fitted common-covariance null. There is no neural adaptation. Avoid using a preliminary nonsignificant result as proof that a later pooled-covariance procedure is justified; inspect covariance estimates directly.
Sensitivity and robustness
Box’s M is sensitive to nonnormal tails and outliers, particularly with unbalanced groups. Groups with n no larger than p produce singular estimates. A rejection may reflect shape/normality violations as well as covariance heterogeneity, and very large samples can detect differences too small to matter scientifically.
How to use and calibrate
Use (1−c)M~χ²[(k−1)p(p+1)/2] approximately, or a documented F correction.
Example application
Assess covariance homogeneity before interpreting a classical multigroup multivariate model.
Interpretation and pitfalls
Watch out
Very sensitive to nonnormality; nonsignificance does not prove equal covariance. Small/singular groups need other methods.
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
Box M tests covariance equality; normality sensitivity can make it unsuitable as a mechanical gate for MANOVA.
Not run — Python launcher syntax checked; R backend runtime not verified · needs Python standard library + Rscript; R packages: heplots
# 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)
X<-matrix(rnorm(120),ncol=3);Y<-matrix(rnorm(150,mean=.3),ncol=3)
print(heplots::boxM(rbind(X,Y),factor(rep(1:2,c(nrow(X),nrow(Y))))))
"""
# 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()
Not run — Syntax checked; runtime not verified in the final environment · needs heplots
set.seed(2026)
X<-matrix(rnorm(120),ncol=3);Y<-matrix(rnorm(150,mean=.3),ncol=3)
print(heplots::boxM(rbind(X,Y),factor(rep(1:2,c(nrow(X),nrow(Y))))))
Sources
- heplots — heplots · boxMAuthor documentation/source reviewed: heplots 1.8.6.search.r-project.org
- boxMsearch.r-project.org
- Statistics guide v4 (historical):
- Python: Python launcher syntax checked; R backend runtime not verified · R: Syntax checked; runtime not verified in the final 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 158, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT158.