I want to code a model where the binomial parameter p comes from a
prior that is a mixture of a discrete (constant p=0.5) and continuous
(Beta prior) part. The probability of coming from the continuous part
is called "cheat" below; "able" is an indicator of which component of
the distribution a particular individual was selected from.
My first attempt looked like this:
model;
{
cheat ~ dunif(0,1)
alpha <- 200
for( i in 1 : 33 ) {
able[i] ~ dbern(cheat)
propa[i] ~ dbeta(alpha,alpha)
prop[1,i] <- 0.5
prop[2,i] <- propa[i]
p[i] <- prop[able[i] + 1 , i]
x[i] ~ dbin(p[i],n[i])
}
}
This causes Winbugs to give a Trap 20 violation, then if you try again
to compile it, you get "multiple definitions of node for p". This
sounds sort of like the error defined on the web page where someone
was indexing parameters from an array, so I tried writing it this way:
model;
{
cheat ~ dunif(0,1)
alpha <- 200
prop[1] <- 0.5
for( i in 1 : 33 ) {
able[i] ~ dbern(cheat)
prop[1+i] ~ dbeta(alpha,alpha)
k <- i*able[i]+1
p[i] <- prop[k]
x[i] ~ dbin(p[i],n[i])
}
}
This gives "multiple definitions of node for k". What's going on?
Duncan Murdoch
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|