JAGS

Overview

JAGS is Just Another Gibbs Sampler. It is a program for analysis of Bayesian hierarchical models using Markov Chain Monte Carlo (MCMC) simulation not wholly unlike BUGS. JAGS was written with three aims in mind:

  • To have a cross-platform engine for the BUGS language
  • To be extensible, allowing users to write their own functions, distributions and samplers.
  • To be a platform for experimentation with ideas in Bayesian modelling

It is often used alongside the R package R2jags which provides wrapper functions and can be installed from CRAN.

The RJAGS libraries will also be used if you install the rjags or JMbayes R packages. Please see the note below about which version of RJAGS you should use for this purpose.

Restrictions on use

All users may access and use JAGS.

JAGS is licensed under the GNU General Public License version 2. You may freely modify and redistribute it under certain conditions.

Set up procedure

We now recommend loading modulefiles within your jobscript so that you have a full record of how the job was run. See the example jobscript below for how to do this. Alternatively, you may load modulefiles on the login node and let the job inherit these settings.

Load one of the following modulefiles:

module load apps/gcc/jags/4.3.0              # Suitable for standalone use (system-wide GCC 4.8.5)

module load apps/gcc/jags/4.3.0-gcc-8.2.0    # Use to install packages that use rjags in R 3.6.2.

Running the application

Please do not run JAGS commands on the login node. qrsh is recommended for some commands. Computationally intense work should be done via the batch system.

Examples

The following example first runs jags as a serial job.

#!/bin/bash --login
#$ -cwd
module load apps/gcc/jags/4.3.0

jags <script file>

and submit the job using qsub jobscript where jobscript is the name of your job script file.

Installing R packages

Additional R packages such as JMbayes can be installed in to your home area. This is covered in more detail in the CSF R documentation but here is a quick example of installing a package named JMbayes which uses JAGS:

module load tools/env/proxy
module load apps/gcc/R/3.6.2                # Uses GCC 8.2.0
module load apps/gcc/jags/4.3.0-gcc-8.2.0   # Use the gcc-8.2.0 compatible version
R
install.packages("JMbayes")
library(JMbayes)

You will be asked to select a mirror site from which to download the JMbayes packages (we typically use the Bristol UK mirror). Once the package has been installed, the library(JMbayes) command should be used each time you wish to use the package.

Further info

Last modified on November 20, 2020 at 10:19 am by George Leaver