Sample mean of iid Bernoulli variables (source code)

= Sample mean of iid Bernoulli variables
{title2=$\overline X=K/n,\quad K\sim\operatorname{Bin}(n,p)$}

For $n\geq1$ <independent and identically distributed> <Bernoulli random variables> with success probability $p$, the <sum> $K=\sum_iX_i$ has a <binomial distribution>. Every length-$n$ pattern with $k$ successes has <probability> $p^k(1-p)^{n-k}$, and the <binomial coefficient> counts its $\binom nk$ possible success positions. Therefore
$$
\mathbb P(\overline X=k/n)=\binom nk p^k(1-p)^{n-k},\qquad
\mathbb E[\overline X]=p,\qquad
\operatorname{Var}(\overline X)=\frac{p(1-p)}n.
$$
The usual endpoint convention includes $p=0$ and $p=1$ as deterministic cases. For $p=1/2$ and $n=4$, the five <probability masses> are $1,4,6,4,1$ divided by $16$. The <sample mean> takes values $0,1/4,1/2,3/4,1$, with <variance> $1/16$ and <standard deviation> $1/4$. At $n=64$, its variance is $1/256$ and its standard deviation is $1/16$.

\Image[/iid-versus-common-coin-sample-means.png]
{title=Exact sample-mean distributions distinguish fresh IID draws from a copied common coin}
{description=Original exact <binomial distribution> probabilities for sample sizes $1,4,16,64$. Blue marks give the mass at each possible mean under independent fair draws. Orange marks give the masses for the same fair draw copied $n$ times: $1/2$ at zero and $1/2$ at one for every $n$. These are discrete <probability masses>, not density values or measured histograms.}