NAG Library Routine Document
g03daf
(discrim)
1
Purpose
g03daf computes a test statistic for the equality of within-group covariance matrices and also computes matrices for use in discriminant analysis.
2
Specification
Fortran Interface
Subroutine g03daf ( |
weight,
n,
m,
x,
ldx,
isx,
nvar,
ing,
ng,
wt,
nig,
gmn,
ldgmn,
det,
gc,
stat,
df,
sig,
wk,
iwk,
ifail) |
Integer, Intent (In) | :: |
n,
m,
ldx,
isx(m),
nvar,
ing(n),
ng,
ldgmn | Integer, Intent (Inout) | :: |
ifail | Integer, Intent (Out) | :: |
nig(ng),
iwk(ng) | Real (Kind=nag_wp), Intent (In) | :: |
x(ldx,m),
wt(*) | Real (Kind=nag_wp), Intent (Inout) | :: |
gmn(ldgmn,nvar) | Real (Kind=nag_wp), Intent (Out) | :: |
det(ng),
gc((ng+1)*nvar*(nvar+1)/2),
stat,
df,
sig,
wk(n*(nvar+1)) | Character (1), Intent (In) | :: |
weight |
|
C Header Interface
#include nagmk26.h
void |
g03daf_ (
const char *weight,
const Integer *n,
const Integer *m,
const double x[],
const Integer *ldx,
const Integer isx[],
const Integer *nvar,
const Integer ing[],
const Integer *ng,
const double wt[],
Integer nig[],
double gmn[],
const Integer *ldgmn,
double det[],
double gc[],
double *stat,
double *df,
double *sig,
double wk[],
Integer iwk[],
Integer *ifail,
const Charlen length_weight) |
|
3
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, g03daf 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
g03dbf. The distances are used in discriminant analysis and
g03dcf uses the results of
g03daf 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.
4
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
5
Arguments
- 1: – Character(1)Input
-
On entry: indicates if weights are to be used.
- No weights are used.
- Weights are to be used and must be supplied in wt.
Constraint:
or .
- 2: – IntegerInput
-
On entry: , the number of observations.
Constraint:
.
- 3: – IntegerInput
-
On entry: the number of variables in the data array
x.
Constraint:
.
- 4: – Real (Kind=nag_wp) arrayInput
-
On entry: must contain the th observation for the th variable, for and .
- 5: – IntegerInput
-
On entry: the first dimension of the array
x as declared in the (sub)program from which
g03daf is called.
Constraint:
.
- 6: – Integer arrayInput
-
On entry:
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
.
- 7: – IntegerInput
-
On entry: , the number of variables in the variance-covariance matrices.
Constraint:
.
- 8: – Integer arrayInput
-
On entry: 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.
- 9: – IntegerInput
-
On entry: the number of groups, .
Constraint:
.
- 10: – Real (Kind=nag_wp) arrayInput
-
Note: the dimension of the array
wt
must be at least
if
, and at least
otherwise.
On entry: 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 .
- 11: – Integer arrayOutput
-
On exit: contains the number of observations in the th group, for .
- 12: – Real (Kind=nag_wp) arrayOutput
-
On exit: the
th row of
gmn contains the means of the
selected variables for the
th group, for
.
- 13: – IntegerInput
-
On entry: the first dimension of the array
gmn as declared in the (sub)program from which
g03daf is called.
Constraint:
.
- 14: – Real (Kind=nag_wp) arrayOutput
-
On exit: the logarithm of the determinants of the within-group variance-covariance matrices.
- 15: – Real (Kind=nag_wp) arrayOutput
-
On exit: the first
elements of
gc contain
and the remaining
blocks of
elements contain the
matrices. All are stored in packed form by columns.
- 16: – Real (Kind=nag_wp)Output
-
On exit: the likelihood-ratio test statistic, .
- 17: – Real (Kind=nag_wp)Output
-
On exit: the degrees of freedom for the distribution of .
- 18: – Real (Kind=nag_wp)Output
-
On exit: the significance level for .
- 19: – Real (Kind=nag_wp) arrayWorkspace
-
- 20: – Integer arrayWorkspace
-
- 21: – IntegerInput/Output
-
On entry:
ifail must be set to
,
. If you are unfamiliar with this argument you should refer to
Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value
is recommended. If the output of error messages is undesirable, then the value
is recommended. Otherwise, if you are not familiar with this argument, the recommended value is
.
When the value is used it is essential to test the value of ifail on exit.
On exit:
unless the routine detects an error or a warning has been flagged (see
Section 6).
6
Error Indicators and Warnings
If on entry
or
, explanatory error messages are output on the current error message unit (as defined by
x04aaf).
Errors or warnings detected by the routine:
-
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.
See
Section 3.9 in How to Use the NAG Library and its Documentation for further information.
Your licence key may have expired or may not have been installed correctly.
See
Section 3.8 in How to Use the NAG Library and its Documentation for further information.
Dynamic memory allocation failed.
See
Section 3.7 in How to Use the NAG Library and its Documentation for further information.
7
Accuracy
The accuracy is dependent on the accuracy of the computation of the
decomposition. See
f08aef (dgeqrf) for further details.
8
Parallelism and Performance
g03daf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
g03daf makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the
X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the
Users' Note for your implementation for any additional implementation-specific information.
The time taken will be approximately proportional to .
10
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
g03daf. The printed results show that there is evidence that the within-group variance-covariance matrices are not equal.
10.1
Program Text
Program Text (g03dafe.f90)
10.2
Program Data
Program Data (g03dafe.d)
10.3
Program Results
Program Results (g03dafe.r)