开始使用免费开始使用

Comparing & contrasting Beta priors

The Beta(\(a\),\(b\)) distribution is defined on the interval from 0 to 1, thus provides a natural and flexible prior for your underlying election support, \(p\). You can tune the Beta shape parameters \(a\) and \(b\) to produce alternative prior models. Below you will compare your original Beta(45,55) prior with two alternatives: Beta(1, 1) and Beta(100, 100). The original 10,000 prior_A samples drawn from Beta(45,55) are in your workspace.

本练习是课程的一部分

Bayesian Modeling with RJAGS

查看课程

练习说明

  • Sample 10,000 draws from the Beta(1,1) prior. Assign the output to prior_B.
  • Sample 10,000 draws from the Beta(100,100) prior. Assign the output to prior_C.
  • The prior_sim data frame combines the prior_A, prior_B, and prior_C prior samples with a corresponding indicator of the priors. To construct a ggplot() density plot of these 3 separate prior samples on the same frame, specify fill = priors in aes().

交互式实操练习

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

# Sample 10000 draws from the Beta(1,1) prior
prior_B <- rbeta(n = ___, shape1 = ___, shape2 = ___)    

# Sample 10000 draws from the Beta(100,100) prior
prior_C <- rbeta(n = ___, shape1 = ___, shape2 = ___)

# Combine the results in a single data frame
prior_sim <- data.frame(samples = c(prior_A, prior_B, prior_C),
        priors = rep(c("A","B","C"), each = 10000))

# Plot the 3 priors
ggplot(___, aes(x = ___, fill = ___)) + 
    geom_density(alpha = 0.5)
编辑并运行代码