Code for running BPA using JAGS

JAGS (the acronym for Just another Gibbs sampler), developed by Martyn Plummer, is another MCMC engine that can be used for a Bayesian analysis of population models. Importantly, JAGS uses almost the identical model definition language (the BUGS language) as does WinBUGS and 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. The R package R2jags (and, internally, rjags) is required. We have found that JAGS is often faster than WinBUGS for the examples in the book. In addition, JAGS runs on Macs, hence, it may be an interesting alternative for many researchers. Quite exciting is the ability for parallel computing with JAGS, which should GREATLY speed up MCMC computations; see function parallel.jags() in the latest version of the R2jags package.

Although most examples in the book and in the solutions should run in JAGS with only minor code adaptations, we here provide the complete book code translated into JAGS. Since JAGS uses a slight dialect of the BUGS language, only very few changes were needed. However, JAGS has sometimes a different behaviour than WinBUGS. In particular, JAGS seems much more sensitive to the choice of starting values; if inappropriate initial values are chosen, updating does not even start. In particular, initial values for the latent state variables (which we often call z in our book) need initial values that are consistent with the observed data. For example, if an individual is known to be alive at a certain occasion t, because it was seen before and after t, but it was not observed at t, an initial value of zt = 0 would cause 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 need not necessarily match. In the following document, we provide some R code to generate appropriate initial values for all the examples treated in the book.

BPA with JAGS.txt