Skip to content
Prev 277753 / 398506 Next

How to Fit Inflated Negative Binomial

Tyler Rinker <tyler_rinker <at> hotmail.com> writes:
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.