Node inconsistent with parents in simple JAGS model

19 Views Asked by At

I'm relatively new to JAGS scripting, and I am getting this weird error. The R code

library(R2jags)
numGears <- 2
maxIter <- 10
a <- c(0.2,0.3)
totalArea <- 1
C <- array(rbinom(1000,size = 1000,0.3),c(2,10,2))
jagsData <- list("C","maxIter","numGears","a","totalArea")
interestParameters <- c("N0","juvProp","f","sJ","b","sA","c")

jagsModel <-
  jags(
    data = jagsData,
    parameters.to.save = interestParameters,
    model.file = "JAGSModel.txt",
    n.iter = 50000,
    n.burnin = 5000,
    n.thin = 1,
    n.chains = 8
  )

with JAGS script

model{
  #Process  
  J[1] <- N0*juvProp
  A[1] <- N0*(1-b)*(1-juvProp)
  B[1] <- N0*b*(1-juvProp)
  for(i in 1:(maxIter-1)){
    J[i+1] <- f*B[i]/2
    A[i+1] <- (1-b)*sJ*J[i]+sA*A[i]
    B[i+1] <- b*sJ*J[i]
  }
  
  #Observation
    for(i in 1:numGears){
        for(j in 1:maxIter){
            C[i,j,1] ~ dbinom(c[i],nJ[i,j])
            nJ[i,j] ~ dpois(a[i]*J[j]/totalArea)
            C[i,j,2] ~ dbinom(1-c[i],nA[i,j])
            nA[i,j] ~ dpois(a[i]*(A[j]+B[j])/totalArea)
        }
    }
    
    
  #Priors
  N0 ~ dnorm(1000,1/10000) T(0,)
  juvProp ~ dunif(0,1)
  f ~ dlnorm(0,1/5)
  sJ ~ dunif(0,1)
  b ~ dunif(0,1)
  sA ~ dunif(0,1)
  for(i in 1:numGears){
    c[i] ~ dunif(0,1)
  }
}

yields this error:

Error in jags.model(model.file, data = data, inits = init.values, n.chains = n.chains,  : 
  Error in node C[1,1,1]
Node inconsistent with parents

I have checked changing the priors, initializing the parameters myself, and nothing seems to fix the issue. Every parameter seems to be consistent with the data, but the error persists.

0

There are 0 best solutions below