nbreg
Explains a count that is more spread out than Poisson allows.
What we have
- NB2, with the overdispersion parameter reported separately
Coming later
- NB1
predictandmarginsafterwards
How you write it
nbreg depvar indepvars [if]
Square brackets mean optional. A vertical bar means choose one.
What it does
Negative binomial regression. Same purpose as poisson, with one extra parameter that lets the spread exceed the average (overdispersion), which is what counts almost always do in practice.
The output reports that extra parameter. If it is essentially zero, Poisson would have done; if it is clearly positive, Poisson's standard errors were too small and its p-values too impressive.
Try it
Every example below was run after sysuse vira.sample02, clear.
. nbreg hhsize age
Negative binomial regression Number of obs = 6,000
LR chi2 = 0.08
Prob > chi2 = 0.7823
Log likelihood = -13487.4660
------------------------------------------------------------------------------
hhsize | Coefficient Std. err. z P>|z| [95% conf. interval]
-------------+----------------------------------------------------------------
age | 9.749e-05 .00035295 0.28 0.782 -.0005943 .00078927
_cons | 1.508892 .01787728 84.40 0.000 1.473854 1.543931
------------------------------------------------------------------------------
alpha | .04290737 .00527869
------------------------------------------------------------------------------
The same thing in pandas and in R
pandas
import statsmodels.formula.api as smf
model = smf.negativebinomial("hhsize ~ age", data=df).fit()
R
library(MASS) model <- glm.nb(hhsize ~ age, data = df) summary(model) # This R has NOT been run against a real R yet: read it as documentation.