繪製成長曲線
你在前一題看到成長曲線的信賴區間非常窄。這裡你將以視覺方式探索:把多條自助法(bootstrap)線與成長曲線一起畫出來。你會使用 plt.semilogy() 將 y 軸設為對數刻度。這代表你需要把理論的線性迴歸曲線取指數,才能拿來繪圖。
本練習屬於課程
統計思維個案研究
練習說明
- 使用
plt.semilogy()繪出資料點。numpy陣列t與bac_area已在你的命名空間中。 - 使用
np.array()產生用來繪製自助法線條的時間值,命名為t_bs。時間應從 0 到 14 小時。 - 撰寫一個
for迴圈,繪出前 100 組自助法重抽的對應迴歸線。你在上一題計算的numpy陣列growth_rate_bs_reps與log_a0_bs_reps已在命名空間中。- 使用
np.exp()對線性迴歸線取指數,計算成長曲線。 - 使用
plt.semilogy()繪製理論直線,並加入參數linewidth=0.5、alpha=0.05、color='red'。
- 使用
- 加上座標軸標籤並顯示圖形。x 與 y 軸的合適標籤分別為
'time (hr)'與'area (sq. µm)'。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Plot data points in a semilog-y plot with axis labeles
_ = ____(____, ____, marker='.', linestyle='none')
# Generate x-values for the bootstrap lines: t_bs
t_bs = ____([____, ____])
# Plot the first 100 bootstrap lines
for i in range(____):
y = ____(____[i] * ____ + ____[i])
_ = ____(____, ____, linewidth=____, alpha=____, color=____)
# Label axes and show plot
_ = plt.xlabel('____')
_ = plt.ylabel('____')
____