ช่วงความเชื่อมั่นแบบ Bootstrap

Statistical Thinking in Python (ตอนที่ 2)

Justin Bois

Lecturer at the California Institute of Technology

ฟังก์ชัน Bootstrap Replicate

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 Replicate จำนวนมาก

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 Replicates

_ = 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 ของค่าเฉลี่ย

ch2-2.011.png

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.])

ch2-2.016.png

Statistical Thinking in Python (ตอนที่ 2)

มาฝึกกันเถอะ!

Statistical Thinking in Python (ตอนที่ 2)

Preparing Video For Download...