開始使用免費開始

死亡人數

Cynthia 的教授現在要她探索生命表中的死亡人數。年齡為 \(x\) 的死亡人數標記為 $d_x$。你能把不同年齡 \(x\) 的死亡人數 \(d_x\) 視覺化嗎?

此外,Cynthia 得知,\(d_x\) 是在一組 \(\ell_x\) 名倖存者中,預期會在年齡 \(x\) 去世的人數。你會為每個年齡 \(x\) 的死亡人數產生二項式樣本,並將模擬結果與登記的 \(d_x\) 比較。

物件 life_table 已預先載入到你的 R 工作空間,另外也已提取出欄位 ageqxlxdx

本練習屬於課程

以 R 估值人壽保險商品

檢視課程

練習說明

  • 繪製 dxage 的圖,檢視各年齡的死亡人數。使用 type = "h" 可得到垂直線而非點。
  • 依據倖存者人數 lx 與死亡率 qx,模擬每個年齡 \(x\) 的死亡人數。使用 rbinom()docs)以向量化方式從二項分配產生樣本。
  • 使用 points()docs)將模擬的死亡人數 sims 疊加在既有圖上。將 pch = 4 設為符號即可使用叉號。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Plot the number of deaths dx by age
plot(___, ___, 
    type = "h", 
    pch = 20, 
    xlab = "Age x", 
    ylab = expression("d"[x]),
    main = "Number of deaths (Belgium, females, 1999)")

# Simulate the number of deaths using a binomial distribution
sims <- ___(n = ___, size = ___, prob = ___)
  
# Plot the simulated number of deaths on top of the previous graph
points(___, ___, 
    pch = 4, 
    col = "red")
編輯並執行程式碼