Nine response times sit on a line. Drag the slowest one far out, and watch the mean and the median.
One far point moves the average
Nine response times in milliseconds; the ninth one moves.
Nine response times in ms. The mean, 16.78, and the median, 16, sit close together.
Predict first. Drag the ninth value far to the right. What does the median do?
Describe this picture
Nine response times in milliseconds as dots on a line from 0 to 125: 12, 14, 15, 15, 16, 18, 19 and 21, the two 15s stacked, and a ninth value that can move. A triangle above the line marks the mean and one below marks the median, each labelled, and a box plot sits beneath, with a dotted line at its upper fence. Before the clip, a question asks what the median will do when the ninth value is dragged far to the right: “stays where it is”, “follows the mean” or “jumps”; a tap picks an answer and starts the clip. In the clip the ninth value slides from 21 out to 95 over 5 seconds. The mean runs from 16.78 to 25, while the median stays at 16. At 95 the box plot rings the point as an outlier, beyond the upper fence at 25, and your guess is drawn as a dotted triangle. Readouts give the ninth value, the mean and the median. After the clip a slider, “Ninth value, ms”, runs from 21 to 120: the mean moves with it the whole way; the median stays at 16.
A sample and its summaries
The nine times are a sample: a few measurements taken from something much larger, here every request the server will ever answer. That larger whole is the population. A number computed from the sample, such as its average, is a statistic. It describes these nine values; the population’s own average is a different number, which the sample can only estimate.
I write the sample values , here . Sorted from smallest to largest they are , with the index in brackets.
Two centres
The sample mean is the plain average,
The median is the middle value once the data are sorted: of nine values. With an even number of values it is halfway between the two middle ones.
Before the clip you guessed what the median would do. It stayed at 16. As the ninth value ran out to 95, the mean followed it from 16.78 to 25, because every millisecond added to one value adds ms to the mean. The median only asks which value is in the middle, and the middle value never changed.
After the clip, drag the ninth value yourself. The slider starts at 21, already above the median, and runs right to 120. Dragging right, the mean climbs from 16.78 to 27.78, while the median stays at 16 the whole way. Only a ninth value below 16, which the slider does not reach, could move the median.
At 95, the mean of 25 is larger than eight of the nine values. It is not a typical response time at all.
Watch out
The average is not always the typical value. One far point can drag it outside the bulk of the data, while the median barely notices. A summary that a few wild values cannot drag far is called robust.
Spread: three ways
The sample standard deviation. As in Variance and standard deviation, spread is measured by squared distances from the centre, but for a sample the sum is divided by , not :
Why is the subject of Estimators: bias and variance, which settles it with an exact count. Here the letter is the sample standard deviation; signal processing pages use for something else.
Quartiles and the IQR. The quartiles and cut off the lowest quarter and the highest quarter of the sorted data. Different programs place them slightly differently; I use NumPy’s default: the value a fraction of the way along is at position , counting the sorted values from 0, with a straight line between neighbours. The interquartile range, , is the width of the middle half.
The MAD. The median absolute deviation is the median of the distances from the median. Multiplied by 1.4826 it matches the standard deviation for bell-shaped data, but it ignores a few wild values.
The box plot
A box plot draws these summaries on one line. The box runs from to with a line at the median. Two fences sit beyond the box, at and . Whiskers reach out to the furthest data inside the fences, and any point beyond a fence is drawn on its own as an outlier.
The shape: histograms and smooth curves
A summary is only as good as the shape behind it, so look at the shape first. Here are 200 waiting times of the lopsided kind in Continuous random variables.
One width for bars and curve
200 waiting times with mean 1, made by a computer (seed 6100).
0 waiting times fall into bins 0.3 wide.
Describe this picture
A histogram of 200 seeded draws (seed 6100) from the exponential waiting time with mean 1, on an axis from 0 to 5, bars 0.3 wide; the draws pour in, then a smooth curve is drawn over them: a kernel estimate, the average of small bells with the same width, 0.3. Dashed markers show the sample mean, 1.04, and median, 0.66. Readouts give the width, the mean and the median. After the clip one slider, “Bin width and smoothing width”, sets both widths together, from 0.05 to 1 in steps of 0.05. At the narrow end the histogram and the curve are jagged; at the wide end the shape is smeared flat.
The smooth curve is a kernel density estimate: put a small bell on every data point and add them up, scaled so the area is 1. The width of each bell plays the part of the bin width. Too narrow and every point shows as its own spike; too wide and the shape disappears. A common rule of thumb, Silverman’s, gives a width of about 0.26 for 200 values of this shape.
The long right tail shows in the summaries too: the mean sits above the median. For this waiting-time law the exact values are 1 and . The 200 draws in the picture give 1.0435 and 0.6634.
Worked example
1. The nine times, with the outlier. The values add to 225, so . The median is 16. By NumPy’s rule and , so and the fences are and : the value 95 is an outlier. The squared deviations from 25 add to 5572, so and ms.
2. The eight times, without it. The values add to 130, so , and the median is . The quartiles are and . The squared deviations add to , so and ms.
One point multiplied the standard deviation by about nine: .
3. The MAD of the nine. The distances from the median 16, sorted, are , and their median is 2. Scaled, ms: close to the clean eight’s , as if the outlier were not there.
4. Why the divisor matters. Two values, 10 and 14, have mean 12 and squared deviations adding to 8. Dividing by gives 4; dividing by gives 8. Estimators: bias and variance shows which is right on average.
5. A median filter. A sensor reports 4, 50, 5, where 50 is a glitch. The mean of the three is ; the median is 5. Replacing each sample by the median of its neighbours removes such spikes.
Try it yourself. The median of is 5, halfway between 3 and 7. The values have mean and median . Adding 10 to every value moves the mean and median by 10 and leaves unchanged.
Where you’ll meet this
Response times. Engineers often report the median and the 95th percentile of response times, not the mean: a few very slow requests would drag the mean and hide what most users see.
Incomes and prices. Incomes and house prices have long right tails, so official figures usually quote the median. The mean is pulled up by the few largest values.
Quality reports. Box plots put many batches side by side on one page, each with its centre, its middle half and its outliers.
In signal processing · the median filter
A median filter slides a short window along a signal and keeps the median of each window, as in the fifth example. It removes spikes that a moving average would smear, as Simple smoothing filters and Image filtering show in the signal processing course.
Where this leads · a projection
Write the nine values as one vector. Their mean times the all-ones vector is its projection onto the all-ones direction, and what is left over has squared length , here 5572. Projections in the linear algebra course builds that picture.
Reference card
| Quantity | Formula | Notes |
|---|---|---|
| Sample mean | follows far points | |
| Median | middle of the sorted data | robust |
| Sample standard deviation | divisor | |
| Quartiles | , at positions and from 0 | NumPy’s default |
| Interquartile range | width of the middle half | |
| Fences | , | beyond them: outliers |
| MAD | median of the distances from the median | × 1.4826 to match for a bell |
| Skewed data | mean pulled towards the long tail | report the median |