Contents
, where are i.i.d. with mean and variance
Deep Breakdown
What it tells me (Situation Awareness): The sample mean is itself a random variable: draw a different sample and you get a different average. Its distribution across all possible samples is the sampling distribution of the mean. Two facts hold for any i.i.d. data, whatever its shape: it is centred on the true mean (, so is unbiased), and its spread shrinks with sample size as . The standard deviation of this distribution, , is the standard error, the yardstick for how far a single sample average typically lands from the truth. The square root is the crucial (and expensive) part: to halve the error you need four times the data. If the data are Normal, is exactly Normal; otherwise the Central Limit Theorem makes it approximately Normal for large . In DA/DS: standard errors and confidence intervals for averages (AOV, revenue per user, session length); A/B test power and sample-size calculations; deciding how many survey responses or labelled examples are enough; understanding why mini-batch gradient noise falls with batch size; reading error bars on dashboards.
Flowchart
Real-world use
Where it is used
Confidence intervals for any average KPI; A/B test z-tests and t-tests (difference of two sample means); sample-size and power planning; polling and survey margins of error; quality control charts ( charts with limits ); mini-batch SGD (gradient estimate variance scales as ); Monte Carlo error estimates.
Problem it solves
A single sample average is an estimate, not the truth. Without knowing how much it would vary from sample to sample, you cannot tell a real lift from noise or decide how much data to collect.
How it solves the problem
Linearity of expectation gives . Independence makes variances add: , and scaling by divides the variance by , giving . This turns "how reliable is my average?" into a closed-form number.
Example in a business
An e-commerce analyst measures average order value with known historical USD. With orders, USD, so a 95% interval is roughly USD, too wide to detect a 5 USD change from a checkout redesign. To get USD (a fourfold reduction) the team needs orders per arm.
The formula, piece by piece
- : the -th observation (e.g. one order's value), a random variable.
- : sample size.
- : the sample mean, the statistic whose distribution we study.
- : the population (true) mean.
- : the population variance of a single observation.
- : unbiasedness; on average across samples, hits the target.
- : variance falls in proportion to .
- : standard deviation of , in the same units as the data; in practice estimated by with the sample standard deviation .
The formula in words
"The average of independent draws is right on target on average, and its typical error is the spread of one draw divided by the square root of ." Tiny example: , gives ; quadrupling to gives , half the error.
Critical Concepts
- Standard deviation vs standard error: (or ) describes variability of individual customers; describes uncertainty in the average. Error bars on a KPI chart should use the SE (or a CI), not the SD.
- Square-root law: precision grows as , so diminishing returns are severe. Going from 1,000 to 100,000 users only cuts the SE by a factor of 10.
- Requires independence: with correlated data (multiple orders per customer, clustered users), the true variance is larger than ; the design effect for clusters of size with intra-cluster correlation quantifies the inflation.
- Shape of the distribution: exactly Normal if the data are Normal; approximately Normal for large by the CLT; for small with unknown use the -distribution with degrees of freedom.
- Finite population: sampling without replacement from units multiplies the variance by .
- Difference of means (A/B tests): , the basis of the two-sample z-test.
- Variance reduction: CUPED and stratification reduce itself (by using pre-experiment covariates), which is often cheaper than increasing .
Step-by-step calculation (tiny example)
Average order value: USD, USD, sample of orders.
Step 1: Expected value of the sample mean USD.
Step 2: Variance of the sample mean .
Step 3: Standard error USD.
Step 4: Approximate 95% range of sample means USD.
Step 5: Sample size for SE of 2.5 USD orders.
Code examples
Beginner example (Python)
import math
mu, sigma, n = 80.0, 60.0, 36
var_mean = sigma**2 / n
se = math.sqrt(var_mean)
print("E[X_bar] =", mu) # 80.0
print("Var(X_bar) =", var_mean) # 100.0
print("SE =", se) # 10.0
print("95% range:", round(mu - 1.96 * se, 1), "to", round(mu + 1.96 * se, 1)) # 60.4 to 99.6
print("n for SE = 2.5:", round((sigma / 2.5) ** 2)) # 576Beginner example (R)
mu <- 80; sigma <- 60; n <- 36
se <- sigma / sqrt(n)
cat("SE =", se, "\n") # 10
cat("95% range:", mu - 1.96 * se, mu + 1.96 * se, "\n") # 60.4 99.6
set.seed(1)
means <- replicate(10000, mean(rexp(n, rate = 1 / 80)))
cat("Simulated mean:", mean(means), " simulated SE:", sd(means), "\n")Professional example (Python)
import numpy as np
rng = np.random.default_rng(42)
# Skewed "population" of order values: exponential with mean 80 (so sigma = 80)
mu_true, sigma_true = 80.0, 80.0
n_reps = 20_000
print(f"{'n':>5} {'mean of X_bar':>14} {'empirical SE':>13} {'theory sigma/sqrt(n)':>21}")
for n in [4, 16, 64, 256]:
samples = rng.exponential(scale=mu_true, size=(n_reps, n))
x_bar = samples.mean(axis=1)
print(f"{n:>5} {x_bar.mean():>14.2f} {x_bar.std(ddof=1):>13.2f} "
f"{sigma_true / np.sqrt(n):>21.2f}")
# In practice sigma is unknown: estimate SE from ONE sample with s / sqrt(n)
one_sample = rng.exponential(scale=mu_true, size=400)
se_hat = one_sample.std(ddof=1) / np.sqrt(one_sample.size)
print(f"\nOne sample of 400: mean = {one_sample.mean():.2f}, "
f"estimated SE = {se_hat:.2f} (theory {sigma_true / 20:.2f})")Source: domain knowledge