多變量迴歸的後驗推論
工作區中已提供 10,000 次迭代的 RJAGS 模擬輸出 rail_sim_2,以及對應的馬可夫鏈輸出資料框:
> head(rail_chains_2, 2)
a b.1. b.2. c s
1 49.76954 0 -12.62112 4.999202 111.02247
2 30.22211 0 -3.16221 4.853491 98.11892
你將使用這 10,000 組參數值,摘要 trail volume、weekday 狀態與 hightemp 之間關係的後驗平均趨勢。
本練習屬於課程
使用 RJAGS 的貝氏建模
練習說明
繪製 volume 對 hightemp 的散佈圖。
- 使用
color區分平日與週末。 - 疊加一條
red線,表示週末時volume與hightemp線性關係的後驗平均趨勢:m = a + c Z。 - 再疊加一條
turquoise3線,表示平日時volume與hightemp線性關係的後驗平均趨勢:m = (a + b.2.) + c Z。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Plot the posterior mean regression models
ggplot(___, aes(x = ___, y = ___, color = ___)) +
geom_point() +
geom_abline(intercept = mean(___), slope = mean(___), color = "red") +
geom_abline(intercept = mean(___) + mean(___), slope = mean(___), color = "turquoise3")