后验预测分布
工作区中的数据框 weight_chains 包含了针对身高 180 cm 成年人体重的 100,000 个后验预测值 Y_180:
> 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")