Tutorials › Adaptive Clinical Trial Design › Monte Carlo Error for Means and Quantiles

Simulation-Based Design Assurance · Tutorial 669 of 799

Monte Carlo Error for Means and Quantiles

You will learn to measure the simulation uncertainty in estimated means and quantiles, and to choose a replication count that gives useful precision.

Intermediate 10 min read

What You'll Learn

  • Calculate Monte Carlo standard errors for means of simulated trial outcomes.
  • Approximate Monte Carlo uncertainty for a continuous-outcome quantile using its local density.
  • Construct and interpret simulation-based intervals for means and quantiles.
  • Relate replication count to a target margin of error.
  • Recognize when skewness, sparse tail data, or an unstable density estimate undermines a normal approximation.
  • Distinguish simulation uncertainty from variability among individual trial outcomes.

Why Simulation Error Matters for Means and Quantiles

A simulation study approximates a design property by generating and analyzing many trial replicates. Even when the design and data-generating scenario are fixed, the estimated mean sample size or the 90th percentile of trial duration can change if the simulation is rerun with a different random seed. That variation is Monte Carlo error: uncertainty caused by using a finite number of simulated replicates to estimate a quantity defined by the simulation scenario.

Monte Carlo error is distinct from variation among trials. For example, trial durations may vary widely from one simulated trial to another, while the estimated mean duration can still be precise if enough replicates are run. Conversely, a tail quantile may be imprecise even when the simulation produces thousands of replicates, because relatively few replicates determine that tail.

The earlier material on Confidence Intervals for Operating Characteristics develops intervals for simulated rates. Here the target is a mean or a quantile of a continuous outcome, such as final sample size, trial duration, or an estimated treatment effect.

Monte Carlo Error for a Mean

Definition: Let \(X_1,\ldots,X_R\) be the outcomes from \(R\) independent simulated trial replicates generated under the same fixed design and scenario. If each \(X_i\) has mean \(\mu_X\) and finite variance \(\sigma_X^2\), the estimated mean is \(\bar{X}=R^{-1}\sum_{i=1}^{R}X_i\). Its Monte Carlo standard error is estimated by \(SE_{\mathrm{MC}}(\bar{X})=s_X/\sqrt{R}\), where \(s_X\) is the sample standard deviation of the replicate outcomes.

This standard error estimates the standard deviation of the estimated mean across repeated simulation runs of size \(R\). Its units are the same as those of \(X\). For example, if \(X\) is final sample size, the Monte Carlo standard error is measured in participants. The formula assumes the replicate outcomes are independent and identically distributed under the scenario and that their variance is finite. A normal approximation for the sampling distribution of \(\bar{X}\) is generally reasonable for sufficiently large \(R\), though strong skewness or influential extreme outcomes can make the approximation poor.

When the normal approximation is suitable, an approximate 95% Monte Carlo interval for \(\mu_X\) is \(\bar{X}\pm1.96SE_{\mathrm{MC}}(\bar{X})\). It describes uncertainty in the simulated estimate of the scenario mean; it is not an interval containing 95% of individual trial outcomes.

Worked Example: Mean Final Sample Size

Suppose 4,000 independent hypothetical trial replicates are simulated under one design scenario. Their final sample sizes have mean 164.2 participants and sample standard deviation 32.0 participants. Assume the simulation code and scenario are fixed, and that no replicate is reused or otherwise dependent on another.

The estimated mean sample size is \(\bar{X}=164.2\) participants. Its Monte Carlo standard error is

$$ SE_{\mathrm{MC}}(\bar{X})=\frac{s_X}{\sqrt{R}} =\frac{32.0}{\sqrt{4{,}000}} =\frac{32.0}{63.246} \approx 0.506\text{ participants}. $$

The approximate 95% Monte Carlo interval is

$$ 164.2\pm1.96(0.506) =164.2\pm0.9918 =(163.21,\ 165.19)\text{ participants}. $$

Thus, under the stated simulation scenario and normal approximation, the estimated mean has a Monte Carlo margin of error of about 0.99 participants. The interval concerns the scenario's mean final sample size, not the range of sample sizes expected in individual trials.

Monte Carlo Error for a Quantile

Let \(F(x)=P(X\leq x)\) be the distribution function of a continuous simulated outcome. Its \(q\) quantile, written \(\xi_q\), is the value satisfying \(F(\xi_q)=q\), for \(0<q<1\), when \(F\) is continuous and the quantile is uniquely defined. The empirical estimate \(\hat{\xi}_q\) is the corresponding quantile of the \(R\) simulated outcomes.

