Bootstrap 信賴區間

Statistical Thinking in Python(第 2 部分)

Justin Bois

Lecturer at the California Institute of Technology

Bootstrap 複製函式

def bootstrap_replicate_1d(data, func):
    """Generate bootstrap replicate of 1D data."""
    bs_sample = np.random.choice(data, len(data))
    return func(bs_sample)

bootstrap_replicate_1d(michelson_speed_of_light, np.mean)
299859.20000000001
bootstrap_replicate_1d(michelson_speed_of_light, np.mean)
299855.70000000001
bootstrap_replicate_1d(michelson_speed_of_light, np.mean)
299850.29999999999
Statistical Thinking in Python(第 2 部分)

大量 bootstrap 複製

bs_replicates = np.empty(10000)

for i in range(10000): bs_replicates[i] = bootstrap_replicate_1d( michelson_speed_of_light, np.mean)
Statistical Thinking in Python(第 2 部分)

繪製 bootstrap 複製的直方圖

_ = plt.hist(bs_replicates, bins=30, density=True)
_ = plt.xlabel('mean speed of light (km/s)')
_ = plt.ylabel('PDF')
plt.show()
Statistical Thinking in Python(第 2 部分)

平均數的 bootstrap 估計

第 2 章圖 2.011

Statistical Thinking in Python(第 2 部分)

統計量的信賴區間

  • 若不斷重複量測,觀察值的 p% 會落在 p% 信賴區間內。
Statistical Thinking in Python(第 2 部分)

Bootstrap 信賴區間

conf_int = np.percentile(bs_replicates, [2.5, 97.5])
array([ 299837.,  299868.])

第 2 章圖 2.016

Statistical Thinking in Python(第 2 部分)

一起來練習吧!

Statistical Thinking in Python(第 2 部分)

Preparing Video For Download...