線性迴歸與成對自助法

統計思維個案研究

Justin Bois

Lecturer, Caltech

細菌生長

1 圖片由 Caltech 的 Jin Park 與 Michael Elowitz 提供
統計思維個案研究

細菌生長

統計思維個案研究
_ = plt.semilogy(t, bac_area, marker='.', linestyle='none')
_ = plt.xlabel('time (hr)')
_ = plt.ylabel('area (sq. µm)')
plt.show()

統計思維個案研究

使用 np.polyfit() 的線性迴歸

slope, intercept = np.polyfit(t, bac_area, 1)

t_theor = np.array([0, 14])
bac_area_theor = slope * t_theor + intercept

_ = plt.plot(t, bac_area, marker='.', linestyle='none')
_ = plt.plot(t_theor, bac_area_theor)
_ = plt.xlabel('time (hr)')
_ = plt.ylabel('area (sq. µm)')
plt.show()
統計思維個案研究

細菌生長的迴歸

統計思維個案研究

使用 np.polyfit() 的半對數線性迴歸

slope, intercept = np.polyfit(t, np.log(bac_area), 1)

t_theor = np.array([0, 14])
bac_area_theor = np.exp(slope * t_theor + intercept)

_ = plt.semilogy(t, bac_area, marker='.', linestyle='none')
_ = plt.semilogy(t_theor, bac_area_theor)
_ = plt.xlabel('time (hr)')
_ = plt.ylabel('area (sq. µm)')
plt.show()
統計思維個案研究

細菌生長的迴歸

統計思維個案研究

成對自助法

  • 以成對方式重抽樣資料
  • 以重抽樣資料計算斜率與截距
  • 每個斜率與截距都是一個自助法重抽樣值
  • 由重抽樣分佈的百分位數計算信賴區間
統計思維個案研究

成對自助法

# Draw 10000 pairs bootstrap reps
slope_reps, int_reps = dcst.draw_bs_pairs_linreg(
  x_data, y_data, size=10000
)

# Compute 95% confidence interval of slope slope_conf_int = np.percentile(slope_reps, [2.5, 97.5])
統計思維個案研究

一起來練習吧!

統計思維個案研究

Preparing Video For Download...