13.1 Binomial Distribution
13.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}. \]
13.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*}\]
13.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} \]
13.1.4 Sampling Statement
n ~
binomial
(N, theta)
Increment target log probability density with binomial_lpmf(n | N, theta)
dropping constant additive terms.
13.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 transformed data and generated quantities blocks.
For a description of argument and return types, see section
vectorized PRNG functions.