To summarize a set of data with one number, should we choose the median or the mean? The answer depends on how the error between this number and each observation is calculated. Suppose five waiting times are 1, 2, 3, 4, and 100 minutes; this is a constructed set of illustrative data. Their median is 3 minutes and their mean is 22 minutes. To make the mean absolute error as small as possible, choose 3; to make the mean squared error as small as possible, choose 22. [1]
One set of numbers, two ways of scoring
First choose a single number a and use it to stand for each of the five waiting times. Each wait is one observation, and the five carry equal weight in the calculation. The absolute error for one wait is the absolute value of the difference between the observation and a; the squared error is the square of that difference. Add up the five errors of each kind and divide by 5 to get two average scores:
Mean absolute error: A(a) = (|1−a| + |2−a| + |3−a| + |4−a| + |100−a|) / 5
Mean squared error: S(a) = ((1−a)² + (2−a)² + (3−a)² + (4−a)² + (100−a)²) / 5
The unit of A is minutes and the unit of S is square minutes. They measure different losses, so one cannot say which error is smaller just by looking at the size of the numbers; what should be compared is the scores of different candidate values within the same column.
| Single number a | Mean absolute error A(a) | Mean squared error S(a) |
|---|---|---|
| 3 minutes, the median | 20.2 minutes | 1883 square minutes |
| 22 minutes, the mean | 31.2 minutes | 1522 square minutes |
For example, with 3 chosen, the five absolute errors are, in order, 2, 1, 0, 1, and 97 minutes, which sum to 101 and average 20.2 minutes; squared, they sum to 9415 and average 1883 square minutes. With 22 chosen, the five absolute errors are 21, 20, 19, 18, and 78 minutes, which sum to 156; squared, they sum to 7610. In the table, 3 wins in the absolute error column and 22 wins in the squared error column. Comparing these two numbers is not enough: the next step is to see why no other candidate number can do better either.

Figure 1 | Mean absolute error and mean squared error for the same constructed dataset (1, 2, 3, 4, 100): the two losses are smallest at the median 3 and the mean 22 respectively. The two panels have different vertical axes, so the heights of the curves cannot be compared directly.
Absolute error: count the numbers on each side
Think of a as a point that can move along the number line. Between 2 and 3, there are two numbers to the left of a: 1 and 2; and three numbers to the right: 3, 4, and 100. Move a small distance δ to the right without crossing 3, and the distance from a to each of the two numbers on the left increases by δ, while the distance to each of the three numbers on the right decreases by δ. The sum of the five absolute errors therefore changes by 2δ−3δ, that is, it falls by δ; the mean absolute error falls by δ/5.
Now look between 3 and 4: there are three numbers to the left of a and two to the right. Move a small distance to the right without crossing 4, and the sum of absolute errors increases by 3δ−2δ, that is, it rises by δ. The direction has reversed: moving right from the left of 3, the error is falling; moving further right past 3, the error starts to rise.
Divide the path of movement into segments at the data points, and this reasoning extends to all candidate values: in every segment to the left of 3, there are more numbers on the right; in every segment to the right of 3, there are more numbers on the left. So 3 is the global minimum point of the mean absolute error for this dataset. What matters here is how many numbers lie on each side of the position, not how far 100 is from 3. [1]
That the median is optimal does not mean the optimal solution for absolute error is always unique. Remove the 100 from the illustrative data, leaving the four numbers 1, 2, 3, and 4: whether a is 2, 2.5, or 3, or indeed any number between 2 and 3, the average of the four absolute errors is 1. Within this interval, moving to the right increases the distances for the two terms on the left by exactly as much as it decreases them for the two terms on the right. By the common single-value definition, the median of four numbers is the average of the middle two, namely 2.5; but the whole interval minimizes the mean absolute error. [1]
This line of reasoning also has a population version: for a continuous distribution, when the expected absolute error is finite, a population median likewise minimizes the expected absolute error. [2]
Squared error: the further from the mean, the larger the extra loss
The mean of the five illustrative numbers is (1 + 2 + 3 + 4 + 100) / 5 = 22. Adding up the difference between each number and 22 gives −21 − 20 − 19 − 18 + 78 = 0. It is precisely this property of summing to zero that lets the mean squared error of any candidate value a be split into two parts:
S(a) = S(22) + (a−22)² = 1522 + (a−22)²
The first part, 1522, is the mean squared error when the mean is chosen; the second part is the square of the distance of a from the mean. The second part cannot be negative and equals zero only when a = 22, so 22 is the unique optimal value. Substituting 3 gives 1522 + (3−22)² = 1883, exactly the result in the table.
For any finite set of data, the same decomposition can be made using that set's mean: the deviations of the data from the mean sum to zero, and what remains is a non-negative squared distance. So for one set of equally weighted data, the mean uniquely minimizes the mean squared error. Correspondingly, for a population with a finite second moment, its expected value gives the expected squared error its unique minimum. [3]
Why large errors pull harder on the mean
In the same example, with 3 chosen, 100 differs from the representative value by 97 and 1 differs from it by 2. The absolute errors are 97 and 2; the squared errors are 9409 and 4. Squaring gives larger deviations a heavier share of the total score, so moving the representative value toward 100 can bring a considerable fall in squared error.
Look specifically at the change from 3 to 22: the squared error of the 100 term falls from 9409 to 6084, a decrease of 3325; the squared errors of the first four terms increase by 1520 in total. Netting the two, the total squared error still falls by 1805, which divided by 5 is a decrease of exactly 361. The mean attains the minimum squared error through this trade-off; the median, under absolute error, balances the numbers of observations on the two sides.
Change the 100 in the illustrative data to 10, so that the data become 1, 2, 3, 4, and 10: the median is still 3, but the mean changes from 22 to 4. This shows how a change in one and the same large value affects the two kinds of central location for this dataset.
So which number to choose depends on first asking what the evaluation rule is: if every additional minute of deviation adds to the loss by the same amount, look at the mean absolute error and choose the median; if the larger the deviation, the greater the loss brought by each additional minute, look at the mean squared error and choose the mean. When the two happen to be equal, one and the same number can be the optimal solution under both rules. [1]
References
-
University of Michigan EECS 398-003 course staff (lectures by Suraj Rampure). Lecture 14: Introduction to Modeling. 2024-10-17 (lecture date).
-
Salvador Balkus. The median minimizes the mean absolute error. 2024-09-23.
-
Salvador Balkus. The expected value minimizes the mean squared error. 2024-09-13.
-
Research Methods · Rituals can be imitated; understanding cannot be faked
-
Compiled and published by the Scholay one-stop academic platform. If anything here infringes your rights, please let us know and it will be taken down.
-
Also published on EnterScholar, a community for scholars in the age of intelligence