開始使用免費開始

基礎 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))
編輯並執行程式碼