Question

I want to create a temp variable in jags, but it doesn't work as it would work in R

for (cid in 1:CAMPAIGN_N) {
  for (time in 1:DATE_N){      
    index <- time * CAMPAIGN_N + cid - 2
    positives[index] ~ dbin( k[time]*ctr[cid], tries[index])
  }
}

Gives error, because index variable is being defined only once. So I had to write it the following ugly way:

for (cid in 1:CAMPAIGN_N) {
  for (time in 1:DATE_N){      
    positives[time * CAMPAIGN_N + cid - 2] 
      ~ dbin( k[time]*ctr[cid], tries[time * CAMPAIGN_N + cid - 2])
  }
}

Is there a way I can create temp variable in jags?

Was it helpful?

Solution

You'd need to let index vary with time and cid.

index[time,cid] <- time * CAMPAIGN_N + cid - 2
positives[index[time,cid]] ~ dbin( k[time]*ctr[cid], tries[index[time,cid]])
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top