mahalanobis {complexlm}R Documentation

Mahalanobis Distance, with better complex behavior

Description

The Mahalanobis distance function included in the stats package returns a complex number when given complex values of x. But a distance (and thus its square) is always positive real. This function calculates the Mahalanobis distance using the conjugate transpose if given complex data, otherwise it calls stats::mahalanobis.

Usage

mahalanobis(x, center, cov, pcov = NULL, inverted = FALSE, ...)

Arguments

x

A length p vector or matrix with row length p. Or, a length 2p vector or matrix with row length 2p.

center

A vector of length equal to that of x.

cov

The covariance matrix (p x p) of the distribution. Or, the "double covariance matrix" of the distribution, which contains the information from cov and pcov in a single (2p x 2p) matrix. Can be generated by matrixweave, vcov.zlm, or vcov.rzlm. vcov.rzlm].

pcov

The pseudo covariance matrix (p x p) of the distribution. Optional.

inverted

Boolean, if TRUE, cov and pcov are not taken to be the inverse covariance and pseudo covariance matrices.

...

Optional arguments to be passed to solve, which is used for computing the inverse of cov. If inverted = TRUE, unused.

Details

Depending on the relative sizes of x, cov, and pcov, the function will perform slightly different calculations. If pcov is not included, the Mahalanobis distance is calculated using only cov. In this case if the dimension of cov is twice that of x, x is interleaved with its complex conjugate so that it becomes the same length as cov. Note that in this case the resulting Mahalanobis distance will only incorporate information about the interactions between the real and imaginary components if the "double covariance matrix is given as cov . If pcov is included in the input, pcov and cov are interleaved to form the "double covariance", and this is used to calculate the Mahalanobis distance, interleaving x if necessary. This gives the user a great deal of flexibility when it comes to input.

Value

numeric. The squared Mahalanobis distance (divergence) between x and center.

References

D. Dai and Y. Liang, High-Dimensional Mahalanobis Distances of Complex Random Vectors, Mathematics 9, 1877 (2021).

See Also

matrixweave

Examples

set.seed(4242)
n <- 8
x <- matrix(complex(real = rnorm(n), imaginary = rnorm(n)), ncol = 2)
mu <- complex(real = 1.4, imaginary = 0.4)
sigma <- 3.4
mahalanobis(x, mu, sigma * diag(2))

[Package complexlm version 1.1.2 Index]