Written and maintained by CASRAI Editorial Board
Published
On this page
The Poisson-gamma distribution describes a count whose Poisson rate is itself unknown and given a gamma distribution. Integrating the rate out gives a negative binomial distribution for the count, which has the same mean as the gamma prior implies but a larger variance than a Poisson. The same pairing is the standard conjugate model for Poisson counts: a Gamma(a, b) prior and y events observed over exposure x give a Gamma(a + y, b + x) posterior for the rate.
Definition: what is the Poisson-gamma distribution?
The Poisson-gamma distribution is a two-level (hierarchical) model. At the first level a count y follows a Poisson distribution with rate θ. At the second level the rate θ is not fixed but follows a gamma distribution with shape a and rate b. Averaging the Poisson probabilities over every possible θ gives the marginal distribution of y, which is negative binomial. The R documentation for the negative binomial states this directly: it arises as a mixture of Poisson distributions with the mean distributed as a gamma distribution.
The model has two readings that use the same algebra. As a mixture, it explains overdispersed counts (more spread than a Poisson allows) by letting each unit have its own rate. As a Bayesian model, the gamma is a prior for one unknown rate and the negative binomial is the posterior predictive distribution for a future count. Both are covered below with the same numbers.
Gamma distribution Poisson, Poisson and gamma distribution: is it the same thing?
“Poisson-gamma”, “gamma-Poisson”, “gamma distribution Poisson” and “Poisson and gamma distribution” all point to this one construction; the order of the words changes, the model does not. It is not a statement that a Poisson variable and a gamma variable are equal. The two distributions are related through the rate: the Poisson counts events and the gamma describes uncertainty or variation in how fast events occur. For each distribution on its own see the guides to the Poisson distribution and the gamma distribution formula.
Formula with every symbol explained
Let yi be observed counts, i = 1, …, n, and write the model as follows.
- Likelihood: yi ~ Poisson(θ), so a count with rate θ has mean θ and variance θ.
- Prior: θ ~ Gamma(a, b), where a is the shape, b is the rate (not the scale), the mean is a/b and the variance is a/b².
- Posterior: θ | y ~ Gamma(a + Σyi, b + n). Σyi is the total number of events observed and n the number of observation periods. Akande’s STA 360/602L lecture notes derive this, and Lancaster University’s MATH331 conjugate-prior table gives the same Gamma(p + Σxi, q + n) result.
- Posterior with exposure: if period i has exposure xi (for example population or person-time), yi ~ Poisson(θxi) and the posterior is Gamma(a + Σyi, b + Σxi).
- Posterior predictive (and prior marginal): for a new count y with exposure 1, y follows a negative binomial distribution with size an and success probability bn/(bn + 1), where an and bn are the posterior shape and rate. Its probability mass is Γ(an + y) / (Γ(an) · y!) · (bn/(bn + 1))an · (1/(bn + 1))y, the dnbinom form in R with size = an and prob = bn/(bn + 1).
- Mean and variance of the marginal: mean an/bn and variance an(bn + 1)/bn², which exceeds the mean. Setting n = 0 gives the same result for the prior.
The variance can also be written as the mean plus the variance of the rate: a/b + a/b². That is the law of total variance: Var(y) = E[θ] + Var(θ). This is why the Poisson-gamma model is a common first remedy for overdispersion; see the negative binomial distribution and negative binomial regression for overdispersion.
Worked example with real numbers
This example reuses the numbers in Akande’s STA 360/602L lecture on conjugacy and extends them with the marginal distribution, which the lecture states but does not tabulate. A rate θ of events per 100,000 people has prior Gamma(3, 5). One city with an exposure of x = 2 (200,000 people) records y = 3 events.
Step 1: the prior and its negative binomial marginal
Prior mean = a/b = 3/5 = 0.6 and prior variance of the rate = 3/25 = 0.12. For a new unit with exposure 1 the marginal is negative binomial with size 3 and prob = 5/(5 + 1) = 5/6. Its mean is 3 × (1/6)/(5/6) = 0.6 and its variance is 3 × 6/25 = 0.72, which equals 0.6 + 0.12 as the law of total variance requires. A Poisson with mean 0.6 would have variance 0.6, so the mixture is 20% more variable.
The probabilities of 0 to 4 events compare as follows (rounded to four places, computed from the mass function above):
| Events y | Poisson(0.6) | Negative binomial (size 3, prob 5/6) |
|---|---|---|
| 0 | 0.5488 | 0.5787 |
| 1 | 0.3293 | 0.2894 |
| 2 | 0.0988 | 0.0965 |
| 3 | 0.0198 | 0.0268 |
| 4 | 0.0030 | 0.0067 |
The mixture puts more weight on zero and on the upper tail, and less on the middle: the signature of overdispersion. For example, P(y = 0) = (5/6)³ = 125/216 = 0.5787, and P(y = 1) = [Γ(4)/(Γ(3) · 1!)] × (5/6)³ × (1/6) = 3 × 0.5787 × 0.1667 = 0.2894.
Step 2: the conjugate update
The posterior is Gamma(a + y, b + x) = Gamma(3 + 3, 5 + 2) = Gamma(6, 7). The posterior mean is 6/7 = 0.857 and the posterior variance is 6/49 = 0.122. The data pulled the mean up from 0.6 and narrowed uncertainty only a little, because one city is little information. With Gamma(6, 7), P(θ is above 1) = 0.30 and P(θ ≤ 2) = 0.99, matching the lecture’s figures.
Step 3: the posterior predictive for a new unit
For a new unit with exposure 1, the predictive distribution is negative binomial with size 6 and prob = 7/8. Its mean is 6/7 = 0.857 and its variance is 6 × 8/49 = 0.980. Then P(y = 0) = (7/8)6 = 0.4488, P(y = 1) = 0.3366, P(y = 2) = 0.1473, P(y = 3) = 0.0491 and P(y = 4) = 0.0138. As more data accumulate the predictive distribution approaches a Poisson with mean equal to the sample mean, because the posterior for θ tightens.
Parameter cross-walk
Negative binomial software does not use the gamma’s own parameters, which is the most common source of errors. The data table below on this page lines up the gamma parameters, the R dnbinom arguments and the worked-example values. Two forms of R’s parameterization exist: size and prob, or size and mu, with variance mu + mu²/size and prob = size/(size + mu). In the worked example size = 3 and mu = 0.6 give prob = 3/3.6 = 5/6, the same distribution.
Interpretation: reading the result
| What you see | How to read it |
|---|---|
| Marginal variance larger than the mean | Counts are overdispersed relative to a Poisson; the excess equals the variance of the rate (a/b²). |
| Posterior shape a + Σy and rate b + Σx | The prior acts like a prior events over b units of exposure; the data add Σy events over Σx exposure. |
| Posterior mean (a + Σy)/(b + Σx) | A compromise between the prior mean a/b and the observed rate Σy/Σx; more data weight it toward the observed rate. |
| Predictive distribution close to Poisson | Little uncertainty about the rate remains, usually after many observations. |
Assumptions and common mistakes
- Rate versus scale. The Gamma(a, b) here uses a rate b. If a source or library uses the scale 1/b, the update b + n becomes 1/(1/scale + n). Check the parameterization before copying a formula.
- Conditional independence. The counts must be independent Poisson draws given θ. Serial correlation, zero inflation or a rate that changes over time breaks the conjugate update.
- One rate versus many. The posterior update above assumes one shared θ. If every unit has its own rate drawn from the gamma, the counts are marginally negative binomial instead. Do not mix the two readings.
- Prior strength. Gamma(a, b) behaves like a events over b units of exposure; a very small a with a very small b is weakly informative but not automatically neutral. For choosing priors see prior distributions and Bayesian regression.
- Exposure. Add the exposure to b, not to the count. Forgetting it turns a rate model into a raw-count model.
How to report a Poisson-gamma analysis (APA example)
Report the model, the prior, the data summary and the posterior. A template in APA style, using the worked example: “Event counts were modelled as Poisson with a gamma prior on the rate (shape = 3, rate = 5, prior mean = 0.6 per 100,000). Observing 3 events over an exposure of 2 (200,000 people) gave a Gamma(6, 7) posterior with mean 0.86 per 100,000 (P[θ above 1] = .30; Gelman et al., 2013).” The reference list entry: Gelman, A., Carlin, J. B., Stern, H. S., Dunson, D. B., Vehtari, A., & Rubin, D. B. (2013). Bayesian data analysis (3rd ed.). Chapman and Hall/CRC.
How to calculate it in Excel, R or Python
All three examples give the prior marginal probabilities for the worked example (size 3, prob 5/6) and the posterior parameters.
Excel
In Excel, NEGBINOM.DIST(number_f, number_s, probability_s, cumulative) takes y as the failures, the size as the successes and the prob as probability_s:
=NEGBINOM.DIST(0, 3, 5/6, FALSE) returns 0.5787
=NEGBINOM.DIST(1, 3, 5/6, FALSE) returns 0.2894
Posterior shape: =3+3 Posterior rate: =5+2 Posterior mean: =6/7
R
dnbinom(0:4, size = 3, prob = 5/6) # 0.5787 0.2894 0.0965 0.0268 0.0067
a_n = 3 + 3; b_n = 5 + 2
a_n / b_n # 0.857
1 - pgamma(1, shape = a_n, rate = b_n) # P(theta above 1) = 0.30
dnbinom(0:4, size = a_n, prob = b_n/(b_n + 1)) # posterior predictive
Python
from scipy.stats import nbinom, gamma
nbinom.pmf(range(5), 3, 5/6) # 0.5787 0.2894 0.0965 0.0268 0.0067
a_n, b_n = 3 + 3, 5 + 2
a_n / b_n # 0.857
gamma.sf(1, a_n, scale=1/b_n) # P(theta above 1) = 0.30
nbinom.pmf(range(5), a_n, b_n/(b_n + 1)) # posterior predictive
Note that SciPy’s gamma takes a scale, so pass scale = 1/b. The probabilities above were computed from the mass function directly and the parameter mapping follows the R documentation.
Sources
- R Core Team. The Negative Binomial Distribution (stats::NegBinomial), R documentation. https://stat.ethz.ch/R-manual/R-devel/library/stats/html/NegBinomial.html (read 2026-11-15)
- Akande, O. STA 360/602L, Deriving conjugacy. https://sta-360-602l-su21.github.io/Course-Website/slides/2-8-derive-conjugacy.html (read 2026-11-15)
- Lancaster University, MATH331 Chapter 2, conjugate priors. https://www.lancaster.ac.uk/~prendivs/accessible/math331/lectures.tex/Ch2.S2.html (read 2026-11-15)
- Gelman, A., Carlin, J. B., Stern, H. S., Dunson, D. B., Vehtari, A., & Rubin, D. B. (2013). Bayesian data analysis (3rd ed.). Chapman and Hall/CRC (bibliographic details confirmed in library catalogues, 2026-11-15)
Data: Poisson-gamma parameter cross-walk with worked-example values
Compares how the Poisson-gamma model is written as a Gamma(a, b) rate prior and update versus the R dnbinom size/prob form, with the values from a worked example (prior Gamma(3, 5), one city of exposure 2 with 3 events). Compiled from the R NegBinomial manual, Akande STA 360/602L conjugacy notes and Lancaster MATH331 conjugate table, with values computed from their formulas.
| Quantity | Gamma-Poisson form | R dnbinom form | Worked-example value |
|---|---|---|---|
| Prior on the rate | theta ~ Gamma(a, b), mean a/b, variance a/b^2 | not applicable | Gamma(3, 5): mean 0.6, variance 0.12 |
| Prior marginal count (exposure 1) | Negative binomial, size a, prob b/(b+1) | dnbinom(y, size = a, prob = b/(b+1)) or size = a, mu = a/b | size 3, prob 5/6: mean 0.6, variance 0.72 |
| Posterior after y events over exposure x | Gamma(a + y, b + x) | not applicable | Gamma(6, 7): mean 0.857, variance 0.122 |
| Posterior predictive count (exposure 1) | Negative binomial, size a_n, prob b_n/(b_n+1) | dnbinom(y, size = a_n, prob = b_n/(b_n+1)) | size 6, prob 7/8: mean 0.857, variance 0.980 |
| Variance relation | Var(y) = a_n(b_n+1)/b_n^2, exceeds the mean | mu + mu^2/size | 0.980 versus mean 0.857 |
Sources
- R documentation: NegBinomial (accessed 2026-11-15)
- Akande, STA 360/602L: deriving conjugacy (accessed 2026-11-15)
- Lancaster MATH331 Chapter 2 conjugate priors (accessed 2026-11-15)
Compiled by CASRAI from the sources above. Free to reuse under CC BY 4.0 with attribution.







