Lably
Skip to content

Mahalanobis distance

Statistical distance measure

  • 7 min read
  • 8 chapters

Related on Lably

Through Probability distribution, Sampling distribution and Standard deviation

It is a multivariate generalization of the absolute value of the standard score z=(x−μ)/σ: how many standard deviations away P is from the mean of D. This distance is zero for P at the mean of D and grows as P moves away from the mean along each principal component axis. If each of these axes is re-scaled to have unit variance, and whitened to be uncorrelated, then the Mahalanobis distance corresponds to standard Euclidean distance in the transformed space. The Mahalanobis distance is thus unitless, scale-invariant, and takes into account the correlations of the data set.

Definition

Given a probability distribution Q on RN, with mean μ→=(μ1,μ2,μ3,…,μN)T and positive semi-definite covariance matrix Σ, the Mahalanobis distance of a point x→=(x1,x2,x3,…,xN)T from Q is dM(x→,Q)=(x→−μ→)TΣ−1(x→−μ→).Given two points x→ and y→ in RN, the Mahalanobis distance between them with respect to Q isdM(x→,y→;Q)=(x→−y→)TΣ−1(x→−y→).which means that dM(x→,Q)=dM(x→,μ→;Q).

Since Σ is positive semi-definite, so is Σ−1. Thus, the square roots are always defined.

We can find useful decompositions of the squared Mahalanobis distance that help to explain some reasons for the outlyingness of multivariate observations and also provide a graphical tool for identifying outliers.

By the spectral theorem, Σ can be decomposed as Σ=STS for some real N×N matrix. One choice for S is the symmetric square root of Σ, which is the standard deviation matrix. This gives us the equivalent definitiondM(x→,y→;Q)=‖S−1(x→−y→)‖where ‖⋅‖ is the Euclidean norm. That is, the Mahalanobis distance is the Euclidean distance after a whitening transformation.

The existence of S is guaranteed by the spectral theorem, but it is not unique. Different choices have different theoretical and practical advantages.

In practice, the distribution Q is usually the sample distribution from a set of IID samples from an underlying unknown distribution, so μ is the sample mean, and Σ is the covariance matrix of the samples.

When the affine span of the samples is not the entire RN, the covariance matrix would not be positive-definite, which means the above definition would not work. However, in general, the Mahalanobis distance is preserved under any full-rank affine transformation of the affine span of the samples. So in case the affine span is not the entire RN, the samples can be first orthogonally projected to Rn, where n is the dimension of the affine span of the samples, then the Mahalanobis distance can be computed as usual.

Sign in to keep reading

7 more chapters are free with a Lably account.

More in Statistics