Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Kendall の順位相関係数(Kendall’s τ)

Kendall の τ\tau は観測値の全ペアの数に対する順序が一致(concordant)/ 不一致(discordant)のペアの数の比率のように定義される相関係数

定義式

τ=CD(n2)\tau = \frac{C - D}{\binom{n}{2}}
  • CC:一致ペア数

  • DD:不一致ペア数

  • (n2)\binom{n}{2}:全ペア数

  • 順位が完全に一致している(すなわちD=0D = 0)ならτ=+1\tau = +1

  • 順位が完全に不一致(すなわちC=0C = 0)ならτ=1\tau = -1

特徴

  • 単調関係を捉える

  • ノイズが強い場合に Spearman より安定する場合がある

  • 値域は [1,1][-1,1]

Source
from scipy.stats import kendalltau
import matplotlib.pyplot as plt
import numpy as np

fig, axes = plt.subplots(figsize=[10, 2.5], ncols=3)

true_r = 0.75
mu = np.array([0.0, 0.0])
Sigma = np.array([[1.0, true_r], [true_r, 1.0]])
samples = np.random.multivariate_normal(mu, Sigma, size=100)
x = samples[:, 0]
y = samples[:, 1]
axes[0].scatter(x, y)
axes[0].set_title(f"Kendall's τ = {kendalltau(x, y).statistic:.3f}")

x = np.linspace(-10, 10, 15)
y = 1 / (1 + np.exp(-x))
axes[1].scatter(x, y)
axes[1].set_title(f"Kendall's τ = {kendalltau(x, y).statistic:.3f}")

x = np.linspace(-3.14,3.14, 100)
y = x**2 + np.random.random(len(x))
axes[2].scatter(x, y)
axes[2].set_title(f"Kendall's τ = {kendalltau(x, y).statistic:.3f}")

%matplotlib inline
<Figure size 1000x250 with 3 Axes>