# Statistics/Distributions/Hypergeometric

### Hypergeometric Distribution

Notation Probability mass function Cumulative distribution function ${\displaystyle h(k)={{{m \choose k}{{N-m} \choose {n-k}}} \over {N \choose n}}}$ {\displaystyle {\begin{aligned}N&\in \left\{0,1,2,\dots \right\}\\m&\in \left\{0,1,2,\dots ,N\right\}\\n&\in \left\{0,1,2,\dots ,N\right\}\end{aligned}}\,} ${\displaystyle \scriptstyle {k\,\in \,\left\{\max {(0,\,n+m-N)},\,\dots ,\,\min {(n,\,m)}\right\}}\,}$ ${\displaystyle {{{m \choose k}{{N-m} \choose {n-k}}} \over {N \choose n}}}$ ${\displaystyle 1-{{{n \choose {k+1}}{{N-n} \choose {m-k-1}}} \over {N \choose m}}\,_{3}F_{2}\!\!\left[{\begin{array}{c}1,\ k+1-m,\ k+1-n\\k+2,\ N+k+2-m-n\end{array}};1\right],}$  where ${\displaystyle \,_{p}F_{q}}$  is the generalized hypergeometric function ${\displaystyle {nm \over N}}$ mode = ${\displaystyle \left\lceil {\frac {(n+1)(m+1)}{N+2}}\right\rceil -1,\left\lfloor {\frac {(n+1)(m+1)}{N+2}}\right\rfloor }$ ${\displaystyle {nm \over N}\left(1-{n \over N}\right)\left(1-{m-1 \over N-1}\right)}$ ${\displaystyle {\frac {(N-2m)(N-1)^{\frac {1}{2}}(N-2n)}{[nm(N-m)(N-n)]^{\frac {1}{2}}(N-2)}}}$ ${\displaystyle \left.{\frac {1}{nm(N-m)(N-n)(N-2)(N-3)}}\cdot \right.}$  ${\displaystyle {\Big [}(N-1)N^{2}{\Big (}N(N+1)-6m(N-m)-6n(N-n){\Big )}+{}}$  ${\displaystyle {}+6nm(N-m)(N-n)(5N-6){\Big ]}}$ ??? ${\displaystyle {\frac {{N-m \choose n}\scriptstyle {\,_{2}F_{1}(-n,-m;N-m-n+1;e^{t})}}{N \choose n}}\,\!}$ ${\displaystyle {\frac {{N-m \choose n}\scriptstyle {\,_{2}F_{1}(-n,-m;N-m-n+1;e^{it})}}{N \choose n}}}$

The hypergeometric distribution describes the number of successes in a sequence of n draws without replacement from a population of N that contained m total successes.

Its probability mass function is:

${\displaystyle f(x)={{{m \choose x}{{N-m} \choose {n-x}}} \over {N \choose n}}{\text{ for all }}x\in [0,n]}$

Technically the support for the function is only where x∈[max(0, n+m-N), min(m, n)]. In situations where this range is not [0,n], f(x)=0 since for k>0, ${\displaystyle {0 \choose k}=0}$ .

#### Probability Density Function

We first check to see that f(x) is a valid pmf. This requires that it is non-negative everywhere and that its total sum is equal to 1. The first condition is obvious. For the second condition we will start with Vandermonde's identity

${\displaystyle \sum _{x=0}^{n}{a \choose x}{b \choose n-x}={a+b \choose n}}$
${\displaystyle \sum _{x=0}^{n}{{a \choose x}{b \choose n-x} \over {a+b \choose n}}=1}$

We now see that if a=m and b=N-m that the condition is satisfied.

#### Mean

We derive the mean as follows:

${\displaystyle \operatorname {E} [X]=\sum _{x=0}^{n}x\cdot f(x;n,m,N)=\sum _{x=0}^{n}x\cdot {{{m \choose x}{{N-m} \choose {n-x}}} \over {N \choose n}}}$
${\displaystyle \operatorname {E} [X]=0\cdot {{{m \choose 0}{{N-m} \choose {n-0}}} \over {N \choose n}}+\sum _{x=1}^{n}x\cdot {{{m \choose x}{{N-m} \choose {n-x}}} \over {N \choose n}}}$

We use the identity ${\displaystyle {\binom {a}{b}}={\frac {a}{b}}{\binom {a-1}{b-1}}}$  in the denominator.

