Looking at Data

Before any formula, look. Histograms that change their story with the bin width, averages dragged about by one outlier, and four datasets with identical summaries that could not be more different

Looking at Data

A list of numbers tells you almost nothing until you draw it. This lesson is about the first thing every statistician does and every formula skips: look. A picture is a choice, though, and a summary such as an average throws most of the data away, so it pays to know what each one can hide.

The Histogram’s Story

Widen the bins until the two humps merge into one, then slide the bin origin and watch a hump appear and vanish. Raise the sample size to see how much finer the bins can go before the picture turns to noise.

Population
Let a rule choose the bins
2
peaks in this histogram
2
peaks in the population
1.62
histogram’s error against the truth (× 1000)
–
smooth curve’s error against the truth (× 1000)
This picture shows 2 peaks, the same number as the population. The count alone does not make the picture right: watch the error against the truth as you change the width. It is large at both ends of the slider and smallest somewhere in between.

All four populations are simulated; none is real data. Teal marks under the axis: the 300 values themselves, which never move. Teal bars: one way of binning them, scaled so that the total area is 1. Dashed white: the density the values were drawn from, known here only because the sample is simulated. Amber: a kernel density estimate, which puts a small bell curve of width h on every value and adds them up. The error is the integrated squared difference between a picture and the dashed curve.

Go deeper:Bins, Bias and Variance

A histogram is an estimate of a density: the height of each bar is the share of the data in its bin divided by the bin’s width, so the bars have total area 1. The width h is a trade. Wide bins average the true density over a long stretch and flatten its features; that systematic error, the bias, grows like h2 when squared. Narrow bins hold few points each, so their heights jump about from sample to sample; that variance shrinks like 1/(nh). Balancing the two gives a best width proportional to n−1/3, which is why more data supports finer bins, but only slowly: eight times the data halves the width.

The three buttons are the classic recipes. Herbert Sturges (1926) reasoned from the binomial coefficients and proposed ⌈log2 n⌉ + 1 bins; it assumes roughly normal data and uses too few bins when n is large. David Scott (1979) worked out the width that minimises the integrated squared error for normal data, 3.49 s n−1/3, with s the standard deviation. David Freedman and Persi Diaconis (1981) replaced s by a spread that outliers cannot inflate, giving 2 · IQR · n−1/3. None of them chooses the origin, and none knows what the data are for. They are starting points.

A kernel density estimate, introduced by Murray Rosenblatt (1956) and Emanuel Parzen (1962), removes the origin from the problem. Instead of dropping each value into a box, it centres a small smooth bump on every value and adds the bumps. The bandwidth plays the part of the bin width, with the same trade: too small and every data point becomes a spike, too large and the estimate is one featureless mound. Its best error falls like n−4/5, a little faster than the histogram’s n−2/3. The rule-of-thumb bandwidth in the demo is Silverman’s, 0.9 · min(s, IQR/1.34) · n−1/5, which oversmooths data with more than one hump.

The habit of drawing first owes most to John Tukey, whose Exploratory Data Analysis (1977) argued that looking at data is detective work that should come before any formal test, and gave the world the box plot. In the demo you can see the true density, so you can tell a real hump from an accident of binning. With real data nobody can, which is the reason to try several widths and origins before believing any feature.

Tug of War: Mean against Median

Drag one point far to the right and watch the mean chase it while the median stays where it was. Then let a billionaire walk into the bar.

Data
Rest the beam on
Influence on
29.3
mean
22.0
median
23.9
20% trimmed mean
21.4
standard deviation
23.5
interquartile range
14.8
MAD
There are 15 points, so each unit you drag the highlighted point moves the mean by exactly 1/15 ≈ 0.067, however far it goes: a straight line in the chart. The median only notices which side of the middle the point is on, so its curve is flat except where the point passes through the middle of the data.

Teal discs: the data. Drag one to move it; the one with the white ring is the highlighted point. Tap an empty spot just above the beam to add a point, and tap a point without dragging to remove it. Amber: the mean and the standard deviation. Fuchsia: the median and the quartiles. Blue: the mean of what is left after dropping the lowest and highest 20% of the points, and the MAD, the median distance from the median, multiplied by 1.4826 so that it is comparable with a standard deviation. Rose rings: points beyond the box plot’s fences, 1.5 × IQR outside the quartiles.

Go deeper:Least Squares, Least Distance, and Breakdown

Both averages solve a problem. The mean is the number c that makes the sum of squared distances Σ (xi − c)2 as small as possible; the median is the number that minimises the sum of plain distances Σ |xi − c|. Squaring is what makes the mean sensitive: a point ten times further away pulls a hundred times as hard on the sum, so the mean must move to appease it. With plain distances every point pulls equally hard, whatever its distance, and the best c is simply where as many points pull left as right. The mean is also the balance point of the data, the one place where the distances to the left add up to the distances to the right. That is the beam in the demo.

The breakdown point of a statistic is the fraction of the data that can be replaced by arbitrary values before the statistic itself can be sent arbitrarily far. For the mean and the standard deviation it is zero: one wild value in a million is enough. For the median it is 50%, the best possible, since beyond that the bad points are the majority. A 20% trimmed mean breaks down at 20%. The interquartile range survives until a quarter of the data is corrupted, and the MAD, the median of the distances from the median, until half. (The demo multiplies the MAD by 1.4826 so that for normal data it estimates the same quantity as the standard deviation.) The chart under the box plot is a finite-sample version of what Frank Hampel called the influence curve: it is unbounded for the mean and bounded for the others.

