Approximations
Helper functions for settings without a conjugate prior, such as the negative binomial dispersion parameter.
Approximation helpers for settings without a conjugate prior.
No conjugate prior exists for the negative binomial dispersion parameter
r. Bradlow, Hardie and Fader (2002) obtain closed-form posterior
inference for the negative binomial distribution by expanding ratios of
gamma functions into polynomials. This module implements the truncated
polynomial expansion of the gamma function ratio that makes their approach
work, as a helper rather than a conjugate model.
negbin_gamma_ratio_approximation(*, z, k, m=50)
Approximate the gamma function ratio gamma(z) / gamma(z + k).
No conjugate prior exists for the negative binomial dispersion
parameter r. Bradlow, Hardie and Fader (2002) obtain closed-form
posterior inference for the negative binomial distribution by
expanding ratios of gamma functions into polynomials. This helper
implements the truncated polynomial expansion of the second of those
ratios. It is an approximation helper, not a conjugate update.
What is exact:
- The expansion starts from the identity
gamma(z) / gamma(z + k) = 1 / (z * (z + 1) * ... * (z + k - 1))which holds exactly for positive integerk. - In the full approach, the other gamma function ratio that appears,
gamma(r + x) / gamma(r), is exactly the rising factorialr * (r + 1) * ... * (r + x - 1)and therefore exactly a degreexpolynomial inrfor integer countsx. No approximation is needed for that part.
What is approximate:
-
Writing
y = z + k, each denominator factor is rewritten as1 / (y - j) = (1 / y) / (1 - j / y)and the geometric series1 / (1 - j / y) = sum_i (j / y) ** iis truncated. Keeping terms through ordermof each series, multiplying the truncated polynomials together, and keeping terms through ordermof the product gives a polynomial in1 / ywith coefficientsU_0 = 1, U_1, ..., U_m. The returned approximation isy ** (-k)times that polynomial. -
The truncation error vanishes as
mgrows and decreases asygrows relative tok. The approximation is reliable whenz = y - kis not small compared tok; it can remain poor whenzis small andkis large, no matter how largemis. Validate the error for your own parameter values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
z
|
NUMERIC
|
positive argument of the numerator gamma function. In the
negative binomial application this is |
required |
k
|
int
|
positive integer number of denominator factors. In the
negative binomial application this is |
required |
m
|
int
|
highest order of the expansion kept. Coefficients |
50
|
Returns:
| Type | Description |
|---|---|
NUMERIC
|
Approximate value of |
NUMERIC
|
scalar |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
TypeError
|
if |
Example
import numpy as np
from conjugate.approximations import negbin_gamma_ratio_approximation
# counts x = [0, 1, 1, 2, 3, 5] with a beta prime prior on the
# rate with alpha_1 = alpha_2 = 2
n, x_total, alpha_1, alpha_2 = 6, 12, 2.0, 2.0
r = np.array([2.0, 5.0])
z = n * r + alpha_1
k = x_total + alpha_2
ratio = negbin_gamma_ratio_approximation(z=z, k=k, m=50)
References
Bradlow, E. T., Hardie, B. G. S., and Fader, P. S. (2002). "Bayesian Inference for the Negative Binomial Distribution via Polynomial Expansions." Journal of Computational and Graphical Statistics, 11(1), 189-201. doi:10.1198/106186002317375677
Source code in conjugate/approximations.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |