线性回归与配对自助法

统计思维案例研习

Justin Bois

Lecturer, Caltech

细菌生长

1 图片由加州理工学院 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])
统计思维案例研习

Passons à la pratique !

统计思维案例研习

Preparing Video For Download...