How to define a temporary local variable in jags?

寵の児 提交于 2019-12-13 01:34:56

问题


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:


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


来源:https://stackoverflow.com/questions/20381267/how-to-define-a-temporary-local-variable-in-jags

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!