How Rejection Sampling Works in Statistics
#Monte Carlo
1 ideas
How Rejection Sampling Works in Statistics
Get new #Monte Carlo ideas by email
Every Thursday: the week's best ideas, with the newest from #Monte Carlo.
Related tags
Monte Carlo Methods: An Introduction to Random Simulation
Some questions are impossible to answer with a formula. How much radiation passes through a shielding wall, how likely a portfolio is to lose a third of its value, how a gas of a million particles settles into equilibrium — each of these involves too many interacting parts for exact calculation. Monte Carlo methods offer a way around that: instead of solving the problem, you simulate it many times and let the average of those simulations stand in for the answer. The trick is that the randomness is not sloppiness. It is the engine.
The core idea
Imagine you want the area of an irregular shape drawn inside a square. Rather than integrating, you scatter points uniformly across the square and count how many fall inside the shape. The fraction that land inside approximates the fraction of the area. That is Monte Carlo in miniature: draw random samples, compute something for each, average the results. Anything you can describe as an expectation over random inputs, you can estimate this way.
Where it comes from
Read more
The method grew out of mid-twentieth-century physics and mathematics, where researchers needed to trace neutron behaviour that no tractable equation could capture. It took its name from the casino tables of Monaco — a nod to the deliberate use of chance. The underlying logic, though, is older than the name: the idea that repeated random trials can approximate a quantity goes back to classical probability puzzles about games of chance.
The main families
Direct sampling is the simplest: generate random inputs from the distribution you care about, evaluate your function, average. Rejection sampling handles the awkward cases where you cannot draw from the target distribution directly — you propose candidates from an easier distribution and keep them with a probability that corrects the mismatch, discarding the rest. Importance sampling instead reweights every sample, concentrating effort where it matters most. Markov chain Monte Carlo (MCMC), with algorithms such as Metropolis–Hastings and Gibbs sampling, builds a chain of dependent samples that gradually settles toward the distribution you want; it is the workhorse of modern Bayesian statistics.
What beginners should know
The error of a Monte Carlo estimate shrinks with the square root of the sample count. To halve your uncertainty you need four times the samples; to gain one more digit of accuracy, a hundred times as many. That single fact governs most practical decisions about these methods.
Randomness quality matters, but not in the way people fear. Pseudo-random number generators are perfectly adequate for most work — a poorly chosen one, however, can quietly bias results. Set and record a seed so your runs are reproducible.
With MCMC, the samples are correlated, so the first portion of a chain is usually discarded as a burn-in period, and you should inspect trace plots to judge whether the chain has actually converged. A chain that wanders is not evidence of success.
Starting out
Begin with a problem whose answer you already know, and check that your simulation recovers it. Keep the code for generating samples separate from the code that computes the quantity. Then scale up, and watch how the estimate settles as you add samples. When it stops moving, you are done — or you are stuck, and only a convergence check will tell you which.
#Monte Carlo: frequently asked questions
What is the Monte Carlo method in simple terms?
It is a way of estimating an answer you cannot calculate exactly by simulating the situation many times at random and averaging the results. Instead of solving the problem directly, you let repeated random trials stand in for the solution. The randomness is deliberate — it is the mechanism, not a shortcut.
How do I get started with Monte Carlo simulation?
Pick a problem whose answer you already know and check that your simulation recovers it. Keep the part of your code that generates samples separate from the part that computes the quantity, then scale up and watch whether the estimate settles. If you cannot tell whether it has settled or stalled, a convergence check is what separates the two.
Which kind of Monte Carlo sampling should I choose?
Start with direct sampling when you can draw from the distribution you care about, since it is the simplest to implement and reason about. Turn to rejection sampling when the target is awkward to draw from directly, and to importance sampling when you want to concentrate effort where it matters most. Chain-based approaches that produce dependent samples are the usual choice for complex probabilistic models, but they need more diagnosis.
How accurate is a Monte Carlo estimate, and when should I stop sampling?
Accuracy improves slowly as you add samples — each extra digit of precision costs a great deal more computation than the one before, so effort quickly hits diminishing returns. Practically, you stop when the estimate stops moving as new samples arrive. That plateau can also mean the sampler is stuck, so pair it with a check that the samples actually explore the range you expect.
What mistakes do beginners make with Monte Carlo?
The common ones are using a badly chosen random number generator that quietly biases results, and forgetting to record a seed so runs cannot be reproduced. Others keep correlated samples without discarding the opening stretch and never look at trace plots, then treat a chain that wanders as proof of success. Verifying against a known answer first catches most of these before they matter.
Videos come from YouTube and posts from Instagram; titles and summaries are our own. All rights belong to their creators.