開始使用免費開始

多變量迴歸的後驗推論

工作區中已提供 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 volumeweekday 狀態與 hightemp 之間關係的後驗平均趨勢。

本練習屬於課程

使用 RJAGS 的貝氏建模

檢視課程

練習說明

繪製 volumehightemp 的散佈圖。

  • 使用 color 區分平日與週末。
  • 疊加一條 red 線,表示週末時 volumehightemp 線性關係的後驗平均趨勢:m = a + c Z
  • 再疊加一條 turquoise3 線,表示平日時 volumehightemp 線性關係的後驗平均趨勢: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")
編輯並執行程式碼