水流效應如何隨泳道位置改變?
為了量化泳道編號對成績的影響,請對 f_13 相對 lanes 的資料做一次線性迴歸。接著以 pairs bootstrap 計算 95% 信賴區間。最後,繪製迴歸圖。陣列 lanes 和 f_13 已在你的命名空間中。
請注意,我們也可以對平均分數差計算誤差棒並用於迴歸,但這超出本課程範圍。
本練習屬於課程
統計思維個案研究
練習說明
- 使用
np.polyfit()計算f_13相對lanes的直線之斜率與截距。 - 使用
dcst.draw_bs_pairs_linreg()取得 10,000 個斜率與截距的 bootstrap 重抽樣複本,分別存入bs_reps_slope與bs_reps_int。 - 使用這些 bootstrap 複本計算斜率的 95% 信賴區間。
- 在螢幕上列印斜率與 95% 信賴區間。這部分已替你完成。
- 使用
np.array()產生要用來繪製 bootstrap 直線的 x 值。x應從1到8。 - 圖上已經放入資料。寫一個
for迴圈,把 100 條 bootstrap 直線加入圖中,並使用參數color='red'、alpha=0.2、linewidth=0.5。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Compute the slope and intercept of the frac diff/lane curve
____, ____ = ____
# Compute bootstrap replicates
bs_reps_slope, bs_reps_int = ____
# Compute 95% confidence interval of slope
conf_int = ____
# Print slope and confidence interval
print("""
slope: {0:.5f} per lane
95% conf int: [{1:.5f}, {2:.5f}] per lane""".format(slope, *conf_int))
# x-values for plotting regression lines
x = ____
# Plot 100 bootstrap replicate lines
for i in ____:
_ = ____(____, ____[i] * ____ + ____[i],
color='red', alpha=0.2, linewidth=0.5)
# Update the plot
plt.draw()
plt.show()