Binomial distribution (source code)

= Binomial distribution
{title2=$\operatorname{Bin}(n,p)$}
{wiki}

The <binomial distribution> counts successes in a fixed number $n$ of <independent> <Bernoulli trials> with common success <probability> $p$. Equivalently,
$$
K=B_1+\cdots+B_n,\qquad B_i\sim\operatorname{Bernoulli}(p),\qquad
\mathbb P(K=k)=\binom nk p^k(1-p)^{n-k},\quad k=0,\ldots,n.
$$
Here $n$ is a nonnegative integer and $0\leq p\leq1$. The <binomial coefficient> $\binom nk=n!/[k!(n-k)!]$ counts placements of the $k$ successes; each particular arrangement has <probability> $p^k(1-p)^{n-k}$. The <binomial theorem> makes the masses sum to $[p+(1-p)]^n=1$. At $p=0$ all mass is at zero, and at $p=1$ all mass is at $n$; these endpoint laws can be read directly without interpreting $0^0$.

The <linearity of expectation> and addition of <variances> for <independent random variables> give
$$
\mathbb E K=np,\qquad \operatorname{Var}(K)=np(1-p).
$$
The fixed trial count, common success <probability>, and joint <independence> are substantive model assumptions. Sampling uniformly without replacement from a finite population instead leads to a <hypergeometric distribution>. <Independent> trials with different success <probabilities> generally give a <Poisson binomial distribution>. Common marginal success <probabilities> alone are insufficient: if all ten indicators equal the same <Bernoulli random variable> with $p=0.3$, their sum is zero with <probability> $0.7$ or ten with <probability> $0.3$. Its <mean> is still three, but its <variance> is $100(0.21)=21$. The standard construction is given in https://online.stat.psu.edu/stat504/Lesson01[Penn State STAT 504, binomial distribution].

For an exact constructed example, let each of ten <independent> trials choose uniformly from ten labelled tokens, with replacement, and mark three tokens as successes. Then $p=3/10$ and $K\sim\operatorname{Bin}(10,0.3)$. Exactly three successes have <probability>
$$
\mathbb P(K=3)=\binom{10}{3}(0.3)^3(0.7)^7
=120(0.027)(0.0823543)=0.266827932.
$$
The <mean> is $10(0.3)=3$, the <variance> is $10(0.3)(0.7)=2.1$, and the <standard deviation> is $\sqrt{2.1}\approx1.4491$. Zero successes have <probability> $0.7^{10}=0.0282475249$, so at least one success has <probability> $1-0.7^{10}=0.9717524751$. A single count calculation replaces enumeration of all $10^{10}$ equally likely token sequences.

\Image[/binomial-count-distribution.png]
{title=Exact binomial count probabilities for ten independent trials with success probability 0.3}

Each bar's height is one <probability> mass. Three is the most likely count, but its mass is only about $26.7\%$: a most likely outcome need not occur most of the time.