始める無料で始める

帰無仮説

この演習では、次のように帰無仮説を定義します。

短時間・長時間という観測時間の違いは、総移動距離に影響しない。

ここで「効果量がゼロ」とは、短時間と長時間のサンプルを相互にシャッフルして、どちらの新しいサンプルにも短時間・長時間の移動が混在するようにしたうえで検定統計量を計算すると、平均的にはその値がゼロになる、という解釈です。

この演習の目標は、シャッフルとリサンプリングを実行することです。あらかじめ与えられている、シャッフル前の時間グループ group_duration_shortgroup_duration_long から始めてください。

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

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

コースを見る

演習の手順

  • np.concatenate() を使って2つの母集団を結合し、その入れ物の中身を np.random.shuffle() でシャッフルします。
  • shuffle_bucket を半分にスライスし、各 shuffle_half から np.random.choice() でリサンプルします。
  • test_statistic を、resample_half2 から resample_half1 を引いて計算します。
  • effect_sizetest_statisticnp.mean() として計算し、結果を出力します。

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

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

# Shuffle the time-ordered distances, then slice the result into two populations.
shuffle_bucket = np.____((group_duration_short, group_duration_long))
np.random.shuffle(____)
slice_index = len(shuffle_bucket)//2
shuffled_half1 = shuffle_bucket[0:____]
shuffled_half2 = shuffle_bucket[____:]

# Create new samples from each shuffled population, and compute the test statistic
resample_half1 = np.random.choice(____, size=500, replace=____)
resample_half2 = np.random.choice(____, size=500, replace=____)
test_statistic = ____ - ____

# Compute and print the effect size
effect_size = np.mean(____)
print('Test Statistic, after shuffling, mean = {}'.format(____))
コードを編集して実行