[R] spearman correction

Peter Dalgaard p.dalgaard at biostat.ku.dk
Wed Dec 1 12:34:57 CET 2004


Prof Brian Ripley <ripley at stats.ox.ac.uk> writes:

> On Wed, 1 Dec 2004, Branimir K. Hackenberger wrote:
> 
> > Who knows which correction (by tied numbers) is used by Spearman-test in
> > function cor.test (e.g. cor.test(a,b,method="spearman"))?
> 
> Anyone who reads the sources!  The critical line in cor.test.default is
> 
>              r <- cor(rank(x), rank(y))
> 
> so it uses rank(), and that averages ranks of tied observations.

...and correcting the p value for that is on the wish list for some of
us. 

As far as I remember, that is quite easy to do in the asymptotic
approximation (but hard to do exactly): Start by working out the
covariance matrix of the y ranks given the tied sets of values; a
matrix with compound symmetry, obviously, and with rows/columns
summing to zero since the sum of the ranks is known, so you really
just need the variance of ry_1. Then note that the statistic is
equivalent to sum(rx*ry) which, conditionally on the values of x (and
y), has the distribution of a linear combination of the ry, the
variance of which is...

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907




More information about the R-help mailing list