検定統計量と効果量
ブートストラップ再標本化で線形関係をどのように調べられるでしょうか。では実践に戻りましょう。各ハイキングを1点としてプロットすると、移動した総距離と経過時間のあいだに線形関係が見て取れます。経過時間の「効果」として移動距離を扱うと、線形回帰と統計的推測のつながりを探ることができます。
この演習では、データを「カテゴリ」として2つの母集団(早い時間帯と遅い時間帯)に分けます。次に、それぞれの母集団内での総移動距離の「差」を見ます。この「差」を「検定統計量」として用い、その分布から、時間帯で距離を分けることの効果を評価します。

この演習はコースの一部です
Pythonで学ぶ線形モデリング入門
演習の手順
numpyの「論理インデクシング」(例:sample_distances[sample_times < 5])を使って、サンプルのdistancesを早い時間帯と遅い時間帯の母集団に分けます。- 2つの時間ビンそれぞれに対して、
np.random.choice()をreplacement=Trueで用いてresampleを作成します。 test_statistic配列をresample_long - resample_shortとして計算し、np.mean()とnp.std()で効果量と不確かさを算出して表示します。- あらかじめ用意された
fig = plot_test_statistic()を使って、test_statisticの分布をプロットします。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# Create two poulations, sample_distances for early and late sample_times.
# Then resample with replacement, taking 500 random draws from each population.
group_duration_short = sample_distances[____ < 5]
group_duration_long = sample_distances[____ > 5]
resample_short = np.random.choice(____, size=500, replace=____)
resample_long = np.random.choice(____, size=500, replace=____)
# Difference the resamples to compute a test statistic distribution, then compute its mean and stdev
test_statistic = resample_long - resample_short
effect_size = np.mean(____)
standard_error = np.std(____)
# Print and plot the results
print('Test Statistic: mean={:0.2f}, stdev={:0.2f}'.format(____, ____))
fig = plot_test_statistic(____)