Understand simulation errorLesson 14 of 76 · 7 min

Watch convergence without promising a winner

Recognise the typical square-root relationship between independent trial count and numerical error.

For independent identically distributed draws with finite variance, the sample mean approaches the model expectation as the sample grows. This law-of-large-numbers statement does not say that every additional draw moves the estimate closer to the answer. The abbreviation i.i.d. means independent and identically distributed. Identically distributed means every draw uses the same model. Finite variance means its average squared deviation has a finite value, the condition used by the error rule below.

The standard deviation of the sample mean is the outcome standard deviation divided by the square root of n. Four times as many draws therefore halves that standard deviation under the same model. It is a statement about repeated experiments, not a guarantee for one running trace.

The exact mean of the squared uniform draws is one third. Python plots one running estimate and separately simulates 200 batches for each draw count. For each batch, it subtracts one third from the batch mean. It squares those errors, averages the squares, then takes the square root. This root mean square error (RMSE) estimates the typical size of the error across batches.

U2‾\overline{U^2} means average the squared uniform draws; n is their count. SE denotes the model standard deviation of that average across repeated runs.

A typical rate, not a promise for one trace
01.6k3.2k4.8k6.4k00.00880.0180.0260.035Model standard errorIndependent draws n
01.6k3.2k4.8k6.4k00.00880.0180.0260.035Model standard errorIndependent draws n
SE(U2‾)=4/(45n)\mathrm{SE}(\overline{U^2})=\sqrt{4/(45n)}
Reference illustration. Analytical standard-error curve for independent averages of U², with U uniform on [0,1]. Increasing draws by four halves typical error. A particular running estimate need not improve monotonically; its actual trace appears in the Python output.

Must the running estimate become closer to one third after every new draw?

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 ↗

n: 100 RMSE across batches: 0.02742
n: 400 RMSE across batches: 0.01447
n: 1600 RMSE across batches: 0.00691
n: 6400 RMSE across batches: 0.00362
Plot generated from the published Python during the build. Refer to its labelled axes and the text output.
Open full-size figure ↗

Read the first result

In the plot, find a place where the running estimate moves away from one third. In the text output, each line gives a draw count (n) and its RMSE across batches.

Try an edit

In the editor, replace 6400 with 10000 in the batch-size list [100, 400, 1600, 6400]. Select Run Python again. Compare “RMSE across batches” for n: 100 and n: 10000 in the new output. With 100 times as many draws, is the error about one tenth as large?

Back to the Python editor

Scope. The square-root rule applies to this independent finite-variance estimator. It is not a universal rate for MCMC or quasi-Monte Carlo.

Try a fresh case

Under the independent finite-variance model, reducing standard error by a factor of ten generally needs what?

Choose an answer
Need a hint?
Hint 1

Write SE proportional to 1/n1/\sqrt n.

Hint 2

Square the desired reduction factor.

Your notes