Mahalanobis Distance Outliers calculator
Calculate Mahalanobis distance for multivariate datasets. Identify outliers accounting for covariate correlations online.
What it does
You care about cases unusual relative to the whole dataset (a global notion of 'unusual', not a local neighbourhood), and your features are continuous, so a distance measure that accounts for correlation between features fits better than checking each variable's outliers independently.
When to use it
Each case gets a distance score summarising how far it sits from the centre of the data once correlations between features are accounted for; large distances flag cases that are jointly unusual even if no single variable looks extreme.
Worked example
You are checking a clinical dataset where height and weight are recorded. A height of 1.9 m is normal and a weight of 50 kg is normal, but together they are not. Mahalanobis distance accounts for how the variables move together, so it catches the impossible combination that no single-column check would.
Cautions
- This assumes roughly elliptical, multivariate-normal-like structure — if the data are strongly non-elliptical or contain distinct sub-populations, this method can flag or miss cases for the wrong reason; like any unsupervised score, the flagged rate depends on the threshold chosen, not a ground-truth anomaly rate, and a flag is a signal for review, not a confirmed anomaly.
- Distances are measured along the covariance structure of the data and compared against a chi-square reference with one degree of freedom per variable. The covariance is the CLASSICAL estimate, computed from every point including the outliers being searched for, so a cluster of extreme points can inflate the very covariance it is measured against and hide itself — masking. The 97.5% threshold also flags about 2.5% of clean multivariate-normal data by construction, so a handful of flags on a large file is expected rather than a finding.
Alternatives
- Per-variable z-score/IQR fences checked one at a time — Checking each variable separately misses multivariate outliers — a case unremarkable on every single variable but an impossible COMBINATION of them — which is exactly what a covariance-aware distance is built to catch.
- Local Outlier Factor — That method targets points unusual relative to their local neighbourhood; if 'unusual' means far from the overall centre of the data, a global distance measure answers that more directly and cheaply.
How to read the output
- The distance and the χ² threshold
- Squared Mahalanobis distance is compared against the 97.5th percentile of a χ² distribution with one degree of freedom per variable — the standard convention. That threshold assumes the data are multivariate normal, and it flags about 2.5% of points even when nothing is wrong. On 1,000 clean rows, expect roughly 25 flags. This is not a test and there is no p-value.
- Why the correlations matter
- Distance is measured along the shape of the data, so a point can be typical on height and typical on weight while the pair together is far outside the cloud. That is the method's strength and the reason a flagged point often looks unremarkable in any single column. Plot the pair before dismissing it.
- More variables than rows
- The covariance matrix cannot be inverted when the rows do not outnumber the variables, and the result says so rather than returning numbers. Even well short of that limit, a covariance estimated from few rows is unstable, and the distances inherit that instability.
- Whether the data were scaled
- Every method here works on distances, and a distance adds up your columns' units. Standardizing puts each variable on the same footing before that sum is taken. Unscaled, the variable with the largest numeric range silently becomes the clustering. Income in pounds against age in years is a clustering of income. Turn scaling off only when the raw units are genuinely comparable and you mean to keep their relative weight.
- What a flag means
- That the combination of values is unusual for this dataset. Nothing about whether it is wrong. Inspect flagged rows; never delete them for being flagged. Report how many were flagged and what you did.
How this calculator is validated · Which statistical test should I use?