MAHALANOBIS (x, <, center> <, cov> );
The MAHALANOBIS function is part of the IMLMLIB library . The MAHALANOBIS function returns the Mahalanobis distance between center and the rows of x, measured according to the Mahalanobis metric. The arguments are as follows:
specifies an numerical matrix that contains n points in p-dimensional space.
is a numerical vector that contains a point in p-dimensional space. The function returns the distances from the rows of x to center. If center is not specified, the sample mean, , is used.
is an covariance matrix that specifies the metric that is used to compute distances. If cov is the identity matrix, then the function returns the usual Euclidean distance. If cov is not specified, the sample covariance matrix of x is used. In this case, the number of rows of x must be strictly greater than the number of columns, so that the covariance matrix is nonsingular.
If u and c are p-dimensional row vectors and S is a covariance matrix, then the Mahalanobis distance between u and c is
The following statements compute the Mahalanobis distance between the rows of x and the point :
x = {1 0, 0 1, -1 0, 0 -1}; center = {1 1}; cov = {4 1, 1 9}; maha = mahalanobis(x, center, cov); print maha;
When the cov argument is an identity matrix, the Mahalanobis distance simplifies to the usual Euclidean distance. See the DISTANCE function for more information.