[R] Mahalanobis
Alberto Murta
amurta at ipimar.pt
Fri Mar 26 19:39:23 CET 2004
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/
More information about the R-help
mailing list