Here is the full question (and note this is a question on my homework, but I just don't understand a portion of it):
Suppose a random variable $X$ has the support of $S_X = \left\{0,1\right\}$ with the probability distribution $P(X = 1) = p$ and $P(X = 0) = 1 - p$ for some $p$ between zero and one.
- Find $E(X)$ (Expectation of X)
- Using the result of 1, find the variance of $X$ using the fact that $Var(X) = E(X^2) - E(X)^2$.
I think I'm getting the right answer for number 1, but I don't know how to apply it to number 2.
1. $E(X) = 0 \times P(X = 0) + 1 \times P(X = 1)$
$ = 0 \times p + 1 \times (1 - p)$ $ = 1- p$
For 2, how can I apply this for $E(X^2)$? Right now I'm getting $Var(X) = 0$ because of this:
$E(X^2) = 0 \times p^2 + (1 - p)^2 = 1 - 2p + p^2$
But then $E(X)^2 = 1 - 2p + p^2$
So doing $Var(X) = E(X^2) - E(X)^2 = 0$
What am I doing wrong?
Consider random variable $X^2$
$P(X^2=0) = P(X=0) = p$
$P(X^2=1) = P(X=1) = 1-p$
$E[X^2] = 0^2.P(X^2=0) + 1^2.P(X^2=1) = 1-p$
Thus, $Var(X) = (1-p) - (1-p)^2 = p(1-p)$
$X$ is a Bernoulli Random Variable