我正在使用包“jagsUI”在 R 中运行模型,模型开始运行一段时间,但随后我收到消息
“mat [,“deviance”] 中的错误:下标超出范围此外:警告消息:In order.params(samples,parameters.to.save,DIC,verbose = verbose):JAGS 没有监控偏差。“
在我认为这可能是 JAGS 的 DIC 模块的问题之前,我从未遇到过此错误,因此我确保在运行模型时加载该模块。关于可能导致这种情况的任何建议?
这是我的代码:
#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()