Creates marginal model-averages posterior distributions for a given parameter based on model-averaged posterior samples and parameter name (and formula with at specification).
marginal_posterior(
samples,
parameter,
formula = NULL,
at = NULL,
prior_samples = FALSE,
use_formula = TRUE,
transformation = NULL,
transformation_arguments = NULL,
transformation_settings = FALSE,
n_samples = 10000,
...
)model-averaged posterior samples created by mix_posteriors().
Mixed factor posteriors that lack the factor metadata of this version of
BayesTools (such as those created by BayesTools 0.3.0) must be recreated
from models fitted with this version: they stop with an error of class
BayesTools_refit_required (see JAGS_validate_fit_contract()).
With use_formula = TRUE and no attached formula state, orthonormal or
mean-difference factor posteriors whose stored contrast basis differs from the
current contrasts stop with the same error class; use_formula = FALSE
keeps using the stored design.
parameter of interest
model formula (needs to be specified if parameter was part of a formula)
named list with predictor levels of the formula for which marginalization
should be performed. Continuous values use fitted/SD units for fitted posterior
views and original data units for views created with transform_scaled = TRUE.
A manipulated continuous predictor is evaluated at the existing grid
c(-1, 0, 1) in those same view units.
If a predictor level is missing, 0 is used for continuous
predictors, the baseline factor level is used for factors with contrast = "treatment" prior
distributions, and the parameter is completely omitted for factors with
contrast = "meandif", contrast = "orthonormal",
contrast = "independent", and ordered-factor levels. A predictor
without its own main-effect term (e.g., x in ~ g + g:x) is
handled by the type, levels, and contrast recorded for it in the
interaction terms that contain it.
whether marginal prior distributions should be generated
whether the parameter should be evaluated as a part of supplied formula
optional transformation of
the marginal posterior, applied with posterior_transform() to the
untransformed marginal posterior and its metadata. The transformation is
validated before the marginal posterior is built.
not used by marginal_posterior(),
which evaluates no plotting grid; transformation_settings is
validated as a logical value and ... is ignored.
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.
marginal_posterior returns a named list of mixed marginal posterior
distributions (either vectors or matrices).
When the mixed posterior samples carry deterministic
posterior_density, posterior_ordinate, or support
metadata (posterior_metadata()), marginal_posterior() propagates
matching metadata to the returned marginal posterior. Matching uses the
parameter name, list/level names such as theta[A], and conditional
metadata when present. Exact support metadata is propagated even when
prior_samples = FALSE; requesting prior samples adds prior-density
metadata but does not replace already attached posterior support.
A transformation is applied by posterior_transform() to the
marginal posterior with all its metadata (supports, atoms, prior densities,
stored posterior densities and ordinates, and component supports); the
mixed posterior samples themselves must be untransformed (samples
transformed with posterior_transform() whose prior is their
prior_list are refused). If support metadata is
absent, support is inferred from prior metadata only when the posterior
samples are on the raw, unconditioned prior scale; otherwise the deterministic
prior-density context is used so formula-scale transformations and
conditional model restrictions are respected. Marginal posteriors with
prior samples also record each draw's mixture component and each
component's exact support (components metadata): the model
of mix_posteriors() ensembles, or the combination of the mixture and
spike-and-slab component indicators of a single fit
(as_mixed_posteriors()). Savage_Dickey_BF() uses them when the
components' supports differ. With log(intercept) formula scaling, the
unscaled intercept (transform_scaled samples) is the exp of a linear
combination of the fitted coefficients with the log of the fitted
intercept: its simple marginal posterior (use_formula = FALSE) takes
its prior density and support from the exp of that combination, and the
linear predictors of a formula marginal posterior are linear in the same
coefficients.
Ordered formula projections reuse retained fitted coefficients, totals and
allocations, with aligned model and draw rows, from the contributing formula
prefixes. Every provided source of a contributing prefix is used;
unrelated prefixes are excluded. Scaling is determined separately for each
prefix; an unscaled prefix keeps its fitted draws when another prefix is scaled.
Scaled mixed posteriors that lack the fitted ordinary coefficients needed by
a formula stop with class
BayesTools_ordered_coordinates_unavailable (parent
BayesTools_ordered_unavailable); recreate the mixed posteriors from
the source fits with this version of BayesTools.