mahalanobis.dist {StatMatch} | R Documentation |
Computes the Mahalanobis Distance
Description
This function computes the Mahalanobis distance among units in a dataset or between observations in two distinct datasets.
Usage
mahalanobis.dist(data.x, data.y=NULL, vc=NULL)
Arguments
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 ( |
Details
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.
Value
A matrix
object with distances among rows of data.x
and those of data.y
.
Author(s)
Marcello D'Orazio mdo.statmatch@gmail.com
References
Mahalanobis, P C (1936) “On the generalised distance in statistics”. Proceedings of the National Institute of Sciences of India 2, pp. 49-55.
See Also
Examples
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)