# Variance of n Bernoulli Trials

Count the variance of n Bernoulli trials with each probability of success is p.

Let random variable $X_i$ be
$1$ if trial is success, or
$0$ if trial fails.

Then expected value $E(X_i) = 1 \times p + 0 \times (1 - p) = p$.
By linearity of expectation $E(X) = p_1 + p_2 + ... + p_n = np$.

To count the variance, I use this formula $V(X) = E(X^2) - E(X)^2$.

where $E(X_i^2) = 1^2 \times p + 0^2 \times (1 - p) = p$
then, $E(X^2) = p_1 + p_2 + ... + p_n = np$.

So, I got variance $V(X) = np - (np)^2 = np(1 - np)$.

But in wiki, it says that the correct variance is $np(1 - p)$.

Where did I do wrong?
Thanks a lot for the help.

• math.stackexchange.com/questions/240070/… Does that help?
– Meow
Aug 13, 2013 at 19:43
• @Alyosha, thanks for the link. I'm still a bit confused, so, $E(X_i^2) \neq p$ ? Aug 13, 2013 at 19:48
• @user350954: your solution can't be correct since in most cases $1-np<0$, which makes the variance negative
– Alex
Aug 13, 2013 at 19:51

The variance of $n$ independent things is the sum of their variances, so $$\text{Var}(X)=\sum_i\text{Var}(X_i)=\sum_iE(X_i^2)-E(X_i)^2$$ Note that your proposed equality $$\text{Var}(X)= E(X^2)-E(X)^2=\sum_iE(X_i^2)- \left(\sum_iE(X_i)\right)^2$$ does not satisfy this, as here the squaring is done after the summing, so two different terms $E(X_i)$ and $E(X_j)$ will multiply, so the independence is lost.
The problem with your proof is that the square of a sum is not equal to the sum of the squares, which is what you used to say $E(X^2)=np$.