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).
On 17 Jan 2003 at 15:59, Damon Wischik wrote: It seems like gnlr() in Jim Lindsay's package gnlm might help you. Kjetil Halvorsen> > 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. > > 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. > > Damon Wischik. > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > http://www.stat.math.ethz.ch/mailman/listinfo/r-help
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