naginterfaces.library.mv.discrim_​mahal¶

naginterfaces.library.mv.discrim_mahal(equal, mode, gmn, gc, nobs, isx, x)[source]

discrim_mahal computes Mahalanobis squared distances for group or pooled variance-covariance matrices. It is intended for use after discrim().

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

https://support.nag.com/numeric/nl/nagdoc_30.1/flhtml/g03/g03dbf.html

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

modestr, length 1

Indicates whether distances from sample points are to be calculated or distances between the group means.

The distances between the sample points given in and the group means are calculated.

The distances between the group means will be calculated.

gmnfloat, array-like, shape

The th row of contains the means of the selected 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.

nobsint

If , the number of sample points in for which distances are to be calculated.

If , is not referenced.

isxint, array-like, shape

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

If , is not referenced.

xfloat, array-like, shape

Note: the required extent for this argument in dimension 1 is determined as follows: if : ; otherwise: .

If the th row of must contain . That is must contain the th sample value for the th variable, for , for . Otherwise is not referenced.

Returns
dfloat, ndarray, shape

The squared distances.

If , contains the squared distance of the th sample point from the th group mean, , for , for .

If and , contains the squared distance between the th mean and the th mean, , for , for .

The elements are not referenced, for .

If and , contains the squared distance between the th mean and the th mean, , for , for .

Since the elements are not referenced, for , for .

Raises
NagValueError
(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 values of .

Constraint: exactly elements of .

(errno )

On entry, diagonal element of for .

(errno )

On entry, diagonal element of .

Notes

Consider variables observed on populations or groups. Let be the sample mean and the within-group variance-covariance matrix for the th group and let be the th sample point in a dataset. A measure of the distance of the point from the th population or group is given by the Mahalanobis distance, :

If the pooled estimated 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_mahal uses the upper triangular matrices and supplied by discrim() such that and . can then be calculated as where or as appropriate.

A particular case is when the distance between the group or population means is to be estimated. The Mahalanobis squared distance between the th and th groups is:

or

Note: and that in the case when the pooled variance-covariance matrix is used so in this case only the lower triangular values of , , are computed.

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