Sampling bias: what population did you actually observe?
抽样偏差
Separate selection bias from sampling variation and enumerate inverse-probability estimates with their real variance cost.
sampling-biasMore data from the wrong doorway
Imagine measuring a model’s average error across three equally important cases. Their fixed losses are0,2,8. The target average is10/3. A logging system preferentially records the easy case: each draw selects the three cases with probabilities1/2,1/3,1/6. The average recorded loss tends toward2, not10/3. Millions of draws can make that wrong average extremely precise.
This is a deliberately complete toy population. It lets us separate the target from the data-collection mechanism without guessing an unobserved ground truth. In a real benchmark, begin by naming the unit and population: requests, users, hospitals, languages or time periods do not imply the same weighting. Read expectation and conditional probability first.
Define bias relative to a target and a design
For an estimator of a fixed target μ, design bias is its expectation over repeated applications of the sampling design minus μ. With finite second moments:
Expand (μ̂−μ) as (μ̂−Eμ̂)+(Eμ̂−μ); the cross term averages to zero. More independent draws from the same selected distribution reduce the variance of their average but leave its expectation at2 in our example. This is why sampling fluctuation and systematic selection require different remedies.
Coverage error excludes parts of the target population. Nonresponse creates a further selection stage among invited units. Measurement and processing errors can distort recorded values even when selection is sound. The Census Bureau’s2020 handbook distinguishes these nonsampling errors and notes that a larger sample does not remove systematic bias. A low response rate is a warning to investigate, not a numerical measure of bias by itself.
Unequal probabilities need not imply a biased estimator
Let a finite population contain N fixed values yᵢ. Indicator Sᵢ records whether unit i is included at least once. If its true inclusion probability πᵢ is known and strictly positive, the Horvitz–Thompson mean estimator is:
This unbiasedness proof uses linearity, not independence of inclusion indicators. Penn State’s sampling course, Definition3.2 specifies the estimator using distinct included units. For several with-replacement draws, per-draw selection probabilities and the probability of ever being included differ: πᵢ=1−(1−pᵢ)ⁿ for n independent draws. Reusing per-draw pᵢ in a distinct-unit HT sum is generally wrong. Our program draws exactly one unit, so the two probabilities coincide.
For the three-case example, the HT mean estimates are0,2,16 depending on which case is drawn. Their design expectation is0/2+2/3+16/6=10/3. The value16 exceeds every population loss: unbiasedness is an average property, not a promise that each estimate looks plausible or is more accurate than an unweighted one.
A normalized weighted mean is another estimator
Dividing a weighted total by an estimated population count gives a ratio estimator:
It is often useful but not generally exactly design-unbiased. With one selected unit, the weights cancel and it equals that unit’s value, so its expectation in our toy design is2. The HT estimator instead uses the known N=3. Do not silently substitute one denominator for the other while keeping the same theorem.
Enumerate the entire design distribution
This complete Python 3.12 program accepts1–30 fixed rational values and matching strictly positive rational probabilities summing to one. It enumerates every possible one-unit sample and computes exact expectations, biases, variances and mean squared errors. It does not estimate unknown propensities or simulate random samples.
from fractions import Fraction as F
def one_draw_design(values, probabilities):
y, pi = list(values), list(probabilities)
if len(y)!=len(pi) or not 1 <= len(y) <= 30:
raise ValueError('matching arrays with one to thirty units required')
if any(type(v) not in (int,F) for v in y+pi):
raise ValueError('rational values and probabilities required')
y,pi = list(map(F,y)),list(map(F,pi))
if any(p<=0 or p>1 for p in pi) or sum(pi,F(0))!=1:
raise ValueError('strictly positive probabilities summing to one required')
n = len(y)
target = sum(y,F(0))/n
naive = y
ht = [v/(n*p) for v,p in zip(y,pi)]
def moments(estimates):
expectation = sum((p*v for p,v in zip(pi,estimates)),F(0))
variance = sum((p*(v-expectation)**2 for p,v in zip(pi,estimates)),F(0))
bias = expectation-target
return expectation,bias,variance,variance+bias*bias
return target,ht,moments(naive),moments(ht)
if __name__ == '__main__':
target,outcomes,naive,ht=one_draw_design([0,2,8],[F(1,2),F(1,3),F(1,6)])
print('population mean:',target)
print('HT mean estimate by selected unit:',[str(x) for x in outcomes])
print('naive: expectation, bias, variance, MSE:',*[str(x) for x in naive])
print('HT: expectation, bias, variance, MSE:',*[str(x) for x in ht])
equal=one_draw_design([0,2,8],[F(1,3)]*3)
print('equal-probability expectations:',equal[2][0],equal[3][0])
Output:
population mean: 10/3
HT mean estimate by selected unit: ['0', '2', '16']
naive: expectation, bias, variance, MSE: 2 -4/3 8 88/9
HT: expectation, bias, variance, MSE: 10/3 0 296/9 296/9
equal-probability expectations: 10/3 10/3
The naive estimator has bias−4/3, variance8 and MSE88/9. HT removes the bias but has variance and MSE296/9 for one draw. Thus the unbiased choice has larger MSE in this particular small design. The calculation exposes a bias–variance tradeoff instead of turning weighting into an unconditional recommendation.
Under equal selection probabilities1/3, both estimators reduce to the selected value and both expectations equal10/3. The routine takes O(N) rational operations and storage; rational bit cost is additional. It rejects zero inclusion probabilities because no finite inverse weight can recover a never-observed unit’s arbitrary unknown value.
A weight is a claim about the missing cases
In practice, response probabilities may be estimated from observed covariates rather than known from a design. Extending inverse weighting then needs suitable conditional selection assumptions, relevant covariates, a correctly specified probability model or another justified identification strategy, and overlap. A fitted score between zero and one does not verify those assumptions. Hidden outcome-dependent nonresponse can remain.
Tiny inclusion probabilities create large weights and unstable estimates. Trimming weights changes the estimator and may trade variance for bias; report the rule and sensitivity. When some target group has zero coverage, collect data or state additional extrapolation assumptions. Neither duplicating available records nor a standard train/test split repairs the absent coverage.
Random assignment to treatment supports internal causal comparisons under a design; random sampling concerns representation of the population. They are separate. A permutation test can be exact for treatment assignment within selected volunteers while the volunteers still fail to represent all users.
Name the quantity that repetition will converge to
- For losses0,2,8 and selection probabilities1/2,1/3,1/6, what is the expected recorded loss?
Answer 1: 0×1/2+2×1/3+8×1/6=2, versus the equally weighted population mean10/3.
- If the third unit is selected, why is the HT mean estimate16 rather than8?
Answer 2: Its contribution is8/(3×1/6)=16. Repeated-design averaging, not each possible estimate, recovers10/3.
- What is the normalized ratio estimator with only one selected unit?
Answer 3: That unit’s value: the inverse weights cancel. Its design bias here is−4/3.
- Will averaging independent repetitions of the naive draw eliminate bias?
Answer 4: No. Its expectation stays2; variance becomes8/n for n repetitions, while squared bias remains16/9.
Audit collection before optimizing the model
Survey sampling supplies a precise vocabulary for inclusion, weighting and coverage. AI evaluation adds practical choices about deduplication, logging policies and deployment populations. Keep those choices visible in a dataset card and evaluation report; a confidence interval for sampling variability does not account for every possible data error.
Project: extend the finite example to two distinct sampled units under a fully specified design. Enumerate legal samples, compute each unit’s actual inclusion probability and compare HT with a ratio estimate. Then remove one population unit from the sampling frame and explain which quantities can no longer be identified without further information.
Make a prediction, then check
Does collecting more observations from the same biased selection mechanism necessarily remove bias?
Learning objectives
- Specify target population and distinguish bias from sampling variation.
- Derive HT unbiasedness and quantify weighting variance.
Prerequisites & connections
Explore related knowledge →References
- STAT 506 — Unequal Probability Sampling
Penn State Department of Statistics - Understanding and Using ACS Data — Chapter11: Measures of Nonsampling Error
U.S. Census Bureau · 2020
Version1 · Editorial status: Recorded technical checks completed
View technical check record (AI)
Codex · 2026-09-06 · Codex single-agent authored technical review: primary-source locations, explicit assumptions, exact/literal and numerical checks, and bilingual review; not independent human or second-agent review.
- Single-agent authored technical review: cited primary-source locations, explicit assumptions, original derivations and examples, bilingual equations and four matching exercises. Not independent human or second-agent review.
- Four focused CPython3.12.4 tests passed: literal reference cases, mathematical invariants or full finite-design calibration, invalid inputs and bilingual structure. Rational arithmetic is separated from floating logarithms. R/SciPy documentation was read without claiming those runtimes were executed.
- Promoted the full prose, equations, code and exercises. Tests read formal MDX only; removed temporary fallbacks/draft skips and updated review assertion to checked. Algorithm and independent references are unchanged; final record binds both locale hashes.
- Publication navigation points published topics to complete articles and removes corresponding pending wording, retaining directory entries for unwritten targets. Principles, equations, programs and exercises are unchanged; final article SHA values rebound.
Source locations checked:
- STAT 506 — Unequal Probability Sampling · Definition3.2 and adjacent inclusion-probability discussion: HT on distinct units, unbiased total, difference from per-draw probability. Read downloaded original HTML after browser timeout; no course dataset copied.
- Understanding and Using ACS Data — Chapter11: Measures of Nonsampling Error · 2020 Chapter11 pp75–77: coverage, nonresponse and processing errors; systematic bias is not removed by larger samples. No current survey statistics adopted.
Related topics