Understand simulation errorLesson 18 of 76 · 8 min
Plan a precision budget
Choose an independent-run budget for a stated numerical precision goal.
Plan simulation count from the target and needed numerical precision. A Bernoulli outcome is one yes/no value, coded 1 or 0. Its variance p(1-p) is at most 0.25. That worst case gives a conservative planning count for the half-width h, the distance from an estimated probability to one endpoint of an approximate normal interval.
For two-sided 95%, z is about 1.96. Plan n by rounding z²×0.25/h² up to the next integer; ceiling means round up. In code half_width is h. Halving h needs about four times the draws. For a mean instead of a probability, replace 0.25 with a supplied outcome variance s².
Fix the count before examining the result, or use a sequential method built to support stopping. Repeatedly checking an ordinary fixed-count interval and stopping when a preferred conclusion appears changes the procedure. Keep numerical precision goals separate from the practical threshold of a decision.
- State the target
mean or event probability
- Choose a half-width
- Plan, then check
How does the planned count change if you halve the desired half-width?
Write a prediction (optional)
Seeded teaching simulation
Select Run Python below with the code unchanged.
A saved draft is open. To run the published example, open Tools and select Restore example. Recover draft brings your code back.
Execution error
Technical error details
Your result
Published example output
This result comes from the original Python. Your runs appear above. Build environment ↗
Target approximate half-width: 0.05 planned trials: 385 Target approximate half-width: 0.02 planned trials: 2401 Target approximate half-width: 0.01 planned trials: 9604 Mean-estimation count from assumed SD: 2213
Read the first result
The mean-planning count depends on an assumed or pilot SD. An unrepresentative pilot can make its precision forecast optimistic.
Try an edit
Replace [.05, .02, .01] with [.05, .02, .01, .005]. Select Run Python again. Compare planned trials for Target approximate half-width 0.01 and 0.005. What is the cost of asking for half the half-width?
Scope. The formulas are approximate planning tools. They do not guarantee model validity, exact coverage or tail exploration.
Try a fresh case
Your first run is inconclusive for a useful threshold. Which continuation is defensible?
Need a hint?
Hint 1
Describe the whole procedure that produced the reported result.
Hint 2
Separate planning for precision from chasing a preferred conclusion.