G03DAF (PDF version)
G03 Chapter Contents
G03 Chapter Introduction
NAG Library Manual

NAG Library Routine Document

G03DAF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

+ Contents

    1  Purpose
    7  Accuracy

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

SUBROUTINE G03DAF ( WEIGHT, N, M, X, LDX, ISX, NVAR, ING, NG, WT, NIG, GMN, LDGMN, DET, GC, STAT, DF, SIG, WK, IWK, IFAIL)
INTEGER  N, M, LDX, ISX(M), NVAR, ING(N), NG, NIG(NG), LDGMN, IWK(NG), IFAIL
REAL (KIND=nag_wp)  X(LDX,M), WT(*), GMN(LDGMN,NVAR), DET(NG), GC((NG+1)*NVAR*(NVAR+1)/2), STAT, DF, SIG, WK(N*(NVAR+1))
CHARACTER(1)  WEIGHT

3  Description

Let a sample of n observations on p variables come from ng groups with nj observations in the jth group and nj=n. If the data is assumed to follow a multivariate Normal distribution with the variance-covariance matrix of the jth group Σj, then to test for equality of the variance-covariance matrices between groups, that is, Σ1=Σ2==Σng=Σ, the following likelihood-ratio test statistic, G, can be used;
G=C n-nglogS-j=1ngnj-1logSj ,
where
C= 1-2p2+3p- 1 6p+ 1ng- 1 j= 1ng1 nj- 1 -1 n-ng ,
and Sj are the within-group variance-covariance matrices and S is the pooled variance-covariance matrix given by
S=j=1ngnj-1Sj n-ng .
For large n, G is approximately distributed as a χ2 variable with 12pp+1ng-1 degrees of freedom, see Morrison (1967) for further comments. If weights are used, then S and Sj are the weighted pooled and within-group variance-covariance matrices and n 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 QR decomposition. The group means are subtracted from the data and then for each group, a QR decomposition is computed to give an upper triangular matrix Rj*. This matrix can be scaled to give a matrix Rj such that Sj=RjTRj. The pooled R matrix is then computed from the Rj matrices. The values of S and the Sj can then be calculated from the diagonal elements of R and the Rj.
This approach means that the Mahalanobis squared distances for a vector observation x can be computed as zTz, where Rjz=x-x-j, x-j being the vector of means of the jth 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  Parameters

1:     WEIGHT – CHARACTER(1)Input
On entry: indicates if weights are to be used.
WEIGHT='U'
No weights are used.
WEIGHT='W'
Weights are to be used and must be supplied in WT.
Constraint: WEIGHT='U' or 'W'.
2:     N – INTEGERInput
On entry: n, the number of observations.
Constraint: N1.
3:     M – INTEGERInput
On entry: the number of variables in the data array X.
Constraint: MNVAR.
4:     X(LDX,M) – REAL (KIND=nag_wp) arrayInput
On entry: Xkl must contain the kth observation for the lth variable, for k=1,2,,n and l=1,2,,M.
5:     LDX – INTEGERInput
On entry: the first dimension of the array X as declared in the (sub)program from which G03DAF is called.
Constraint: LDXN.
6:     ISX(M) – INTEGER arrayInput
On entry: ISXl indicates whether or not the lth variable in X is to be included in the variance-covariance matrices.
If ISXl>0 the lth variable is included, for l=1,2,,M; otherwise it is not referenced.
Constraint: ISXl>0 for NVAR values of l.
7:     NVAR – INTEGERInput
On entry: p, the number of variables in the variance-covariance matrices.
Constraint: NVAR1.
8:     ING(N) – INTEGER arrayInput
On entry: INGk indicates to which group the kth observation belongs, for k=1,2,,n.
Constraint: 1INGkNG, for k=1,2,,n
The values of ING must be such that each group has at least NVAR members.
9:     NG – INTEGERInput
On entry: the number of groups, ng.
Constraint: NG2.
10:   WT(*) – REAL (KIND=nag_wp) arrayInput
Note: the dimension of the array WT must be at least N if WEIGHT='W', and at least 1 otherwise.
On entry: if WEIGHT='W' the first n 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 WTk=0.0 the kth observation is excluded from the calculations.
If WEIGHT='U', WT is not referenced and the effective number of observations for a group is the number of observations in that group.
Constraint: if WEIGHT='W', WTk0.0, for k=1,2,,n.
11:   NIG(NG) – INTEGER arrayOutput
On exit: NIGj contains the number of observations in the jth group, for j=1,2,,ng.
12:   GMN(LDGMN,NVAR) – REAL (KIND=nag_wp) arrayOutput
On exit: the jth row of GMN contains the means of the p selected variables for the jth group, for j=1,2,,ng.
13:   LDGMN – INTEGERInput
On entry: the first dimension of the array GMN as declared in the (sub)program from which G03DAF is called.
Constraint: LDGMNNG.
14:   DET(NG) – REAL (KIND=nag_wp) arrayOutput
On exit: the logarithm of the determinants of the within-group variance-covariance matrices.
15:   GC(NG+1×NVAR×NVAR+1/2) – REAL (KIND=nag_wp) arrayOutput
On exit: the first pp+1/2 elements of GC contain R and the remaining ng blocks of pp+1/2 elements contain the Rj matrices. All are stored in packed form by columns.
16:   STAT – REAL (KIND=nag_wp)Output
On exit: the likelihood-ratio test statistic, G.
17:   DF – REAL (KIND=nag_wp)Output
On exit: the degrees of freedom for the distribution of G.
18:   SIG – REAL (KIND=nag_wp)Output
On exit: the significance level for G.
19:   WK(N×NVAR+1) – REAL (KIND=nag_wp) arrayWorkspace
20:   IWK(NG) – INTEGER arrayWorkspace
21:   IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to 0, -1​ or ​1. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value -1​ or ​1 is recommended. If the output of error messages is undesirable, then the value 1 is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is 0. When the value -1​ or ​1 is used it is essential to test the value of IFAIL on exit.
On exit: IFAIL=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6  Error Indicators and Warnings

If on entry IFAIL=0 or -1, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
IFAIL=1
On entry,NVAR<1,
orN<1,
orNG<2,
orM<NVAR,
orLDX<N,
orLDGMN<NG,
orWEIGHT'U' or 'W'.
IFAIL=2
On entry,WEIGHT='W' and a value of WT<0.0.
IFAIL=3
On entry,there are not exactly NVAR elements of ISX>0,
ora value of ING is not in the range 1 to NG,
orthe effective number of observations for a group is less than 1,
ora group has less than NVAR members.
IFAIL=4
R or one of the Rj is not of full rank.

7  Accuracy

The accuracy is dependent on the accuracy of the computation of the QR decomposition. See F08AEF (DGEQRF) for further details.

8  Further Comments

The time taken will be approximately proportional to np2.

9  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 21 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.

9.1  Program Text

Program Text (g03dafe.f90)

9.2  Program Data

Program Data (g03dafe.d)

9.3  Program Results

Program Results (g03dafe.r)


G03DAF (PDF version)
G03 Chapter Contents
G03 Chapter Introduction
NAG Library Manual

© The Numerical Algorithms Group Ltd, Oxford, UK. 2012