Definition
The sample mean is the sum of the observed values divided by their number: the arithmetic average of a sample, written and read “x bar”. It is the value every observation would have if their total were shared out equally, so the number of observations times the mean gives back the total. The sample mean is the usual estimator §11.2 of the population mean, the average over the whole population or the long-run average of the process that produced the data. One extreme value can move it far.
The idea
Three requests take 2, 4 and 6 milliseconds (ms). Their total is ms. Shared equally among the three requests, the total gives ms each. That is the mean. It does not claim that any request took 4 ms; it claims that three requests of 4 ms each would use the same total time. The mean is the right summary whenever the total is what matters: the processor time that a thousand requests consume, the energy drawn from a battery, the number of requests a server completes per hour.
Put equal weights on a ruler at the positions 2, 4 and 6. The ruler balances at 4. The picture is exact, not an approximation: the mean is the balance point of equal weights placed at the observed values. It also shows the mean’s sensitivity: moving one weight far along the ruler moves the balance point a long way, however many weights stay near the middle.
How it works
Let be the number of observations and the -th observation, for ; the subscript only numbers the observations. Then where is shorthand for the sum of all observations. For the three requests, and ms.
Deviations balance. The deviations from the mean, , always add up to zero. For the three requests they are , and ms. Their average therefore cannot measure spread; the variance §11.14 uses squared deviations instead.
Units and shifts. The mean has the units of the data. Adding a constant to every observation adds to the mean, and multiplying every observation by multiplies the mean by .
Additivity. If each request passes through two stages with times and , the mean of the totals equals the mean of the plus the mean of the . The median §11.13, the middle value after sorting, does not have this property (see the median entry).
Sensitivity. Raising one observation by raises the mean by , with no upper limit.
Used to estimate the population mean (mu), the sample mean has two properties that need different assumptions. If every observation has expected value , meaning that its average over many repetitions of the measurement is , the sample mean is unbiased: its own expected value is . If, in addition, the observations are independent of each other, each with variance (sigma squared), the standard error §11.15 of the sample mean, its typical distance from , is . Four times as many observations halve the standard error.
Worked example
Replace the 6 ms request by one that took 606 ms, for example because a lost packet had to be resent. The mean becomes ms. No request took anything near 204 ms. The mean still shares the total equally, since ms, but it no longer describes a typical request. The median of 2, 4 and 606 ms is still 4 ms.
The change can be found without recomputing the sum. One observation rose by ms. Shared among observations, that raises the mean by ms, from 4 to 204 ms. In a sample of 300 requests the same single delay would raise the mean by ms. A larger sample dilutes one large value, but nothing caps its influence: the 600 ms could have been 600 seconds.
Who shares equally must be decided. Board 1 contributes three requests of 2, 4 and 6 ms; board 2 contributes one request of 40 ms. The mean over requests is ms, each request counting once. The mean over boards first averages each board, giving 4 ms and 40 ms, then averages those: ms, each board counting once. Both numbers are correct, for different questions: the first describes a request chosen at random, the second a board chosen at random.
Stated precisely
For observations , the sample mean satisfies four exact statements that need no assumption about how the data arose.
.
is the number that makes the sum of squared distances smallest.
Replacing one observation by changes by exactly .
If for every , then .
As an estimator, the sample mean needs assumptions. Let be the population mean, let denote expected value, the average over repeated samples drawn the same way, and let denote variance, the expected squared distance of a quantity from its expected value.
If for every , then . Independence is not needed for this.
If, in addition, the are independent, each with variance , then . Dependence between observations, such as many requests from one session, changes this formula.
If the are independent and identically distributed §11.5 with a finite mean , then approaches as grows. This is the law of large numbers §15.46.
Limits and common mistakes
The mean is not a typical value when the data are skewed, meaning that the values spread much further on one side of the middle than on the other. Report the median or other quantiles §11.16 alongside it, or the empirical cumulative distribution function §11.17, which shows every value.
The mean is not a deadline guarantee. A mean of 4 ms is compatible with a request that misses a 5 ms deadline.
Averaging only the requests that succeeded estimates the duration of successful requests, not of all requests. A request that was abandoned after a waiting limit has a duration known only to exceed that limit; see the censoring §11.28 entry. Such requests must stay visible under a rule declared before the analysis.
Deleting an inconvenient large value changes the question the mean answers. First find out whether the value is a measurement error or a real event (see the outlier handling §11.31 entry). A trimmed mean, which drops a fixed fraction of the smallest and of the largest values before averaging, is a different, declared summary, not a correction of the mean.
The mean of per-request ratios differs from the ratio of total times; see the entry on the ratio of aggregates versus the aggregate of ratios §11.40.
For some distributions in which extreme values occur often enough, such as the Cauchy distribution, the population mean does not exist, and the sample mean never settles down however large the sample.
Questions answered
How can one large outlier change the mean?
One large outlier, a value far above the rest, raises the mean by its excess over the value it replaces divided by the number of observations, and nothing limits how large that excess can be. If one observation rises by in a sample of observations, the total rises by and the mean, the total divided by , rises by . Replacing 6 ms by 606 ms in the sample 2, 4 and 6 ms raises the total by 600 ms and the mean by ms, from 4 ms to 204 ms, a value no request came near. The breakdown point of an estimator is the smallest fraction of observations that, replaced by arbitrary values, can carry the estimate arbitrarily far. For the mean it is , one observation; for the median it is about one half, and the median of 2, 4 and 606 ms is still 4 ms. Before acting, find out whether the outlier is a measurement error or a real event. A real long delay is part of the total cost and belongs in the mean; report the median and the slowest values alongside it, so that readers see both the typical request and the rare long one.
Related entries: Median (§11.13), Variance and standard deviation (§11.14), Outlier handling (§11.31), Standard error (§11.15), Estimand and estimator (§11.2), Ratio of aggregates versus aggregate of ratios (§11.40).