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.
mahalanobis(x, center, cov, pcov = NULL, inverted = FALSE, ...)numeric. The squared Mahalanobis distance (divergence) between x and center.
A length \(p\) vector or matrix with row length \(p\). Or, a length \(2p\) vector or matrix with row length \(2p\).
A vector of length equal to that of x.
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].
The pseudo covariance matrix \((p x p)\) of the distribution. Optional.
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.
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.
D. Dai and Y. Liang, High-Dimensional Mahalanobis Distances of Complex Random Vectors, Mathematics 9, 1877 (2021).
matrixweave
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))
Run the code above in your browser using DataLab