Tutorials › Nonlinear Mixed-Effects Models (NLME) › Monte Carlo Error in Simulated Summaries

Simulation From Fitted Models · Tutorial 704 of 797

Monte Carlo Error in Simulated Summaries

Calculate Monte Carlo standard errors for common simulated summaries and interpret them separately from model-based uncertainty.

Intermediate 10 min read

What You'll Learn

  • Define Monte Carlo error as finite-simulation variability in an estimated summary.
  • Estimate the Monte Carlo standard error of a simulated mean.
  • Quantify Monte Carlo error for event probabilities using indicator variables.
  • Approximate quantile Monte Carlo error and identify when the approximation is unreliable.
  • Distinguish a simulation summary’s numerical error from uncertainty in the model-based outcome distribution.
  • Diagnose dependence and sparse-tail problems that make naive standard errors misleading.

Why Simulated Summaries Need an Error Measure

A simulation can produce thousands of plausible outcomes from a fitted nonlinear mixed-effects model, but a reported mean, percentile, or event probability is still calculated from a finite set of simulated values. If the simulation were repeated, the summary would generally change. Monte Carlo error describes this finite-simulation variability. It tells us how precisely the computation has estimated a summary of the distribution specified by the simulation procedure.

This is not the same as uncertainty about the model or the outcomes. A prediction interval describes variation in outcomes under a specified model and prediction target. Parameter uncertainty describes uncertainty about fitted model parameters. Monte Carlo error describes the additional numerical variability arising because we used a finite number of random draws to estimate a quantity. These sources can be present at the same time, but they answer different questions.

Definition: Let \(Y_1,\ldots,Y_M\) be simulated quantities generated to estimate a target summary \(T\) of a specified distribution. Monte Carlo error is the variation in the estimated summary across repeated runs of the simulation algorithm, with that target distribution and algorithm held fixed. The Monte Carlo standard error (MCSE) estimates the standard deviation of that repeated-run variation.

The simplest formulas assume the \(M\) simulated quantities are independent and identically distributed draws from the target distribution, with finite variance when estimating a mean. For nested simulations, the independent units must be complete independent simulation replicates; records sharing the same parameter draw or other shared random input are not automatically independent replicates. If draws are dependent, the independent-draw formulas below may understate error and must be replaced by methods that account for the dependence.

Monte Carlo Error for a Simulated Mean

Suppose the target is the expected value \(\mu_Y=E(Y)\), where \(Y\) has finite variance \(\sigma_Y^2\). The simulation estimate is the average of the \(M\) draws. Independence gives the variance of that average directly.

$$ \widehat{\mu}_Y=\bar{Y}=\frac{1}{M}\sum_{m=1}^{M}Y_m,\qquad \operatorname{Var}(\bar{Y})=\frac{\sigma_Y^2}{M},\qquad \widehat{MCSE}(\bar{Y})=\frac{s_Y}{\sqrt{M}}. $$

Here \(s_Y\) is the sample standard deviation of the simulated values. The estimated MCSE has the same units as \(Y\). It estimates how much the simulated mean would typically vary across repeated runs of size \(M\); it is not the standard deviation of individual outcomes. Under the usual large-sample approximation, \(\bar{Y}\) is approximately normal around \(\mu_Y\), so \(\bar{Y}\pm1.96\,s_Y/\sqrt{M}\) gives an approximate 95% interval for the simulation estimate’s repeated-run variability. This interval is about numerical precision for estimating \(\mu_Y\), not a prediction interval for a future outcome.

Worked Example: MCSE for a Simulated Mean Exposure

Suppose 2,500 independent hypothetical simulations produce an exposure measure in mg·h/L. Their mean is 8.40 mg·h/L and their sample standard deviation is 3.00 mg·h/L. Assume the simulations were generated from the same target distribution and have finite variance.

The estimated MCSE of the mean is

$$ \widehat{MCSE}(\bar{Y})=\frac{s_Y}{\sqrt{M}} =\frac{3.00\ \text{mg·h/L}}{\sqrt{2500}} =\frac{3.00}{50}\ \text{mg·h/L} =0.0600\ \text{mg·h/L}. $$

Thus, across repeated independent runs of 2,500 simulations, the estimated mean would typically fluctuate by about 0.0600 mg·h/L around the target mean. An approximate 95% Monte Carlo interval is \(8.40\pm1.96(0.0600)\), or 8.282 to 8.518 mg·h/L. This interval quantifies simulation precision for the target mean; it does not say that 95% of individual exposures fall in that range.

