Skip to contents

forward_sim_generator() is the fitter-agnostic analogue of ifs_generator(). It fits the model ONCE on pilot_bundle, draws theta from the posterior (via extract_draws()), and forward-simulates y via the fitter's predict_fit() (posterior-predictive) at the chosen draw's parameters. Works with any Fitter that supports predict_fit() (LinearRegressionFitter, BrmsFitter, ...).

Usage

forward_sim_generator(
  fitter,
  fit_spec,
  pilot_bundle,
  predictor_generator,
  response = NULL,
  n_draws = NULL
)

Arguments

fitter

An S7 Fitter object supporting predict_fit().

fit_spec

A list (single-row fit_grid entry) with at least formula.

pilot_bundle

A data_bundle list used for the one-time preconditioning fit.

predictor_generator

Function (data_spec, task_ctx) -> data.frame producing predictor covariates. Must consume the ambient RNG state.

response

Name of the response column. Defaults to pilot_bundle$response, falling back to the LHS of fit_spec$formula, then to "y".

n_draws

Optional integer override for the number of draws to store.

Value

A generator function (data_spec, task_ctx) -> data_bundle.

Details

Unlike prior_draws_generator() (which targets the prior), this generator concentrates the truth draw in a region of high posterior mass, which is practical for diffuse or improper priors. Note this is not by itself a valid SBC configuration: valid SBC requires the fitting prior to match the theta-generating distribution (here the pilot posterior), so a diffuse or unmatched fitting prior yields systematically non-uniform (cap-shaped) ranks; see the caveat in ifs_generator().

Because forward simulation here relies on predict_fit(), the response is drawn exactly as the fitter implements its posterior-predictive sampling, which respects the fitter's response distribution and link function. Each task uses a distinct draw, deterministically indexed by task_ctx$rep_idx.

Limitations

The true_params reported by this generator are the extract_draws() columns for the selected draw; for LinearRegressionFitter these are Intercept, <coef>, sigma. The response is forward-simulated via the fitter's predict_fit() applied to the predictor design (a single Gaussian draw for Gaussian fitters). Fitters without predict_fit() support are not supported (e.g. raw CmdStanFitter, which has no newdata semantics).