mahal_dist {RRPP} | R Documentation |
Calculate the pairwise Mahalanobis distances between observations
Description
This function emulates the dist
function
but allows a covariance matrix (Cov) to be included for standardizing
distances. It is assumed that the Covariance matrix makes sense with
respect to the data, and that the number of variables match between data and covariance matrix.
Usage
mahal_dist(x, Cov, ...)
Arguments
x |
A numeric matrix of data frame. |
Cov |
A covariance matrix with the same number of variables as the data. |
... |
Other arguments passed to |
Details
No tests are performed on distances but could be performed with the
pairwise
function. Distances are only calculated if
the covariance matrix is not singular.
Value
An object of class "dist".
Author(s)
Michael Collyer
Examples
# Using the Pupfish data (see lm.rrpp help for more detail)
data(Pupfish)
Pupfish$Y <- ordinate(Pupfish$coords)$x[, 1:3]
fit <- lm.rrpp(Y ~ Sex * Pop, SS.type = "I",
data = Pupfish, print.progress = FALSE, iter = 0)
means <- unique(model.matrix(fit)) %*% coef(fit)
rownames(means) <- unique(interaction(Pupfish$Sex, Pupfish$Pop))
means
S <- getResCov(fit)
dist(means)
mahal_dist(means, S)
[Package RRPP version 2.1.2 Index]