# boxtest

boxtest performs Box test of equality of covariance matrices

## Syntax

• out=boxtest(Y,group)example
• out=boxtest(Y,group,Name,Value)example

## Description

Box test is used to determine whether two or more covariance matrices are equal. Note that Box test is sensitive to departures from normality. If the samples come from non-normal distributions, then Box test may simply be testing for non-normality.

 out =boxtest(Y, group) Box test for Iris data.

 out =boxtest(Y, group, Name, Value) Box test for Iris data displaying results.

## Examples

expand all

### Box test for Iris data.

load fisheriris
% Compute Box test of equality of covariance matrices
out=boxtest(meas,species);

### Box test for Iris data displaying results.

load fisheriris
% Compute Box test of equality of covariance matrices
out=boxtest(meas,species,'dispresults',true);
*****************************************************************
Test of homogeneity of covariances (without correction factor)
146.6632

LRchi2approx = Chi2 approximation of Box test of homogeneity of covariances
140.9430

p value of the Chi2 approximation of Box test
3.3520e-20

*****************************************************************


## Related Examples

expand all

### Box test for Iris with option Fapprox.

load fisheriris
% Compute Box test of equality of covariance matrices
out=boxtest(meas,species,'dispresults',true,'Fapprox',true)
*****************************************************************
Test of homogeneity of covariances (without correction factor)
146.6632

LRchi2approx = Chi2 approximation of Box test of homogeneity of covariances
140.9430

p value of the Chi2 approximation of Box test
3.3520e-20

LRFapprox = F approximation of Box test of homogeneity of covariances
7.0453

p value of the F approximation of Box test
3.5781e-20

*****************************************************************

out =

struct with fields:

LR: 146.6632
LRchi2approx: 140.9430
LRchi2approx_pval: 3.3520e-20
LRFapprox: 7.0453
LRFapprox_pval: 3.5781e-20
Spl: [4×4 double]



## Input Arguments

### Y — Input data. Matrix.

n x v data matrix. n observations and v variables. Rows of Y represent observations, and columns represent variables. Missing values (NaN's) and infinite values (Inf's) are allowed, since observations (rows) with missing or infinite values will automatically be excluded from the computations.

Data Types: single | double

### group — Grouping variable. Numeric vector | logical vector | character array | cell array of character vectors.

group is a grouping variable defined as a categorical variable, vector, character array, or cell array of character vectors. Two observations are in the same group if they have the same value in the group array. The observations in each group represent a sample from a population.

Data Types: single| double

### Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as  Name1,Value1,...,NameN,ValueN.

Example:  'Fapprox',true , 'dispresults',true 

### Fapprox —Test based on F approximation.boolean.

If Fapprox is true, the asymptotic F distribution of the value of Box test is also computed. On the other hand is Fapprox is false (default) just the chi2 approximation is computed.

Example:  'Fapprox',true 

Data Types: logical

### dispresults —Display results.boolean.

If dispresults is true, the value of the test and the associated p-value will be shown on the screen. On the other hand is dispresults is false (default) nothing is shown on the screen.

Example:  'dispresults',true 

Data Types: logical

## Output Arguments

### out — description Structure

Structure which contains the following fields

Value Description
LR

scalar which contains Box test (uncorrected) for equality of covariances.

This is -2ln M (see 'More About section' for the definition of M).

LRchi2approx

scalar which contains Box test (corrected) for equality of covariances. This version is called $\chi^2$ approximation of the Box test.

This is $-2(1-c_1)\ln M$ (see further details for the definition of $c_1$ and $M$). This value must be compared with a $\chi^2$ with $0.5v(v+1)(g-1)$ degrees of freedom.

LRchi2approx_pval

scalar which contains the p-value of $\chi^2$ approximation of Box test of homogeneity of covariances.

LRFapprox

scalar which contains the $F$ approximation of Box test of homogeneity of covariances. This field is given just if input option Fapprox is true.

LRFapprox_pval

scalar which contains the p-value of $F$ approximation of Box test of homogeneity of covariances. This field is given just if input option Fapprox is true.

Spl

pooled variance covariance matrix.

We assume independent samples of size $n_1$, $n_2$, $\ldots$, $n_g$ from a $v$-multivariate normal distribution. The hypothesis of equality of covariances is:

$H_0= \Sigma_1 = \Sigma_2 = \ldots = \Sigma_g$

To make the test we calculate:

$M=\frac{ |S_1|^{n_1-1} |S_2|^{n_2-1} \ldots |S_g|^{n_g-1} }{|S_{pl}|^{\sum_{i=1}^g n_i-1} }$

where $S_i$ is the covariance matrix of group $i$ and $S_{pl}$ is the pooled sample covariance matrix. It is clear that we must have $n_i-1>v$ otherwise $|S_i|=0$ for some $i$ and $M$ would be zero. The statistic $M$ is a modification of the likelihood ratio test and varies between 0 and 1 with values near 1 favouring $H_0$ and values near 0 leading to the rejection of $H_0$ (see Rencher (2002) p. 256 for further details). The quantity $-2 \ln M$ is approximately distributed as a $\chi^2$ distribution and is given in $\mbox{out.LR}$. The quantity $-2(1-c_1) \ln M$ (where $c_1$ is a small sample correction factor) is usually called correct Box test and is approximately distributed as a $\chi^2$ with $0.5 (g-1) v(v+1)$ degrees of freedom. We reject $H_0$ if $$-2(1-c_1) \ln M >\chi^2_{1-\alpha}$$ where $\chi^2_{1-\alpha}$ is the $1-\alpha$ quantile. The value of this test is contained in $\mbox{out.LRchi2approx}$ and the corresponding p-value of this test is given in $\mbox{out.LRchi2approx_pval}$.

Box also derived and F approximation to the test. This test is computed just if input option Fapprox is true. The value of this last test and the corresponding p-values are given in $\mbox{out.LRFapprox}$ and $\mbox{LRFapprox_pval}$.

WARNING: if the absolute value of the determinant of the covariance matrix of any group is less than 1e-40, a missing value for LR test is reported.

## References

Mardia, K.V., J.T. Kent, and J.M. Bibby (1979), "Multivariate Analysis," Academic Press, London, pp. 140. [MKB].

Rencher A.C. (2002), "Methods of Multivariate Analysis", 2nd edition, Wiley, New York, pp. 280-284.