Learn R Programming

fastR (version 1.1)

Mahalanobis distance: Mahalanobis distance

Description

Mahalanobis distance.

Usage

mahala(x, m, s, inverted = FALSE)

Arguments

x
A matrix with the data, where rows denotes observations (vectors) and the columns contain the variables.
m
The mean vector.
s
The covariance or any square symmetric matrix.
inverted
If the covariance matrix is already inverted put this equal to TRUE.

Value

A vector with the Mahalanobis distances.

See Also

cova, cora

Examples

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

Run the code above in your browser using DataLab