Skip to contents

Computes the squared Mahalanobis distance of all rows in x.

Usage

# S4 method for CompositionMatrix
mahalanobis(x, center, cov, ..., robust = TRUE, method = c("mve", "mcd"))

# S4 method for ILR
mahalanobis(x, center, cov, ..., robust = TRUE, method = c("mve", "mcd"))

Arguments

x

A CompositionMatrix or an ILR object.

center

A numeric vector giving the mean vector of the distribution. If missing, will be estimated from x.

cov

A numeric matrix giving the covariance of the distribution. If missing, will be estimated from x.

...

Extra parameters to be passed to MASS::cov.rob(). Only used if robust is TRUE.

robust

A logical scalar: should robust location and scatter estimation be used?

method

A character string specifying the method to be used. It must be one of "mve" (minimum volume ellipsoid) or "mcd" (minimum covariance determinant). Only used if robust is TRUE.

Value

A numeric vector.

See also

Author

N. Frerebeau

Examples

## Data from Aitchison 1986
data("hongite")

## Coerce to compositional data
coda <- as_composition(hongite)

## Mahalanobis distance
mahalanobis(coda)
#> 
#>         H1         H2         H3         H4         H5         H6         H7 
#>  5.1307933  0.5074407  2.1126269  2.8998211 19.0843749  5.6475980 33.6658536 
#>         H8         H9        H10        H11        H12        H13        H14 
#> 25.7137516  1.2502063 56.7461076  1.7542646  5.9925765  4.5827167 22.1196584 
#>        H15        H16        H17        H18        H19        H20        H21 
#>  1.9526275 25.7147694  7.6312860  2.1336759  2.5354194  4.4406867  2.3685685 
#>        H22        H23        H24        H25 
#>  3.7668943 25.9902036  6.7638903  6.5289073