I'm constructing a model using the glm()
function in R. Let's say that I know that my data have an error distribution that fits a negative binomial distribution.
When I search the R manual for the various families, family=binomial
is offered as an option, but negative binomial
is not.
In the same section of the R manual (family), NegBinomial
is linked in the "See also" section, but it is presented in the context of binomial coefficients (and I'm not even sure what this is referring to).
So, to summarize, I'm hoping to find syntax that would be analogous to glm(y~x, family=negbinomial, data=d,na.omit)
.
With an unknown overdispersion parameter, the negative binomial is not part of the negative exponential family, so can't be fitted as a standard GLM (or by glm()
). There is a glm.nb()
function in the MASS
package that can help you ...
library(MASS)
glm.nb(y~x, ...)
If you happen to have a known/fixed overdispersion parameter (e.g. if you want to fit a geometric distribution model, which has theta=1
), you can use the negative.binomial
family from MASS
:
glm(y~x,family=negative.binomial(theta=1), ...)
It might not hurt if MASS::glm.nb
were in the "See Also" section of ?glm
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With