This is an old version, view current version.

12.1 Binomial Distribution

12.1.1 Probability Mass Function

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

12.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*}

12.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}

12.1.4 Sampling Statement

n ~ binomial(N, theta)

Increment target log probability density with binomial_lpmf( n | N, theta) dropping constant additive terms.

12.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

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

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

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

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