線形回帰
1975年と2012年の両方のデータに対して線形回帰を実行し、その後、回帰パラメータのペアブートストラップ推定を行ってください。回帰直線の傾きと切片について、95%信頼区間を報告します。
draw_bs_pairs_linreg() 関数は、第2章で作成したものを使用します。
リマインドとして、呼び出しシグネチャは draw_bs_pairs_linreg(x, y, size=1) で、bs_slope_reps と bs_intercept_reps を返します。くちばしの長さのデータは bl_1975 と bl_2012 に、くちばしの深さのデータは bd_1975 と bd_2012 に保存されています。
この演習はコースの一部です
Pythonで学ぶ統計思考(パート2)
演習の手順
- 1975年と2012年の両データセットについて、傾きと切片を計算します。
- 作成した
draw_bs_pairs_linreg()関数を使って、線形回帰に対するペアブートストラップ標本を1000組取得します。 - 傾きと切片の95%信頼区間を計算します。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# Compute the linear regressions
slope_1975, intercept_1975 = ____
slope_2012, intercept_2012 = ____
# Perform pairs bootstrap for the linear regressions
bs_slope_reps_1975, bs_intercept_reps_1975 = \
____
bs_slope_reps_2012, bs_intercept_reps_2012 = \
____
# Compute confidence intervals of slopes
slope_conf_int_1975 = ____
slope_conf_int_2012 = ____
intercept_conf_int_1975 = ____
intercept_conf_int_2012 = ____
# Print the results
print('1975: slope =', slope_1975,
'conf int =', slope_conf_int_1975)
print('1975: intercept =', intercept_1975,
'conf int =', intercept_conf_int_1975)
print('2012: slope =', slope_2012,
'conf int =', slope_conf_int_2012)
print('2012: intercept =', intercept_2012,
'conf int =', intercept_conf_int_2012)