Here is a useful identity relating the expectation of a non-negative random variable $X$ to the integral of its tail. $ \newcommand{\abs}[1]{| #1 |} \newcommand{\E}{\mathbb{E}} \newcommand{\ind}{\mathbf{1}} \renewcommand{\Pr}{\mathbb{P}} $

Proposition: Let $X \geq 0$ be a non-negative random variable. We have the equality $$ \E X = \int_0^\infty \Pr( X \geq t ) \; dt \:. $$

Proof: We simply write the right hand side as $$ \begin{align*} \int_0^\infty \Pr( X \geq t ) \; dt &= \int_0^\infty \int \ind_{\{X \geq t\}} \; d\mu \; dt \\ &\stackrel{(a)}{=} \int \int_0^\infty \ind_{\{X \geq t\}} \; dt \; d\mu \stackrel{(b)}{=} \int \int_0^X \; dt \; d\mu = \int X \; d\mu = \E X \:, \end{align*} $$ where in (a) we used Fubini's theorem to switch the order of integration and in (b) we used the fact that $X \geq 0$.

As an example, we can use this identity to compute the expected value of an exponential random variable without having to integrate by parts. Letting $X$ be a standard exponential random variable with density $f(x) = e^{-x}$, we have for any $t \geq 0$ that $\Pr(X \geq t) = \int_0^t e^{-x} \; dx = e^{-t}$. Hence, $$ \E X = \int_0^\infty \Pr(X \geq t) \; dt = \int_0^\infty e^{-t} \; dt = 1 \:. $$