基础 Jackknife 估计——均值
Jackknife 重抽样是一种较早的方法,使用频率不如自助法(bootstrapping)高。不过,了解如何进行基本的 jackknife 估计仍然很有用。在本练习中,您将计算均值的 jackknife 估计。让我们回到扳手工厂的情境。
您经营一家扳手工厂,需要测量扳手的平均长度,以确保符合规格。工厂每天生产成千上万把扳手,但逐一测量并不可行。不过,您手头有一个包含 100 把扳手的代表性样本。现在用 jackknife 估计来得到平均长度。
请在 Shell 中查看变量 wrench_lengths。
本练习是课程的一部分
Python 中的统计模拟
练习说明
- 通过依次从
wrench_lengths中留出一个观测值,获取 jackknife 样本,并将其赋给jk_sample。 - 计算
jk_sample的均值,并将其追加到mean_lengths。 - 最后,将
mean_lengths数组的均值作为 jackknife 估计mean_lengths_jk。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Leave one observation out from wrench_lengths to get the jackknife sample and store the mean length
mean_lengths, n = [], len(wrench_lengths)
index = np.arange(n)
for i in range(n):
jk_sample = ____[index != i]
mean_lengths.append(____)
# The jackknife estimate is the mean of the mean lengths from each sample
mean_lengths_jk = ____(np.array(mean_lengths))
print("Jackknife estimate of the mean = {}".format(mean_lengths_jk))