hard worker
hard worker

Reputation: 191

Error for the multi normal in JAGS,Compilation error on line 12. Attempt to redefine node q[1:3]

cat("
model {
l ~ dgamma(0.001, 0.001)
g ~ dgamma(0.001, 0.001)
o ~ dunif(0, 1)
p ~ dunif(0, 1)
for(i in 1:nSites) {
  N[i,1] ~ dpois(l)
  y[i,1] ~ dbin(p, N[i,1])
  for(t in 2:nYears) {
      pi<-c(1-p_b-p_c,p_b,p_c)
      q[1:3]~dmulti(pi[1:3],N[i,t-1])
      Mit[i,t-1]<-q[1]
      M[i,t] ~ dpois(l)
      new<-o*(Mit[i,t-1])
      D[i,t] ~ dpois(new)
      N[i,t]<-M[i,t]+D[i,t]
      y[i,t] ~ 
    }
  }
}
", fill=TRUE)

there is an error called Compilation error on line 12. Attempt to redefine node q[1:3] I want to use multinormal to participate N[i,t-1] into the matrix M[i,t],use the probability vector c(1-Pb-Pc,Pb,Pc),however, I met some errors

Upvotes: 0

Views: 128

Answers (1)

mfidino
mfidino

Reputation: 3055

It looks like the q vector is being overwritten for each t in 2:nYears. I would index q by t-1 and i because the it looks like it should vary by site and year (given the inputs).

cat("
model {
l ~ dgamma(0.001, 0.001)
g ~ dgamma(0.001, 0.001)
o ~ dunif(0, 1)
p ~ dunif(0, 1)
for(i in 1:nSites) {
  N[i,1] ~ dpois(l)
  y[i,1] ~ dbin(p, N[i,1])
  for(t in 2:nYears) {
      pi<-c(1-p_b-p_c,p_b,p_c)
      q[1:3,i,t-1]~dmulti(pi[1:3],N[i,t-1])
      Mit[i,t-1]<-q[1]
      M[i,t] ~ dpois(l)
      new<-o*(Mit[i,t-1])
      D[i,t] ~ dpois(new)
      N[i,t]<-M[i,t]+D[i,t]
      y[i,t] ~ dbin(p, N[i,t])
    }
  }
}
", fill=TRUE)

Without a reproducible example (e.g., a dataset to go along with the model) I'm not 100% sure you are trying to model, but assuming that q is a derived variable in the model this should work (i.e., you are not supplying data q into the model that is a vector of length 3).

Upvotes: 2

Related Questions