Mahalanobis distance measures how far an observation is from the center of a multivariate distribution after accounting for scale (variance) and correlation (covariance). Unlike Euclidean distance, it adapts to the “shape” of the data cloud: directions with high variance contribute less, and correlated variables are treated appropriately. This makes the metric useful for outlier detection, anomaly scoring, clustering, and multivariate quality control.
This calculator is for the two-variable case, where you provide an observation vector x, a mean vector μ, and a 2×2 covariance matrix Σ.
Let x be your observation and μ be the mean of the reference distribution. Define the centered vector:
v = x − μ
The (squared) Mahalanobis distance is:
And the distance is D = √(D²).
In two dimensions:
x = (x1, x2)T, μ = (μ1, μ2)T, and
Σ = [ [σ11, σ12], [σ21, σ22] ]
The determinant of the covariance matrix is:
det(Σ) = σ11σ22 − σ12σ21
If det(Σ) ≠ 0, then the inverse is:
Σ−1 = (1 / det(Σ)) · [ [σ22, −σ12], [−σ21, σ11] ]
Let v1 = x1 − μ1 and v2 = x2 − μ2. Then:
D² = [v1 v2−1 · [v1, v2]T
Interpretation depends on assumptions about your reference distribution and on the number of dimensions. In the special (but common) case where the data are approximately multivariate normal with k variables, the statistic D² approximately follows a chi-square distribution with k degrees of freedom.
For this page (k = 2):
| Coverage (inside contour) | Chi-square cutoff for D² (df = 2) | Equivalent D = √(cutoff) | Practical interpretation |
|---|---|---|---|
| ≈ 68% | ≈ 2.28 | ≈ 1.51 | “Near typical” in 2D (analogous to 1σ idea, but not identical) |
| ≈ 95% | ≈ 5.99 | ≈ 2.45 | Common outlier screening boundary |
| ≈ 99% | ≈ 9.21 | ≈ 3.03 | Stronger anomaly flag (fewer false positives) |
These numbers are guidelines, not universal rules. If your data are heavy-tailed, skewed, multi-modal, or the mean/covariance estimates are unstable, then “chi-square thresholds” can be misleading.
Suppose your two variables are (1) height and (2) weight. Let the reference mean be μ = (170, 70). Let the covariance matrix be:
Σ = [ [36, 30], [30, 100] ]
Interpretation: variance of height is 36 (sd 6), variance of weight is 100 (sd 10), and covariance is 30 (positive correlation).
Now evaluate the observation x = (180, 90):
Compute D²:
Interpretation: In 2D, D ≈ 2.143 corresponds to D² ≈ 4.59, which is below the 95% cutoff (5.99). Under an approximately bivariate normal reference, this point is somewhat unusual but not extreme enough to be outside a common 95% ellipse.
It measures how far a point is from a distribution’s mean after accounting for variance and correlation—effectively a covariance-adjusted “number of standard deviations” in multivariate space.
Covariance captures both scaling (variances) and correlation (how variables move together). Mahalanobis distance down-weights directions with high variance and corrects for correlated axes, unlike Euclidean distance.
A valid covariance matrix is symmetric. If they differ, you likely have a data entry error. Consider setting both to the same value (often the estimated covariance between the two variables).
It means det(Σ) ≠ 0 so Σ has a well-defined inverse. If the variables are perfectly (or near-perfectly) linearly dependent, Σ becomes singular (non-invertible) and Mahalanobis distance cannot be computed reliably.
If a multivariate normal approximation is reasonable, use D² cutoffs from the chi-square distribution with k degrees of freedom (here k = 2). For example, the 95% cutoff is D² ≈ 5.99 (D ≈ 2.45). Otherwise, consider empirical/robust thresholds.