Re: [R] S in cor.test(..., method="spearman")

From: Sundar Dorai-Raj <sundar.dorai-raj_at_pdf.com>
Date: Wed 13 Sep 2006 - 15:31:12 GMT

Dietrich Trenkler said the following on 9/13/2006 9:44 AM:
> Dear HelpeRs,
>
> I have some data:
>
> "ice" <- structure(c(0.386, 0.374, 0.393, 0.425, 0.406, 0.344,
> 0.327, 0.288, 0.269, 0.256, 0.286, 0.298, 0.329, 0.318, 0.381,
> 0.381, 0.47, 0.443, 0.386, 0.342, 0.319, 0.307, 0.284, 0.326,
> 0.309, 0.359, 0.376, 0.416, 0.437, 0.548, 41, 56, 63, 68,
> 69, 65, 61, 47, 32, 24, 28, 26, 32, 40, 55, 63, 72, 72, 67,
> 60, 44, 40, 32, 27, 28, 33, 41, 52, 64, 71), .Dim = as.integer(c(30,
> 2)))
>
> Using
>
> cor.test(ice[,1],ice[,2],method="spearman")
>
> I get (apart from a warning message due to ties)
>
> Spearman's rank correlation rho
>
> data: ice[, 1] and ice[, 2]
> S = 769.4403, p-value = 1.543e-08
> alternative hypothesis: true rho is not equal to 0
> sample estimates:
> rho
> 0.828823
>
> I wonder what S is. I presume it is
>
> sum((rank(ice[,1])-rank(ice[,2]))^2),
>
> but this delivers 768.5. Is it the way ranks are computed in cor.test?
>
>
> Thank you in advance.
>
> D. Trenkler
>

Looking at the code will help. Try

stats:::cor.test.default

This reveals that S is determined by:

x <- ice[, 1]
y <- ice[, 2]
n <- nrow(ice)
r <- cor(rank(x), rank(y))
S <- (n^3 - n) * (1 - r)/6

S
## [1] 769.4403

See ?cor.test as to definition of "S".

HTH, --sundar



R-help@stat.math.ethz.ch 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. Received on Thu Sep 14 01:35:14 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 13 Sep 2006 - 16:30:17 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.