- Introduced by
- Gelman, Carlin, Stern, Dunson, Vehtari & Rubin; Cameron & Trivedi
- Year
- 1990s–2000s
- Type
- Bayesian GLM for overdispersed counts
- Family
- Regression / GLM
What does it do?
Bayesian Negative Binomial Regression models count outcomes (non-negative integers) that are overdispersed, meaning the variance is larger than the mean.
It places a negative binomial likelihood on the counts, links the mean to predictors through a log link, and assigns priors to both the regression coefficients and the dispersion parameter. Inference usually yields full posterior distributions, obtained by MCMC or variational methods, rather than point estimates.
The intuition behind the method
A Poisson model forces the variance to equal the mean, which is often too restrictive for real counts. The negative binomial adds a dispersion parameter phi that allows the variance to exceed the mean; as phi becomes large, the model approaches the Poisson. In the Bayesian version, phi and the regression coefficients are all unknowns with priors, so the result is a joint posterior that combines the data with prior information. Uncertainty about the amount of overdispersion is therefore carried into the intervals for the coefficients and into predictions, rather than being fixed at one estimate. With small samples, the priors also pull unstable coefficient estimates toward plausible values.
History
Negative binomial regression is a standard generalised linear model for overdispersed counts and is treated in general count-data texts such as Cameron and Trivedi (2013). Bayesian treatment of such models, including priors, posterior simulation and posterior predictive checking, is covered in general Bayesian texts such as Gelman et al. (2013). Probabilistic programming tools such as Stan and brms make MCMC fitting of this model accessible to applied researchers.
When to use it
Choose this model when the outcome is a count, when the counts show overdispersion (for example, a dispersion test or a comparison of Poisson and negative binomial fits points to extra variability), and when you want uncertainty for every parameter, including the dispersion. It is most useful with small or moderate samples, where asymptotic likelihood intervals may be unreliable, or when prior information from earlier studies should be used. Do not use it when the counts are consistent with a Poisson distribution, since the extra parameter then adds little. Do not use it when zeros are far more frequent than the negative binomial predicts; a zero-inflated model is more suitable then. If the outcome is a bounded count out of a known total, a binomial model fits the design better. If MCMC is impractical and a frequentist negative binomial fit answers the question, that simpler route is adequate.
Limitations and considerations
- MCMC sampling cost grows with data size and with hierarchical extensions, so fitting can be slow compared with a maximum likelihood negative binomial fit.
- The dispersion parameter phi is often weakly identified when there are few observations or little variation in the mean; its posterior can then remain close to its prior.
- Estimates of the coefficients and of phi depend on the priors chosen, and this dependence must be reported and justified for readers used to frequentist output.
- Convergence must be checked with trace plots and effective sample sizes as well as summary statistics, which adds steps compared with standard maximum likelihood output.
- The model does not handle substantial excess zeros; a Bayesian zero-inflated negative binomial is needed in that case.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- The negative binomial likelihood has a dispersion parameter, so the variance can exceed the mean; a Poisson model with the same mean structure cannot represent this.
- Because phi is sampled jointly with the coefficients, the credible intervals for the coefficients include uncertainty about the amount of overdispersion, rather than conditioning on a single estimated value.
- Priors on the coefficients provide regularisation, which can stabilise estimates when samples are small or predictors are sparse.
- Posterior predictive draws of counts carry the same parameter uncertainty, which makes it direct to check whether simulated counts match the observed spread.
- A Poisson counterpart fitted to the same data can be compared with this model using LOO-CV or WAIC on the same scale.
Applications
- Epidemiological case counts across populations whose underlying incidence differs, where variability beyond the Poisson is expected.
- Citation, publication, or patent counts in bibliometric and innovation studies, where a small number of units have very high counts.
- Accident or crime frequencies across geographic units with unequal exposure and heterogeneous underlying risk.
- Hospital visit or healthcare utilisation counts per patient, where baseline risk differs greatly between patients.
- Species abundance counts in ecology, where clumping of individuals makes overdispersion common.
How it works
How it works
Each count outcome y_i is assumed to follow a negative binomial distribution with mean mu_i and dispersion (size) parameter phi. In the common NB2 form the variance is Var(y_i) = mu_i + mu_i^2 / phi. As phi becomes large the variance approaches mu_i and the distribution approaches the Poisson; as phi decreases, overdispersion increases. Software may parameterise the distribution differently, so check which quantity a given tool reports.
Formula
y_i \sim \mathrm{NegBin}(\mu_i,\,\phi)A log link sets log(mu_i) equal to the linear predictor x_i^T beta. This keeps the predicted mean positive, and exponentiating a coefficient gives a multiplicative effect on the expected count, reported as an incidence rate ratio. When counts are observed over differing exposures (time at risk, population size), include log(exposure_i) as an offset, a term with its coefficient fixed at 1; exp(beta) is then a rate ratio per unit of exposure.
Formula
\log(\mu_i) = \mathbf{x}_i^{\top}\boldsymbol{\beta}Priors are placed on the regression coefficients beta and on the dispersion phi. Weakly informative choices, such as Normal(0, 2.5) for beta (for suitably scaled predictors) and Half-Normal or Exponential forms for a positive dispersion quantity, regularise estimates without strongly imposing beliefs; these are common options in applied work, not fixed standards. Software differs in whether it reports phi or its reciprocal, so the prior must be applied to the parameter as that tool defines it.
Formula
\boldsymbol{\beta} \sim p(\boldsymbol{\beta}),\quad \phi \sim p(\phi)Bayes' theorem combines the negative binomial likelihood and the priors into the joint posterior over beta and phi. For the usual priors this posterior has no closed form, so it is approximated by MCMC (for example NUTS in Stan or brms) or by variational inference, which is faster but gives only an approximate posterior.
Formula
p(\boldsymbol{\beta},\phi\mid\mathbf{y}) \propto p(\mathbf{y}\mid\boldsymbol{\beta},\phi)\,p(\boldsymbol{\beta})\,p(\phi)The main outputs are posterior summaries (median, credible intervals) for beta and phi, and exponentiated coefficients exp(beta_j) for rate ratios. Convergence must be checked with R-hat, effective sample size and trace plots. Posterior predictive checks compare simulated counts with observed counts, including the zero count and the upper tail, to assess fit.
Formula
\exp(\beta_j)\ \text{summarised from draws}\ \boldsymbol{\beta}^{(s)},\ s=1,\dots,SCommon pitfalls
- Skipping posterior predictive checks: good convergence does not show that the predicted count distribution matches the observed counts, especially in the upper tail.
- Very diffuse priors on phi can allow implausibly extreme dispersion values and slow mixing. Half-Normal or Exponential priors are weakly informative alternatives.
- The negative binomial is parameterised differently across software (NB-1 versus NB-2 forms, and dispersion reported directly or as a reciprocal). Check the documentation of the tool you use before comparing estimates or setting priors.
- Overdispersion produced by excess zeros can be mistaken for ordinary overdispersion; compare the observed zero count with the fitted model before choosing between the two structures.
- Treating a single rule-of-thumb threshold for R-hat or effective sample size as proof of convergence: check these together with trace plots, since thresholds do not guarantee convergence.
- Ignoring unequal exposure: modelling counts from units with different exposure without an offset makes coefficients hard to interpret as rates.
Frequently asked questions
How do I tell whether my count data need a negative binomial rather than Poisson model?
Fit both models and compare them with LOO-CV in the Bayesian framework. A ratio of residual deviance to degrees of freedom well above 1 in the Poisson fit suggests overdispersion. A posterior predictive check in which the Poisson model consistently under-predicts the upper tail is a clear visual signal.
What prior should I use for the dispersion parameter phi?
Place the prior on the dispersion parameter in the form the software uses. Half-Normal(0, 1) or Exponential(1) are common weakly informative choices for a positive parameter, though suitable scales depend on the data. If the software reports the reciprocal of phi, apply the prior to that quantity instead, and check the parameterisation before interpreting the result. Avoid Uniform(0, large) priors, which can place mass on extreme values and slow MCMC mixing.
Can I add random effects (hierarchical structure) to a Bayesian NB model?
Yes. Bayesian NB regression extends naturally to hierarchical models by placing further priors on group-level coefficients. This is straightforward in brms or Stan and is one of the main advantages of the Bayesian approach.
How do I interpret the regression coefficients?
Exponentiating a posterior coefficient exp(beta_j) gives the incidence rate ratio: the multiplicative change in the expected count for a one-unit increase in predictor j, holding other predictors constant. A credible interval for exp(beta_j) that excludes 1 indicates a credibly non-null effect.
What if many counts are zero?
If zeros are more frequent than a negative binomial distribution predicts, a Bayesian zero-inflated negative binomial (ZINB) model is more appropriate. Check with a posterior predictive plot comparing observed versus predicted zero counts.
How do I handle counts observed over different exposures?
Include log(exposure_i) as an offset in the linear predictor with its coefficient fixed at 1. The exponentiated coefficients are then rate ratios per unit of exposure.
Related methods
Sources
Gelman, A., Carlin, J. B., Stern, H. S., Dunson, D. B., Vehtari, A., & Rubin, D. B. (2013). Bayesian Data Analysis (3rd ed.). CRC Press.
ISBN: 978-1439840955Cameron, A. C., & Trivedi, P. K. (2013). Regression Analysis of Count Data (2nd ed.). Cambridge University Press.
ISBN: 978-1107667273