Let $Y$ be a random variable with finite expectation, and $m$ be a median

of $Y;$ i.e., $P(Y \le m) \ge 1/2$ and $P(Y \ge m) \ge 1/2.$ Show that, for

any real numbers $a$ and $b$ such that $m\le a \le b$ or $m \ge a \ge b,$

$E|Y − a| \le E|Y − b|.$

It is known than the mean absolute deviation is minimum about the median. If $m$ is the median then for $m\le a \le b$ or $m \ge a \ge b,$ $a$ is closer to $m$ than $b.$ So, the expected absolute deviation for $a$ will be less than $b.$ The inequality is intuitively clear to me. *Please prove it mathematically.*

## Best Answer

## Intuition

As explained at Expectation of a function of a random variable from CDF, an integration by parts shows that when a random variable $X$ has a (cumulative) distribution function $F,$ the expectation of $|X-a|$ is the sum of the shaded areas shown:

The left hand region is the area under $F$ to the left of $a$ while the right hand region is the area

above$F$ to the right of $a:$ that is, it's the area under $1-F$ to the right of $a.$This is an extremely useful picture to have in mind when thinking about expectations. It can make seemingly complicated relationships intuitively obvious.The height of $F$ is at least $1/2$ at the median $m,$ as shown by the dotted lines.

When $a \ge m$ is increased to $b,$ these areas change: the left hand area grows while the right hand area shrinks. The resulting region is shown here in blue.

The old area was $I+II+IV$ while the new one is $II + III + IV.$ Their difference therefore is $III - I.$ (This is the integral of $F - (1 - F) = 1 - 2F$ between $a$ and $b.$) Because $III$ includes the entire rectangle between $a$ and $b$ below the height $1/2$ and $I$ lies within the rectangle between $a$ and $b$ above the height $1/2,$ the difference $III - I$ cannot be negative (and actually is positive in the figure). Thus,

as $a\ge m$ increases, the expectation of $|X-a|$ cannot shrink -- it can only grow.A similar geometric argument can be used to analyze any quantile, not just the median, by means of a suitable weighting of the upper and lower areas. See https://stats.stackexchange.com/a/252043/919 for some analysis of this.

## Formal Solution

Fix an arbitrary (but finite) $b \gt m,$ suppose $a$ is any number for which $m \le a \le b,$ and consider the difference

$$h(a) = E\left[|Y-b| - |Y-a|\right] = E\left[|Y-b|\right] - E\left[|Y-a|\right].$$

We aim to show $h(a) \ge 0.$ We will do this by computing the expectation and finding a simple lower bound for it. The only technique we need is a straightforward integration by parts.

Writing $F$ for the distribution of $Y$ and integrating in the sense of Lebesgue-Stieltjes,

compute this expectation by breaking the integral into three regionsbounded by $a$ and $b$ so that the absolute values can be expressed more simply within each region (look closely at how the signs in the integrands vary in the third line):$$\begin{aligned} h(a) &= \int \left(|x-b| - |x-a|\right)\,\mathrm{d}F(x) \\ &= \left(\int_{-\infty}^a + \int_a^b + \int_b^\infty\right) \left(|x-b| - |x-a|\right)\,\mathrm{d}F(x) \\ &= \int_{-\infty}^a(b-x)-(a-x)\,\mathrm{d}F(x) + \int_a^b(b-x)-(x-a) \,\mathrm{d}F(x) \\&\quad+ \int_b^\infty(x-b)-(x-a)\,\mathrm{d}F(x) \\ &= (b-a)\int_{-\infty}^a\,\mathrm{d}F(x) + \int_a^b(a+b-2x) \,\mathrm{d}F(x) + (a-b)\int_b^\infty\,\mathrm{d}F(x). \\ \end{aligned}$$

Evaluate the middle integral by parts:$$\begin{aligned} \int_a^b(a+b-2x) \,\mathrm{d}F(x) &= (a+b-2x)F(x)\bigg|^b_a + 2\int_a^b F(x)\,\mathrm{d}x\\ &= (a-b)F(b) - (b-a)F(a)+ 2\int_a^b F(x)\,\mathrm{d}x \\ &= (a-b)(F(b) + F(a))+ 2\int_a^b F(x)\,\mathrm{d}x. \end{aligned}$$

Plug this into the previous expression for $h(a)$ and note that

because $a \ge m,$ $F(x) \ge 1/2$ throughout this integral:$$\begin{aligned} h(a) & = (b-a)F(a) + \left[(a-b)(F(b)+F(a)) + 2\int_a^b F(x)\,\mathrm{d}x\right] + (a-b)(1 - F(b)) \\ &= a-b + 2\int_a^b F(x)\,\mathrm{d}x\\ &= 2\int_a^b \left(F(x) - \frac{1}{2}\right)\,\mathrm{d}x \\ &\ge 2\int_a^b \left(\frac{1}{2}-\frac{1}{2}\right)\,\mathrm{d}x \\ &=0, \end{aligned}$$

QED.The demonstration for the other case $b \le a \le m$ follows by applying this result to the random variable $-Y$ and the values $-m\le-a\le-b$ (because $-m$ is a median of $-Y.$)