if/else statement for defining a distribution in JAGS

流过昼夜 提交于 2020-12-10 08:51:06

问题


In JAGS I'd like to define a Poisson distribution for parameter w[i] which is also truncated (greater than or equal to 2) if another parameter, e[i], is greater than 0.

Essentially I want it to represent:

w[i] ~ ifelse( e[i] > 0, dpois(mu) T(2,) , dpois(mu) )

I've tried using the step function by adapting the code that was given in response to someone else's post which was requesting something similar: Choosing Different Distributions based on if - else condition in WinBugs/JAGS

But this doesn't seem to work?

Thank you


回答1:


Maybe something like this?

pois1 ~ dpois(mu) T(2,)
pois2 ~ dpois(mu)
for(i in 1:N){
indicator1[i] <- ifelse(e[i] > 0, 1, 0)
indicator2[i] <- ifelse(e[i] <= 0, 1, 0)
w[i] <- (pois1 * indicator1[i]) + (pois2 * indicator2[i])
}

When e[i] is greater than 1 w[i] takes the value from pois1. If it is not w[i] takes the value from pois2.

EDIT: Or, you could define only one indicator variable and do it like this.

pois1 ~ dpois(mu) T(2,)
pois2 ~ dpois(mu)
for(i in 1:N){
indicator[i] <- ifelse(e[i] > 0, 1, 0)
w[i] <- (pois1 * indicator[i]) + (pois2 * (1 - indicator[i]))
}


来源:https://stackoverflow.com/questions/46730232/if-else-statement-for-defining-a-distribution-in-jags

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