NAG CL Interface
g03dcc (discrim_​group)

Settings help

CL Name Style:


1 Purpose

g03dcc allocates observations to groups according to selected rules. It is intended for use after g03dac.

2 Specification

#include <nag.h>
void  g03dcc (Nag_DiscrimMethod type, Nag_GroupCovars equal, Nag_PriorProbability priors, Integer nvar, Integer ng, const Integer nig[], const double gmean[], Integer tdg, const double gc[], const double det[], Integer nobs, Integer m, const Integer isx[], const double x[], Integer tdx, double prior[], double p[], Integer tdp, Integer iag[], Nag_Boolean atiq, double ati[], NagError *fail)
The function may be called by the names: g03dcc or nag_mv_discrim_group.

3 Description

Discriminant analysis is concerned with the allocation of observations to groups using information from other observations whose group membership is known, X t ; these are called the training set. Consider p variables observed on n g populations or groups. Let x ¯ j be the sample mean and S j the within-group variance-covariance matrix for the j th group; these are calculated from a training set of n observations with n j observations in the j th group, and let x k be the k th observation from the set of observations to be allocated to the n g 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 j th group mean is given by the Mahalanobis distance, D kj 2 :
D kj 2 = ( x k - x ¯ j ) T S j −1 ( x k - x ¯ j ) . (1)
If the pooled estimate of the variance-covariance matrix S is used rather than the within-group variance-covariance matrices, then the distance is:
D kj 2 = ( x k - x ¯ j ) T S −1 ( x k - x ¯ j ) . (2)
Instead of using the variance-covariance matrices S and S j , g03dcc uses the upper triangular matrices R and R j supplied by g03dac such that S = RT R and S j = RjT R j . D kj 2 can then be calculated as zT z where R j z = ( x k - x ¯ j ) or Rz = ( x k - x ¯ j ) as appropriate.
In addition to the distances, a set of prior probabilities of group membership, π j , for j=1,2,, n g , may be used, with π j = 1 . 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 π 1 = π 2 = = π n g , that is, equal prior probabilities, and π j = n j / n , for j=1,2,, n g , that is, prior probabilities proportional to the number of observations in the groups in the training set.
g03dcc uses one of four allocation rules. In all four rules the p variables are assumed to follow a multivariate Normal distribution with mean μ j and variance-covariance matrix Σ j if the observation comes from the j th group. The different rules depend on whether or not the within-group variance-covariance matrices are assumed equal, i.e., Σ 1 = Σ 2 = = Σ n g , and whether a predictive or estimative approach is used. If p ( x k μ j , Σ j ) is the probability of observing the observation x k from group j , then the posterior probability of belonging to group j is:
p ( j x k μ j , Σ j ) p ( x k μ j , Σ j ) π j . (3)
In the estimative approach, the arguments μ j and Σ j in (3) are replaced by their estimates calculated from X t . In the predictive approach, a non-informative prior distribution is used for the arguments and a posterior distribution for the arguments, p ( μ j , Σ j X t ) , is found. A predictive distribution is then obtained by integrating p ( j x k , μ j , Σ j ) p ( μ j , Σ j X ) over the argument space. This predictive distribution then replaces p ( x k μ j , Σ j ) 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, p ( j x k , μ j , Σ j ) , by q j , the four allocation rules are:
  1. (i)Estimative with equal variance-covariance matrices – Linear Discrimination.
    log(q) j - 1 2 D kj 2 + logπ j  
  2. (ii)Estimative with unequal variance-covariance matrices – Quadratic Discrimination.
    log(q) j - 1 2 D kj 2 + logπ j - 1 2 log| S j |  
  3. (iii)Predictive with equal variance-covariance matrices.
    q j −1 (( n j +1)/ n j ) p/2 {1+[ n j /(( n-n g )( n j +1))] D kj 2 } (n+1- n g ) / 2  
  4. (iv)Predictive with unequal variance-covariance matrices
    q j −1 C {(( n j 2 -1)/ n j )| S j |} p/2 {1+( n j /( n j 2 -1)) D kj 2 } n j / 2  
    where
    C = Γ ( 1 2 ( n j -p)) Γ ( 1 2 n j )  
    In the above the appropriate value of D kj 2 from (1) or (2) is used. The values of the q j are standardized so that,
    j=1 n g q j = 1 .  
    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, g03dcc computes an atypicality index, I j ( x k ) . This represents the probability of obtaining an observation more typical of group j than the observed x k (see Aitchison and Dunsmore (1975) and Aitchison et al. (1977)). The atypicality index is computed as:
    I j ( x k ) = P ( B z : 1 2 p , 1 2 ( n j -d) )  
    where P ( B β : a ,b) is the lower tail probability from a beta distribution where, for unequal within-group variance-covariance matrices,
    z = D kj 2 / ( D kj 2 +( n j 2 -1)/ n j ) ,  
    and for equal within-group variance-covariance matrices,
    z = D kj 2 / ( D kj 2 +( n-n g )( n j -1)/ n j ) .  
    If I j ( x k ) is close to 1 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 I j ( x k ) .

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 Arguments

