14.1 Binomial distribution

14.1.1 Probability mass function

Suppose \(N \in \mathbb{N}\) and \(\theta \in [0,1]\), and \(n \in \{0,\ldots,N\}\). \[ \text{Binomial}(n~|~N,\theta) = \binom{N}{n} \theta^n (1 - \theta)^{N - n}. \]

14.1.2 Log probability mass function

\[\begin{eqnarray*} \log \text{Binomial}(n~|~N,\theta) & = & \log \Gamma(N+1) - \log \Gamma(n + 1) - \log \Gamma(N- n + 1) \\[4pt] & & { } + n \log \theta + (N - n) \log (1 - \theta), \end{eqnarray*}\]

14.1.3 Gradient of log probability mass function

\[ \frac{\partial}{\partial \theta} \log \text{Binomial}(n~|~N,\theta) = \frac{n}{\theta} - \frac{N - n}{1 - \theta} \]

14.1.4 Sampling statement

n ~ binomial(N, theta)

Increment target log probability density with binomial_lupmf(n | N, theta).
Available since 2.0

14.1.5 Stan functions

real binomial_lpmf(ints n | ints N, reals theta)
The log binomial probability mass of n successes in N trials given chance of success theta
Available since 2.12

real binomial_lupmf(ints n | ints N, reals theta)
The log binomial probability mass of n successes in N trials given chance of success theta dropping constant additive terms
Available since 2.25

real binomial_cdf(ints n, ints N, reals theta)
The binomial cumulative distribution function of n successes in N trials given chance of success theta
Available since 2.0

real binomial_lcdf(ints n | ints N, reals theta)
The log of the binomial cumulative distribution function of n successes in N trials given chance of success theta
Available since 2.12

real binomial_lccdf(ints n | ints N, reals theta)
The log of the binomial complementary cumulative distribution function of n successes in N trials given chance of success theta
Available since 2.12

R binomial_rng(ints N, reals theta)
Generate a binomial variate with N trials and chance of success theta; may only be used in transformed data and generated quantities blocks. For a description of argument and return types, see section vectorized PRNG functions.
Available since 2.18