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()