## A mathematical view on the notion of “median”

These days we hear about medians of all kinds of things: household income, lifetime of items such as lightbulbs, and so on. It’s time to get a rigorous grip on the concept.

Definition. Suppose $X\neq \emptyset$ is a set, $(C, \leq)$ a totally ordered set, and $f: X \to C$ a function. Then $m\in C$ is said to be a median of $f$ if the sets $\{x \in X : f(x) \leq m\}$ and  $\{x \in X : f(x) \geq m\}$ have equal size.

It is a reflex of mathematicians to ask about existence and uniqueness of any concept they stumble upon. (Note that I wrote “a median” and not “the median” above.) Indeed, as much as the definition above seems to make sense: Even for simple example, the median needs not exist. Let $X = \{1,2,3\}$ and let $f:X\to \mathbb{R}$ be defined by $f(1) = f(2) = 0$ and $f(3) = 1$. Then $f$ has no median according to the definition above. On the other hand, if $X = \{1,2\}$ and $f:X\to \mathbb{R}$ is the inclusion map, then every element of the open interval $]1,2[$ is a median!

There are many common fixes to the problems of existence and uniqueness, but no definition is really elegant. (Most resort to listing the elements in ascending order and to pick the arithmetical middle of the “middle elements” in the list or something similar.)

Other difficulties arise when we want to pick medians of infinite sample sets. Let $(C,\leq)$ be a totally ordered set. We say that $m\in C$ is a median of $C$ if the sets $\{c \in C : c \leq m\}$ and  $\{c \in C : c \geq m\}$ have equal cardinality. Note that in $\mathbb{R}$ every element is a median, but $\mathbb{N}$ has no median at all!