Rfast (version 1.7.3)

Mahalanobis distance: Mahalanobis distance

Description

Mahalanobis distance.

Usage

mahala(x, mu, sigma, ischol)

Arguments

x
A matrix with the data, where rows denotes observations (vectors) and the columns contain the variables.
mu
The mean vector.
sigma
The covariance or any square symmetric matrix.
ischol
A boolean variable set to true if the Cholesky decomposition of the covariance matrix is supplied in the argument "sigma".

Value

A vector with the Mahalanobis distances.

See Also

dista, colmeans

Examples

Run this code
x <- matrix( rnorm(1000 * 200), ncol = 200 )
m <- colmeans(x)
s <- cov(x)
system.time( a1 <- mahala(x, m, s) )
system.time( a2 <- mahalanobis(x, m, s) )
all.equal(as.vector(a1), as.vector(a2))

Run the code above in your browser using DataLab