Learn R Programming

runjags (version 1.2.1-0)

runjags-class: The 'runjags' class (and associated classes) and available S3 methods

Description

Objects of class 'runjags' are produced by the run.jags/extend.jags/autorun.jags etc functions, and can be passed to extend.jags and autoextend.jags to extend the simulation. They also have a few specific S3 methods for print, plot and extraction of the MCMC objects contained within the runjags object.

Objects of class 'runjags.bginfo' represents a JAGS model being run using a background method and can be passed to the results.jags function to retrieve (a copy of this object will also have been saved to 'jagsinfo.Rsave' in the working directory of the background JAGS call in case the returned object is not saved by the user).

Objects of class 'runjags.study' are produced by the run.jags.study function.

These functions provide print and plot methods, and conversion facilities to/from MCMC objects and objects of class 'jags' for compatibility with the rjags package.

The 'failedjags' environment is used to store JAGS model/data/initial value files from failed simulations for inspection by the user.

Usage

## S3 method for class 'runjags':
print(x, vars=NA, digits = 5, ...)
	## S3 method for class 'runjags':
plot(x,vars=NA, layout=NA, 
	newwindows=runjags.getOption("newwindows"), file="", type="all", ...)
	
	## S3 method for class 'runjags.model':
print(x, linenumbers=runjags.getOption("linenumbers"), ...)
	## S3 method for class 'runjags.data':
print(x, linenumbers=runjags.getOption("linenumbers"), ...)
	## S3 method for class 'runjags.inits':
print(x, linenumbers=runjags.getOption("linenumbers"), ...)
	## S3 method for class 'runjags.output':
print(x, linenumbers=runjags.getOption("linenumbers"), ...)
	
	## S3 method for class 'runjags.study':
print(x,...)
	## S3 method for class 'runjags.bginfo':
print(x, ...)
	
	## S3 method for class 'runjags':
as.mcmc(x)
	## S3 method for class 'runjags':
as.mcmc.list(x, vars=NA, ...)

## S3 method for class 'runjags': as.jags(x, ...) ## S3 method for class 'jags': as.runjags(x, monitor, modules=runjags.getOption('modules'), factories=runjags.getOption('factories'), check=TRUE, jags = runjags.getOption('jagspath'), ...)

Arguments

x
an object of class 'runjags' (as returned by the run.jags or autorun.jags functions), or for the as.runjags method an object of class 'jags' (as return
vars
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 ca
digits
the number of significant digits to display for tabulated statistics. Default 5.
layout
a numeric vector of length 2 representing the number of rows and columns to produce plots in. Default 1 plot per page for trace and density options, or a single row of 2 plots if plotting both types.
newwindows
if there are a greater number of variables than will fit on one page, should new graphics windows be created for each plot or the exisiting device used for all plots? Ignored if writing plots to file. Default TRUE on Mac/Windows GUI systems, and FALSE o
file
an optional character string representing a filename to save plots to (as a PDF) rather than using the default graphics device. Default "" (ie don't write to file).
type
option to produce 'trace' plots, 'density' plots, a 'crosscorr' plot or 'all'. Cases are ignored and partial matching is used; the argument may also be of length >1. Default 'all'.
linenumbers
option to prepend lines with line numbers for runjags model/data/initial value strings. This may be helpful for debugging against the output of (failed) JAGS runs. Default TRUE.
...
other options to be passed down to underlying methods where available (ignored for plot.runjags - see below).
monitor
a character vector of the names of variables to monitor. No default.
modules
external modules to be loaded into JAGS. More than 1 module can be used. Default none.
factories
factory modules to be loaded into JAGS. More than 1 factory can be used. Factories should be in the format '()', for example: factories='mix::TemperedMix(sampler)'. Default none.
check
should the runjags object returned be checked to ensure that an external call to JAGS is able to run the model? Default TRUE.
jags
the system call or path for activating JAGS (ignored if check==FALSE). Default calls findjags() to attempt to locate JAGS on your system.

Value

  • The print method for runjags objects displays a range of summary statistics for the MCMC chains (similar to that produced by summary.mcmc, but with additional details).

    The plot method produces trace and density plots (note that these are pre-plotted and stored inside the runjags object, so the usual options to lattice or plot functions are not available).

    The as.mcmc method combines the chains (with a warning) and returns an mcmc object, and the as.mcmc.list method extracts the mcmc.list from the runjags object (or possibly a sub-selection of variables given by vars). See also combine.mcmc which can be used directly on runjags objects.

    The print methods for runjags model, data and initial value strings simply provide the option for printing line numbers which may be useful for debugging. The print methods for runjags.study and runjags.bginfo objects provide a basic overview of the objects.

    The as.jags method allows runjags objects to be converted to rjags style compiled JAGS models - additional arguments adapt and quiet are passed directly to jags.model, other arguments are ignored. If the runjags object already contains a compiled JAGS model, this is returned directly without re-compilation.

Details

The runjags class contains the full model, data, modules, factories etc required to run JAGS and is designed to encapsulate the model in a similar vein to the 'lm' or 'mer' class. Most interaction with a runjags object should be done using the print/plot/as.mcmc.list methods, but it may also be helpful to access some elements of the list directly - the names of the elements can be access using 'names(runjags.object)'. For example, this is currently the only method of extracting the full pd/popt/pd.i information.

See Also

runjags.options,

combine.mcmc,

run.jags,

autorun.jags,

summary.mcmc