fit | R Documentation |
Runs a Bayesian MCMC using rstan to draw samples of a model of the class FOImodel
, with data of the class SeroData
.
It is an adaptation of the function sampling
in the rstan package.
fit(
model,
data = data,
iter = 5000,
chains = 4,
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,
...
)
## S3 method for class 'FOIfit'
print(x, digits_summary = 2, ...)
## S3 method for class 'FOIfit'
summary(x, ...)
model |
A |
data |
A |
iter |
integer. Number of iterations for each chain, including warmup. Default = 5000. |
chains |
integer. Number of independent Markov chains. Default = 4. |
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 not be larger than iter and the default is iter/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, |
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 |
A list with the class FOIfit
, which contains the
following items:
fit: The results of the fit, of class stanfit
.
data: The input data.
model: The input model.
Nathanael Hoze nathanael.hoze@gmail.com
SeroData
Define the format of the serological data.
FOImodel
Define a model.
data <- simulate_SeroData(number_samples = 1000,
age_class = 1,
epidemic_years = c(1976,1992),
foi = c(0.2,0.3))
model <- FOImodel('outbreak', K = 2)
F1 <- fit(model = model, data = data)
seroprevalence.fit(F1)
plot(F1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.