Default Parameters for Sampling Hamstr Models with Stan
get_stan_sampler_args.Rd
Returns a list of parameters for the Stan sampler
Usage
get_stan_sampler_args(
chains = 4,
cores = chains,
iter = 2000,
warmup = floor(iter/2),
thin = 1,
seed = sample.int(.Machine$integer.max, 1),
check_data = TRUE,
sample_file = NULL,
diagnostic_file = NULL,
verbose = FALSE,
algorithm = c("NUTS", "HMC", "Fixed_param"),
control = NULL,
include = TRUE,
open_progress = interactive() && !isatty(stdout()) && !identical(Sys.getenv("RSTUDIO"),
"1"),
show_messages = TRUE,
...
)
Arguments
- chains
A positive integer specifying the number of Markov chains. The default is 4.
- cores
Number of cores to use when executing the chains in parallel, which defaults to 1 but we recommend setting the
mc.cores
option to be as many processors as the hardware and RAM allow (up to the number of chains).- iter
A positive integer specifying the number of iterations for each chain (including warmup). The default is 2000.
- warmup
A positive integer specifying the number of warmup (aka burnin) iterations per chain. If step-size adaptation is on (which it is by default), this also controls the number of iterations for which adaptation is run (and hence these warmup samples should not be used for inference). The number of warmup iterations should be smaller than
iter
and the default isiter/2
.- thin
A positive integer specifying the period for saving samples. The default is 1, which is usually the recommended value.
- seed
The seed for random number generation. The default is generated from 1 to the maximum integer supported by R on the machine. Even if multiple chains are used, only one seed is needed, with other chains having seeds derived from that of the first chain to avoid dependent samples. When a seed is specified by a number,
as.integer
will be applied to it. Ifas.integer
producesNA
, the seed is generated randomly. The seed can also be specified as a character string of digits, such as"12345"
, which is converted to integer.- check_data
Logical, defaulting to
TRUE
. IfTRUE
the data will be preprocessed; otherwise not. See the Passing data to Stan section instan
.- sample_file
An optional character string providing the name of a file. If specified the draws for all parameters and other saved quantities will be written to the file. If not provided, files are not created. When the folder specified is not writable,
tempdir()
is used. When there are multiple chains, an underscore and chain number are appended to the file name prior to the.csv
extension.- diagnostic_file
An optional character string providing the name of a file. If specified the diagnostics data for all parameters will be written to the file. If not provided, files are not created. When the folder specified is not writable,
tempdir()
is used. When there are multiple chains, an underscore and chain number are appended to the file name prior to the.csv
extension.- verbose
TRUE
orFALSE
: flag indicating whether to print intermediate output from Stan on the console, which might be helpful for model debugging.- algorithm
One of sampling algorithms that are implemented in Stan. Current options are
"NUTS"
(No-U-Turn sampler, Hoffman and Gelman 2011, Betancourt 2017),"HMC"
(static HMC), or"Fixed_param"
. The default and preferred algorithm is"NUTS"
.- control
A named
list
of parameters to control the sampler's behavior. See the details in the documentation for thecontrol
argument instan
.- include
Logical scalar defaulting to
TRUE
indicating whether to include or exclude the parameters given by thepars
argument. IfFALSE
, only entire multidimensional parameters can be excluded, rather than particular elements of them.- open_progress
Logical scalar that only takes effect if
cores > 1
but is recommended to beTRUE
in interactive use so that the progress of the chains will be redirected to a file that is automatically opened for inspection. For very short runs, the user might preferFALSE
.- show_messages
Either a logical scalar (defaulting to
TRUE
) indicating whether to print the summary of Informational Messages to the screen after a chain is finished or a character string naming a path where the summary is stored. Setting toFALSE
is not recommended unless you are very sure that the model is correct up to numerical error.- ...
Additional arguments can be
chain_id
,init_r
,test_grad
,append_samples
,refresh
,enable_random_init
. See the documentation instan
.
Examples
get_stan_sampler_args()
#> $chains
#> [1] 4
#>
#> $cores
#> [1] 4
#>
#> $iter
#> [1] 2000
#>
#> $warmup
#> [1] 1000
#>
#> $thin
#> [1] 1
#>
#> $seed
#> [1] 346871191
#>
#> $check_data
#> [1] TRUE
#>
#> $sample_file
#> NULL
#>
#> $diagnostic_file
#> NULL
#>
#> $verbose
#> [1] FALSE
#>
#> $algorithm
#> [1] "NUTS" "HMC" "Fixed_param"
#>
#> $control
#> NULL
#>
#> $include
#> [1] TRUE
#>
#> $open_progress
#> [1] FALSE
#>
#> $show_messages
#> [1] TRUE
#>