# Expected Value of a Generic Positive Random Variable

Here is a math problem:

Suppose we are told that $P(X > 0) = 1$ and are given that $\lim_{n\to\infty} x\big[1-F(x)\big] = 0$. Show that $\mathbb{E}[X] = \int_0^{\infty} P(X > x)dx$.

Let’s start with the definition of expectation and use integration by parts.

$\mathbb{E}[X] = \int_{-\infty}^{\infty}xf_X(x)dx = \int_0^{\infty}xf_X(x)dx$ since we are given $x \in (0,\infty)$.

Now using integration by parts, making the natural selection we have:

$u=F_X(x) \quad \quad v=x$
$u'=f_X(x) \quad \quad v'=dx$

Recall that $\int u'v = uv-\int uv'$ and plugging in our selections we get:

$\mathbb{E}[X] = \int_0^{\infty}xf_X(x)dx = xF_X(x)\bigm|_0^{\infty} - \int_0^{\infty} F_X(x)dx$

Let’s rewrite $\int_0^{\infty} F_X(x)dx$ as $\int_0^{\infty} \big(1 - P(X > x)\big)dx$. This simplifies to $\int_0^{\infty} dx - \int_0^{\infty} P(X > x)dx$. Let’s plug this back into our equation above:

$\mathbb{E}[X] = \int_0^{\infty}xf_X(x)dx = xF_X(x)\bigm|_0^{\infty} - \bigg(\int_0^{\infty} dx - \int_0^{\infty} P(X > x)dx \bigg)$

$\mathbb{E}[X] = xF_X(x)\bigm|_0^{\infty} - x\bigm|_0^{\infty} + \int_0^{\infty} P(X > x)dx$

$\mathbb{E}[X] = \big[xF_X(x)- x\big]_0^{\infty} + \int_0^{\infty} P(X > x)dx$

$\mathbb{E}[X] = \big[x(F_X(x)- 1)\big]_0^{\infty} + \int_0^{\infty} P(X > x)dx$

$\mathbb{E}[X] = \big[-x(1-F_X(x))\big]^{x=\infty} + \int_0^{\infty} P(X > x)dx$ since plugging in $0$ to the first half of our expression just yields $0$. We can’t actually evaluate $x$ at infinity, instead we take the limit:

$\mathbb{E}[X] = -\lim_{x\to\infty} x\big[1-F(x)\big] + \int_0^{\infty} P(X > x)dx$, but recall that we are told $\lim_{x\to\infty} x\big[1-F(x)\big] = 0$ and so we are simply left with:

$\mathbb{E}[X] = \int_0^{\infty} P(X > x)dx$, our desired result.