okay i just rewrite my code. Now the problem is when i compile it, I get an error of "multiple definition of node a". Do anyone know what wrong in my code. I create the variable a,b and c for the model not to have many constants.
model{
for(i in 1:n){
a <- (k[1] + step(s1[i]-.9)*k[2] + step(s1[i]*.5-.9)*k[3])
b <- (r[1] + step(s2[i]-.9)*r[2] + step(s2[i]*.5-.9)*r[3])
c <- (s[1] + step(s3[i]-.9)*s[2] + step(s3[i]*.5-.9)*s[3])
dummy[i] <- 0
dummy[i] ~ dloglik(logLike[i])
# This is the log transformation of the 3-variate poisson
logLike[i] <- -theta12[i] + a*log(theta12[i]) - logfact(a) -theta13[i] - b*log(theta13[i]) - logfact(b)-theta23[i] - c*log(theta23[i]) - logfact(c)-theta1[i] + (y1[i]-a-b)*log(theta1[i]) + logfact(y1[i]-a-b)-theta2[i] + (y2[i]-a-c)*log(theta2[i]) + logfact(y2[i]-a-c)-theta3[i] + (y3[i]-b-c)*log(theta3[i]) + logfact(y3[i]-b-c)
log(theta1[i]) <- alpha1 + beta1*log(L[i])
log(theta2[i]) <- alpha2 + beta2*log(L[i])
log(theta3[i]) <- alpha3 + beta3*log(L[i])
log(theta12[i]) <- alpha4 + beta4*log(L[i])
log(theta23[i]) <- alpha5 + beta5*log(L[i])
log(theta13[i]) <- alpha6 + beta6*log(L[i])
}
alpha1 ~ dgamma(.001, .001)
alpha2 ~ dgamma(.001, .001)
alpha3 ~ dgamma(.001, .001)
alpha4 ~ dgamma(.001, .001)
alpha5 ~ dgamma(.001, .001)
alpha6 ~ dgamma(.001, .001)
beta1 ~ dgamma(.001, .001)
beta2 ~ dgamma(.001, .001)
beta3 ~ dgamma(.001, .001)
beta4 ~ dgamma(.001, .001)
beta5 ~ dgamma(.001, .001)
beta6 ~ dgamma(.001, .001)
}
data
list(y1 =c(0,1,2,3,2),
y2 = c(1,2,3,0,2),
y3 = c(1,3,2,3,2),
k = c(0,1,2,3,4),
s = c(0,1,2,3,4),
r = c(0,1,2,3,4),
L = c(1,2,3,4,5),
s1= c(0,1,2,0,2),
s2= c(0,0,0,0,0),
s3= c(1,1,0,0,0),n=5)
inits
list(beta1=0,beta2=0,beta3=0,beta4=0,beta5=0,beta6=0,alpha1=0,alpha2=0,alpha3=0,
alpha4=0,alpha5=0,alpha6=0)
You get this error because you've defined a, b, c within a for() loop. In other words you've defined a constant node multiple times (n times). You should replace a, b, c with a[i], b[i], c[i]. Think of BUGS as a model description language, not a programming language. Every quantity in your model has to have one single definition as a fixed or random function of other quantities.
来源:https://stackoverflow.com/questions/14509546/multiple-definition-of-node-a-error-in-winbugs