Suppose the average of a file of past deliveries is used to estimate the average delay of next month’s parcels. That average is one number, but another file of the same size would have given a different number, and the file may not even represent the deliveries that matter. Before trusting the average, we need to know how much it would vary from sample to sample and whether it aims at the right target. This lesson describes that variation through the sampling distribution and the standard error, and it settles what the law of large numbers and a confidence interval can and cannot promise.
Key terms
Estimator
Definition The population is the collection of units, or the data-generating process, that a question is about, and a parameter is a number that describes it, such as its mean . A sample is the set of observations obtained from the population by a stated sampling process. An estimator of is a rule , fixed before the data are seen, that turns a sample into a number. Because the sample is random, the estimator is a random variable, and the number it returns for the observed sample is an estimate. The sampling distribution of is its probability distribution over all the samples the process could produce, with the population, the sample size and the sampling design held fixed. The estimator is unbiased for under a model if for every distribution the model allows. The sample mean
is unbiased for whenever every has mean , by linearity of expectation.
In plain words The estimator is the recipe, and the estimate is the number the recipe produced from one data set. The sampling distribution lists every number the recipe could have produced under the same process, with its probability. It is a different distribution from the distribution of individual observations. Unbiased means right on average over repeated samples, not right in each sample.
Example In a constructed population, each delivery is delayed minutes or minutes, each with probability . Its mean is minutes, and since both outcomes lie minutes from the mean, its variance is minutes squared and its standard deviation is minutes. These are constructed numbers, not measured delays. The observed sample gives the estimate minutes. With four independent deliveries there are equally likely ordered samples. When of the four delays are ten minutes the mean is , and this happens in of the samples.
| Sample mean in minutes | |||||
|---|---|---|---|---|---|
| Number of samples |
The expectation of this sampling distribution is minutes, so the sample mean is unbiased here, yet of the samples give an estimate other than .
Independent and identically distributed
Definition Random variables are identically distributed if they all have the same probability distribution, so that for every and every set of values. They are independent if, for all sets ,
For discrete variables it is enough to check single values, . The two conditions together are abbreviated iid, and neither one implies the other. The variables are exchangeable if, for every permutation of the indices , the rearranged vector has the same joint distribution as . Independent and identically distributed variables are exchangeable, and exchangeable variables are identically distributed, but exchangeable variables need not be independent.
In plain words Identically distributed is a statement about each observation on its own. Independence is a statement about how the observations relate, and it says that learning the values of some of them does not change the probabilities for the others. Random splits of rows into training, validation and test data rely on this picture of independent rows from one distribution, so rows that share a customer, a device or a time period need splits that keep those groups together or respect time order.
Example Drawing a fresh zero-or-ten delay for each of four parcels gives iid observations. Now draw one delay for a van and give it to all four parcels on the van, so . Each parcel still has delay or with probability , so the four are identically distributed and exchangeable. They are not independent, since instead of . Drawing two records without replacement from a file of four deliveries with delays , , and gives another exchangeable pair that is not independent. The second record is with probability overall, but with probability when the first is . In the other direction, delays from two services drawn independently, one with outcomes or and one with outcomes or , each with probability , are independent but not identically distributed.
Standard error
Definition The standard error of an estimator is the standard deviation of its sampling distribution, for a stated population, sample size and sampling design. Let be independent with common mean and common finite variance , as in iid sampling from a population with finite variance. Independence makes the variance of the sum equal to , and dividing the sum by divides its variance by , so
Without independence the covariances stay in the variance of the sum, as in Expectation, Variance, and Covariance, and
When is unknown, it is usually replaced by the sample standard deviation
defined for , which gives the estimated standard error . Under iid sampling with finite variance the sample variance is unbiased, , but is in general not unbiased for , and the estimated standard error is itself a statistic with its own sampling distribution.
In plain words The standard deviation says how much individual delays vary. The standard error says how much the average of delays would vary if the whole sampling were repeated. More independent observations shrink the standard error like , so quadrupling halves it, while stays the same. Rows that copy one another add no independent information.
Example For the delay population and , the standard error is minutes, which matches the sampling distribution in the table above, whose variance is . Sixteen independent deliveries give minutes. For the observed sample the squared deviations from are , , and , which sum to , so , and the estimated standard error is minutes. The match with the true value is luck. The samples and , with total probability , give and an estimated standard error of . Over all samples averages exactly , while averages about . In the shared-van file the four-row mean equals the van delay , so its standard error is minutes, not .
Law of large numbers
Definition Let be iid with mean and finite variance , and let be the mean of the first of them. The weak law of large numbers says that converges in probability to , which means that for every fixed
A proof notes that on the event and everywhere, so the expectation of is at least times the probability of that event. Since , that expectation is , and dividing by gives Chebyshev’s bound
which tends to as grows. These conditions are sufficient, not necessary. For iid observations a finite mean is already enough, and other versions allow some dependence or observations that are not identically distributed. The law is a statement about a limit and gives no exact probability at any finite .
In plain words Pick any tolerance around . With enough iid observations, an average that misses by at least that tolerance becomes as unlikely as you like. The law does not say that each new average is closer than the last one, the law alone does not say how large must be in a given problem, and it does not make the average settle near the mean of a population the data did not come from.
Example For the delay population , so with tolerance minute the bound is . At it is , so the mean of independent delays misses by at least one minute with probability at most . The exact probability is about , so the bound is valid but very loose. At the bound is and the exact probability is about . At the bound is , which says nothing, and the exact probability is , because only the samples with mean miss by less than a minute.
Confidence interval
Definition A confidence interval procedure at level for a parameter is a rule that turns each possible sample into an interval whose endpoints are statistics, such that under the stated model
for every allowed value of the parameters. The probability is over repeated samples, with fixed and the endpoints random. A conservative procedure guarantees at least , and an approximate one reaches only approximately. The probability that the interval contains under the process that actually produced the data is its coverage probability. For iid observations with known , the normal-based 95 percent interval for is
It is exact, apart from rounding , when the observations are normal. Otherwise its justification is the central limit theorem, which says that for iid observations with finite variance
meaning that the distribution function of the standardized mean converges to the standard normal one at every point. This is a limit statement about the standardized mean, not about individual observations. How accurate it is at a given depends on the population, so no single sample size works for every case. When is estimated by , the Student t interval , with the quantile of the t distribution with degrees of freedom, is exact for iid normal observations, but not for arbitrary nonnormal or dependent data.
In plain words The 95 percent belongs to the recipe, not to one interval. If the conditions hold, the long-run proportion of intervals from repeated samples that contain the fixed is 95 percent. Once the data are in, a computed interval either contains or does not. The label is a target that the assumptions have to justify, and the interval is about the mean, not about where 95 percent of individual delays fall.
Example Take the delay population with known and . The standard error is , so the half-width is minutes. The intervals centered at , and contain , and those centered at and miss it. The covering samples number of , so the probability that the random interval contains is
not . With the half-width is , the interval contains exactly when the number of ten-minute delays is from to , and the binomial probabilities of those add up to a coverage of about . Coverage need not move steadily toward , since it is about at and about at . A simulation estimates the same coverage by repeating the sampling.
import numpy as np
rng = np.random.default_rng(18019)
n, reps = 4, 20_000
samples = rng.choice([0, 10], size=(reps, n))
means = samples.mean(axis=1)
half = 1.96 * 5 / np.sqrt(n)
print(np.mean(np.abs(means - 5) <= half))One run printed . The Monte Carlo standard error of such a proportion is about , so the simulation agrees with the exact to within about Monte Carlo standard errors. More repetitions make the estimate of the coverage more precise, while a larger changes the coverage itself.
Selection bias
Definition Selection bias is a systematic error that arises when the process deciding which units or outcomes enter the data is related to the outcomes being measured, so that the recorded observations follow a different distribution from the target population. Let mean that a unit is recorded, and suppose the records are iid draws from the distribution of given , with finite variance. Then the mean of records has expectation and, by the law of large numbers, converges in probability to it rather than to . As an estimator of its bias at every sample size is
If recording is independent of , this difference is . A larger sample, a smaller standard error or a narrower interval does not remove the bias, since all of them describe variation around .
In plain words More data from the wrong process give a more precise answer to a different question. Before trusting a small standard error, ask how the data were collected and which cases could not appear in them. The same problem arises when a model is trained or evaluated on records that were filtered differently from the cases it will meet in use.
Example Suppose a logging system in the delay population records only the deliveries that had no delay. Then , and the mean of the records is at every sample size, minutes below . Every record is , so , the estimated standard error is , and the interval is the single point , which never contains . The interval looks perfectly certain and is always wrong.
Check yourself
- A constructed delay population has standard deviation minutes, and deliveries are sampled independently. Find the standard error of the mean for and for , and the smallest that makes it at most minutes. A report on deliveries then says that individual delays vary by only about minute. What is wrong with that sentence?
Show the answer
The standard errors are minutes and minute, so quadrupling halves the standard error. The condition means , so .
The figure of minute is the standard error of the mean of deliveries. It describes how much that average would vary over repeated samples. Individual delays still have standard deviation minutes at every sample size, so a correct report says that individual delays have standard deviation minutes and that their mean has standard error minute.
- A delay population has standard deviation minutes. A file holds parcel rows from independently sampled vans, five parcels per van, and every parcel on a van has exactly that van’s delay. The rows average minutes. An analyst reports as a 95 percent confidence interval for the mean delay. Find the standard error under this model and the corrected normal-based interval. What does the corrected calculation still not establish?
Show the answer
Write for the delay of van . Each van contributes five copies of , so the row average is the average of independent van delays,
and its standard error is minutes. The analyst’s treats the rows as independent and is too small by a factor of . The analyst’s interval, here , comes from a procedure that adds about minutes on either side of the row average. Even if the van delays were normal, that procedure would cover the true mean in only about 62 percent of repeated samples, since that half-width is true standard errors and a standard normal variable lies within of with probability about .
The corrected half-width is minutes, so the interval is . Its 95 percent label still needs a justification, either normal van delays or a normal approximation that is adequate for a mean of independent vans, and the vans must be a random sample of the vans the question is about. The interval also concerns the mean delay, not the range that holds 95 percent of individual parcel delays.
- In the constructed delay population, with delays of or minutes each with probability , a logging system records every zero-minute delivery but records each ten-minute delivery only with probability , independently of everything else. An analyst treats the records as iid draws and reports for the mean delay. What does the mean of the records converge to, and what happens to the probability that the interval contains as the number of records grows?
Show the answer
Recorded deliveries make up of all deliveries, and the ten-minute ones are of the records. The records are therefore iid with mean
minutes, and by the law of large numbers their average converges in probability to , not to . The selection bias is minutes at every sample size.
The recorded delays have standard deviation minutes, so with records the standard error is about minutes and a typical interval is about . Exact binomial calculations put the probability that the interval contains at about for records, about for records and below one in a million for records. The coverage of the true mean goes to zero as the data grow, because the interval narrows around the wrong value. The remedy is knowledge of the logging process, not more records. In this model, weighting each ten-minute record by , because only half of those deliveries are logged, makes the weighted mean converge to .