In my work, when individuals refer to the "mean" value of a data set, they're typically referring to the arithmetic mean (i.e. "average", or "expected value"). If I provided the geometric mean, people would likely think I'm being snide or non-helpful, as the definition of "mean" is known in advance.

I'm trying to determine if there are multiple definitions of the "median" of a data set. For example, one of the definitions provided by a colleague for finding the median of a data set with an even number of elements would be:

Algorithm 'A'

  • Divide the number of elements by two, round down.
  • That value is the index of the median.
  • i.e. For the following set, the median would be 5.
  • [4, 5, 6, 7]

This seems to make sense, though the rounding-down aspect seems a bit arbitrary.

Algorithm 'B'

In any case, another colleague has proposed a separate algorithm, which was in a stats textbook of his (need to get the name and author):

  • Divide the number of elements by 2, and keep a copy of the rounded-up and rounded-down integers. Name them n_lo and n_hi.
  • Take the arithmetic mean of the elements at n_lo and n_hi.
  • i.e. For the following set, the median would be (5+6)/2 = 5.5.
  • [4, 5, 6, 7]

This seems wrong though, as the median value, 5.5 in this case, isn't actually in the original data set. When we swapped out algorithm 'A' for 'B' in some test code, it broke horribly (as we expected).

Question

Is there a formal "name" for these two approaches to calculating the median of a data set? i.e. "lesser-of-the-two median" versus "average-the-middle-elements-and-make-new-data median"?

  • 16
    I have never seen algorithm "A" considered a median. It shouldn't be a problem that a descriptive statistic of the central tendency of data is not among the data themselves: after all, most means are not in the data, either. A more fundamental property we would like the median to have is that it does not change when the sequence of data is reversed, since ordering data from smallest to largest or largest to smallest is an arbitrary matter of taste. For this reason most authors define the median as in algorithm "B," because that is by far the simplest possible order-invariant procedure. – whuber Sep 18 at 16:15
  • 3
    @whuber Algorithm 'A' is sometimes called the low-median. There is also of course a corresponding High-median. Typically the median is the average of the two (which may or may not be one element from the set the median is computed over). – user603 Sep 18 at 17:24
  • 7
    A good time and place to repeat the comment that the two central values in an ordered sample with an even number of observations -- like 3 and 4 in 1, 2, 3, 4, 5, 6 -- are to be regarded as comedians (independently quipped by S.M. Stigler, R. Koenker, and no doubt others). – Nick Cox Sep 18 at 17:38
  • 3
    Aren’t both algorithms missing the crucial step of sorting the data? – Emil Sep 18 at 19:53
  • 2
    If you need your "median" to always be an element of the data set, you might actually be looking for a medoid. – Ilmari Karonen Sep 18 at 21:59
up vote 23 down vote accepted

TL;DR - I'm not aware of specific names being given to different estimators of sample medians. Methods to estimate sample statistics from some data are rather fussy and different resources give different definitions.

In Hogg, McKean and Craig's Introduction to Mathematical Statistics, the authors provide a definition of medians of random samples, but only in the case that there are an odd number of samples! The authors write

Certain functions of the order statistics are important statistics themselves... if $n$ is odd, $Y_{(n+1)/2}$ ... is called the median of the random sample.

The authors provide no guidance on what to do if you have an even number of samples. (Note that $Y_i$ is the $i$th smallest datum.)

But this seems unnecessarily restrictive; I would prefer to be able to define a median of a random sample for even or odd $n$. Moreover, I would like the median to be unique. Given these two requirements, I have to make some decisions about how to best find a unique sample median. Both Algorithm A and Algorithm B satisfy these requirements. Imposing additional requirements could eliminate either or both from consideration.

Algorithm B has the property that half the data fall above the value, and half the data fall below the value. In light of the definition of the median of a random variable, this seems nice.


Whether or not a particular estimator breaks unit tests is a property of the unit tests -- unit tests written against a specific estimator won't necessarily hold when you substitute another estimator. In the ideal case, the unit tests were chosen because they reflect the critical needs of your organization, not because of a doctrinaire argument over definitions.

  • 2
    (+1) We can add too that (1) When values come with weights then the definition of medians in principle and in practice must cover that too. (Implicitly in answers so far, all weights are equal, therefore immaterial.) While linear interpolation in the cumulative sum of weights is simplest, there are situations where other kinds of interpolation might make sense. (2) More rigorous definitions of median are usually intended to cover discrete and continuous and hybrid distributions alike, including those with spikes of probability somewhere. – Nick Cox Sep 18 at 17:43

What @Sycorax says.

As a matter of fact, there are surprisingly many definitions of general quantiles, so in particular also of medians. Hyndman & Fan (1996, The American Statistician) give an overview that is, AFAIK, still comprehensive. The different types do not have formal names. You may simply need to be clear on which type you are using. (It often does not make a big difference with data sets of realistic sizes.)

Note that it is commonly accepted to have a value that is not present in the data set as the median, e.g., 5.5 as a median for (4, 5, 6, 7). This is the default behavior for R:

> median(4:7)
[1] 5.5

R's median() by default uses type 7 of Hyndman & Fan's classification.

  • 4
    +1 for "It often does not make a big difference with data sets of realistic sizes." I'll steal that, instead of my usual "if it makes material a difference, you probably need more data." :) – Jason Sep 19 at 4:49
  • 1
    If you have a binary variable with values 0, 1 (say) and with about equally many 0s and 1s (mean close to 0.5) then large sample size will not necessarily stop the reported median flipping back and forth between 0, 0.5 and 1. Mosteller and Tukey (Data Analysis and Regression 1977) cite strongly bimodal and nearly symmetric distributions as cases where the median might not behave especially well. – Nick Cox Sep 20 at 8:31

In R's mad function, it uses the terms "lo-median" to describe your algorithm A, "hi-median" to describe rounding up instead, and just "median" to describe your algorithm B (which, as others have noted is by far the most common definition).

Curiously, there is no such option on R's median() function! (But R's quantile() has type for fine control.)

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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