[Rd] Incorrect Kendall's tau for ordered variables (PR#14207)

msa at biostat.mgh.harvard.edu msa at biostat.mgh.harvard.edu
Mon Feb 8 05:45:08 CET 2010


Full_Name: Marek Ancukiewicz
Version: 2.10.1
OS: Linux
Submission from: (NULL) (74.0.49.2)


Both cor() and cor.test() incorrectly handle ordered variables with 
method="kendall", cor() incorrectly handles ordered variables for 
method="spearman" (method="person" always works correctly, while 
method="spearman" works for cor.test, but not for cor()).

In erroneous calculations these functions ignore the inherent ordering
of the ordered variable (e.g., '9'<'10'<'11') and instead seem to assume 
an alphabetic ordering ('10'<'11'<'9'). 

> cor(9:11,1:3,method="k")
[1] 1
> cor(as.ordered(9:11),1:3,method="k")
[1] -0.3333333
> cor.test(as.ordered(9:11),1:3,method="k")

	Kendall's rank correlation tau

data:  as.ordered(9:11) and 1:3 
T = 1, p-value = 1
alternative hypothesis: true tau is not equal to 0 
sample estimates:
       tau 
-0.3333333 

> cor(9:11,1:3,method="s")
[1] 1
> cor(as.ordered(9:11),1:3,method="s")
[1] -0.5
> cor.test(as.ordered(9:11),1:3,method="s")

	Spearman's rank correlation rho

data:  as.ordered(9:11) and 1:3 
S = 0, p-value = 0.3333
alternative hypothesis: true rho is not equal to 0 
sample estimates:
rho 
  1



More information about the R-devel mailing list