# Integration by parts in expectation of a random variable

Prove the integration by parts property of expectation of a random variable, that is, for a random variable $$X$$ with cumulative distribution function $$F_X$$ and probability density function $$f_X$$,
\begin{align*} E[X] = \int_{-\infty}^{\infty}x f_X(x)\, dx = \int_{0}^{\infty}(1 - F_X(x)) \,dx - \int_{-\infty}^{0}x F_X(x)dx \end{align*}

My attempt:

\begin{align*} E[X] &= \int_{-\infty}^{\infty}x f_X(x)\, dx \\ &= \bigg[xF(x)\bigg]_{-\infty}^{\infty} - \int_{-\infty}^{\infty}F_X(x)\, dx \end{align*}

But I get stuck here itself and it leads nowhere. So how do I use integration by parts to prove the result?

As right hand side guides you, First split negative and positive parts. Then try to prove it.

An intuitive proof (Maybe you didn't believe it is a proof!):

Consider a vertical element in graph of $$f(x)$$, and prove it occurs in left hand side $$(xf(x))$$ as many as in right hand side$$((1-F(x))$$ or $$(xF(x)))$$.

• I'm sorry I didn't understand your hint. I did try to split it as well, but to no avail. Could you write out a few steps that I could complete? Sep 10 '20 at 12:06

Maybe it's too late for the asker but useful for the later readers.

As Ali Ashja' said, first separate the integral in two: in positive values and negative values: $$\int_0^{\infty}xf(x)dx+\int_{-\infty}^0xf(x)dx$$. Then apply integration by parts with $$u=x$$ and $$dv=f(x)dx$$. You have to choose a primitive of $$f(x)$$ for $$v$$, surely you think $$v=F(x)$$ is an option, that's true but in this case it's better to choose $$v=F(x)-1$$ and you will see a more similar expression to the final result.

The original statement is simply false! The correct statement is

$$\mathbb{E}[X]=\int_0^{\infty}\left[1-F_X(x)\right]dx-\int_{-\infty}^0 F_X(x)dx=I_1-I_2$$

this can be easy proved integrating by parts

$$I_1=\underbrace{\left[x(1-F_X(x) ) \right]_0^{\infty}}_{=0}+\int_0^{\infty}xf_X(x)dx$$

$$I_2=\underbrace{\left[xF_X(x) \right]_{-\infty}^0}_{=0}-\int_{-\infty}^0xf_X(x)dx$$

thus

$$\mathbb{E}[X]=I_1-I_2=\int_{-\infty}^{\infty}xf_X(x)dx$$

The expressions =0 in the above $$I_1,I_2$$ can be easily proved applying de l'Hôpital to the resulting limit

Geometrically, this means that the expectation is the difference between Purple and Yellow Areas