This is an old version, view current version.

## 12.4 Hypergeometric Distribution

### 12.4.1 Probability Mass Function

If $$a \in \mathbb{N}$$, $$b \in \mathbb{N}$$, and $$N \in \{0,\ldots,a+b\}$$, then for $$n \in \{\max(0,N-b),\ldots,\min(a,N)\}$$, $\text{Hypergeometric}(n~|~N,a,b) = \frac{\normalsize{\binom{a}{n} \binom{b}{N - n}}} {\normalsize{\binom{a + b}{N}}}.$

### 12.4.2 Sampling Statement

n ~ hypergeometric(N, a, b)

Increment target log probability density with hypergeometric_lpmf( n | N, a, b) dropping constant additive terms.

### 12.4.3 Stan Functions

real hypergeometric_lpmf(int n ~|~ int N, int a, int b)
The log hypergeometric probability mass of n successes in N trials given total success count of a and total failure count of b

int hypergeometric_rng(int N, int a, int2 b)
Generate a hypergeometric variate with N trials, total success count of a, and total failure count of b; may only be used in transformed data and generated quantities blocks