Skip to contents

Package overview and global options

An overview of the package and how it differs from RStan.

cmdstanr-package cmdstanr CmdStanR
CmdStanR: the R interface to CmdStan
cmdstanr_global_options
CmdStanR global options

Installing and setting the path to CmdStan

Install CmdStan, assuming the necessary C++ toolchain.

install_cmdstan() rebuild_cmdstan() cmdstan_make_local() check_cmdstan_toolchain()
Install CmdStan or clean and rebuild an existing installation
set_cmdstan_path() cmdstan_path() cmdstan_version()
Get or set the file path to the CmdStan installation

Running CmdStan from R

Run CmdStan from R.

cmdstan_model() compile_stan_file()
Create a new CmdStanModel object
stan_build_info() print(<stan_build_info>)
What is known about how a CmdStan executable was built
CmdStanModel
CmdStanModel objects
build_info()
What is known about how the model's executable was built
check_syntax() check_syntax_stan_file()
Check syntax of a Stan program
cmdstan_defaults()
Get CmdStan default argument values
diagnose()
Run Stan's diagnose method
expose_functions()
Expose Stan functions to R
format() format_stan_file()
Run stanc's auto-formatter on the model code.
generate_quantities()
Run Stan's standalone generated quantities method
is_current()
Check whether the model can run without a rebuild
laplace()
Run Stan's Laplace algorithm
model-method-model-info
Access information from a CmdStanModel object
optimize()
Run Stan's optimization algorithms
pathfinder()
Run Stan's Pathfinder Variational Inference Algorithm
sample()
Run Stan's MCMC algorithms
sample_mpi()
Run Stan's MCMC algorithms with MPI
variables() variables_stan_file()
Input and output variables of a Stan program
variational()
Run Stan's variational approximation algorithms
cmdstanr_example() print_example_program()
Fit models for use in examples

Fitted model objects and methods

CmdStanMCMC
CmdStanMCMC objects
CmdStanMLE
CmdStanMLE objects
CmdStanLaplace
CmdStanLaplace objects
CmdStanVB
CmdStanVB objects
CmdStanPathfinder
CmdStanPathfinder objects
CmdStanGQ
CmdStanGQ objects
CmdStanDiagnose
CmdStanDiagnose objects
cmdstan_summary() cmdstan_diagnose()
Run CmdStan's stansummary and diagnose utilities
code()
Return Stan code
command()
Return the command that ran CmdStan
constrain_variables()
Transform a set of unconstrained parameter values to the constrained scale
diagnostic_summary()
Sampler diagnostic summaries and warnings
draws()
Extract posterior draws
fitted_params_files()
Extract the fitted-parameter CSV files used for generated quantities
grad_log_prob()
Calculate the log-probability and the gradient w.r.t. each input for a given vector of unconstrained parameters
gradients()
Extract gradients after diagnostic mode
hessian()
Calculate the log-probability, the gradient w.r.t. each input, and the Hessian for a given vector of unconstrained parameters
init()
Extract user-specified initial values
init_model_methods()
Compile additional methods for accessing the model log-probability function and parameter constraining and unconstraining.
inv_metric()
Extract inverse metric (inverse mass matrix) after MCMC
log_prob()
Calculate the log-probability given a provided vector of unconstrained parameters.
loo()
Leave-one-out cross-validation (LOO-CV)
lp() lp_approx()
Extract log probability (target)
materialize()
Materialize model object
metadata()
Extract metadata from CmdStan CSV files
mle()
Extract point estimate after optimization
mode()
Extract the mode used for a Laplace approximation
num_chains()
Extract the number of chains
output()
Access console output
profiles()
Return profiling data
return_codes()
Extract return codes from CmdStan
sampler_diagnostics()
Extract sampler diagnostics after MCMC
save_object()
Save fitted model object to a file
save_output_files() save_latent_dynamics_files() save_profile_files() save_data_file() save_config_files() save_metric_files() output_files() profile_files() latent_dynamics_files() data_file() config_files() metric_files()
Save output and data files
summary()
Compute a summary table of estimates and diagnostics
time()
Report timing of CmdStan runs
unconstrain_draws()
Transform all parameter draws to the unconstrained scale
unconstrain_variables()
Transform a set of parameter values to the unconstrained scale
expose_functions()
Expose Stan functions to R

Other tools

read_cmdstan_csv() as_cmdstan_fit()
Read CmdStan CSV files into R
write_stan_json()
Write data to a JSON file readable by CmdStan
write_stan_file()
Write Stan code to a file
print_stan_file()
Print a Stan file with syntax highlighting in Quarto and R Markdown
draws_to_csv()
Write posterior draws objects to CSV files suitable for running standalone generated quantities with CmdStan.
as_mcmc.list()
Convert CmdStanMCMC to mcmc.list
as_draws(<CmdStanMCMC>) as_draws(<CmdStanMLE>) as_draws(<CmdStanLaplace>) as_draws(<CmdStanVB>) as_draws(<CmdStanGQ>) as_draws(<CmdStanPathfinder>)
Create a draws object from a CmdStanR fitted model object
as.CmdStanMCMC() as.CmdStanMLE() as.CmdStanLaplace() as.CmdStanVB() as.CmdStanPathfinder() as.CmdStanGQ() as.CmdStanDiagnose()
Coercion methods for CmdStan objects

Using CmdStanR with knitr and R Markdown

register_knitr_engine()
Register CmdStanR's knitr engine for Stan
eng_cmdstan()
CmdStan knitr engine for Stan