# Variance of binomial distribution

Why for $X\sim B(n,p)$ is $Var(X)=np(1-p)$?

$Var(X)=\sum x_i^2 p_i -(\sum x_i p_i)^2=\sum_{r=0}^n r^2 \binom{n}{r}p^r(1-p)^{n-r}+( \sum_{r=0}^n r \binom{n}{r}p^r(1-p)^{n-r} )^2$

In my short-sightedness, I don't see any viable ways to derive the variance from this.

-

An easier way is to recognize that $X = Y_1 + Y_2 + \cdots Y_n$ where $Y_k$ are independent Bernoulli random variables with parameter $p$. For a Bernoulli random variable $Y_k$, we have $$\text{Var}(Y_k) = p(1-p)$$ Since $Y_k$ are independent, we have that $$\text{Var}(X) = \text{Var}(Y_1) + \text{Var}(Y_2) + \cdots + \text{Var}(Y_n) = np(1-p)$$

To go the direct way, we need to first evaluate couple of summations.

We will evaluate the sums $$\sum_{k = 0}^n k \mathbb{P}(X=k) \text{ and }\sum_{k = 0}^n k^2 \mathbb{P}(X=k)$$ First note that $\mathbb{P}(X=k) = \dbinom{n}k p^k (1-p)^{n-k}$. Hence, $$\sum_{k = 0}^n k \mathbb{P}(X=k) = \sum_{k = 0}^n k \dbinom{n}k p^k (1-p)^{n-k}$$ Note that $$k \dbinom{n}k = \dfrac{n!}{(n-k)! (k-1)!} = n \dbinom{n-1}{k-1}$$ Hence, \begin{align} \sum_{k = 0}^n k \mathbb{P}(X=k) & = \sum_{k = 1}^n n \dbinom{n-1}{k-1} p^k (1-p)^{n-k} = np \sum_{k = 1}^n \dbinom{n-1}{k-1} p^{k-1} (1-p)^{(n-1)-(k-1)}\\ & = np \left( p + (1-p)\right)^{n-1} = np \end{align} Similarly, \begin{align} k^2 \dbinom{n}k & = k \dfrac{n!}{(n-k)! (k-1)!} = n k \dbinom{n-1}{k-1}\\ & = n (k-1) \dbinom{n-1}{k-1} + n \dbinom{n-1}{k-1}\\ & = n(n-1) \dbinom{n-2}{k-2} + n \dbinom{n-1}{k-1} \end{align} Hence, \begin{align} \sum_{k = 0}^n k^2 \mathbb{P}(X=k) & = \sum_{k = 2}^n n(n-1) \dbinom{n-2}{k-2} p^k (1-p)^{n-k} + \sum_{k = 1}^n n \dbinom{n-1}{k-1} p^k (1-p)^{n-k}\\ & = n(n-1)p^2 + n p \end{align} Hence, \begin{align} \text{Var}(X) & = \sum_{k = 0}^n k^2 \mathbb{P}(X=k) - \left(\sum_{k = 0}^n k \mathbb{P}(X=k) \right)^2\\ & = n(n-1)p^2 + n p - (np)^2 = n^2p^2 - np^2 + np - n^2 p^2\\ & = np(1-p) \end{align}

-
Thanks for the answer. Bernoulli trials (at least the LaTex of them) seem much more elegant than brute force, do you know of a good introduction to them? – Alyosha Nov 18 '12 at 20:15
@Alyosha Wiki has good articles on both en.wikipedia.org/wiki/Bernoulli_distribution and en.wikipedia.org/wiki/Binomial_distribution – user17762 Nov 18 '12 at 20:31

Compute the expected value of $k$ \begin{align} \mathrm{E}(k) &=\sum_{k=1}^nk\binom{n}{k}p^k(1-p)^{n-k}\\ &=\sum_{k=1}^nnp\binom{n-1}{k-1}p^{k-1}(1-p)^{n-k}\\ &=np(p+(1-p))^{n-1}\\ &=np\tag{1} \end{align} Compute the expected value of $k(k-1)$ \begin{align} \mathrm{E}(k(k-1)) &=\sum_{k=1}^nk(k-1)\binom{n}{k}p^k(1-p)^{n-k}\\ &=\sum_{k=1}^nn(n-1)p^2\binom{n-2}{k-2}p^{k-2}(1-p)^{n-k}\\ &=n(n-1)p^2(p+(1-p))^{n-2}\\ &=n(n-1)p^2\tag{2} \end{align} Add $(1)$ and $(2)$ to get $\mathrm{E}(k^2)$ then subtract the square of $(1)$ to get \begin{align} \mathrm{Var}(k) &=\mathrm{E}(k^2)-\mathrm{E}(k)^2\\ &=n^2p^2-np^2+np-n^2p^2\\ &=np(1-p)\tag{3} \end{align}

-

Use a different model. Let $S_n = \sum_{i=1}^n X_i$ where $X_i$ are iid bernoulli random variables with parameter p. Then $S_n$ is Binomial(p,n).

Now $Var(S_n) = \sum_{i=1}^n Var(X_i) = np(1-p)$

-

Replace $1-p$ by $q$, then replace each factor of $r$ by $p\partial/\partial p$.

-