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.
Deze oefening maakt deel uit van de cursus
Bayesian Modeling with RJAGS
Oefeninstructies
- Obtain
summary()statistics of theweight_sim_bigchains. - The posterior mean of \(b\) is reported in Table 1 of the
summary(). Use the rawweight_chainsto verify this calculation. - Construct a scatterplot of the
wgtvshgtdata inbdims. Usegeom_abline()to superimpose the posterior mean trend. - Construct another scatterplot of
wgtvshgt. Superimpose the 20 regression lines defined by the first 20 sets of \(a\) & \(b\) parameter values inweight_chains.
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
# 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)