# Use rstanarm example model
fit <- example_model
# Intervals and point estimates
plot(fit) +
ggplot2::ggtitle("Posterior medians \n with 80% and 95% credible intervals")
plot(fit, pars = "size", regex_pars = "period",
ci_level = 0.95, outer_level = 1, show_density = TRUE)
# Traceplot
# note: rstanarm doesn't store the warmup draws by default
(trace <- plot(fit, "trace", pars = "(Intercept)"))
trace + ggplot2::scale_color_discrete()
trace + ggplot2::scale_color_manual(values = c("maroon", "skyblue2"))
# Distributions
plot_title <- ggplot2::ggtitle("Posterior Distributions")
plot(fit, "hist", fill = "skyblue", regex_pars = "period") + plot_title
plot(fit, "dens", pars = "(Intercept)", regex_pars = "period",
separate_chains = TRUE, alpha = 1/3) + plot_title
# Scatterplot
plot(fit, plotfun = "scat", pars = paste0("period", 2:3))
plot(fit, plotfun = "scat", pars = c("(Intercept)", "size"),
color = "black", size = 5, alpha = 0.2)
# Some diagnostics
plot(fit, "rhat")
plot(fit, "ess")
# Using regex_pars
plot(fit, regex_pars = "period")
plot(fit, regex_pars = "herd:1")
plot(fit, regex_pars = "herd:1\\]")
plot(fit, regex_pars = "herd:[279]")
plot(fit, regex_pars = "herd:[279]|period2")
plot(fit, regex_pars = c("herd:[279]", "period2"))
# For graphical posterior predictive checks see
# help("pp_check", package = "rstanarm")
Run the code above in your browser using DataLab