开始使用免费开始使用

后验预测分布

工作区中的数据框 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 个后验合理预测的密度图。
  • 绘制 bdimswgthgt 的散点图。
    • 使用 geom_abline() 叠加后验回归趋势线。
    • 使用 geom_segment()hgt 为 180 处叠加一条竖线,其上下端点用 ci_180 的下限与上限(yyend)表示。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# 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")
编辑并运行代码