None of this makes the mean wrong. Totals are made of means: if a budget, a payroll or a dose has to add up, the mean is the right summary and the median is useless, because n times the median is not the total of anything. And when the data are well behaved, the mean uses them more efficiently. For normal data a median needs about 57% more observations to be as precise as a mean. The question to ask is what the number is for, and whether one value should be allowed to decide it.

Robust statistics grew from that question. In 1960 John Tukey showed that a small fraction of wild values is enough to make the standard deviation a poorer measure of spread than cruder alternatives. Peter Huber’s 1964 paper found the estimators that lose the least in the worst case, a compromise that behaves like the mean near the middle of the data and like the median in the tails, and Hampel’s influence curve and breakdown point supplied the language used ever since. The box plot is Tukey’s own robust picture: quartiles for the box, and fences 1.5 × IQR beyond them to flag points worth a second look. A flag is a prompt to look, not a verdict that the point is wrong.

Same Statistics, Any Shape

Compare the four pictures with the one table they share. Then press Play, pick a shape or draw your own, and watch the points move there while the statistics stay frozen.

Anscombe’s quartet (1973)IIIIIIIV
mean of x9.009.009.009.00
mean of y7.507.507.507.50
variance of x11.0011.0011.0011.00
variance of y4.134.134.124.12
correlation0.8160.8160.8160.817
fitted liney = 3.00 + 0.500xy = 3.00 + 0.500xy = 3.00 + 0.500xy = 3.00 + 0.500x

These are exactly the forty-four pairs Anscombe published, which he constructed to make his point; they are not measurements of anything. Teal: the eleven points of each dataset. Amber: the least-squares line. The table is computed from the points, and the four columns agree to two or three significant figures. Only the first picture is what the numbers suggest: a straight trend with scatter. The second is a curve, the third a perfect line with one bad point, the fourth a single point holding up the whole fit.

Target shape
Statistic of the 120 pointsat the startnow
mean of x52.50552.505
mean of y47.50547.505
standard deviation of x18.00518.005
standard deviation of y18.00518.005
correlation−0.065−0.065
0
nudges tried
0
nudges kept
0.00
average distance to the shape (9.59 for the cloud)
A shapeless cloud of 120 points. Press Play: the points will crawl onto the dashed shape, and the five numbers in the table will not change in their first two decimal places. Only the grey third decimal moves.

Teal: the 120 points. Dashed white: the target shape. Amber: the two things the summary statistics describe, a cross centred on the means with arms one standard deviation long, and the least-squares line. Each nudge moves one point a short random distance. It is kept if the point ends up closer to the shape (occasionally also if it does not, which stops the search getting stuck), and only if all five statistics, cut off after two decimal places, are unchanged. This is a simplified version of the published method, written for this page, and the starting cloud is simulated.

Go deeper:Anscombe’s Quartet and the Datasaurus

Frank Anscombe published his four datasets in 1973, in a paper called “Graphs in Statistical Analysis”, to attack the idea that numerical calculations are exact and graphs are rough. Each set has eleven points. All four have mean of x equal to 9, mean of y 7.50, variance of x 11, variance of y close to 4.125, correlation 0.816, and the same least-squares line, y = 3.00 + 0.500x. A regression program prints practically the same output for each. Only a plot shows that the line is a fair summary of the first, the wrong model for the second, thrown off by one point in the third, and created by one point in the fourth.

In 2016 Alberto Cairo made the point unforgettable with the Datasaurus, a scatter plot with unremarkable summary statistics that turns out, when drawn, to be a dinosaur. The next year Justin Matejka and George Fitzmaurice published “Same Stats, Different Graphs”, a method for producing such datasets on demand: start from any scatter, move one point a tiny random distance, keep the move if it brings the scatter closer to a target shape and leaves the summary statistics unchanged to two decimal places, and repeat a few hundred thousand times. Accepting an occasional move in the wrong direction, less often as time goes on, is the idea of simulated annealing, and it keeps the search from freezing too early.

The second demo is a simplified version of that method written for this page, not the authors’ code. It holds five numbers fixed: two means, two standard deviations and the correlation. Because the least-squares line is determined by those five numbers, it cannot move either. The target shapes are centred and sized to suit the cloud’s statistics, which is why the points can reach them; a shape far off-centre could be approached only part of the way.

The lesson is about counting. A scatter of 120 points is 240 numbers. Five summary statistics are five equations, which leave 235 dimensions of freedom, so infinitely many datasets share any finite list of summaries. A summary is a lossy compression, and it is a good one only when the data have the shape the summary assumes: a mean and standard deviation for a single symmetric hump, a correlation for a straight-line cloud. Whether they do is something only a picture can tell you.

Key Takeaways

  • A histogram is a choice: change the bin width or the origin and the same data can gain or lose a peak.
  • One extreme value can drag the mean and the standard deviation anywhere; the median and the IQR barely move.
  • The mean is still the right summary when totals matter, and the median when a typical case does.
  • Very different datasets can share every summary statistic, so draw the data before computing from them.

Spot a mistake or have an idea?

Search