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.
Este exercício faz parte do curso
Bayesian Modeling with RJAGS
Instruções do exercício
- 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 theprior_A
,prior_B
, andprior_C
priorsamples
with a corresponding indicator of thepriors
. To construct aggplot()
density plot of these 3 separate priorsamples
on the same frame, specifyfill = priors
inaes()
.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
# 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)