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.

Choose a numerical precision budget
  1. State the target

    mean or event probability

  2. Choose a half-width
    hh
  3. Plan, then check
    n≈(zs/h)2n\approx(zs/h)^2
Reference illustration. In the mean-planning formula, z is the chosen normal critical value, s the supplied SD and h the desired half-width. Probability planning uses a Bernoulli variance bound. A chosen trial count is conditional on those assumptions, not new evidence about the world.

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.

Tools
About Python ↗

The code is editable. Press Ctrl+Enter or ⌘+Enter to run Python from the editor.

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?

Back to the Python editor

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?

Choose an answer
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.

Your notes