JAGS_fit {BayesTools} | R Documentation |
Fits a 'JAGS' model
Description
A wrapper around run.jags that simplifies fitting 'JAGS' models with usage with pre-specified model part of the 'JAGS' syntax, data and list of prior distributions.
Usage
JAGS_fit(
model_syntax,
data = NULL,
prior_list = NULL,
formula_list = NULL,
formula_data_list = NULL,
formula_prior_list = NULL,
chains = 4,
adapt = 500,
burnin = 1000,
sample = 4000,
thin = 1,
autofit = FALSE,
autofit_control = list(max_Rhat = 1.05, min_ESS = 500, max_error = 0.01, max_SD_error =
0.05, max_time = list(time = 60, unit = "mins"), sample_extend = 1000, restarts = 10),
parallel = FALSE,
cores = chains,
silent = TRUE,
seed = NULL,
add_parameters = NULL,
required_packages = NULL
)
JAGS_extend(
fit,
autofit_control = list(max_Rhat = 1.05, min_ESS = 500, max_error = 0.01, max_SD_error =
0.05, max_time = list(time = 60, unit = "mins"), sample_extend = 1000, restarts = 10),
parallel = FALSE,
cores = NULL,
silent = TRUE,
seed = NULL
)
Arguments
model_syntax |
jags syntax for the model part |
data |
list containing data to fit the model (not including data for the formulas) |
prior_list |
named list of prior distribution
(names correspond to the parameter names) of parameters not specified within the
|
formula_list |
named list of formulas to be added to the model (names correspond to the parameter name created by each of the formula) |
formula_data_list |
named list of data frames containing data for each formula (names of the lists correspond to the parameter name created by each of the formula) |
formula_prior_list |
named list of named lists of prior distributions
(names of the lists correspond to the parameter name created by each of the formula and
the names of the prior distribution correspond to the parameter names) of parameters specified
within the |
chains |
number of chains to be run, defaults to |
adapt |
number of samples used for adapting the MCMC chains, defaults to |
burnin |
number of burnin iterations of the MCMC chains, defaults to |
sample |
number of sampling iterations of the MCMC chains, defaults to |
thin |
thinning interval for the MCMC samples, defaults to |
autofit |
whether the models should be refitted until convergence criteria
specified in |
autofit_control |
a list of arguments controlling the autofit function. Possible options are:
|
parallel |
whether the chains should be run in parallel |
cores |
number of cores used for multithreading if |
silent |
whether the function should proceed silently, defaults to |
seed |
seed for random number generation |
add_parameters |
vector of additional parameter names that should be used
monitored but were not specified in the |
required_packages |
character vector specifying list of packages containing
JAGS models required for sampling (in case that the function is run in parallel or in
detached R session). Defaults to |
fit |
a 'BayesTools_fit' object (created by |
Value
JAGS_fit
returns an object of class 'runjags' and 'BayesTools_fit'.
See Also
Examples
## Not run:
# simulate data
set.seed(1)
data <- list(
x = rnorm(10),
N = 10
)
data$x
# define priors
priors_list <- list(mu = prior("normal", list(0, 1)))
# define likelihood for the data
model_syntax <-
"model{
for(i in 1:N){
x[i] ~ dnorm(mu, 1)
}
}"
# fit the models
fit <- JAGS_fit(model_syntax, data, priors_list)
## End(Not run)