Beating the square-root law
The error is sigma over the square root of N. Parts 1 to 3 taught you to buy N - and every halving of the error bar quadruples the bill. This part is about the other letter. Shrink sigma and the same laptop does what a cluster was doing: control variates worth hundreds of times, importance sampling that turns an impossible estimate routine, and points placed so well they beat randomness at its own game.
The scorecard, before anything else
Every technique here reports one number: the variance-reduction factor, measured as the naive variance divided by the technique's variance at equal computational budget. It reads directly as “how many times more naive samples would buy the same accuracy”. A factor of 4 halves your error bars for free, forever. A factor of 683 replaces a compute cluster with a laptop. And a factor below 1 means the technique backfired - which is possible, which happens, and which only the scorecard will catch.
Insisting on that number is the whole discipline of this part. Variance reduction is the one area of simulation where folklore runs thickest - people apply a technique because they read that it helps, never measure whether it helped here, and occasionally ship something worse than what they started with.
Antithetic variates: cancellation by construction
Part 1 left a promissory note: independence makes errors cancel eventually, but engineered negative correlation makes them cancel faster. Here is the redemption, and it costs one line. Simulate in pairs: for every draw Z, also evaluate the payoff at minus Z, and average the pair.
If the payoff is monotone - a call rises with Z - then the two halves of each pair move oppositely, their correlation goes negative, and the pair is worth more than two independent draws. A bonus falls out for free: the pair's average shock is exactly zero, so drift-type errors vanish identically.
Measured on the European call at equal budget: correlation between the halves of a pair, minus 0.31; variance-reduction factor, 1.5. Modest - and that is the honest lesson. Antithetic costs one line and reliably helps on monotone payoffs, but it is a 1.5-to-2 times tool, not a revolution. On a non-monotone payoff - a straddle, anything symmetric in Z - that correlation can turn positive and the factor drops below 1. Cheap, mildly useful, occasionally treacherous. Run the scorecard, always.
Control variates: the professional's favourite weapon
Now the revolution. Suppose you're estimating something and you can find a sidekick variable, computed on the same scenarios, with two properties: it is strongly correlated with your target, and its exact mean is already known in closed form. Then the sidekick's simulation error is visible to you - you can see how far its sample mean landed from the truth you know - and since the two err together, that visible error tells you which way your invisible one went.
The correction has mean zero, so the estimator stays unbiased for any beta - and the optimal beta is a regression slope, because a control variate simply is the regression of your target on its sidekick. Look hard at that shrinkage factor, because it is the whole economics of the technique: a correlation of 0.9 buys 5 times, 0.99 buys 50 times, 0.999 buys 500 times. The entire craft is finding a sidekick that is almost your problem, but solvable.
And Part 3 planted one. The arithmetic Asian option - no formula, our patient - has a near-twin: the geometric Asian, whose payoff uses the geometric average, is lognormal-friendly, and does have a closed form. Arithmetic and geometric averages of the same path are nearly the same number, so the correlation should be enormous. The full liturgy runs in three steps.
- Certify the control. Never bet on a formula you haven't tested. The geometric Asian's closed form says 4.1017; a plain simulation of the same payoff says 4.0898 give or take 0.0243 - inside the interval, formula certified. This step looks like bureaucracy and is the thing that catches a mis-transcribed variance term.
- Measure the friendship. The correlation between the arithmetic and geometric payoffs comes out at 0.99927, with an optimal beta of 1.053. Plug that correlation into the shrinkage formula and it predicts a factor near 700 before you have run a single line of the real estimator.
- Collect. Naive arithmetic-Asian price: 4.34602 give or take 0.02558. Control-variate estimate: 4.35852 give or take 0.00098. Measured variance-reduction factor: 683 times.
Run the scorecard
The same European call, the same computational budget, three estimators. The bars are each method's error bar - the thing you are actually buying. The sidekick here is deliberately mediocre: the terminal price itself, whose exact mean we know, correlates about 0.89 with the payoff. Watch what a merely-good friend buys, then remember the Asian option's near-twin scored 0.99927.
The formula predicts the factor from the correlation alone, before you run anything: one over one minus 0.89 squared is about 4.7 - and that is what the scorecard measures. This is why finding a better sidekick, not buying more compute, is where a professional spends the afternoon.
Stratification, and common random numbers formally filed
Stratification attacks a different inefficiency: pure random sampling clumps. Some regions get oversampled, others missed, and that unevenness is variance. The fix is to partition the input space into strata and allocate samples evenly within each, so that only within-stratum noise survives. Stratifying Part 1's pi estimator into 100 slices along one axis buys 1.4 times - real, cheap and modest, because only one axis of a two-dimensional problem got treated. Its true role in modern practice is as the concept underneath two industrial tools: Latin Hypercube Sampling, which stratifies every input dimension at once and is the default in risk software, and quasi-Monte Carlo below, which is fairly described as stratification taken to its logical extreme.
Common random numbers, which Part 3 already deployed for Greeks at 349 times, deserves formal filing as a general principle: whenever the deliverable is a difference - design A against design B, bumped against unbumped, this year's model against last year's - run both sides on identical randomness and let the covariance term do the work. It costs literally nothing but seed discipline, which Part 1 already made a habit, and it is the highest ratio of benefit to effort in this entire guide.
Importance sampling: hunting rare events
You need the probability that a standard normal exceeds 4.5 - a stand-in for every probability-of-ruin, default, or catastrophic-failure question there is. The truth, computable here precisely because we are practising on a solvable case, is about 3.4 in a million. Naive Monte Carlo with a million draws sees a handful of events, and the error bar comes out as large as the answer itself.
And the scaling is hopeless by design. The relative error of a frequency estimate goes like one over the square root of the expected number of hits, so getting ten thousand hits on a one-in-a-million event means ten billion draws. The disease isn't slow convergence; it is that almost every sample lands in the boring region and contributes nothing but certainty about what you already knew.
The cure is audacious: stop sampling from the true distribution. Sample instead from a proposal that puts its mass where the interesting events live - then correct for the lie, sample by sample, with a likelihood ratio weight.
One line of algebra - multiply and divide by the proposal - and it says: the average of f under the true law equals the average of f times w under the proposal law. Samples from the exciting proposal, each carrying an honest weight that says “I was two hundred times more likely under q than under p, so I count for a two-hundredth of a real sample”, give an exactly unbiased estimator. All the cleverness moves into choosing the proposal.
For normal tails the canonical proposal is a mean shift: sample from a normal centred on the interesting region instead of on zero. With the shift set to 4.5 and the same million samples that failed before, the estimate lands at 3.399 in a million give or take 15 in a billion - a measured variance-reduction factor around 68,000 times, and a naive equivalent of roughly seventy billion samples. This is not an incremental improvement. It is the difference between “cannot be done on this hardware” and “runs in two seconds”, and it is the standard machinery behind rare-event numbers you have seen quoted with a straight face: one-in-a-billion network failure rates, deep value-at-risk quantiles, particle-physics detection significances.
The design pattern that scales: tilt the driver, not everything
Same weapon, finance costume. Ten assets driven by a common market factor plus idiosyncratic noise - Part 3's factor model. Target: the probability the portfolio loses more than half its value, roughly a three-and-a-half sigma crash. Naive at 400,000 draws sees 87 events and returns 2.18 in ten thousand with a 21% relative error.
The move: tilt only the market factor - shift its proposal, weight by that factor's likelihood ratio alone, and leave the ten idiosyncratic streams completely untouched. This is the pattern that scales: in high-dimensional problems, identify the low-dimensional driver of the rare event and tilt just that. Tilting everything wastes proposal budget and destabilises the weights. Result: 2.02 in ten thousand give or take 1.6 in a million, a factor of about 830, obtained by tilting one coordinate out of eleven.
Tilt the dice - and watch the smoke detector
Two hundred thousand draws either way. Naive counts how many happened to land past the threshold; importance sampling shifts the proposal there and pays with weights. The exact answer is known, because we are practising where we can check. Then push the tilt too far and watch the technique fail the way it fails in production: silently, and optimistically.
Aim the proposal at the threshold and importance sampling is a miracle. Aim it far past, and the estimator rides on a hundred-odd samples while claiming a million's worth of authority - the interval stays narrow because it is computed from the samples you got, and the samples you got don't know what they're missing. Report the effective sample size next to every importance-sampling estimate the way you report a standard error next to every mean.
Quasi-Monte Carlo: attacking the exponent itself
Every technique so far accepted the square-root law and fought over the constant. Quasi-Monte Carlo picks the other fight. Look at a few hundred random uniform points on a square: clumps here, bare patches there. That is not a flaw in your generator - equal probability everywhere guarantees clumps, the same way fair coins produce runs.
Stratification fought clumping on a fixed grid. Quasi-Monte Carlo asks the audacious follow-up: why not abandon randomness altogether and place the points deterministically, so that every region contains almost exactly its fair share at every prefix length? Sequences achieving this are called low-discrepancy, and the workhorse is the Sobol sequence. Feed Sobol points into any estimator you would have fed uniforms - through the inverse transform, exactly Part 2's pipeline - and the error falls roughly like one over N instead of one over the square root of N. At a million points, that is the difference between three digits and six.
The measurements. On the European call, sweeping the budget and fitting log-log slopes: pseudo-random comes out at minus 0.49, reassuringly close to the theoretical minus 0.5, while scrambled Sobol comes out at minus 0.83 - not a better constant but a visibly steeper line, pulling away without limit. On the 52-dimensional Asian option - the stress test - Sobol's error is 4.1 times smaller, worth about 17 times fewer samples.
Why it survives 52 dimensions, and when not to bother
The theory's error bound carries a log-N-to-the-d factor that should frighten anyone at dimension 52. It doesn't bite, because the payoff has low effective dimension: the average of a random walk is dominated by a few large-scale features of the path - roughly its overall drift and coarse shape - so most of the integrand's variance lives in a handful of directions, and Sobol's earliest coordinates, which are its best-behaved ones, can be aimed at exactly those. Practitioners sharpen this deliberately by constructing the path with a Brownian bridge, where the first coordinate sets the endpoint and later ones fill in midpoints hierarchically, concentrating variance into the leading coordinates and widening the lead.
When to reach for it, honestly: smooth-ish integrands of moderate-to-high dimension with low effective dimension - derivative pricing being the canonical habitat, which is why banks adopted Sobol decades ago. Where it disappoints: integrands dominated by discontinuities, genuinely high-dimensional structure, and rare-event problems, which are importance sampling's turf. The cost of trying is one line - swap the source of uniforms - and with scrambling, the scorecard tells you immediately whether it paid.
Simulation studies as a science
Part 2's power project simulated tidy trials: independent patients, one per row. Real biostatistics is hierarchical - patients nest inside clinics, students inside schools - and often the unit of randomisation is the cluster, because you cannot give half a clinic a new workflow. Patients who share a clinic share a clinic effect, and even a small intraclass correlation changes everything.
Stage the crime under known truth: six clinics per arm, fifty patients each, an intraclass correlation of 0.05, and no true effect whatsoever. The plain patient-level t-test on 300 against 300 patients - what a hurried analyst reaches for - produces a false-positive rate of 28.8% against a nominal 5%. Not inflated: catastrophic. One in three null studies comes out “significant”. Collapse to cluster means and t-test those six against six, and the false-positive rate is 5.0%, exact.
The mechanism is Part 1's law of large numbers colliding with Part 3's correlation: positively correlated observations are worth fewer than their count, so a standard error computed as if they were independent comes out too small - here by a factor that inflates every t-statistic by about 1.9 times. Same disease as the parallel-seed trap. Same disease as MCMC autocorrelation below. Three costumes, one crime: counting correlated things as if they were independent.
That pattern - simulate the null, take the quantile of the maximum - is worth filing under its general name, because it is how multiple-comparison corrections, scan statistics and permutation-based error control all work. One pattern, half the questions in modern applied statistics. You have already run it on this site from the other end, in the multiple-comparisons case, where the maximum runs across contexts rather than across looks.
A simulation study is an experiment: ADEMP, and sizing it
Close the loop on rigour. A simulation study is an experiment - it has a design, a sample size and error bars - and the field has learned to demand of it the same reporting standards it demands of trials. The published framework is ADEMP: state your Aims, your Data-generating mechanisms (all of them, because one mechanism proves nothing about robustness), your Estimands, the Methods compared, and the Performance measures - power, type I error, bias, coverage - before running anything.
And size the thing. A power estimate is a proportion, so its standard error is the familiar root of p times one minus p over the number of simulations - which makes this table worth memorising: hitting plus or minus 2 percentage points at a power near 80% needs about 1,500 replications, plus or minus 1 point needs about 6,100, and plus or minus half a point needs about 25,000. A methods paper reporting “power = 82%” off 100 replications carries an error bar of plus or minus 8 points and should not survive review. You are now equipped to be the reviewer who says so, with the formula in hand.
The bridge to MCMC
Everything in this series assumed one quiet superpower: that you can draw independent samples from your distribution, because it is a named distribution your library stocks, or an inverse CDF you can build, or a model you simulate forward. Bayesian inference demolishes that assumption on contact. A posterior is the likelihood times the prior, up to a constant - you can evaluate the right-hand side at any parameter value in microseconds, but the normalising constant is an integral over the whole parameter space: unknown, and in high dimensions unknowable. So here is the wall: a distribution you can touch pointwise but cannot sample.
The 1953 idea - Metropolis and colleagues, at Los Alamos again, the same building as Part 1's opening story five years on - is to stop trying to leap into the distribution and instead wander through it, taking steps whose local rules need only density ratios, in which the unknown constant cancels. Propose a small random step. Compute the ratio of the unnormalised densities. If it goes uphill, accept. If it goes downhill, accept with probability equal to that ratio; otherwise stay - and record the current point again.
The ritual, one last time. Certify against a case with a known answer: a coin showing 7 heads in 10 tosses under a uniform prior has an exactly known posterior with mean two-thirds. The chain's histogram lies indistinguishably on the true density, and its posterior mean comes out at 0.6657 against a true 0.6667 - inside the error bar. Machinery certified; now it may be pointed at posteriors nobody can write down.
But look at the price. The chain delivers the right distribution with the wrong independence: consecutive samples sit near each other by construction, so they are positively autocorrelated - and Part 1 told you exactly what that costs, because impaired cancellation is impaired cancellation. The exchange rate has a formula: the chain behaves like a smaller number of independent draws, the effective sample size. Measured here: a 58,000-draw chain is worth about 13,500 independent ones - 23% efficiency - and the posterior mean's standard error must be quoted using that number, not the raw count. Quoting MCMC error bars with raw N is pseudo-replication: the same crime, for the third time, as the parallel-seed trap and the clustered t-test.
Tuning, diagnostics, and where the field goes next
The proposal step size is a real dial with failure at both ends. Too small and nearly every proposal is accepted but the chain diffuses glacially - high acceptance, enormous autocorrelation. Too large and proposals constantly land in low-density territory and get rejected, freezing the chain for dozens of iterations. The folk optimum for random-walk proposals is acceptance somewhere around 20 to 50%, and it is measurable rather than folklore: a tuned chain running at about 46% acceptance beats an earlier draft at 62% on effective sample size.
The standing diagnostics - trace plots that look like fuzzy caterpillars rather than wandering rivers, acceptance rate, autocorrelation decay, effective sample size, discarding a burn-in before the chain forgets where it started, and running several chains from dispersed starts to check they agree - are exactly what you will see in every Stan or PyMC workflow. Modern samplers replace the blind random walk with proposals guided by the gradient of the log density, buying dramatically longer steps and automating the tuning, but they change none of the concepts above. Which is why the ten-line Metropolis you just certified is the right first MCMC, and for understanding, arguably the only essential one.
The production checklist
Both guides compressed into the pre-flight list for any simulation that will touch a decision.
Model
- Distributions justified input by input, tails scrutinised where tails matter.
- Dependence modelled, not defaulted - with tail dependence considered explicitly if joint extremes drive the answer.
- Pricing measure versus real-world measure: stated, and correct for the question being asked.
Machinery
- Seeded generators, spawned streams for parallelism - never hand-seeded workers.
- Exact scheme where available; if Euler, discretisation error managed separately from statistical error.
- Certified against a known answer, with the disagreement quoted in standard errors.
Efficiency
- Scorecard run before brute force. Common random numbers for any difference - free. A control variate hunted for - often 10 to 1000 times.
- Antithetic if the payoff is monotone. Sobol tried if the integrand is smooth - one line. Importance sampling if events are rare, with effective sample size reported.
Reporting
- Every number wears an error bar; the world's spread and your estimate's noise never confused.
- Percentile error bars sized for the tail if the tail is the deliverable.
- Effective sample size honest under any correlation - clusters, chains, streams.
- Seed, N and assumptions in the report; the seed-change and N-doubling ritual passed.
Now go and break it on purpose
Every number quoted above is the pro notebook's actual output, seeds fixed, so you will reproduce them to the digit. Section 4 is the variance-reduction scorecard including the 683-times control variate; Section 5 is importance sampling and the effective-sample-size collapse; Section 6 is Sobol; Section 7 is the cluster trial and the calibrated sequential design; Section 8 is the ten-line Metropolis. Then do the thing the guide actually asks of you: overshoot the tilt, drop the correction from the drift, seed the workers identically - and watch your diagnostics catch every one. That is the skill. Everything else is cumulative sums.
The whole series
That's the guide. Part 1 builds the engine and its error bar, Part 2 the recipe and two real projects, Part 3 paths, options and correlation, and all four sit on the series hub.
Frequently asked
What is a control variate?
A sidekick variable computed on the same scenarios that correlates strongly with what you want and whose exact mean you already know. Because you can see the sidekick's simulation error and the two err together, you can subtract it off. The variance shrinks by one over one minus the squared correlation, so 0.9 buys five times, 0.99 buys fifty, 0.999 buys five hundred. The craft is finding a sidekick that is almost your problem but solvable.
What is importance sampling?
Sampling from a proposal that puts its mass where the interesting events are, then correcting for the lie sample by sample with a likelihood-ratio weight. It is exactly unbiased, and for rare events it is the difference between impossible and routine: a one-in-a-million probability needs about ten billion naive draws, or a million well-tilted ones.
Why does importance sampling fail silently?
Because the confidence interval is computed from the samples you got, and those samples don't know what they're missing. If the proposal misses part of the important region the estimate can sit far from the truth behind a beautifully narrow interval. The standing diagnostic is effective sample size - report it next to every importance-sampling estimate, and distrust a narrow interval attached to a tiny one.
What is quasi-Monte Carlo?
Replacing random points with deterministic low-discrepancy points, such as a Sobol sequence, that cover the space far more evenly than randomness manages. It attacks the exponent rather than the constant: error falls roughly like one over N rather than one over the square root of N. Scrambling restores randomness so you keep an honest error bar, which is why unscrambled Sobol has no place in applications.
“How would I know if this were wrong?” is the habit this series is really teaching - and it is the same habit an exam question rewards. Stat Exam Pro drills it, with worked answers.
Get it on iPhone