💡 學習重點:離散機率的定義
  ■ Binomial[n, p]: 重複機率為p的實驗n次,其成功次數的分佈
  ■ Geomtric[p]: 重複機率為p的實驗,第一次成功前失敗次數的分佈
  ■ NBinomial[n, p]: 重複機率為p的實驗,第n次成功前失敗次數的分佈
  ■ Poisson[\(\lambda\)]: 期望值為\(\lambda\)的小機率事件發生次數的分佈


pacman::p_load(dplyr, vcd)

【1】Death by Horse Kick

資料:Load built-in dataset into HK

nDeaths
  0   1   2   3   4 
109  65  22   3   1 

檢定:Does it comply to Poisson Distribution?


     Goodness-of-fit test for poisson distribution

                     X^2 df P(> X^2)
Likelihood Ratio 0.86822  3  0.83309

係數:What is the \(\lambda\)?

$lambda
[1] 0.61

應用:What is the probability of nDeath >= 2?

[1] 0.12521


🧙 問題討論:
如果保險公司想要為國防部設計一個被馬踢死的保險:
  ■ 如果你只要只靠HorseKick這一份數據,每一軍團每年被馬踢死的次數超過5次的機率是多?
  ■ 如果我們將數據fit到理論分布上面,根據理論分佈,被馬踢死的次數超過5次的機率是多?
  ■ 以上哪一種做法才是比較合理的做法的?

What is the probability of nDeath >= 5?

[1] 0.00042497



【2】“May” in Federalist Papers

資料:Load data into Fed

nMay
  0   1   2   3   4   5   6 
156  63  29   8   4   1   1 

檢定:Does it comply to Poisson Distribution?


     Goodness-of-fit test for poisson distribution

                    X^2 df   P(> X^2)
Likelihood Ratio 25.243  5 0.00012505

Does it comply to Negtive Binomial Distribution?


     Goodness-of-fit test for nbinomial distribution

                   X^2 df P(> X^2)
Likelihood Ratio 1.964  4  0.74238

係數:What are the parameters?

$size
[1] 1.1863

$prob
[1] 0.64376

分佈:How does the distribution looks like?

機率:How is the probability that 2 <= nMay <= 6?

[1] 0.15526



💡 學習重點:離散機率的應用步驟
  1. 檢定分佈的種類
  2. 估計分佈的參數
  3. 推論事件的機率