Skip to contents

Compares each explicit parameter prior with its retained marginal posterior distribution. When an sbt_fit() is supplied, priors and posterior draws are taken directly from the portable fit.

Usage

plot_prior_posterior(
  fit,
  priors = NULL,
  pars = NULL,
  labels = NULL,
  include_without_prior = FALSE,
  scale = c("natural", "model"),
  adjust = 1,
  n = 512L,
  ncol = NULL
)

Arguments

fit

An sbt_fit() containing MCMC output, or a posterior object with an iteration-by-chain-by-variable samples array and a scalar warmup count.

priors

Optional named prior list compatible with get_priors(). Required when fit is not an sbt_fit; do not supply it for an sbt_fit.

pars

Optional character vector selecting prior-bearing parameters. Base names select every vector element (for example, par_sel_rho_y); expanded names select one element (for example, par_sel_rho_y[2]). By default, every explicit prior with retained posterior draws is shown.

labels

Optional character labels for plot panels. A named vector can map either base or expanded parameter names. An unnamed vector must have one label per selected posterior variable.

include_without_prior

Logical. If TRUE, parameters requested in pars can be shown when they have retained posterior draws but no explicit scalar prior. Their panels contain only a posterior density. The default parameter selection remains the prior-bearing parameters.

scale

Plot log parameters on their natural or model scale. On the natural scale, parameters whose names begin with par_log_ are exponentiated and both densities include the required Jacobian.

adjust

Positive bandwidth multiplier passed to stats::density() for the posterior density.

n

Integer number of evaluation points per density.

ncol

Optional number of facet columns.

Value

A ggplot2 object. Its data contain the evaluated prior and posterior densities on the displayed scale.

Details

By default, only parameters that have both an explicit prior and retained posterior draws are plotted. Fixed parameters can have prior specifications in the model input, but do not have posterior distributions and are therefore omitted. Posterior densities are drawn only across the range of finite retained draws; prior densities use their 0.1%–99.9% quantile range, extended when necessary to include the posterior. Set include_without_prior = TRUE and request parameters in pars to add posterior-only panels.