Section 11.15

Standard error

Definition

The standard error of an estimate is the standard deviation §11.14 of its sampling distribution: the spread of the values the estimate would take if the whole data collection were repeated many times, each time with new data. It measures how uncertain an estimate is, not how much single observations vary. An estimator §11.2 is the rule that turns data into an estimate. For the mean of nn independent observations with standard deviation σ\sigma, the standard error is σ/n\sigma / \sqrt n, usually estimated by s/ns / \sqrt n, where ss is the sample standard deviation.

The idea

A server’s response time §9.32 varies from request to request with a standard deviation of 2 milliseconds. An engineer measures four requests and reports their mean. Repeating the four-request measurement would give a different mean, because different requests would be measured. That run-to-run variation of the mean is a second spread. The standard deviation says how much one request varies; the standard error says how much the reported mean would change if the measurement were repeated.

Averaging shrinks the second spread because random deviations partly cancel: a slow request and a fast one pull the mean in opposite directions. The spread of a sum of nn independent values grows like n\sqrt n, not like nn, so the spread of their mean shrinks like 1/n1 / \sqrt n. Four times as many observations halve the standard error. Deviations cancel in this way only if they are independent of one another; copies of one observation, or observations that share one disturbance, do not cancel.

How it works

For the sample mean §11.12 of nn observations:

  1. Each observation has variance σ2\sigma^2, the square of its standard deviation σ\sigma.

  2. If the observations are independent, the variance of their sum is the sum of their variances, nσ2n \sigma^2.

  3. The mean is the sum divided by nn. Dividing a random quantity by nn divides its variance by n2n^2, so the variance of the mean is nσ2/n2=σ2/nn \sigma^2 / n^2 = \sigma^2 / n.

  4. The standard error is the square root of that variance: σ/n\sigma / \sqrt n.

  5. σ\sigma is rarely known, so replace it with the sample standard deviation ss to get the estimated standard error s/ns / \sqrt n.

Here nn must count independent observations. In an experiment these are the experimental units §11.3, the things to which a treatment is applied independently, not the rows of a log. Other estimators have other formulas. The proportion p̂\hat p of successes among nn independent trials has estimated standard error p̂(1−p̂)/n\sqrt{\hat p (1 - \hat p) / n}. For a median §11.13, a percentile §11.16 or a ratio there is often no simple formula, and the bootstrap §11.19, which recomputes the estimate on many resamples of the data, estimates the standard error instead.

Worked example

Four independent response times each have standard deviation σ=2\sigma = 2 milliseconds, so each has variance 22=42^2 = 4 square milliseconds. Their sum has variance 4+4+4+4=164 + 4 + 4 + 4 = 16 square milliseconds. The mean is the sum divided by 4, which divides the variance by 42=164^2 = 16: the variance of the mean is 16/16=116 / 16 = 1 square millisecond, and the standard error is 1=1\sqrt 1 = 1 millisecond. The formula agrees: σ/n=2/4=2/2=1\sigma / \sqrt n = 2 / \sqrt 4 = 2 / 2 = 1 millisecond. Each single response time still varies with standard deviation 2 milliseconds.

With σ\sigma unknown, take a measured sample of 2, 4 and 6 milliseconds. Its sample standard deviation is s=2s = 2 milliseconds, as the Variance and standard deviation entry computes. The estimated standard error of its mean is 2/3≈2/1.732≈1.1552 / \sqrt 3 \approx 2 / 1.732 \approx 1.155 milliseconds. This number estimates how much the means of three such observations vary from sample to sample. It does not say that the observed mean, 4 milliseconds, lies within 1.155 milliseconds of the true mean.

Now the formula applied wrongly. One response time XX is written to a log four times by mistake. The four rows all equal XX, so their mean is (X+X+X+X)/4=X(X + X + X + X) / 4 = X, whose standard deviation is still 2 milliseconds. The formula σ/n\sigma / \sqrt n with n=4n = 4 would claim 1 millisecond, half the truth, because the four rows carry the information of one observation. Computed from the rows, s/ns / \sqrt n is even worse: the four equal rows give s=0s = 0. Counting such rows as independent observations is called pseudoreplication §11.6.

Stated precisely

Let θ̂\hat\theta (read theta-hat) be an estimate computed from random data. Its standard error is Var(θ̂)\sqrt{\operatorname{Var}(\hat\theta)}, the standard deviation of θ̂\hat\theta over repetitions of the data collection. For observations X1,…,XnX_1, \dots, X_n with mean X‾\bar X, Var(X‾)=1n2[∑i=1nVar(Xi)+2∑i<jCov(Xi,Xj)],\operatorname{Var}(\bar X) = \frac{1}{n^2} \left[ \sum_{i=1}^{n} \operatorname{Var}(X_i) + 2 \sum_{i<j} \operatorname{Cov}(X_i, X_j) \right], where ∑i=1n\sum_{i=1}^{n} adds over the nn observations, ∑i<j\sum_{i<j} adds over each pair once, and Cov(Xi,Xj)=E[(Xi−E[Xi])(Xj−E[Xj])]\operatorname{Cov}(X_i, X_j) = \mathrm{E}[(X_i - \mathrm{E}[X_i])(X_j - \mathrm{E}[X_j])] is the covariance §15.44 of the pair, with E\mathrm{E} the expected value, the probability-weighted average. A positive covariance means the two values tend to move together.

