JAGS is the acronym for “Just another Gibbs sampler”. Developed by Martyn Plummer, it is a Markov chain Monte Carlo (MCMC) program that can be used for Bayesian analysis of population models. JAGS uses almost the identical model definition language (the BUGS language) as does the older program WinBUGS, for which we had originally written the BPA book over 10 years ago, and its descendant OpenBUGS. JAGS can be downloaded for free from http://mcmc-jags.sourceforge.net/ and may be run from R in a very similar way as WinBUGS. We have found that JAGS is often faster than WinBUGS for the examples in the book, and in addition, JAGS runs natively on Macs. Hence, JAGS will nowadays be the way in which most researchers will want to fit the models in the BPA book (and you may also want to check out the R package NIMBLE, which likewise has almost the same model-definition syntax and is an incredibly powerful program). Together with some of the R interface programs (see bottom of the page) JAGS supports easy parallel computing, which will GREATLY speed up your MCMC computations.
Virtually all examples in the book and in the solutions should run in JAGS with only minor adaptations from the code with which you run them with WinBUGS as shown in the printed book. Hence, we here provide the complete book code translated into JAGS. Although very similar to WinBUGS, JAGS sometimes exhibits slightly different behaviour. In particular, JAGS seems to be much more sensitive to the choice of starting values; if inappropriate initial values are chosen, updating may not even start. In particular, initial values for the latent state variables (which we often refer to as z in the book) must be defined so that they do not contradict the observed data and the model. For example, if an individual is known to be alive at a certain occasion t because it was seen before and after t, but was not observed at t, then an initial value of z[t] = 0 would throw an error in JAGS. Finding appropriate initial values can be particularly difficult in multistate capture-recapture models, where the coding of the observed states and the coding of the true states do not necessarily match. In the following code files, we provide some R code to generate appropriate initial values for all the examples in the BPA book.
JAGS can be run from R using several different interface packages. Most of them are wrappers for the R package ‘rjags’ (written by the JAGS developer Plummer), which some use directly when running JAGS from R. We provide code from the ‘R2jags’ package, which we had originally used for JAGS, and from the ‘jagsUI’ package, which is now our favourite. The structure of the output from the two packages is slightly different, and the output from ‘jagsUI’ is more similar to that produced when running WinBUGS with the R interface ‘R2WinBUGS’ (i.e., as shown in the printed book). The ‘jagsUI’ package has an easy way to parallelize the Markov chains: this is an argument in the main jags() function that just needs to be turned on.