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.
Diese Übung ist Teil des Kurses
Bayesian Modeling with RJAGS
Anleitung zur Übung
- 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_simdata frame combines theprior_A,prior_B, andprior_Cpriorsampleswith a corresponding indicator of thepriors. To construct aggplot()density plot of these 3 separate priorsampleson the same frame, specifyfill = priorsinaes().
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
# 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)