urc_hist.RdCreates posterior histograms for parameters from a JAGS MCMC model.
Parameters can be selected individually or by their base parameter name.
The resulting ggplot2 object can be further customized using
standard ggplot2 functionality.
urc_hist(
model,
parameters = NULL,
exclude = NULL,
deviance = FALSE,
labels = NULL,
bins = 30,
binwidth = NULL,
fill = NA,
color = "#333333",
alpha = 1,
linewidth = 0.4,
scales = "free",
ncol = NULL,
nrow = NULL,
x_label = "Posterior",
y_label = "Density",
title = NULL,
subtitle = NULL,
caption = NULL,
theme = ggplot2::theme_minimal(),
theme_args = list(),
histogram_args = list(),
...
)A fitted JAGS model object containing posterior samples.
Optional character vector specifying the parameters
to plot. If NULL, all available parameters are plotted except
loglik and, by default, deviance. Parameters can be
specified by their exact name (e.g., "lambda[1]") or by their
base name (e.g., "lambda"), which selects all indexed
parameters.
Optional character vector specifying parameters to exclude from the plot. Exact parameter names or base parameter names can be used.
Logical; should posterior deviance be included?
Defaults to FALSE.
Optional named character vector used to rename parameter labels in the facets. Names can correspond to exact parameter names or base parameter names.
Number of histogram bins. Defaults to 30.
Optional numeric value specifying the width of the
histogram bins. If NULL, ggplot2 determines the bin
width automatically.
Character string specifying the histogram fill color.
Defaults to NA, producing an unfilled histogram.
Character string specifying the histogram outline color.
Defaults to "#333333".
Numeric value between 0 and 1 specifying histogram
transparency. Defaults to 1.
Numeric value specifying the histogram outline width.
Defaults to 0.4.
Character string specifying the scales used for the
facets. Must be one of "fixed", "free", "free_x",
or "free_y". Defaults to "free".
Number of columns in the facet layout.
Number of rows in the facet layout.
Character string specifying the x-axis label.
Defaults to "Posterior".
Character string specifying the y-axis label.
Defaults to "Density".
Optional plot title.
Optional plot subtitle.
Optional plot caption.
A ggplot2 theme object. Defaults to
ggplot2::theme_minimal().
Named list of arguments passed to
ggplot2::theme().
Named list of additional arguments passed to
ggplot2::geom_histogram().
Additional ggplot2 layers or components added to the plot.
A ggplot object showing posterior histograms.
if (FALSE) { # \dontrun{
output <- urc_mcmc(x = mydata)
# Plot all parameters
urc_hist(output$models$poisson)
# Plot selected parameters
urc_hist(
output$models$zip,
parameters = c("lambda", "pi")
)
# Plot a specific indexed parameter
urc_hist(
output$models$zip,
parameters = "lambda[1]"
)
# Plot all lambda parameters
urc_hist(
output$models$zip,
parameters = "lambda"
)
# Exclude a parameter
urc_hist(
output$models$zip,
exclude = "pi"
)
# Rename parameters
urc_hist(
output$models$zip,
labels = c(
lambda = "Mean Count",
pi = "Zero-Inflation Probability"
)
)
# Add color
urc_hist(
output$models$poisson,
fill = "#0072B2",
color = "#0072B2",
alpha = 0.3
)
# Publication-style plot
urc_hist(
output$models$poisson,
theme = ggplot2::theme_classic(),
bins = 25
)
# Add additional ggplot components
urc_hist(output$models$poisson) +
ggplot2::geom_vline(
xintercept = 0,
linetype = "dashed"
)
} # }