Let $X\sim f_X$, where $f_X$ is the probability density function of $X$. Let $g: \mathbb{R} \to \mathbb{R}$ a strictly monotonic (decreasing or increasing) mapping. I aim to prove or disprove:

$$ g[\mathrm{median} (X)] = \mathrm{median}[g(X)] $$


Let $x_0 = \mathrm{median} (X)$, $Y=g(X)$, $y_0 = g(x_0)$. Then, we want to show:

$$ 0.5 = \int_{-\infty}^{y_0} f_Y (y) dy $$

WLOG, assume $g$: increasing. By change of variables, $f_Y(y) = f_X(x)/g'(x)$ and $dy=dx g'(x)$. Thus,

$$ \begin{align} \int_{-\infty}^{y_0} f_Y (y) dy &= \int_{-\infty}^{y_0} f_X(x) dx \\ &\neq \int_{-\infty}^{x_0} f_X(x) dx = 0.5 \end{align} $$

So, if $f_X>0$ a.s., then the above statement holds only if $g(x_0) = x_0$. However, take an example of log-normal distribution, where $X\sim N(\mu, \sigma^2)$ and $g(x)=\exp(x)$. There is no real solution to $g(x_0) = x_0$, and $f_X >0$ a.s. But it is still true that $\mathrm{median}[g(X)] = g(\mu)$.

So my disproof is invalid? Any suggestions are welcome.

  • 2
    $\begingroup$ Related Math.SE post. $\endgroup$ Commented Jan 20, 2023 at 19:36
  • 7
    $\begingroup$ You don't need a density: you only need that the median be uniquely defined. The transformation is merely an order-preserving (or order-reversing) relabeling of the values and, since the median is defined solely in terms of relative order, you're done. $\endgroup$
    – whuber
    Commented Jan 20, 2023 at 19:59

4 Answers 4


The conjecture is true and your disproof is flawed. The flaw in your steps occurs when you make a change-of-variables in the initial step but do not change the range of integration accordingly. While it is not the simplest method of proof (see here for a simpler approach using the CDF), you could construct a proof of this result using the density functions along the lines you are trying. If $g$ is strictly increasing and differentiable you have $g'(x) \geqslant 0$ for all $x \in\mathbb{R}$, which then gives:

$$\begin{align} \int \limits_{-\infty}^{y_0} f_Y(y) \ dy &= \int \limits_{-\infty}^{g(x_0)} f_Y(y) \ dy \\[6pt] &= \int \limits_{-\infty}^{x_0} f_Y(g(x)) \cdot \frac{dy}{dx} \ dx \\[6pt] &= \int \limits_{-\infty}^{x_0} f_Y(g(x)) \cdot g'(x) \ dx \\[6pt] &= \int \limits_{-\infty}^{x_0} f_X(x) \ dx \\[12pt] &= \frac{1}{2}. \\[6pt] \end{align}$$

When proving this result, I would also recommend you tighten up your assertion that you can use increasing $g$ without a loss of generality. You need to make it clear why the decreasing case is analogous to the increasing case. This is related to the formula for transformation of random variables for monotonic transformations.

  • 6
    $\begingroup$ +1. The decreasing case is most simply handled by composing it with negation relative to the median, reducing it to the increasing case. $\endgroup$
    – whuber
    Commented Jan 20, 2023 at 20:00
  • 3
    $\begingroup$ Indeed. But you would want to state that in the proof rather than just saying "without loss of generality" for the increasing case. $\endgroup$
    – Ben
    Commented Jan 20, 2023 at 20:03
  • 3
    $\begingroup$ I see your point. $\endgroup$
    – whuber
    Commented Jan 20, 2023 at 20:05

Here is a generalization. It is intended to reveal which properties of probability are involved in the result. It turns out that density functions are irrelevant.

Any number $\mu$ determines two events relative to the random variable $X$: $\mathscr E^-_\mu(X): X \le \mu$ and $\mathscr E^+_\mu: X \ge \mu.$

Any (strictly) monotonic transformation $g$ either preserves these events or reverses them, in the sense that the two sets $g(E^{\pm}_\mu(X))$ are the two sets $E^{\pm}_{g(\mu)}(g(X)).$ This follows immediately from the definition of (strict) monotonicity as preserving equality and either preserving or reversing strict inequality.

When $0\lt q \lt 1$ is a probability, it defines a nonempty set of numbers -- any one of which can be called the $q^{\text{th}}$ quantile of $X$ -- consisting of all $\mu_q$ for which $\Pr(E^-_{\mu_q}(X)) \ge q$ and $\Pr(E^+_{\mu_q}(X)) \ge 1-q.$