Unlike a mean, a quantile's Monte Carlo error depends not only on the number of replicates but also on how concentrated the outcome distribution is near the target quantile. If the density \(f(\xi_q)\) is positive and sufficiently smooth near \(\xi_q\), then for large \(R\),

$$ SE_{\mathrm{MC}}(\hat{\xi}_q) \approx \sqrt{\frac{q(1-q)}{R f(\xi_q)^2}}. $$

The density has units of inverse outcome units, so this standard error has the outcome's units. A small density near the quantile means that a modest change in cumulative probability corresponds to a larger change in outcome value, making the estimated quantile less precise.

Why the Quantile Formula Holds

The justification follows from the sampling variation of the empirical distribution function and a local approximation to \(F\). At the true quantile, the number of simulated outcomes at or below \(\xi_q\) has a binomial distribution with parameters \(R\) and \(q\). Therefore the empirical cumulative proportion at \(\xi_q\) has mean \(q\) and variance \(q(1-q)/R\). For large \(R\), its error is approximately normal.

Near \(\xi_q\), differentiability of \(F\) with positive density gives the local approximation \(F(\xi_q+\delta)\approx q+f(\xi_q)\delta\). Thus, to first order, an error in cumulative proportion is converted into an error in quantile by dividing by \(f(\xi_q)\). The resulting variance is approximately

$$ \operatorname{Var}(\hat{\xi}_q) \approx \frac{q(1-q)}{R f(\xi_q)^2}, $$

which yields the stated standard error after taking the square root. This approximation requires independent replicates, a continuous distribution near the quantile, a positive and reasonably smooth density there, and enough simulations for the large-sample approximation to be useful. In practice, \(f(\xi_q)\) is unknown and must be estimated from the simulated outcomes.

Worked Example: The 90th Percentile of Trial Duration

In a hypothetical simulation, \(R=2{,}500\) independent trial durations are generated. The empirical 90th percentile is 18.0 days. For this illustration, suppose a local density estimate at 18.0 days is \(0.040\) per day, obtained from about 100 outcomes in a one-day-wide interval around that value. The density is positive and the replicate count is large enough to consider the asymptotic approximation, although the estimate should still be checked for stability.

Substitute \(q=0.90\), \(R=2{,}500\), and \(f(\hat{\xi}_{0.90})=0.040\) per day:

$$ SE_{\mathrm{MC}}(\hat{\xi}_{0.90}) \approx \sqrt{\frac{0.90(0.10)} {2{,}500(0.040)^2}} = \sqrt{\frac{0.09}{2{,}500(0.0016)}} = \sqrt{\frac{0.09}{4}} = \sqrt{0.0225} =0.150\text{ days}. $$

The approximate 95% Monte Carlo interval is

$$ 18.0\pm1.96(0.150) =18.0\pm0.294 =(17.706,\ 18.294)\text{ days}. $$

This interval quantifies the simulation uncertainty in estimating the scenario's 90th percentile duration. It does not mean that 95% of trial durations fall between 17.706 and 18.294 days; the 90th percentile itself describes the outcome distribution, while this interval describes uncertainty in the estimated percentile.

Planning Replications for a Mean

The standard error formula can be rearranged to plan the number of simulations needed for a chosen precision. If the replicate standard deviation is expected to be about \(s_X\), a target approximate 95% margin of error \(h\) for a mean requires

$$ 1.96\frac{s_X}{\sqrt{R}}\leq h \quad\Longrightarrow\quad R\geq\left(\frac{1.96s_X}{h}\right)^2. $$

The value of \(s_X\) is usually estimated from a pilot run or prior simulation experience, so the calculated replication count is a planning value rather than a guarantee. Rounding up is necessary, and a final precision assessment should use the standard deviation observed in the completed simulation.

Worked Example: Choosing Replications for a Mean

A pilot simulation suggests that final sample size has standard deviation 24 participants. The goal is an approximate 95% Monte Carlo margin of error no greater than 0.5 participants for the mean final sample size. Assume the pilot standard deviation is a reasonable planning value and independent replicates can be generated.

Rearrange the margin-of-error condition and substitute the values:

$$ R\geq\left(\frac{1.96(24)}{0.5}\right)^2 =(94.08)^2 =8{,}851.0464. $$

Because the replication count must be a whole number and must meet or exceed the bound, choose \(R=8{,}852\) replicates. Using the planning standard deviation, the resulting approximate margin is \(1.96(24)/\sqrt{8{,}852}\approx0.500\) participants. If the completed run has a larger standard deviation than 24, its actual Monte Carlo margin will be larger and should be reported as such.

