Expectation, Variance, and Sampling
Expectation: a long-run weighted average
For a discrete random variable:
If a successful tool call yields 10, a failure costs 4, and the success rate is 0.7, then expected utility is . Expectation does not mean every call returns 5.8; it is a long-run average model for many comparable trials.
Variance and standard deviation
Variance is in squared units; standard deviation returns to the original unit. Two Agents can have the same average score while one fails severely on occasion, giving it greater variance and tail risk. An engineering choice should not depend only on the mean.
Sample variance commonly uses :
This is a common unbiased estimator of population variance. When describing the complete population currently in hand, a denominator of can be appropriate; state the context.
Covariance and correlation
The correlation coefficient is normalized to :
If two Agents fail together on the same hard tasks, their outcomes are positively correlated. A paired comparison must preserve this correspondence; independently shuffling A and B scores loses information. Correlation does not establish causation, and it directly describes only linear association.
Sampling and standard error
A population is the complete set of entities of interest, and a sample is the part actually observed. The sample mean is itself a random variable. If observations are independent and identically distributed with finite variance, its standard error is approximately:
Quadrupling the sample size roughly halves standard error; it does not reduce it by a factor of four. Large numbers of repeated or highly correlated observations do not add information at the rate of independent observations.
Bias and variance
- Sampling bias: an evaluation contains only short English question-answer tasks but is generalized to long Chinese tool-use tasks.
- Measurement bias: a grader systematically favors one writing style.
- Random variation: a metric naturally varies when you draw another representative task set.
More samples can reduce random error, but they cannot repair systematic bias. Define the target population and sampling frame before discussing sample size.
Uses in ML, retrieval, and evaluation
- A mini-batch gradient is a noisy estimate of the full gradient; batch size affects variance and cost.
- Comparing two retrievers on the same queries is a paired design and is usually more efficient than using two different query sets.
- Random assignment in an online A/B test helps reduce confounding, but you still must check exposure, missing data, and interference.
- Repeated stochastic-generation evaluations can estimate output variation; do not keep only the best run.
A verifiable example
from statistics import mean, stdev
scores = [1, 1, 0, 1, 0, 1, 1, 1]
print("mean", mean(scores))
print("sample sd", stdev(scores))
print("SE", stdev(scores) / len(scores) ** 0.5)Exercises and self-check
- Construct two sets of 0-to-1 scores with the same mean of 0.8 and different variance.
- Explain why an A–B difference on the same task is better suited to a paired comparison than two independently sampled group means.
- I can distinguish standard deviation from standard error.
- I know that more samples cannot remove selection bias.
- I preserve the pairing structure.
References
NIST Measures of Scale and Python statistics, checked on 2026-07-14. Previous: Random variables and common distributions | Next: Estimation, confidence intervals, and hypothesis testing.