PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_mv_discrim (g03da)
Purpose
nag_mv_discrim (g03da) computes a test statistic for the equality of within-group covariance matrices and also computes matrices for use in discriminant analysis.
Syntax
[
nig,
gmn,
det,
gc,
stat,
df,
sig,
ifail] = g03da(
x,
isx,
nvar,
ing,
ng, 'n',
n, 'm',
m, 'wt',
wt)
[
nig,
gmn,
det,
gc,
stat,
df,
sig,
ifail] = nag_mv_discrim(
x,
isx,
nvar,
ing,
ng, 'n',
n, 'm',
m, 'wt',
wt)
Note: the interface to this routine has changed since earlier releases of the toolbox:
At Mark 24: |
weight was removed from the interface; wt was made optional |
Description
Let a sample of
observations on
variables come from
groups with
observations in the
th group and
. If the data is assumed to follow a multivariate Normal distribution with the variance-covariance matrix of the
th group
, then to test for equality of the variance-covariance matrices between groups, that is,
, the following likelihood-ratio test statistic,
, can be used;
where
and
are the within-group variance-covariance matrices and
is the pooled variance-covariance matrix given by
For large
,
is approximately distributed as a
variable with
degrees of freedom, see
Morrison (1967) for further comments. If weights are used, then
and
are the weighted pooled and within-group variance-covariance matrices and
is the effective number of observations, that is, the sum of the weights.
Instead of calculating the within-group variance-covariance matrices and then computing their determinants in order to calculate the test statistic, nag_mv_discrim (g03da) uses a decomposition. The group means are subtracted from the data and then for each group, a decomposition is computed to give an upper triangular matrix . This matrix can be scaled to give a matrix such that . The pooled matrix is then computed from the matrices. The values of and the can then be calculated from the diagonal elements of and the .
This approach means that the Mahalanobis squared distances for a vector observation
can be computed as
, where
,
being the vector of means of the
th group. These distances can be calculated by
nag_mv_discrim_mahal (g03db). The distances are used in discriminant analysis and
nag_mv_discrim_group (g03dc) uses the results of
nag_mv_discrim (g03da) to perform several different types of discriminant analysis. The differences between the discriminant methods are, in part, due to whether or not the within-group variance-covariance matrices are equal.
References
Aitchison J and Dunsmore I R (1975) Statistical Prediction Analysis Cambridge
Kendall M G and Stuart A (1976) The Advanced Theory of Statistics (Volume 3) (3rd Edition) Griffin
Krzanowski W J (1990) Principles of Multivariate Analysis Oxford University Press
Morrison D F (1967) Multivariate Statistical Methods McGraw–Hill
Parameters
Compulsory Input Parameters
- 1:
– double array
-
ldx, the first dimension of the array, must satisfy the constraint
.
must contain the th observation for the th variable, for and .
- 2:
– int64int32nag_int array
-
indicates whether or not the
th variable in
x is to be included in the variance-covariance matrices.
If
the th variable is included, for ; otherwise it is not referenced.
Constraint:
for
nvar values of
.
- 3:
– int64int32nag_int scalar
-
, the number of variables in the variance-covariance matrices.
Constraint:
.
- 4:
– int64int32nag_int array
-
indicates to which group the th observation belongs, for .
Constraint:
, for
The values of
ing must be such that each group has at least
nvar members.
- 5:
– int64int32nag_int scalar
-
The number of groups, .
Constraint:
.
Optional Input Parameters
- 1:
– int64int32nag_int scalar
-
Default:
the dimension of the array
ing and the first dimension of the array
x. (An error is raised if these dimensions are not equal.)
, the number of observations.
Constraint:
.
- 2:
– int64int32nag_int scalar
-
Default:
the dimension of the array
isx and the second dimension of the array
x. (An error is raised if these dimensions are not equal.)
The number of variables in the data array
x.
Constraint:
.
- 3:
– double array
-
The dimension of the array
wt
must be at least
if
, and at least
otherwise
If
the first
elements of
wt must contain the weights to be used in the analysis and the effective number of observations for a group is the sum of the weights of the observations in that group. If
the
th observation is excluded from the calculations.
If
,
wt is not referenced and the effective number of observations for a group is the number of observations in that group.
Constraint:
if , , for .
Output Parameters
- 1:
– int64int32nag_int array
-
contains the number of observations in the th group, for .
- 2:
– double array
-
The
th row of
gmn contains the means of the
selected variables for the
th group, for
.
- 3:
– double array
-
The logarithm of the determinants of the within-group variance-covariance matrices.
- 4:
– double array
-
The first
elements of
gc contain
and the remaining
blocks of
elements contain the
matrices. All are stored in packed form by columns.
- 5:
– double scalar
-
The likelihood-ratio test statistic, .
- 6:
– double scalar
-
The degrees of freedom for the distribution of .
- 7:
– double scalar
-
The significance level for .
- 8:
– int64int32nag_int scalar
unless the function detects an error (see
Error Indicators and Warnings).
Error Indicators and Warnings
Errors or warnings detected by the function:
-
-
On entry, | , |
or | , |
or | , |
or | , |
or | , |
or | , |
or | or . |
-
-
On entry, | and a value of . |
-
-
On entry, | there are not exactly nvar elements of , |
or | a value of ing is not in the range to ng, |
or | the effective number of observations for a group is less than , |
or | a group has less than nvar members. |
-
-
or one of the is not of full rank.
-
An unexpected error has been triggered by this routine. Please
contact
NAG.
-
Your licence key may have expired or may not have been installed correctly.
-
Dynamic memory allocation failed.
Accuracy
The accuracy is dependent on the accuracy of the computation of the
decomposition. See
nag_lapack_dgeqrf (f08ae) for further details.
Further Comments
The time taken will be approximately proportional to .
Example
The data, taken from
Aitchison and Dunsmore (1975), is concerned with the diagnosis of three ‘types’ of Cushing's syndrome. The variables are the logarithms of the urinary excretion rates (mg/24hr) of two steroid metabolites. Observations for a total of
patients are input and the statistics computed by
nag_mv_discrim (g03da). The printed results show that there is evidence that the within-group variance-covariance matrices are not equal.
Open in the MATLAB editor:
g03da_example
function g03da_example
fprintf('g03da example results\n\n');
x = [1.1314, 2.4596;
1.0986, 0.2624;
0.6419, -2.3026;
1.3350, -3.2189;
1.4110, 0.0953;
0.6419, -0.9163;
2.1163, 0.0000;
1.3350, -1.6094;
1.3610, -0.5108;
2.0541, 0.1823;
2.2083, -0.5108;
2.7344, 1.2809;
2.0412, 0.4700;
1.8718, -0.9163;
1.7405, -0.9163;
2.6101, 0.4700;
2.3224, 1.8563;
2.2192, 2.0669;
2.2618, 1.1314;
3.9853, 0.9163;
2.7600, 2.0281];
[n,m] = size(x);
isx = ones(m,1,'int64');
nvar = int64(m);
ing = ones(n,1,'int64');
ing(7:16) = int64(2);
ing(17:n) = int64(3);
ng = int64(3);
[nig, gmean, det, gc, stat, df, sig, ifail] = ...
g03da( ...
x, isx, nvar, ing, ng);
mtitle = 'Group means';
matrix = 'General';
diag = ' ';
[ifail] = x04ca( ...
matrix, diag, gmean, mtitle);
fprintf('\nLog of determinants\n\n');
fprintf('%10.4f%10.4f%10.4f\n\n', det);
fprintf(' Stat = %7.4f\n', stat);
fprintf(' DF = %7.4f\n', df);
fprintf(' SIG = %7.4f\n', sig);
g03da example results
Group means
1 2
1 1.0433 -0.6034
2 2.0073 -0.2060
3 2.7097 1.5998
Log of determinants
-0.8273 -3.0460 -2.2877
Stat = 19.2410
DF = 6.0000
SIG = 0.0038
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015