Tutorials › Multivariate Statistics (Graduate) › Box’s M Test For Two Covariance Matrices

Covariance Matrix Inference · Tutorial 251 of 975

Box’s M Test For Two Covariance Matrices

Learn to compute and calibrate Box’s M for testing whether two independent Gaussian groups share a covariance matrix.

Intermediate 10 min read

What You'll Learn

  • State the null and alternative hypotheses for equality of two covariance matrices
  • Form the pooled covariance matrix from two equal-sized groups
  • Express Box’s M using the three relevant covariance determinants
  • Derive the statistic from the likelihood ratio for Wishart scatter matrices
  • Apply the two-group finite-sample correction and chi-square degrees of freedom
  • Interpret the test’s assumptions, approximation, and rejection rule

Why Compare Covariance Matrices?

Two populations can have the same mean vector and still differ in how their variables vary together. For example, two clinical groups might have similar average biomarker levels but different variability or correlation between biomarkers. Box’s M test addresses a specific question: do two independent multivariate Gaussian groups have the same covariance matrix?

Here the focus is the equal-sample-size case. The statistic compares each group’s sample covariance determinant with the determinant of their pooled covariance matrix. Its null calibration is an approximation, not an exact chi-square distribution.

Definition: Suppose two independent groups each contain \(n\) observations on \(p\) variables. For group \(i\), let \(S_i\) be its usual unbiased sample covariance matrix, based on deviations from that group’s sample mean. The pooled covariance matrix is $$ S_p=\frac{(n-1)S_1+(n-1)S_2}{2(n-1)}=\frac{S_1+S_2}{2}. $$ Box’s M statistic is $$ M=2(n-1)\log|S_p|-(n-1)\log|S_1|-(n-1)\log|S_2|. $$

The hypotheses are \(H_0:\Sigma_1=\Sigma_2\) against \(H_A:\Sigma_1\ne\Sigma_2\), where \(\Sigma_i\) is the population covariance matrix for group \(i\). The determinant measures generalized variance: it reflects joint spread across all \(p\) dimensions, including dependence among variables. Consequently, Box’s M compares overall covariance structure, not just separate marginal variances.

For the usual nonsingular setting, assume each group is a random sample from a \(p\)-variate normal population, the two samples are independent, and \(n>p\). Then \(S_1\) and \(S_2\) are positive definite with probability one, so their determinants and logarithms are defined. The pooled matrix is positive definite as well.

Determinant Form and Likelihood-Ratio Basis

Write \(\nu=n-1\), the degrees of freedom for each group’s sample covariance matrix. The statistic can be written compactly as $$ M=2\nu\log|S_p|-\nu\log|S_1|-\nu\log|S_2| =\nu\log\left(\frac{|S_p|^2}{|S_1||S_2|}\right). $$ This form makes clear that Box’s M is large when the pooled determinant substantially exceeds the geometric mean of the two group determinants.

The likelihood-ratio basis can be stated using the within-group scatter matrices \(W_i=\nu S_i\). Under multivariate normal sampling, these are independent Wishart scatter matrices with \(\nu\) degrees of freedom. Under the alternative, each group has its own covariance estimate \(S_i\); under the null, the common estimate is \(S_p=(W_1+W_2)/(2\nu)\). In the ratio of maximized Wishart likelihoods, the trace terms cancel: at each fitted covariance, the fitted trace contribution is \(p\) times its degrees-of-freedom total. What remains is the determinant contrast in \(M\).

Result: For positive-definite \(S_1\) and \(S_2\), \(M\ge 0\), with equality exactly when \(S_1=S_2\).

To verify this, use the concavity of the log determinant on positive-definite matrices: $$ \log\left|\frac{S_1+S_2}{2}\right| \geq \frac{1}{2}\log|S_1|+\frac{1}{2}\log|S_2|. $$ Multiplying both sides by \(2\nu>0\) gives \(M\geq0\). The log determinant is strictly concave on positive-definite matrices, so equality holds exactly when \(S_1=S_2\). Thus the statistic cannot be negative; a negative computed value signals a calculation or numerical-precision problem. \(\square\)

Worked Example: Opposing Variability Across Two Variables

Two independent groups each have \(n=10\) observations on \(p=2\) variables. Suppose their sample covariance matrices are $$ S_1=\begin{pmatrix}4&0\\0&1\end{pmatrix}, \qquad S_2=\begin{pmatrix}1&0\\0&4\end{pmatrix}. $$ Find \(M\).

The pooled matrix and determinants are $$ S_p=\frac{S_1+S_2}{2} =\begin{pmatrix}2.5&0\\0&2.5\end{pmatrix}, \qquad |S_p|=6.25,\quad |S_1|=|S_2|=4. $$ Since \(n-1=9\), $$ M=18\log(6.25)-9\log(4)-9\log(4) =18\log\left(\frac{6.25}{4}\right) =18\log(1.5625)\approx8.033. $$ The determinants of the two group matrices match, but their high-variance directions differ. Pooling them produces a larger determinant, which is why \(M\) is positive.

Finite-Sample Correction and Null Calibration

The raw statistic \(M\) is not generally calibrated directly by a chi-square distribution in finite samples. For two equal-sized groups, the standard Box correction is a multiplicative adjustment. Define $$ c=\frac{2p^2+3p-1}{4(p+1)(n-1)}. $$ The corrected statistic is \(M_c=(1-c)M\). Under the null hypothesis, it is approximately chi-square with \(p(p+1)/2\) degrees of freedom. The degrees of freedom count the distinct entries in a symmetric \(p\times p\) covariance matrix: \(p\) diagonal entries and \(p(p-1)/2\) distinct off-diagonal entries.

