diss_mahalanobis: Mahalanobis dissimilarity method constructor

View source: R/diss_methods.R

diss_mahalanobisR Documentation

Mahalanobis dissimilarity method constructor

Description

Creates a configuration object for computing Mahalanobis dissimilarity. Pass the result to dissimilarity() to compute the dissimilarity matrix.

The Mahalanobis distance is computed by first transforming the data into Mahalanobis space via a factorization of the inverse covariance matrix M^{-1} = W^{T}W (using SVD), then applying Euclidean distance in that transformed space:

d(x_i, x_j) = \sqrt{\frac{1}{p}(x_i - x_j)M^{-1}(x_i - x_j)^T}

Usage

diss_mahalanobis(center = TRUE, scale = FALSE)

Arguments

center

Logical. Center the data before computing distances? Applied jointly to Xr and Xu if both are provided. Default TRUE.

scale

Logical. Scale the data before computing distances? Applied jointly to Xr and Xu if both are provided. Default FALSE.

Value

An object of class c("diss_mahalanobis", "diss_method").

Important limitations

The covariance matrix will be singular — and the distance therefore uncomputable — when the number of observations is smaller than the number of variables, or when variables are perfectly collinear. This is common with raw spectral data; consider using diss_euclidean() on PCA scores instead.

Author(s)

Leonardo Ramirez-Lopez

See Also

dissimilarity, diss_euclidean, diss_cosine

Examples

m <- diss_mahalanobis()
m <- diss_mahalanobis(center = TRUE, scale = TRUE)

resemble documentation built on April 21, 2026, 1:07 a.m.