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
{"ft_lang_label":"__label__en","ft_lang_prob":0.6225054,"math_prob":0.9996567,"size":914,"snap":"2021-31-2021-39","text_gpt3_token_len":297,"char_repetition_ratio":0.14615385,"word_repetition_ratio":0.015748031,"special_character_ratio":0.30743983,"punctuation_ratio":0.16931216,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99992883,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-09-25T14:56:44Z\",\"WARC-Record-ID\":\"<urn:uuid:51ec9b23-b657-44b1-bc13-bc90afa40daa>\",\"Content-Length\":\"90085\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:1129871a-233f-4075-a124-01691637a50d>\",\"WARC-Concurrent-To\":\"<urn:uuid:11f53439-66b8-475c-ab3a-e391cf42a66e>\",\"WARC-IP-Address\":\"185.199.108.153\",\"WARC-Target-URI\":\"https://mc-stan.org/docs/2_22/functions-reference/hypergeometric-distribution.html\",\"WARC-Payload-Digest\":\"sha1:FO6UWASIRKJQQNL65RF5X6MOTXMHQHAP\",\"WARC-Block-Digest\":\"sha1:7UI2DVVBKNU6VJNTPPCYMF5IGRJBQ7U6\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-39/CC-MAIN-2021-39_segments_1631780057687.51_warc_CC-MAIN-20210925142524-20210925172524-00117.warc.gz\"}"}