开始使用免费开始使用

Posterior credible intervals

Let's focus on slope parameter \(b\), the rate of change in weight over height. The posterior mean of \(b\) reflects the trend in the posterior model of the slope. In contrast, a posterior credible interval provides a range of posterior plausible slope values, thus reflects posterior uncertainty about \(b\). For example, the 95% credible interval for \(b\) ranges from the 2.5th to the 97.5th quantile of the \(b\) posterior. Thus there's a 95% (posterior) chance that \(b\) is in this range.

You will use RJAGS simulation output to approximate credible intervals for \(b\). The 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, weight_chains.

本练习是课程的一部分

Bayesian Modeling with RJAGS

查看课程

练习说明

  • Obtain summary() statistics of the weight_sim_big chains.
  • The 2.5% and 97.5% posterior quantiles for \(b\) are reported in Table 2 of the summary(). Apply quantile() to the raw weight_chains to verify these calculations. Save this as ci_95 and print it.
  • Similarly, use the weight_chains data to construct a 90% credible interval for \(b\). Save this as ci_90 and print it.
  • Construct a density plot of the \(b\) Markov chain values. Superimpose vertical lines representing the 90% credible interval for \(b\) using geom_vline() with xintercept = ci_90.

交互式实操练习

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

# Summarize the posterior Markov chains


# Calculate the 95% posterior credible interval for b
ci_95 <- quantile(___, probs = c(___, ___))
ci_95

# Calculate the 90% posterior credible interval for b
ci_90 <- ___
ci_90

# Mark the 90% credible interval 
ggplot(___, aes(x = ___)) + 
    geom_density() + 
    geom_vline(xintercept = ___, color = "red")
编辑并运行代码