This function fits a stan model using the light-weight interface provided by cmdstanr. The code was adapted from McElreath rethinking package.
Usage
run_stan(
model_code,
data = list(),
algorithm = "sampling",
chains = 4,
cores = getOption("ibis.nthread"),
threads = 1,
iter = 1000,
warmup = floor(iter/2),
control = list(adapt_delta = 0.95),
cpp_options = list(),
force = FALSE,
path = base::getwd(),
save_warmup = TRUE,
return_stanfit = FALSE,
...
)Arguments
- model_code
A
characterpointing to the stan modelling code.- data
A
listwith all the parameters required to run the model_code in stan.- algorithm
A
charactergiving the algorithm to use. Either'sampling'(Default),'optimize'or'variational'for penalized likelihood estimation.- chains
A
numericindicating the number of chains to use for estimation.- cores
Number of threads for sampling. Default set to
'getOption("ibis.nthread")'. Seeibis_options().- threads
numericgiving the number of threads to be run per chain. Has to be specified in accordance with cores.- iter
A
numericvalue giving the number of MCMC samples to generate.- warmup
numericfor the number of warm-up samples for MCMC. Default set to 1/2 of iter.- control
A
listwith further control options for stan.- cpp_options
A
listwith options for the Cpp compiling.- force
logicalindication whether to force recompile the model (Default:FALSE).- path
characterindicating a path to be made available to the stan compiler.- save_warmup
A
logicalflag whether to save the warmup samples.- return_stanfit
A
logicalflag whether to convert sampling output to anrstanstanfit object. Defaults toFALSE; the native cmdstanr CmdStanFit object is used otherwise.- ...
Other non-specified parameters.
