Mathematical foundations
Monte Carlo, Importance Sampling, and MCMC
Learn direct Monte Carlo, variance reduction, importance sampling, MCMC dependence, and diagnostics for rare-event and intractable expectations.
By the end you can
- Construct direct and weighted Monte Carlo estimators
- Explain support overlap and weight degeneracy in importance sampling
- Interpret autocorrelation and effective sample size in MCMC
- Design diagnostics for Monte Carlo error, rare regions, and multimodality
Visual
A map of Monte Carlo methods
The sampling mechanism determines the estimator and its diagnostics. Each of the four branches below fails in its own way, so each is checked with its own number: a trial budget for direct simulation, a weight-tail parameter for reweighting, an autocorrelation summary for a dependent chain, an ensemble size for a population of particles. None of those numbers is a matter of taste. Each has been written down by a standards body, a journal or a review, and the rest of this lesson quotes them.
Direct Monte Carlo
Sample from the target and average the quantity of interest.
Importance sampling
Sample from a proposal and reweight toward the target.
Markov chain Monte Carlo
Build a dependent chain with the target as its stationary distribution.
Sequential Monte Carlo
Move and reweight a population of particles through a sequence of targets.
Monte Carlo replaces a difficult integral with random computation
Many expectations and probabilities cannot be evaluated analytically. Monte Carlo methods approximate them using samples from a distribution that is easy enough to generate. The method is general because the error rate does not depend directly on geometric dimension in the same way as grid integration. It is also slow. Root-n convergence is slow enough that an international measurement standard had to legislate a number for it.
The metrology standard JCGM 101:2008 fixes the sample budget outright. Its own text reads: “A value of M = 10^6 can often be expected to deliver a 95 % coverage interval for the output quantity such that this length is correct to one or two significant decimal digits.” A million draws buys one or two digits of the interval's length. That is the price of the square root.
The standard also gives a general rule rather than a single default. For a coverage probability p it requires “a value of M that is large compared with 1/(1-p), e.g. M at least 10^4 times greater than 1/(1-p)”, and it allows M to be selected adaptively as the trials progress, because no pre-assigned number is guaranteed to suffice. The UK's National Physical Laboratory built software to the standard in 2011. It reproduces the four Supplement 1 example problems at M = 10^6 and applies the procedure “either non-adaptively or adaptively”.
Good Monte Carlo work therefore depends on variance reduction, diagnostics, and honest accounting of dependence and rare events.
Random simulation is an estimator with its own uncertainty, and a metrology standard had to put M = 10^6 on the price of two digits.
Case
Los Alamos, 1953: the estimator arrived as an equation-of-state tool
The method was published from a weapons laboratory. Metropolis and four co-authors wrote Equation of State Calculations by Fast Computing Machines; all of them worked at the Los Alamos Scientific Laboratory except Edward Teller, who was at the University of Chicago. The Journal of Chemical Physics received the paper on 6 March 1953 and printed it that June.
The abstract states what the estimator was built to do, and it is worth reading in its own words rather than in a summary: “The method consists of a modified Monte Carlo integration over configuration space. Results for the two-dimensional rigid-sphere system have been obtained on the Los Alamos MANIAC and are presented here.” No posterior, no risk model, no ensemble forecast. Rigid spheres in two dimensions, computed on the laboratory's own machine.
The reach was recognised afterwards. J. E. Gubernatis, at Los Alamos, wrote on Marshall Rosenbluth and the Metropolis algorithm for Physics of Plasmas, and the US Department of Energy's own literature record carries the abstract. It says the 1953 paper “marked the beginning of the use of the Monte Carlo method for solving problems in the physical sciences”, and that the technique “subsequently became known as the Metropolis algorithm”.
Analogy
Estimating a continent from survey expeditions
A continent's average elevation can be estimated from field expeditions. Randomly sampled locations are direct Monte Carlo. Deliberate oversampling of mountains is importance sampling. A walking expedition, where each location depends on the previous one, is MCMC, and many nearby measurements may add less information than their count suggests. That is the same coverage and dependence risk that weights and transition kernels are designed to manage. The rest of the lesson is about the published numbers that tell you which of these you are actually in: how many draws the budget needs, how heavy the heaviest weight is allowed to be, and how much independent information a dependent chain really holds.
Sample count is not the same as effective information.
Example
Why naive simulation misses a rare failure
The rare event does not have to be invented. FAA Advisory Circular 25.1309-1B, issued 30 August 2024, defines the top severity category: “Extremely Improbable Failure Condition. A failure condition having an average probability per flight hour on the order of 1 x 10-9 or less.” That is the target a certification argument has to reach.
Now try to reach it by sampling. Butler and Finelli, at NASA Langley Research Center, did the arithmetic in 1993 in IEEE Transactions on Software Engineering. Take a system required to fail with probability 10^-9 over a 10-hour mission. Their Table 1 gives an expected test duration of 10^10 hours — 1,141,550 years — with a single test article, and 10^9 hours, or 114,155 years, with ten replicates. Their text calls life testing at these targets “prohibitively impractical”. Their abstract states the conclusion without hedging: “This paper affirms that the quantification of life-critical software reliability is infeasible using statistical methods whether applied to standard software or fault-tolerant software.” Naive sampling here is not merely inefficient. It is off the table by six orders of magnitude in wall-clock centuries.
- Naive budget: A single test article runs 1,141,550 years to expect the failure once. Ten replicates bring it down to 114,155 years, which is not an improvement anyone can use.
- Misleading estimate: Zero observed failures does not establish zero risk, which is why the FAA warns that “performing only a quantitative analysis to show that a failure condition is extremely improbable is insufficient, due to the variability and uncertainty in the analytical process”.
- Importance idea: Sample more often from stressful conditions where failures are plausible, so the event actually appears in the sample at all.
- Reweighting: Correct for the altered sampling distribution when estimating target risk. Otherwise the oversampled stress conditions become the answer instead of the route to it.
- Danger: A proposal with poor support can miss an important failure mode entirely, and no weight can recover a region the sampler never visited.
Comparison
Four variance-reduction strategies
Variance can often be reduced without changing the estimand. Three of the four strategies below leave the sampling distribution alone and work on the arithmetic around it. The fourth, importance sampling, changes the distribution itself. That is why its failure is the one with published numbers attached: a fitted tail parameter with a cut-off at 0.7, and an ensemble requirement that grows exponentially with dimension. The two sections that follow supply both.
Control variates
Use a correlated quantity with known expectation.
- Subtract predictable variation
- Requires a useful correlation
- Can be estimated from pilot runs
- Does not alter target support
Antithetic sampling
Pair negatively related random draws.
- Cancels some fluctuations
- Works best with monotone structure
- Can fail without negative correlation
- Simple for symmetric simulations
Stratification
Allocate samples across important regions.
- Improves coverage
- Supports subgroup estimates
- Needs correct weighting
- Requires declared strata
Importance sampling
Change the sampling distribution and reweight.
- Targets rare regions
- Weights can be unstable
- Requires support overlap
- Effective sample size can collapse
Steps
Audit a simulation-based estimate
An expectation from random computation earns trust through this protocol. Two of its six steps rest on published thresholds rather than on judgement, and one of those two is skipped by most of the literature that would need it.
Step 4, inspect weights, has a pass/fail statistic. Pareto smoothed importance sampling fits a generalised Pareto distribution to the tail of the importance ratios and reads off the shape parameter, k̂. Vehtari and four co-authors set the method out in the Journal of Machine Learning Research in 2024. The algorithm's final step reports a warning “If the estimated shape parameter k̂ exceeds min(1 - 1/log10(S), 0.7)”, and above two thousand samples the formula collapses to a single number: “For S > 2000 this threshold is 0.7”. Beyond it the estimates are unstable, biased, and their Monte Carlo error is itself unreliable. Marc Box, in his own paper on importance sampling with partitioned data, summarises the scale: “They find that k̂ < 0.5 is an indicator of good performance, but that Pareto smoothed importance weights will still provide reliable results for k̂ < 0.7 and that importance sampling is unreliable beyond this.” Step 4 is a number to report. It is not an instruction to look at a histogram and feel reassured.
Step 5, estimate Monte Carlo error, is the one that gets left out. Morris and colleagues, writing in Statistics in Medicine in 2019, read 100 randomly selected simulation studies from volume 34 of that same journal and counted: “In our review of Volume 34, seven articles presented Monte Carlo SEs for estimated performance: three in the text, two in a table, one in a graph, and one in a float caption.” Seven of a hundred. The budget was not defended either: “Of the 87 studies reporting n_sim, four provided any justification of the choice.”
An independent audit in a different field reached the same place. Six authors screened 321 articles from three psychology journals published in 2021-2022 and found a simulation study in 100 of them. Their report, in Psychological Methods in November 2024, says that “The vast majority of studies (77%) did not report the uncertainty of performance measures (Panel B in Figure 2), despite our liberal approach of including visualizations such as box plots as indicative of Monte Carlo uncertainty.” Only 8% justified the number of repetitions.
The protocol below is a correction of documented practice. It is not a description of what everyone already does.
1. Define the estimand
Write the target expectation, probability, or integral.
2. Describe the sampler
State target, proposal, transition kernel, and initialization.
3. Quantify dependence
Estimate autocorrelation and effective sample size.
4. Inspect weights
Check support overlap, extremes, and weight concentration.
5. Estimate Monte Carlo error
Use repeated runs, batch means, or justified variance estimates.
6. Stress rare regions
Design targeted checks for tails, modes, and failure events.
Key idea
Self-normalized importance sampling is biased but often useful
If the target density is known only up to a constant, normalized weights can estimate expectations without that constant. The resulting ratio estimator is generally biased at finite sample size. Consistency can still hold under suitable conditions.
Extreme weights remain dangerous, and the danger has been measured rather than merely named. Snyder and colleagues studied the regime in which one particle takes essentially all the weight, in Monthly Weather Review in December 2008. Their abstract states: “Evidence is provided that the ensemble size required for a successful particle filter scales exponentially with the problem size.” In their independent unit-variance Gaussian example, a 200-dimensional state requires at least 10^11 members to avoid collapse. A 2019 review in the Quarterly Journal of the Royal Meteorological Society restates the result: the number of particles needed to avoid weight collapse “has to grow exponentially with the dimension of the observations y for a large class of particle filters”.
Ten to the eleventh draws for two hundred dimensions is what "weights can be unstable" means once someone counts. Report effective sample size, fit the weight tail, and inspect the weight distribution. Do not quote only the point estimate.
A normalized weighted average can be stable-looking while supported by only a few effective samples.
MCMC trades independence for access to a difficult target
When direct samples are unavailable, a Markov chain can be designed so that its stationary distribution is the target. After convergence, chain states can estimate expectations. The samples are dependent, so the raw number of iterations overstates the information they carry.
The practice of checking this has a date. Gelman and Rubin introduced the potential scale reduction factor in Statistical Science in November 1992, together with the design that makes it meaningful. Their abstract puts it plainly: “Our recommended strategy is to use several independent sequences, with starting points sampled from an overdispersed distribution.” A single chain cannot report on the territory it never left.
The threshold that came with it has since been tightened by an order of magnitude, and on simulation evidence rather than taste. Vehtari and four co-authors, in Bayesian Analysis in 2021, recommend “only using the sample if R̂ < 1.01. This threshold is much tighter than the one recommended by Gelman and Rubin (1992), reflecting lessons learnt over more than 25 years of use”. They put a floor under the effective sample size in the same breath: “To ensure reliable estimates of variances and autocorrelations needed for R̂ and ESS, we recommend requiring that the rank-normalized ESS is greater than 400, a number we chose based on practical experience and simulations (see Appendix A) as typically sufficient to get a stable estimate of the Monte Carlo standard error.”
Both numbers are necessary and neither is sufficient. Rank-normalised R̂ below 1.01 and rank-normalised ESS above 400 are what current practice asks before a chain's output is used at all. Convergence diagnostics can reveal problems, but they cannot prove that every relevant mode was explored.
Case
Hastings, 1970: the generalization that made autocorrelation a diagnostic
Statistics got the general version in 1970. W. K. Hastings published Monte Carlo Sampling Methods Using Markov Chains and Their Applications in Biometrika that April.
A 2020 survey of Bayesian computation from 1763 onward records both of his contributions: “Hastings also generalizes the acceptance probability … to one that accommodates a general ‘candidate’ distribution”, and, in formalizing the standard error, “explicitly linking, for the first time, the autocorrelation in the Markov draws to the efficiency of the MCMC-based estimate”.
That link is now the diagnostic. R̂ and effective sample size are the numbers it eventually turned into. They are the reason a chain of a million iterations may be worth reporting only if its rank-normalised ESS clears 400.
Key takeaways
- Monte Carlo approximates expectations through random samples and carries sampling error big enough that JCGM 101:2008 legislates the budget: M = 10^6 trials for a 95 % coverage interval whose length is correct to one or two significant decimal digits, and M at least 10^4 times greater than 1/(1-p) in general.
- Importance sampling changes the proposal and corrects with weights, which requires support overlap. The check has a number: warn when the fitted Pareto shape k̂ exceeds min(1 - 1/log10(S), 0.7), which is 0.7 for S > 2000.
- Weight collapse is measured, not merely possible. A 200-dimensional state needs at least 10^11 particle-filter members, and the requirement grows exponentially with dimension for a large class of particle filters.
- MCMC buys access to a difficult target with dependence, and current practice prices that access at rank-normalised R̂ below 1.01 and rank-normalised ESS above 400 — an order of magnitude tighter than the 1992 Gelman and Rubin threshold, tightened on simulation evidence.
- Variance reduction can improve precision without changing the estimand, but Monte Carlo error itself is usually left unreported: seven of 100 simulation studies in volume 34 of Statistics in Medicine gave Monte Carlo standard errors, and 77% of the audited psychology studies reported no uncertainty at all.
- Rare-event estimates require targeted coverage rather than confidence from zero observed failures: against the FAA's 1 x 10-9 per flight hour bar, naive life testing runs 1,141,550 years with one test article and 114,155 years with ten.