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 |
center |
A vector of length equal to that of |
cov |
The covariance matrix |
pcov |
The pseudo covariance matrix |
inverted |
Boolean, if TRUE, |
... |
Optional arguments to be passed to solve, which is used for computing the inverse of |
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
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))