Learn R Programming

symMCD (version 0.6)

Maha: Fast squared Mahalanobis distances

Description

Computes squared Mahalanobis distances using different choices of location and scatter matrices.

Usage

Maha(X, center, scatter)
MahaClassical(X)
MahaOrigin(X)

Value

A numeric vector with the squared distances

Arguments

X

numeric data matrix.

center

numeric vector giving the location vector.

scatter

numeric matrix giving the scatter matrix.

Details

The function Maha allows the user to supply a custom location and scatter matrix in order to compute (pseudo) Mahalanobis distances. This makes it possible to use alternative location and scatter estimates instead of the sample mean vector and covariance matrix. In contrast, the function MahaClassical always uses the sample mean and the classical covariance matrix. The function MahaOrigin fixes the location at the origin and computes the corresponding covariance matrix with respect to the origin.

The three functions provided here prioritize computational efficiency, but offer fewer options than mahalanobis. For example, mahalanobis allows the user to provide a pre-inverted scatter matrix.

See Also

Examples

Run this code
X <- matrix(rnorm(300), ncol = 3)

COV <- cov(X)
MEAN <- colMeans(X)

Maha(X, MEAN, COV)
mahalanobis(X, MEAN, COV)
MahaClassical(X)


MEAN0 <- rep(0, 3)
COV0 <- crossprod(X)/99
MahaOrigin(X)
mahalanobis(X, MEAN0, COV0)

Run the code above in your browser using DataLab