[R] MLE of negative binomial distribution parameters

Ben Bolker bbolker at gmail.com
Sat Oct 20 16:05:08 CEST 2012

Zoraida <zmorales <at> ingellicom.com> writes:

> I need to estimate the parameters for negative binomial distribution (pdf)
> using maximun likelihood, I also need to estimate the parameter for the
> Poisson by ML, which can be done by hand, but later I need to conduct a
> likelihood ratio test between these two distributions and I don't know how
> to start! I'm not an expert programmer in R.  Please help  

  It sounds like you might need some local help.  If you're trying
to fit the parameters to a single data set (i.e. no predictor variables,
just a set of values), then you probably want fitdistr() from the MASS
 modified from ?fitdistr:
 x4 <- rnegbin(500, mu = 5, theta = 4)
 ff <- fitdistr(x4, "Negative Binomial")
 ff2 <- fitdistr(x4, "Poisson")
     size         mu    
  4.2159071   4.9447685 
 (0.5043658) (0.1466082)


  'log Lik.' -1250.121 (df=2)

 'log Lik.' -1350.088 (df=1)

You can use the pchisq() function to compute the p-value
for the likelihood ratio test (hint: use lower.tail=FALSE
to compute the upper tail area ...)

  If you want to fit  and compare negative binomial or Poisson models
with covariates, use glm and MASS::glm.nb, or mle2 from
the bbmle packages ...

More information about the R-help mailing list