Learn R Programming

resemble (version 3.0.1)

diss_mahalanobis: 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^TWM^-1 = W'W (using SVD), then applying Euclidean distance in that transformed space:

d(x_i, x_j) = 1p(x_i - x_j)M^-1(x_i - x_j)^Td(x_i, x_j) = sqrt(1/p * (x_i - x_j) M^-1 (x_i - x_j)^T)

Usage

diss_mahalanobis(center = TRUE, scale = FALSE)

Value

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

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.

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.

See Also

dissimilarity, diss_euclidean, diss_cosine

Examples

Run this code
m <- diss_mahalanobis()
m <- diss_mahalanobis(center = TRUE, scale = TRUE)

Run the code above in your browser using DataLab