σ Probability & statistics

Mean, median and mode: which measure to use and when

Arithmetic mean, median, mode, trimmed, geometric and harmonic mean: how to compute them, how they react to extremes and which to choose case by case.

«The average salary in the company is 3,620 euros.» The sentence can be arithmetically correct and at the same time describe badly the reality of almost every employee. Measures of central tendency summarise a set of data with a single number, but each measure answers a different question. Choosing the wrong one is one of the simplest ways to convey a false impression without saying anything technically incorrect.

An example to start with

A small company has ten employees with these monthly salaries, in euros:

1,500, 1,600, 1,700, 1,800, 1,800, 1,800, 1,900, 2,000, 2,100, 20,000

The last value is the owner's. Let us compute the three classic measures.

  • Arithmetic mean: the sum is 36,200, divided by 10 gives 3,620 euros.
  • Median: with the values sorted, the two central ones are 1,800 and 1,800, so the median is 1,800 euros.
  • Mode: the most frequent value is 1,800 euros, which appears three times.

Nine people out of ten earn less than the mean. The median and the mode describe the typical salary much better.

The arithmetic mean

The mean is the sum of the values divided by how many there are. It has excellent mathematical properties: it uses all the data, combines easily across groups and is the point that minimises the sum of squared deviations. This is why it underlies almost all statistical methods.

Its weakness is its sensitivity to extreme values. A single anomalous data point is enough to shift it a great deal, as in the example. We say the mean is not robust.

The median

The median is the central value of the sorted data: half the values lie below, half above. With an even number of data points you take the mean of the two central ones. It is robust: if the owner's salary went from 20,000 to 200,000 euros, the median would stay at 1,800.

It is the right measure for skewed quantities such as incomes, house prices, response times and file sizes. Its limitation is that it ignores how far away the extreme values are: two distributions with the same median can have very different tails.

The mode

The mode is the most frequent value. It is the only measure of central tendency usable with qualitative data: the browser most used by visitors, the most common error code, the best-selling size. With continuous data it is of little use, because exactly equal values are rare; the modal class of a histogram is used instead. A distribution can have several modes, and this often signals that different groups are mixed together.

Less known but useful measures

The trimmed mean

A fixed percentage of values is removed at both ends, for example the lowest 10% and the highest 10%, and the mean of the rest is computed. It is a compromise between mean and median: it resists extremes but uses more information than the median alone.

The geometric mean

It is for quantities that multiply, such as growth rates. If a value rises by 10% and then falls by 10%, the arithmetic mean of the rates is 0%, but the final value is 1.1 · 0.9 = 0.99 times the initial one. The geometric mean of the factors, √0.99 ≈ 0.995, correctly indicates a loss of about 0.5% per period.

The harmonic mean

It is for averages of ratios such as speeds. If you travel a route at 60 km/h on the way out and, over the same distance, at 40 km/h on the way back, the average speed is not 50 km/h but 48 km/h, because you spend more time at the lower speed. The harmonic mean gives exactly this value.

How to choose

Situation Recommended measure
Symmetric data without outliers Arithmetic mean
Skewed data or data with extreme values Median
Qualitative data or categories Mode
Data with a few outliers to dampen Trimmed mean
Growth rates, returns Geometric mean
Speeds, ratios over fixed quantities Harmonic mean

A technical case: latencies

In web service monitoring the mean of response times is almost always misleading. A few extremely slow cases inflate it, and at the same time the mean hides how many users are really waiting. This is why percentiles are used: the median tells you what the typical request is like, the 95th or 99th percentile tells you how slow the worst experience suffered by a non-negligible share of users is. In my work I always prefer to show the median and high percentiles together, because they tell two different and complementary stories.

Honest communication

When presenting a summary figure:

  1. state which measure you are using, rather than writing just «on average»;
  2. if the data are skewed, show mean and median side by side;
  3. always include a measure of spread as well;
  4. if there are different groups, consider presenting them separately.

In short

  • Mean, median and mode answer different questions about the same set of data.
  • The mean is sensitive to extreme values; the median is robust.
  • The mode is the only measure of central tendency for qualitative data.
  • Geometric and harmonic means are for growth rates and ratios respectively.
  • For latencies and skewed data, median and high percentiles are worth more than the mean.
MM
Marco Marzaduri

Marco Marzaduri works in cybersecurity, digital forensics and web development. A computer science graduate, he combines rigorous technical analysis with attention to the people who use technology.

Read also