Understand simulation errorLesson 16 of 76 · 7 min
An interval for a simulated mean
Construct an approximate confidence interval for a model expectation.
An interval for an expectation describes numerical uncertainty about a fixed model mean, not the range of individual outcomes. Coverage refers to repeated independent simulations: if each run constructs a 95% confidence interval, about 95% should contain that same fixed mean when the method's assumptions hold. One interval can miss it.
For independent finite-variance draws whose sample mean is approximately normal, use mean ± critical value × MCSE. A two-sided 95% interval leaves 5% outside: 2.5% in each tail. The normal 97.5th percentile, stats.norm.ppf(.975), is about 1.96; symmetry supplies the lower endpoint.
The normal approximation can work for the mean of many skewed outcomes, but is not automatic for tiny samples or poorly explored tails. The exponential model has a known expectation to check. Compare the short interval for that expectation with the central 95% of individual waits. More draws narrow numerical error, not the underlying wait distribution.
is the estimated mean, is outcome sample SD and n is the independent draw count; ± means form a lower and an upper endpoint.
Should a 95% interval for the expectation contain 95% of the individual waits?
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 ↗
Mean wait estimate (minutes): 5.0263 Approximate 95% MC interval: [4.9277 5.1249] Known model expectation: 5 Outcome percentiles 2.5/97.5: [ 0.133 18.292]
Read the first result
Read Approximate 95% MC interval and check whether it contains Known model expectation. Outcome percentiles 2.5/97.5 answer a different question about individual outcomes.
Try an edit
Replace size=10000 with size=20 on the line that creates waits. Select Run Python. Then replace default_rng(2015) with default_rng(16) for a new sample. Select Run Python again. Compare the endpoints of Approximate 95% MC interval with Known model expectation after each edit. Why does a small skewed sample deserve more scrutiny?
Scope. This normal interval is approximate and conditional on independent draws and adequate exploration of the outcome distribution.
Try a fresh case
A confidence interval for expected project duration is 9.9–10.1 days. What does it establish about individual projects?
Need a hint?
Hint 1
Identify the interval’s target quantity.
Hint 2
Compare the mean with a randomly selected project duration.