urc_density.RdCreates posterior density plots from posterior samples obtained from
a JAGS MCMC model. Parameters can be selected individually or by their
base parameter name, and the resulting ggplot2 object can be
extensively customized.
urc_density(
model,
parameters = NULL,
exclude = NULL,
deviance = FALSE,
labels = NULL,
fill = "#333333",
color = NA,
alpha = 0.25,
linewidth = 0.6,
adjust = 1,
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(),
density_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.
Character string specifying the fill color of the density.
Defaults to "#333333".
Character string specifying the outline color of the
density. Defaults to NA, meaning no outline is drawn.
Numeric value between 0 and 1 specifying density
transparency. Defaults to 0.25.
Numeric value specifying the width of the density
outline. Defaults to 0.6.
Numeric value used to adjust the bandwidth of the
density estimate. Values greater than 1 produce a smoother density,
while values less than 1 produce a more detailed density.
Defaults to 1.
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_density().
Additional ggplot2 layers or components added to the plot.
A ggplot object showing posterior densities.
if (FALSE) { # \dontrun{
output <- urc_mcmc(x = mydata)
# Plot all parameters
urc_density(output$models$poisson)
# Plot selected parameters
urc_density(
output$models$zip,
parameters = c("lambda", "pi")
)
# Plot a specific indexed parameter
urc_density(
output$models$zip,
parameters = "lambda[1]"
)
# Plot all lambda parameters
urc_density(
output$models$zip,
parameters = "lambda"
)
# Rename parameters
urc_density(
output$models$zip,
labels = c(
lambda = "Mean Count",
pi = "Zero-Inflation Probability"
)
)
# Publication-style plot
urc_density(
output$models$poisson,
fill = "#333333",
alpha = 0.25,
color = "#333333",
linewidth = 0.6,
theme = ggplot2::theme_classic()
)
# Customize density estimation
urc_density(
output$models$poisson,
adjust = 1.5
)
# Add additional ggplot components
urc_density(output$models$poisson) +
ggplot2::geom_vline(
xintercept = 0,
linetype = "dashed"
)
} # }