[R] Mahalanobis
Liaw, Andy
andy_liaw at merck.com
Fri Mar 26 22:02:40 CET 2004
If I'm not mistaken, the data you generated form a simplex in the
p-dimensional space. Mahalanobis distance for such data, using sample mean
and covariance, just give the distance to the centroid after normalization.
The normalization step make all the points equidistance from the centroid.
To see this, try generating 3 points in 2D, and plot the principal component
scores: You'll see the points on the vertices of a regular triangle.
Andy
> From: Alberto Murta
>
> Dear all
>
> Why isn'it possible to calculate Mahalanobis distances with R
> for a matrix
> with 1 row (observations) more than the number of columns (variables)?
>
> > mydata <- matrix(runif(12,-5,5), 4, 3)
> > mahalanobis(x=mydata, center=apply(mydata,2,mean), cov=var(mydata))
> [1] 2.25 2.25 2.25 2.25
>
> > mydata <- matrix(runif(420,-5,5), 21, 20)
> > mahalanobis(x=mydata, center=apply(mydata,2,mean), cov=var(mydata))
> [1] 19.04762 19.04762 19.04762 19.04762 19.04762 19.04762
> 19.04762 19.04762
> 19.04762 19.04762 19.04762 19.04762
> [13] 19.04762 19.04762 19.04762 19.04762 19.04762 19.04762
> 19.04762 19.04762
> 19.04762
>
> > mydata <- matrix(runif(132,-5,5), 12, 11)
> > mahalanobis(x=mydata, center=apply(mydata,2,mean), cov=var(mydata))
> [1] 10.08333 10.08333 10.08333 10.08333 10.08333 10.08333
> 10.08333 10.08333
> 10.08333 10.08333 10.08333 10.08333
>
> Thanks in advance
>
> Alberto Murta
>
> > version
> _
> platform i686-pc-linux-gnu
> arch i686
> os linux-gnu
> system i686, linux-gnu
> status
> major 1
> minor 8.1
> year 2003
> month 11
> day 21
> language R
>
> --
> Alberto G. Murta
> Institute for Agriculture and Fisheries Research (INIAP-IPIMAR)
> Av. Brasilia, 1449-006 Lisboa, Portugal | Phone: +351 213027062
> Fax:+351 213015948 | http://ipimar-iniap.ipimar.pt/pelagicos/
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
>
More information about the R-help
mailing list