​group, equal, priors, nig, gmn, gc, det, isx, x, prior, atiq)[source]

discrim_group allocates observations to groups according to selected rules. It is intended for use after discrim().

For full information please refer to the NAG Library document for g03dc

typstr, length 1

Whether the estimative or predictive approach is used.

The estimative approach is used.

The predictive approach is used.

equalstr, length 1

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

The within-group variance-covariance matrices are assumed to be unequal and the matrices , for , stored in the remainder of are used.

priorsstr, length 1

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 .

nigint, array-like, shape

The number of observations in each group in the training set, .

gmnfloat, array-like, shape

The th row of contains the means of the variables for the th group, for . These are returned by discrim().

gcfloat, array-like, shape

The first elements of 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 discrim().

If only the first elements are referenced, if only the elements to are referenced.

detfloat, array-like, shape

If . the logarithms of the determinants of the within-group variance-covariance matrices as returned by discrim(). Otherwise is not referenced.

isxint, array-like, shape

indicates if the th variable in is to be included in the distance calculations.

If , the th variable is included, for ; otherwise the th variable is not referenced.

xfloat, array-like, shape

must contain the th observation for the th variable, for , for .

priorfloat, array-like, shape

If , the prior probabilities for the groups.


must be if atypicality indices are required. If is the array is not set.

priorfloat, ndarray, shape

If , the computed prior probabilities in proportion to group sizes for the groups.

If , the input prior probabilities will be unchanged.

If , is not set.

pfloat, ndarray, shape

contains the posterior probability for allocating the th observation to the th group, for , for .

iagint, ndarray, shape

The groups to which the observations have been allocated.

atifloat, ndarray, shape

If is , will contain the predictive atypicality index for the th observation with respect to the th group, for , for .

If is , is not set.

(errno )

On entry, .

Constraint: or .

(errno )

On entry, .

Constraint: , or .

(errno )

On entry, .

Constraint: or .

(errno )

On entry, and .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, and .

Constraint: .

(errno )

On entry, .

(errno )

On entry, , and .

Constraint: .

(errno )

On entry, and values of .

Constraint: exactly elements of .

(errno )

On entry, .

(errno )

On entry, and .

Constraint: .

(errno )

On entry, a diagonal element of or is zero.


In the NAG Library the traditional C interface for this routine uses a different algorithmic base. Please contact NAG if you have any questions about compatibility.

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 , discrim_group uses the upper triangular matrices and supplied by discrim() 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.

discrim_group 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:

  1. Estimative with equal variance-covariance matrices – Linear Discrimination

  2. Estimative with unequal variance-covariance matrices – Quadratic Discrimination

  3. Predictive with equal variance-covariance matrices

  4. Predictive with unequal variance-covariance matrices


In the above the appropriate value of from (1) and (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, discrim_group computes an atypicality index, . The predictive atypicality index is returned, irrespective of the value of the parameter . 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:


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 .


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