[R] Negative Binomial modelling
Thomas Lumley
tlumley at u.washington.edu
Sat Jan 18 20:05:03 CET 2003
On Fri, 17 Jan 2003, Damon Wischik wrote:
>
> I have some data which I am trying to fit with a negative binomial
> distribution. I have found the glm.nb function from MASS.
>
> I have reason to believe that the mean parameter mu depends on
> certain factors, and that the shape parameter theta depends on
> others.
>
> If, say, the factors are P and Q, it might be that
> mu ~ P:Q and theta ~ P
> (where mu ~ P:Q means that mu is a function of the pair (P,Q))
> in which case I could call glm.nb several times, one for each
> level of P (though this would be somewhat cumbersome).
>
> From looking at the data, I have reason to believe that
> mu ~ P and theta ~ Q.
> How can I go about fitting this?
>
> I expect I will have to write my own likelihood-maximization
> routine, and I am happy to do this (though if there are packages
> that do it for me, so much the better). In fact, my real model
> is a mixture model, and for this I am sure I will have to write
> my own likelihood-maximization routine.
No, you probably won't. The built-in optimisers in nlm and optim work
pretty well -- they're sometimes a bit slow but not as slow as writing
your own.
> What I want to learn from this list is if there are helpful
> commands that would do all the tedious work of working out how
> many variables there are etc. I'm hoping for some sort of call like
> gm( count ~ mydist(mu=p:q, theta=q) )
> where all I need to write the likelihood-maximization routine
> and the function gm does the rest, providing the answer in
> a suitable format for doing chi-squared tests etc.
Jim Lindsey's gnlr in his gnlm package will probably work. If not, I will
soon be releasing a survey package that among other things fits MLEs by
weighted likelihood.
-thomas
Thomas Lumley Asst. Professor, Biostatistics
tlumley at u.washington.edu University of Washington, Seattle
More information about the R-help
mailing list