# Deriving the variance of a binomial distribution

I know that the variance of a binomial distribution is the number of trials multiplied by the variance of each trial, but I'm not seeing the derivation of this. Here's my logic so far:

For each trial ($x$), $p$ = probability of success (1), and $1-p$ = probability of failure (0):

$$E(x) = 1\cdot p+0\cdot(1-p) = p$$ $$E(x^2) = 1^2\cdot p+0^2\cdot(1-p) = p$$ $$Var(x) = E(x^2)-E(x)^2 = p - p^2 = p(1-p)$$

From here, for any combination of trials ($X$):

$$X = x_1 + x_2 + \cdots + x_n$$ $$E(X) = E(x_1) + E(x_2) + \cdots + E(x_n)$$ $$E(X) = np$$ $$E(X^2) = E(x_1^2) + E(x_2^2) + \cdots + E(x_n^2)$$ $$E(X^2) = np$$

By this, the logic indicates the variance would be:

$$Var(X) = E(X^2) - E(X)^2 = np - (np)^2 = np(1-np)$$

...however, this is not correct, since the variance is as follows:

$$Var(X) = Var(x_1) + Var(x_2) + \cdots + Var(x_n)$$ $$Var(X) = p(1-p) + p(1-p) + \cdots + p(1-p)$$ $$Var(X) = np(1-p)$$

I'm not seeing in my derivation where I'm missing the mark mathematically, and resulting in the incorrect "n" in the parentheses.

• The problem is that $(x_1+ x_2 + \cdots x_n)^2 \neq x_1^2 + x_2^2 + \cdots + x_n^2$. – Antoine May 9 '15 at 19:28
• You can use $$X^2 = \{X_1 ^2 + X_2 ^2 + \cdots + X_n ^2\} + 2{n\choose k}\sum_{i \neq j}(X_I X_J)$$, then calculate expectations using linearity and independence of random variables. – Tamojit Maiti Jun 19 '18 at 4:39

$E [X_i X_j] = p^2$. ${}{}{}{}{}{}{}{}{}$

So $E X^2 = \sum_{i=1}^n E X_i^2 + \sum_{i \neq j} E[X_i X_j] = np +(n^2-n)p^2$, and so $\operatorname{var} X = np(1-p)$.

• Ok I see that $E(X^2)$ is not the same as $E(x^2)$ for an individual trial's probability distribution, and that's where my mistake has been. I also see the this represented by the sums you mentioned. However, I'm not seeing the math that equates these sums to $np+(n^2-n)p^2$....I've not had much number theory. Is there a quick resource or explanation to help me understand this? I guess for starters, one question I'd have is what is the value of $x_{1}$, $x_{2}$, etc., in $X$? I know what $E(x_{1})$ is from the trial distribution function and its random variable, but not the "trial" itself... – Topher May 9 '15 at 20:35
• $(\sum_k X_k)^2 = \sum_i \sum_j X_i X_j$. Look at the $n^2$ pairs $(i,j)$, $n$ of them are equal and the other $n^2-n$ are not. This is where the $n$, $n^2-n$ come from. – copper.hat May 9 '15 at 20:39

Your computation of $\mathbb{E}[X^2]$ is incorrect. In particular, $$\mathbb{E}[X^2] \neq \mathbb{E}[X_1^2] + \dots + \mathbb{E}[X_n^2]$$ since $\mathbb{E}[X^2] = \mathbb{E}[(X_1+\dots+X_n)^2]$.

To extend your line of thought, $X=X_2 + X_2 + X_3 + \cdots + X_n$ be the random variable that denotes the number of successes in $n$ Bernoulli trials. As you correctly state, all the $X_i$ s are indicator variables that 'indicate' whether success/failure occurs in the $i^{th}$ trial.

Clearly, $E[X_i]=p$ and $E[X_i ^2]=p$

Now $X=X_1 + X_2 + \cdots + X_n$

Squaring both sides, we have $$X^2 = \{X_1 ^2 + X_2 ^2 + \cdots + X_n ^2\} + 2{n\choose k}\sum_{i \neq j}(X_I X_J)$$

This is the important bit that you were missing.

Now you can evaluate expectation of $X^2$ by using the linearity of expectations property and the fact that for two independent random variables $X,Y$ we have $E[XY]=E[X]E[Y]$

For completeness,

$$\Rightarrow E[X^2]=nE[X_i ^2] + n(n-1)E[X_i]E[X_i]$$ $$\Rightarrow E[X^2]=np + n(n-1)p^2$$

$$\Rightarrow \sigma ^2(X)=E[X^2] - (E[X])^2$$ $$\Rightarrow \sigma^2(X)=np+n(n-1)p^2 -(np)^2$$ $$\Rightarrow \sigma^2(X)=np-np^2=np(1-p)$$