Posterior point estimates
Recall the likelihood of the Bayesian regression model of weight \(Y\) by height \(X\): \(Y \sim N(m, s^2)\) where \(m = a + b X\). A 100,000 iteration RJAGS simulation of the posterior, weight_sim_big
, is in your workspace along with a data frame of the Markov chain output:
> head(weight_chains, 2)
a b s iter
1 -113.9029 1.072505 8.772007 1
2 -115.0644 1.077914 8.986393 2
The posterior means of the intercept & slope parameters, \(a\) & \(b\), reflect the posterior mean trend in the relationship between weight & height. In contrast, the full posteriors of \(a\) & \(b\) reflect the range of plausible parameters, thus posterior uncertainty in the trend. You will examine the trend and uncertainty in this trend below. The bdims
data are in your workspace.
This exercise is part of the course
Bayesian Modeling with RJAGS
Exercise instructions
- Obtain
summary()
statistics of theweight_sim_big
chains. - The posterior mean of \(b\) is reported in Table 1 of the
summary()
. Use the rawweight_chains
to verify this calculation. - Construct a scatterplot of the
wgt
vshgt
data inbdims
. Usegeom_abline()
to superimpose the posterior mean trend. - Construct another scatterplot of
wgt
vshgt
. Superimpose the 20 regression lines defined by the first 20 sets of \(a\) & \(b\) parameter values inweight_chains
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Summarize the posterior Markov chains
# Calculate the estimated posterior mean of b
mean(___)
# Plot the posterior mean regression model
ggplot(bdims, aes(x = ___, y = ___)) +
geom_point() +
geom_abline(intercept = mean(___), slope = mean(___), color = "red")
# Visualize the range of 20 posterior regression models
ggplot(bdims, aes(x = ___, y = ___)) +
geom_point() +
geom_abline(intercept = ___[1:20], slope = ___[1:20], color = "gray", size = 0.25)