NAG Library Routine Document

g03daf  (discrim)

 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

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 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
Arguments

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:     xldxm – 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:     isxm – 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:     ingn – 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:   nigng – Integer arrayOutput
On exit: nigj contains the number of observations in the jth group, for j=1,2,,ng.
12:   gmnldgmnnvar – 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:   detng – Real (Kind=nag_wp) arrayOutput
On exit: the logarithm of the determinants of the within-group variance-covariance matrices.
15:   gcng+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:   wkn×nvar+1 – Real (Kind=nag_wp) arrayWorkspace
20:   iwkng – Integer arrayWorkspace
21:   ifail – IntegerInput/Output
On entry: ifail must be set to 0, -1​ or ​1. 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 -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 argument, 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.
ifail=-99
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.
ifail=-399
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.
ifail=-999
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 QR 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.

9
Further Comments

The time taken will be approximately proportional to np2.

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

10.1
Program Text

Program Text (g03dafe.f90)

10.2
Program Data

Program Data (g03dafe.d)

10.3
Program Results

Program Results (g03dafe.r)

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