從 Poisson 與二項分配進行模擬
如果你拋 100,000 次硬幣,且每次正面機率為 0.2%,可以用 Poisson(2) 分配來近似。讓我們用模擬來驗證。
本練習屬於課程
R 的機率基礎
練習說明
- 產生 100,000 個來自 Binomial(1000, 0.002) 分配的抽樣,並將結果存為
binom_sample。 - 產生 100,000 個來自能近似此二項分配的 Poisson 分配的抽樣,使用
rpois()函式。將結果存為poisson_sample。 - 使用
compare_histograms()函式比較兩個分配。(記住它需要兩個引數:要比較的兩個樣本)。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Draw a random sample of 100,000 from the Binomial(1000, .002) distribution
binom_sample <-
# Draw a random sample of 100,000 from the Poisson approximation
poisson_sample <-
# Compare the two distributions with the compare_histograms function