Estimating and Checking Quantile Precision

A quantile standard error requires an estimate of the local density, not just the empirical quantile. One approach is to estimate the slope of the empirical distribution function near \(\hat{\xi}_q\). A local estimate based on a window of width \(w\), for example, is the fraction of simulated outcomes in that window divided by \(w\). More flexible density estimates can use nearby order statistics or a smoothed density curve. The choice of window or smoothing level matters: a narrow window can be noisy, while an overly wide one can conceal changes in density near the quantile.

For a normal-approximation interval, use the estimated density \(\hat f(\hat{\xi}_q)\) in the standard-error formula and calculate \(\hat{\xi}_q\pm1.96SE_{\mathrm{MC}}(\hat{\xi}_q)\). Interpret the result as an approximate interval for the scenario quantile, with the assumptions above in view. A density estimate close to zero, a tail quantile supported by very few observations, or a visibly irregular density near the target are warnings that this interval may be unreliable.

An alternative is an order-statistic interval. For a continuous distribution, the number of simulated outcomes below the true \(q\) quantile follows a \(\operatorname{Binomial}(R,q)\) distribution. This fact can be used to select lower and upper order-statistic indices with a desired coverage level, avoiding an explicit density estimate. Such intervals can be conservative because their coverage changes in discrete steps, and they can be wide when the quantile is in a tail. The density-based standard error is often a compact summary for large simulations; order-statistic intervals are a useful check when density estimation is questionable.

Diagnostics, Limitations, and a Common Pitfall

Before interpreting a Monte Carlo standard error, check that the simulated replicates are independent and generated under the same intended scenario. If outcomes are dependent, \(s_X/\sqrt{R}\) need not estimate the standard error correctly. Also inspect the outcome distribution: a mean can be sensitive to a long tail, while a quantile's estimated precision can be sensitive to local gaps, clustering, or an unstable density estimate. For a quantile, compare plausible density bandwidths or local windows; materially different standard errors indicate that the approximation needs caution.

The formulas quantify random simulation error, not errors in the protocol algorithm, the data-generating assumptions, or the chosen scenario. A very small Monte Carlo standard error cannot establish that the simulated model represents the clinical setting well. Nor does adding replicates remove bias from a coding error or an unsuitable model. Replication should be increased when the estimate is too noisy for its intended use, but first confirm that the simulation is producing the intended outcomes.

Common mistake: A student reports that a simulated 90th percentile is 18 days and concludes that about 90% of simulation runs will produce a quantile between 17.7 and 18.3 days. This confuses the outcome distribution with uncertainty in its estimated quantile. The 90th percentile is a feature of the distribution of individual simulated trial durations; a Monte Carlo interval describes uncertainty in estimating that feature from a finite set of replicates.

A second frequent error is to report the standard deviation of replicate outcomes as the Monte Carlo standard error of their mean. The standard deviation describes trial-to-trial spread; the estimated mean's Monte Carlo standard error is that standard deviation divided by \(\sqrt{R}\). For quantiles, reporting only the percentile and replicate count is not enough to assess precision: the local density also matters.

Check Your Understanding

Answer each question, then compare with the solutions below.

  1. A simulation has \(R=1{,}600\) independent replicate outcomes with sample standard deviation 20 units. What is the estimated Monte Carlo standard error of their mean?
  2. For a continuous outcome, \(q=0.75\), \(R=1{,}000\), and the density at the estimated quantile is \(0.10\) per unit. Calculate the approximate Monte Carlo standard error of the quantile.
  3. If the standard deviation of a simulated outcome stays fixed, what happens to the Monte Carlo standard error of its mean when the replication count is multiplied by four?
  4. Why can a tail quantile have substantial Monte Carlo error even when the number of simulated trials seems large?

Solutions. (1) \(SE_{\mathrm{MC}}=20/\sqrt{1{,}600}=20/40=0.500\) units. (2) \(SE_{\mathrm{MC}}\approx\sqrt{0.75(0.25)/(1{,}000(0.10)^2)}=\sqrt{0.1875/10}=\sqrt{0.01875}\approx0.137\) units. (3) It is divided by \(\sqrt{4}=2\), because \(SE_{\mathrm{MC}}=s_X/\sqrt{R}\). (4) A tail quantile is informed by a relatively small fraction of the simulated outcomes, and if the density near that quantile is low, a small cumulative-probability error can correspond to a large change in the quantile value.

Clinical Biostats