[R] Mahalanobis Distance

jorgeA thetroopermail at gmail.com
Tue Sep 27 19:07:35 CEST 2011

Hello David(s),

First of all, thank you for your help.

I was running some tests, and I wish to know if I have correctly understood
your explanation. Well, when I use rbind(), I get the variables binded by
row, and when I use cbind() I get the variables binded by column.

The dist() function, as the help says, "computes and returns the distance
matrix computed by using the specified distance measure to compute the
distances between the rows of a data matrix", so, in that case I use rbind()
(as the help example does).

The mahalanobis() function help says "returns the squared Mahalanobis
distance of all rows in x and the vector mu = center with respect to Sigma =
cov.", so, here again, the calculations are done by row. Using cbind() I get
one result for each row like this:

mahalanobis(testeCbind, center = colMeans(testeCbind), cov=var(testeCbind))

I get as result 15 values (the number of rows).

With dist(), using euclidean and rbind() I get only one value (because is
calculated by row). 

Thinking on that way, mahalanobis distance is not so aproprietad for my kind
of input data. Am I correct? Or is there a way to make the calculation of
mahalanobis of all points and get only one value as the result of how
"distante" the variables (subseries) are?

Thank you all again.

Best regars,
Jorge Aikes Junior

View this message in context: http://r.789695.n4.nabble.com/Mahalanobis-Distance-tp3844960p3848247.html
Sent from the R help mailing list archive at Nabble.com.

More information about the R-help mailing list