Posterior predictive distribution
The weight_chains
data frame (in your workspace) contains your 100,000 posterior predictions, Y_180
, for the weight of a 180 cm tall adult:
> 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
You will use these 100,000 predictions to approximate the posterior predictive distribution for the weight of a 180 cm tall adult. The bdims
data are in your workspace.
This exercise is part of the course
Bayesian Modeling with RJAGS
Exercise instructions
- Use the 10,000
Y_180
values to construct a 95% posterior credible interval for the weight of a 180 cm tall adult. - Construct a density plot of your 100,000 posterior plausible predictions.
- Construct a scatterplot of the
wgt
vshgt
data inbdims
.- Use
geom_abline()
to superimpose the posterior regression trend. - Use
geom_segment()
to superimpose a vertical line at ahgt
of 180 that represents the lower & upper limits (y
andyend
) ofci_180
.
- Use
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# 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")