1: type Nag_DiscrimMethod Input
On entry: indicates whether the estimative or predictive approach is to be used.
type=Nag_DiscrimEstimate
The estimative approach is used.
type=Nag_DiscrimPredict
The predictive approach is used.
Constraint: type=Nag_DiscrimEstimate or Nag_DiscrimPredict.
2: equal Nag_GroupCovars 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.
equal=Nag_EqualCovar
The within-group variance-covariance matrices are assumed equal and the matrix R stored in the first p (p+1) / 2 elements of gc is used.
equal=Nag_NotEqualCovar
The within-group variance-covariance matrices are assumed to be unequal and the matrices R i , for i=1,2,, n g , stored in the remainder of gc are used.
Constraint: equal=Nag_EqualCovar or Nag_NotEqualCovar.
3: priors Nag_PriorProbability Input
On entry: indicates the form of the prior probabilities to be used.
priors=Nag_EqualPrior
Equal prior probabilities are used.
priors=Nag_GroupSizePrior
Prior probabilities proportional to the group sizes in the training set, n j , are used.
priors=Nag_UserPrior
The prior probabilities are input in prior.
Constraint: priors=Nag_EqualPrior, Nag_GroupSizePrior or Nag_UserPrior.
4: nvar Integer Input
On entry: the number of variables, p , in the variance-covariance matrices as specified to g03dac.
Constraint: nvar1 .
5: ng Integer Input
On entry: the number of groups, n g .
Constraint: ng2 .
6: nig[ng] const Integer Input
On entry: the number of observations in each group training set, n j .
Constraints:
  • if equal=Nag_EqualCovar, nig[j-1] > 0 and j=1 n g nig[j-1] > ng + nvar , for j=1,2,, n g ;
  • if equal=Nag_NotEqualCovar, nig[j-1] > nvar , for j=1,2,, n g .
7: gmean[ng×tdg] const double Input
Note: the (i,j)th element of the matrix is stored in gmean[(i-1)×tdg+j-1].
On entry: the j th row of gmean contains the means of the p variables for the j th group, for j=1,2,, n j . These are returned by g03dac.
8: tdg Integer Input
On entry: the stride separating matrix column elements in the array gmean.
Constraint: tdgnvar .
9: gc[dim] const double Input
Note: the dimension, dim, of the array gc must be at least (ng+1)×nvar×(nvar+1)/2.
On entry: the first p (p+1) / 2 elements of gc should contain the upper triangular matrix R and the next n g blocks of p (p+1) / 2 elements should contain the upper triangular matrices R j .
All matrices must be stored packed by column. These matrices are returned by g03dac. If equal=Nag_EqualCovar, only the first p (p+1) / 2 elements are referenced, if equal=Nag_NotEqualCovar, only the elements p (p+1) / 2 to ( n g +1) p (p+1) / 2 - 1 are referenced.
Constraints:
  • if equal=Nag_EqualCovar, the diagonal elements of R must be 0.0 ;
  • if equal=Nag_NotEqualCovar, the diagonal elements of the R j must be 0.0 , for j=1,2,, n g .