${\displaystyle \operatorname {E} [X]=0+\sum _{x=1}^{n}x\cdot {{{m \choose x}{{N-m} \choose {n-x}}} \over {{N \over n}{{N-1} \choose {n-1}}}}}$
${\displaystyle \operatorname {E} [X]={n \over N}\sum _{x=1}^{n}x\cdot {{{m \choose x}{{N-m} \choose {n-x}}} \over {{N-1} \choose {n-1}}}}$

Next we use the identity ${\displaystyle b{\binom {a}{b}}=a{\binom {a-1}{b-1}}}$  in the first binomial of the numerator.

${\displaystyle \operatorname {E} [X]={n \over N}\sum _{x=1}^{n}{m{{m-1 \choose x-1}{{N-m} \choose {n-x}}} \over {{N-1} \choose {n-1}}}}$

Next, for the variables inside the sum we define corresponding prime variables that are one less. So N′=N−1, m′=m−1, x′=x−1, n′=n-1.

${\displaystyle \operatorname {E} [X]={mn \over N}\sum _{x'=0}^{n'}{{{m' \choose x'}{{N'-m'} \choose {n'-x'}}} \over {{N'} \choose {n'}}}}$
${\displaystyle \operatorname {E} [X]={mn \over N}\sum _{x'=0}^{n'}f(x';n',m',N')}$

Now we see that the sum is the total sum over a Hypergeometric pmf with modified parameters. This is equal to 1. Therefore

${\displaystyle \operatorname {E} [X]={nm \over N}}$

#### Variance

We first determine E(X2).

${\displaystyle \operatorname {E} [X^{2}]=\sum _{x=0}^{n}f(x;n,m,N)\cdot x^{2}=\sum _{x=0}^{n}{{{m \choose x}{{N-m} \choose {n-x}}} \over {N \choose n}}\cdot x^{2}}$
${\displaystyle \operatorname {E} [X^{2}]={{{m \choose 0}{{N-m} \choose {n-0}}} \over {N \choose n}}\cdot 0^{2}+\sum _{x=1}^{n}{{{m \choose x}{{N-m} \choose {n-x}}} \over {N \choose n}}\cdot x^{2}}$
${\displaystyle \operatorname {E} [X^{2}]=0+\sum _{x=1}^{n}{{m{m-1 \choose x-1}{{N-m} \choose {n-x}}} \over {{N \over n}{{N-1} \choose {n-1}}}}\cdot x}$
${\displaystyle \operatorname {E} [X^{2}]={mn \over N}\sum _{x=1}^{n}{{{m-1 \choose x-1}{{N-m} \choose {n-x}}} \over {{N-1} \choose {n-1}}}\cdot x}$

We use the same variable substitution as when deriving the mean.

${\displaystyle \operatorname {E} [X^{2}]={mn \over N}\sum _{x'=0}^{n'}{{{m' \choose x'}{{N'-m'} \choose {n'-x'}}} \over {{N'} \choose {n'}}}(x'+1)}$
${\displaystyle \operatorname {E} [X^{2}]={mn \over N}\left[\sum _{x'=0}^{n'}{{{m' \choose x'}{{N'-m'} \choose {n'-x'}}} \over {{N'} \choose {n'}}}x'+\sum _{x'=0}^{n'}{{{m' \choose x'}{{N'-m'} \choose {n'-x'}}} \over {{N'} \choose {n'}}}\right]}$

The first sum is the expected value of a hypergeometric random variable with parameteres (n',m',N'). The second sum is the total sum that random variable's pmf.

${\displaystyle \operatorname {E} [X^{2}]={mn \over N}\left[{n'm' \over N'}+1\right]}$
${\displaystyle \operatorname {E} [X^{2}]={mn \over N}\left[{(n-1)(m-1) \over (N-1)}+1\right]={mn \over N}\left[{{(n-1)(m-1)+(N-1)} \over (N-1)}\right]}$

We then solve for the variance

${\displaystyle \operatorname {Var} (X)=\operatorname {E} [X^{2}]-(\operatorname {E} [X])^{2}}$
${\displaystyle \operatorname {Var} (X)={mn \over N}\left[{{(n-1)(m-1)+(N-1)} \over (N-1)}\right]-\left({mn \over N}\right)^{2}}$
${\displaystyle \operatorname {Var} (X)={Nmn \over N^{2}}\left[{{(n-1)(m-1)+(N-1)} \over (N-1)}\right]-{(N-1)(mn)^{2} \over (N-1)N^{2}}}$
${\displaystyle \operatorname {Var} (X)={nm(N-n)(N-m) \over N^{2}(N-1)}}$

or, equivalently,

${\displaystyle \operatorname {Var} (X)={nm \over N}\left(1-{n \over N}\right)\left(1-{m-1 \over N-1}\right)}$