用于在JAGS中定义分布的if/else语句 [英] if/else statement for defining a distribution in JAGS
问题描述
在JAGS中,我想为参数w [i]定义泊松分布,如果另一个参数e [i]大于0,该参数也会被截断(大于或等于2).
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.
基本上我希望它代表:
w [i]〜ifelse(e [i]> 0,dpois(mu)T(2,),dpois(mu))
w[i] ~ ifelse( e[i] > 0, dpois(mu) T(2,) , dpois(mu) )
我尝试使用step函数来调整为响应其他人的帖子而提供的代码,该帖子要求类似的内容:
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
但这似乎不起作用吗?
谢谢
推荐答案
也许是这样?
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])
}
当e[i]
大于1时,w[i]
从pois1
中获取值.如果不是,则w[i]
从pois2
获取值.
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
.
或者,您可以仅定义一个指标变量,并像这样进行.
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]))
}
这篇关于用于在JAGS中定义分布的if/else语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!