置換検定

Pythonで学ぶ推測の基礎

Paul Savala

Assistant Professor of Mathematics

置換検定

異なる色の小さな人物が2つのグループに分かれている。

Pythonで学ぶ推測の基礎

置換検定

  • サンプルをシャッフル
  • 結果を記録
  • 観測差は偶然の範囲か?

小さな人物が入れ替わっている。

Pythonで学ぶ推測の基礎

SciPyでの置換検定

new_satisfaction = [94, 85, 79, 91, 82]
old_satisfcation = [90, 87, 77, 85, 82]

# Group together our data data = (new_satisfaction, old_satisfcation)
# Define our test statistic def statistic(x, y): return np.mean(x) - np.mean(y)
# Compute a permutation test for the difference in means stats.permutation_test(data, statistic, n_resamples=1000, vectorized=False, alternative='greater')
Pythonで学ぶ推測の基礎

相関の置換検定

赤と青の線の折れ線グラフ。やや相関している。

stats.pearsonr(red_data, blue_data)[0]
0.08
Pythonで学ぶ推測の基礎

相関の置換検定

data = (red_data, blue_data)

def statistic(x, y): return stats.pearsonr(x, y)[0]
res = stats.permutation_test(data, statistic, n_resamples=1000, vectorized=False, alternative='two-sided')
print(res.pvalue < 0.05)
False
Pythonで学ぶ推測の基礎

置換検定

 

  • データをランダムに「シャッフル」して帰無分布を作成
  • 結果の「有意性」を検定

ブートストラップ

 

  • データをランダムに「サンプリング」して分布を作成
  • 最も起こりやすい結果を示す信頼区間を作成
Pythonで学ぶ推測の基礎

練習してみましょう!

Pythonで学ぶ推測の基礎

Preparing Video For Download...