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.
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
)
jags syntax for the model part
list containing data to fit the model (not including data for the formulas)
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)
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)
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 formula
number of chains to be run, defaults to 4
number of samples used for adapting the MCMC chains, defaults to 500
number of burnin iterations of the MCMC chains, defaults to 1000
number of sampling iterations of the MCMC chains, defaults to 4000
thinning interval for the MCMC samples, defaults to 1
whether the models should be refitted until convergence criteria
specified in autofit_control
. Defaults to FALSE
.
a list of arguments controlling the autofit function. Possible options are:
maximum R-hat error for the autofit function.
Defaults to 1.05
.
minimum effective sample size. Defaults to 500
.
maximum MCMC error. Defaults to 1.01
.
maximum MCMC error as the proportion of standard
deviation of the parameters. Defaults to 0.05
.
list specifying the time time
and units
after which the automatic fitting function is stopped. The units arguments
need to correspond to units
passed to difftime function.
number of samples between each convergence check. Defaults to
1000
.
number of times new initial values should be generated in case the model
fails to initialize. Defaults to 10
.
whether the chains should be run in parallel FALSE
number of cores used for multithreading if parallel = TRUE
,
defaults to chains
whether the function should proceed silently, defaults to TRUE
seed for random number generation
vector of additional parameter names that should be used
monitored but were not specified in the prior_list
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 NULL
.
a 'BayesTools_fit' object (created by JAGS_fit()
function) to be
extended
JAGS_fit
returns an object of class 'runjags' and 'BayesTools_fit'.
if (FALSE) {
# 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)
}