开始使用免费开始使用

其他统计量的自助法重复

我们在之前的练习中已经看到,均值近似服从正态分布。但对其他统计量,这一性质未必成立。不过不用担心:作为黑客式统计实践者,您始终可以使用自助法重复!在本练习中,您将为谢菲尔德气象站的年降雨量数据计算方差的自助法重复,并绘制这些重复值的直方图。

这里您将使用几道练习前定义的 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,便于将方差的单位转换为平方厘米。
  • 使用 normed=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()
编辑并运行代码