[Math] Deriving the variance of the Bernoulli distribution

probabilityprobability distributions

For a Bernoulli distribution, $\mu_X = p$. I can easily derive this from the general equation for mean of a discrete random variable:
$$
\mu_X=\sum_{i=1}^kx_iPr(X=x)
$$
$$
\mu_X=1(p)+0(1-p)=p
$$
I know that the variance of the Bernoulli distribution is supposed to be $\sigma_x^2=p(1-p)$. But I can not seem to derive that properly from the general equation for variance of a discrete random variable:
$$
\sigma_x^2=\sum_{i=1}^k(x_i-\mu_X)Pr(X=x_i)
$$
$$
\sigma_x^2=(x_0-p)(1-p)+(x_1-p)(p)
$$
$$
\sigma_x^2=(0-p)(1-p)+(1-p)(p)
$$
$$
\sigma_x^2=-p(1-p)+(1-p)(p)
$$
$$
\sigma_x^2=-p+p^2+p-p^2
$$
$$
\sigma_x^2=0
$$
This is obviously incorrect; what am I doing incorrectly in my derivation?

Best Answer

$$ \sigma_x^2=\sum_{i=1}^k(x_i-\mu_X)^\color{red}2Pr(X=x_i) $$ $$ \sigma_x^2=(x_0-p)^\color{red}2(1-p)+(x_1-p)^\color{red}2(p) $$ $$ \sigma_x^2=(0-p)^\color{red}2(1-p)+(1-p)^\color{red}2(p) $$ $$ \sigma_x^2=p^\color{red}2(1-p)+(1-p)^\color{red}2(p) $$ $$ \sigma_x^2=p(1-p)(p+1-p)=p(1-p) $$

Related Question