Kendall's Tau-b

The correlation between two variables, ${\displaystyle x}$ and ${\displaystyle y}$, is:

${\displaystyle \tau _{b}={\frac {n_{c}-n_{d}}{\sqrt {(n_{t}-n_{x})(n_{t}-n_{y})}}}}$

where

${\displaystyle n_{c}=\sum _{i=1}^{n}\sum _{j=1}^{n}w_{i}(I_{x_{i}>x_{j},y_{i}>y_{j}}+I_{x_{i}>x_{j},y_{i}>y_{j}})}$,
${\displaystyle n_{d}=\sum _{i=1}^{n}\sum _{j=1}^{n}w_{i}(I_{x_{i}y_{j}}+I_{x_{i}>x_{j},y_{i},
${\displaystyle n_{w}=\sum _{i=1}^{n}w_{i}}$,
${\displaystyle n_{t}={\frac {n_{w}(n_{w}-1)}{2}}}$,
${\displaystyle n_{x}=\sum _{j=1}^{t}\sum _{i=n}^{n}w_{i}I_{x_{i}=j}}$,
${\displaystyle n_{y}=\sum _{j=1}^{r}\sum _{i=n}^{n}w_{i}I_{y_{i}=j}}$,
${\displaystyle w_{i}}$ is the Calibrated Weight for the ${\displaystyle i}$th of ${\displaystyle n}$ is the number of observations,
${\displaystyle x}$ is a variable with ${\displaystyle t}$ unique values, categorised in the range ${\displaystyle {1,2,..,t}}$,
${\displaystyle y}$ is a variable with ${\displaystyle r}$ unique values, categorised in the range ${\displaystyle {1,2,..,r}}$,

The tests statistic is:

${\displaystyle z={n_{c}-n_{d} \over {\sqrt {v}}}}$

where

${\displaystyle v=(v_{0}-v_{x}-v_{y})/18+v_{1}+v_{2}}$,
${\displaystyle v_{0}=n(n-1)(2n+5)}$,
${\displaystyle v_{x}=\sum _{j}t_{xj}(t_{xj}-1)(2t_{xj}+5)}$,
${\displaystyle v_{y}=\sum _{j}t_{yj}t_{yj}-1)(2t_{yj}+5)}$,
${\displaystyle v_{1}=\sum _{j=1}^{r}t_{xj}(t_{xj}-1)(t_{xj}-2)}$,
${\displaystyle v_{2}=\sum _{j=1}^{t}t_{yj}(t_{yj}-1)(t_{yj}-2)}$,
${\displaystyle v_{3}=(v1v2)/(9n_{w}(n_{w}-1)(n_{w}-2))}$,
${\displaystyle v_{4}=\sum _{j=1}^{r}t_{xj}(t_{xj}-1)}$,
${\displaystyle v_{5}=\sum _{j=1}^{t}t_{yj}(t_{yj}-1)}$,
${\displaystyle v_{6}=(v_{4}v_{5})/(2n_{w}(n_{w}-1))}$,
${\displaystyle {\hat {\sigma }}=(v_{0}-v_{x}-v_{y})/18+v3+v6}$,
${\displaystyle z={\frac {n_{c}-n_{d}}{\hat {\sigma }}}}$,
${\displaystyle p\approx 2(1-\Phi (|z|))}$