比較二項分配的累積機率
如果你拋 1000 次硬幣,而且每次出現正面的機率是 20%,得到 190 次或更少正面的機率是多少?
用二項分配或其常態近似來解,結果會很接近。這個練習中,你會用模擬與精確計算兩種方式來解。
本練習屬於課程
R 的機率基礎
練習說明
- 使用上一題提供的模擬
binom_sample來估計得到 190 次或更少正面的機率。 - 使用模擬的
normal_sample來估計得到 190 次或更少正面的機率。 - 用
pbinom()計算二項分配小於等於 190 的精確機率。 - 用
pnorm()計算常態分配小於等於 190 的精確機率。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Simulations from the normal and binomial distributions
binom_sample <- rbinom(100000, 1000, .2)
normal_sample <- rnorm(100000, 200, sqrt(160))
# Use binom_sample to estimate the probability of <= 190 heads
# Use normal_sample to estimate the probability of <= 190 heads
# Calculate the probability of <= 190 heads with pbinom
# Calculate the probability of <= 190 heads with pnorm