Mahalanobis: Classical and Robust Mahalanobis Distances

View source: R/Mahalanobis.R

MahalanobisR Documentation

Classical and Robust Mahalanobis Distances

Description

This function is a convenience wrapper to stats::mahalanobis() offering also the possibility to calculate robust Mahalanobis squared distances using MCD and MVE estimators of center and covariance (from MASS::cov.rob())

Usage

Mahalanobis(
  x,
  center,
  cov,
  method = c("classical", "mcd", "mve"),
  nsamp = "best",
  ...
)

Arguments

x

a numeric matrix or data frame with, say, p columns

center

mean vector of the data; if this and cov are both supplied, the function simply calls stats::mahalanobis() to calculate the result

cov

covariance matrix (p x p) of the data

method

estimation method used for center and covariance, one of: "classical" (product-moment), "mcd" (minimum covariance determinant), or "mve" (minimum volume ellipsoid).

nsamp

passed to MASS::cov.rob()

...

other arguments passed to MASS::cov.rob()

Details

Any missing data in a row of x causes NA to be returned for that row.

Value

 a vector of length `nrow(x)` containing the squared distances.

Author(s)

Michael Friendly

See Also

stats::mahalanobis(), MASS::cov.rob()

Other robust methods: plot.robmlm(), robmlm()

Examples


summary(Mahalanobis(iris[, 1:4]))
summary(Mahalanobis(iris[, 1:4], method="mve"))
summary(Mahalanobis(iris[, 1:4], method="mcd"))



heplots documentation built on Sept. 13, 2026, 5:06 p.m.