RJAGS output Node inconsistent with parents

2019-09-18 01:11发布

Hi everyone I'm new in JAGS and currently doing a bayesian inference using mcmc through RJAGS. I've been trying my best to debug my code until I'm stuck with this error "Error in node e1[3] Node inconsistent with parents".

e1<-c(1,1,0,1,1,0,0,1,0,0,1,0,1,1,1,1,1,0,0,1,1,0,1,1,1,1,0,0,1,1,0,0,0,0,0,1,1,1,1,1,0,0,0,1,1,0,1,1,0,0,1,1,1,1,0,1)
e2<-c(1,1,0,1,1,1,0,1,0,1,1,1,0,1,1,1,1,0,1,1,1,1,0,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,0,1,1,0,0,1,1,1,0,1,1,0,1,1,1,1,1)
c1<-c(2412,3485,881,1515,1824,1603,865,2638,332013,7379,1,1189,1,106,278,1406,9408,21596,15880,833,543,611,272,7883,
      1,15091,11642,849,203,566,425,1,125124,687196,21377,3901,1131,543,1,21218,1118,5519,434800,1288,4700,820,659,6644,
      1198,3581,1013,1021,5877,833,1,11797)
c2<-c(1189,905,902,1154,20896,14973,1665,1,1096,309,641,1,935,282,
      1,566,2245,112,18366,1096,1476,1,2486,1131,607,67,19390,284,
      641,566,1154,1,2672,4857,1131,1231,4594,655,1127,4187,1223,417,
      3381,1,1006,1,1920,4964,1911,765 ,876,14,942,849,4130)
n<-c(56,55)

model<-function() {
  #control
  for(i in 1:n[1]){
    e1[i] ~ dbern(p1[i])
    c1[i] ~ dlnorm(eta[1],lambda[1])
    p1[i] <- ilogit(alpha[1]+beta[1]*c1[i])
  }
  #treatment
  for(i in 1:n[2]){
    e2[i] ~ dbern(p2[i])
    c2[i] ~ dlnorm(eta[2],lambda[2])
    p2[i] <- ilogit(alpha[2]+beta[2]*c2[i])
  }

  for (t in 1:2) {
    eta[t] ~ dgamma(9,2)
    lambda[t] ~ dunif(0,100)
    alpha[t] ~ dnorm(0,1)
    beta[t] ~ ddexp(0, gamma)  
  }
 gamma ~ dunif(1,10)
}

library(R2jags)
dataJags <- list("n","c1","c2","e1","e2") 
params <- c("eta","lambda","alpha","beta")
inits <- function(){
  list(eta=runif(2,0,1),lambda=runif(2,0,1),alpha=runif(2,0,1),beta=runif(2,0,1)
  )
}
n.iter <- 10000
n.burnin <- 5000
n.thin <- floor((n.iter-n.burnin)/500)
flxpin <- jags(dataJags, inits, params, model.file=model,
               n.chains=3, n.iter, n.burnin, n.thin,
               DIC=TRUE, progress.bar="text")

I hope anyone can give me how to debug this. Thanks a lot.

0条回答
登录 后发表回答