I am trying to write jags code for the following scenario
- Toss a coin with unknown probability of heads (p)
- If heads, then draw a random integer from 1 to 12
- If tails, then draw a random integer from 1 to 6
Based on data of the integers drawn, compute posterior distribution of p, assuming uniform prior on (0,1).
Here is my code
model = "model
{
p ~ dunif(0, 1) # prior for coin
for (i in 1 : n) {
coin[i] ~ dbern(p)
temp[i] = (coin[i]) * (-1/12) + (1/6) # if coin=0(tails),then temp=1/6, if coin = 1(heads), then temp = 1/12
pi = rep(temp[i], 1/temp[i]) # vector of probabilities, i.e. rep(1/12, 12) or rep(1/6, 6)
number[i] ~ dcat(pi)
}
}"
When I run this model JAGS throws the following error: RUNTIME ERROR: Expected parameters with fixed values in function rep
If passing a stochastic node to rep is not allowed, then how can I simulate the above scenario?