run_model: Run JAGS model for prepared species data

View source: R/run-model.R

run_modelR Documentation

Run JAGS model for prepared species data

Description

run-model runs a JAGS model as specified by the user for the species of interest

Usage

run_model(
  jags_data = NULL,
  model_file_path = NULL,
  inits = NULL,
  parameters_to_save = c("n"),
  track_n = TRUE,
  n_chains = 3,
  n_adapt = NULL,
  n_burnin = 20000,
  n_thin = 10,
  n_saved_steps = 2000,
  n_iter = 10000,
  parallel = FALSE,
  n_cores = NULL,
  quiet = FALSE,
  modules = NULL,
  ...
)

Arguments

jags_data

List or environment containing the data to model, as output by prepare_jags_data

model_file_path

Path to custom model. Overrides the model variable set by prepare_jags_data

inits

Optional list of initialization values for JAGS model. If none are specified, the JAGS model will generate its own initial values.

parameters_to_save

Character vector of parameters to monitor in JAGS. Defaults to just monitoring "n"

track_n

By default, the parameter "n" will always be tracked, even if the user forgets to specify it. However, if the user is positive they do not want to track "n", this parameter can be be set to FALSE. NOTE: you will not be able to generate annual indices if "n" is not tracked.

n_chains

Optional number of chains to run. Defaults to 3.

n_adapt

Optional integer specifying the number of steps to adapt the JAGS model. The default is NULL, which will result in the function running groups of 100 adaptation iterations (to amax of 10,000) until JAGS reports adaptation is sufficient. If you set it manually, 1000 is the recommended minimum value.

n_burnin

Optional integer specifying the number of iterations to burn in the model. Defaults to 20000 per chain.

n_thin

Optional number of steps to thin or discard.

n_saved_steps

Optional number of steps to save per chain. Defaults to 2000.

n_iter

Optional number of iterations per chain. Defaults to 10000.

parallel

Should each chain be run parallel on separate cores?

n_cores

Number of cores to use if running in parallel. If NULL (default), and parallel = TRUE, the number of cores used will be the minimum of the n_chains specified and the number of cores on your computer

quiet

Should JAGS output be suppressed?

modules

Character vector of JAGS modules to load before analysis. By default no extra modules are loaded (other than 'basemod' and 'bugs'). To force glm or other modules to load, use modules = "glm". Be warned, our experience suggests that including the glm module may cause problems with the BBS data.

...

Additional arguments

Value

jagsUI object

Examples


# Toy example with Pacific Wren sample data
# First, stratify the sample data

strat_data <- stratify(by = "bbs_cws", sample_data = TRUE)

# Prepare the stratified data for use in a JAGS model.
jags_data <- prepare_jags_data(strat_data = strat_data,
                               species_to_run = "Pacific Wren",
                               model = "firstdiff",
                               min_year = 2009,
                               max_year = 2018)

# Now run a JAGS model. For the sake of speed, we've adjusted
#   some arguments so that the JAGS model will not run any
#   adaptation steps (n_adapt = 0), no burnin steps (n_burnin = 0),
#   only 50 iterations per chain (n_iter = 50), and will not
#   thin the chain (n_thin = 1). This will produce several convergence
#   warnings, but we can ignore them for the sake of this toy example.

jags_mod <- run_model(jags_data = jags_data,
                      n_adapt = 0,
                      n_burnin = 0,
                      n_iter = 10,
                      n_thin = 1,
                      parameters_to_save = c("n", "strata"))


BrandonEdwards/bbsBayes documentation built on March 3, 2023, 9:55 a.m.