Characterise the minimizer of a function that includes the expectation Let $X \in L^1.$ I need to characterize the minimizer of the function: $$ d(x) = \mathbb{E} [|X-x|], \,\, x\in \mathbb{R}.$$ Let m be the minimizer we are looking for. Then for $x\leq m$ (and eventually for $x \geq m$) , I want to show the following,$\,\,d(m) -d(x)\leq 
 (m-x) (\mathbb{P} (X< m) -\mathbb{P} (X \geq m))  $ :  $$d(m) -d(x) = \mathbb{E} [|X-m|] - \mathbb{E} [|X-x|] \leq \int_{\mathbb{R}} X^{+} + X^{-} + |m|\,\,\, d \mathbb{P} \,\,- \int_{\mathbb{R}} X^{+} + X^{-} + |x|\,\,\, d \mathbb{P} = (|m|-|x|) \int_{\mathbb{R}} \,\,\, d \mathbb{P}.$$
Since $m$ is a minimizer, $d(m)-d(x)\leq 0.\,\,$ I am not sure how I can go from here.
Can somebody provide some support or a solution proposal ? Thanks.
 A: Let $\phi(x) = \int |x-X| dP =  \int g_X(x) dP$. Note that $\phi$ is defined everywhere, convex and $\phi(x) \to \infty$ as $|x| \to \infty$. In particular,
$\phi$ has a minimiser.
Write $[X \le x]$ for $\{ \omega | X(\omega) \le x \}$, etc. For a function $\phi$ denote the one sided directional derivative at $x$ in the direction $h$ as $d \phi(x;h)$.
Fix some $\alpha$ and let $g_\alpha(x) = |x-\alpha|$.
Note that
$d g_\alpha (x;+1) = \begin{cases}
+1, & x \ge \alpha\\
-1, & \text{otherwise}
\end{cases}$, and
$d g_\alpha (x;-1) = \begin{cases}
+1, & x \le \alpha\\
-1, & \text{otherwise}
\end{cases}$.
Note that the directional derivative of $g_\alpha$ is defined everywhere.
Let $l=P[X<x], e=P[X=x], g=P[X>x]$.
An application of the dominated convergence theorem shows that with $h =\pm 1$ we have
$d \phi(x; h) = \int dg_X(x;h) dP$ from which we get
$d \phi(x; +1) = l+e-g$, $d \phi(x; -1) = g+e-l$.
Since $\phi$ is convex, we have $x^*$ is a minimiser iff $d \phi(x^*,+1) \ge 0$ and $d \phi(x^*,-1) \ge 0$.
Hence $x$ is a minimiser of $\phi$ iff $l+e \ge g$ and $g+e \ge l$. Combining with $l+e+g = 1$ this gives $l+e \ge {1 \over 2}$, $g+e \ge {1 \over 2}$.
Now suppose $l+e \ge {1 \over 2}$, $g+e \ge {1 \over 2}$, then from $l+e+g = 1$ we get ${1 \over 2} \ge g$ and ${1 \over 2} \ge l$ and so $l+e \ge g$ and $g+e \ge l$.
In particular, we see that $x$ is a minimiser iff
$P[X \le x] \ge {1 \over 2}$ and $P[X \ge x] \ge {1 \over 2}$.
This is the definition of the median (see https://en.wikipedia.org/wiki/Median#Probability_distributions).
A: $\newcommand{\sgn}{\operatorname{sgn}}$
Note that
$$
|x-c|=\int_c^x\sgn(x-t)\,\mathrm{d}t\tag1
$$
Thus, for $b\gt a$,
$$
\begin{align}
&\int_{-\infty}^\infty|x-b|\,\mathrm{d}\mu(x)-\int_{-\infty}^\infty|x-a|\,\mathrm{d}\mu(x)\tag{2a}\\
&=\int_{-\infty}^\infty\int_b^x\sgn(x-t)\,\mathrm{d}t\,\mathrm{d}\mu(x)-\int_{-\infty}^\infty\int_a^x\sgn(x-t)\,\mathrm{d}t\,\mathrm{d}\mu(x)\tag{2b}\\
&=-\int_{-\infty}^\infty\int_a^b\sgn(x-t)\,\mathrm{d}t\,\mathrm{d}\mu(x)\tag{2c}\\
&=-\int_a^b\int_{-\infty}^\infty\sgn(x-t)\,\mathrm{d}\mu(x)\,\mathrm{d}t\tag{2d}\\
&=\int_a^b(\mu(-\infty,t)+\mu(-\infty,t]-1)\,\mathrm{d}t\tag{2e}
\end{align}
$$
Explanation:
$\text{(2b)}$: integrate $(1)$ against $\mathrm{d}\mu$
$\text{(2c)}$: $\int_b^xf(t)\,\mathrm{d}t-\int_a^xf(t)\,\mathrm{d}t=-\int_a^bf(t)\,\mathrm{d}t$
$\text{(2d)}$: Fubini's Theorem
$\text{(2e)}$: $\sgn(x-t)=1-[x\le t]-[x\lt t]\qquad$ (Iverson brackets)
Therefore, if $\mu(-\infty,b)+\mu(-\infty,b]\le1$, then
$$
\int_{-\infty}^\infty|x-b|\,\mathrm{d}\mu(x)-\int_{-\infty}^\infty|x-a|\,\mathrm{d}\mu(x)\le0\tag{3a}
$$
That is, $\int_{-\infty}^\infty|x-c|\,\mathrm{d}\mu(x)$ is decreasing when $\mu(-\infty,c)+\mu(-\infty,c]\le1$.
Furthermore, if $\mu(-\infty,a)+\mu(-\infty,a]\ge1$, then
$$
\int_{-\infty}^\infty|x-b|\,\mathrm{d}\mu(x)-\int_{-\infty}^\infty|x-a|\,\mathrm{d}\mu(x)\ge0\tag{3b}
$$
That is, $\int_{-\infty}^\infty|x-c|\,\mathrm{d}\mu(x)$ is increasing when $\mu(-\infty,c)+\mu(-\infty,c]\ge1$.
Thus, $\int_{-\infty}^\infty|x-c|\,\mathrm{d}\mu(x)$ is minimized when $\mu(-\infty,c)\le\frac12\le\mu(-\infty,c]$.
