Visualizing the regression priors
In the previous exercise, you simulated 10,000 samples for each parameter (\(a\), \(b\), \(s\)) in the Bayesian regression model of weight \(Y\) by height \(X\): \(Y \sim N(m, s^2)\) with mean \(m = a + bX\). The set of \(a\), \(b\), and \(s\) values in each row of samples represents a prior plausible regression scenario. To explore the scope of these prior scenarios, you will simulate 50 pairs of height and weight values from each of the first 12 sets of prior parameters \(a\), \(b\), and \(s\).
Este exercício faz parte do curso
Bayesian Modeling with RJAGS
Instruções do exercício
- Create a data frame
prior_simulationwhich includesn = 50replicates of the first 12 sets of prior parameters insamples(600 rows in total!). - For each of the 600
prior_simulationrows:- Simulate a
heightvalue from a \(N(170, 10^2)\) model. - Simulate a
weightvalue from \(N(a + b X, s^2)\) where \(X\) is height and \((a,b,s)\) are the prior parameter set.
- Simulate a
- You now have 50 simulated
heightandweightpairs for each of the 12 parameter sets. Useggplot()to construct a scatterplot of these 50 pairs for eachsetof parameter values. Be sure to putweighton the y-axis!
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
# Replicate the first 12 parameter sets 50 times each
prior_scenarios_rep <- bind_rows(replicate(n = ___, expr = samples[1:12, ], simplify = FALSE))
# Simulate 50 height & weight data points for each parameter set
prior_simulation <- prior_scenarios_rep %>%
mutate(height = rnorm(n = 600, mean = ___, sd = ___)) %>%
mutate(weight = rnorm(n = 600, mean = ___, sd = ___))
# Plot the simulated data & regression model for each parameter set
ggplot(prior_simulation, aes(x = ___, y = ___)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE, size = 0.75) +
facet_wrap(~ set)