從二項與常態分配進行模擬
在這個練習中,你會自己動手檢查:用常態分配近似二項分配是否合理。方法是從二項分配及其常態近似各自大量模擬樣本,然後比較它們的長條圖。
本練習屬於課程
R 的機率基礎
練習說明
- 產生 100,000 次來自 Binomial(1000, .2) 分配的抽樣,將結果存為
binom_sample。 - 使用
rnorm()產生 100,000 次來自近似此二項分配的常態分配之抽樣。(記得rnorm()需要平均數與標準差,而標準差是變異數的平方根)。將結果存為normal_sample。 - 使用
compare_histograms()比較這兩個分配。(記得它需要兩個引數:要比較的第一個與第二個向量)。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Draw a random sample of 100,000 from the Binomial(1000, .2) distribution
binom_sample <-
# Draw a random sample of 100,000 from the normal approximation
normal_sample <-
# Compare the two distributions with the compare_histograms function