View source: R/mahalanobis.dist.R
mahalanobis.dist | R Documentation |
This function computes the Mahalanobis distance among units in a dataset or between observations in two distinct datasets.
mahalanobis.dist(data.x, data.y=NULL, vc=NULL)
data.x |
A matrix or a data frame containing variables that should be used in the computation of the distance between units. Only continuous variables are allowed. Missing values ( When only |
data.y |
A numeric matrix or data frame with the same variables, of the same type, as those in |
vc |
Covariance matrix that should be used in distance computation. If it is not supplied ( |
The Mahalanobis distance is calculated by means of:
d(i,j)=\sqrt{(x_i - x_j)^T S^{-1} (x_i - x_j)}
The covariance matrix S is estimated from the available data when vc=NULL
, otherwise the one supplied via the argument vc
is used.
A matrix
object with distances among rows of data.x
and those of data.y
.
Marcello D'Orazio mdo.statmatch@gmail.com
Mahalanobis, P C (1936) “On the generalised distance in statistics”. Proceedings of the National Institute of Sciences of India 2, pp. 49-55.
mahalanobis
md1 <- mahalanobis.dist(iris[1:6,1:4])
md2 <- mahalanobis.dist(data.x=iris[1:6,1:4], data.y=iris[51:60, 1:4])
vv <- var(iris[,1:4])
md1a <- mahalanobis.dist(data.x=iris[1:6,1:4], vc=vv)
md2a <- mahalanobis.dist(data.x=iris[1:6,1:4], data.y=iris[51:60, 1:4], vc=vv)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.