Hi,
I’d like to model the following generative process: (in pseudo-code)
c ~ Categorical([p0, p1, p2])
x' ~ Poisson(mu)
if c == 0:
x = -x'
elif c ==1:
x = 0
else:
x = x'
So, one might regard this as an extended ZeroInflatedPoisson, where we added the additional case that the outcome variable is negative (but its absolute value is still drawn from a Poisson distribution).
I am wondering if it is possible to write down such a model in pymc3. My first idea was to use a deterministic variable for this, i.e. do something like this:
alpha = np.ones(3)
p = pm.Dirichlet('p', alpha)
c = pm.Categorical('c', p)
mu = pm.HalfNormal(0, 10)
x_prime = pm.Poisson(mu)
x_cand = [-1. * x_prime, 0., x_prime]
pm.Deterministic('obs', x_cand[c], observed=data)
However, pm.Deterministic does not accept any observed data. I also found this thread (Observed Deterministic) which gives an explanation for that.
However, isn’t this just a straightforward extension of the ZeroInflated model? So, is it correct to conclude that to achieve the above behavior, I’d need to create my own pymc3 distribution which implements the likelihood explicitly, just like ZeroInflatedPoisson is doing it?
From simply observing the values of x_cand, you know what the proportion of zero values, negative values, and positive values are. Thus, there’s no need to estimate p in this case - it’s directly given to you*. Then, you could just negate any of the negative x_cand values to make them positive and then do x = pm.Poisson('x', mu=mu, observed=x_cand_positive) .
*Caveat: If you want to generate predictions, then it would be good to have a posterior distribution over p for which you’d need to fit a Dirichlet. However, this could be handled in a separate model
Hi, thank you for your reply.
I think you’re making a good point that I can essentially split up the model into two parts:
estimating the posterior of the parameters for the Poisson part
estimating the posterior of the Categorical distribution
To generate posterior predictions, I then would have to write a simple additional function that puts the pieces together.
The only caveat is that in general this only works if the distributions don’t share support. For the zero-inflated part this is only approximately true, since a zero in the observed data could also arise from the Poisson distribution. For sufficiently large rates, this is a good approximation.