R/JAGS-formula-predict-target.R
JAGS_predict_formula.RdReturns formula-scale predictions from fitted BayesTools formula metadata.
Unlike JAGS_evaluate_formula(), this helper can return structured
prediction output for marginal random-effect targets, including marginal
random-effect covariance or simulated random-effect draws.
Unavailable new rows for a posterior-indexed row source raise
BayesTools_prediction_new_rows_unavailable (parent
BayesTools_prediction_unavailable), with reason = "posterior_indexed_row_source",
block, displayed source label, affected prediction rows, and caller
context. This applies to conditional and both marginal targets where the
source of the new rows is needed, under new_levels = "sample"; with
new_levels = "zero" the new rows contribute zero and need no source.
Mapping, source-value, and monitoring errors retain their existing
conditions.
model fitted with JAGS_fit(), or posterior draws carrying the
formula design of parameter (JAGS_formula_draws()).
formula parameter name.
optional formula. If NULL, the fitted formula for
parameter is used. For formula_target = "marginal", random-effect
terms in formula must match fitted blocks and select the blocks whose
marginal covariance or draws are included; without such terms, all fitted
blocks are included.
optional prediction data. If NULL, fitted source data are used.
optional named prior list. If NULL, fitted priors are
used.
prediction target: "conditional", "fixed", or
"marginal". The default includes fitted random-effect contributions.
optional random-effect block names. For
formula_target = "conditional" or "marginal" with random-effect terms in
formula, the default is the blocks of those terms, and supplied blocks
must be among those blocks.
new-level policy for conditional or marginal random-effect
prediction. Use a random_new_levels() object or one of "error", "zero",
or "sample". Grouping levels declared in the fitted grouping factor but
without rows in the fitting data are predicted as new levels, except in
blocks with a known group covariance; see prior_random().
marginal representation used only with
formula_target = "marginal": "covariance" returns fixed means plus
marginal random-effect covariance; "sample" returns materialized
random-effect draws. For known group covariance, "sample" jointly draws
the requested fitted levels from the corresponding covariance submatrix;
noncentered multi-column ID, DIAG, and US blocks jointly retain both the
group kernel and the draw-specific coefficient covariance. New levels remain
unsupported.
optional random seed used when random-effect draws are simulated.
whether to include component matrices where available.
optional integer vector mapping supplied prediction rows
to fitted observation indices. It is required for selected
posterior-indexed row sources. Reordering and duplicate indices are
supported; callback-computed row sources do not use it. The entries of rows
of new random-effect levels predicted with new_levels = "zero" are
ignored, because those rows contribute zero; they must still be valid fitted
observation indices.
A list of class BayesTools_formula_prediction with fields value,
mean, random, vcov, components, and metadata.