Answers · The mathematics underneath
When should I give up on finding an exact formula and simulate instead?
In shortGive up on an exact formula when the quantity can be written as an average of something drawable, since simulation then gives an estimate with a measurable error.
Give up on the exact formula as soon as the quantity can be written as an average of something you can draw at random, and an exact closed form is either absent or intractable. The test is not whether the algebra is hard, but whether you can name a random draw , a computable from one draw, and check that the average of is the quantity wanted. Most quantities worth knowing fail the first test for a formula, not the second: an integral with no elementary antiderivative, or a queue with abandonment, is perfectly definite and still has no usable closed form. The formula is the special case. Simulation is the default when the average rewriting exists.
The test in practice
Write the target as . For the average wait in a queue with abandonment, is one random day of arrivals and service times, is the mean wait on that day, and the average over days is the long-run average wait. In the simplest queue with arrival rate 0.8 per minute and service rate 1 per minute, the mean wait in queue is minutes; add abandonment, or a server that slows when busy, and that formula stops. For an area under a curve on , is a point drawn evenly in the interval and is the height of the curve there; the average height is the area because the width is one. For a probability, is one when the event happens and zero otherwise, so counting hits out of trials is the same operation with a particular .
| step | question | the random draw | computed from one draw | the average | what happened |
|---|---|---|---|---|---|
| 1 | area under $x^2$ on $[0,1]$ | $x$ uniform in $[0,1]$ | $x^2$ | the area, $1/3$ | width is one |
| 2 | chance of at least three sixes in five dice | one roll of five dice | one if at least three are sixes, else zero | the probability, $23/648$ | indicator average |
| 3 | average wait in a queue with abandonment | one random day of arrivals and service times | the mean wait on that day | the long-run average wait | no closed form |
Take the area under from 0 to 1. The exact value is . Draw points uniformly, square each, average. The estimator is unbiased, and its standard error is the standard deviation of divided by . Since and , the variance of is .
For five dice and at least three sixes, the exact probability is also available. There are equally likely rolls. The count is : ten ways to choose which three are sixes and two non-sixes, five ways for four sixes, one for five. So . A hundred thousand trials gives about 0.0355, with one standard error . Two standard errors is 0.00117, so quote 0.0355 plus or minus 0.0012, not 0.0354938. The exact value is there for this toy; the simulation did not need it. The last digits of a single run are noise.
The natural guess is that a hard enough derivation will always end in a formula. It will not. Most integrals have no elementary antiderivative, and most systems with two or more random parts interacting have no closed form for anything about them. The queue with abandonment is a definite question with a definite answer, and the algebra has run out. Treating a formula as the only rigorous answer is a category error: a simulated estimate with a stated error is a measurement of the same quantity, and a formula that cannot be evaluated is not more exact in practice.
What the error costs
The price is exactness. The estimate changes from run to run, and the size of that change is estimable from the same samples. A simulated number should be quoted with uncertainty attached, as estimate plus or minus something, and never as a bare figure. If a downstream user sees 0.33331 they may treat the fourth decimal as information; it is usually noise. The error shrinks like , so halving it needs four times the samples: the area estimate at has standard error 0.000943, and at it has standard error 0.000471.
Where it stops
The method stops being direct when cannot be written as with a drawable , or when the draw is from the wrong distribution. Then the average converges to the wrong number, and more samples only make the wrong number more precise. If has infinite variance, the standard error from the samples is unreliable and the normal error rule can fail. A conditional average over the worst five per cent of years is a further warning: it throws away ninety-five per cent of draws, so its error is much larger than the raw sample count suggests. That case needs a deliberate sampling design, not a bigger loop.
Worth keeping
- A quantity with no closed form can still be computed if it is the average of something drawable at random.
- A probability is the average of a zero-one indicator, so counting hits out of trials estimates it.
- A simulated estimate is incomplete without its error, and halving that error needs four times the samples.
Where this goes next
This question is one step of Answering With Random Samples, a course that works through its subject from the beginning. The page that teaches this part of it is When the Formula Runs Out, and it reads the whole way through whether or not you have an account.
What an account changes is the practice: problems standing under every idea, marked with a reason rather than a tick, in a copy of the course that is yours.
Read that pageThe whole courseOther questions people ask about this
- Why does the average of many random samples get closer to the true value as I take more samples?Because the average of independent draws is centred on the true value at every sample size, and its typical distance from that value shrinks like one over the square root of the number of draws.
- How do I estimate the error of a statistic when I don't have a formula for it?Resample your own data many times, recompute the statistic each time, and use the spread of those results as the error bar.
- Why does cutting the error in half require four times as many samples?The error shrinks in proportion to one over the square root of the sample count, so halving it needs four times the samples.
- What is the difference between variance and standard deviation?They measure the same spread: variance is the average squared distance from the mean, standard deviation is its square root, so you report the standard deviation and calculate with the variance.
- How do you make a vague claim precise enough to tell whether it's true?Fix what is being talked about, what is asserted, which cases are covered and the cut-off, then name an observation that would prove it false.
- How do you find the parabola that best fits a function near a point?Match the function's height, slope and bending at the chosen point; those three conditions single out exactly one parabola.