Negative binomial regression standard errors in knitr
Published:
Now if that blog post title doesn’t get your blood moving, I don’t know what will.
I just spent far too long finding a dependency bug that I thought I’d document.
I used the glm.nb function from the MASS library (in R) to build a negative binomial model of contributions to wikis. I saved the model to an .Rdata file, which I then imported into my Rtex knitr document. When I built the document, the table of the regression results showed the correct coefficients, but the standard errors and z-scores were different from what R was reporting.
I finally figured out that I had to import the MASS library in my knitr document. Apparently, it is used for calculating the standard errors, even after the model is fit.