其他统计量的自举重复
我们在之前的练习中看到,均值近似服从正态分布。其他统计量不一定如此,但别担心:作为黑客统计学家,您始终可以进行自举重复!在本练习中,您将为谢菲尔德气象站年度降雨量的方差生成自举重复,并绘制这些重复值的直方图。
这里,您将继续使用几道练习前定义的 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
本练习是课程的一部分
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()