Monte Carlo Error for a Probability

A probability can be estimated by turning each simulated outcome into an indicator. For a defined event \(A\), set \(I_m=1\) if simulation \(m\) satisfies \(A\), and \(I_m=0\) otherwise. If the simulated outcomes are independent and each has event probability \(p=P(A)\), then the indicators are independent Bernoulli variables with variance \(p(1-p)\). Replacing \(p\) by the observed event fraction gives the estimated MCSE.

$$ \hat{p}=\frac{1}{M}\sum_{m=1}^{M}I_m,\qquad \widehat{MCSE}(\hat{p})= \sqrt{\frac{\hat{p}(1-\hat{p})}{M}}. $$

The MCSE is in probability units. The approximation is most useful when the sample contains enough events and non-events for a normal approximation to be reasonable. If the estimated probability is very close to zero or one, a symmetric normal interval can behave poorly; the MCSE formula remains a useful scale indicator, but a suitable binomial interval or more simulation may be needed for interval estimation.

Worked Example: MCSE for Target Attainment

In 2,000 independent hypothetical simulations, 1,460 outcomes meet a prespecified exposure target. The simulation event is defined identically for every draw, and all draws are generated from the same target distribution.

The estimated target-attainment probability is \(\hat{p}=1460/2000=0.730\). Its estimated MCSE is

$$ \widehat{MCSE}(\hat{p}) =\sqrt{\frac{0.730(1-0.730)}{2000}} =\sqrt{\frac{0.1971}{2000}} =\sqrt{0.00009855} \approx0.00993. $$

The probability estimate therefore has a Monte Carlo standard error of about 0.00993, or 0.993 percentage points. A rough normal-based 95% Monte Carlo interval is \(0.730\pm1.96(0.00993)\), which is approximately 0.7105 to 0.7495. It describes numerical uncertainty in estimating the target event probability, not uncertainty about whether any particular person will attain the target.

Monte Carlo Error for a Quantile

Quantiles require a different calculation because their precision depends not only on the number of simulations but also on how densely outcomes are concentrated near the quantile. Let \(q_\tau\) be the population quantile of order \(\tau\), so that \(F(q_\tau)=\tau\), where \(F\) is the cumulative distribution function. If the distribution has a positive, smooth density \(f\) near \(q_\tau\), a large-sample approximation is

$$ \widehat{MCSE}(\hat{q}_\tau) \approx \sqrt{\frac{\tau(1-\tau)}{M f(q_\tau)^2}}. $$

In practice, \(q_\tau\) and \(f(q_\tau)\) are unknown, so the formula uses the simulated quantile and an estimate of the density near it. The result has the units of the outcome: \(f(q_\tau)\) has inverse-outcome units, which makes the MCSE an outcome-scale quantity. The approximation can be unstable when the density estimate is poor, the distribution is irregular near the quantile, or very few simulated values lie in the relevant tail.

Justification: At the true quantile, the empirical distribution function \(\hat{F}_M(q_\tau)\) is the average of \(M\) independent indicators of the event \(Y_m\le q_\tau\). Its expectation is \(\tau\) and its variance is \(\tau(1-\tau)/M\). Near \(q_\tau\), a small change \(\Delta\) in the distribution-function value corresponds approximately to a change \(\Delta/f(q_\tau)\) in the outcome scale, because \(F(q_\tau+h)\approx F(q_\tau)+f(q_\tau)h\). Dividing the standard deviation of \(\hat{F}_M(q_\tau)\) by \(f(q_\tau)\) gives the stated quantile MCSE approximation. The argument requires a positive, sufficiently smooth density near the quantile.

Worked Example: MCSE for a Simulated 90th Percentile

Suppose 10,000 independent hypothetical simulations yield an estimated 90th percentile of 12.4 mg/L. A suitable local density estimate near that value is 0.020 per mg/L. Assume the outcome distribution has a smooth positive density in that neighbourhood.

Using \(\tau=0.90\), the approximate MCSE is

$$ \widehat{MCSE}(\hat{q}_{0.90}) \approx \sqrt{\frac{0.90(0.10)} {10{,}000(0.020\ \text{per mg/L})^2}} = \sqrt{\frac{0.09}{4\ \text{per (mg/L)}^2}} =0.150\ \text{mg/L}. $$

