문제

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?

도움이 되었습니까?

해결책

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]])
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top