# Calculate the expectation of a random variable given its cdf

The cdf of a random variable $X$ is given by the following.

$F_X(x) = \begin{cases} 0 & x < 0\\\\ \frac x2 & x \in [0,1)\\\\ \frac 23 & x \in [1,2)\\\\ \frac{11}{12} & x \in [2,3) \\\\ 1 & x \ge 3 \end{cases}$ How do I calculate the expectation of the random variable $X$?

-

$$\int_0^\infty (1 - F(x))\ dx$$

-
Would you elaborate? How should I integrate since F(x) can take many different forms depending on x. –  idealistikz Sep 24 '12 at 20:52
@idealistikz just break it down into 3 parts, depending on the interval, and the integral over the whoel thing is the sum of the intergals over individual parts. –  gt6989b Sep 24 '12 at 20:59
Why do I break it into 3 parts when there are 5 conditions? Do you mean 5 parts? –  idealistikz Sep 24 '12 at 21:03
@idealistikz: Because the integral over the last part is clearly $0$, and the first part is irrelevant: the probability there is $0$. –  Brian M. Scott Sep 24 '12 at 21:09
Why is the integral over the last part 0? When x>=3, isn't the integral for that part x? –  idealistikz Sep 24 '12 at 21:12
show 7 more comments

You can come up with a piecewise defined density function by differentiating, but that fails to account for the jump discontinuities at $x=1$, $x=2$, and $x=3$. You get $$f(x) = 1/2\text{ if }1<x<2\text{ and }f(x)=0\text{ elsewhere}.$$ Calling the random variable (capital) $X$, we then have $$\begin{cases} \Pr(X\in A) = \int_A \frac12\ dx & \text{if }A\subseteq[0,1), \\[8pt] \Pr(X=1) = 1/6, \\[8pt] \Pr(X=2) = 1/4, \\[8pt] \Pr(X=3) = 1/12. \end{cases}$$ The expected value is then $$\int_0^1 x\frac12\, dx + 1\cdot\frac16 + 2\cdot\frac14+3\cdot\frac{1}{12}.$$ This is somewhat pedestrian, but it has this advantage over Robert Israel's answer: the method still works even for random variables that can be negative.

-

There is another, definitely less good way, to find the expectation. Let us analyze the distribution of the random variable $X$. The part before $0$ is harmless.

For $0\le x\lt 1$, the cumulative distribution function is $x/2$, nice and familiar, the density function is the derivative of the the cdf, which is $1/2$.

At $1$, and all the way up to but not including $2$, the cdf is $2/3$. So there is a sudden jump at $x=1$. As we approach $1$ from the left, the cdf approaches $1/2$, but all of a sudden it is $2/3$ at $1$, and then stays at that all the way to, but not including $2$. What that means is that there is a discrete "weight" of $2/3-1/2$ at $x=1$: $\Pr(X=1)=2/3-1/2=1/6$.

The cdf takes another sudden jump to $11/12$ at $2$. That means we have a weight of $11/12-2/3$, that is, $3/12$, at $x=2$.

Finally, there is another weight of $1/12$ at $x=3$.

To sum up, this is a mixed continuous-discrete situation: there is a continuous uniform distribution, density $1/2$, between $0$ and $1$. In addition, $\Pr(X=1)=1/6$, $\Pr(X=2)=3/12$, and $\Pr(X=3)=1/12$. The moment about the origin (mean) is therefore $$\int_0^1 x\cdot\frac{1}{2}\,dx+ 1\cdot\frac{1}{6}+2\cdot \frac{3}{12}+3\cdot \frac{1}{12}.$$

I think this simplifies to $\dfrac{7}{6}$. You might want to compare that with the result you get from doing it the full integration way. The latter approach is the one you should become comfortable with.

-