Data Distributions and Statistics
Learning goals
- Show the mean minimizing total squared distance
- Note the median minimizing total absolute distance
- Explain why deviations sum to zero, forcing squares
- Contrast sensitive measures with resistant ones
- Build the five-number summary and the IQR
- Divide by for a sample variance, and say why
The data set and its two centers
Write a data set as a list of numbers, . Two summaries claim to be its center.
The mean pools the values and shares the total out equally. Using the sigma notation from the sequences chapter, and writing it (read “x bar”),
The median sorts the values and takes the middle one. With an odd count the middle value is a single data point. With an even count no single value is in the middle, so the median is the average of the two middle values. The mean does arithmetic on the sizes of the values; the median only cares about their order. That difference is the whole story of this lesson.
Compare two classes whose test scores both have a mean of and a median of :
Every measure of center agrees on these two sets, and yet nobody would call them the same class. A center alone is not a summary of a data set. You also need its spread, and later its shape.
The mean balances the data
The deviation of a value is its signed distance from the mean, : positive above the mean, negative below. The mean is the one place where those pulls cancel exactly.
The deviations from the mean always add to zero#
Start from the definition of the mean. Multiplying through by gives the fact we need, that the values add up to .
Now add up all the deviations. The sum splits into two pieces, because is subtracted once for each of the values:
The first piece is exactly , so the whole thing is .
This holds for every data set that has ever existed, which makes it both a beautiful fact and a useless measurement. If you tried to summarize spread by averaging the deviations, you would get every single time, for tightly packed data and wildly scattered data alike. Any honest measure of spread has to defeat that cancellation first. Hold on to that; it is what forces the definition of variance later.
The mean is the least-squares center
Saying the mean “balances” the data is a picture. Here is a sharper claim: the mean is the single number that sits closest to the data, when “close” is measured by total squared distance. Pick any guess for the center and score it with
The guess with the lowest score wins. The remarkable thing is that is a quadratic in , so you already know how to find its minimum.
The mean is the unique minimizer of the total squared distance#
Expand the square inside the sum and split it into three sums:
Read that as a function of . The quantities and are fixed numbers baked into the data, so is a quadratic in whose leading coefficient is . Since , the parabola opens upward and it has a genuine minimum at its vertex.
Substitute and complete the square:
The bracket on the right does not contain , so it is a constant as far as this comparison goes. The only term that responds to your guess is , which is never negative and is zero exactly when .
So is smallest precisely at , and at no other value of . The mean is not merely a center of the data; it is the unique number whose total squared distance to the data is as small as it can possibly be.
Two consequences are worth naming now, because the rest of the lesson leans on them. First, the leftover constant equals , the minimum possible total squared distance. That number is about to become the variance. Second, because the vertex sits at , moving any one data value by an amount moves the mean by exactly . Drag one value far enough and the mean follows it as far as you like.
The median is the least-absolute-distance center
Squaring is not the only way to measure how far your guess sits from the data. Measure it with plain absolute distance instead,
and a different champion wins. Not the mean: the median.
The median minimizes the total absolute distance#
Sort the data so that , then pair the values from the outside in: the smallest with the largest, the second smallest with the second largest, and so on.
Take any one pair, a low value and a high value with , and ask what that pair contributes to . If your guess lands between them, so that , the two distances add to
the gap between the partners, no matter where between them sits. If instead , both distances grow and the sum becomes , which is strictly bigger than the gap. The same thing happens, by the mirror argument, if .
So each pair contributes at least its own gap , a number fixed by the data, and it contributes exactly that gap precisely when lies between the two partners. Adding over all the pairs, is at least the sum of the gaps, and that lower bound does not depend on at all. To achieve it, must lie inside every pair’s interval at once.
Those intervals are nested, each one sitting inside the one before it, so the only way to be inside all of them is to be inside the innermost one. If is odd, the innermost pair is the middle value paired with itself, and its interval is that single point. So when is odd, is smallest exactly when is the middle value: the median. If is even, the innermost pair is the two middle values, and every between them ties for the minimum. The median, the average of those two, is one of the winners, sitting at the center of the winning interval.
Be precise about that last sentence rather than glossing it. With an even count the minimizer is not unique: any number between the two middle values does equally well. The convention of averaging them simply picks the middle of a tied region. With an odd count the median is the one and only minimizer.
The two theorems together explain the entire personality of these two statistics. See them race on the tiny data set , whose mean is and whose median is :
| Guess | Total squared distance | Total absolute distance |
|---|---|---|
| median | ||
| mean | ||
Each center wins its own game and loses the other one. Neither is the “real” center. They optimize different things.
Check your understanding
For the data , a classmate claims the value that makes as small as possible is , because is the median. What is the actual minimizer?
The total squared distance is a quadratic in , and its vertex is at the mean. Expanding, , so the vertex sits at
Check it against the median: , while . The median does minimize something, but it minimizes the total absolute distance, not the squared one.
Robustness, or why one bad value ruins the mean
Now the payoff. Return to the five houses, in thousands of dollars:
Their total is , so the mean is , while the median is the third sorted value, . Four of the five houses sold for less than the mean. A statistic that overstates four sales out of five is not describing this street.
The proofs above say exactly why. The mean is the vertex of a parabola whose position is , so it is built out of the sizes of the values. Squared distance punishes a far-off point brutally: the mean has to move toward the mansion to keep that penalty down. The median is the innermost point of a nest of intervals built out of the order of the values. Sliding the largest value further out to sea changes the outermost gap, but it does not change which value is in the middle. So the innermost interval, and therefore the median, does not move at all.
A value like , sitting far away from the bulk of the data, is an outlier. A statistic that an outlier can drag around is called sensitive; one it cannot is called resistant or robust. The mean is sensitive, the median is resistant, and now you know it is not a coincidence but a consequence of what each one minimizes. This is why house prices and household incomes are reported as medians in the news, and it is worth being suspicious when someone reports a mean instead.
Worked example 1 Push the outlier further and watch each center respond
The five sale prices, in thousands, are , , , , , with mean and median . Suppose the mansion actually sold for thousand, a full more than recorded. What happens to each center?
The mean moves by exactly when one value moves by , because the mean is the total divided by and only the total changed:
Check it directly. The new total is , and . The mean has climbed above every house on the street except the mansion.
The median does not move at all. Sorting the new data gives , and the middle value is still
Nothing about the middle of the order changed, because the mansion was already the largest value and it stayed the largest value. You could sell it for a hundred million and the median of these five sales would still be thousand. That single sentence is what “resistant” means.
Shape, and what skew does to the centers
Sort a data set into bins of equal width and draw a bar for the count in each bin, and you have a histogram. Unlike a bar graph of categories, the bars sit on a number line and their order means something, so the picture shows you the shape of the distribution.
Four shapes are worth naming. A symmetric distribution looks the same reflected about its center. A right-skewed (or positively skewed) one has a long tail of large values stretching to the right, as incomes and house prices do. A left-skewed one has a long tail to the left, as exam scores do when most of the class does well and a few people bomb it. A bimodal distribution has two separate peaks, which is almost always a sign that two different groups have been mixed together.
For a symmetric data set the mean and the median are equal, and that one is a theorem, not a slogan. Pair each value with its mirror image about the center of symmetry, note that each pair averages to that center, and both statistics land there.
Skew is a different matter, and here you should be careful, because textbooks routinely overclaim. The useful rule of thumb is that a right-skewed distribution usually has its mean above its median, and a left-skewed one usually has its mean below. The reason is that the mean feels the size of every value in the long tail while the median only counts how many values are out there. That rule is reliable enough to be worth knowing, and it is the reason a gap between the mean and the median is a good skew detector. It is not a theorem: mathematicians have constructed data sets with a long right tail whose mean sits below the median. Treat “the mean is pulled toward the tail” as a strong hint about the data, and then go look at the histogram rather than trusting the slogan.
The bimodal case deserves a warning of its own. If a distribution has two clear peaks, both the mean and the median can land in the valley between them, at a value that describes almost none of the data. Think of commute times in a town where half the people walk to work in minutes and half drive for : a center of minutes describes nobody’s morning. When you see two peaks, the right move is not to pick a better center. It is to report the two groups separately.
Spread, part one: the range is fragile, the IQR is not
The crudest measure of spread is the range, . Its problem is now easy to state precisely: it is computed from the two most extreme values in the data. Those are exactly the two values most likely to be outliers. The range is not merely sensitive; it is built entirely out of the data’s least trustworthy points.
The fix is to throw away the ends and measure the middle. Sort the data and cut it in half at the median. The first quartile is the median of the lower half, and the third quartile is the median of the upper half. (When the count is odd, leave the middle value out of both halves; this lesson uses that convention throughout.) Roughly a quarter of the data lies below , and roughly a quarter lies above , so the box between them holds the middle half of the data. Its width is the interquartile range:
The IQR is resistant for the same reason the median is. Push the largest value out to infinity and it is still just “some value in the top half”; it changes no quartile, so the IQR does not move.
That last claim needs one honest qualification, and it is the kind textbooks skip. It holds only when there is enough data for the extremes to sit outside the quartile calculation. With three values, is the largest value, and with four values it is the average of the top two. So in those cases the outlier is part of , and dragging it does move the IQR. The set has and an IQR of , but change the to a and becomes . The same caveat applies to the median when there are only two values. For any data set large enough to be worth summarizing, the extremes fall outside the box and the resistance is real, which is the case worth remembering.
Taken together, the five-number summary is
and a box plot draws it: a box from to with a line at the median, and whiskers reaching out to the extremes.
That leaves the question of what counts as an outlier, and here honesty matters. There is no law of nature that defines one. The standard convention, due to John Tukey, is to call a value an outlier when it falls more than beyond the nearer end of the box:
Those two cutoffs are called the fences. The number was chosen because it flags very few points in well-behaved data and plenty of points in badly behaved data. Nothing forces it, and some analysts use to mark the truly extreme cases. When a data set has outliers by this rule, a box plot draws the whiskers only out to the most extreme values inside the fences. The plot also draws the outliers as separate dots, so the picture shows you the exception instead of hiding it inside a long whisker.
Worked example 2 A five-number summary, the IQR, and the outlier test
Twelve commuters report their travel times, in minutes, already sorted:
With , an even count, the median is the average of the th and th values:
The lower half is , and its median is the average of its two middle values:
The upper half is , so in the same way
The five-number summary is therefore , and the interquartile range is . Now run the outlier test. Since , the fences sit at
Every value from to lies between the fences, but , so the -minute commute is an outlier by Tukey’s convention. The box plot’s right whisker therefore stops at , the largest ordinary value, and the is drawn as its own point.
Notice what this data set does to the two centers. Its mean is and its median is , so the mean sits above the median. That is exactly what the skew rule of thumb suggests for data with one long right tail.
Check your understanding
For the eight sorted values , find the interquartile range.
The count is even, so cut the sorted list into two halves of four. The lower half is and the upper half is . Each quartile is the median of its half, and each half has an even count, so average its two middle values.
The interquartile range is the width of the box between them.
The value is the range, , which is the fragile measure this section replaced, and is the median of the whole list.
Spread, part two: variance and standard deviation
The IQR is the spread that belongs to the median: both are built from order, and both are resistant. Now build the spread that belongs to the mean, from squared distance.
You cannot simply average the deviations, because the first proof in this lesson showed that they always add to zero. Two repairs are available. You can take absolute values, which gives an honest measure called the mean absolute deviation. (Take those absolute deviations from the median instead, and you get the spread that genuinely belongs to it, by the second theorem above.) Or you can square the deviations, which kills the signs just as effectively and punishes a far-off value much harder than a near one. A deviation of contributes times what a deviation of contributes. Most importantly, squaring gives the very quantity the mean already minimizes. Squaring keeps you inside the world where the mean is the champion, and it keeps the algebra smooth, because has no corner in it.
Average the squared deviations and you get the variance. If your list is the entire group you care about, the group is called a population, its mean is written , and
The variance is in squared units, which is nonsense to report (squared minutes, squared dollars), so take the square root to come home to the original units. That is the standard deviation , and it is the honest headline number: roughly, how far a typical value sits from the mean.
The divisor: why sometimes becomes
Here is the question every textbook fudges, so let us do it properly. Suppose your numbers are not the whole group but a sample drawn from a much larger population whose true mean you do not know. You want the population’s spread, but you cannot measure deviations from , because you do not have . All you can do is measure deviations from the sample’s own mean .
That substitution is not innocent, and the least-squares theorem tells you exactly how it fails. That theorem says is smallest at , so plugging the true mean into that sum can only give something at least as big:
with equality in exactly one case, the coincidence , where the sample mean happens to land precisely on the population mean.
Read that inequality carefully, because it is the whole point. The spread you want is the one measured from the true center, on the right. The spread you can compute is the one on the left, and it can never come out too big. It comes out too small in every sample except that one lucky coincidence, and it does so not by bad luck but by construction. That is because is the value that makes that sum as small as it can possibly be. The sample measures its deviations from a center it fitted to itself, so it looks a little tighter than the population it came from. An estimate that misses in the same direction nearly every time, rather than erring evenly on both sides, is called biased, and this one is biased downward.
The repair is to divide by something smaller than , which inflates the answer. The sample variance divides by :
Now the honest part. This argument proves that dividing by understates the spread, and it makes the correction reasonable. But it does not prove that is the exactly right amount to correct by rather than, say, or . Showing that requires the expected value of a random variable, which is machinery you do not have yet. Take it as a debt this lesson leaves open, and take the rule with it:
- Use when your numbers are the whole population you care about (the heights of all people on this team).
- Use when your numbers are a sample used to estimate a larger population (the heights of people chosen from a city).
The divisor is a statement about what you are claiming, not about the arithmetic. Any question that asks for “the variance” without telling you which one is ambiguous and has two right answers, so expect every question here to say which one it wants.
Worked example 3 Both divisors on the same five numbers
Take the data . The mean is
The deviations from are , which sum to , as they must. Square them and add:
That sum of is all the raw material either formula uses. If these five numbers are the whole population, divide by :
If instead they are a sample from a bigger group, divide by :
Same data, same deviations, two different answers, because the two formulas answer two different questions. The sample version is larger, which is the correction doing its job. That correction compensates for the fact that the deviations were measured from , the center that makes them as small as possible.
One more property to file away: the standard deviation inherits the mean’s fragility. Squaring a large deviation makes it enormous, so a single outlier can dominate the whole sum. In the commute data, the -minute value alone contributes of the total , which is more than three quarters of it. The IQR ignores that value completely. So the pairing is clean: report the mean with the standard deviation, and the median with the IQR, and never mix a resistant center with a sensitive spread.
Check your understanding
The four values are a sample from a larger population. What is the sample standard deviation ?
The mean is , so the deviations are and the sum of their squares is
The values are a sample, so divide by , not by .
Dividing by would give the population standard deviation , which answers a different question, and stopping at reports the variance without taking the square root.
Choosing a summary
Every statistic in this lesson belongs to one of two families, and the families do not mix.
| Squared world | Order world | |
|---|---|---|
| Center | mean | median |
| What the center minimizes | total squared distance | total absolute distance |
| Spread | standard deviation | IQR |
| Effect of one wild outlier | drags both | moves neither, once there is enough data for the extremes to sit outside the box |
| Report it when | the data is roughly symmetric, or you genuinely need the total | the data is skewed or has outliers |
The mean is not a worse statistic than the median. It is the right one whenever the total is what you actually care about, since is the total. To work out a per-person share of a bill, the mean is the only correct answer and the median is useless. The failure mode is not using the mean; it is using the mean to describe a typical value in data that is skewed. Look at the shape first, then choose.