# Calculate the variance of random variable $X$

A random variable has the cumulative distribution function $$F(x)=\begin{cases} 0 & x<1\\\frac{x^2-2x+2}{2}&x\in[1,2)\\1&x\geq2\end{cases}.$$ Calculate the variance of $X$.

First I differentiated the distribution function to get the density function, $f_X(x)=x-1$, for $x\in[1,2)$, and then I calculated $$E(X^2)-[E(X)]^2=\int_1^2x^2(x-1)dx-\bigg(\int_1^2x(x-1)dx\bigg)^2=\frac{13}{18}.$$ However, the correct answer is $\frac{5}{36}$. Why is that answer correct? I thought $var(X)=E(X^2)-[E(X)]^2$?

Also, Merry Christmas!

Note that $X$ does not have continuous distribution. For $F(x)$ approaches $0$ as $x$ approaches $1$ from the left, while $F(1)=1/2$.

So there is a point mass of $1/2$ at $x=1$. This has to be taken into consideration both for the calculation of $E(X)$ and of $E(X^2)$. (Your expression for the variance in terms of $E(X)$ and $E(X^2)$ is correct.)

• You may already know how to find expectations of mixtures such as this one, We do what comes naturally. For example $E(X)=(1)(1/2)+\int_1^2 x(x-1)\,dx$. Dec 25, 2015 at 21:21

A useful trick for non-negative random variables is to note that:

$E[X] = \int_0^\infty (1- F(x)) dx$

$E[X^2] = 2 \int_0^\infty x (1- F(x)) dx$

(These can be derived by integration by parts. No need to worry about point masses, which you have as André Nicolas pointed out.)

Thus, $E[X] = \int_0^1 1 dx + \int_1^2 (1- \frac{x^2-2x+2}{2}) dx$. Similarly, $E[X^2] = 2 \left( \int_0^\infty x dx+ \int_1^2 x(1- \frac{x^2-2x+2}{2}) dx \right)$.

Then, apply $var(X) = E[X^2] - (E[X])^2$ as you stated.