Skip to content

Describing data

One far point drags the mean but barely moves the median, so choose the summary that fits the data, and read its shape first.

Helps to know first
This topic

First, the picture

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.

ninth value
21
mean
16.78
median
16

Predict first. Drag the ninth value far to the right. What does the median do?

0.00 / 8.40 s
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 x1,…,xnx_1,\dots,x_n, here n=9n=9. Sorted from smallest to largest they are x(1)≤x(2)≤⋯≤x(n)x_{(1)}\le x_{(2)}\le\dots\le x_{(n)}, with the index in brackets.

Two centres

The sample mean is the plain average,

xˉ=1n∑k=1nxk.\bar x=\frac1n\sum_{k=1}^{n}x_k.

The median is the middle value once the data are sorted: x(5)x_{(5)} 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 1/91/9 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 n−1n-1, not nn:

s2=1n−1∑k=1n(xk−xˉ)2,s=s2.s^2=\frac{1}{n-1}\sum_{k=1}^{n}(x_k-\bar x)^2,\qquad s=\sqrt{s^2}.

Why n−1n-1 is the subject of Estimators: bias and variance, which settles it with an exact count. Here the letter ss is the sample standard deviation; signal processing pages use ss for something else.

Quartiles and the IQR. The quartiles Q1Q_1 and Q3Q_3 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 ff of the way along is at position (n−1)f(n-1)f, counting the sorted values from 0, with a straight line between neighbours. The interquartile range, IQR=Q3−Q1\mathrm{IQR}=Q_3-Q_1, 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 Q1Q_1 to Q3Q_3 with a line at the median. Two fences sit 1.5 IQR1.5\,\mathrm{IQR} beyond the box, at Q1−1.5 IQRQ_1-1.5\,\mathrm{IQR} and Q3+1.5 IQRQ_3+1.5\,\mathrm{IQR}. Whiskers reach out to the furthest data inside the fences, and any point beyond a fence is drawn on its own as an outlier.

10255075100fence 25ms
Fig. The nine response times and their box plot. The box holds the middle half, 15 to 19, with the median at 16. The upper fence is at 25, so 95 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.

width
0.30
mean
–
median
–
0.00 / 7.40 s
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 ln⁡2=0.6931\ln2=0.6931. 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 xˉ=25\bar x=25. The median is 16. By NumPy’s rule Q1=15Q_1=15 and Q3=19Q_3=19, so IQR=4\mathrm{IQR}=4 and the fences are 15−6=915-6=9 and 19+6=2519+6=25: the value 95 is an outlier. The squared deviations from 25 add to 5572, so s2=5572/8=696.5s^2=5572/8=696.5 and s=26.39s=26.39 ms.

2. The eight times, without it. The values add to 130, so xˉ=16.25\bar x=16.25, and the median is 15.515.5. The quartiles are 14.7514.75 and 18.2518.25. The squared deviations add to 59.559.5, so s2=59.5/7=8.5s^2=59.5/7=8.5 and s=2.9155s=2.9155 ms.

One point multiplied the standard deviation by about nine: 26.39/2.9155=9.0526.39/2.9155=9.05.

3. The MAD of the nine. The distances from the median 16, sorted, are 0,1,1,2,2,3,4,5,790,1,1,2,2,3,4,5,79, and their median is 2. Scaled, 1.4826×2=2.971.4826\times2=2.97 ms: close to the clean eight’s ss, 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 n=2n=2 gives 4; dividing by n−1=1n-1=1 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 19.6719.67; the median is 5. Replacing each sample by the median of its neighbours removes such spikes.

Try it yourself. The median of 3,9,1,73,9,1,7 is 5, halfway between 3 and 7. The values 1,2,3,1001,2,3,100 have mean 26.526.5 and median 2.52.5. Adding 10 to every value moves the mean and median by 10 and leaves ss 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 (n−1)s2(n-1)s^2, here 5572. Projections in the linear algebra course builds that picture.

Reference card

QuantityFormulaNotes
Sample meanxˉ=1n∑k=1nxk\bar x=\frac1n\sum_{k=1}^{n}x_kfollows far points
Medianmiddle of the sorted datarobust
Sample standard deviations2=1n−1∑k=1n(xk−xˉ)2s^2=\frac1{n-1}\sum_{k=1}^{n}(x_k-\bar x)^2divisor n−1n-1
QuartilesQ1Q_1, Q3Q_3 at positions (n−1)/4(n-1)/4 and 3(n−1)/43(n-1)/4 from 0NumPy’s default
Interquartile rangeIQR=Q3−Q1\mathrm{IQR}=Q_3-Q_1width of the middle half
FencesQ1−1.5 IQRQ_1-1.5\,\mathrm{IQR}, Q3+1.5 IQRQ_3+1.5\,\mathrm{IQR}beyond them: outliers
MADmedian of the distances from the median× 1.4826 to match ss for a bell
Skewed datamean pulled towards the long tailreport the median

Keep reading with a free account.

By creating an account you accept the terms of use.

Sign in

Already have an account? Use the service you signed up with.

Or keep reading: get new lessons by email

Are you 13 or over?

Accounts and email updates are for people aged 13 or over. We keep only your answer, never your date of birth.

End of the lesson

Where to go next.

Phasorium

Account

Sign inKeep your place on any device

Subjects

Site

Look