始める無料で始める

検定統計量を可視化する

この演習では、帰無仮説に近づくために、2 通りの方法で得られた検定統計量の分布を比較します。

まず、早い時間帯と遅い時間帯でグループ化した 2 つの「母集団」を調べ、検定統計量の分布を計算します。次に、2 つの母集団をシャッフルして時間順をなくし、それぞれが早い・遅い時間の混在となるようにしてから、検定統計量の分布を再計算します。

準備として、2 つの時間継続グループ group_duration_shortgroup_duration_long、および 2 つの関数 shuffle_and_split()plot_test_statistic() をあらかじめ読み込んであります。

この演習はコースの一部です

Pythonで学ぶ線形モデリング入門

コースを見る

演習の手順

  • np.random.choice() を使って group_duration_shortgroup_duration_long をリサンプリングし、リサンプルの差を取って test_statistic_unshuffled を計算します。
  • 元の group_duration_shortgroup_duration_long(この順序で指定)に対して shuffle_and_split() を用い、2 つの新しい混合集団を作成します。
  • シャッフル後の集団をリサンプリングし、resample_long から resample_short を引いて、新しい test_statistic_shuffled を計算します。
  • plot_test_statistic() を使って、2 つの検定統計量の分布をプロットし、見た目で比較します。

実践的なインタラクティブ演習

このサンプルコードを完成させて、この演習に挑戦してみましょう。

# From the unshuffled groups, compute the test statistic distribution
resample_short = np.random.choice(____, size=500, replace=____)
resample_long = np.random.choice(____, size=500, replace=____)
test_statistic_unshuffled = ____ - ____

# Shuffle two populations, cut in half, and recompute the test statistic
shuffled_half1, shuffled_half2 = shuffle_and_split(____, ____)
resample_half1 = np.random.choice(____, size=500, replace=____)
resample_half2 = np.random.choice(____, size=500, replace=____)
test_statistic_shuffled = resample_half2 - resample_half1

# Plot both the unshuffled and shuffled results and compare
fig = plot_test_statistic(____, label='Unshuffled')
fig = plot_test_statistic(____, label='Shuffled')
コードを編集して実行