# NOT RUN {
# }
# NOT RUN {
if (!exists("example_model")) example(example_model)
# display non-varying (i.e. not group-level) coefficients
posterior_vs_prior(example_model, pars = "beta")
# show group-level (varying) parameters and group by parameter
posterior_vs_prior(example_model, pars = "varying",
group_by_parameter = TRUE, color_by = "vs")
# group by parameter and allow axis scales to vary across facets
posterior_vs_prior(example_model, regex_pars = "period",
group_by_parameter = TRUE, color_by = "none",
facet_args = list(scales = "free"))
# assign to object and customize with functions from ggplot2
(gg <- posterior_vs_prior(example_model, pars = c("beta", "varying"), prob = 0.8))
gg +
ggplot2::geom_hline(yintercept = 0, size = 0.3, linetype = 3) +
ggplot2::coord_flip() +
ggplot2::ggtitle("Comparing the prior and posterior")
# compare very wide and very narrow priors using roaches example
# (see help(roaches, "rstanarm") for info on the dataset)
roaches$roach100 <- roaches$roach1 / 100
wide_prior <- normal(0, 10)
narrow_prior <- normal(0, 0.1)
fit_pois_wide_prior <- stan_glm(y ~ treatment + roach100 + senior,
offset = log(exposure2),
family = "poisson", data = roaches,
prior = wide_prior)
posterior_vs_prior(fit_pois_wide_prior, pars = "beta", prob = 0.5,
group_by_parameter = TRUE, color_by = "vs",
facet_args = list(scales = "free"))
fit_pois_narrow_prior <- update(fit_pois_wide_prior, prior = narrow_prior)
posterior_vs_prior(fit_pois_narrow_prior, pars = "beta", prob = 0.5,
group_by_parameter = TRUE, color_by = "vs",
facet_args = list(scales = "free"))
# look at cutpoints for ordinal model
fit_polr <- stan_polr(tobgp ~ agegp, data = esoph, method = "probit",
prior = R2(0.2, "mean"), init_r = 0.1)
(gg_polr <- posterior_vs_prior(fit_polr, regex_pars = "\\|", color_by = "vs",
group_by_parameter = TRUE))
# flip the x and y axes
gg_polr + ggplot2::coord_flip()
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab