Lesson 3
Sampling Error and Confidence Intervals
The standard error, the confidence interval, and the diagnostic methods that verify convergence.
1 Modelling context
A Monte Carlo estimate without a standard error is a number, not a result. The estimate varies across repetitions of the experiment, and the magnitude of that variation is what determines whether the estimate is useful. Reporting the estimate alone conceals the sampling variability and makes it impossible to compare results from different simulations or to know whether the sample size was adequate.
This lesson develops the standard error and confidence interval for Monte Carlo estimates, and the diagnostic methods for verifying that the number of samples was sufficient. Together with the estimator from Lesson 1 and the integration techniques from Lesson 2, these complete the toolbox for Monte Carlo estimation.
Every estimate carries an uncertainty
The reporting convention for Monte Carlo results includes the estimate, the standard error, the sample size, and the seed. A result missing any of these is incomplete.
2 Learning objectives
By the end of this lesson you will be able to
- Compute the standard error of a Monte Carlo estimate.
- Construct a confidence interval for a Monte Carlo estimate using the central limit theorem.
- Choose a sample size to achieve a target standard error or confidence interval width.
- Diagnose convergence using running-mean plots and the standard-error scaling.
- Distinguish sampling error from structural model error in reporting.
3 Prerequisite review
- Sample variance
-
s² = (1/(N−1)) Σ (Yᵢ − Ȳ)²whereYᵢ = g(Xᵢ)andȲis the sample mean. An unbiased estimate of the variance ofg(X). - Central limit theorem
-
For independent identically-distributed random variables with finite
variance, the sample mean is approximately normally distributed for
large
N. This justifies the use of normal-based confidence intervals. - Standard normal quantile
-
The value
z_αsuch thatP(Z > z_α) = αforZ ~ Normal(0, 1). For a two-sided 95% interval,z_{0.025} = 1.96. - Running mean
-
The sequence of estimates
θ̂_1, θ̂_2, θ̂_3, …computed as samples accumulate. Convergence is verified by observing that the running mean stabilises.
4 Mathematical formulation
Standard error
Let Yᵢ = g(Xᵢ) and let θ = E[Y]. The Monte
Carlo estimator is θ̂_N = Ȳ, the sample mean of
Y. Its variance is
Var( θ̂_N ) = Var( Y ) / N
Estimating Var(Y) by the sample variance
s², the estimated standard error is
SE( θ̂_N ) = s / √N
The standard error is the estimated standard deviation of the
estimator. It quantifies how much θ̂_N would vary across
repetitions of the experiment.
Confidence interval
By the central limit theorem, for large N the estimator
is approximately normal:
( θ̂_N − θ ) / SE( θ̂_N ) ≈ Normal(0, 1)
Rearranging gives an approximate two-sided confidence interval at
level 1 − α:
θ̂_N ± z_{α/2} · SE( θ̂_N )
For a 95% interval, z_{0.025} = 1.96. For a 90%
interval, z_{0.05} = 1.645. For a 99% interval,
z_{0.005} = 2.576.
The interval is approximate because it relies on the central limit
theorem. It is typically accurate for N ≳ 30 unless the
distribution of Y is highly skewed or heavy-tailed.
Choosing a sample size
Suppose we want the standard error to be at most ε. From
SE = σ / √N, the required sample size is
N ≥ ( σ / ε )²
where σ² = Var(Y). Since σ is usually
unknown in advance, a pilot run of 100–1000 samples provides an
estimate of σ, which is then used to plan the full run.
For a confidence-interval-width criterion, the width of the interval is
approximately 2 z_{α/2} σ / √N. Setting this equal to a
target width w gives
N ≥ ( 2 z_{α/2} σ / w )²
Convergence diagnostics
Three practical diagnostics confirm that the sample size is adequate:
-
Running mean plot. Plot
θ̂_nagainstn. The curve should stabilise asngrows. Persistent oscillation indicates insufficient samples. -
Standard-error scaling. The standard error should
scale as
1/√N. A log-log plot ofSEagainstNshould be a straight line of slope−1/2. - Multiple-seed replication. Run the simulation with several independent seeds. The estimates should scatter around the true value with no systematic drift.
1/√N. Each tenfold increase in sample size reduces the
interval width by a factor of about √10 ≈ 3.16.
5 Worked example
Sample-size planning for a probability estimate
We want to estimate P(X > 2) where
X ~ Exp(1). The true value is e^{−2} ≈ 0.1353.
We want the width of the 95% confidence interval to be at most
0.005.
Step 1 — Pilot run.
Run the simulation with N = 500 samples. Suppose the
estimated probability is p̂ = 0.132.
Step 2 — Estimate the variance.
For a probability estimate, σ² = p(1−p). Substituting
p̂ = 0.132:
σ̂² ≈ 0.132 · 0.868 = 0.1146
σ̂ ≈ 0.338
Step 3 — Compute the required sample size.
For a target confidence-interval width w = 0.005:
N ≥ ( 2 · 1.96 · σ̂ / w )²
≥ ( 2 · 1.96 · 0.338 / 0.005 )²
≥ ( 265.0 )²
≈ 70,225
So about 70,000 samples are required to achieve the target interval width.
Step 4 — Confirm the pilot estimate.
Run the simulation with N = 70,000. The estimated
probability is p̂ = 0.1352, with a standard error of
SE = √( 0.1352 · 0.8648 / 70,000 ) ≈ 0.0013
The 95% confidence interval is
0.1352 ± 1.96 · 0.0013 ≈ [0.1327, 0.1377], with width
0.0050 — matching the target.
Step 5 — Verify convergence.
Plot the running mean against the sample index. The curve should
stabilise within the confidence band as N approaches
70,000. If the curve is still drifting, the pilot estimate of
σ was too optimistic, and the run should be extended.
6 Verification check
Checks to perform
- Compare the estimated standard error to the truth. If the analytical standard error is known, compare against it. A large discrepancy indicates the sample size is too small or the samples are not independent.
-
Confirm the
1/√Nscaling. Compute the standard error at several sample sizes and check that it halves whenNquadruples. -
Inspect the running mean. It should stabilise
within a band of width approximately
2 SEaround the final estimate. - Test with different seeds. Repeat the simulation with several independent seeds. The estimates should scatter around the true value; a systematic drift indicates bias or non-independence.
- Check the confidence-interval coverage. Run 100 independent simulations and compute the confidence interval for each. The true value should be inside approximately 95% of the intervals.
7 Interpretation
The confidence interval is the appropriate way to report a Monte Carlo estimate. It gives the reader both the central estimate and the range of plausible values, and it communicates how precise the estimate is.
Three interpretive points are worth emphasising:
- The interval is not a statement about the model. It describes the sampling variability of the estimator, not the uncertainty in the model. Model error and sampling error are distinct.
- The interval narrows as the square root of the sample size. To halve the interval width, quadruple the sample size. To reduce it by a factor of 10, use 100 times as many samples. This is a substantial cost, which motivates the variance-reduction techniques of Unit 4.2.
- The interval assumes the estimator is unbiased. A biased estimator produces a confidence interval that does not contain the true value, no matter how narrow it is.
Reporting template
A complete Monte Carlo report states: the model or quantity estimated, the estimator used, the sample size, the estimate, the standard error, the confidence interval, and the seed. Every element is part of the result.
8 Uncertainty and limitations
The standard error and confidence interval are approximate. Several conditions must hold for them to be reliable.
| Condition | Consequence if violated |
|---|---|
| Independent samples | Standard error formula σ/√N is invalid; the actual SE is larger |
| Identically distributed samples | The estimator may be biased |
| Finite variance | Central limit theorem fails; confidence intervals are unreliable |
Large enough N |
Normal approximation is poor; intervals undercover |
Heavy-tailed distributions violate the finite-variance condition. For such distributions the standard error can seriously understate the uncertainty, and the confidence intervals can undercover. Alternative methods — bootstrap confidence intervals, or estimators designed for heavy-tailed data — are required.
Small-sample caution
The central limit theorem provides an approximation, not a
guarantee. For small N, or for highly skewed
distributions, the normal-based confidence interval may be
inaccurate. Always inspect the running-mean plot and the histogram
of Y values before trusting the interval.
9 Common implementation errors
Watch for these
-
Using
1/Nin the sample variance. The unbiased estimator of variance uses1/(N−1). Using1/Nunderestimates the variance and the standard error. -
Forgetting the
1/√Nfactor in the standard error. The standard error iss/√N, nots. Confusing the two produces a standard error that is too large by a factor of√N. - Using the wrong quantile. For a 95% two-sided interval, the correct quantile is 1.96, not 1.645 (which is the one-sided quantile) and not 2.576 (which is for 99%).
-
Assuming the confidence interval is exact. It is
an asymptotic approximation. For small
Nor skewed distributions, the actual coverage can be lower than the nominal level. - Reporting the interval without stating the level. "The estimate is 0.1352 ± 0.0013" is incomplete; the level (95%) must be stated.
-
Confusing the standard error of the estimate with the
standard deviation of the samples. The standard error is
s/√N; the standard deviation iss. They differ by a factor of√N.
10 Independent modelling task
Your turn
- Choose a quantity to estimate by Monte Carlo — a probability, an integral, or a mean. State the estimator.
-
Run a pilot simulation with
N = 500. Compute the sample mean and sample standard deviation. -
Estimate the sample size required for a 95% confidence interval
with width
0.01, using the pilot standard deviation. - Run the simulation with the computed sample size. Compute the estimate, standard error, and 95% confidence interval.
- Verify that the interval width is close to the target. If not, extend the run and recompute.
-
Run the simulation at four additional sample sizes and plot the
standard error against
Non a log-log scale. Confirm the slope is approximately−1/2. - Write a one-paragraph report using the reporting template from section 7.
This exercise completes Laboratory 7 and the sampling-error component of Assignment 4.
11 Reflection prompt
Reflect before continuing
A Monte Carlo estimate has a very narrow confidence interval. Does this mean the estimate is accurate?
Two or three sentences. Consider the difference between sampling error (which the interval measures) and structural error (which it does not).
12 Lesson summary
Key takeaways
-
The standard error of a Monte Carlo estimator is
s/√N. It measures the variability of the estimator across repetitions. -
The 95% confidence interval is
θ̂ ± 1.96 · SE. Its width scales as1/√N. -
Sample size can be planned from a pilot run.
N ≥ (2 z σ / w)²for a target interval widthw. -
Convergence is verified by the running mean plot and the
standard-error scaling. The slope of the log-log SE
plot should be
−1/2. - The confidence interval measures sampling error only. It says nothing about model error.
Unit 4.1 complete
You have defined Monte Carlo estimators, applied them to integrals and probabilities, and quantified their sampling error. Unit 4.2 turns to the mechanics and design of simulation: how randomness is generated, how distributions are transformed, and how experiments are designed to reduce variance.
§ Self-quiz, practice, and homework
Self-quiz
Q1
The standard error of a Monte Carlo estimator is:
Show answer
s/√N.
Q2
The 95% confidence interval for a Monte Carlo estimate is approximately:
Show answer
θ̂ ± 1.96 · SE. The quantile 1.96 is the standard normal 97.5th percentile.
Q3
To halve the width of a Monte Carlo confidence interval, the sample size must be:
Show answer
Quadrupled. Width scales as 1/√N, so halving it requires N → 4N.
Q4
A running-mean plot is used to:
Show answer
Diagnose convergence of the estimator. A persistent trend indicates insufficient samples.
Q5
A narrow confidence interval around a Monte Carlo estimate guarantees:
Show answer
The sampling error is small. It says nothing about bias, model error, or accuracy.
Practice exercises
- Given a sample of size
N = 500with sample meanȲ = 0.746and sample standard deviations = 0.031, compute the standard error and the 95% confidence interval. - Estimate the sample size required for the same estimator to achieve a standard error of
0.001. - For a probability estimate
p̂ = 0.4atN = 2500, compute the standard error and the 95% confidence interval. - Sketch the running-mean plot you would expect for a well-converged Monte Carlo estimator. Then sketch the plot for a non-converged one.
Homework problems
-
Sample-size planning. Choose a quantity with a known analytical value. Run a pilot at
N = 500and use the pilot estimate to plan a full run at a target interval width. Run the full simulation and verify the actual interval width matches the target. Write a 500-word report. -
Coverage study. For the same estimator, run 100 independent simulations at
N = 500, each with a different seed. Compute the 95% confidence interval in each case and count how many contain the true value. Is the empirical coverage close to 95%? - Heavy-tailed caution. Estimate a quantity that involves a heavy-tailed random variable (e.g. the mean of a Pareto-distributed variable, or the variance of a Student's t with 3 degrees of freedom). Compare the nominal 95% confidence-interval coverage to the empirical coverage. Explain why they differ.
Mini project
Produce a complete Monte Carlo estimation report for a quantity of your choice. Include: the model and estimator, a pilot run, a sample-size calculation, the full run, the estimate, the standard error, the 95% confidence interval, the seed, and a convergence diagnostic plot. Submit the spreadsheet and a two-page report. This is the basis for Laboratory 7 and Assignment 4.