[R] How to Fit Inflated Negative Binomial

Ben Bolker bbolker at gmail.com
Thu Nov 17 20:45:47 CET 2011


Tyler Rinker <tyler_rinker <at> hotmail.com> writes:

> 
> 
> try: library(pscl)
> 
> There's a zeroinfl for zero inflated neg. binom.
> 
> Tyler

> > 
> > Dear All,
> > I am trying to fit some data both as a negative binomial and a zero 
> > inflated binomial.
> > For the first case, I have no particular problems, see the small snippet 
> > below
> > 

 
set.seed(123) #to have reproducible results

## You don't actually need MASS::rnegbin, rnbinom in base
##  R works fine (different parameter names)

x6 <- c(rep(0,100),rnbinom(500,mu=5,size=4))

## sample() is irrelevant, it just permutes the results

library(pscl)
zz <- zeroinfl(x6~1|1,dist="negbin")
exp(coef(zz)[1])  ## mu
zz$theta          ## theta
plogis(coef(zz)[2]) ## zprob

Alternatively you can use fitdistr with the dzinbinom()
function from the emdbook package:

library(emdbook)
fitdistr(x6,dzinbinom,start=list(mu=4,size=5,zprob=0.2))

The pscl solution is likely to be much more robust.



More information about the R-help mailing list