2

I'm running a model in R using the package 'jagsUI' and the model begins to run for a little bit, but then I get the message

"Error in mat[, "deviance"] : subscript out of bounds In addition: Warning message: In order.params(samples, parameters.to.save, DIC, verbose = verbose) : JAGS did not monitor deviance."

I've never come across this error before I thought it might be an issue with the DIC module of JAGS so I made sure to load the module when running the model. Any suggestions on what might be causing this?

Here is my code:

#write out model
writeLines("

       model {                                  #Open overall model bracket

       ############################################################
       #Priors
       ############################################################

       omega ~ dunif(0,1)

       alpha.lam~dnorm(0,0.1)

      Beta_FEDR[1] <- 0
      Beta_FEDR[2]~dnorm(0,0.1)
      Beta_FEDR[3]~dnorm(0,0.1)
      Beta_FEDR[4]~dnorm(0,0.1)
      Beta_FEDR[5]~dnorm(0,0.1)
      Beta_FEDR[6]~dnorm(0,0.1)
      Beta_FEDR[7]~dnorm(0,0.1)


       # i obs random effect
       for (i in 1:N) {
       eps[i]~dnorm(0,tau.disp)#I(-20,20)  #random observation effect
       }

       #hyperprior on random observation effects precision
       tau.disp ~ dgamma(0.1,0.001)


       ############################################################
       #Likelihood specification
       ############################################################

       for (i in 1:N){                                          # Open i likelihood bracket; corresponds to obs
       #n observations

       w[i] ~ dbern(omega)
       NREKN[i] ~ dpois(eff.lambda[i]) 
       eff.lambda[i] <- w[i]*lambda[i]

       log(lambda[i]) <- alpha.lam + Beta_FEDR[FEDR[i]] +eps[i]

       # Fit assessments

       residual[i] <- NREKN[i] - eff.lambda[i]
       predicted[i] <- eff.lambda[i]
       sq[i] <- pow(residual[i],2)


       # Generate replicate datasets
       NREKN.new[i] ~ dpois(eff.lambda[i])
       sq.new[i] <- pow(NREKN.new[i]-predicted[i],2)


       } # close i likelihood bracket

       ############################################################
       #Derived quantities
       ############################################################
       # Add up discrepancy measures
       fit <- sum(sq[])
       fit.new <- sum(sq.new[])
       test <- step(fit.new-fit)
       bpvalue <- mean(test)
       } #close model

       ", con = here("Shorebird_aquaculture_project","REKN_Models", 
      "ZIP_DistOnlyModel.txt"))

#Identify filepath of model file;
modfile <- here("Shorebird_aquaculture_project","REKN_Models", 
"ZIP_DistOnlyModel.txt")

sink(file=here("Shorebird_aquaculture_project","OutputFiles","REKN","outputDistOnlyModel.txt"))

 #create JAGS model object 'out' using the jags function of package jagsUI             

out <- jags(data = data,
 parameters.to.save = params,
 inits = initsFunction,
 model.file = modfile,
 modules=c('glm','dic'),
 n.chains = 2,
 n.adapt = 100,
 n.iter = 30000,
 n.burnin = 10000,
 n.thin = 2,
 parallel=TRUE,
 seed=as.integer(Sys.time()),
 n.cores=2)

sink()
Curtis
  • 449
  • 1
  • 4
  • 17

1 Answers1

2

I can't definitively say (so maybe this should be a comment, not an answer), but I just encountered this exact error message and was able to resolve it.

Turns out I had forgotten to include the response variable in my input data!

Only when I ran with parallel=F did I get the error message There are no observed stochastic nodes. My guess is this message is suppressed when running in parallel, and that the error we observed gets tripped before the "missing data" error.

I realize this comes 6 months late, but maybe it's useful to someone down the line.

Matt Tyers
  • 2,125
  • 1
  • 14
  • 23
  • Thanks @Matt Tyers, the problem was the dependent variable specification in the model. I have "NREKN" as the dependent variable, but in the data file it was coded as "REKN", such a lame mistake on my part – Curtis Aug 17 '18 at 23:39
  • @Matt Tyers Thanks!! I had the error message "Failed to set trace monitor for deviance There are no observed stochastic nodes" and the reason was that I also forgot to include my response variable in my input data! – Sam Fed Jun 16 '21 at 21:29