[R] Spearman rank-order correlation matrix

Frank E Harrell Jr fharrell at virginia.edu
Tue May 7 17:09:55 CEST 2002


Also check out the rcorr function in the Hmisc library if you have very large matrices.  rcorr may be a bit faster, and it handles pairwise deletion of missing values.  rcorr accepts a matrix as its first argument.  -Frank Harrell

On Tue, 07 May 2002 10:19:52 -0400
John Fox <jfox at mcmaster.ca> wrote:

> Dear Russell,
> 
> At 04:52 PM 5/6/2002 -0700, Russell Senior wrote:
> 
> >I"ve got a data frame with a selection of columns I want to compute a
> >rank-order correlation matrix from without disturbing the original
> >data frame.
> >
> >   foo[,c("a","b","d","f","g")]
> >
> >What I wanted to do, intuitively, was:
> >
> >   > cor(rank(foo[,c("a","b","d","f","g")]))
> >
> >but rank in that context ranks all of the values from the matrix
> >together as one long vector.  I want the columns (and their names) to
> >be preserved, just replacing the value with its rank.  What is the
> >most direct way to get what I want?
> 
> Try
> 
>          cor(apply(foo[,c("a","b","d","f","g")], 2, rank))
> 
> I hope that this helps,
>   John
> 
> 
> 
> -----------------------------------------------------
> John Fox
> Department of Sociology
> McMaster University
> Hamilton, Ontario, Canada L8S 4M4
> email: jfox at mcmaster.ca
> phone: 905-525-9140x23604
> web: www.socsci.mcmaster.ca/jfox
> -----------------------------------------------------
> 
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


-- 
Frank E Harrell Jr              Prof. of Biostatistics & Statistics
Div. of Biostatistics & Epidem. Dept. of Health Evaluation Sciences
U. Virginia School of Medicine  http://hesweb1.med.virginia.edu/biostat
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list