6

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

james_980
  • 75
  • 1
  • 4

2 Answers2

5

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]))
}
mfidino
  • 3,030
  • 1
  • 9
  • 13
  • Thanks! This works. Now realise the problem I had was actually that e[i] was circularly defined, but all sorted now. – james_980 Oct 16 '17 at 13:00
  • Great. I added another way to do with for defining only one indicator variable in the answer as well. – mfidino Oct 16 '17 at 13:40
0

You could try this

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

A lower bound of 0 on the Poisson distribution is equivalent to not having a lower bound.

Martyn Plummer
  • 331
  • 1
  • 1