urc_acf.RdCreates autocorrelation function (ACF) plots for posterior samples from a JAGS MCMC model. Autocorrelation is calculated separately for each MCMC chain and parameter.
urc_acf(
model,
parameters = NULL,
exclude = NULL,
deviance = FALSE,
chains = NULL,
max_lag = 50,
labels = NULL,
x_label = "Lag",
y_label = "Autocorrelation",
title = NULL,
subtitle = NULL,
caption = NULL,
scales = "fixed",
line_args = list(),
theme = ggplot2::theme_minimal(),
theme_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 numeric vector specifying the chains to plot.
If NULL, all available chains are plotted.
Maximum lag to display. Defaults to 50.
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 x-axis label.
Defaults to "Lag".
Character string specifying the y-axis label.
Defaults to "Autocorrelation".
Optional plot title.
Optional plot subtitle.
Optional plot caption.
Character string specifying the scales used for the
facets. Must be one of "fixed", "free", "free_x",
or "free_y". Defaults to "fixed".
Named list of arguments passed to
ggplot2::geom_line().
A ggplot2 theme object. Defaults to
ggplot2::theme_minimal().
Named list of arguments passed to
ggplot2::theme().
Additional ggplot2 layers or components added to the plot.
A ggplot object showing posterior autocorrelation
functions for each parameter and MCMC chain.
if (FALSE) { # \dontrun{
output <- urc_mcmc(x = mydata)
# Plot ACF for all parameters and all chains
urc_acf(output$models$poisson)
# Plot selected parameters
urc_acf(
output$models$zip,
parameters = c("lambda", "pi")
)
# Plot selected chains
urc_acf(
output$models$poisson,
chains = 1
)
# Change maximum lag
urc_acf(
output$models$poisson,
max_lag = 100
)
# Rename parameters
urc_acf(
output$models$zip,
labels = c(
lambda = "Mean Count",
pi = "Zero-Inflation Probability"
)
)
# Customize the plot
urc_acf(
output$models$poisson,
title = "Posterior Autocorrelation",
line_args = list(linewidth = 1),
theme = ggplot2::theme_classic()
)
# Add additional ggplot components
urc_acf(output$models$poisson) +
ggplot2::geom_hline(
yintercept = 0,
linetype = "dashed"
)
} # }