Dispatches a fit to the backend recorded on stan_opts (from
stan_options()). The compiled model is resolved by model_name from the
calling package: for "rstan", package::stanmodels[[model_name]]; for
"cmdstanr", inst/stan/<model_name>.stan under package. The calling
package is detected automatically and can be overridden with package.
Arguments
- model_name
name of the Stan model; used to look up the compiled model in the calling package's
stanmodels(rstan) and to locate the.stansource file under itsinst/stan/(cmdstanr).- dat_stan
the Stan data list.
- init
the init list, sized to the chain count.
- stan_opts
the validated
stan_options()list (carrying abackendelement).- drop_pars
character vector of parameter names to exclude from the saved draws, or
NULLto keep everything. Honored by rstan; cmdstanr cannot drop parameters and warns if any are requested.- package
name of the host package whose model is being fit. Defaults to the package that called
fit_model(), which is correct for the usual case of a host package fitting one of its own models.
Examples
if (FALSE) { # \dontrun{
# From inside a host package that ships a compiled `coverage` model:
opts <- stan_options(chains = 2, iter = 500, seed = 1)
fit <- fit_model("coverage", dat_stan = data_list, init = init_list,
stan_opts = opts)
} # }