2
$\begingroup$

I am trying to calculate Kendall’s tau coefficient for example given by Scipy in python. It is for tied ranks with tau-b version. The tau should be -0.47140452079103173 but I get a different result. I use formulas in "Handbook of Parametric and Nonparametric. Statistical Procedures. David J. Sheskin. Chapman & Hall/CRC." page 900.

$$x = [12, 2, 1, 12, 2]$$ $$y = [1, 4, 7, 1, 0]$$

rank the data: $$rank x = [4.5, 2.5, 1, 4.5, 2.5]$$ $$rank y = [2.5, 4, 5, 2.5, 1]$$

dimensions: $n=5, m=2 $ $$rank x+rank y = [7, 6.5, 6, 7, 3.5]$$ $$T=7+6.5+6+7+3.5=30$$ $$U=7^2+6.5^2+6^2+7^2+3.5^2=188.5$$

calculate the tie correlation(${\displaystyle\sum_{i=1}^m}{\displaystyle\sum_{a=1}^s}(t^3-t)$):

in x there are 2 tied groups each with 2 members: $(2^3-2)+(2^3-2)=12$

in y there is 1 tied group with 2 members: $(2^3-2)= 6$

total tie correlations: $12+6=18$

$$W=\frac{12U-3m^2n(n+1)^2}{m^2n(n^2-1)-m{\displaystyle\sum_{i=1}^m}{\displaystyle\sum_{a=1}^s}(t^3-t)}=\frac{12(188.5)-3\times 2^2\times 5(5+1)^2}{2^2\times5(5^2-1)-2(18)}=0.22973$$

Sorry for the low-quality question. there are not many numeric questions for tau-b. I hope this question can be helpful also for others who review python's example.

$\endgroup$
4
  • 1
    $\begingroup$ Scipy may use an adjusted algorithm for the calculation. Have you taken a look at the code? $\endgroup$
    – Jon
    Commented Feb 10, 2017 at 21:48
  • $\begingroup$ You say you used the " formulas in "Handbook of Parametric and Nonparametric. ". Are these all listed out? Otherwise, readers may not know which formulas/algorithms you are referring to. $\endgroup$
    – Jon
    Commented Feb 10, 2017 at 21:49
  • $\begingroup$ Also, there appear to be multiple algorithms for Kendall's tau: en.wikipedia.org/wiki/Kendall_rank_correlation_coefficient. It'll be useful to know which Scipy is using. $\endgroup$
    – Jon
    Commented Feb 10, 2017 at 21:51
  • $\begingroup$ @jon the formula is the one written in the question. $\endgroup$
    – Sadegh
    Commented Feb 10, 2017 at 22:40

1 Answer 1

4
$\begingroup$

The formula you are using is calculating Kendall's W, also known as Kendall's coefficient of concordance. Kendall's W not the same as Kendall's tau-b.

To calculate the Kendall tau-b for the given data set, you can use the formula in the Wikipedia page. I count $n_0=10$, $n_1=2$, $n_2=1$, $n_c=2$, $n_d=6$, so that $$ \tau_B=\frac{ 2-6}{\sqrt{(10-2)(10-1)}}=-\frac4{\sqrt{72}}=-.4714045. $$

EDIT: How to calculate $n_1$? We see that $x$ has two groups of ties, namely $\{2,2\}$ and $\{12,12\}$, each with two ties per group, so $t_1=2$ and $t_2=2$ and $$n_1:=\frac12\sum_it_i(t_i-1)=\frac12(2\cdot1)+\frac12(2\cdot1)=2.$$ As for $n_2$, we see that $y$ has one group of ties, namely $\{1,1\}$, so $u_1=2$ and $$n_2:=\frac12\sum_ju_j(u_j-1)=\frac12(2\cdot1)=1.$$

$\endgroup$
9
  • $\begingroup$ thanks for the answer. I will take a look and then accept it. about the calculation of U, I used ranks not vectors itself. $\endgroup$
    – Sadegh
    Commented Feb 10, 2017 at 22:44
  • $\begingroup$ @Woeitg You are right about the ranks. I can't believe I missed that! $\endgroup$
    – grand_chat
    Commented Feb 10, 2017 at 22:45
  • $\begingroup$ well, actually I did that mistake in the first place and then modify the question. maybe you saw it before modification. Now I add more modification to clarify it. $\endgroup$
    – Sadegh
    Commented Feb 10, 2017 at 22:48
  • $\begingroup$ @Woeitg Right, I recall you got a value of $W$ that was much higher than 1. $\endgroup$
    – grand_chat
    Commented Feb 10, 2017 at 22:50
  • $\begingroup$ Can you add steps for calculating n1 and n2? number of ties in x is 2 (there are two group of similar values) and 1 (there is one group of similar value). feed it in formula gives n1=(2(2-1)/2)+(2(2-1)/2+0+(2(2-1)/2)+(2(2-1)/2=4 $\endgroup$
    – Sadegh
    Commented Feb 10, 2017 at 23:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.