# Kendall’s tau-b version calculation steps with tied ranks

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.

• Scipy may use an adjusted algorithm for the calculation. Have you taken a look at the code? – Jon Feb 10 '17 at 21:48
• 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. – Jon Feb 10 '17 at 21:49
• 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. – Jon Feb 10 '17 at 21:51
• @jon the formula is the one written in the question. – Woeitg Feb 10 '17 at 22:40

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.$$
• @Woeitg Right, I recall you got a value of $W$ that was much higher than 1. – grand_chat Feb 10 '17 at 22:50