文盲率/生育率資料的配對 bootstrap
使用你剛寫好的函式,進行配對 bootstrap,繪製直方圖來描述從文盲率/生育率資料估計出的斜率分佈,同時回報斜率的 95% 信賴區間。資料已提供在 NumPy 陣列 illiteracy 與 fertility 中。
提醒你,draw_bs_pairs_linreg() 的函式簽章是 draw_bs_pairs_linreg(x, y, size=1),並且會回傳兩個值:bs_slope_reps 與 bs_intercept_reps。
本練習屬於課程
Statistical Thinking in Python(第 2 部分)
練習說明
- 使用你的
draw_bs_pairs_linreg()函式,對斜率與截距進行1000次 bootstrap 重抽樣。x 軸資料為illiteracy,y 軸資料為fertility。 - 計算並列印斜率的 95% bootstrap 信賴區間。
- 繪製並顯示斜率重抽樣的直方圖,記得標示座標軸。這部分已為你完成,點擊「Submit」即可看到直方圖!
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Generate replicates of slope and intercept using pairs bootstrap
bs_slope_reps, bs_intercept_reps = ____
# Compute and print 95% CI for slope
print(np.percentile(____, ____))
# Plot the histogram
_ = plt.hist(bs_slope_reps, bins=50, density=True)
_ = plt.xlabel('slope')
_ = plt.ylabel('PDF')
plt.show()