04
Estimating moments from Monte Carlo simulations
Monte Carlo moments are estimates whose precision depends on the number of independent simulations.
Monte Carlo estimators
For independent values \(X_1,\ldots,X_M\), estimate the first two raw moments and variance by
\[
\widehat m_1=\frac1M\sum_rX_r,
\qquad
\widehat m_2=\frac1M\sum_rX_r^2,
\qquad
s^2=\frac1{M-1}\sum_r(X_r-\widehat m_1)^2.
\]
Two different kinds of variation
| Quantity | Meaning |
|---|---|
| Sample variance \(s^2\) | Estimated intrinsic variation between epidemic outcomes. |
| Monte Carlo SE of the mean \(s/\sqrt M\) | Estimated numerical sampling error in \(\widehat m_1\). |
More simulations reduce Monte Carlo error, but they do not remove the biological stochastic variance represented by the model.
Interactive Python laboratory
Interactive PythonMonte Carlo moment estimates
Output
Run the code to see the result.
Interpret the interval correctly
The displayed 95% interval describes Monte Carlo uncertainty in the estimated mean under a normal approximation. It is not the range containing 95% of epidemic outcomes and does not include parameter uncertainty.
Reproducibility checklist
- State the seed, sample size, model and observation time.
- Use independent simulations.
- Report
ddof=1for sample variance. - Increase \(M\) and check that conclusions stabilise.
- Do not treat the largest run as the exact truth.
What this lesson adds
You can now estimate raw moments and variance from Monte Carlo samples, calculate the standard error of a mean estimate, and distinguish biological stochasticity from finite-simulation error.