Not a user-side function. Do not invoke directly.
Usage
tar_stan_vb_rep_run(
stan_file,
stan_name,
stan_path,
data,
output_type,
compile,
quiet,
stdout,
stderr,
dir,
pedantic,
include_paths,
cpp_options,
stanc_options,
force_recompile,
seed,
refresh,
init,
save_latent_dynamics,
output_dir,
algorithm,
iter,
grad_samples,
elbo_samples,
eta,
adapt_engaged,
adapt_iter,
tol_rel_obj,
eval_elbo,
output_samples,
sig_figs,
data_copy,
variables,
summaries,
summary_args,
transform
)
Arguments
- stan_file
(string) The path to a
.stan
file containing a Stan program. The helper functionwrite_stan_file()
is provided for cases when it is more convenient to specify the Stan program as a string. Ifstan_file
is not specified thenexe_file
must be specified.- stan_name
Friendly suffix of the Stan model target.
- stan_path
Original path to the input Stan file.
- data
(multiple options) The data to use for the variables specified in the data block of the Stan program. One of the following:
A named list of R objects with the names corresponding to variables declared in the data block of the Stan program. Internally this list is then written to JSON for CmdStan using
write_stan_json()
. Seewrite_stan_json()
for details on the conversions performed on R objects before they are passed to Stan.A path to a data file compatible with CmdStan (JSON or R dump). See the appendices in the CmdStan guide for details on using these formats.
NULL
or an empty list if the Stan program has no data block.
- output_type
Type of output to create, either
"summaries"
,"draws"
, or"diagnostics"
.- compile
(logical) Do compilation? The default is
TRUE
. IfFALSE
compilation can be done later via the$compile()
method.- quiet
(logical) Should the verbose output from CmdStan during compilation be suppressed? The default is
TRUE
, but if you encounter an error we recommend trying again withquiet=FALSE
to see more of the output.- stdout
Character of length 1, file path to write the stdout stream of the model when it runs. Set to
NULL
to print to the console. Set toR.utils::nullfile()
to suppress stdout. Does not apply to messages, warnings, or errors.- stderr
Character of length 1, file path to write the stderr stream of the model when it runs. Set to
NULL
to print to the console. Set toR.utils::nullfile()
to suppress stderr. Does not apply to messages, warnings, or errors.- dir
(string) The path to the directory in which to store the CmdStan executable (or
.hpp
file if using$save_hpp_file()
). The default is the same location as the Stan program.- pedantic
(logical) Should pedantic mode be turned on? The default is
FALSE
. Pedantic mode attempts to warn you about potential issues in your Stan program beyond syntax errors. For details see the Pedantic mode chapter in the Stan Reference Manual. Note: to do a pedantic check for a model without compiling it or for a model that is already compiled the$check_syntax()
method can be used instead.- include_paths
(character vector) Paths to directories where Stan should look for files specified in
#include
directives in the Stan program.- cpp_options
(list) Any makefile options to be used when compiling the model (
STAN_THREADS
,STAN_MPI
,STAN_OPENCL
, etc.). Anything you would otherwise write in themake/local
file. For an example of using threading see the Stan case study Reduce Sum: A Minimal Example.- stanc_options
(list) Any Stan-to-C++ transpiler options to be used when compiling the model. See the Examples section below as well as the
stanc
chapter of the CmdStan Guide for more details on available options: https://mc-stan.org/docs/cmdstan-guide/stanc.html.- force_recompile
(logical) Should the model be recompiled even if was not modified since last compiled. The default is
FALSE
. Can also be set via a globalcmdstanr_force_recompile
option.- seed
(positive integer(s)) A seed for the (P)RNG to pass to CmdStan. In the case of multi-chain sampling the single
seed
will automatically be augmented by the the run (chain) ID so that each chain uses a different seed. The exception is the transformed data block, which defaults to using same seed for all chains so that the same data is generated for all chains if RNG functions are used. The only timeseed
should be specified as a vector (one element per chain) is if RNG functions are used in transformed data and the goal is to generate different data for each chain.- refresh
(non-negative integer) The number of iterations between printed screen updates. If
refresh = 0
, only error messages will be printed.- init
(multiple options) The initialization method to use for the variables declared in the parameters block of the Stan program. One of the following:
A real number
x>0
. This initializes all parameters randomly between[-x,x]
on the unconstrained parameter space.;The number
0
. This initializes all parameters to0
;A character vector of paths (one per chain) to JSON or Rdump files containing initial values for all or some parameters. See
write_stan_json()
to write R objects to JSON files compatible with CmdStan.A list of lists containing initial values for all or some parameters. For MCMC the list should contain a sublist for each chain. For other model fitting methods there should be just one sublist. The sublists should have named elements corresponding to the parameters for which you are specifying initial values. See Examples.
A function that returns a single list with names corresponding to the parameters for which you are specifying initial values. The function can take no arguments or a single argument
chain_id
. For MCMC, if the function has argumentchain_id
it will be supplied with the chain id (from 1 to number of chains) when called to generate the initial values. See Examples.
- save_latent_dynamics
(logical) Should auxiliary diagnostic information about the latent dynamics be written to temporary diagnostic CSV files? This argument replaces CmdStan's
diagnostic_file
argument and the content written to CSV is controlled by the user's CmdStan installation and not CmdStanR (for some algorithms no content may be written). The default isFALSE
, which is appropriate for almost every use case. To save the temporary files created whensave_latent_dynamics=TRUE
see the$save_latent_dynamics_files()
method.- output_dir
(string) A path to a directory where CmdStan should write its output CSV files. For interactive use this can typically be left at
NULL
(temporary directory) since CmdStanR makes the CmdStan output (posterior draws and diagnostics) available in R via methods of the fitted model objects. The behavior ofoutput_dir
is as follows:If
NULL
(the default), then the CSV files are written to a temporary directory and only saved permanently if the user calls one of the$save_*
methods of the fitted model object (e.g.,$save_output_files()
). These temporary files are removed when the fitted model object is garbage collected (manually or automatically).If a path, then the files are created in
output_dir
with names corresponding to the defaults used by$save_output_files()
.
- algorithm
(string) The algorithm. Either
"meanfield"
or"fullrank"
.- iter
(positive integer) The maximum number of iterations.
- grad_samples
(positive integer) The number of samples for Monte Carlo estimate of gradients.
- elbo_samples
(positive integer) The number of samples for Monte Carlo estimate of ELBO (objective function).
- eta
(positive real) The step size weighting parameter for adaptive step size sequence.
- adapt_engaged
(logical) Do warmup adaptation?
- adapt_iter
(positive integer) The maximum number of adaptation iterations.
- tol_rel_obj
(positive real) Convergence tolerance on the relative norm of the objective.
- eval_elbo
(positive integer) Evaluate ELBO every Nth iteration.
- output_samples
(positive integer) Use
draws
argument instead.output_samples
will be deprecated in the future.- sig_figs
(positive integer) The number of significant figures used when storing the output values. By default, CmdStan represent the output values with 6 significant figures. The upper limit for
sig_figs
is 18. Increasing this value will result in larger output CSV files and thus an increased usage of disk space.- data_copy
Character vector of names of scalars in
data
. These values will be inserted as columns in the output data frame for each rep. To join more than just scalars, include a.join_data
element of your Stan data list with names and dimensions corresponding to those of the model. For details, read https://docs.ropensci.org/stantargets/articles/simulation.html.- variables
(character vector) Optionally, the names of the variables (parameters, transformed parameters, and generated quantities) to read in.
If
NULL
(the default) then all variables are included.If an empty string (
variables=""
) then none are included.For non-scalar variables all elements or specific elements can be selected:
variables = "theta"
selects all elements oftheta
;variables = c("theta[1]", "theta[3]")
selects only the 1st and 3rd elements.
- summaries
Optional list of summary functions passed to
...
inposterior::summarize_draws()
through$summary()
on theCmdStanFit
object.- summary_args
Optional list of summary function arguments passed to
.args
inposterior::summarize_draws()
through$summary()
on theCmdStanFit
object.- transform
Symbol or
NULL
, name of a function that accepts argumentsdata
anddraws
and returns a data frame. Here,data
is the JAGS data list supplied to the model, anddraws
is a data frame with one column per model parameter and one row per posterior sample. Any arguments other thandata
anddraws
must have valid default values becausestantargets
will not populate them. See the simulation-based calibration (SBC) section of the simulation vignette for an example.