Skip to contents

Computes the squared Mahalanobis distance of all rows in x.

Usage

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

# S4 method for class '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 
#>  4.8416641  0.5268597  2.8217025  0.7805709 20.4639923  6.8908961 33.2466487 
#>         H8         H9        H10        H11        H12        H13        H14 
#> 32.3471329  1.7015288  8.5956701  2.0374883  5.8768012  5.7154573 11.3813839 
#>        H15        H16        H17        H18        H19        H20        H21 
#>  1.9683500  8.3199851 15.0207721  1.8352990  2.8291314  4.6339628  1.4407278 
#>        H22        H23        H24        H25 
#>  1.0102074  4.9903095  2.1507501  7.0326380