boxtest performs Box test of equality of covariance matrices
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.
Box test for Iris data displaying results.out
=boxtest(Y
,
group
,
Name, Value
)
load iris data
load fisheriris % Compute Box test of equality of covariance matrices out=boxtest(meas,species);
load iris data
load fisheriris % Compute Box test of equality of covariance matrices out=boxtest(meas,species,'dispresults',true);
***************************************************************** Test of homogeneity of covariances (without correction factor) 1.466632492125116e+02 LRchi2approx = Chi2 approximation of Box test of homogeneity of covariances 1.409430499234975e+02 p value of the Chi2 approximation of Box test 3.352034178317562e-20 *****************************************************************
load iris data
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) 1.466632492125116e+02 LRchi2approx = Chi2 approximation of Box test of homogeneity of covariances 1.409430499234975e+02 p value of the Chi2 approximation of Box test 3.352034178317562e-20 LRFapprox = F approximation of Box test of homogeneity of covariances 7.045261695711880 p value of the F approximation of Box test 3.578106019823562e-20 ***************************************************************** out = struct with fields: LR: 1.466632492125116e+02 LRchi2approx: 1.409430499234975e+02 LRchi2approx_pval: 3.352034178317562e-20 LRFapprox: 7.045261695711880 LRFapprox_pval: 3.578106019823562e-20 Spl: [4×4 double]
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.
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: Numeric vector | logical vector | character array | cell
array of character vectors | string array.
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
.
'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
out
— description
StructureStructure 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.
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.