Hi, I am not sure I am using correctly the mahalanobis distnace method... Suppose I have a response variable Y and predictor variables X1 and X2 all <- cbind(Y, X1, X2) mahalanobis(all, colMeans(all), cov(all)); However, my results from this are different from the ones I am getting using another statistical software. I was reading that the comparison is with the means of the predictor variables which led me to think that the above should be transformed into: predictors <- cbind(X1, X2) mahalanobis(all, colMeans(predictors), cov(all)) But still the results are different.... Am I doing something wrong or have I misunderstood something in the use of the function mahalanobis? Thanks. -- yianni
On 31/05/07, Anup Nandialath <anup_nandialath at yahoo.com> wrote:> oops forgot the example example > > try this line > > sqrt(mahalanobis(all, colMeans(predictors), cov(all), FALSE)Hi and thanks for the reply Anup. Unfortunately, I had a look on the example before posting but not much of a help... I did some further tests and in order to have the same results I must run mahalanobis with the predictors only dataset, ie. mahalanobis(predictors, colMeans(predictors), cov(predictors)). Now, on a first glance it seems to me a bit strange that the influence of these points on a regression are measured without taking into account the response variable (provided that the other stat software calculates the mahalanobis distances correctly).... but I guess this is something that I have to resolve by doing some studying on my own on the mahalanobis distance... thanks again.> > now cross check with other software > > best > > Anup > > > ________________________________ > No need to miss a message. Get email on-the-go > with Yahoo! Mail for Mobile. Get started. > >-- yianni
Yianni You probably would have gotten more helpful replies if you indicated the substantiative problem you were trying to solve. From your description, it seems like you want to calculate leverage of predictors, (X1, X2) in the lm( y ~ X1+X2). My crystal ball says you may be an SPSS user, for whom mahalanobis D^2 of the predictors is what you have to beg for to get leverages. In R, you will get the most happiness from ?leverage.plot in the car package. mahalanobois D^2 are proportional to leverage. -Michael gatemaze at gmail.com wrote:> Hi, I am not sure I am using correctly the mahalanobis distnace method... > Suppose I have a response variable Y and predictor variables X1 and X2 > > all <- cbind(Y, X1, X2) > mahalanobis(all, colMeans(all), cov(all)); > > However, my results from this are different from the ones I am getting > using another statistical software. > > I was reading that the comparison is with the means of the predictor > variables which led me to think that the above should be transformed > into: > > predictors <- cbind(X1, X2) > mahalanobis(all, colMeans(predictors), cov(all)) > > But still the results are different.... > > Am I doing something wrong or have I misunderstood something in the > use of the function mahalanobis? Thanks. >-- Michael Friendly Email: friendly AT yorku DOT ca Professor, Psychology Dept. York University Voice: 416 736-5115 x66249 Fax: 416 736-5814 4700 Keele Street http://www.math.yorku.ca/SCS/friendly.html Toronto, ONT M3J 1P3 CANADA