# Finding the mean out of a CDF

I'm trying to find the mean out of a cumulative density function (cdf). I found this question but it was no use because I didn't cover the explanation I was expecting. Here's my function: $$F(x) = \begin{cases} 0, & \text{if x < 0}\\[2ex] x^2, & \text{if 0 \le x < 1/2}\\[2ex] \frac{1}{4}, & \text{if 1/2\le x<3} \\[2ex] \frac{x-2}{4}, & \text{if 3\le x < 6}\\[2ex] 1, & \text{if x\ge 6} \end{cases}$$

In the question I linked to above, only the interval in the middle was used in the integration. Would anyone mind explaining the intuition behind integrating this function in order to find the mean?

• In the linked post, mean was calculated using the relation $E(X)=\int_0^{\infty}(1-F(x))\,dx$ for a nonnegative RV $X$. If you look carefully, all the pieces were integrated (not just the 'middle' one), then added. – StubbornAtom Jun 26 '17 at 18:38

It is said in an answer that the user made an error in the arithmetic.

For your case, I assume the sample space is $[0, 6].$ Here's what we do:

Integrate the CDF as follows:

$$\int_0 ^6 1 - F(x) \ dx = 6 - \left( \int_0^\frac{1}{2} x^2 \ dx + \int_\frac{1}{2} ^3 \frac{1}{4} \ dx + \int_3 ^6 \frac{x-2}{4} \ dx \right)$$

Can you take it from here?

• the last integral limit shoul be 3 to 6 i guess – Upstart Jun 26 '17 at 18:44
• Yes, thank you for catching that. – Sean Roberson Jun 26 '17 at 18:44

$F(x) = \int_{0}^{x} f(x) dx\\ \mu = \int_{0}^{6} xf(x) dx$

Integration by parts.

$\mu = xF(x)|_0^6 - \int_{0}^{6} F(x) dx\\ \mu = 6 - \int_{-\infty}^{\infty} F(x) dx\\ \mu = 6 - \int_{0}^{\frac 12} x^2 dx - \int_{\frac 12}^{3} \frac 14 dx- \int_{3}^{6} \frac {x-2}{4} dx$

However you could also say

$f(x) = \frac {d}{dx} F(x) = \begin{cases} 2x &0\le x \le \frac 12\\0 &\frac12 <x \le 3\\\frac {x}{4} &3 <x \le 6\\0&x>6\end{cases}$

$\mu = \int_0^{\frac 12} 2x^2 dx +\int_3^{6} \frac {x}{4} dx$

And, hopefully, those two results are equal.