Model-averages posterior distributions based on a list of models, vector of parameters, and a list of indicators of the null or alternative hypothesis models for each parameter.

mix_posteriors(
  model_list,
  parameters,
  is_null_list,
  conditional = FALSE,
  seed = NULL,
  n_samples = 10000,
  on_failure = c("error", "drop", "zero")
)

Arguments

model_list

list of models, each of which contains marginal likelihood estimated with bridge sampling marglik and prior model odds prior_weights

parameters

vector of parameters names for which inference should be drawn

is_null_list

list with entries for each parameter carrying either logical vector of indicators specifying whether the model corresponds to the null or alternative hypothesis (or an integer vector indexing models corresponding to the null hypothesis; use 0 or integer(0) when no models are null) Exact matching unique list names bind by parameter name; other ensemble lists retain positional order. Marginal inference requires unnamed lists or unique complete names matching its requested parameters.

conditional

whether prior and posterior model probabilities should be returned only for the non-null models. Defaults to FALSE. Inclusion Bayes factors stay the unconditional inclusion odds; after conditioning, posterior inclusion is 1, so recomputing the Bayes factor from the renormalized probabilities would be Inf.

seed

integer specifying seed for sampling posteriors for model averaging. The caller's random-number state (.Random.seed and RNGkind()) is restored afterwards. Defaults to NULL, which draws the shared sampling seed from the caller's random-number stream (one draw).

n_samples

number of samples to be drawn for the model-averaged posterior distribution

on_failure

policy for missing (NA) marginal likelihoods in models with positive prior probability. "error" aborts (the default), "drop" removes failed models from the prior model space and renormalizes, and "zero" explicitly assigns the failed models zero evidence. Non-default policies emit a warning and return audit metadata. Only NA is treated as a computation failure under this policy. In model lists, store a failed computation as bridgesampling_object(NA), a result flagged as failed whose marginal likelihood is read as NA. A finite failure must be reported as NA; by contrast, -Inf is an intentional zero-evidence shortcut (for example via bridgesampling_object()) and quietly receives posterior model probability zero without consulting on_failure.

Value

mix_posteriors returns a named list of mixed posterior distributions (either a vector of matrix).

Details

For simplex parameters such as Dirichlet priors, absent model parameters are not filled with an implicit spike at zero because the all-zero vector is off the simplex. Every model with positive prior or posterior probability must provide an explicit compatible simplex prior or point prior on the simplex.

Mixture draws are aligned across parameters by restarting from one shared sampling seed and requiring identical posterior model probabilities for every requested parameter. That holds for unconditional averaging even when is_null_list differs by parameter. Conditional averaging (conditional = TRUE) with different null indicators per parameter produces different post_probs and therefore different mixture allocations; mix_posteriors() hard-errors in that case. Mix each conditional parameter in a separate call instead.

With on_failure = "drop" or "zero", one warning is emitted for the model list, and every mixed parameter carries the marglik_failure attribute that ensemble_inference() returns for that parameter.

For an ordered total with a declared inclusion event, conditional averaging also conditions within each model. Posterior model probabilities are multiplied by the event's fraction of fitted draws; prior probabilities are multiplied by its declared prior probability. Resampling uses eligible original draw indices, and conditional prior contexts preserve the original fitted source specifications. A parameterized total without an inclusion event, including a Bernoulli total, retains every state. A compound event must be applied once to full aligned sources; separately conditioned ordered parameters cannot be combined as joint draws by this function.

Positive model declarations remain active when their visible probability rounds to zero. Numeric mixed draws remain usable. A prior law or atom law requiring model probabilities unavailable at full precision is explicitly refused with BayesTools_formula_measure_unavailable and the cause numerical_model_probability_unavailable; structured model/log diagnostics are retained in posterior_metadata(). Descriptive marginal_posterior(use_formula = FALSE, prior_samples = FALSE) remains available. An ordered projection with no allocated rows for a positive model requires a complete declared atom certificate; otherwise that measure has cause structural_target_law_unavailable. Independently known support and valid sibling measures remain available.