Greetings. There seems to be a problem with the P-value computation in the cor.test with method="spearman". In R1.8.0 (MS Windows) I seem to be getting intermittently nonsense P-values, but the rho's are OK. I can get this reproducibly with the toy example attached where the first use is OK and subsequent calls with the same data give nonsense. (I have also seen the problem without the warning about duplicated values.) The toy example behaves correctly under 1.7.1. Steve. ---Script--- x<-1:100 y<-rep(c(2,3,4,5),25) cor.test(x,y,m="p") cor.test(x,y,m="s") cor.test(x,y,m="s") cor.test(x,y,m="k") ---Output-- R : Copyright 2003, The R Development Core Team Version 1.8.0 (2003-10-08) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for a HTML browser interface to help. Type 'q()' to quit R.> x<-1:100 > y<-rep(c(2,3,4,5),25) > cor.test(x,y,m="p")Pearson's product-moment correlation data: x and y t = 0.3837, df = 98, p-value = 0.702 alternative hypothesis: true correlation is not equal to 0 95 percent confidence interval: -0.1588952 0.2333745 sample estimates: cor 0.03873177> cor.test(x,y,m="s")Spearman's rank correlation rho data: x and y S = 160195, p-value = 0.7015 alternative hypothesis: true rho is not equal to 0 sample estimates: rho 0.03873177 Warning message: p-values may be incorrect due to ties in: cor.test.default(x, y, m = "s")> cor.test(x,y,m="s")Spearman's rank correlation rho data: x and y S = 160195, p-value = < 2.2e-16 alternative hypothesis: true rho is not equal to 0 sample estimates: rho 0.03873177 Warning message: p-values may be incorrect due to ties in: cor.test.default(x, y, m = "s")> cor.test(x,y,m="k")Kendall's rank correlation tau data: x and y z = 0.5132, p-value = 0.6078 alternative hypothesis: true tau is not equal to 0 sample estimates: tau 0.03481553>Dr Steve Roberts steve.roberts at man.ac.uk Senior Lecturer in Medical Statistics, CMMCH NHS Trust and University of Manchester Biostatistics Group, 0161 275 5192 / 0161 276 5785
It works fine for me, on a Sun.> x<-1:100 > y<-rep(c(2,3,4,5),25) > cor.test(x,y,m="p")Pearson's product-moment correlation data: x and y t = 0.3837, df = 98, p-value = 0.702 alternative hypothesis: true correlation is not equal to 0 95 percent confidence interval: -0.1588952 0.2333745 sample estimates: cor 0.03873177> cor.test(x,y,m="s")Spearman's rank correlation rho data: x and y S = 160195, p-value = 0.7015 alternative hypothesis: true rho is not equal to 0 sample estimates: rho 0.03873177 Warning message: p-values may be incorrect due to ties in: cor.test.default(x, y, m = "s")> cor.test(x,y,m="s")Spearman's rank correlation rho data: x and y S = 160195, p-value = 0.7015 alternative hypothesis: true rho is not equal to 0 sample estimates: rho 0.03873177 Warning message: p-values may be incorrect due to ties in: cor.test.default(x, y, m = "s")> cor.test(x,y,m="k")Kendall's rank correlation tau data: x and y z = 0.5132, p-value = 0.6078 alternative hypothesis: true tau is not equal to 0 sample estimates: tau 0.03481553 -- __________________________________________________ [ ] [ Giovanni Petris GPetris at uark.edu ] [ Department of Mathematical Sciences ] [ University of Arkansas - Fayetteville, AR 72701 ] [ Ph: (479) 575-6324, 575-8630 (fax) ] [ http://definetti.uark.edu/~gpetris/ ] [__________________________________________________]
On Fri, 2003-11-07 at 08:45, Steve Roberts wrote:> Greetings. > > There seems to be a problem with the P-value computation in the > cor.test with method="spearman". In R1.8.0 (MS Windows) I > seem to be getting intermittently nonsense P-values, but the rho's > are OK. I can get this reproducibly with the toy example attached > where the first use is OK and subsequent calls with the same data > give nonsense. (I have also seen the problem without the warning > about duplicated values.) The toy example behaves correctly under > 1.7.1. >SNIP This is PR#4718, which appears to be fixed in R 1.8.1: http://r-bugs.biostat.ku.dk/cgi-bin/R/Analyses-fixed?user=guest;selectid=4718 I don't know that a pre-compiled version of r-patched for Windows is available. If not, then the 'rcorr' function in Frank Harrell's Hmisc package my be a short term solution for you until R 1.8.1 becomes available. HTH, Marc Schwartz
Maybe Matching Threads
- cor.test(method = spearman, exact = TRUE) not exact (PR#14095)
- S in cor.test(..., method="spearman")
- cor(..., method="spearman") or cor(..., method="kendall") (PR#6641)
- bug in cor.test(method = "spearman")
- Wrong result with cor(x, y, method="spearman", use="complete.obs") with NA's???