dot-mahalanobis_depth_cpp: Mahalanobis Depth

.mahalanobis_depth_cppR Documentation

Mahalanobis Depth

Description

Computes the Mahalanobis depth of one or more query points with respect to a reference distribution estimated from data.

Usage

.mahalanobis_depth_cpp(x, data, mu = NULL, sigma = NULL)

Arguments

x

Numeric matrix of query points (m x d), or a numeric vector of length d for a single query point.

data

Numeric matrix of reference data (n x d). Used to estimate the mean and covariance.

mu

Optional numeric vector of length d. If supplied, overrides the mean estimated from data.

sigma

Optional numeric matrix (d x d). If supplied, overrides the covariance estimated from data. Must be positive definite.

Details

Mahalanobis depth is defined as

D(x, F) = \frac{1}{1 + (x - \mu)^\top \Sigma^{-1} (x - \mu)}

where \mu and \Sigma are the mean vector and covariance matrix of F, estimated from data.

Note: The deepest point under this depth function is the mean vector, not a robust generalization of the median. Mahalanobis depth is included here as a computationally trivial baseline and for comparison purposes. For a genuine depth function, prefer simplicial_depth or tukey_depth.

Value

Numeric vector of depth values in (0, 1], one per query point. A value of 1 indicates the query point coincides with the center (mean). Values decrease toward 0 as points move away from the center.

Examples


set.seed(42)
data <- matrix(rnorm(200), nrow = 100, ncol = 2)
x    <- matrix(c(0, 0, 3, 3), nrow = 2, byrow = TRUE)
mahalanobis_depth(x, data)



depthR documentation built on June 26, 2026, 5:07 p.m.