TITLE: Prove that $E(X) = \int_{0}^{\infty} P(X>x)\,dx = \int_{0}^{\infty} (1-F_X(x))\,dx$.
QUESTION [8 upvotes]: Let $X$ be a continuous non-negative random variable (i.e. $R_x$ has only non-negative values). Prove that $$E(X) = \int_{0}^{\infty} P(X>x)\,dx  = \int_{0}^{\infty} (1-F_X(x))\,dx$$ where $F_X(x)$ is the CDF for $X$. Using this result, find $E(X)$ for an exponential ($\lambda$) random variable.

I know that by definition, $F_X(x) = P(X \leq x)$ and so $1 - F_X(x) = P(X>x)$
The solution is:
$$\int_{0}^{\infty} \int_{x}^{\infty} f(y)\,dy dx   
= \int_{0}^{\infty} \int_{0}^{y} f(y)\,dy dx 
= \int_{0}^{\infty} yf(y) dy.$$
I'm really confused as to where the double integral came from. I'm also rusty on multivariate calc, so I'm confused about the swapping of $x$ and $\infty$ to $0$ and $y$.
Any help would be greatly appreciated!

REPLY [6 votes]: First note that \begin{align}
P\{X>x\}&=E(1_{X>x})\\
&=\int_0^{\infty}1_{y>x}f(y)dy
\end{align}
Therefore 
\begin{align}
\int_0^{\infty}P\{X>x\}dx&=\int_0^{\infty}\int_0^{\infty}1_{y>x}f(y)dydx\\
&=\int_0^{\infty}\int_0^{\infty}1_{y>x}f(y)dxdy\\
&=\int_0^{\infty}yf(y)dy\\
\end{align}