(Proof: start with a very large number $\alpha$ and decrease it as long as $\Pr(E^-_{\alpha}(X)) \ge q$. Start with a very small number $\beta$ and increase it as long as $\Pr(E^+_{\beta}(X))\ge 1-q.$ If $\alpha \gt \beta,$ there exists $\gamma$ strictly between $\alpha$ and $\beta$ that, by construction, satisfies $\Pr(E^-_{\gamma}(X)) \lt q$ (because $\gamma \lt \alpha$) and $\Pr(E^+_{\gamma}(X)) \lt 1-q$ (because $\gamma \gt \beta$). But then

$$1 = \Pr(\mathbb R) = \Pr(E^-_{\gamma}(X)\cup E^+_{\gamma}(X)) \lt \Pr(E^-_{\gamma}(X)) + \Pr(E^+_{\gamma}(X)) \lt q + 1-q = 1,$$

a contradiction. Notice how this constructive demonstration relies only on two simple probability axioms and a basic property of real numbers.)

The $q$ quantiles of $X$ are defined to be the interval $[\alpha,\beta],$ which we have seen is nonempty. As a matter of temporary notation, denote such a set by $X[q].$

Putting these two observations together, we conclude that

any strictly monotonically increasing transformation $g$ maps quantiles to quantiles (that is, $g(X[q]) \subseteq g(X)[q]$ for all $q\in(0,1)$) while a strictly monotonically decreasing transformation maps the $q$ quantiles into the $1-q$ quantiles (that is, $g(X[q])\subseteq g(X)[1-q]$).

(As @Ilmari Karonen kindly points out in comments, $g$ is guaranteed to preserve quantiles when it is continuous, for then it will have an inverse that maps quantiles back into quantiles.)

Applying this to the case $q=1/2=1-q$ shows that $g$ preserves medians as sets. When the median is unique (a singleton set), the median of $g(X)$ therefore is $g$ applied to the median of $X.$

You may wish to show that when $X$ has a density function defined in a neighborhood of its $q$ quantile and is not identically zero in any such neighborhood, it has a unique $q$ quantile: that is, $X[q]$ is a singleton.

  • 2
    $\begingroup$ +1. It is worth noting that even for weakly monotonic functions, a median is mapped to a median, though it might be possible that a non-median is also mapped to a median. $\endgroup$
    – Henry
    Commented Jan 21, 2023 at 17:56
  • $\begingroup$ I would have thought on your final point of a unique quantile of a distribution with a density function, this might require the density to be positive in the neighbourhood of the quantile $\endgroup$
    – Henry
    Commented Jan 21, 2023 at 17:58
  • $\begingroup$ @Henry Exactly right, thank you! $\endgroup$
    – whuber
    Commented Jan 21, 2023 at 19:00
  • 1
    $\begingroup$ I think for $g(X[q]) = g(X)[q]$ you need $g$ to be continuous. If it's not, you might have $g(X[q]) \subsetneq g(X)[q]$. $\endgroup$ Commented Jan 22, 2023 at 9:35
  • 1
    $\begingroup$ @whuber: $X \sim \mathcal N(0,1)$, $q = \frac12$, $g(x) = \begin{cases} x & \text{if } x ≤ 0 \\ x+1 & \text{if } x > 0 \end{cases}$ $\implies g(X[q]) = g(\{0\}) = \{0\} \ne g(X)[q] = [0,1]$ $\endgroup$ Commented Jan 22, 2023 at 15:29

By definition, $m$ is a median of the random variable $X$ if and only if $$\mathrm{Pr}[X ≤ m] ≥ \tfrac12 \text{ and } \mathrm{Pr}[X ≥ m] ≥ \tfrac12.$$