Result: For two independent \(p\)-variate normal samples of equal size \(n\), the Box-corrected statistic is $$ M_c=(1-c)M,\qquad c=\frac{2p^2+3p-1}{4(p+1)(n-1)}. $$ Under \(H_0:\Sigma_1=\Sigma_2\), the null calibration is approximately $$ M_c\ \dot{\sim}\ \chi^2_{p(p+1)/2}. $$ At significance level \(\alpha\), reject \(H_0\) when \(M_c\) exceeds the \(1-\alpha\) quantile of this chi-square distribution.

The correction specializes the general Box factor to two groups with equal sample sizes. In the general factor, the sample-size term is \(\sum_i 1/(n_i-1)-1/\sum_i(n_i-1)\), and the group-count term is \(g-1\), where \(g\) is the number of groups. With \(g=2\) and \(n_1=n_2=n\), the sample-size term becomes $$ \frac{1}{n-1}+\frac{1}{n-1}-\frac{1}{2(n-1)} =\frac{3}{2(n-1)}. $$ Multiplying this by \((2p^2+3p-1)/(6(p+1)(g-1))\), with \(g-1=1\), gives exactly \(c=(2p^2+3p-1)/(4(p+1)(n-1))\). This verifies the equal-size correction used here.

For instance, when \(p=2\), the degrees of freedom are \(2(3)/2=3\), and the correction is \(c=13/[12(n-1)]\). The test uses the upper tail because large values indicate that the two group covariance matrices fit poorly with a common covariance. The chi-square calibration is an approximation; it does not make the finite-sample distribution exactly chi-square.

Worked Example: Apply the Correction and Make a Decision

Continue with the matrices from the first example, where \(n=10\) and \(p=2\). We found \(M\approx8.033\). The correction factor is $$ c=\frac{2(2^2)+3(2)-1}{4(2+1)(10-1)} =\frac{13}{108}\approx0.1204. $$ Thus $$ M_c=\left(1-\frac{13}{108}\right)8.033 =\frac{95}{108}(8.033)\approx7.066. $$ At \(\alpha=0.05\), the upper 5% critical value of \(\chi^2_3\) is approximately \(7.815\). Since \(7.066<7.815\), this test does not reject equality of the covariance matrices at the 5% level. This conclusion is not proof that the matrices are equal; it says the observed statistic does not exceed the chosen approximate critical value.

Worked Example: Different Overall Scales

Suppose two independent groups have \(n=8\) observations each on two variables, with $$ S_1=I_2,\qquad S_2=4I_2. $$ Then \(S_p=2.5I_2\), so \(|S_1|=1\), \(|S_2|=16\), and \(|S_p|=6.25\). Here \(2(n-1)=14\), and $$ M=14\log(6.25)-7\log(1)-7\log(16) =14\log\left(\frac{6.25}{4}\right) =14\log(1.5625)\approx6.248. $$ For \(p=2\), the correction is \(c=13/[4(3)(7)]=13/84\). Therefore $$ M_c=\frac{71}{84}(6.248)\approx5.281, \qquad df=3. $$ Both groups have the same correlation structure, but their covariance matrices differ in scale. Equality of covariance matrices requires both scale and dependence structure to agree.

Worked Example: Pooling Off-Diagonal Covariances

Consider two groups of size \(n=6\), each measured on two variables: $$ S_1=\begin{pmatrix}2&1\\1&2\end{pmatrix}, \qquad S_2=\begin{pmatrix}2&-1\\-1&2\end{pmatrix}. $$ Each determinant is \(2(2)-1^2=3\). The pooled matrix is $$ S_p=\frac{S_1+S_2}{2} =\begin{pmatrix}2&0\\0&2\end{pmatrix}, \qquad |S_p|=4. $$ There are \(n-1=5\) degrees of freedom per group, so $$ M=10\log(4)-5\log(3)-5\log(3) =10\log(4/3)\approx2.877. $$ The correction is \(c=13/[4(3)(5)]=13/60\), giving $$ M_c=\frac{47}{60}(2.877)\approx2.254. $$ The pooled off-diagonal entry is zero because the group covariances have opposite signs. Comparing only the two determinants would miss this difference in covariance structure.

Interpretation and Common Pitfall

Box’s M is useful when an analysis requires a common covariance matrix across two groups, because it gives a formal check of that equality assumption. Its interpretation depends on the model: the samples should be independent, and the multivariate normal assumption supports both the Wishart likelihood basis and the stated calibration. Strong departures from normality can make the chi-square approximation unreliable.

Common mistake: comparing determinants alone. It is tempting to conclude that the covariance matrices are equal whenever \(|S_1|=|S_2|\). Equal determinants only mean equal generalized variances; they do not imply equal matrices. For example, the first worked example has equal group determinants but different covariance matrices. Box’s M uses the determinant of the pooled matrix as well, so it detects the mismatch in directions of variability. Another error is to treat the chi-square reference distribution as exact: it is an approximation after the finite-sample correction.

Key takeaway: For two independent, equal-sized Gaussian groups, compute the pooled covariance matrix, form the determinant contrast \(M\), multiply by the Box correction \(1-c\), and compare with an upper-tail chi-square distribution having \(p(p+1)/2\) degrees of freedom.

Check Your Understanding

Use the definitions and calibration above to answer these questions.

  1. For two groups of equal size \(n\), write the pooled covariance matrix in terms of \(S_1\) and \(S_2\).
  2. Why can equal determinants \(|S_1|=|S_2|\) fail to establish equality of covariance matrices?
  3. For \(p=3\), what are the chi-square degrees of freedom used to calibrate the corrected statistic?
  4. Which direction of the chi-square distribution is used for the rejection rule, and why?
  5. What sampling assumptions support the Box’s M null calibration?
Clinical Biostats