1

I am running JAGS models through the R package runjags. I just updated to JAGS 4.0.0 from JAGS 3.4, and have noticed some unexpected behavior that seems to be related to the update.

First, when I run a model, I now get a warning message WARNING: Unused variable(s) in data table: followed by a list of data objects that are referenced in the model and provided as data. It doesn't seem to affect the results (but it is very puzzling). I have, however, noticed a few times while playing around with this that for some variables the posteriors were virtually identical to the priors (indicating that no updating occured). I can't seem to recreate the update failure right now, but below is a reproducible code example illustrating the odd warning message. The code example on the run.jags help page also produces the same warning.

Second, I thought I'd check to see if the same message pops up if I use the R package R2jags instead of runjags, but R2jags won't load because apparently rjags (one of the dependencies) is not compatible with JAGS 4.0 (its looking for JAGS 3.X). Also, in the runjags function run.jags, the argument method="rjags" doesn't seem to work anymore, but method="parallel" does work.

I'm using runjags_2.0.1-4 and R 3.2.2.

So my questions are:

1) Is rjags really incompatible with JAGS 4.0? The motivation to go to 4.0 was to use vectors as indices (see https://martynplummer.wordpress.com/2015/08/16/whats-new-in-jags-4-0-0-part-34-r-style-features/).

2) What is up with the unused variable(s) warning, and should I be concerned about it?

Thanks, Glenn

Code:

#--- GENERATE DATA ------------------------
rm(list=ls())
# Number of sites and observations per site
N <- 200
nobs <- 3
# generate covariates and standardize (where appropriate)
set.seed(123)
forest <- rnorm(N) 
# relationship between occupancy and covariates
b0 <- 0.5  
b.for <- 0.5
psi <- plogis(b0 + b.for*forest)
# draw occupancy for each site
z <- rbinom(n=N, size=1,prob=psi)
# specify detection probablility
p <- 0.5
pz <- p*z
# generate the observations
Y <- rbinom(n=N, size=nobs,prob=pz)
#---- BUGS model ------------------------
model1 <- "model {
for (i in 1:N){ 
    logit(eta[i]) <- b0 + b.for*forest[i] 
    z[i] ~ dbern(eta[i])
    pz[i] <- z[i]*p
    y[i] ~ dbin(pz[i],nobs) 
} #i
b0.0 ~ dunif(0,1)
b0 <- log(b0.0/(1-b0.0)) 
b.for ~ dnorm(0,0.01)
p ~ dunif(0,1)
}"
occ.data1 <-list(y=Y,N=N,nobs=nobs,forest=forest)
inits1 <- function(){list(b0.0=runif(1),b.for=rnorm(1),p=runif(1),z=as.numeric(Y>0))}  
parameters1 <- c("b0","b.for","p")
#---- RUN MODEL ------------------------
library(runjags)
ni <- 2000
nt <- 1
nb <- 1000
nc <- 3
ad <- 100
out <- run.jags(model=model1,data=occ.data1,monitor=parameters1,n.chains=nc,inits=inits1,burnin=nb,
    sample=ni,adapt=ad,thin=nt,modules=c("glm","dic"),method="parallel")
  • rjags_4-3 is not on CRAN yet, but is available from http://sourceforge.net/projects/mcmc-jags/files/rjags/4/. The `?run.jags` example (which uses `method='rjags'`) works fine for me (no errors/warnings) with R (64-bit) 3.2.2 on Windows, with JAGS 4.0, runjags 2.0.2-8, and rjags 4-3. – jbaums Oct 11 '15 at 02:52
  • (FYI: your own code hasn't been added to the post) – jbaums Oct 11 '15 at 02:53
  • @jbaums Oops - I added the example code now. And thanks, rjags works for me now as well, but ONLY if I work from an administrative account. Otherwise, I get: `Loading required namespace: rjags Failed with error: ‘.onLoad failed in loadNamespace() for 'rjags', details: call: fun(libname, pkgname) error: C:\Program Files/x64/bin/libjags-4.dll not found’ Error: The rjags package is not installed (or failed to load) - please (re-)install this package to use the 'rjags' method for runjags` The referenced file does exist in C:\Program Files\JAGS\JAGS-4.0.0\x64\bin. – Glenn Stauffer Oct 12 '15 at 16:05

1 Answers1

1

To answer your questions:

1) rjags and JAGS used linked (non-interchangable) versions, and CRAN systems are still using JAGS_3.4.0 so the version of rjags on CRAN matches. This will be updated soon, and in the meantime you can grab the correct version of rjags from the sourceforge page as @jbaums notes.

2) This is a helpful message from JAGS/rjags telling you that you have specified something as data that the model isn't using. Remember that variable names are case sensitive i.e.

library('runjags')
model <- "model {
    m ~ dunif(-1000,1000)
    #data# M
    #inits# m
    #monitor# m
}"
M <- 0
m <- list(-10, 10)

results <- run.jags(model, method="interruptible", n.chains=2)
results <- run.jags(model, method="rjags", n.chains=2)

... gives you a warning because M does not match m. Also note that the warning looks a bit different from the two function calls - in the first it comes half-way down the JAGS output and in the second it comes as a warning in R after the function is completed.

As for 'should I be concerned' - yes if you think these variables should be in your model. If you can't find the problem try posting the code you are using - it got cut off from your original post.

Matt

Matt Denwood
  • 2,537
  • 1
  • 12
  • 16
  • Many thanks. `method="rjags"` works now (sometimes - see comment above). I've added some example code now. Interestingly, when I use `method="rjags"` or `method="rjparallel"` I do not get the unused variable(s) error, but I do get the error with `method="parallel"` or `method="interruptible"`. The exact same code does not produce errors with JAGS 3.4.0, regardless of method. So, I suspect some peculiarity of my setup (getting JAGS 4, rjags, runjags installed properly, given incomplete admin privileges), not a problem in my code? – Glenn Stauffer Oct 12 '15 at 16:05
  • Thanks for the code - I can replicate the warning message. It turns out that it is actually a bug in JAGS 4 (a false positive warning) so it can be safely ignored in your case! This doesn't show up in JAGS 3, or using the rjags interface (i.e. method%in%c('rjags','rjparallel')) which does these checks a bit differently. I will discuss this with Martyn and see if we can get it fixed for JAGS 4.0.2. – Matt Denwood Oct 14 '15 at 08:27
  • Update: I have fixed the issue in JAGS so these false positive warnings should go away in the next release (JAGS 4.0.2 - whenever that will be). If you prefer not to wait you can download and install the fixed release-4_patched source code from: https://sourceforge.net/p/mcmc-jags/code-0/ci/release-4_patched/tree/ – Matt Denwood Oct 14 '15 at 09:23
  • OK, thanks. I did suspect a bug, because I noticed that the specific variables that were listed as unused changed depending on the order of model statements/prior assignments in the code. – Glenn Stauffer Oct 14 '15 at 14:54
  • Yes, it would have depended on the relative order that they are defined in the data and in the JAGS model. If the two lined up by chance then there was no warning....! – Matt Denwood Oct 16 '15 at 21:04