sampling | R Documentation |
Draw samples from the model defined by class stanmodel
.
## S4 method for signature 'stanmodel'
sampling(object, data = list(), pars = NA,
chains = 4, iter = 2000, warmup = floor(iter/2), thin = 1,
seed = sample.int(.Machine$integer.max, 1),
init = 'random', check_data = TRUE,
sample_file = NULL, diagnostic_file = NULL, verbose = FALSE,
algorithm = c("NUTS", "HMC", "Fixed_param"),
control = NULL, include = TRUE,
cores = getOption("mc.cores", 1L),
open_progress = interactive() && !isatty(stdout()) &&
!identical(Sys.getenv("RSTUDIO"), "1"),
show_messages = TRUE, ...)
object |
An object of class |
data |
A named |
pars |
A vector of character strings specifying parameters of interest.
The default is |
chains |
A positive integer specifying the number of Markov chains. The default is 4. |
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 |
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, |
init |
Initial values specification. See the detailed documentation for
the init argument in |
check_data |
Logical, defaulting to |
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, |
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, |
verbose |
|
algorithm |
One of sampling algorithms that are implemented in Stan.
Current options are |
control |
A named |
include |
Logical scalar defaulting to |
cores |
Number of cores to use when executing the chains in parallel,
which defaults to 1 but we recommend setting the |
open_progress |
Logical scalar that only takes effect if
|
show_messages |
Either a logical scalar (defaulting to |
... |
Additional arguments can be |
An object of S4 class stanfit
representing
the fitted results. Slot mode
for this object
indicates if the sampling is done or not.
sampling
signature(object = "stanmodel")
Call a sampler (NUTS, HMC, or Fixed_param depending on parameters)
to draw samples from the model defined by S4 class stanmodel
given the data, initial values, etc.
stanmodel
, stanfit
, stan
## Not run:
m <- stan_model(model_code = 'parameters {real y;} model {y ~ normal(0,1);}')
f <- sampling(m, iter = 100)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.