Skip to contents

Drop-in replacement for mahalanobis that handles singular (rank-deficient) covariance matrices by falling back to the Moore–Penrose pseudoinverse via MASS::ginv.

Usage

robust_mahalanobis(x, center = NULL, cov = NULL, inverted = FALSE)

Arguments

x

Numeric matrix (samples x features) or vector.

center

Numeric vector of column means (length = number of features). If NULL, computed from x.

cov

Covariance matrix. If NULL, computed from x.

inverted

Logical; if TRUE, cov is already inverted.

Value

Named numeric vector of Mahalanobis distances.