rmcelreath / rethinking

Statistical Rethinking course and book package
2.14k stars 603 forks source link

Zero Inflated Negative Binomial Model #404

Open FishModeler opened 1 year ago

FishModeler commented 1 year ago

Hello! I am looking for help/resources to guide me on how to change this zero-inflate Poisson model into zero-inflated negative binomial model. I don't see a function like dzipois that would easily take care of this issue. Could I somehow use dgampois in a zero-inflated negative binomial model? Any ideas? Thank you!!!

SitePoisson <- ulam( alist( SportfishCount ~ dzipois(pbar,lamba), logit(pbar) <- z1+z2Dim2 log(lamba)a + b Dim1+c Dim2+d HTOY, a ~ dnorm(1.85,2.76), b ~ dnorm(1,100), c ~ dnorm(1,100), d ~ dnorm(0,1), c(z1,z2)~dnorm(0,1) ), data = ModelData, start=list(a=0,b=0,c=0,d=0,z1=0.1,z2=0.2), iter=5000,warmup=2000,chains =3, cores = 4, log_lik = TRUE )

rmcelreath commented 1 year ago

There is no template for zigampois unfortunately. I can add it to the feature list. It is just a slight modification of dzipois.

In the meantime, you could get very close to zigampois by just adding random intercepts on each observation. That will add dispersion like a negative-binomial. It might be hard to get it to sample right, unless it is non-centered however.

Another approach is the modify the Stan code, if you are comfortable doing that. You can replace poisson with an appropriately parameterized negative-binomial. That's all that should be necessary.