mina
mina

Reputation: 55

Multiple definitions of node winbugs

I have some problem with this code in winbugs. The model is sintatically correct and data are loaded, but when I compile, software output is "multiple definitions of node Z". I don't know how to solve the problem.

This is the model:

#BUGS Model
model {
for (i in 1:n){
  for (j in 1:p){
    Y[i , j] ~ dcat ( prob [i , j , 1: M[j]])
    B <- sum(alpha[j])  
  } 
  theta [i] ~ dnorm (0.0 , 1.0)
}
for (i in 1:n){
  for (j in 1:p){
    for (k in 1:M[j]){
      Z <- sum(delta [k ])
      eta [i , j , k] <- 1.7* alpha [j] * (B * (theta [i] - beta [j] ) + Z)
      exp.eta[i , j , k] <- exp( eta[i , j , k])
      psum[ i , j , k] <- sum(eta[i , j , 1:k])
      prob[i , j , k] <- exp.eta[i , j , k] / psum[i , j , 1:M[j]]
    }
  }
}
for (j in 1:p){
  alpha [j] ~ dnorm (0 , pr.alpha) I(0 , )
  for (k in 2:M[j]){
    delta [k] ~ dnorm (0.0 , 1.0)
  }
  for (k in 1:M[j]){
    beta [j] ~ dnorm (0 , pr.beta )
  }
}
delta [1] <- 0.0
pr.alpha <- pow(1 , -2)
pr.beta <- pow(1, -2)
}

#data
list(n=10, p=8)

M[] M[] M[] M[] M[] M[] M[] M[]
2 2 4 2 2 3 4 2 
2 1 1 2 1 2 2 3
1 2 1 3 1 1 4 4
2 1 1 2 1 1 2 4 
3 4 4 3 3 3 1 1 
4 3 4 4 4 4 4 4 
1 1 2 2 1 2 4 4 
2 1 1 3 1 4 2 4 
3 4 1 1 1 2 2 2 
2 2 2 1 4 4 4 4 
END

Thanks to everyone that will answer.

Upvotes: 4

Views: 1763

Answers (1)

guyabel
guyabel

Reputation: 8366

Your problems lie in defining some nodes multiple times in BUGS loops. For example B is defined np times in the first i and j loop. BUGS will not allow this. You cannot override a node value. You need to either

1) Add some indexes to B, Z, delta[k] and beta[j] to enable BUGS to store simulated values within elements of nodes during the loops. e.g replace B with B[i,j] and Z with Z[i,j,k]

or

2) Move B, Z, delta[k] and beta[j] to loops that only cover the indexes they already have. i.e. B, Z not in a loop as they have no index, delta[k] only in a for(k in 1:...) loop.

The decision depends on what you have in mind for your model and what you want parameters you want to store.

Upvotes: 3

Related Questions