Creates density plots, trace plots, and autocorrelation plots for a given parameter of a JAGS model.

JAGS_diagnostics(
  fit,
  parameter,
  type,
  plot_type = "base",
  xlim = NULL,
  ylim = NULL,
  lags = 30,
  n_points = 1000,
  transformations = NULL,
  transform_factors = FALSE,
  short_name = FALSE,
  parameter_names = FALSE,
  formula_prefix = TRUE,
  ...
)

JAGS_diagnostics_density(
  fit,
  parameter,
  plot_type = "base",
  xlim = NULL,
  n_points = 1000,
  transformations = NULL,
  transform_factors = FALSE,
  short_name = FALSE,
  parameter_names = FALSE,
  formula_prefix = TRUE,
  ...
)

JAGS_diagnostics_trace(
  fit,
  parameter,
  plot_type = "base",
  ylim = NULL,
  transformations = NULL,
  transform_factors = FALSE,
  short_name = FALSE,
  parameter_names = FALSE,
  formula_prefix = TRUE,
  ...
)

JAGS_diagnostics_autocorrelation(
  fit,
  parameter,
  plot_type = "base",
  lags = 30,
  transformations = NULL,
  transform_factors = FALSE,
  short_name = FALSE,
  parameter_names = FALSE,
  formula_prefix = TRUE,
  ...
)

Arguments

fit

a JAGS model fitted via JAGS_fit() or a derived-draw view from JAGS_with_draws(). Diagnostics describe the supplied view draws.

parameter

parameter to be plotted

type

what type of model diagnostic should be plotted. The available options are "density", "trace", and "autocorrelation"

plot_type

whether to use a base plot "base" or ggplot2 "ggplot" for plotting.

xlim

x plotting range

ylim

y plotting range

lags

number of lags to be shown for the autocorrelation plot. Defaults to 30.

n_points

number of equally spaced points in the x_range if x_seq is unspecified

transformations

named list of transformations to be applied to specific parameters

transform_factors

whether factors with orthonormal/meandif prior distribution should be transformed to differences from the grand mean, and factors with prior_ordered() prior distribution to their level effects (without the reference level of a "cumulative" contrast, which is fixed at zero). Untransformed ordered factors show the sampled parameters: runjags_estimates_table() reports the total effect (<term>{total}) and the allocation shares of the random allocations (<term>[share: <level>], the share of the total added when reaching <level>; fixed allocations have no rows). ensemble_estimates_table() reports retained fitted totals and the union of allocation shares sampled by any declared ordered model. Fixed ordered allocations fill that union with their declared constants. Models without the ordered parameterization have undefined (NA) shares, with their defined fraction reported in a footnote. Shares remain defined on zero-total and excluded spike draws of an ordered model. Legacy mixed objects without retained sources must be recreated from source fits.

short_name

whether prior distribution names should be shorted

parameter_names

whether parameter names should be printed

formula_prefix

whether the parameter prefix from formula should be printed. Defaults to TRUE.

...

additional arguments

Value

diagnostics returns either NULL if plot_type = "base" or an object/list of objects (depending on the number of parameters to be plotted) of class 'ggplot' if plot_type = "ggplot".

Details

The trace shows the retained MCMC iteration of every draw on its x axis (thinned chains keep their original positions). Autocorrelation uses the retained original iteration positions. Requested lags without finite observation pairs, beyond the retained chain, or with nonfinite autocorrelation are retained as NA. One warning per parameter and chain has classes BayesTools_autocorrelation_unavailable and BayesTools_plot_condition, with parameter, chain, unavailable_lags, pair_count and reason fields. Computed x/y objects retain full-length pair_count and unavailability_reason attributes; both renderers display finite bars only. No iteration compression, replacement estimate or confidence band is introduced.

Coordinates whose convergence role is "structural" (see JAGS_check_convergence()) are constants of the prior: the weight bins that the prior fixes (for example by wf_fixed()) or the coefficients of an ordered prior with a point total and fixed allocation. The density and autocorrelation diagnostics omit them when their draws are constant, and when nothing else remains the call returns NULL with a message, as for a spike prior; the trace is produced as for any other parameter. A parameter with a prior_none() prior is not sampled: the call returns NULL with a message for every type.