ComeçarComece de graça

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.

Este exercício faz parte do curso

Bayesian Modeling with RJAGS

Ver curso

Instruções do exercício

  • Obtain summary() statistics of the weight_sim_big chains.
  • The posterior mean of \(b\) is reported in Table 1 of the summary(). Use the raw weight_chains to verify this calculation.
  • Construct a scatterplot of the wgt vs hgt data in bdims. Use geom_abline() to superimpose the posterior mean trend.
  • Construct another scatterplot of wgt vs hgt. Superimpose the 20 regression lines defined by the first 20 sets of \(a\) & \(b\) parameter values in weight_chains.

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

# 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)
Editar e executar o código