Draw ten adults at random, with replacement, from the 5,247 adults with a blood pressure reading in the National Health and Nutrition Examination Survey (NHANES) of 2017 to 2018, and average their systolic pressures. How often is that average 140 mm Hg or more? Simulating 10,000 such groups with one random seed gives 0.0247, and with the next seed 0.0226. The exact answer, which the article's script computes by convolution, is 0.0237. How far from the truth can a simulation be expected to land, how should 30 runs of it be read, and how can the same computing time buy a more accurate answer? For the rarer event that the average reaches 160 mm Hg, whose probability is $7.87 \times 10^{-6}$, 10,000 simulated groups see nothing at all in 29 of 30 seeds, and the question becomes how to estimate a probability that plain simulation almost never observes.
Monte Carlo integration estimates an expected value, which is a sum or an integral, by the average of the quantity over independent random draws. Importance sampling draws from a different distribution, chosen to put the draws where they matter, and corrects by weighting each draw with the ratio of the two probabilities. The site's simulations, from the coverage checks of the course pages to the bootstrap and the samplers of Markov Chain Monte Carlo, are all Monte Carlo integration, and this article is the home of its theory: later articles that report a Monte Carlo standard error or a median over seeds build on the results here.
First we define the estimator and prove its unbiasedness, its variance and its central-limit interval. Then we ask what the site's convention, seeded experiments with 30 runs summarized by a median and interquartile range, measures and what it leaves out. Next come three ways of spending the same draws more efficiently: antithetic variates, control variates and stratification, each with its variance proved and measured exactly on the blood pressures. Then importance sampling: its variance, the optimal proposal, a bound for exponential tilting that turns the rare event into a routine computation, the self-normalized estimator and its bias, and the effective sample size. Last, the rare events of model evaluation. The article assumes Expectation, Variance and Covariance, The Laws of Large Numbers and Convergence in Distribution and the Proof of the Central Limit Theorem. Probability Fundamentals introduces simulation in NumPy and the binomial Monte Carlo error; this article goes beneath it.
The Monte Carlo estimator
Many quantities are expectations. A probability is the expected value of an indicator, an integral over an interval is an expected value under the uniform distribution, and a property of a sampling distribution is an expected value over the samples. Write the quantity as
$$\theta = E[f(X)] = \sum_x f(x)\,p(x) \quad\text{or}\quad \theta = \int f(x)\,p(x)\,dx,$$
where $X$ is a random variable (or vector) with mass function or density $p$, and $f$ is a real function. In the running example $X = (X_1, \ldots, X_{10})$ is the vector of ten pressures drawn independently from the 5,247 adults, so $p$ gives probability $(1/5{,}247)^{10}$ to each ordered choice of ten adults, and $f(X) = \mathbf{1}\{\bar X \ge 140\}$, where $\bar X$ is the mean of the ten. Then $\theta_{140} = P(\bar X \ge 140) = 0.0237$. An integral $\int_a^b g(u)\,du$ is the case $\theta = (b - a)E[g(U)]$ with $U$ uniform on $[a, b]$.
The Monte Carlo estimator draws $X_1, \ldots, X_n$ independently from $p$ (here each $X_i$ is one simulated group of ten) and averages:
$$\hat\theta_n = \frac{1}{n}\sum_{i=1}^n f(X_i).$$
Theorem 1 (the Monte Carlo estimator). Let $X_1, X_2, \ldots$ be independent and identically distributed (i.i.d.) with the distribution of $X$, and suppose $E\lvert f(X)\rvert < \infty$.
- $E[\hat\theta_n] = \theta$ for every $n$.
- $\hat\theta_n \xrightarrow{\text{a.s.}} \theta$ as $n \to \infty$.
- If also $\sigma^2 = \operatorname{Var}(f(X))$ is finite, then $\operatorname{Var}(\hat\theta_n) = \sigma^2/n$, and with $s_n$ the sample standard deviation of $f(X_1), \ldots, f(X_n)$ and $\sigma > 0$, the interval $\hat\theta_n \pm 1.96\,s_n/\sqrt{n}$ covers $\theta$ with probability tending to 0.95.
The idea: the values $f(X_i)$ are themselves an i.i.d. sample with mean $\theta$, so everything known about sample means applies to them unchanged.
Proof. The variables $Y_i = f(X_i)$ are i.i.d. with mean $\theta$. (1) By linearity of expectation (Expectation, Variance and Covariance, Theorem 3), $E[\hat\theta_n] = \frac1n\sum E[Y_i] = \theta$. (2) is the strong law of large numbers for a finite mean, stated and cited in The Laws of Large Numbers (and proved there under a finite fourth moment, which covers every bounded $f$, such as an indicator). (3) Independent variables are uncorrelated, so the variance of the sum is the sum of the variances, $n\sigma^2$, and dividing by $n^2$ gives $\sigma^2/n$. The coverage statement is Corollary 2 of the central limit theorem article, applied to the $Y_i$. $\square$
Three consequences shape everything that follows.
- The error falls as $1/\sqrt{n}$. The root mean squared error is $\sigma/\sqrt{n}$. One more correct decimal digit needs a hundred times as many draws (Owen, 2013, Section 2.1).
- The rate does not depend on the dimension. Nothing in Theorem 1 refers to the number of coordinates of $X$, which is 10 here and could be thousands. Owen (2013, Section 2.1) contrasts this with Simpson's rule, whose error is of order $n^{-4}$ in one dimension for an integrand with a continuous fourth derivative but whose direct extension to $d$ dimensions has error of order $n^{-4/d}$. Deterministic rules win for smooth low-dimensional integrals; Monte Carlo wins when the dimension is high or the integrand is rough, as an indicator is.
- Precision is a matter of variance. Any change that halves $\sigma^2$ without changing $\theta$ is worth as much as doubling $n$. The second half of this article is about such changes.
Relative error and the sample size it needs. For a probability, $f$ is an indicator and $\sigma^2 = \theta(1 - \theta)$. The relative variance $\sigma^2/\theta^2 = (1 - \theta)/\theta$ is the variance of one draw in units of $\theta^2$, and a 95% interval of half-width $\varepsilon\theta$ needs about
$$n = \frac{z_{0.975}^2\,\sigma^2}{\varepsilon^2\theta^2}$$
draws, where $z_{0.975} = 1.95996$ is the 0.975 quantile of the standard normal distribution (the article's sample sizes use it unrounded; intervals are written with 1.96). For $\theta_{140}$ the relative variance is 41.19, so a 1% relative error needs 1,582,248 groups. For a rare event $(1 - \theta)/\theta \approx 1/\theta$: the draws needed grow like the reciprocal of the probability, which is the problem importance sampling addresses.
Back to the blood pressures. With $n$ = 10,000 groups the estimator has standard deviation $\sqrt{0.0237 \times 0.9763/10{,}000} = 0.00152$ (from the exact $\theta_{140}$). Seed 0 gave 0.0247 with the interval 0.0217 to 0.0277, which covers the truth; seed 1 gave 0.0226. Over the 30 seeds (NumPy's default_rng(131_000_000 + s), $s = 0, \ldots, 29$), the plain estimates had median 0.0239 (interquartile range 0.0226 to 0.0247), and 28 of the 30 intervals covered 0.0237, against the 28.5 expected of intervals with exactly 95% coverage.
What thirty seeds measure
The site's experiments follow one convention: a randomized experiment is run with 30 seeds, stated on the page, and summarized by the median over seeds and the interquartile range, the 25th to 75th percentiles of the 30 results (numpy.percentile's linear interpolation). The convention is easy to over-read. Three layers of randomness are in play, and seeds touch only some of them.
| Layer | Example in this article | Varies across seeds? |
|---|---|---|
| The data as a sample from a larger population | the 5,247 adults are one sample of United States adults | no |
| Samples drawn from the data inside the experiment | the ten adults of each simulated group | yes |
| The finite number of simulated samples per seed | 10,000 groups per seed | yes |
The first row is sampling error in the ordinary statistical sense. Every seed uses the same 5,247 adults, so no amount of reseeding reveals how different the answer would be with a different survey sample. The second and third rows are what the seeds vary. In an experiment that studies a sampling distribution, such as the coverage of an interval, the second row is the object of study and the third is simulation error (or Monte Carlo error), the error that would vanish with infinitely many simulated samples. The spread over seeds of a reported share is that simulation error.
How large is each here? The simulation error of one seed's estimate of $\theta_{140}$ has standard deviation 0.00152, computed above. For the sampling error, the script drew 30 populations of 5,247 adults with replacement from the real ones and computed $\theta_{140}$ exactly in each, with no simulation error at all. Over these resampled populations $\theta_{140}$ had median 0.0236 (interquartile range 0.0224 to 0.0245) and standard deviation 0.0028. So the sampling error of the data, even as this crude resampling measures it, is nearly twice the simulation error of one seed, and the seeds say nothing about it. The resampling treats the adults as an independent sample, which NHANES is not: its clustered and stratified design makes most standard errors larger still, as the design effects of 1.59 to 8.20 in Survey Weights and the Horvitz–Thompson Estimator suggest (those also include the effect of weighting, which the unweighted $\theta_{140}$ here does not have). And because the survey weights are set aside, the 5,247 adults describe the examined sample, not the country.
What the median and the interquartile range estimate. Let $T_1, \ldots, T_{30}$ be the 30 seed-level estimates, independent with a common continuous distribution whose median is $m$. If the estimator is unbiased and its distribution is close to symmetric, as a mean of 10,000 draws is by the central limit theorem, then $m$ is close to $\theta$, and the median of the 30 estimates estimates $m$. The interquartile range estimates the spread of one seed's result: for a normal distribution with standard deviation $\tau$ the quartiles are $\mu \pm 0.674\tau$, so the interquartile range is $1.349\tau$. In the plain run the interquartile range of the 30 estimates was 0.00208, against $1.349 \times 0.00152 = 0.00205$.
Theorem 2 (an interval for the median from ordered seeds). Let $T_{(1)} \le \cdots \le T_{(30)}$ be the ordered results of 30 independent runs with a common distribution, and let $m$ be a median of it: $P(T_i < m) \le 1/2 \le P(T_i \le m)$. For $j < k$,
$$P\big(T_{(j)} \le m \le T_{(k)}\big) \ge \frac{1}{2^{30}}\sum_{i=j}^{k-1}\binom{30}{i},$$
with equality when the distribution is continuous.
The idea: each run falls below $m$ with probability one half, independently, so the number below $m$ is binomial, and $m$ lies between two order statistics exactly when that count lies between their ranks. Ties at $m$, which a share of 10,000 draws can produce, only help.
Proof. Let $B$ be binomial with 30 trials and probability one half, and let $B_{\le}$ and $B_{<}$ count the runs with $T_i \le m$ and with $T_i < m$. Both are binomial, because the runs are independent, with success probabilities at least and at most one half respectively. Now $T_{(j)} \le m$ exactly when at least $j$ runs are at most $m$, that is $B_{\le} \ge j$, and $m \le T_{(k)}$ exactly when fewer than $k$ runs are below $m$, that is $B_{<} \le k - 1$. A binomial count is more likely to be small when its success probability is smaller (generate both counts from the same 30 uniform numbers, counting a success when a uniform falls below the success probability), so $P(B_{\le} < j) \le P(B < j)$ and $P(B_{<} \ge k) \le P(B \ge k)$. The interval fails only if one of these two events occurs, so its coverage is at least $1 - P(B < j) - P(B \ge k) = P(j \le B \le k - 1)$, the sum in the statement. For a continuous distribution no run equals $m$ with probability 1, so $B_{\le} = B_{<}$, which has the distribution of $B$; the two failure events are then disjoint and the inequality is an equality. $\square$
For $j = 10$ and $k = 21$ the probability is 0.957: the 10th and 21st of the 30 ordered results form an interval of at least 95% for the median of the estimator's distribution. The interquartile range, read the same way, covers $m$ with probability between 0.984 and 0.995 (for a continuous distribution: between the probabilities that 9 to 21 and that 8 to 22 of the runs fall below $m$, since numpy.percentile places the quartiles between the 8th and 9th and between the 22nd and 23rd ordered results).
Example (the interquartile range is not a confidence interval for the truth). A tempting reading of "0.0239 (0.0226 to 0.0247)" is that the true value lies between 0.0226 and 0.0247 with probability one half. It does not mean that, in either direction. As an interval for $m$ it is conservative, at 98% to 99.5% by Theorem 2. As a statement about one seed's estimate, roughly half of further seeds would land inside it. And as a statement about $\theta$, it is only as good as the assumption that the estimator is unbiased: a bias shared by every seed, from a biased estimator (such as the self-normalized estimate below), an unconverged sampler or a bug, moves all 30 results together and leaves the interquartile range unchanged. Seeds measure variability, never bias.
Are 30 consecutive seeds independent? The scripts seed NumPy's default generator with consecutive integers, such as default_rng(131_000_000 + s). NumPy's documentation on parallel random number generation says that its SeedSequence, which turns the integer into the generator's state, hashes the seed so that "two input seeds that are very close to each other will produce initial states that are very far from each other (with very high probability)", and it warns against building worker seeds as root_seed + worker_id, because subsets of workers whose seeds coincide "will return identical results" (NumPy Developers, 2026). For the site the practical rule follows: within one script the 30 seeds are distinct and the streams independent with very high probability, but two experiments whose seed ranges overlap reuse identical streams. That is why each script on the site claims its own range of bases.
Antithetic variates
The first way to reduce variance pairs each draw with its mirror image. Here is the idea in one sentence: if a draw that gives a high value is paired with one that tends to give a low value, the pair's average varies less than an average of two independent draws.
Every draw in the running example can be made from uniform numbers. With $Q$ the quantile function of the 5,247 pressures, $Q(U)$ has their distribution when $U$ is uniform on $(0, 1)$ (the inverse transform, Theorem 3 of Random Variables and Distribution Functions). A group is then $g(\mathbf{U}) = f(Q(U_1), \ldots, Q(U_{10}))$ with $\mathbf{U}$ uniform on the unit cube, and since $1 - U$ is also uniform, so is $\mathbf{1} - \mathbf{U}$. The antithetic estimator uses $n/2$ independent uniform vectors and their reflections:
$$\hat\theta_{\text{anti}} = \frac{1}{n}\sum_{i=1}^{n/2}\big[g(\mathbf{U}_i) + g(\mathbf{1} - \mathbf{U}_i)\big].$$
Theorem 3 (variance of antithetic sampling). Let $n$ be even. If $\sigma^2 = \operatorname{Var}(g(\mathbf{U}))$ is finite and $\rho = \operatorname{Corr}(g(\mathbf{U}), g(\mathbf{1} - \mathbf{U}))$, then $\hat\theta_{\text{anti}}$ is unbiased and
$$\operatorname{Var}(\hat\theta_{\text{anti}}) = \frac{\sigma^2}{n}(1 + \rho).$$
Proof. Each term has mean $\theta$ because $\mathbf{1} - \mathbf{U}$ has the distribution of $\mathbf{U}$. The $n/2$ pairs are independent, so the variance is $\frac{n}{2}\cdot\frac{1}{n^2}\operatorname{Var}(g(\mathbf{U}) + g(\mathbf{1} - \mathbf{U}))$. The variance of the sum is $\sigma^2 + \sigma^2 + 2\rho\sigma^2$ (Expectation, Variance and Covariance, Theorem 6), so the total is $\frac{1}{2n}\cdot 2\sigma^2(1 + \rho) = \sigma^2(1 + \rho)/n$. $\square$
The gain is the factor $1 + \rho$, which lies between 0 (the pair's average is constant) and 2 (the mirror image repeats the draw). Owen (2013, Section 8.2) notes that both extremes occur. When is $\rho$ guaranteed to be negative? When $g$ is monotone in every coordinate, by an inequality for independent coordinates.
Lemma (monotone functions of independent coordinates are positively correlated). Let $U_1, \ldots, U_d$ be independent and uniform on $(0, 1)$, and let $a$ and $b$ be functions on the unit cube, each nondecreasing in every coordinate when the others are held fixed, with $E[a(\mathbf{U})^2]$ and $E[b(\mathbf{U})^2]$ finite. Then $\operatorname{Cov}(a(\mathbf{U}), b(\mathbf{U})) \ge 0$.
The plan: one coordinate first, by comparing two independent copies, then induction, conditioning on the last coordinate.
Proof. For $d = 1$ let $V$ be independent of $U$ with the same distribution. For any $u, v$ the differences $a(u) - a(v)$ and $b(u) - b(v)$ have the same sign, because both functions are nondecreasing, so their product is nonnegative. Taking expectations, and using the product rule for the independent $U$ and $V$ (Expectation, Variance and Covariance, Theorem 5),
$$0 \le E\big[(a(U) - a(V))(b(U) - b(V))\big] = 2E[a(U)b(U)] - 2E[a(U)]E[b(U)] = 2\operatorname{Cov}(a(U), b(U)).$$
Suppose the statement holds in dimension $d - 1$, and write $\mathbf{V} = (U_1, \ldots, U_{d-1})$, which is independent of $U_d$. For a fixed $u$ let $A(u) = E[a(\mathbf{V}, u)]$, $B(u) = E[b(\mathbf{V}, u)]$ and $c(u) = E[a(\mathbf{V}, u)\,b(\mathbf{V}, u)] - A(u)B(u)$, the covariance of the two functions with the last coordinate frozen at $u$. Because $\mathbf{V}$ and $U_d$ are independent and $U_d$ is uniform, an expectation over $\mathbf{U}$ is the integral over $u$ of the expectation over $\mathbf{V}$ (Fubini's theorem, which this unit takes as given), so
$$\operatorname{Cov}(a, b) = \int_0^1 E[a(\mathbf{V}, u)b(\mathbf{V}, u)]\,du - \int_0^1 A\,du\int_0^1 B\,du = \int_0^1 c(u)\,du + \Big[\int_0^1 AB\,du - \int_0^1 A\,du\int_0^1 B\,du\Big].$$
This is the law of total covariance of Conditional Expectation (Theorem 4), written for a uniform conditioning coordinate. For each $u$, $a(\cdot, u)$ and $b(\cdot, u)$ are nondecreasing in each of the $d - 1$ independent uniform coordinates of $\mathbf{V}$, so $c(u) \ge 0$ by the induction hypothesis, and the first integral is nonnegative. (The hypothesis needs $a(\cdot, u)$ and $b(\cdot, u)$ square-integrable; since $E[a^2] = \int_0^1 E[a(\mathbf{V}, u)^2]\,du$ is finite, this holds for every $u$ outside a set of length zero, which does not affect the integral.) The function $A$ is nondecreasing, since $a$ is nondecreasing in its last coordinate at every value of the others, and so is $B$; both are square-integrable, because $A(u)^2 \le E[a(\mathbf{V}, u)^2]$ by Jensen's inequality, and likewise for $B$. The bracket is $\operatorname{Cov}(A(U_d), B(U_d))$, which is nonnegative by the case $d = 1$. $\square$
Corollary (antithetic sampling never hurts a monotone integrand). If $g$ is nondecreasing in every coordinate (or nonincreasing in every coordinate), then $\rho \le 0$ and $\operatorname{Var}(\hat\theta_{\text{anti}}) \le \sigma^2/n$. The same holds if $g$ is nondecreasing in some coordinates and nonincreasing in the others: replacing each of the latter $U_k$ by $1 - U_k$, which is again uniform and commutes with the antithetic reflection, makes $g$ nondecreasing in all of them.
Proof. Apply the lemma to $a(\mathbf{u}) = g(\mathbf{u})$ and $b(\mathbf{u}) = -g(\mathbf{1} - \mathbf{u})$, which is nondecreasing in every coordinate when $g$ is. Then $\operatorname{Cov}(g(\mathbf{U}), g(\mathbf{1} - \mathbf{U})) = -\operatorname{Cov}(a, b) \le 0$. For $g$ nonincreasing apply this to $-g$. $\square$
On the blood pressures. The indicator that the mean of ten pressures is at least 140 is nondecreasing in each uniform, so the corollary applies, but it guarantees little: one run of 1,000,000 antithetic pairs (seed 131,090,000) gave a correlation of $-0.024$, a variance factor of 0.976. Over 30 seeds of 5,000 pairs the estimates had median 0.0238 (interquartile range 0.0227 to 0.0245). An indicator of a tail is far from linear in the inputs, and most reflected groups fall below 140 whether or not the original group was above it. Owen (2013, Section 8.2) makes the same point: monotonicity guarantees $\rho \le 0$ but says nothing about its size. Worked problem 1 shows the other extreme.
Example (antithetic sampling can nearly double the variance). The event that the mean of ten lies 10 mm Hg or more from the population mean, in either direction, has probability 0.1128. Its indicator is not monotone: a group far above the mean reflects into a group far below it, so the pair agrees. The 1,000,000 pairs gave a correlation of 0.616 for this event, so antithetic sampling multiplies the variance by 1.62. Antithetic variates help when the integrand is close to an odd function about the center of the distribution and hurt when it is close to an even one (Owen, 2013, eq. 8.4).
Control variates
The second method uses a quantity whose expectation is known exactly. The mean of the ten pressures is such a quantity: its expectation is the population mean, 126.36 mm Hg, and its variance is the population variance 405.01 divided by 10. Groups whose mean is unusually high are more likely to reach 140, so the observed excess of $\bar X$ over 126.36 says which way the simulation has erred.
Let $h(X)$ have known mean $\mu_h$. The control variate estimator with coefficient $\beta$ is
$$\hat\theta_\beta = \frac{1}{n}\sum_{i=1}^n\big[f(X_i) - \beta\,(h(X_i) - \mu_h)\big].$$
Theorem 4 (control variates). For every fixed $\beta$, $\hat\theta_\beta$ is unbiased with variance $\frac1n\big[\operatorname{Var}(f) - 2\beta\operatorname{Cov}(f, h) + \beta^2\operatorname{Var}(h)\big]$, writing $f$ and $h$ for $f(X)$ and $h(X)$. The variance is smallest at $\beta^* = \operatorname{Cov}(f, h)/\operatorname{Var}(h)$, where it equals $\frac{\sigma^2}{n}(1 - \rho^2)$ with $\rho = \operatorname{Corr}(f, h)$.
Proof. The correction term has expectation $\beta(E[h] - \mu_h) = 0$, so the estimator is unbiased. Each summand is $f - \beta h$ plus a constant, whose variance is $\operatorname{Var}(f) - 2\beta\operatorname{Cov}(f, h) + \beta^2\operatorname{Var}(h)$ by the variance of a linear combination; independence of the draws divides it by $n$. This is a quadratic in $\beta$ with positive leading coefficient, minimized where its derivative $-2\operatorname{Cov}(f, h) + 2\beta\operatorname{Var}(h)$ vanishes, at $\beta^*$. Substituting, the bracket becomes $\operatorname{Var}(f) - \operatorname{Cov}(f, h)^2/\operatorname{Var}(h) = \operatorname{Var}(f)(1 - \rho^2)$. $\square$
Any correlation helps, positive or negative, and the gain depends only on $\rho^2$. In practice $\beta^*$ is unknown and is estimated by the least-squares slope of the $f(X_i)$ on the $h(X_i)$, from the same draws. That makes the estimator slightly biased in general; Owen (2013, Section 8.9) calls the bias usually small, and its end notes cite Avramidis and Wilson (1993) for a split-sample version that removes it.
On the blood pressures. From the exact distribution of the sum of ten pressures, $\operatorname{Cov}(\mathbf{1}\{\bar X \ge 140\}, \bar X) = 0.3941$, and $\operatorname{Var}(\bar X) = 405.01/10 = 40.50$, so $\beta^* = 0.00973$ and the correlation is $\rho = 0.407$. The variance factor $1 - \rho^2$ is 0.834: the control variate is worth 20% more draws. With $\beta$ estimated in each seed, the 30 control variate estimates had median 0.0234 (interquartile range 0.0228 to 0.0241).
Stratification
The third method divides the possible draws into groups, called strata, whose probabilities are known, and samples a fixed number from each. Variation between strata then contributes nothing, because each stratum's share of the sample is set by design instead of by chance.
Let the sample space be split into strata $1, \ldots, J$ with known probabilities $\pi_j$, let $\theta_j = E[f(X) \mid \text{stratum } j]$ and $\sigma_j^2 = \operatorname{Var}(f(X) \mid \text{stratum } j)$, so that $\theta = \sum_j \pi_j\theta_j$. Draw $n_j \ge 1$ points independently from the conditional distribution in stratum $j$, independently across strata, and let $\bar f_j$ be their average. The stratified estimator is $\hat\theta_{\text{strat}} = \sum_j \pi_j \bar f_j$.
Theorem 5 (stratified sampling).
- $\hat\theta_{\text{strat}}$ is unbiased, with $\operatorname{Var}(\hat\theta_{\text{strat}}) = \sum_j \pi_j^2\sigma_j^2/n_j$.
- With proportional allocation, $n_j = n\pi_j$, the variance is $\frac1n\sum_j\pi_j\sigma_j^2$, which is at most $\sigma^2/n$; the difference is $\frac1n\sum_j\pi_j(\theta_j - \theta)^2$, the between-strata variance.
- Among allocations with $\sum_j n_j = n$ (treated as real numbers), the variance is smallest, if every $\sigma_j > 0$, for Neyman allocation, $n_j \propto \pi_j\sigma_j$, where it equals $\frac1n\big(\sum_j \pi_j\sigma_j\big)^2$.
The idea of the second part: plain sampling pays for two sources of variation, within strata and between them, and proportional allocation removes the second.
Proof. (1) $E[\bar f_j] = \theta_j$, so $E[\hat\theta_{\text{strat}}] = \sum_j\pi_j\theta_j = \theta$. The $\bar f_j$ are independent with variances $\sigma_j^2/n_j$ by Theorem 1, and the variance of the weighted sum is $\sum_j\pi_j^2\sigma_j^2/n_j$. (2) Substituting $n_j = n\pi_j$ gives $\frac1n\sum_j\pi_j\sigma_j^2$. Let $Z$ be the stratum of $X$. By the law of total variance (Conditional Expectation, Theorem 3), $\sigma^2 = E[\operatorname{Var}(f \mid Z)] + \operatorname{Var}(E[f \mid Z]) = \sum_j\pi_j\sigma_j^2 + \sum_j\pi_j(\theta_j - \theta)^2$. (3) Apply the Cauchy–Schwarz inequality (Probability Inequalities) to $X = \pi_K\sigma_K/\sqrt{n_K}$ and $Y = \sqrt{n_K}$, where the stratum index $K$ is chosen uniformly at random from the $J$ strata; multiplying both sides of $(E[XY])^2 \le E[X^2]E[Y^2]$ by $J^2$ gives the finite-sum form. For any positive $n_j$ with $\sum_j n_j = n$,
$$\Big(\sum_j\pi_j\sigma_j\Big)^2 = \Big(\sum_j\frac{\pi_j\sigma_j}{\sqrt{n_j}}\sqrt{n_j}\Big)^2 \le \Big(\sum_j\frac{\pi_j^2\sigma_j^2}{n_j}\Big)\Big(\sum_j n_j\Big),$$
so $\sum_j\pi_j^2\sigma_j^2/n_j \ge \frac1n(\sum_j\pi_j\sigma_j)^2$, with equality when $\sqrt{n_j}$ is proportional to $\pi_j\sigma_j/\sqrt{n_j}$, that is when $n_j \propto \pi_j\sigma_j$. $\square$
The same algebra in a finite population, sampling without replacement, is the subject of Survey Sampling Designs; in Monte Carlo the draws within a stratum are independent, so no finite population correction appears. Owen (2013, Section 8.4) gives the Monte Carlo version, with costs that differ by stratum.
On the blood pressures. A natural stratifying variable is the number $L$ of adults aged 60 or over among the ten. Of the 5,247 adults, 1,923 are aged 60 or over, so $L$ is binomial with 10 trials and probability $1{,}923/5{,}247$, and its distribution is known exactly. Within stratum $L = j$ a group is $j$ adults drawn from the older adults and $10 - j$ from the younger. The script computes each $\theta_j$ exactly by convolution: the probability of a mean of 140 or more is 0.0011 when none of the ten is 60 or over (a stratum of probability $\pi_0 = 0.0104$), 0.0368 when five are, and 0.3078 when all ten are. Yet the gain is small. Of the variance of one indicator, $\theta(1 - \theta) = 0.02314$, the within-strata part is 0.02254 and the between-strata part only 0.00060, so proportional allocation keeps a fraction 0.974 of the variance. Age explains little of whether ten random pressures average 140, because the within-group variation of pressure dominates. Neyman allocation does better, by sending more groups to the strata with many older adults, where $\theta_j(1 - \theta_j)$ is larger.
What the experiment shows
Each method spent 10,000 groups per seed on $\theta_{140}$. Proportional allocation, rounded to integers with at least two groups in every stratum, used 10,002 groups; Neyman allocation used 10,001, with 2 in the stratum of ten older adults. The first column gives the variance relative to plain Monte Carlo with 10,000 groups, for the integer allocations actually used (per group, proportional allocation keeps 0.974, as above), from the exact distributions except for the antithetic correlation, which was estimated from 1,000,000 pairs.
| Method | Variance relative to plain | Median over 30 seeds (IQR) |
|---|---|---|
| plain Monte Carlo | 1 | 0.0239 (0.0226 to 0.0247) |
| antithetic variates | 0.976 | 0.0238 (0.0227 to 0.0245) |
| control variate $\bar X$ | 0.834 | 0.0234 (0.0228 to 0.0241) |
| strata by age, proportional | 0.973 | 0.0239 (0.0227 to 0.0251) |
| strata by age, Neyman | 0.798 | 0.0237 (0.0227 to 0.0251) |
The exact value is 0.0237. The Neyman figure, 0.798, is also its limit for real-valued allocations.
Example (thirty seeds do not rank close methods). In the left panel the Neyman estimates look no tighter than the plain ones, and their standard deviation over seeds was in fact larger, although the exact variance is 20% smaller and the exact standard deviation 11% smaller. A standard deviation estimated from 30 values is itself noisy. For normal data the sample variance of $n$ values has approximate relative standard deviation $\sqrt{2/n}$ (Corollary 2 of The Delta Method, with kurtosis 3), so by the delta method once more the sample standard deviation has approximate relative standard deviation $1/\sqrt{2n}$, which is 0.129 for $n = 30$, and the ratio of two independent ones about $\sqrt{2}$ times that, 0.18. A difference of 11% cannot be seen in 30 seeds. The exact variances in the table are the reliable comparison; the seeds confirm only that every method is centered on 0.0237. When an article on this site compares two methods by the spread of 30 seeds, the comparison is itself an estimate.
All three methods give modest gains on this problem, because the event is a tail and none of the known quantities predicts it well. For a rare event the remedy has to change where the draws fall.
Importance sampling
For $\theta_{160} = P(\bar X \ge 160) = 7.87 \times 10^{-6}$, plain Monte Carlo with 10,000 groups expects 0.079 events, and the probability that it sees none is 0.924. In the experiment (seeds $131{,}040{,}000 + s$) 29 of the 30 seeds saw no group at all, and each reported an estimate of 0. The relative variance of one indicator is 127,085, and a 10% relative error would need 48.8 million groups.
Importance sampling rewrites the expectation under a proposal distribution $q$ that produces the event often. Wherever $q(x) > 0$ whenever $f(x)p(x) \neq 0$,
$$\theta = \sum_x f(x)p(x) = \sum_x f(x)\frac{p(x)}{q(x)}q(x) = E_q\big[f(X)w(X)\big], \qquad w(x) = \frac{p(x)}{q(x)},$$
with sums replaced by integrals for densities. The ratio $w$ is the likelihood ratio or weight, and $E_q$, $\operatorname{Var}_q$ denote moments when $X$ has distribution $q$. The importance sampling estimator draws $X_1, \ldots, X_n$ independently from $q$:
$$\hat\theta_q = \frac1n\sum_{i=1}^n f(X_i)w(X_i).$$
Theorem 6 (importance sampling). If $q(x) > 0$ wherever $f(x)p(x) \neq 0$, then $E_q[\hat\theta_q] = \theta$ and
$$\operatorname{Var}_q(\hat\theta_q) = \frac{\sigma_q^2}{n}, \qquad \sigma_q^2 = E_q\big[f(X)^2w(X)^2\big] - \theta^2 = E_p\big[f(X)^2 w(X)\big] - \theta^2.$$
Proof. Points with $q(x) = 0$ are never drawn and have $f(x)p(x) = 0$, so they contribute nothing to $\theta$; the identity above therefore holds with the sum over points where $q > 0$, and each term $f(X_i)w(X_i)$ has mean $\theta$. Theorem 1 applied to the i.i.d. values $f(X_i)w(X_i)$ gives the variance with $\sigma_q^2 = E_q[(fw)^2] - \theta^2$. Finally $E_q[f^2w^2] = \sum_x f(x)^2\frac{p(x)^2}{q(x)^2}q(x) = \sum_x f(x)^2 w(x)p(x) = E_p[f^2w]$. $\square$
The last form shows the danger: wherever $q$ is much smaller than $p$, the weight is large, and if $f$ is not small there, the variance explodes. A proposal must not have lighter tails than $p$ where $f$ matters (Owen, 2013, Section 9.1).
Theorem 7 (the optimal proposal). Suppose $E_p\lvert f(X)\rvert > 0$. Among proposals with $q > 0$ wherever $fp \neq 0$, the variance $\sigma_q^2$ is smallest for
$$q^*(x) = \frac{\lvert f(x)\rvert\,p(x)}{E_p\lvert f(X)\rvert},$$
where $\sigma_{q^*}^2 = (E_p\lvert f(X)\rvert)^2 - \theta^2$. If $f \ge 0$, then $q^* = fp/\theta$ and $\sigma_{q^*}^2 = 0$: every draw returns $\theta$ exactly.
The idea: the variance is a mean square of $\lvert f\rvert w$ under $q$, which can never be less than the square of its mean, and that mean, $E_p\lvert f\rvert$, does not depend on $q$; equality needs $\lvert f\rvert w$ constant, which is $q^*$.
Proof. For any admissible $q$, $E_q[\lvert f\rvert w] = \sum_x\lvert f(x)\rvert p(x) = E_p\lvert f\rvert$, by the same cancellation as in Theorem 6. By the Cauchy–Schwarz inequality (or because a variance is nonnegative), $E_q[f^2w^2] \ge (E_q[\lvert f\rvert w])^2 = (E_p\lvert f\rvert)^2$. So $\sigma_q^2 \ge (E_p\lvert f\rvert)^2 - \theta^2$ for every $q$. Under $q^*$, $\lvert f(x)\rvert w(x) = \lvert f(x)\rvert p(x)/q^*(x) = E_p\lvert f\rvert$ wherever $q^*(x) > 0$, a constant, so the bound is attained. If $f \ge 0$ then $E_p\lvert f\rvert = \theta$ and the minimum is 0. $\square$
Owen (2013, Section 9.1 and its end notes) attributes the optimality of $q \propto \lvert f\rvert p$ to Kahn and Marshall (1953), and two very early descriptions of importance sampling to Kahn (1950). The zero-variance proposal is useless as an algorithm, since its normalizing constant is $\theta$ itself, but it says what a good proposal looks like. For a probability, $f = \mathbf{1}_A$ and $q^* = p(\cdot \mid A)$: the ideal proposal is the original distribution conditioned on the event. A good proposal puts nearly all its mass on the event, and within the event it keeps the shape of $p$.
Exponential tilting
Conditioning ten draws on a mean of 160 or more is hard to do directly. Exponential tilting approximates it with independent draws. Replace the uniform choice of an adult by the tilted probabilities
$$q_t(x_k) = \frac{e^{t x_k}}{\sum_{l} e^{t x_l}}, \qquad k = 1, \ldots, 5{,}247,$$
for a constant $t > 0$, which favor adults with high pressures, and draw the ten adults independently from $q_t$. Write $M(t) = \frac{1}{5{,}247}\sum_k e^{t x_k}$ for the moment generating function of one draw under $p$. One draw has weight $p/q_t = M(t)e^{-tx}$, and a group with sum $S$ of its ten pressures has weight $w = M(t)^{10}e^{-tS}$, which depends on the group only through $S$. Choosing $t$ so that the tilted mean $\sum_k x_kq_t(x_k)$ equals 160 places the typical tilted group at the edge of the event. Owen (2013, Section 9.6) describes tilting as a change of parameter in an exponential family; here the family is generated from an arbitrary finite distribution, and the tilt is the same one the Chernoff bound uses.
Theorem 8 (the variance of a tilted estimator is bounded by the Chernoff bound). Let $X_1, \ldots, X_m$ be i.i.d. with moment generating function $M$ finite at $t > 0$, let $A = \{S \ge mc\}$ for their sum $S$, let $\theta = P(A)$, and let $q$ draw each $X_i$ from the tilted distribution, so that $w = M(t)^m e^{-tS}$. Then the importance sampling estimator of $\theta$ from one tilted group has
$$E_q\big[(w\mathbf{1}_A)^2\big] \le M(t)^m e^{-tmc}\,\theta, \qquad\text{so}\qquad \frac{\sigma_q^2}{\theta^2} \le \frac{M(t)^m e^{-tmc}}{\theta} - 1.$$
Proof. By Theorem 6, $E_q[(w\mathbf{1}_A)^2] = E_p[w\mathbf{1}_A]$. On $A$, $S \ge mc$ and $t > 0$, so $w = M(t)^m e^{-tS} \le M(t)^m e^{-tmc}$. Hence $E_p[w\mathbf{1}_A] \le M(t)^m e^{-tmc}P(A)$. Subtract $\theta^2$ and divide by $\theta^2$. $\square$
The constant $M(t)^m e^{-tmc}$ is exactly the Chernoff bound on $\theta$ (Probability Inequalities, "Chernoff bound", applied to the sum, whose moment generating function is $M(t)^m$). So the relative variance of the tilted estimator is at most the ratio of the Chernoff bound to the true probability, minus 1. Plain Monte Carlo has relative variance about $1/\theta$. When the Chernoff bound is within a modest factor of $\theta$, tilting removes almost all of the dependence on the rarity of the event.
On the blood pressures. The tilted mean is 160 at $t$ = 0.0465 per mm Hg. The Chernoff bound there is $1.03 \times 10^{-4}$, thirteen times the true $7.87 \times 10^{-6}$, so Theorem 8 bounds the relative variance by 12.1. The exact relative variance, computed from the distribution of $S$, is 5.80, against 127,085 for plain Monte Carlo: tilting is worth 21,914 times as many plain draws. A 10% relative error needs 2,228 tilted groups instead of 48.8 million, and with 10,000 groups the relative standard error is 0.024. The figure shows how the choice of tilt matters.
The smallest relative variance on the grid, 5.77, is at a tilted mean of 161.0; the choice "tilted mean equal to the threshold" is within 1% of it. Over 30 seeds of 10,000 tilted groups (seeds $131{,}050{,}000 + s$), the importance sampling estimates had median $7.85 \times 10^{-6}$ (interquartile range 7.72 to 8.04, per million), and 28 of the 30 intervals $\hat\theta_q \pm 1.96\,\hat\sigma_q/\sqrt{n}$ covered the truth. A median share 0.492 of the tilted groups fell in the event, close to half.
Self-normalized importance sampling
Often $p$ is known only up to a constant: a posterior distribution, for instance, is a likelihood times a prior divided by an evidence that is hard to compute (Markov Chain Monte Carlo and Variational Inference are other answers to that problem). With unnormalized weights $w_u = c\,w$ for an unknown $c > 0$, the self-normalized estimator
$$\tilde\theta_q = \frac{\sum_{i=1}^n f(X_i)w_u(X_i)}{\sum_{i=1}^n w_u(X_i)} = \frac{\frac1n\sum_i f(X_i)w(X_i)}{\frac1n\sum_i w(X_i)}$$
does not need $c$, which cancels. It is the importance sampling counterpart of the Hájek estimator of survey sampling, which divides a Horvitz–Thompson total by an estimated population size (Survey Weights and the Horvitz–Thompson Estimator proves its error identity and a bound on its bias).
Theorem 9 (self-normalized importance sampling). Suppose $q > 0$ wherever $p > 0$ and $E_p\lvert f\rvert < \infty$.
- $\tilde\theta_q \xrightarrow{\text{a.s.}} \theta$.
- If $E_q[w^2]$ and $E_q[w^2f^2]$ are finite, then $\sqrt{n}(\tilde\theta_q - \theta)$ converges in distribution to the normal distribution with mean 0 and variance $\sigma_{\text{sn}}^2 = E_q\big[w(X)^2(f(X) - \theta)^2\big]$.
- In general $\tilde\theta_q$ is biased.
Proof. (1) The numerator average has mean $\theta$ and the denominator average has mean $E_q[w] = \sum_x p(x) = 1$ (this is where $q > 0$ wherever $p > 0$ is needed, a stronger condition than Theorem 6's). By the strong law both converge almost surely, the numerator to $\theta$ and the denominator to 1, so their ratio converges to $\theta$. (2) The pair of averages $(\bar a, \bar b)$ of $a_i = f(X_i)w(X_i)$ and $b_i = w(X_i)$ satisfies the hypothesis of the delta method for several variables: after centering and scaling by $\sqrt{n}$, every linear combination of the two is asymptotically normal (Corollary 3 of the central limit theorem article). The ratio $g(\bar a, \bar b) = \bar a/\bar b$ (defined as 0 where $\bar b = 0$, which never occurs here because every weight is positive, so that $g$ is defined everywhere as the delta method requires) has gradient $(1, -\theta)$ at $(\theta, 1)$, so by the delta method for several variables (The Delta Method, Theorem 3) the limit is normal with variance $\operatorname{Var}_q(a - \theta b) = E_q[w^2(f - \theta)^2]$, since $a - \theta b = w(f - \theta)$ has mean 0. (3) Worked problem 3 gives a case with $n = 2$ where the expectation is computed exactly and differs from $\theta$. $\square$
Where does the bias come from, and how large is it? A second-order expansion of the ratio about $(\theta, 1)$ gives $\tilde\theta_q - \theta \approx (\bar a - \theta) - \theta(\bar b - 1) - (\bar a - \theta)(\bar b - 1) + \theta(\bar b - 1)^2$. The first two terms have mean 0, and the last two have mean $-\operatorname{Cov}(\bar a, \bar b) + \theta\operatorname{Var}(\bar b)$, which is
$$\operatorname{bias}(\tilde\theta_q) \approx -\frac1n E_q\big[w^2(f - \theta)\big].$$
This is an approximation, not a theorem: the expansion presumes that $\bar b$ is close to 1, which needs $n$ large compared with $E_q[w^2]$, and the remainder has not been bounded here. Owen (2013, Section 9.2) recommends, when $w$ is computable, a regression estimator that uses $w$ as a control variate with known mean 1, which cannot have larger asymptotic variance than either estimator.
On the blood pressures, the tilt that served the ordinary estimator fails the self-normalized one. The same 30 runs of 10,000 tilted groups gave self-normalized estimates with median $11.53 \times 10^{-6}$ (interquartile range 9.01 to 12.88, per million): too high by about 47%, and widely spread. The cause is the denominator. The weight $M(t)^{10}e^{-tS}$ is enormous for groups with low pressures, which the tilted proposal almost never draws, so $E_q[w^2] = E_p[w] = (M(t)M(-t))^{10}$ is 18,304. Its mean is 1, but the draws that would bring the average up to 1 are missing: the mean weight per seed had median 0.681 (interquartile range 0.587 to 0.882). Dividing by it inflates the estimate. The expansion above would predict a relative bias of 1.83 at $n$ = 10,000, which only confirms that $n$ is far too small for it to apply. The ordinary estimator does not divide by the weights, and the indicator multiplies away the large weights outside the event, so it is unaffected.
A defensive mixture repairs it. Draw each group from $p$ with probability one half and from the tilted proposal otherwise. The weight of a group is then $w = 1/(\tfrac12 + \tfrac12 q_t/p)$, at most 2 (Owen, 2013, Section 9.11; its end notes credit defensive mixtures to Hesterberg's dissertation and to Hesterberg, 1995). The exact relative variance of the ordinary estimator rises to 12.60, about twice the pure tilt's, but $E_q[w^2]$ is 1.926. Over 30 seeds (131,060,000 + $s$) the mixture's ordinary estimates had median 7.75 per million (interquartile range 7.57 to 7.94) and its self-normalized estimates 7.80 (7.52 to 7.96), both centered on the truth of 7.87.
The effective sample size
How many equally weighted draws is a weighted sample worth? Suppose the values being averaged had a common variance $\tau^2$ and were uncorrelated, and the weights $w_1, \ldots, w_n$ were fixed. The weighted mean $\sum_i w_iZ_i/\sum_i w_i$ then has variance $\tau^2\sum_i w_i^2/(\sum_i w_i)^2$, the variance of a linear combination of uncorrelated variables. Setting this equal to $\tau^2/n_e$ gives Kish's effective sample size
$$n_e = \frac{\big(\sum_i w_i\big)^2}{\sum_i w_i^2},$$
which Survey Weights and the Horvitz–Thompson Estimator derives for survey weights and Owen (2013, eq. 9.13) uses for importance sampling, where Kong (1992) related it to the efficiency of the self-normalized estimator (as Owen's end notes report). Its population version is $n\,(E_q[w])^2/E_q[w^2] = n/E_q[w^2]$, and since $E_q[w] = 1$, $E_q[w^2] = 1 + \operatorname{Var}_q(w)$: the effective fraction is one over one plus the variance of the weights.
Example (the effective sample size can mislead in both directions). The effective sample size depends on the weights only, not on $f$, and Owen (2013, Section 9.3) warns that it is an imperfect diagnostic. The running example shows both failures.
- Under the pure tilt, the population effective sample size of 10,000 groups is $10{,}000/18{,}304 = 0.55$, and the realized Kish value had median 13. By this diagnostic the sample is worthless, yet the ordinary importance sampling estimate of $\theta_{160}$ has a relative standard error of 0.024. For that $f$ the large weights never matter. The diagnostic is right about the self-normalized estimate, which it was designed for.
- Plain Monte Carlo is importance sampling with $q = p$: every weight is 1 and the effective sample size is the full 10,000. Yet for $\theta_{160}$ the estimate was 0 in 29 of 30 seeds.
Under the defensive mixture the population value is 5,193 and the realized median 5,199, and both estimators work. An effective sample size computed from the weights alone says whether the weights are balanced; whether the draws cover the region that matters for a given $f$ needs the $f$-specific variance of Theorem 6, estimated from the draws, or an exact check like the ones here.
Rare events in model evaluation
The rare-event problem of this article is the one Estimating Rare Event Rates and Forecasting Rare Language Model Behaviors face for language models. A prompt's elicitation probability, the probability that one sampled output shows a behavior, is an expectation over the model's sampling distribution, and estimating it by sampling $K$ outputs is plain Monte Carlo with relative variance $(1 - p)/p$. Jones et al. (2025, Section 4.5) sample 100 outputs per query (500 for some substances) when the behavior must be judged from free text. With $K = 100$, a prompt whose elicitation probability is 0.001 shows no event with probability $0.999^{100} = 0.905$, and its estimate has relative standard error $\sqrt{0.999/(100 \times 0.001)} = 3.16$. For the letter E of Estimating Rare Event Rates, whose average probability is 0.0002037, a 10% relative error by sampling would need 1.89 million samples per prompt.
Three routes appear in the sources, and each is a case of this article's theory.
- Computing the probability exactly, as Estimating Rare Event Rates does from a single forward pass when the behavior is one token, is the zero-variance case of Theorem 7: there is nothing left to sample.
- Importance sampling over outputs or inputs. Jones et al. (2025, Section 4.5) name importance sampling, exploiting knowledge of what harmful outputs look like, as a way to compute elicitation probabilities more cheaply, and leave it to future work. Wu and Hilton (2025) compare importance sampling methods, which search for inputs likely to produce a rare output, with extrapolation from the distribution of the model's logits, on small transformers, and report importance sampling best (abstract). Theorems 6 to 9 are what such methods must respect: a proposal that gives part of the event small probability leaves the estimator unbiased but can make its variance enormous, one that gives part of it probability zero biases it downward, and a self-normalized version can be biased by far more than its spread suggests, as in the tilted run above.
- Extrapolating the tail, the Gumbel-tail method of Jones et al. (2025), replaces sampling with a model of how the largest probabilities grow; its assumptions are examined in Estimating Rare Event Rates.
What is proved here, what is cited, what the experiment shows
Proved here: the unbiasedness, variance and central-limit interval of the Monte Carlo estimator, given the laws of large numbers and the central limit theorem (Theorem 1); the distribution-free interval for the median of 30 runs (Theorem 2); the variance of antithetic sampling (Theorem 3), the positive correlation of coordinatewise monotone functions of independent uniforms by induction, and its corollary that antithetic sampling cannot increase the variance of a monotone integrand; the control variate variance and its optimal coefficient (Theorem 4); the stratified variance, the gain of proportional allocation by the law of total variance, and Neyman allocation by Cauchy–Schwarz (Theorem 5); the unbiasedness and variance of importance sampling (Theorem 6) and its optimal and zero-variance proposals (Theorem 7); the bound of exponential tilting by the Chernoff bound (Theorem 8); the consistency and asymptotic variance of the self-normalized estimator, and its bias in an exact case (Theorem 9 and Worked problem 3); Kish's effective sample size under its model.
Taken from other pages: linearity, the product rule and the variance of a linear combination, from Expectation, Variance and Covariance; the laws of total variance and covariance, from Conditional Expectation; the inverse transform, from Random Variables and Distribution Functions; the Chernoff and Cauchy–Schwarz inequalities, from Probability Inequalities; the strong law, from The Laws of Large Numbers (proved there under a finite fourth moment, cited under a finite mean); the studentized central limit theorem and its vector form, from the central limit theorem article; the multivariate delta method, from The Delta Method.
Cited, not proved: the bias approximation of the self-normalized estimator (derived to second order, remainder not bounded); the smallness of the bias of an estimated control variate coefficient (Owen, 2013, Section 8.9); the error rates of Simpson's rule (Owen, 2013, Section 2.1); the historical attributions to Kahn (1950), Kahn and Marshall (1953), Hammersley and Morton (1956, antithetic variates), Kong (1992) and Hesterberg (1995, defensive mixtures), all as Owen's end notes report them; NumPy's statements about seeding. As in the rest of the unit, measure theory is avoided (Random Variables and Distribution Functions lists what that costs); the induction step of the monotonicity lemma uses Fubini's theorem, which the unit takes as given.
The experiment shows, for the probabilities that ten NHANES pressures average 140 and 160 mm Hg, the exact variances of every method above, and 30 seeded runs of each that agree with them within the noise of 30 seeds. Its statements about which method is better hold for these targets and these strata; the size of each gain is specific to the problem, as the contrast between the monotone and two-sided antithetic examples shows.
Worked problems
These problems were written for this article; none comes from a textbook. Each extends a result above to a case the running example does not cover. The script tools/experiments/statistics/monte-carlo-integration-and-importance-sampling.py computes every number and asserts that the page shows it.
Problem 1 (when antithetic sampling is spectacular). Estimate $\int_0^1 e^u\,du = e - 1 = 1.7183$ by Monte Carlo with $U$ uniform. Compare plain sampling and antithetic pairs at the same number of evaluations of $e^u$, and explain the gain.
Solution. Plain sampling: $E[e^U] = e - 1$ and $E[e^{2U}] = (e^2 - 1)/2$, so $\operatorname{Var}(e^U) = (e^2 - 1)/2 - (e - 1)^2 = 0.2420$. The antithetic pair has $E[e^Ue^{1-U}] = e$, so $\operatorname{Cov}(e^U, e^{1-U}) = e - (e - 1)^2 = -0.2342$, and the correlation is $\rho = -0.2342/0.2420 = -0.9677$. The pair's average $(e^U + e^{1-U})/2$ has variance $\frac14[2 \times 0.2420 + 2 \times (-0.2342)] = 0.00391$. Two plain evaluations have variance $0.2420/2 = 0.1210$, so for the same number of evaluations antithetic sampling reduces the variance by a factor of 30.9, which is $1/(1 + \rho)$ by Theorem 3. The reason is the decomposition of Owen (2013, eq. 8.4): write $e^u$ as an even part $(e^u + e^{1-u})/2$ and an odd part $(e^u - e^{1-u})/2$ about $u = 1/2$. Antithetic sampling removes the odd part's variance and doubles the even part's. The exponential is nearly linear on $[0, 1]$, so nearly all of its variance is odd. By Owen's relation $\rho = (\sigma_E^2 - \sigma_O^2)/(\sigma_E^2 + \sigma_O^2)$, with $\sigma_E^2$ and $\sigma_O^2$ the variances of the even and odd parts, the even share of the variance is $(1 + \rho)/2$. The tail indicator of the running example lies in between: its even share is 0.488, nearly equal to the odd share, so antithetic sampling removes about as much as it adds, and its factor was 0.976. The two-sided event of the example above is mostly even, with share 0.81, and its factor was 1.62.
Problem 2 (a normal tail, and the cost of shifting too far). Estimate $\theta = P(Z > 4)$ for a standard normal $Z$ by importance sampling from the normal with mean $\mu$ and variance 1. Find the relative variance as a function of $\mu$, the best $\mu$, and what happens at $\mu = 6$.
Solution. Here $\theta = 1 - \Phi(4) = 3.167 \times 10^{-5}$, and plain Monte Carlo has relative variance $(1 - \theta)/\theta = 31{,}573$, so a 1% relative error at 95% would need 1.2 billion draws. With $q$ the normal density centered at $\mu$, $w(z) = \phi(z)/\phi(z - \mu) = e^{-\mu z + \mu^2/2}$. By Theorem 6 the second moment is $E_p[w\mathbf{1}\{Z > 4\}] = \int_4^\infty e^{-\mu z + \mu^2/2}\phi(z)\,dz$. Completing the square, $e^{-\mu z}\phi(z) = e^{\mu^2/2}\phi(z + \mu)$, so the integral is $e^{\mu^2}\int_4^\infty\phi(z + \mu)\,dz = e^{\mu^2}(1 - \Phi(4 + \mu))$, and
$$\frac{\sigma_q^2}{\theta^2} = \frac{e^{\mu^2}\big(1 - \Phi(4 + \mu)\big)}{\theta^2} - 1.$$
At $\mu = 4$, the shift that puts the proposal's mean on the threshold, it is 4.51; 173,292 draws then give a 1% relative error. The minimum over $\mu$ is 4.47, at $\mu = 4.12$, a little beyond the threshold, as in the blood-pressure figure. At $\mu = 6$ it is 31.8: the proposal now puts most of its draws far past 4, where $p$ has little mass, while the region just above 4, which holds most of the event's probability, is drawn rarely and with large weights. A proposal can fail by overshooting as well as by missing.
Problem 3 (the exact bias of a self-normalized estimate). Let $p$ put probability one half on each of 0 and 1, let $f(x) = x$, so $\theta = 1/2$, and let $q$ put probability 3/4 on 1 and 1/4 on 0. With $n = 2$ draws from $q$, find the expectations of the ordinary and self-normalized estimators, and compare the bias with the second-order approximation.
Solution. The weights are $w(1) = (1/2)/(3/4) = 2/3$ and $w(0) = (1/2)/(1/4) = 2$. Enumerate the four outcomes. Both draws equal 1, with probability 9/16: the self-normalized estimate is 1. One of each, with probability $2 \times 3/16 = 6/16$: it is $(2/3)/(2/3 + 2) = 1/4$. Both 0, with probability 1/16: it is 0. Its expectation is $9/16 + (6/16)(1/4) = 21/32 = 0.65625$, a bias of $5/32 = 0.15625$. The ordinary estimator $\frac12[f(X_1)w(X_1) + f(X_2)w(X_2)]$ has expectation exactly 1/2, by Theorem 6. The approximation $-\frac1n E_q[w^2(f - \theta)]$ is $-\frac12\big[\tfrac34 \cdot \tfrac49 \cdot \tfrac12 + \tfrac14 \cdot 4 \cdot (-\tfrac12)\big] = -\frac12\big(\tfrac16 - \tfrac12\big) = 1/6 = 0.1667$, close to the exact 0.15625 even at $n = 2$. Here the proposal overweights the outcome where $f$ is large, and dividing by the realized weights pulls the estimate toward that outcome's value: the bias is upward.
Problem 4 (reading another article's seeds). The Laws of Large Numbers reports that the running mean of 100 blood pressures missed the population mean by 2 mm Hg or more in a share 0.3190 of sequences, median over 30 seeds of 1,000 sequences each, with interquartile range 0.3080 to 0.3305. Is the spread what simulation error alone would produce, and what interval does it give for the probability?
Solution. Each seed's share is a binomial proportion out of 1,000. That article gives 0.3203 as the normal approximation to the probability, so one seed's standard deviation is about $\sqrt{0.3203 \times 0.6797/1{,}000} = 0.0148$, and the interquartile range of a normal with that spread is $1.349 \times 0.0148 = 0.0199$. The reported range is $0.3305 - 0.3080 = 0.0225$. A sample interquartile range of 30 values varies a good deal: in a seeded simulation (200,000 sets of 30 normal values with standard deviation 0.0148, seed 131,097,000), its median was 0.0188, and it was 0.0225 or more in a share 0.19 of the sets. The reported range is within that variation: the spread is simulation error. By Theorem 2, the interval from the 10th to the 21st ordered result would cover the median of a seed's distribution, which for a share of 1,000 is essentially the probability, with probability at least 0.957; the interquartile range itself covers it with probability at least 0.984 (between 0.984 and 0.995 if no seed could equal the median exactly). Pooling the 30 seeds would give one share out of 30,000 sequences, with standard deviation $0.0148/\sqrt{30}$; the median and interquartile range are a robust summary, not the most precise one.
Open questions
- Do the site's reported interquartile ranges match their simulation error? Problem 4 checks one row. A script could read every statistics experiment's
data/*.json, compute the binomial or delta-method standard deviation implied by each reported share, and compare it with the reported interquartile range; rows whose spread is far wider than simulation error would point to unstated variability (a resampled dataset, a training run) or a bug. - How much larger is the design-based sampling error of $\theta_{140}$? The 30 resampled populations treat the adults as independent. Resampling NHANES's masked variance units within strata, as Survey Weights and the Horvitz–Thompson Estimator does for its standard errors, would show how far the true sampling error exceeds the 0.0028 found here.
- Can importance sampling estimate free-text elicitation probabilities cheaply? Jones et al. (2025, Section 4.5) propose it and leave it open. A test on this site's evaluation setup: for prompts whose probability of a short target string can be computed exactly (as for the letter E in Estimating Rare Event Rates), compare sampling with a proposal that conditions the model on a prefix of the target, weighting by the ratio of sequence probabilities, against the exact value; the effective sample size and the tilted self-normalized failure above say which diagnostics to report.
- Does randomized quasi-Monte Carlo beat $1/\sqrt{n}$ on the site's smooth simulations? Owen (2013) treats randomized quasi-Monte Carlo in its later chapters and has since revised them as Practical Quasi-Monte Carlo Integration (2023). Rerunning a smooth experiment of this unit, such as a coverage computed from sample means, with scrambled Sobol' points from
scipy.stats.qmcover 30 random scramblings would measure the gain against plain sampling at equal cost.
Summary
| Result | Estimator or quantity | Variance per draw, or statement | Status |
|---|---|---|---|
| Monte Carlo | $\frac1n\sum f(X_i)$ | $\sigma^2$; interval $\pm 1.96\,s_n/\sqrt n$ | proved (limits by link) |
| Median of 30 seeds | $T_{(10)}$ to $T_{(21)}$ | covers the median with probability 0.957 | proved |
| Antithetic | pairs $\mathbf{U}$, $\mathbf{1} - \mathbf{U}$ | $\sigma^2(1 + \rho)$; $\rho \le 0$ if monotone | proved |
| Control variate | $f - \beta(h - \mu_h)$ | $\sigma^2(1 - \rho^2)$ at $\beta^*$ | proved |
| Stratification | $\sum\pi_j\bar f_j$ | $\sum\pi_j\sigma_j^2$ (proportional); $(\sum\pi_j\sigma_j)^2$ (Neyman) | proved |
| Importance sampling | $\frac1n\sum f(X_i)w(X_i)$ | $E_p[f^2w] - \theta^2$; zero at $q \propto fp$ | proved |
| Exponential tilting | tilted draws | relative variance at most Chernoff bound$/\theta - 1$ | proved |
| Self-normalized | $\sum fw/\sum w$ | consistent; $E_q[w^2(f - \theta)^2]$; biased | proved; bias formula approximate |
| Effective sample size | $(\sum w)^2/\sum w^2$ | ignores $f$ | derived under its model |
What we have learned
The Monte Carlo estimator is a sample mean, so it inherits everything proved about sample means: it is unbiased, its variance is $\sigma^2/n$ in any dimension, and its error is approximately normal. The site's 30 seeds measure that simulation error and nothing else. On the blood pressures, one seed's estimate of $\theta_{140}$ varied with standard deviation 0.00152, while the sampling error of the data, which no seed touches, was nearly twice as large; and a bias shared by all seeds is invisible in their spread. Antithetic variates, control variates and stratification each remove a part of $\sigma^2$ that the theorems identify exactly, and on this tail probability they removed between 2% and 20% of it. Importance sampling changed the problem instead: tilting the draws toward high pressures estimated a probability of $7.87 \times 10^{-6}$ with 22,000 times less variance than plain sampling (the Chernoff bound of Theorem 8 guaranteed at least 10,546 times), while the self-normalized estimate from the same draws was biased upward by about 47% and the effective sample size called the sample worthless. The proposal has to be judged by the variance for the quantity being estimated.
The draws here were independent. When independent draws from the target are impossible, a Markov chain that has the target as its stationary distribution supplies dependent ones, and the variance of their average acquires the autocorrelations: that is the subject of Markov Chain Monte Carlo. Resampling the data itself, with the Monte Carlo error of this article stacked on the statistical error of the plug-in estimate, is the subject of The Bootstrap Method and The Plug-In Principle and Why the Bootstrap Works.
Every number in this article is computed by tools/experiments/statistics/monte-carlo-integration-and-importance-sampling.py in the site's repository, which downloads the NHANES files from the CDC and checks their checksums; the figures are drawn by tools/figures/monte-carlo-integration-and-importance-sampling.py.
References
- Avramidis, A. N., and Wilson, J. R. (1993). A splitting scheme for control variates. Operations Research Letters, 14(4), 187–198. https://doi.org/10.1016/0167-6377(93)90069-S Cited as Owen (2013, Chapter 8 end notes) describes it and as its abstract states (an unbiased estimator of the mean response); paper not opened. record
- Hammersley, J. M., and Morton, K. W. (1956). A new Monte Carlo technique: antithetic variates. Mathematical Proceedings of the Cambridge Philosophical Society, 52(3), 449–475. https://doi.org/10.1017/S0305004100031455 Cited for the introduction of antithetic sampling, as Owen (2013, Chapter 8 end notes) reports. record
- Hesterberg, T. (1995). Weighted average importance sampling and defensive mixture distributions. Technometrics, 37(2), 185–194. https://doi.org/10.1080/00401706.1995.10484303 Cited for defensive mixtures, which it proposes in its Section 6.1 with weights bounded by the inverse of the mixing fraction; Owen (2013, Chapter 9 end notes) gives the same credit. record
- Jones, E., Tong, M., Mu, J., Mahfoud, M., Leike, J., Grosse, R., Kaplan, J., Fithian, W., Perez, E., and Sharma, M. (2025). Forecasting rare language model behaviors. arXiv:2502.16797v1. https://arxiv.org/abs/2502.16797 Section 4.5. record · 3 pages
- Kahn, H. (1950). Random sampling (Monte Carlo) techniques in neutron attenuation problems, I and II. Nucleonics, 6(5), 27–37, and 6(6), 60–65. Cited as Owen (2013, Chapter 9 end notes) reports; not opened. record
- Kahn, H., and Marshall, A. W. (1953). Methods of reducing sample size in Monte Carlo computations. Journal of the Operations Research Society of America, 1(5), 263–278. https://doi.org/10.1287/opre.1.5.263 Cited for the optimal importance density, as Owen (2013, Section 9.1) attributes it. record
- Kong, A. (1992). A note on importance sampling using standardized weights. Technical Report 348, Department of Statistics, University of Chicago. Cited as Owen (2013, Chapter 9 end notes) reports; not opened. record
- National Center for Health Statistics (2020). National Health and Nutrition Examination Survey 2017–2018: Demographic Variables and Sample Weights (DEMO_J) and Blood Pressure (BPX_J) data files. Centers for Disease Control and Prevention. https://wwwn.cdc.gov/nchs/nhanes/continuousnhanes/default.aspx?BeginYear=2017 record · 109 pages
- NumPy Developers (2026). Parallel random number generation. NumPy Reference, version 2.5. https://numpy.org/doc/stable/reference/random/parallel.html record
- Owen, A. B. (2013). Monte Carlo Theory, Methods and Examples. https://artowen.su.domains/mc/ Chapter 2 (Sections 2.1, 2.2), Chapter 8 (Sections 8.2, 8.4, 8.9 and end notes; eq. 8.4), Chapter 9 (Sections 9.1, 9.2, 9.3, 9.6, 9.11 and end notes; eq. 9.13). record
- Owen, A. B. (2023). Practical Quasi-Monte Carlo Integration. https://artowen.su.domains/mc/practicalqmc.pdf record
- Wu, G., and Hilton, J. (2025). Estimating the probabilities of rare outputs in language models. In International Conference on Learning Representations (ICLR 2025). https://openreview.net/forum?id=DC8bsa9bzY. arXiv:2410.13211. Abstract. record