Mahalanobis Distance

DESCRIPTION:

Returns a vector of the Mahalanobis distances for the rows of a data matrix.

USAGE:

mahalanobis(x, center, cov, inverted=F) 

REQUIRED ARGUMENTS:

x
matrix of data. Rows represent observations and columns represent variables. Missing values ( NAs) are allowed.
center
vector of the mean of the distribution. The length of center must equal the number of columns in x. Missing values are not accepted.
cov
matrix giving the covariance matrix for the distribution. This must be square and have the same number of columns as x. This may alternatively be a QR decomposition of the covariance matrix, or the inverse of the covariance matrix (see inverted). Missing values are not accepted.

OPTIONAL ARGUMENTS:

inverted
logical flag: if TRUE, then cov is taken to be the inverse of the covariance matrix.

VALUE:

a vector, each element of which is the (squared) Mahalanobis distance for the corresponding row of x.

DETAILS:

The result contains missing values for rows of x that contain missing values.

The ith element of the result is equal to (x[i,]-center)%*%solve(cov)%*%(x[i,]-center) .

REFERENCES:

The Mahalanobis distance is discussed in many multivariate books such as:

Mardia, K. V., Kent, J. T. and Bibby, J. M. (1979). Multivariate Analysis. Academic Press, London.

SEE ALSO:

, .

EXAMPLES:

freeny.cov <- cov.mve(freeny.x) 
freeny.mah <- mahalanobis(freeny.x, freeny.cov$center, freeny.cov$cov)