runjags models | R Documentation |
Using the runjags (Denwood 2016) package to produce JAGS-based forecasts.
fit_runjags
: Wraps up the runjags model object preparation functions with the model running (run.jags
function in the runjags (Denwood 2016) package) we use to run JAGS (Plummer 2003) models in portalcasting.
runjags_data
, runjags_monitor
, runjags_model
, runjags_inits
: Produce the model-specific components as named.
forecast.runjags
: A convenience function for extracting existing forecasts from runjags objects and summarizing them into a "forecast"
-class object.
runjags_controls
: Combines the run.jags
control parameters that users may be interested in changing with a few portalcasting-specific parameters into a control list for input into specific model functions.
runjags_inits(inits)
runjags_model(model_file)
runjags_monitors(monitors, metadata)
runjags_data(data_names, abundance, metadata, covariates)
fit_runjags(
abundance,
metadata,
covariates,
monitors,
inits,
model_file,
data_names,
control_runjags = runjags_controls()
)
## S3 method for class 'runjags'
forecast(object, h, level, nsamples, seed = NULL, ...)
runjags_controls(
nchains = 4,
adapt = 10000,
burnin = 10000,
sample = 10000,
thin = 10,
modules = "glm",
method = "interruptible",
factories = "",
mutate = NA,
silent_jags = FALSE
)
inits |
|
model_file |
|
monitors |
|
metadata |
|
data_names |
|
abundance |
Non-negative |
covariates |
|
control_runjags |
|
object |
A |
h |
|
level |
|
nsamples |
|
seed |
A single |
... |
Additional parameters |
nchains |
Non-negative |
adapt |
Non-negative |
burnin |
Non-negative |
sample |
Non-negative |
thin |
Positive |
modules |
|
method |
|
factories |
|
mutate |
A |
silent_jags |
|
fit_runjags
: An object of class "runjags"
of model components. See run.jags
.
runjags_data
: A list
of model-specific data for use in run.jags
.
runjags_monitor
: A vector
of model-specific character
values of parameters to track in run.jags
.
runjags_model
: A single character
value of the JAGS model block for run.jags
.
runjags_inits
: A function
that takes the argument data
to produce chain-specific initial values for run.jags
.
runjags_controls
: A list
of controls.
forecast.runjags
: list
with "forecast"
-class with named elements including "mean"
, "lower"
, "upper"
, and "level"
.
Denwood, M. J. 2016. runjags: an R package providing interface utilities, model templates, parallel computing methods and additional distributions for MCMC models in JAGS. Journal of Statistical Software, 71:9. URL.
Plummer, M. 2003. JAGS: A program for analysis of Bayesian graphical models using Gibbs Sampling. Proceedings of the 3rd International Workshop on Distributed Statistical Computing (DSC 2003). ISSN 1609-395X.
Helper functions for prefab models:
prefabricated models
,
tsglm models
## Not run:
main1 <- file.path(tempdir(), "runjags")
setup_dir(main = main1)
dataset <- "all"
species <- "DM"
model <- "jags_RW"
model_file <- gsub("'", "",
models_controls(main1)[[model]]$fit$full_model_file)
abundance <- prepare_abundance(main = main1,
dataset = dataset,
species = species,
model = model)
model_controls <- models_controls(main = main1,
models = model)[[model]]
metadata <- read_metadata(main = main1)
newmoons <- read_newmoons(main = main1)
covariates <- read_covariates(main = main1)
control_runjags <- runjags_controls(nchains = 3,
adapt = 1e3,
burnin = 1e3,
sample = 1e3,
thin = 1)
data_names <- c("count", "N", "log_mean_count")
runjags_model(model_file = model_file)
runjags_monitors(monitors = c("mu", "sigma"),
metadata = metadata)
data <- runjags_data(data_names = data_names,
abundance = abundance,
metadata = metadata,
covariates = covariates)
runjags_inits(inits = list(mu = rnorm(1, mean = data$log_mean_count, sd = 0.1),
sigma = runif(1, min = 0.01, max = 0.5)))
fit <- fit_runjags(abundance = abundance,
metadata = metadata,
covariates = covariates,
monitors = c("mu", "sigma"),
inits = list(mu = rnorm(1, data$log_mean_count, 0.1),
sigma = runif(1, 0.01, 0.5)),
model_file = model_file,
data_names = data_names,
control_runjags = control_runjags)
forecast(object = fit,
h = metadata$time$lead_time_newmoons,
level = metadata$confidence_level,
nsamples = metadata$nsamples)
unlink(main1, recursive = TRUE)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.