後驗預測分佈
weight_chains 資料框(已在你的工作空間中)包含 100,000 個後驗預測 Y_180,對象是身高 180 cm 的成年人體重:
> head(weight_chains, 2)
a b s iter m_180 Y_180
1 -113.9029 1.072505 8.772007 1 79.14803 71.65811
2 -115.0644 1.077914 8.986393 2 78.96014 75.78893
你將使用這 100,000 個預測來近似身高 180 cm 成年人體重的後驗預測分佈。bdims 資料已在你的工作空間中。
本練習屬於課程
使用 RJAGS 的貝氏建模
練習說明
- 使用 10,000 個
Y_180值來建構身高 180 cm 成年人體重的 95% 後驗可信區間。 - 繪製 100,000 個後驗合理預測值的密度圖。
- 繪製
bdims中wgt對hgt的散佈圖。- 使用
geom_abline()疊加後驗迴歸趨勢。 - 使用
geom_segment()在hgt為 180 的位置疊加一條垂直線,其上下界對應ci_180的下限與上限(y與yend)。
- 使用
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Construct a posterior credible interval for the prediction
ci_180 <- quantile(___, probs = c(___, ___))
ci_180
# Construct a density plot of the posterior predictions
ggplot(___, aes(x = ___)) +
geom_density() +
geom_vline(xintercept = ci_180, color = "red")
# Visualize the credible interval on a scatterplot of the data
ggplot(___, aes(x = ___, y = ___)) +
geom_point() +
geom_abline(intercept = mean(___), slope = mean(___), color = "red") +
geom_segment(x = 180, xend = 180, y = ___, yend = ___, color = "red")