Last data update: 2014.03.03

R: Mahalanobis Distance
mahaldisR Documentation

Mahalanobis Distance

Description

mahaldis measures the pairwise Mahalanobis (1936) distances between individual objects.

Usage

mahaldis(x)

Arguments

x

matrix containing the variables. NAs are not tolerated.

Details

mahaldis computes the Mahalanobis (1936) distances between individual objects. The Mahalanobis distance takes into account correlations among variables and does not depend on the scales of the variables.

mahaldis builds on the fact that type-II principal component analysis (PCA) preserves the Mahalanobis distance among objects (Legendre and Legendre 2012). Therefore, mahaldis first performs a type-II PCA on standardized variables, and then computes the Euclidean distances among (repositioned) objects whose positions are given in the matrix G. This is equivalent to the Mahalanobis distances in the space of the original variables (Legendre and Legendre 2012).

Value

an object of class dist.

Author(s)

Pierre Legendre pierre.legendre@umontreal.ca

http://www.bio.umontreal.ca/legendre/indexEn.html

Ported to FD by Etienne Laliberté.

References

Legendre, P. and L. Legendre (2012) Numerical Ecology. 3nd English edition. Amsterdam: Elsevier.

See Also

mahalanobis computes the Mahalanobis distances among groups of objects, not individual objects.

Examples

mat <- matrix(rnorm(100), 50, 20)

ex1 <- mahaldis(mat)

# check attributes
attributes(ex1)

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(FD)
Loading required package: ade4
Loading required package: ape
Loading required package: geometry
Loading required package: magic
Loading required package: abind
Loading required package: vegan
Loading required package: permute
Loading required package: lattice
This is vegan 2.4-0

Attaching package: 'vegan'

The following object is masked from 'package:ade4':

    cca

> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/FD/mahaldis.Rd_%03d_medium.png", width=480, height=480)
> ### Name: mahaldis
> ### Title: Mahalanobis Distance
> ### Aliases: mahaldis
> ### Keywords: multivariate
> 
> ### ** Examples
> 
> mat <- matrix(rnorm(100), 50, 20)
> 
> ex1 <- mahaldis(mat)
> 
> # check attributes
> attributes(ex1)
$Size
[1] 50

$Diag
[1] FALSE

$Upper
[1] FALSE

$method
[1] "Mahalanobis"

$call
dist(x = G)

$class
[1] "dist"

> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>