其他統計量的自助複本
在先前的練習中,我們看到平均數近似服從常態分布。這不一定適用於其他統計量,但別擔心:身為駭客統計學家,我們總是可以抽自助(bootstrap)複本!在本練習中,你將為雪菲爾氣象站(Sheffield Weather Station)的年降雨量「變異數」產生自助複本,並繪製這些複本的長條圖。
這裡你會使用幾個練習前定義的 draw_bs_reps() 函式。下方提供參考:
def draw_bs_reps(data, func, size=1):
"""Draw bootstrap replicates."""
# Initialize array of replicates
bs_replicates = np.empty(size)
# Generate replicates
for i in range(size):
bs_replicates[i] = bootstrap_replicate_1d(data, func)
return bs_replicates
本練習屬於課程
Statistical Thinking in Python(第 2 部分)
練習說明
- 使用你寫的
draw_bs_reps()函式,對儲存在rainfall資料集裡的年降雨量「變異數」抽取10000個自助複本。提示:用np.var來計算變異數。 - 將變異數複本(
bs_replicates)都除以100,方便以平方公分為單位來表示變異數。 - 使用
density=True以及50個箱數來對bs_replicates繪製長條圖。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Generate 10,000 bootstrap replicates of the variance: bs_replicates
bs_replicates = ____
# Put the variance in units of square centimeters
____
# Make a histogram of the results
_ = plt.hist(____, ____, ____)
_ = plt.xlabel('variance of annual rainfall (sq. cm)')
_ = plt.ylabel('PDF')
# Show the plot
plt.show()