帰無仮説
この演習では、次のように帰無仮説を定義します。
短時間・長時間という観測時間の違いは、総移動距離に影響しない。
ここで「効果量がゼロ」とは、短時間と長時間のサンプルを相互にシャッフルして、どちらの新しいサンプルにも短時間・長時間の移動が混在するようにしたうえで検定統計量を計算すると、平均的にはその値がゼロになる、という解釈です。
この演習の目標は、シャッフルとリサンプリングを実行することです。あらかじめ与えられている、シャッフル前の時間グループ group_duration_short と group_duration_long から始めてください。
この演習はコースの一部です
Pythonで学ぶ線形モデリング入門
演習の手順
np.concatenate()を使って2つの母集団を結合し、その入れ物の中身をnp.random.shuffle()でシャッフルします。shuffle_bucketを半分にスライスし、各shuffle_halfからnp.random.choice()でリサンプルします。test_statisticを、resample_half2からresample_half1を引いて計算します。effect_sizeをtest_statisticのnp.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(____))