get_prior_parameters: Inspect custom priors

View source: R/prior-diagnostics.R

get_prior_parametersR Documentation

Inspect custom priors

Description

get_prior_parameters() lists the parameters that custom priors can refer to: the elements of par and theta passed to the custom and custom_log_jacobian functions in sdmTMBpriors(), with their values. Use it with a fitted model or one set up with do_fit = FALSE.

Usage

get_prior_parameters(object, random = FALSE)

get_prior_densities(object)

Arguments

object

An sdmTMB() model fit with the RTMB backend. For get_prior_densities(), it must have custom priors.

random

Include the random effects (e.g., random field values)? There are often many of them.

Details

get_prior_densities() evaluates the custom prior functions at the estimated parameters, including random effects at their conditional modes, and returns the log density of each term. Like the objective, it evaluates custom_log_jacobian only if bayesian = TRUE.

par holds the raw parameters, with the names and shapes used internally. Matrix columns are model components (e.g., the two parts of a delta model); the second component's main effects are in b_j2. theta holds natural-scale transformations of par, such as phi = exp(ln_phi) and range = sqrt(8) / kappa.

Elements of par that are fixed, by map or because the model doesn't use them, are left out, since a prior on them would have no effect. All elements of theta are listed, including transformations of parameters this model doesn't use (e.g., tweedie_p in a model without a Tweedie family). Check that the par elements underlying a theta element are listed before putting a prior on it. Standard deviations of random fields the model doesn't include (e.g., sigma_O without a spatial field) are zero.

These names and shapes are internal and could change in future versions of sdmTMB. Check them with get_prior_parameters() when writing custom priors.

Value

get_prior_parameters(): a data frame with one row per element:

  • expression: how to refer to the element in a custom prior function;

  • list, name: "par" or "theta", and the element's name;

  • label: the coefficient name, where available;

  • value: the estimate (or starting value if the model isn't fit);

  • status: for par, "estimated", "random", or "shared" (estimated jointly with other elements via map); "derived" for theta.

get_prior_densities(): a data frame with one row per term added to the objective: type ("density", or "log_jacobian" if bayesian = TRUE), term (the returned name, or its position), and log_density.

See Also

sdmTMBpriors()

Examples

fit <- sdmTMB(density ~ depth_scaled, data = pcod_2011,
  family = tweedie(), mesh = pcod_mesh_2011,
  control = sdmTMBcontrol(backend = "rtmb"),
  priors = sdmTMBpriors(custom = function(par, theta) {
    c(depth = RTMB::dnorm(par$b_j[2], 0, 1, log = TRUE))
  }))
get_prior_parameters(fit)
get_prior_densities(fit)

sdmTMB documentation built on Oct. 17, 2026, 1:07 a.m.