I try to estimate delta[j,k] on the condition sum(delta[j,1:5])=0 for each "j". but when I compile the code, software output is "multiple definitions of node W[1]". Could someone help me?
model {
for (j in 1:p){
for (k in 1:5){
Z[j, k]<- sum(delta[j,1:k])
}
for (i in 1:n){
Y[i , j] ~ dcat ( prob [i , j , 1: 5])
}}
for (i in 1:n){
theta [i] ~ dnorm (0.0 , 1.0)
}
for (i in 1:n){
for (j in 1:p){
for (k in 1:5){
eta[i , j , k] <- alpha [j] * (k*theta [i] - k*beta [j]+Z[j, k])
psum [i , j , k] <- sum(eta[i , j , 1: k])
exp.psum[i , j , k]<- exp( psum [i , j , k])
prob [i , j , k] <- exp.psum[i , j , k] / sum(exp.psum [i , j , 1:5])
} } }
for (j in 1:p){
W[j] <- sum(delta [j, 1:5])
W[j]<- 0
alpha [j] ~ dlnorm (0.83 , pr.alpha)
beta [j] ~ dnorm (-1.73 , pr.beta )
delta[j,1] <- 0.0
for (k in 2:5){
delta [j , k] ~ dnorm (0.02 , pr.delta )
} }
pr.alpha <- pow(1.2 , -2)
pr.beta <- pow(0.7, -2)
pr.delta <- pow(1.3, -2)
}
thanks
BUGS does not allow you to overwrite deterministic nodes,... you have have W[j] <-
twice in the last for
loop.
I guess there are many way to write the code to meet your condition. For example you could use a different distribution for delta
or set delta[1]
to be the remainder required to get all delta
to sum to 0 after simulating delta[2]
to delta[5]