I asked this at Math.StackExchange without any success (link):

What's the best way (or does it even make sense) to measure the instantaneous rate of change in the median of a collection of functions (where the median function at is defined at some $x$ as the point-wise median of the functional values at $x$)?

Set-up: I have a finite collection of continuous, differentiable real functions on an interval, $\{f_i(x)\}$. Since they are not nicely distributed (e.g. on a small subinterval some $f_j$ might be an extreme outlier), the point-wise median, $m(x) = \text{median}(\{f_i(x)\})$, is a better measure of the center than the average.

Question: How do you measure/compute/define the instantaneous rate of change in $m$?

Really, for some small interval around a given $x$, $m$ is just one of the $f_i$. But although this $f_i$ is in the center, how it's changing might be vastly different then how the bulk of functions are progressing. For instance, in general the collection of functions could be increasing (as evidenced in a plot or by general understanding of the contextual problem), but in the moment that $f_i(x)$ is central, $f'_i(x)$ could be negative. So does it make (more? any?) sense to define $m'(x) = \text{median}(\{f'_i(x)\})$?

Here's a similar but different situation where the answer is obvious: If you use the average instead of the median, then, since the average is just a linear combination of the functions, the derivative of the average is the average of the derivatives. So what's the analogous answer for the median? Also, whatever works for the median should also probably work for any percentile function since the median is just the 50-percentile.

  • $\begingroup$ You may as well ask what the derivative of the maximum operation is. max(x,y) in the x direction has derivative 0 or 1 depending on whether x is less than or greater than y, for example. The median (as a function of m real variables) has derivative 1 on a certain subset of R^m, and 0 elsewhere. For purposes of the chain rule, I think that is the best you are going to get. $\endgroup$ May 19 '14 at 15:38
  • $\begingroup$ In other words, the derivative of the median is the derivative of the median: at a value x, the derivative is f_i'(x), where i is that index of the m indices that gives the middle value at x (for m odd, and a similar statement for m even, assuming enough distinct values; trouble ensues when you have several i from which to choose). $\endgroup$ May 19 '14 at 15:48

At a point $x$ where there is exactly one function $f_i$ such that $f_i(x)$ is the median, the derivative of the median is indeed the derivative of $f_i$ (this is not the median of the derivatives). At a point where there are more than one functions equal to the median, the derivative of the median exists only if the derivatives of these functions are equal at that point. Otherwise, the derivative of the median does not exist at that point.

In particular, the median function is in general at best Lipschitz.


The answer may be clear from an application: the median justice on the Supreme Court. See here.

enter image description here

In this case there are nine $f_i$'s, for the nine seats on the Supreme Court, each in a different color. Each $f_i$ represents a score of the Justice's ideology, which may or may not be differentiable at any time.

The median ideology is shown with yellow highlighter. At any time $t$, let

  • $O$ be the old median justice, the $i$ with $f_i$ in the median just before $t$
  • $N$ be the new median justice, $i$ with $f_i$ in the median just after $t$

Then there are four possibilities, from most to least common:

  • $\exists m'$ and $O=N$, with $m'=f_O'(t)$. (E.g. the usual situation, whenever the same justice stays in the median, and that justice's score is differentiable.)

  • $\nexists m'$ and $O=N$, with $\nexists f_O'(t)$. (E.g. at $t=2010$, $O=N=Kennedy$, but Kennedy stopped his conservative trend so abruptly that $f_O'(t)$ does not exist.)

  • $\nexists m'$ and $O\neq N$. (E.g. at $t=2005$, $O=O'Connor$, $N=Kennedy$, and this shifted the median ideology abruptly with $f_O(2005^-)\neq f_N(2005^+)$.)

  • $\exists m'$ and $O\neq N$. (E.g. at $t=1975$, $O=White$, $N=Stewart$, and the median trajectory remained differentiable with $f_O(1975^-)=f_N(1975^+)$, $f_O'(1975^-)=f_N'(1975^+)$ even though the individual justices had non-differentiable paths there.)

Note I am taking each $f_i$ to be an a.e. continuous function, defined at all times, as depicted in the graph. The underlying data is discrete, but I think this is a useful abstraction of the Justice's voting patterns.


There are probably no good answer to your question, apart from what you already said, with the addition of Deane Yang's answer. Moreover, it is easy to design examples where the derivative of the median exists, but is at each point very large in absolute value while the median is almost constant. So, let me suggest you to change your point of view.

Since the use of the median is to compensate for outliers, you might be interested in non-linear averages. Classical examples include geometric mean, harmonic mean, root mean square. Some of them minimize the effect of outliers (in this respect, square mean root could be a good choice).

Another possibility is to use a weighted mean, where the $i$-th weight depends on the rank of $f_i(x)$ among the values at $x$. Taking high weights on the center, you interpolate between the arithmetic mean and the median.

Last, you could take the median and then regularize by convolution, if what you are really interested in is the short- or mid-term rate of change, rather than the truly instantaneous rate of change.

Using any of these methods, you will easily get a smooth quantity. But the choice of the method should really be driven by the specifics of your problem.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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