How to define a temporary local variable in jags?

455 views Asked by At

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?

1

There are 1 answers

0
Chris Jackson On BEST ANSWER

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]])