Complete Corrected Formula for Generating Function
Complete Corrected Formula for Generating Function
distribution
Ken Yamamoto
Faculty of Science, University of the Ryukyus, Nishihara, Okinawa 903-0213, Japan
The hypergeometric distribution is a popular distribution, whose properties have been extensively
investigated. Generating functions of this distribution, such as the probability-generating function,
the moment-generating function, and the characteristic function, are known to involve the Gauss hy-
pergeometric function. We elucidate that the existing formula of generating functions is incomplete
and provide the corrected formula. In view of the utility and applicability of the hypergeometric
distribution, the exact and correct foundation is crucially important.
arXiv:2407.20677v1 [math.PR] 30 Jul 2024
1. INTRODUCTION
The hypergeometric distribution is a useful and popular discrete probability distribution in probability theory and
statistics. This distribution describes the number of successes in a sample drawn from a finite population without
replacement. The hypergeometric distribution has been applied to biology [4], complex networks [3], and blockchain
technology [5]. Furthermore, the hypergeometric distribution provides the theoretical basis for Fisher’s exact test [11]
and the Mantel–Haenszel test [13] used in medical statistics, and mark–recapture methods [12] in ecology. A simple
example of the hypergeometric distribution is picking colored balls from an urn [1, 6]. Let an urn contain K white
balls and N − K black balls. We let X denote the number of white balls in n balls picked randomly. The probability
that k balls are white is given by
K N −K N
Pr (X = k) = . (1)
k n−k n
This is the probability mass function of the hypergeometric distribution. The support of this distribution, i.e., the
set of k with Pr (X = k) > 0, consists of integers within max{0, n + K − N } ≤ k ≤ min{n, K}. If we consider the
factorial of negative integers as infinity, Eq. (1) is correct for all integers k.
The hypergeometric distribution is related to several distributions. When picking balls with replacement, the number
of white balls follows the binomial distribution [6], which is simpler than the hypergeometric distribution. When we
pick balls one by one without replacement until the number of black balls reaches a given value, the number of white
balls follows the negative hypergeometric distribution [8]. The multivariate hypergeometric distribution [2] appears
when the balls have more than two colors. In the Pólya urn model [7], at each step, one ball is drawn, its color is
observed, and the ball is returned in the urn with additional balls of the same color. In this model, the number of
white balls follows a distribution referred to as the beta-binomial distribution [6].
Many publications, e.g., [1, 2, 6, 10], contain the moment-generating function, the characteristic function, and the
probability-generating function of the hypergeometric distribution. The most fundamental function among them is
the probability-generating function
∞
X
GX (z) := E z X = Pr (X = k) z k .
k=0
Using GX , the√moment-generating function is expressed as MX (t) = GX (et ), the characteristic function as ϕX (t) =
GX (eit ) (i = −1), and the cumulant-generating function as KX (t) = ln GX (et ). The existing formula for the
probability-generating function of the hypergeometric distribution is
(N − n)!(N − K)!
GX (z) = 2 F1 (−n, −K; N − K − n + 1; z) . (2)
N !(N − K − n)!
Here, 2 F1 is the Gauss hypergeometric function defined by
∞
X (a)k (b)k z k
2 F1 (a, b; c; z) := ,
(c)k k!
k=0
2
The Gauss hypergeometric function 2 F1 (a, b; c; z) diverges when c is zero or negative integer because (c)k = 0 for
k ≥ |c| + 1. Therefore, Eq. (2) is not properly defined when n ≥ N − K + 1. The factorial (N − K − n)! also diverges
for such n, and Eq. (2) takes an indeterminate form “∞/∞.” The condition n ≥ N − K + 1 indicates that the number
n of balls drawn is greater than the number of black balls. In this study, we aim to establish the complete formula
for GX (z) by providing the determinate expression for n ≥ N − K + 1.
(N − n)!(N − K)!
N !(N − K − n)! 2 F1 (−n, −K; N − K − n + 1; z) n ≤ N − K, (3a)
GX (z) =
n!K!
z n+K−N 2 F1 (n − N, K − N ; n + K − N + 1; z) n ≥ N − K + 1. (3b)
N !(n + K − N )!
Equation (3b) is the correct determinate formula for n ≥ N − K + 1. Although this result might be trivial for
expert mathematicians, the explicit expression will be useful for students, engineers, practitioners, and programmers
who are not necessarily familiar with mathematics.
Remark 1.1. As the first two arguments of the hypergeometric function, −n and −K in Eq. (3a), and n − N
and K − N in Eq. (3b), are negative integers, the infinite sum of 2 F1 becomes finite. Therefore, 2 F1 in Eq. (3)
becomes a polynomial of z for any N , K, and n, whose degree is min{n, K} for Eq. (3a) and min{N − n, N − K}
for Eq. (3b). In both Eqs. (3a) and (3b), GX (z) has degree min{n, K}; the degree of Eq. (3b) is calculated as
n + K − N + min{N − n, N − K} = min{n, K}.
Remark 1.2. We set the range of Eq. (3b) as n ≥ N − K + 1 in order to supplement the range n ≤ N − K of
Eq. (3a). However, Eq. (3b) is defined even for n = N − K, and both Eqs. (3a) and (3b) for n = N − K have the
same form
n!K!
GX (z) = 2 F1 (−n, −K; 1; z) .
N!
The author believes that it is worth presenting the moment-generating function and characteristic function of the
hypergeometric random variable X explicitly, because they appear more frequently than the probability-generating
function in many publications.
Corollary 1.1 (Moment-generating function and characteristic function). The moment-generating function MX (t) =
GX (et ) and characteristic function ϕX (t) = GX (eit ) of X are
(N − n)!(N − K)!
t
2 F1 −n, −K; N − K − n + 1; e n ≤ N − K,
N !(N − K − n)!
MX (t) =
n!K!
z n+K−N 2 F1 n − N, K − N ; n + K − N + 1; et
n ≥ N − K + 1,
N !(n + K − N )!
and
(N − n)!(N − K)!
it
2 F1 −n, −K; N − K − n + 1; e n ≤ N − K,
N !(N − K − n)!
ϕX (t) =
n!K!
z n+K−N 2 F1 n − N, K − N ; n + K − N + 1; eit
n ≥ N − K + 1,
N !(n + K − N )!
respectively.
3
We do not prove Eq. (3a), which is a well-known existing result and present only the proof of Eq. (3b) for the
n ≥ N − K + 1 case. We provide two proofs.
First proof. When n ≥ N − K + 1, the lower bound of the support of X becomes max{0, n + K − N } = n + K − N .
The probability-generating function can be computed as follows.
∞
n!(N − n)! X K! (N − K)!
GX (z) = zk
N! k!(K − k)! (n − k)!(N − K − n + k)!
k=n+K−N
∞
n!K! X (n + K − N )! (N − n)! (N − K)! z j
= z n+K−N
N !(n + K − N )! j=0
(n + K − N + j)! (N − n − j)! (N − K − j)! j!
∞
X (n − N )j (K − N )j z j
n!K!
= z n+K−N
N !(n + K − N )! j=0
(n + K − N + 1)j j!
n!K!
= z n+K−N 2 F1 (n − N, K − N ; n + K − N + 1; z) ,
N !(n + K − N )!
(M + j)!
= (M + 1)(M + 2) · · · (M + j) = (M + 1)j ,
M!
M!
= M (M − 1) · · · (M − j + 1) = (−1)j (−M )(−M + 1) · · · (−M + j − 1) = (−1)j (−M )j
(M − j)!
Second proof. We introduce the random variable X ′ as the number of black balls left in the urn. The number of white
balls left becomes N − n − X ′ , and the relation K = X + (N − n − X ′ ) holds for the total number of white balls.
Therefore, we obtain
X = X ′ − N + K + n.
Picking n balls from the urn is equivalent to choosing N − n =: n′ balls to be left in the urn. That is, X ′
follows a hypergeometric distribution representing the number of black balls in randomly selected n′ balls, out of total
K ′ = N −K black balls. When n ≥ N −K +1, n′ satisfies n′ ≤ N −K ′ −1 < N −K ′. Hence, the probability-generating
function of X ′ is expressed in the form of Eq. (3a) with (n, K) replaced by (n′ , K ′ ):
(N − n′ )!(N − K ′ )! ′ ′ ′ ′
GX ′ (z) = 2 F1 (−n , −K ; N − K − n + 1; z)
N !(N − K ′ − n′ )!
n!K!
= 2 F1 (n − N, K − N ; n + K − N + 1; z) .
N !(n + K − N )!
In conclusion,
h ′ i
GX (z) = E z X = E z X +n+K−N = z n+K−N GX ′ (z)
n!K!
= z n+K−N 2 F1 (n − N, K − N ; n + K − N + 1; z) .
N !(n + K − N )!
Remark 2.1. The Gauss hypergeometric function 2 F1 (a, b; c; z) cannot be defined for c = 0, −1, −2, . . ., but the limit
holds for nonnegative integer m (see [9]), where Γ is the gamma function. In this sense, 2 F1 (a, b; c; z) /Γ(c) exists
for any c. Using this property, we can attain Eq. (3b) from Eq. (3a) as a formality by taking a suitable limit.
Equation (3a) can be rewritten as
n!
(−n)n+K−N = (−n)(−n + 1) · · · (K − N − 1) = (−1)n+K−N
(N − K)!
and
K!
(−K)n+K−N = (−K)(−K + 1) · · · (n − N − 1) = (−1)n+K−N ,
(N − n)!
3. ALTERNATIVE EXPRESSION
As stated in the second proof in the previous section, picking n balls is equivalent to selecting N − n balls to be
left in the urn. It is expected that a kind of symmetry for n and N − n exists in GX (z). However, Eq. (3) does not
directly display this symmetry. In fact, Eq. (3) switches its form at n = N − K, not n = N/2. We seek an alternative
expression of GX (z) in this section, focusing on this symmetry.
Corollary 3.1. The probability-generating function GX (z) in Eq. (3) is rewritten in the following form.
(a) When K ≤ N/2,
(N − n)!(N − K)! N
N !(N − K − n)! 2 F1 (−n, −K; N − K − n + 1; z) n≤ , (5a)
2
GX (z) =
n!(N − K)! K N
z 2 F1 n − N, −K; n − K + 1; z −1
n≥ . (5b)
N !(n − K)! 2
(N − n)!K! n N
−1
N !(K − n)! z 2 F1 −n, K − N ; K − n + 1; z n≤ , (6a)
2
GX (z) =
n!K! N
z n+K−N 2 F1 (n − N, K − N ; n + K − N + 1; z) n≥ . (6b)
N !(n + K − N )! 2
As a formality, Eq. (5b) is formed from Eq. (5a) by replacing n with N − n and z with z −1 , and multiplying z K .
The same replacement rule is applicable to Eq. (6). The factor z K represents that the symmetry is incomplete.
Proof. We use the formula [9]
(b)m
(−z)m 2 F1 −m, 1 − c − m; 1 − b − m; z −1 ,
2 F1 (−m, b; c; z) = (7)
(c)m
(a) K (b) K
Eq. (3b) or (6b) Eq. (6a)
4 4
3 3
2 2 Eq. (5b)
1 1
0 n 0 n
0 1 2 3 4 0 1 2 3 4
Eq. (3a) or (5a)
FIG. 1. Covering regions of Eqs. (3), (5), and (6) for N = 4 on the n–K plane.
To obtain Eq. (5b), we apply the formula (7) to Eq. (3a) with m = K, b = −n, and c = N − K − n + 1:
(N − n)!(N − K)!
2 F1 (−n, −K; N − K − n + 1; z)
N !(N − K − n)!
(N − n)!)N − K)! (−n)K
(−z)K 2 F1 n − N, −K; n − K + 1; z −1 .
= (8)
N !(N − K − n)! (N − K − n + 1)K
By substituting relations
n!
(−n)K = (−n)(−n + 1) · · · (−n + K − 1) = (−1)K ,
(n − K)!
(N − n)!
(N − K − n + 1)K = (N − K − n + 1)(N − K − n + 2) · · · (N − n) = ,
(N − K − n)!
we obtain
n!(N − K)! K
GX (z) = z 2 F1 n − N, −K; n − K + 1; z −1 .
N !(n − K)!
The range of n where hypergeometric functions in Eq. (8) are properly defined is K ≤ n ≤ N − K. Therefore, Eq. (5b)
for N/2 ≤ n ≤ N − K is proven.
Equation (5b) for n ≥ N − K can be derived from Eq. (3b). By using Eq. (7) with m = N − n, b = K − N , and
c = n + K − N + 1, Eq. (3b) becomes
n!K! (K − N )N −n
(−1)N −n z K 2 F1 n − N, −K; n − K + 1; z −1
N !(n + K − N )! (n + K − N + 1)N −n
n!(N − K)! K
= z 2 F1 n − N, −K; n − K + 1; z −1 ,
N !(n − K)!
where
(N − K)! K!
(K − N )N −n = (−1)N −n , (n + K − N + 1)N −n = .
(n − K)! (n + K − N )!
(b) Equation (6b) can be directly obtained from Eq. (3b), as Eq. (5a) was derived in (a) from Eq. (3a). As above,
Equation (6a) is derived from Eq. (3) by using the formula (7), where Eqs. (3a) and (3b) covers n ≤ N − K and
N − K ≤ n ≤ N/2, respectively.
Remark 3.1. In Corollary 3.1, “n ≤ N/2” and “n ≥ N/2” are used to highlight the symmetry of n and N − n.
These ranges can be extended as long as the third argument of the hypergeometric function is a positive integer. For
example, Eqs. (5a) and (5b) are valid for n ≤ N −K and n ≥ K, respectively; both equations include K ≤ n ≤ N −K,
and they become identical. Similarly, the ranges of n in Eqs. (6a) and (6b) can be extended to n ≤ K and n ≥ N − K,
respectively. Hence, Eqs. (5a) and (6b) are essentially identical to Eqs. (3a) and (3b), respectively. Figure 1 shows
regions where the equations in Theorem 1.1 and Corollary 3.1 are defined. In Fig. 1(a), the overlap of two regions
consists of the points on the descending diagonal n = N − K. This overlap is mentioned in Remark 1.2. In Fig. 1(b),
6
the overlap of Eqs. (5b) and (6a) occurs along the ascending diagonal n = K. Furthermore, when N is even, the
n = K = N/2 case is included in all four regions, and GX (z) is the same regardless of which equation is used.
Specifically, when N = 2m and N = K = m, the probability-generating function GX (z) can be written using the
Legendre polynomial Pm :
(b)m
(1 − z)m 2 F1 −m, c − b; 1 − b − m; (1 − z)−1
2 F1 (−m, b; c; z) =
(c)m
is used in the third equality, and the hypergeometric representation [9] of the Legendre polynomial
1−x
Pm (x) = 2 F1 −m, m + 1; 1;
2
4. MOMENTS
A typical application of the probability- and moment-generating functions is the calculation of moments. In many
books, e.g., [1, 2, 6, 8, 10], the mean and variance of the hypergeometric distribution become
nK n(N − n)K(N − K)
E [X] = , V [X] = ,
N N 2 (N − 1)
respectively. More generally, factorial moments, E [X(X − 1) · · · (X − r + 1)] for r = 1, 2, . . ., can be exactly calculated
for the hypergeometric distribution:
n!K!(N − r)!
E [X(X − 1) · · · (X − r + 1)] = . (9)
N !(K − r)!(N − r)!
Although direct computation of Eq. (9) based on the probability mass function (1) is possible, the factorial moments
can be systematically calculated using the probability-generating function GX as
dr GX (z)
E [X(X − 1) · · · (X − r + 1)] = .
dz r z=1
Using the probability-generating function in Eq. (3a), the factorial moment in Eq. (9) can be easily obtained using
formulas (see [9]):
dr (a)r (b)r
r 2 F1 (a, b; c; z) = 2 F1 (a + r, b + r; c + r; z)
dz (c)r
and
Γ(c)Γ(c − a − b)
2 F1 (a, b; c; 1) = .
Γ(c − a)Γ(c − b)
What computation is performed for n ≥ N − K + 1 in which Eq. (3b) is applied? The effective formula [9] in this
case is
dr c−1
(z 2 F1 (a, b; c; z)) = (c − r)r z c−r−12 F1 (a, b; c − r; z) . (10)
dz r
For 2 F1 (n − N, K − N ; n + K − N + 1; z) (a = n − N , b = K − N , and c = n + K − N + 1) in Eq. (3b), c − r =
n + K − N + 1 − r becomes 0 or a negative integer when r ≥ n + K − N + 1. Therefore, 2 F1 (a, b; c − r; z) cannot be
defined for such r, and a special treatment is necessary.
7
Proposition 4.1 (Supplement formula to Eq. (10)). For positive integers m and r which satisfy m ≤ r,
Proof. Using the gamma function instead of the Pochhammer symbol, Eq. (10) can be written as
In the computation of the rth factorial moment of X for n ≥ N − K + 1, Eq. (10) can be directly applied for
r ≤ n + K − N , and Proposition 4.1 is needed for r ≥ n + K − N + 1. In both cases, the final formula of the factorial
moment becomes identical with the existing formula (9). Therefore, the moments are not affected when starting from
the new formula (3b) for n ≥ N − K + 1. The author presumes that Eq. (3b) has not focused thus far because the
moments become the same as the formulas obtained from the existing expression (3a). Moreover, individual values
of generating functions have probably been less frequently required, which has kept researchers away from careful
investigation of the generating functions of the hypergeometric distribution.
[1] Balakrishnan, N. and Nevzorov, V. B. (2004) A Primer on Statistical Distributions. New York: Wiley.
[2] Bishop, Y. M. M., Fineberg, S. E., and Holland, P. W. (1975) Discrete Multivariate Analysis: Theory and Practice.
Cambridge, MA: MIT Press.
[3] Casiraghi, G., Nanumyan, V., Scholtes, I., and Schweitzer, F. (2017) From relational data to graphs: inferring significant
links using Generalized hypergeometric ensembles, volume 10540 of Lecture Notes in Computer Science, (pp. 111–120).
Springer: Cham.
[4] Fury, W., Batliwalla, F., Gregersen, P. K., and Li, W. (2006) Overlapping probabilities of top ranking gene lists, hyperge-
ometric distribution, and stringency of gene selection criterion. In 2006 International Conference of the IEEE Engineering
in Medicine and Biology Society (pp. 5531–5534).
[5] Hafid, A., Hafid, A. S., and Samih, M. (2020) A novel methodology-based joint hypergeometric distribution to analyze the
security of sharded blockchains. In IEEE Access, volume 8 (pp. 179389–179899).
[6] Johnson, N. L., Kotz, S., and Kemp, A. W. (1992) Univariate Discrete Distributions. New York: Wiley, 2nd edition.
[7] Mahmoud, H. M. (2009) Pólya Urn Models. Boca Raton: CRC Press.
[8] Mukhopadhyay, P. (2012) An Introduction to the Theory of Probability. Singapore: World Scientific.
[9] Olver, F. W., Lozier, D. W., Boisvert, R. F., and Clark, C. W. (2010) NIST Handbook of Mathematical Functions.
Cambridge: Cambridge University Press.
[10] Patel, J. K., Kapadia, C. H., and Owen, D. B. (1976) Handbook of Statistical Distributions. New York: Dekker.
[11] Rivals, I., Personnaz, L., Taing, L., and Potier, M.-C. (2007) Enrichment or depletion of a GO category within a class of
genes: which test?. Bioinformatics 23 401–407.
[12] Seber, G. A. F. (2013) Capture–Recapture methods—I, (pp. 35–42). Wiley: New York.
[13] Wittes, J. and Wallenstein, S. (1987) The power of the Mantel–Haenszel test. Journal of the American Statistical Associ-
ation 82 1104–1109.