# Why use the Mahalanobis distance

I understand in theory why the Mahalanobis distance is a good measure for mutlivariate outlier detection. However, everything I tend to read warns against calculating the inverse/pseudoinverse of a covariance matrix, which is needed to compute the mahalanobis distance.

So, if nobody wants to compute the inverse, what distance measure should be used?

• "However, everything I tend to read warns against calculating the inverse/pseudoinverse of a covariance matrix" can you add a reference? The answer to your question depends on the context (and more particularly on the #of dimensions $p$) – user603 Feb 27 '13 at 15:07
• @user603 As I have just learnt, I have a 21 dimension feature (sums to 1) and am trying to construct a covariance matrix from ~70 samples. This produces an ill conditioned covariance matrix, so the calculation of inverse/pseudoinverse is highly sensitive to small numerical change. Making the Mahalanobis distance inappropriate for me. Are there other alternatives? – Aly Feb 27 '13 at 15:20
• One immediate issue is that your data "(sums to 1)". Consider a 2-d case, where data is of the form (x, y) where y = 1-x. The variables are perfectly correlated, hence of course the covariance matrix will be ill-formed as it looks like [ 1, 1; 1, 1]. Basically you have a redundant variable (back to my example, if you know x, you definetely know y). Try dropping a single variable. – Cam.Davidson.Pilon Feb 27 '13 at 16:38
• If the authors of your literature are honest, they will eat their own words when they encounter linear regression. – Cam.Davidson.Pilon Feb 27 '13 at 16:41
• as Cam.Davidson.Pilon wrote, you problems are not caused by by the mahalanobis distances per-se but because you are dealing with so called compositional data. You have to first transform your data in a specific way. See the pointer to a short intro about this type of data in my answer to a related question. By the way, one of the most popular such transformations basically amounts to doing what I recommended in an answer to one of your previous questions. – user603 Feb 27 '13 at 16:48

• The variance-covariance matrix rescales the variables sounds strange, - it is not the correlation matrix. – ttnphns Feb 27 '13 at 16:50