開始使用免費開始

水流效應如何隨泳道位置改變?

為了量化泳道編號對成績的影響,請對 f_13 相對 lanes 的資料做一次線性迴歸。接著以 pairs bootstrap 計算 95% 信賴區間。最後,繪製迴歸圖。陣列 lanesf_13 已在你的命名空間中。

請注意,我們也可以對平均分數差計算誤差棒並用於迴歸,但這超出本課程範圍。

本練習屬於課程

統計思維個案研究

檢視課程

練習說明

  • 使用 np.polyfit() 計算 f_13 相對 lanes 的直線之斜率與截距。
  • 使用 dcst.draw_bs_pairs_linreg() 取得 10,000 個斜率與截距的 bootstrap 重抽樣複本,分別存入 bs_reps_slopebs_reps_int
  • 使用這些 bootstrap 複本計算斜率的 95% 信賴區間。
  • 在螢幕上列印斜率與 95% 信賴區間。這部分已替你完成。
  • 使用 np.array() 產生要用來繪製 bootstrap 直線的 x 值。x 應從 18
  • 圖上已經放入資料。寫一個 for 迴圈,把 100 條 bootstrap 直線加入圖中,並使用參數 color='red'alpha=0.2linewidth=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()
編輯並執行程式碼