Returns 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.

JAGS_predict_formula(
  fit,
  parameter,
  formula = NULL,
  data = NULL,
  prior_list = NULL,
  formula_target = c("conditional", "fixed", "marginal"),
  blocks = NULL,
  new_levels = NULL,
  marginal_method = c("covariance", "sample"),
  seed = NULL,
  components = FALSE,
  fitted_rows = NULL
)

Arguments

fit

model fitted with JAGS_fit(), or posterior draws carrying the formula design of parameter (JAGS_formula_draws()).

parameter

formula parameter name.

formula

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.

data

optional prediction data. If NULL, fitted source data are used.

prior_list

optional named prior list. If NULL, fitted priors are used.

formula_target

prediction target: "conditional", "fixed", or "marginal". The default includes fitted random-effect contributions.

blocks

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_levels

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_method

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.

seed

optional random seed used when random-effect draws are simulated.

components

whether to include component matrices where available.

fitted_rows

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.

Value

A list of class BayesTools_formula_prediction with fields value, mean, random, vcov, components, and metadata.