Skip to contents

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,
  ...
)

Arguments

model_code

A character pointing to the stan modelling code.

data

A list with all the parameters required to run the model_code in stan.

algorithm

A character giving the algorithm to use. Either 'sampling' (Default), 'optimize' or 'variational' for penalized likelihood estimation.

chains

A numeric indicating the number of chains to use for estimation.

cores

Number of threads for sampling. Default set to 'getOption("ibis.nthread")'. See ibis_options().

threads

numeric giving the number of threads to be run per chain. Has to be specified in accordance with cores.

iter

A numeric value giving the number of MCMC samples to generate.

warmup

numeric for the number of warm-up samples for MCMC. Default set to 1/2 of iter.

control

A list with further control options for stan.

cpp_options

A list with options for the Cpp compiling.

force

logical indication whether to force recompile the model (Default: FALSE).

path

character indicating a path to be made available to the stan compiler.

save_warmup

A logical flag whether to save the warmup samples.

...

Other non-specified parameters.

Value

A rstan object

See also

rethinking R package