How do we obtain $\int_0^\infty 1-F(x)dx$ for the expectation of a random variable? Under what conditions does this give the expectation? For the first time I have come across the form $\int_0^\infty 1-F(x)dx$ for the expectation of a random variable $X$, with cumulative distribution function $F(x)$. I am familiar with the expectation as being $\int_0^\infty xf(x)dx$, with $f(x)$ the probability density function. But I am confused as to when one can apply this new formula. It seems to me that it will not always work.
If I attempt to show equivalence of these, I will integrate by parts:
$\int_0^\infty (1-F(x))dx = x(1-F(x))|_0^\infty + \int_0^\infty xf(x)dx$
Thus if $\int_0^\infty (1-F(x))dx$ is to be the expectation, we need $x(1-F(x))|_0^\infty =0$.
Clearly $0(1-F(0))=0$, however if we have $\text{lim}_{t\rightarrow \infty}t(1-F(t))=0$, I think that requires some additional assumptions on how quickly $F(t)\rightarrow 1$ for large $t$? As we need $t = o(\frac{1}{(1-F(t))})$?
What kinds of random variables does this new formula work for? Could anyone give some concrete examples to help me have some intuition? I have a feeling that whether a random variable has finite expectation or not will affect whether a formula will work, but there are probably many more cases/examples.
 A: The formula will always work if the random variable is almost surely nonnegative (Note that a nonnegative random variable always admits an expectation, although it can be infinite).
To prove it, you can just use the Fubini Tonnelli formula (you integrate positive functions so they always exist but can have an infinite value)
$\int_0^\infty (1-F(x))dx=\int_0^\infty \mathbb{P}(X>x)dx = \int_0^\infty \int_x^\infty (f(t)dt)dx =  \int_0^\infty  tf(t)dt = \mathbb{E}(X)$
The proof above is only valid in the case where the variable admits a density function, but it also works if it doesn't):
$\int_0^\infty (1-F(x))dx=\int_0^\infty \mathbb{P}(X>x)dx = \int_0^\infty \int_x^\infty (d\mathbb{P}(t))dx =  \int_0^\infty  td\mathbb{P}(t) = \mathbb{E}(X)$ where $\mathbb{P}$ is the distribution of the random variable.
So the only case where this formula does not work is the case where the random variable can be negative with a nonzero possibility (Which makes sense cause the formula does not even look at the distribution over the negative real numbers).
The flaw in your integration by parts is that the only case where your first term is not zero is only in the case where the expectation is infinite. It is the only case where the first term does not converge (cause having a finite expectation is equivalent to $x\mathbb{P}(X>x)$ has a limit equal to $0$ when $x\rightarrow \infty$). In this case, the integration by parts gives you that $\int_0^\infty (1-F(x))dx=$ something positive + $\infty$ which is always infinite, even if the "something positive" is not well-defined (the proper reasonning only involves an integration by parts on a finite interval, and you can get to the correct conclusion by having the upper bound of the interval go to infinity).
