開始使用免費開始

Poisson 後驗預測

你的 l_weekday 變數反映了 80 度平日的流量「趨勢」:

> head(poisson_chains, 2)
       a b.1.    b.2.      c l_weekend l_weekday
1 5.0198    0 -0.1222 0.0141   465.924   412.324
2 5.0186    0 -0.1218 0.0141   466.284   412.829

既然你已經理解了「趨勢」,接下來就來做預測吧!更具體地說,我們要「預測」下一個 80 度平日的步道使用量。為了達成這點,你必須把來自趨勢之外的個體變異性納入考量,這在概似模型中為 \(Y\)i \(\sim Pois(l\)i) 所描述。

使用 rpois(n, lambda)(樣本數為 n、速率參數為 lambda),你將在 poisson_chains 中每一個後驗上合理的趨勢值下,模擬 Poisson 的流量預測。

本練習屬於課程

使用 RJAGS 的貝氏建模

檢視課程

練習說明

  • 針對 poisson_chains 中 10,000 個 l_weekday 值的每一個,使用 rpois() 預測 80 度平日的流量。將結果存為 poisson_chainsY_weekday
  • 使用 ggplot() 繪製 Y_weekday 預測值的機率密度圖。
  • 估計 80 度平日流量小於 400 位使用者的後驗機率。

動手互動練習

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

# Simulate weekday predictions under each parameter set
poisson_chains <- poisson_chains %>% 
    mutate(Y_weekday = rpois(n = ___, lambda = ___))
    
# Construct a density plot of the posterior weekday predictions
ggplot(___, aes(x = ___)) + 
    geom_density()
    
# Posterior probability that weekday volume is less 400
mean(___)
編輯並執行程式碼