10: det[ng] const double Input
On entry: if equal=Nag_NotEqualCovar, the logarithms of the determinants of the within-group variance-covariance matrices as returned by g03dac. Otherwise det is not referenced.
11: nobs Integer Input
On entry: the number of observations in x which are to be allocated.
Constraint: nobs1 .
12: m Integer Input
On entry: the number of variables in the data array x.
Constraint: mnvar .
13: isx[m] const Integer Input
On entry: isx[l-1] indicates if the l th variable in x is to be included in the distance calculations. If isx[l-1] > 0 the l th variable is included, for l=1,2,,m; otherwise the l th variable is not referenced.
Constraint: isx[l-1] > 0 for nvar values of l .
14: x[nobs×tdx] const double Input
On entry: x[(k-1)×tdx+l-1] must contain the k th observation for the l th variable, for k=1,2,,nobs and l=1,2,,m.
15: tdx Integer Input
On entry: the stride separating matrix column elements in the array x.
Constraint: tdxm .
16: prior[ng] double Input/Output
On entry: if priors=Nag_UserPrior the prior probabilities for the n g groups.
Constraint: if priors=Nag_UserPrior, prior[j-1] > 0.0 and |1- j=1 n g prior[j-1]| 10 × machine precision , for j=1,2,, n g .
On exit: if priors=Nag_GroupSizePrior, the computed prior probabilities in proportion to group sizes for the n g groups.
If priors=Nag_UserPrior, the input prior probabilities will be unchanged.
If priors=Nag_EqualPrior, prior is not set.
17: p[nobs×tdp] double Output
On exit: p[(k-1)×tdp+j-1] contains the posterior probability p kj for allocating the k th observation to the j th group, for k=1,2,,nobs and j=1,2,, n g .
18: tdp Integer Input
On entry: the stride separating matrix column elements in the arrays p, ati.
Constraint: tdpng .
19: iag[nobs] Integer Output
On exit: the groups to which the observations have been allocated.
20: atiq Nag_Boolean Input
On entry: atiq must be Nag_TRUE if atypicality indices are required. If atiq is Nag_FALSE, the array ati is not set.
21: ati[nobs×tdp] double Output
On exit: if atiq is Nag_TRUE, ati[(k-1)×tdp+j-1] will contain the atypicality index for the k th observation with respect to the j th group, for k=1,2,,nobs and j=1,2,, n g . If atiq is Nag_FALSE, ati is not set.
22: fail NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

6 Error Indicators and Warnings

NE_2_INT_ARG_LT
On entry, m=value while nvar=value . These arguments must satisfy mnvar .
On entry, tdg=value while nvar=value . These arguments must satisfy tdgnvar .
On entry, tdp=value while ng=value . These arguments must satisfy tdpng .
On entry, tdx=value while m=value . These arguments must satisfy tdxm .
NE_ALLOC_FAIL
Dynamic memory allocation failed.
NE_BAD_PARAM
On entry, argument equal had an illegal value.
On entry, argument priors had an illegal value.
On entry, argument type had an illegal value.
NE_DIAG_0_COND
A diagonal element of R is zero when equal=Nag_EqualCovar.
NE_DIAG_0_J_COND
A diagonal element of R is zero for some j , when equal=Nag_NotEqualCovar
NE_GROUP_SUM
On entry, the j=1 ng nig[j-1] = value, ng=value , nvar=value .
Constraint: j=1 ng nig[j-1] > ng + nvar when equal=Nag_EqualCovar.
NE_INT_ARG_LT
On entry, ng=value.
Constraint: ng2.
On entry, nobs=value.
Constraint: nobs1.
On entry, nvar=value.
Constraint: nvar1.
NE_INTARR
On entry, nig[value] = value.
Constraint: nig[i-1] > 0 , for i=1,2,,ng, when equal=Nag_EqualCovar.
NE_INTARR_INT
On entry, nig[value] = value, nvar=value .
Constraint: nig[i-1] > nvar , i = 1 , 2 , , ng when equal=Nag_NotEqualCovar.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
NE_PRIOR_SUM
On entry, j=1 ng prior[j-1] = value.
Constraint: j=1 ng prior[j-1] must be within 10 × machine precision of 1 when priors=Nag_UserPrior.
NE_REALARR
On entry, prior[value] = value.
Constraint: prior[j-1] > 0 , j = 1 , 2 , , ng when priors=Nag_UserPrior.
NE_VAR_INCL_INDICATED
The number of variables, nvar in the analysis =value , while number of variables included in the analysis via array isx=value .
Constraint: these two numbers must be the same.

7 Accuracy

The accuracy of the returned posterior probabilities will depend on the accuracy of the input R or R j matrices. The atypicality index should be accurate to four significant places.

8 Parallelism and Performance

g03dcc is not threaded in any implementation.

9 Further Comments

The distances D kj 2 can be computed using g03dbc 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 21 patients are input and the group means and R matrices are computed by g03dac. 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, q j , and the atypicality index are printed along with the allocated group. The atypicality index shows that observations 5 and 6 do not seem to be typical of the three types present in the initial 21 observations.

10.1 Program Text

Program Text (g03dcce.c)

10.2 Program Data

Program Data (g03dcce.d)

10.3 Program Results

Program Results (g03dcce.r)