The approximate 95% Monte Carlo interval is \(12.4\pm1.96(0.150)\), or 12.106 to 12.694 mg/L. This interval reflects the expected run-to-run variation in the estimated 90th percentile under the specified simulation distribution. It is not an interval containing 90% of outcomes; the 90th percentile itself is the outcome threshold below which 90% of that distribution lies.

Separating Numerical Error from Model-Based Uncertainty

A simulated summary may target a distribution that already incorporates parameter uncertainty, between-subject variability, residual variability, or some combination determined by the simulation design. Monte Carlo error is conditional on that chosen target and on the procedure used to sample from it. Increasing \(M\) reduces finite-simulation error, but it does not by itself make the fitted model more appropriate, reduce uncertainty in the data, or change the target distribution.

For example, a prediction interval can be wide because future outcomes vary substantially, while its estimated endpoints have small MCSE because they were calculated from many simulations. Conversely, the target distribution can be narrow but a tail quantile can have appreciable MCSE if few simulations resolve that tail. Report the summary and its MCSE with the units and target clearly identified; do not combine or label them as if they measured the same source of uncertainty.

Diagnostics, Alternatives, and Limitations

A reported MCSE is useful only if its assumptions and estimation are credible. Check that the simulation replicates used in the formula are independent. In a nested design, many records may share a parameter draw or subject draw; treating all such records as independent can make the nominal replicate count much larger than the effective number of independent draws. For dependent simulation output, use an error estimate that accounts for dependence rather than applying the independent-draw formulas mechanically.

For means and probabilities, compare estimates and MCSEs across independent batches as a practical diagnostic. Batch estimates should fluctuate on a scale broadly compatible with their estimated errors. For quantiles, also inspect the simulated values around the estimated quantile and the stability of the local density estimate. Sparse tails, a multimodal or sharply changing distribution near the target quantile, or large changes under reasonable density-estimation choices signal that the asymptotic quantile MCSE may be unreliable.

When a summary has a tractable analytic calculation, using it can avoid simulation error for that summary. Otherwise, independent batches or a resampling-based estimate of the summary’s repeated-simulation variability can serve as checks; these methods still require adequate simulation output and do not remove model uncertainty. No single MCSE formula is universally valid: the mean formula needs finite variance, the probability formula relies on correctly defined independent event indicators, and the quantile approximation needs a regular positive density near the quantile.

  • Wrong: “The prediction interval is wide, so the Monte Carlo error must be large.”
    Correction: Prediction spread describes variation in the target outcomes; MCSE describes finite-simulation precision of an estimated summary.
  • Wrong: “There are 50,000 simulated records, so the independent-draw formula must use \(M=50{,}000\).”
    Correction: Use the number of independent simulation units relevant to the estimator. Shared random draws can induce dependence among records.
  • Wrong: “The quantile MCSE is small because the estimated quantile hardly changed between two runs.”
    Correction: Check the local density and tail information, and use repeated runs as a diagnostic rather than a substitute for a justified error estimate.
Key takeaway: State which distribution and summary the simulation targets, identify the independent simulation units, and report Monte Carlo error separately from model-based outcome or parameter uncertainty.

Check Your Understanding

Answer each question using the target and assumptions stated. Solutions follow the questions.

  1. For 1,600 independent simulations, a quantity has sample standard deviation 4.0 units. What is the estimated MCSE of its simulated mean?
  2. In 500 independent simulations, 40 satisfy an event. Calculate the estimated event probability and its MCSE.
  3. A 75th percentile is estimated from 4,000 simulations. The local density estimate is 0.10 per unit. Calculate the approximate quantile MCSE.
  4. In one sentence, distinguish a prediction interval from the Monte Carlo interval for an estimated mean.
  5. Why might using every record in a nested simulation as an independent replicate understate Monte Carlo error?

Solutions. (1) \(4.0/\sqrt{1600}=4.0/40=0.100\) units. (2) \(\hat{p}=40/500=0.0800\), and \(\widehat{MCSE}=\sqrt{0.0800(0.920)/500}=\sqrt{0.0001472}\approx0.0121\), or 1.21 percentage points. (3) \(\sqrt{0.75(0.25)/[4000(0.10)^2]}=\sqrt{0.1875/40}\approx0.0685\) units. (4) A prediction interval describes the distribution of outcomes under the model, whereas a Monte Carlo interval describes repeated-simulation variability in estimating a summary of that distribution. (5) Records sharing a parameter or other random draw are dependent, so the total record count overstates the number of independent units and can make a naive MCSE too small.