[R] Mahalanobis distance

Joris Meys jorismeys at gmail.com
Wed Jun 23 02:53:34 CEST 2010


Say X is your data matrix with the variable, then you could do :
 X <- matrix(rnorm(2100),300,7)
 S <- var(X)
 dist <- as.dist(
     apply(X,1,function(i){
         mahalanobis(X,i,S)
         }
     )
 )

Cheers
Joris

On Tue, Jun 22, 2010 at 11:41 PM, yoo hoo <freesuccess2001 at yahoo.com> wrote:
> I am a new R user.  i have a question about Mahalanobis distance.actually i have 300 rows and 7 columns. columns are different measurements, 300 rows are genes. since genes can
> classify into 4 categories. i used dist() with euclidean distance and cmdscale to do MDS plot. but find out Mahalanobis distance may be
> better. how do i use Mahalanobis() to generate similar dist object which i can use MDS plot? second question is if should i calculate mean for
> every categories for every measurement first and do 4*4 distance matrix, or i should calculate pairwise distance first and then find category
> means since i only care about relative position of 4 categories in MDS
> plot. Thank you very much.
>
>
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Joris Meys
Statistical consultant

Ghent University
Faculty of Bioscience Engineering
Department of Applied mathematics, biometrics and process control

tel : +32 9 264 59 87
Joris.Meys at Ugent.be
-------------------------------
Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php



More information about the R-help mailing list