12.3 Beta-Binomial Distribution

12.3.1 Probability Mass Function

If \(N \in \mathbb{N}\), \(\alpha \in \mathbb{R}^+\), and \(\beta \in \mathbb{R}^+\), then for \(n \in {0,\ldots,N}\), \[ \text{BetaBinomial}(n~|~N,\alpha,\beta) = \binom{N}{n} \frac{\mathrm{B}(n+\alpha, N -n + \beta)}{\mathrm{B}(\alpha,\beta)}, \] where the beta function \(\mathrm{B}(u,v)\) is defined for \(u \in \mathbb{R}^+\) and \(v \in \mathbb{R}^+\) by \[ \mathrm{B}(u,v) = \frac{\Gamma(u) \ \Gamma(v)}{\Gamma(u + v)}. \]

12.3.2 Sampling Statement

n ~ beta_binomial(N, alpha, beta)

Increment target log probability density with beta_binomial_lpmf( n | N, alpha, beta) dropping constant additive terms.

12.3.3 Stan Functions

real beta_binomial_lpmf(ints n | ints N, reals alpha, reals beta)
The log beta-binomial probability mass of n successes in N trials given prior success count (plus one) of alpha and prior failure count (plus one) of beta

real beta_binomial_cdf(ints n, ints N, reals alpha, reals beta)
The beta-binomial cumulative distribution function of n successes in N trials given prior success count (plus one) of alpha and prior failure count (plus one) of beta

real beta_binomial_lcdf(ints n | ints N, reals alpha, reals beta)
The log of the beta-binomial cumulative distribution function of n successes in N trials given prior success count (plus one) of alpha and prior failure count (plus one) of beta

real beta_binomial_lccdf(ints n | ints N, reals alpha, reals beta)
The log of the beta-binomial complementary cumulative distribution function of n successes in N trials given prior success count (plus one) of alpha and prior failure count (plus one) of beta

R beta_binomial_rng(ints N, reals alpha, reals beta)
Generate a beta-binomial variate with N trials, prior success count (plus one) of alpha, and prior failure count (plus one) of beta; may only be used in generated quantities block. For a description of argument and return types, see section 10.8.3.