(Note that, in general, $X$ may have multiple medians if there is an interval of values satisfying the definition, and that it's possible for either or both probabilities to be strictly greater than $\tfrac12$ if $\mathrm{Pr}[X = m] > 0$.)

Also by definition, a function $g: \mathbb R \to \mathbb R$ is monotone increasing if and only if $$a ≤ b \implies g(a) ≤ g(b)$$ for all $a,b \in \mathbb R$.

(A function $g$ is called strictly monotone increasing if $a < b \implies g(a) < g(b)$, but we don't actually need this stronger property here.)

Now, let $m$ be a median of $X$ and let $g$ be monotone increasing. Then $X ≤ m \implies g(X) ≤ g(m)$ (and $X ≥ m \implies g(X) ≥ g(m)$), and thus $$\begin{aligned} \mathrm{Pr}[g(X) ≤ g(m)] ≥ \mathrm{Pr}[X ≤ m] &≥ \tfrac12 \text{ and } \\ \mathrm{Pr}[g(X) ≥ g(m)] ≥ \mathrm{Pr}[X ≥ m] &≥ \tfrac12. \end{aligned}$$

In other words, if $m$ is a median of $X$ and $g$ is monotone increasing, then $g(m)$ is a median of $g(X)$.

Ps. Note that the result above holds for any real-valued random variable $X$ and any monotone increasing function $g$, even if the medians of $X$ and/or $g(X)$ are not uniquely defined.

However, it only guarantees that $g(m)$ is some median of $g(X)$, but not that any particular rule for picking a "canonical" median $m$ for $X$ — such always taking the low end, high end or the midpoint of the interval of possible medians — will necessarily yield $g(m)$ when applied to the distribution of $g(X)$.

Also, if the function $g$ is discontinuous, $g(X)$ may have multiple medians even if $X$ does not, while if $g$ is not strictly increasing, $X$ may have multiple medians even if $g(X)$ does not. And if $g$ is not strictly increasing, then it's also possible for $g(m)$ to be a median of $g(X)$ even if $m$ is not a median of $X$.

In particular, even if we define $\operatorname{median}[X]$ to be the set of all medians of $X$, the most we can say in general is that $g(\operatorname{median}[X]) \subseteq \operatorname{median}[g(X)]$.

Pps. The result above can also be straightforwardly generalized to arbitrary quantiles by defining $m$ to be a $p$-quantile of $X$ (for some $p \in [0,1]$) if and only if $$\mathrm{Pr}[X ≤ m] ≥ p \text{ and } \mathrm{Pr}[X ≥ m] ≥ 1-p$$ and using essentially the same proof to show that, if $g$ is monotone increasing, then $g(m)$ is a $p$-quantile of $g(X)$.

  • $\begingroup$ Your definition of median is incorrect. For instance, the unique median of a Bernoulli$(p)$ variable $X$ with $0\lt p\lt 1/2$ is $0,$ but $\Pr(X\lt 0) = 0\ne p=\Pr(0\lt X).$ $\endgroup$
    – whuber
    Commented Jan 21, 2023 at 16:14
  • 2
    $\begingroup$ @whuber: You're right. I actually realized that myself when I was getting to sleep last night, but chose not to get up and correct the answer immediately. :D It's fixed now (and also strengthened a bit). $\endgroup$ Commented Jan 22, 2023 at 9:33

The claim is obviously true for a discrete variable (i.e. we consider a probability distribution over a finite number of events): given a set $A$, the median is a number $a_0$ such that $\sum_{\{a: a \leq a_0\}}p(a)=\sum_{\{a: a \geq a_0\}}p(a)$. Clearly, $\sum_{\{g(a): g(a)\leq g(a_0)\}}p(g(a))=\sum_{\{a: a\leq a_0\}}p(a)$, and $\sum_{\{g(a): g(a) \geq g(a_0)\}}p(g(a))=\sum_{\{a: a \geq a_0\}}p(a)$, so $\sum_{\{g(a): g(a)\leq g(a_0)\}}p(g(a))= \sum_{\{g(a): g(a) \geq g(a_0)\}}p(g(a))$

We can then extend it to the continuous case by taking Reimann sums: partition the domain into a finite number of intervals, find the probability density of the interval, and multiply by the size of the interval. Then we let the lengths of the intervals go to zero.

When we transform an interval by $g$, we multiply the length of the interval by $g'$, and divide the probability density by $g'$, so the total probability mass is unchanged. This is a bit handwavy, since we need to take this "in the limit" for $g'$ to be constant over the interval, but the basic concept should be reasonably intuitive. The error in your logic is that you essentially only changed the probability density, and ignored that since each interval will be scaled, the overall domain is also scaled.

  • $\begingroup$ We must also have that $g$ is invertible, or the median of $X$ be unique. For example let $X$ be a Bernoulli distribution with $p = 0.5$ and let $$g(x) = \begin{cases}x &\quad {x\leq 0.5} \\ x+1 &\quad {x>0.5} \end{cases}$$ Then $\{0,1\}$ are medians of $X$ and $\{0,1,2\}$ are medians of $g(X)$. But we have $$g(\{0,1\}) \neq \{g(0),g(1),g(2)\}$$ $\endgroup$ Commented Jan 23, 2023 at 6:55
  • $\begingroup$ @SextusEmpiricus The question specifies strictly monotonic. Your example is nonstrictly monotonic. $\endgroup$ Commented Jan 25, 2023 at 4:48
  • $\begingroup$ It is only the function $g^{-1}$ that is nonstrictly monotonic (and that is indeed the trick of the example). However, the function $g$ is strictly monotonic. $\endgroup$ Commented Jan 25, 2023 at 6:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.