The $return_codes() method returns a vector of return codes from the CmdStan run(s). A return code of 0 indicates a successful run.

return_codes()

Value

An integer vector of return codes with length equal to the number of CmdStan runs (number of chains for MCMC and one otherwise).

See also

Examples

# \dontrun{ # example with return codes all zero fit_mcmc <- cmdstanr_example("schools", method = "sample")
#> Model executable is up to date!
#> Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
#> Chain 1 Exception: normal_lpdf: Scale parameter is 0, but must be > 0! (in '/var/folders/h6/14xy_35x4wd2tz542dn0qhtc0000gn/T/RtmpGraDrG/model-2ed21886c09b.stan', line 14, column 2 to column 41)
#> Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
#> Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
#> Chain 1
#> #> Warning: 114 of 4000 (3.0%) transitions ended with a divergence. #> This may indicate insufficient exploration of the posterior distribution. #> Possible remedies include: #> * Increasing adapt_delta closer to 1 (default is 0.8) #> * Reparameterizing the model (e.g. using a non-centered parameterization) #> * Using informative or weakly informative prior distributions
fit_mcmc$return_codes() # should be all zero
#> [1] 0 0 0 0
# example of non-zero return code (optimization fails for hierarchical model) fit_opt <- cmdstanr_example("schools", method = "optimize")
#> Model executable is up to date!
#> Optimization terminated with error:
#> Line search failed to achieve a sufficient decrease, no more progress can be made
fit_opt$return_codes() # should be non-zero
#> [1] 70
# }