Guarantee. If (1) every observation has the same finite variance σ2\sigma^2 and (2) every pair has covariance 0, which independence ensures, the covariance sum vanishes and Var(X‾)=nσ2n2=σ2n,standard error of X‾=σn.\operatorname{Var}(\bar X) = \frac{n \sigma^2}{n^2} = \frac{\sigma^2}{n}, \qquad \text{standard error of } \bar X = \frac{\sigma}{\sqrt n}. No assumption of a normal distribution is needed for this formula. Replacing σ\sigma by ss gives an estimate of the standard error, not its exact value, and for small nn that estimate itself varies a lot.

If instead every pair has the same correlation ρ\rho (read rho), the covariance divided by σ2\sigma^2, a number between −1-1 and 1 that measures how strongly two values move together, then the n(n−1)/2n(n-1)/2 pairs each have covariance ρσ2\rho \sigma^2 and Var(X‾)=σ2n(1+(n−1)ρ).\operatorname{Var}(\bar X) = \frac{\sigma^2}{n} \bigl(1 + (n - 1) \rho\bigr). With n=4n = 4 copies of one value, ρ=1\rho = 1 and the variance is (σ2/4)(1+3)=σ2(\sigma^2 / 4)(1 + 3) = \sigma^2, so the standard error is σ\sigma, as the worked example found. With n=100n = 100 and a modest ρ=0.1\rho = 0.1, the factor is 1+99×0.1=10.91 + 99 \times 0.1 = 10.9, and the true standard error is σ10.9/100≈0.330σ\sigma \sqrt{10.9 / 100} \approx 0.330\,\sigma, more than three times the 0.1σ0.1\,\sigma that the independent formula gives. The 100 values carry the information of about 100/10.9≈9.2100 / 10.9 \approx 9.2 independent ones.

Limits and common mistakes

A standard error is not the standard deviation of the data. Because it is smaller by the factor n\sqrt n, error bars §18.1.11 that show standard errors make data look far less variable than error bars that show standard deviations. A figure must say which it shows.

The standard error measures random sampling variation only. It says nothing about bias, a systematic error such as a timer that always reads 3% high, or about a test that measured the wrong population. A huge sample gives a tiny standard error around a wrong value.

The formula s/ns / \sqrt n fails when observations are dependent. Requests measured on one device, in one session or during one burst of background load share disturbances, and consecutive measurements in a time series are often correlated; s/ns / \sqrt n is then too small. Compute the standard error over the independent units, for example by treating the per-device means as the observations, or use a method built for the dependence, such as the cluster bootstrap §11.21.

The formula for the mean does not carry over to other estimators. For data from a normal distribution, the bell-shaped distribution that many measurement errors roughly follow, the standard error of the median is about 1.2533σ/n1.2533\,\sigma / \sqrt n for large nn, where 1.2533≈π/21.2533 \approx \sqrt{\pi / 2}. Tail percentiles such as the 99th have much larger standard errors than the mean.

A standard error is not an interval. A confidence interval §11.18 multiplies it by a factor taken from the normal distribution or from Student’s t distribution, the distribution that accounts for estimating σ\sigma by ss. Using those factors needs normally distributed data or, by the central limit theorem §15.45, a sample large enough that the mean is approximately normally distributed. For heavy-tailed data, in which extreme values are relatively common, that can take a very large nn.

Questions answered

When is sample standard deviation divided by square root of n appropriate?

Dividing the sample standard deviation ss by n\sqrt n is appropriate when the quantity wanted is the standard error of a sample mean, meaning how much that mean would vary across repetitions of the data collection, and when the nn observations are independent, or at least uncorrelated, and share one finite variance. Then s/ns / \sqrt n estimates the true standard error σ/n\sigma / \sqrt n, where σ\sigma is the standard deviation of one observation. The data need not follow a normal distribution for this estimate.

It is not appropriate in three common cases. First, when nn counts rows that are not independent, such as requests inside one session or one log row copied four times; then nn must count the independent units, or a method for clustered data must be used. Second, when the estimate is not a mean but, for example, a median, a percentile or a ratio, each of which has its own standard error. Third, when the goal is the spread of individual observations, which is ss itself. Turning s/ns / \sqrt n into a confidence interval with a normal or Student t factor additionally needs normally distributed data or a large nn.

Related entries: Variance and standard deviation (§11.14), Confidence interval (§11.18), Cluster bootstrap (§11.21), Measurement uncertainty (§11.33), Pseudoreplication (§11.6), Correlation and covariance (§15.44), Central limit theorem (§15.45).