始める無料で始める

検定統計量と効果量

ブートストラップ再標本化で線形関係をどのように調べられるでしょうか。では実践に戻りましょう。各ハイキングを1点としてプロットすると、移動した総距離と経過時間のあいだに線形関係が見て取れます。経過時間の「効果」として移動距離を扱うと、線形回帰と統計的推測のつながりを探ることができます。

この演習では、データを「カテゴリ」として2つの母集団(早い時間帯と遅い時間帯)に分けます。次に、それぞれの母集団内での総移動距離の「差」を見ます。この「差」を「検定統計量」として用い、その分布から、時間帯で距離を分けることの効果を評価します。

ch04_ex11_fig03.png

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

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(____)
コードを編集して実行