Fit models for use in examples
cmdstanr_example(
example = c("logistic", "schools", "schools_ncp"),
method = c("sample", "optimize", "laplace", "variational", "pathfinder", "diagnose"),
...,
quiet = TRUE,
force_recompile = getOption("cmdstanr_force_recompile", default = FALSE)
)
print_example_program(example = c("logistic", "schools", "schools_ncp"))(string) The name of the example. The currently available examples are
"logistic": logistic regression with intercept and 3 predictors.
"schools": the so-called "eight schools" model, a hierarchical
meta-analysis. Fitting this model will result in warnings about
divergences.
"schools_ncp": non-centered parameterization of the "eight schools"
model that fixes the problem with divergences.
To print the Stan code for a given example use
print_example_program(example).
(string) Which fitting method should be used? The default is
the "sample" method (MCMC).
Arguments passed to the chosen method. See the help pages for
the individual methods for details.
(logical) If TRUE (the default) then fitting the model is
wrapped in utils::capture.output().
Passed to the $compile() method.
The fitted model object returned by the selected method.
if (FALSE) { # \dontrun{
print_example_program("logistic")
fit_logistic_mcmc <- cmdstanr_example("logistic", chains = 2)
fit_logistic_mcmc$summary()
fit_logistic_optim <- cmdstanr_example("logistic", method = "optimize")
fit_logistic_optim$summary()
fit_logistic_vb <- cmdstanr_example("logistic", method = "variational")
fit_logistic_vb$summary()
print_example_program("schools")
fit_schools_mcmc <- cmdstanr_example("schools")
fit_schools_mcmc$summary()
print_example_program("schools_ncp")
fit_schools_ncp_mcmc <- cmdstanr_example("schools_ncp")
fit_schools_ncp_mcmc$summary()
# optimization fails for hierarchical model
cmdstanr_example("schools", "optimize", quiet = FALSE)
} # }