Function reference • cmdstanr

# Reference

## Package description An overview of the package and how it differs from RStan.
`cmdstanr-package` `cmdstanr` `CmdStanR` | CmdStanR: the R interface to CmdStan
## 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()` | Create a new CmdStanModel object
`CmdStanModel` | CmdStanModel objects
`check_syntax()` | Check syntax of a Stan program
`compile()` | Compile a Stan program
`diagnose()` | Run Stan's diagnose method
`expose_functions()` | Expose Stan functions to R
`format()` | Run stanc's auto-formatter on the model code.
`generate_quantities()` | Run Stan's standalone generated quantities method
`optimize()` | Run Stan's optimization algorithms
`sample()` | Run Stan's MCMC algorithms
`sample_mpi()` | Run Stan's MCMC algorithms with MPI
`variables()` | 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
`CmdStanVB` | CmdStanVB objects
`CmdStanGQ` | CmdStanGQ objects
`CmdStanDiagnose` | CmdStanDiagnose objects
`cmdstan_summary()` `cmdstan_diagnose()` | Run CmdStan's `stansummary` and `diagnose` utilities
`code()` | Return Stan code
`constrain_variables()` | Transform a set of unconstrained parameter values to the constrained scale
`diagnostic_summary()` | Sampler diagnostic summaries and warnings
`draws()` | Extract posterior draws
`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 (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)
`metadata()` | Extract metadata from CmdStan CSV files
`mle()` | Extract (penalized) maximum likelihood estimate after optimization
`num_chains()` | Extract number of chains after MCMC
`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()` `output_files()` `profile_files()` `latent_dynamics_files()` `data_file()` | 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
`variable_skeleton()` | Return the variable skeleton for `relist`
`expose_functions()` | Expose Stan functions to R
## Other tools for working with CmdStan
`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
`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(<CmdStanVB>)` `as_draws(<CmdStanGQ>)` | Create a `draws` object from a CmdStanR fitted model object
## Using CmdStanR with knitr and R Markdown
`register_knitr_engine()` | Register CmdStanR's knitr engine for Stan
`eng_cmdstan()` | CmdStan knitr engine for Stan