runjags-class: The runjags class and available S3 methods

runjags-classR Documentation

The runjags class and available S3 methods


Objects of class 'runjags' are produced by run.jags, results.jags and autorun.jags, and contain the MCMC chains as well as all information required to extend the simulation. These are a number of utility functions associated with these objects.


## S3 method for class 'runjags'
as.mcmc(x, vars = NA, add.mutate = TRUE, ...)

## S3 method for class 'runjags'
as.mcmc.list(x, vars = NA, add.mutate = TRUE, ...)

## S3 method for class 'runjags'
as.jags(x, adapt = 1000, quiet = FALSE, ...)

## S3 method for class 'jags'
  monitor = stop("No monitored variables supplied"),
  modules = runjags.getOption("modules"),
  factories = runjags.getOption("factories"),
  jags = runjags.getOption("jagspath"),
  mutate = NA,
  check = TRUE,


cleanup.jags(all.folders = FALSE, silent = FALSE)

cleanup.JAGS(all.folders = FALSE, silent = FALSE)

failed.jags(show = c("model", "output"))

as.jags(x, adapt = 1000, quiet = FALSE, ...)

## Default S3 method:
as.jags(x, ...)

as.runjags(jags.model, ...)

## Default S3 method:
as.runjags(jags.model, ...)

## S3 method for class 'runjags'
  variable = object$residual,
  show.summary = FALSE,
  output = "mean",

## S3 method for class 'runjags'
  variable = object$fitted,
  show.summary = FALSE,
  output = "mean",



an object of class runjags.


an optional character vector of variable names to extract. If supplied, only variable names in the object supplied with a partial match to anything in 'vars' will be summarised/plotted/extracted. Note that regular expressions are not allowed, but the caret (^) token can be used to specify the match at the start of a variable name, and a quoted vars will be matched exactly. Default NA meaning all variables available are returned.


option to use the inbuild mutate function to produce additional MCMC variables before returning the MCMC object.


additional options to be passed to default methods or additional functions.


as for jags.model


as for jags.model


a model produced by jags.model


a character vector of the names of variables to monitor, as for run.jags


a character vector of external modules to be loaded into JAGS, either as the module name on its own or as the module name and status separated by a space, for example 'glm on'.


a character vector of factory modules to be loaded into JAGS. Factories should be provided in the format '\<facname\> \<factype\> \<status\>' (where status is optional), for example: factories='mix::TemperedMix sampler on'. You must also ensure that any required modules are also specified (in this case 'mix').


the system call or path for activating JAGS. Default uses the option given in runjags.options.


either a function or a list with first element a function and remaining elements arguments to this function that can be used to add variables to the model output. See add.summary for more details.


option to check that the model can be (re)-compiled.


option to remove ALL simulation folders created using keep.jags.files=TRUE and not just unsuccessful simulations.


option to suppress feedback when deleting simulation folders.


which parts of the failed JAGS simulation to display - options are: 'model', 'data', 'inits', 'output', 'end.state', 'all'


an object of class runjags.


the name of the variable within the JAGS simulation that denotes the residual/fitted variable. This must be specified to be able to use the residuals and fitted methods.


option to show the full summary statistics of the returned models before extracting just the residuals/fitted variable information.


the type of output required for the residuals and fitted methods - options are: 'mean', 'mcmc', 'hpd', 'summary', 'runjags'.


The functions and methods detailed here permit conversion of runjags objects to MCMC objects and to/from jags models created by jags.model. There are also S3 methods for print, summary and plot available for runjags class objects - see add.summary for details of the arguments available to these. The 'failed.jags' function allows the user to interrogate the details of JAGS models that failed to compile or produce MCMC output. By default, any simulation folders for models that failed to import are kept until the R session is ended - in some circumstances it may be possible to partially recover the results using results.jags. The cleanup.jags function can be used to remove simulation folders created in the current R session, and is called when the runjags package is unloaded.

See Also

add.summary for details on plot, print and summary methods for runjags class objects, extract.runjags for a method to extract peripheral information from runjags objects, runjags.options for general options available, and run.jags and autorun.jags for the functions that create objects of this class.


# Coercion between jags and runjags objects (requires loading the rjags package):
jags.model <- LINE
runjags.model <- as.runjags(jags.model, monitor=c('alpha','beta'))
## Not run: 
runjags.model <- extend.jags(runjags.model)
jags.model <- as.jags(runjags.model)
# Coercion to MCMC (requires loading the coda package):
mcmc <- as.mcmc.list(runjags.model)

## End(Not run)

runjags documentation built on April 15, 2022, 5:05 p.m.