ケンドールの順位相関係数(Kendall’s tau)#
順序尺度 × 順序尺度(ランキング)に対して使われる相関指標で、順位の一致/不一致ペア数に基づいて計算される
kendalltau — SciPy v1.15.2 Manual
\[
\tau=\frac{n_c-n_d}{\sqrt{\left(n_0-n_1\right)\left(n_0-n_2\right)}}
\]
\(n_c\) :一致順(concordant)のペアの数
\(n_d\) :不一致順(discordant)のペアの数
\(n_0=\frac{n(n-1)}{2}:\) すべてのペアの総数
\(n_1=\sum t_i\left(t_i-1\right) / 2\) :Xで順位が同じぺアの数の補正(ties in X)
\(n_2=\sum u_j\left(u_j-1\right) / 2\) :Yで順位が同じぺアの数の補正(ties in Y)
x = [1, 1, 2, 2, 3, 3]
y = [0, 0, 0, 1, 1, 1]
from scipy.stats import kendalltau
print(f"{kendalltau(x, y).statistic=:.3f}")
from ordinalcorr import polychoric
print(f"{polychoric(x, y)=:.3f}")
kendalltau(x, y).statistic=0.770
polychoric(x, y)=0.999