Custom Likelihood for Zero-inflated Lognormal Model

Hey! Okay, so I believe you are confusing “zero-inflation” with “hurdle”. My way to think about this is that for (zero-)inflation you need something to be there in the first place. In a hurdle model, you first have to jump the hurdle before you get to the other part.

In case of the Poisson for example, you already got probability mass at 0. So putting extra probability mass on 0 is inflation.

In case of the LogNormal the probability at 0 is 0. You’d first have to jump the hurdle (go beyond zero) before you get to the part where the LogNormal does have non-zero probability. This is also what I think is wrong in your code: lognormal_lpdf(0 | mu, sigma) will return -Inf. The correct approach is actually simpler (LogNormal hurdle):

    if (y == 0) { 
      return bernoulli_lpmf(1 | zi);
    } else { 
      return bernoulli_lpmf(0 | zi) + lognormal_lpdf(y | mu, sigma); 
    } 

(You could also have Poisson hurdle model, but that would mean truncating the Poisson (to y > 0), so that the Bernoulli part is solely responsible for the probability contribution at y = 0. This is a bit more tricky to code.)

I don’t think I did a particularly good job verbalizing my thoughts here… Hope this helps anyways. But feel free to ask If something not clear.

Cheers,
Max