Section 11.12

Sample mean

Definition

The sample mean is the sum of the observed values divided by their number: the arithmetic average of a sample, written x‾\bar{x} 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 2+4+6=122 + 4 + 6 = 12 ms. Shared equally among the three requests, the total gives 12/3=412/3 = 4 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 nn be the number of observations and xix_i the ii-th observation, for i=1,…,ni = 1, \dots, n; the subscript ii only numbers the observations. Then x‾=x1+x2+…+xnn=1n∑i=1nxi,\bar{x} = \frac{x_1 + x_2 + \dots + x_n}{n} = \frac{1}{n} \sum_{i=1}^{n} x_i, where ∑i=1nxi\sum_{i=1}^{n} x_i is shorthand for the sum of all nn observations. For the three requests, n=3n = 3 and x‾=12/3=4\bar{x} = 12/3 = 4 ms.

Used to estimate the population mean μ\mu (mu), the sample mean has two properties that need different assumptions. If every observation has expected value μ\mu, meaning that its average over many repetitions of the measurement is μ\mu, the sample mean is unbiased: its own expected value is μ\mu. If, in addition, the observations are independent of each other, each with variance σ2\sigma^2 (sigma squared), the standard error §11.15 of the sample mean, its typical distance from μ\mu, is σ/n\sigma/\sqrt{n}. 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 (2+4+606)/3=612/3=204(2 + 4 + 606)/3 = 612/3 = 204 ms. No request took anything near 204 ms. The mean still shares the total equally, since 3×204=6123 \times 204 = 612 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 606−6=600606 - 6 = 600 ms. Shared among n=3n = 3 observations, that raises the mean by 600/3=200600/3 = 200 ms, from 4 to 204 ms. In a sample of 300 requests the same single delay would raise the mean by 600/300=2600/300 = 2 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 (2+4+6+40)/4=52/4=13(2 + 4 + 6 + 40)/4 = 52/4 = 13 ms, each request counting once. The mean over boards first averages each board, giving 4 ms and 40 ms, then averages those: (4+40)/2=22(4 + 40)/2 = 22 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 x1,…,xnx_1, \dots, x_n, the sample mean x‾=1n∑i=1nxi\bar{x} = \frac{1}{n} \sum_{i=1}^{n} x_i satisfies four exact statements that need no assumption about how the data arose.

  1. ∑i=1n(xi−x‾)=0\sum_{i=1}^{n} (x_i - \bar{x}) = 0.

  2. x‾\bar{x} is the number cc that makes the sum of squared distances ∑i=1n(xi−c)2\sum_{i=1}^{n} (x_i - c)^2 smallest.

  3. Replacing one observation xjx_j by xj+dx_j + d changes x‾\bar{x} by exactly d/nd/n.

  4. If zi=ai+biz_i = a_i + b_i for every ii, then z‾=a‾+b‾\bar{z} = \bar{a} + \bar{b}.

As an estimator, the sample mean needs assumptions. Let μ\mu be the population mean, let E[⋅]E[\cdot] denote expected value, the average over repeated samples drawn the same way, and let Var(⋅)\mathrm{Var}(\cdot) denote variance, the expected squared distance of a quantity from its expected value.

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 dd in a sample of nn observations, the total rises by dd and the mean, the total divided by nn, rises by d/nd/n. Replacing 6 ms by 606 ms in the sample 2, 4 and 6 ms raises the total by 600 ms and the mean by 600/3=200600/3 = 200 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 1/n1/n, 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).