Creates marginal model-averaged and conditional posterior distributions based on a BayesTools JAGS model, vector of parameters, formula, and a list of conditional specifications for each parameter. Computes inclusion Bayes factors for each marginal estimate via a Savage-Dickey density approximation.

as_marginal_inference(
  model,
  marginal_parameters,
  parameters,
  conditional_list,
  conditional_rule,
  formula,
  null_hypothesis = 0,
  normal_approximation = FALSE,
  n_samples = 10000,
  silent = FALSE,
  force_plots = FALSE,
  density_method = "KDE",
  compute_BF = TRUE
)

Arguments

model

model fit via the JAGS_fit function with this version of BayesTools. Fits without its parameter map and fit contract (such as fits created by BayesTools 0.3.0) must be refitted: they stop with an error of class BayesTools_refit_required (see JAGS_validate_fit_contract()).

marginal_parameters

parameters for which the the marginal summary should be created

parameters

all parameters included in the model_list that are relevant for the formula (all of which need to have specification of is_null_list)

conditional_list

list of conditional parameters for each marginal parameter Unnamed entries bind to marginal_parameters in supplied order; uniquely named complete lists bind by key. Partial or mismatched names and duplicate, missing or empty marginal keys are refused.

conditional_rule

a character string specifying the rule for conditioning. Either "AND" or "OR". Defaults to "AND".

formula

model formula (needs to be specified if parameter was part of a formula)

null_hypothesis

point null hypothesis to test. Defaults to 0

normal_approximation

whether the height of the posterior density at the null should be approximated via a normal distribution (rather than kernel density). The prior height is always the structural prior-density ordinate. Defaults to FALSE.

n_samples

controls the numerical grid used for model-averaged prior densities (a grid has at least 16 points). It is not used when the samples carry a stored prior-density context. For a simple parameter, an explicitly attached prior_density is authoritative and is propagated instead of being reconstructed from prior_list.

silent

whether warnings should be returned silently. Defaults to FALSE

force_plots

temporal argument allowing to generate conditional posterior samples suitable for prior and posterior plots. Only available when conditioning on a single parameter.

density_method

posterior density method used for Savage-Dickey Bayes factors. Currently only "KDE" is supported by marginal_inference() and as_marginal_inference() because generic model-averaged marginal posteriors do not have a well-defined precomputed density source.

compute_BF

whether to compute inclusion Bayes factors. When FALSE, the averaged and conditional marginal posteriors are returned and the inference list is empty.

Value

as_marginal_inference returns an object of class 'marginal_inference'.

Details

For as_marginal_inference(), conditional_list is applied separately to each output marginal or level. A requested conditional parameter is active only for levels whose linear combination has a nonzero weight for that parameter. Requested conditionals with zero weight are ignored for that level; if no requested conditionals are active, the level uses the fully averaged posterior and prior context. Level comparisons require the compared levels to use the same effective conditional subset and rule. As in marginal_inference(), a parameter or level whose conditional posterior has a declared point mass at the null hypothesis gets an NA inclusion Bayes factor with the reason in its "warnings" attribute. Known prior-ordinate refusals and a numerically unavailable posterior ordinate also produce NA plus the original reason, including scalar marginal table results; direct scalar Savage_Dickey_BF() remains strict. A level whose effective conditional subset is non-empty and leaves no draws is unavailable: it gets the warning "No samples left after conditioning." (once per distinct conditioning event) and is absent from the conditional and inference entries of its parameter, while the other levels and the averaged marginals are kept. A parameter without an available level has no conditional or inference entry.