NAG Library Routine Document
G03DCF
1 Purpose
G03DCF allocates observations to groups according to selected rules. It is intended for use after
G03DAF.
2 Specification
SUBROUTINE G03DCF ( |
TYP, EQUAL, PRIORS, NVAR, NG, NIG, GMN, LDGMN, GC, DET, NOBS, M, ISX, X, LDX, PRIOR, P, LDP, IAG, ATIQ, ATI, WK, IFAIL) |
INTEGER |
NVAR, NG, NIG(NG), LDGMN, NOBS, M, ISX(M), LDX, LDP, IAG(NOBS), IFAIL |
REAL (KIND=nag_wp) |
GMN(LDGMN,NVAR), GC((NG+1)*NVAR*(NVAR+1)/2), DET(NG), X(LDX,M), PRIOR(NG), P(LDP,NG), ATI(LDP,*), WK(2*NVAR) |
LOGICAL |
ATIQ |
CHARACTER(1) |
TYP, EQUAL, PRIORS |
|
3 Description
Discriminant analysis is concerned with the allocation of observations to groups using information from other observations whose group membership is known,
; these are called the training set. Consider
variables observed on
populations or groups. Let
be the sample mean and
the within-group variance-covariance matrix for the
th group; these are calculated from a training set of
observations with
observations in the
th group, and let
be the
th observation from the set of observations to be allocated to the
groups. The observation can be allocated to a group according to a selected rule. The allocation rule or discriminant function will be based on the distance of the observation from an estimate of the location of the groups, usually the group means. A measure of the distance of the observation from the
th group mean is given by the Mahalanobis distance,
:
If the pooled estimate of the variance-covariance matrix
is used rather than the within-group variance-covariance matrices, then the distance is:
Instead of using the variance-covariance matrices
and
, G03DCF uses the upper triangular matrices
and
supplied by
G03DAF such that
and
.
can then be calculated as
where
or
as appropriate.
In addition to the distances, a set of prior probabilities of group membership, , for , may be used, with . The prior probabilities reflect your view as to the likelihood of the observations coming from the different groups. Two common cases for prior probabilities are , that is, equal prior probabilities, and , for , that is, prior probabilities proportional to the number of observations in the groups in the training set.
G03DCF uses one of four allocation rules. In all four rules the
variables are assumed to follow a multivariate Normal distribution with mean
and variance-covariance matrix
if the observation comes from the
th group. The different rules depend on whether or not the within-group variance-covariance matrices are assumed equal, i.e.,
, and whether a predictive or estimative approach is used. If
is the probability of observing the observation
from group
, then the posterior probability of belonging to group
is:
In the estimative approach, the parameters
and
in
(3) are replaced by their estimates calculated from
. In the predictive approach, a non-informative prior distribution is used for the parameters and a posterior distribution for the parameters,
, is found. A predictive distribution is then obtained by integrating
over the parameter space. This predictive distribution then replaces
in
(3). See
Aitchison and Dunsmore (1975),
Aitchison et al. (1977) and
Moran and Murphy (1979) for further details.
The observation is allocated to the group with the highest posterior probability. Denoting the posterior probabilities,
, by
, the four allocation rules are:
(i) |
Estimative with equal variance-covariance matrices – Linear Discrimination
|
(ii) |
Estimative with unequal variance-covariance matrices – Quadratic Discrimination
|
(iii) |
Predictive with equal variance-covariance matrices
|
(iv) |
Predictive with unequal variance-covariance matrices
where
|
In the above the appropriate value of
from
(1) or
(2) is used. The values of the
are standardized so that,
Moran and Murphy (1979) show the similarity between the predictive methods and methods based upon likelihood ratio tests.
In addition to allocating the observation to a group, G03DCF computes an atypicality index,
. The predictive atypicality index is returned, irrespective of the value of the parameter
TYP. This represents the probability of obtaining an observation more typical of group
than the observed
(see
Aitchison and Dunsmore (1975) and
Aitchison et al. (1977)). The atypicality index is computed for unequal within-group variance-covariance matrices as:
where
is the lower tail probability from a beta distribution and
and for equal within-group variance-covariance matrices as:
with
If
is close to
for all groups it indicates that the observation may come from a grouping not represented in the training set.
Moran and Murphy (1979) provide a frequentist interpretation of
.
4 References
Aitchison J and Dunsmore I R (1975) Statistical Prediction Analysis Cambridge
Aitchison J, Habbema J D F and Kay J W (1977) A critical comparison of two methods of statistical discrimination Appl. Statist. 26 15–25
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
Moran M A and Murphy B J (1979) A closer look at two alternative methods of statistical discrimination Appl. Statist. 28 223–232
Morrison D F (1967) Multivariate Statistical Methods McGraw–Hill
5 Parameters
- 1: – CHARACTER(1)Input
-
On entry: whether the estimative or predictive approach is used.
- The estimative approach is used.
- The predictive approach is used.
Constraint:
or .
- 2: – CHARACTER(1)Input
-
On entry: indicates whether or not the within-group variance-covariance matrices are assumed to be equal and the pooled variance-covariance matrix used.
- The within-group variance-covariance matrices are assumed equal and the matrix stored in the first elements of GC is used.
- The within-group variance-covariance matrices are assumed to be unequal and the matrices
, for , stored in the remainder of GC are used.
Constraint:
or .
- 3: – CHARACTER(1)Input
-
On entry: indicates the form of the prior probabilities to be used.
- Equal prior probabilities are used.
- Prior probabilities proportional to the group sizes in the training set, , are used.
- The prior probabilities are input in PRIOR.
Constraint:
, or .
- 4: – INTEGERInput
-
On entry: , the number of variables in the variance-covariance matrices.
Constraint:
.
- 5: – INTEGERInput
-
On entry: the number of groups, .
Constraint:
.
- 6: – INTEGER arrayInput
-
On entry: the number of observations in each group in the training set, .
Constraints:
- if , and , for ;
- if , , for .
- 7: – REAL (KIND=nag_wp) arrayInput
-
On entry: the
th row of
GMN contains the means of the
variables for the
th group, for
. These are returned by
G03DAF.
- 8: – INTEGERInput
-
On entry: the first dimension of the array
GMN as declared in the (sub)program from which G03DCF is called.
Constraint:
.
- 9: – REAL (KIND=nag_wp) arrayInput
-
On entry: the first
elements of
GC should contain the upper triangular matrix
and the next
blocks of
elements should contain the upper triangular matrices
.
All matrices must be stored packed by column. These matrices are returned by
G03DAF. If
only the first
elements are referenced, if
only the elements
to
are referenced.
Constraints:
- if , the diagonal elements of must be ;
- if , the diagonal elements of the must be , for .
- 10: – REAL (KIND=nag_wp) arrayInput
-
On entry: if
. the logarithms of the determinants of the within-group variance-covariance matrices as returned by
G03DAF. Otherwise
DET is not referenced.
- 11: – INTEGERInput
-
On entry: the number of observations in
X which are to be allocated.
Constraint:
.
- 12: – INTEGERInput
-
On entry: the number of variables in the data array
X.
Constraint:
.
- 13: – INTEGER arrayInput
-
On entry:
indicates if the
th variable in
X is to be included in the distance calculations.
If
, the th variable is included, for ; otherwise the th variable is not referenced.
Constraint:
for
NVAR values of
.
- 14: – REAL (KIND=nag_wp) arrayInput
-
On entry: must contain the th observation for the th variable, for and .
- 15: – INTEGERInput
-
On entry: the first dimension of the array
X as declared in the (sub)program from which G03DCF is called.
Constraint:
.
- 16: – REAL (KIND=nag_wp) arrayInput/Output
-
On entry: if , the prior probabilities for the groups.
Constraint:
if , and , for .
On exit: if
, the computed prior probabilities in proportion to group sizes for the
groups.
If , the input prior probabilities will be unchanged.
If
,
PRIOR is not set.
- 17: – REAL (KIND=nag_wp) arrayOutput
-
On exit: contains the posterior probability for allocating the th observation to the th group, for and .
- 18: – INTEGERInput
-
On entry: the first dimension of the arrays
P and
ATI as declared in the (sub)program from which G03DCF is called.
Constraint:
.
- 19: – INTEGER arrayOutput
-
On exit: the groups to which the observations have been allocated.
- 20: – LOGICALInput
-
On entry:
ATIQ must be .TRUE. if atypicality indices are required. If
ATIQ is .FALSE. the array
ATI is not set.
- 21: – REAL (KIND=nag_wp) arrayOutput
-
Note: the second dimension of the array
ATI
must be at least
if
, and at least
otherwise.
On exit: if
ATIQ is .TRUE.,
will contain the predictive atypicality index for the
th observation with respect to the
th group, for
and
.
If
ATIQ is .FALSE.,
ATI is not set.
- 22: – REAL (KIND=nag_wp) arrayWorkspace
-
- 23: – INTEGERInput/Output
-
On entry:
IFAIL must be set to
,
. 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
is recommended. If the output of error messages is undesirable, then the value
is recommended. Otherwise, if you are not familiar with this parameter, 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 | or ‘P’, |
or | or ‘U’, |
or | , ‘I’ or ‘P’. |
-
On entry, | the number of variables indicated by ISX is not equal to NVAR, |
or | and , for some , |
or | and , |
or | and for some . |
-
On entry, | and for some , |
or | and is not within of . |
-
On entry, | and a diagonal element of is zero, |
or | and a diagonal element of for some is zero. |
An unexpected error has been triggered by this routine. Please
contact
NAG.
See
Section 3.8 in the Essential Introduction for further information.
Your licence key may have expired or may not have been installed correctly.
See
Section 3.7 in the Essential Introduction for further information.
Dynamic memory allocation failed.
See
Section 3.6 in the Essential Introduction for further information.
7 Accuracy
The accuracy of the returned posterior probabilities will depend on the accuracy of the input or matrices. The atypicality index should be accurate to four significant places.
8 Parallelism and Performance
G03DCF is not threaded by NAG in any implementation.
G03DCF 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 distances
can be computed using
G03DBF if other forms of discrimination are required.
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 group means and
matrices are computed by
G03DAF. A further six observations of unknown type are input and allocations made using the predictive approach and under the assumption that the within-group covariance matrices are not equal. The posterior probabilities of group membership,
, and the atypicality index are printed along with the allocated group. The atypicality index shows that observations
and
do not seem to be typical of the three types present in the initial
observations.
10.1 Program Text
Program Text (g03dcfe.f90)
10.2 Program Data
Program Data (g03dcfe.d)
10.3 Program Results
Program Results (g03dcfe.r)