Tutorials › Pharmacometric Workflows and Reproducible Modeling › Assessing Random-Seed and Replicate Variability

Quality Control and Independent Review · Tutorial 346 of 399

Assessing Random-Seed and Replicate Variability

Use replicate-level variation and carefully controlled reruns to assess whether simulation differences are plausible Monte Carlo noise or evidence of a deterministic discrepancy.

Intermediate 10 min read

What You'll Learn

  • Distinguish a new random seed from an independent simulation replicate.
  • Estimate Monte Carlo standard errors from replicate-level summaries.
  • Calculate expected variation in simulated event proportions under stated assumptions.
  • Compare independent runs while accounting for the variability of each run.
  • Diagnose reproducibility, random-stream, and implementation problems without treating a noisy difference as proof of an error.

Why Compare Independent Replicates?

A simulation can produce different numerical summaries even when its model, inputs, and code have not changed. Random draws vary from run to run, so a simulated event proportion or mean is an estimate with Monte Carlo variation. A discrepancy between runs is therefore not automatically evidence of a changed model or a coding defect. The review question is whether the difference is plausible given the simulation’s expected random variation, and whether other evidence points to a deterministic difference.

The earlier material on checking simulation outputs against model intent concerns whether outputs are consistent with the intended model. Replicate assessment adds a related but distinct check: hold that intended model and its inputs fixed, vary the random draws, and quantify how much the reported summaries change. This does not replace checks of dose events, model components, or output logic. It helps separate stochastic variation from changes in configuration, implementation, or execution.

A replicate is one run of a specified simulation procedure. Its random seed initializes a pseudorandom-number generator; changing the seed commonly changes the sequence of generated values. A different seed is not, by itself, a proof that two runs are statistically independent. Independence depends on how the generator and streams are managed. Reproducible review therefore records the seed, generator and stream settings, simulation inputs, code version, and run configuration.

Replicate-Level Quantities and Assumptions

Definition: Let \(T_r\) be a numerical summary from replicate \(r\), such as an event proportion, a mean concentration, or a selected quantile, for \(r=1,\ldots,R\). When the replicates are independent and generated by the same procedure, \(T_1,\ldots,T_R\) are identically distributed under that procedure. The replicate average is \(\bar{T}=\frac{1}{R}\sum_{r=1}^R T_r\), and the observed replicate-to-replicate spread estimates the Monte Carlo variation in \(T_r\).

The same procedure means that the model, parameter values, input data or covariates, simulation size, output definition, and relevant options are held fixed. Only the intended random draws differ. If a run changes sample size, a parameter, a covariate distribution, or code, then its difference from another run is not attributable solely to random-seed variation. Such differences may be intentional, but they require a different comparison.

If each replicate summary has finite variance \(\tau^2\), independence gives the variance of the replicate average. The sample variance \(s_T^2\) estimates \(\tau^2\), so \(s_T/\sqrt{R}\) estimates the Monte Carlo standard error of \(\bar{T}\).

$$ \operatorname{Var}(\bar{T})=\operatorname{Var}\left(\frac{1}{R}\sum_{r=1}^R T_r\right) =\frac{1}{R^2}\sum_{r=1}^R\operatorname{Var}(T_r) =\frac{\tau^2}{R}, \qquad s_T^2=\frac{1}{R-1}\sum_{r=1}^R(T_r-\bar{T})^2, \qquad \widehat{SE}(\bar{T})=\frac{s_T}{\sqrt{R}}. $$

The variance equality uses independence: covariances between distinct replicates are zero. If replicates are correlated, that equality does not hold and the usual standard error can understate or overstate uncertainty. Also distinguish \(R\), the number of independent replicates, from the number of simulated subjects or draws within each replicate. More subjects within one run may reduce that run’s noise, but do not provide the same information about between-replicate variation as additional independent runs.

Event Proportions: Expected Variation Across Seeds

Suppose each replicate generates \(M\) independent, identically distributed Bernoulli outcomes with a common event probability \(p\). The simulated proportion in one replicate is \(\hat{p}=K/M\), where \(K\) is the number of events. Its expectation is \(p\), and its variance is \(p(1-p)/M\). Because \(p\) is usually unknown, substituting \(\hat{p}\) gives the estimated standard error for that replicate’s proportion. The common-probability and identical-distribution assumptions matter; independence alone does not justify this binomial formula.

$$ \operatorname{Var}(\hat{p})=\frac{p(1-p)}{M}, \qquad \widehat{SE}(\hat{p})=\sqrt{\frac{\hat{p}(1-\hat{p})}{M}}. $$

If independent Bernoulli outcomes instead have different event probabilities \(p_i\), then \(\hat{p}=M^{-1}\sum_{i=1}^M X_i\) has variance \(M^{-2}\sum_{i=1}^M p_i(1-p_i)\). The single binomial standard-error formula is not generally appropriate in that case. In a simulation review, first decide whether the outcomes are genuinely generated under a common probability or whether covariates or other individual-level features make their probabilities differ.

Worked Example: Comparing Two Simulated Event Proportions

In a hypothetical simulation, each replicate produces \(M=10{,}000\) independent, identically distributed event outcomes under the same model and settings. Two independent replicates produce 1,981 and 2,044 events. Assess whether their difference is large relative to expected Monte Carlo variation.

The replicate proportions are \(0.1981\) and \(0.2044\), so the observed difference is \(0.2044-0.1981=0.0063\), or 0.63 percentage points. Under the common-probability assumption, estimate \(p\) using the pooled proportion:

$$ \hat{p}_{\mathrm{pool}}=\frac{1{,}981+2{,}044}{2(10{,}000)}=0.20125. $$

The estimated standard error for the difference between two independent proportions, each based on \(M\) outcomes, is \(\sqrt{2\hat{p}_{\mathrm{pool}}(1-\hat{p}_{\mathrm{pool}})/M}\). Substitution gives:

$$ \widehat{SE}(\hat{p}_2-\hat{p}_1) =\sqrt{\frac{2(0.20125)(1-0.20125)}{10{,}000}} =\sqrt{0.0000321496875} \approx 0.005669. $$

The observed difference is about \(0.0063/0.005669=1.11\) estimated standard errors. That difference is not, by itself, an unusual signal of a deterministic change. This calculation is a scale check, not proof that the implementation is correct. It is appropriate here because the replicates were specified to use the same procedure, independent draws, and a common event probability.

Continuous Summaries and a Short Derivation

For a continuous output, the replicate statistic might be the mean apparent clearance among simulated subjects, a concentration quantile, or the fraction meeting a threshold. Calculate the same statistic in every replicate. The sample standard deviation \(s_T\) describes the spread of individual replicate summaries; the Monte Carlo standard error \(s_T/\sqrt{R}\) describes the estimated precision of their average. These answer different questions and should not be reported interchangeably.

The standard error formula follows directly from the variance of a sum. If each replicate statistic has variance \(\tau^2\), then independence makes every cross-product covariance zero. Thus the variance of the sum is \(R\tau^2\), and dividing that sum by \(R\) divides its variance by \(R^2\). The result is \(\tau^2/R\). Replacing the unknown \(\tau^2\) with the sample variance gives the estimated standard error above. This derivation also shows why the formula needs independent replicates with a common distribution and finite variance.

Worked Example: Monte Carlo Error in a Simulated Mean

Five hypothetical independent replicates each simulate the same number of subjects under fixed model inputs. Their mean apparent clearances are 1.02, 0.98, 1.01, 0.99, and 1.00 L/h. Calculate the average, replicate standard deviation, and Monte Carlo standard error of the average.

The average is \(\bar{T}=(1.02+0.98+1.01+0.99+1.00)/5=1.00\) L/h. The squared deviations from the average sum to \(0.02^2+(-0.02)^2+0.01^2+(-0.01)^2+0^2=0.0010\;(\mathrm{L/h})^2\). Therefore:

$$ s_T=\sqrt{\frac{0.0010}{5-1}} =\sqrt{0.00025} \approx 0.01581\ \mathrm{L/h}, \qquad \widehat{SE}(\bar{T})=\frac{0.01581}{\sqrt{5}} \approx 0.007071\ \mathrm{L/h}. $$

The five replicate means have an observed standard deviation of about 0.01581 L/h. The estimated Monte Carlo standard error of their average is about 0.007071 L/h. With only five replicates, this estimate is itself imprecise; it should not be presented as a highly stable characterization of the simulation’s variability.

Comparing Two Independent Runs

To compare two implementations or configurations, calculate the same summary in independent replicates from each. Let \(\bar{T}_A\) and \(\bar{T}_B\) be the averages across \(R_A\) and \(R_B\) replicates, with sample standard deviations \(s_A\) and \(s_B\). If the two sets of replicates are independent, the estimated standard error of their difference is \(\sqrt{s_A^2/R_A+s_B^2/R_B}\). This comparison is meaningful only if both sets target the same intended quantity; if a setting is deliberately changed, the expected change must be considered separately.

Worked Example: A Difference That Warrants Follow-Up

Two hypothetical implementations are intended to simulate the same model and produce the same output summary, in units of mg·h/L. Four independent replicate summaries from implementation A are 10.1, 9.8, 10.0, and 10.1. Four from implementation B are 10.3, 10.0, 10.2, and 10.3. Calculate the difference and its estimated Monte Carlo standard error.

The means are \(\bar{T}_A=10.0\) mg·h/L and \(\bar{T}_B=10.2\) mg·h/L. For each set, the squared deviations from its mean sum to \(0.06\;(\mathrm{mg\cdot h/L})^2\). Each sample variance is therefore \(0.06/(4-1)=0.0200\;(\mathrm{mg\cdot h/L})^2\), and each sample standard deviation is \(\sqrt{0.0200}=0.1414\) mg·h/L.

$$ \bar{T}_B-\bar{T}_A=10.2-10.0=0.200\ \mathrm{mg\cdot h/L}, \qquad \widehat{SE}(\bar{T}_B-\bar{T}_A) =\sqrt{\frac{0.0200}{4}+\frac{0.0200}{4}} =\sqrt{0.0100} =0.1000\ \mathrm{mg\cdot h/L}. $$

The difference is twice its estimated standard error. This is a review signal: check whether the intended inputs, output definitions, software versions, and random-stream setup truly match, then run more replicates if needed. Four replicates per implementation give a weak basis for characterizing variability, and a difference of this size does not establish that implementation B is wrong. It could be random variation, an unrecorded configuration difference, or an implementation discrepancy.

Diagnostics, Alternatives, and Limitations

A useful review separates reproducibility checks from statistical comparisons. First, rerun the same configuration with the same seed and generator settings. If the software is designed for deterministic replay, the outputs should reproduce to the documented numerical tolerance. Failure to reproduce is a reproducibility issue to investigate; it is not ordinary variation between independent seeds. Next, run distinct seeds using the same fixed configuration and compare replicate-level summaries. Record enough metadata to make either check interpretable.

Inspect the full set of replicate summaries, not just their average. A single extreme replicate, a steadily drifting sequence, unexpectedly identical outputs across distinct streams, or a spread that changes markedly between batches may indicate a problem. Check logs for warnings, failed runs, different sample sizes, missing outputs, accidental seed reuse, and stream overlap. Also verify that summary calculations use the same units, time points, and denominator in every replicate.

When there are only a few replicates, \(s_T\) is a noisy estimate of the true between-replicate spread. Highly skewed or heavy-tailed replicate statistics may also make a normal approximation for the average unreliable at small \(R\). A conventional interval based on a normal approximation, \(\bar{T}\pm 1.96\,\widehat{SE}(\bar{T})\), is only an approximate 95% interval when replicate averages are sufficiently close to normal and the standard error estimate is reliable. It is not a probability statement about a fixed parameter, and it should not be used mechanically with very few or pathological replicates.

The main alternative to independent-seed comparison is a paired comparison using common random numbers: align corresponding random inputs across two implementations, then analyze within-pair differences. Pairing can reduce noise when matched draws are positively correlated, but requires deliberate stream control and is not the independent-replicate calculation presented above. Repeating the exact same seed is useful for checking replay, not for estimating variation across independent simulations. In either approach, numeric agreement alone does not verify that the simulated model matches its intent.

Common pitfall: “The two outputs differ, so the model must have changed.” That conclusion ignores Monte Carlo variation. Conversely, “The difference is within two standard errors, so the implementation is correct” overstates what a noisy comparison can establish. Quantify expected variation, check that the runs are genuinely comparable, and investigate discrepancies that are large, structured, or irreproducible.

Check Your Understanding

Answer each question, then compare with the solutions.

  1. Each of \(M=2{,}500\) outcomes in a replicate is independent and identically distributed Bernoulli with estimated event probability 0.16. Calculate the estimated standard error of the replicate proportion.
  2. Why is a different seed not sufficient evidence that two runs are independent replicates?
  3. Three independent replicate summaries are 4.8, 5.0, and 5.2 mg/L. Calculate their average and the estimated standard error of the average.
  4. Two runs have identical inputs and code but different seeds. Their output summaries differ by 0.3 units, while the estimated standard error of their difference is 0.1 units. What is an appropriate review conclusion?

Solutions. (1) The common-probability Bernoulli assumption supports the formula: \(\sqrt{0.16(1-0.16)/2{,}500}=\sqrt{0.00005376}\approx0.007332\), or about 0.7332 percentage points. (2) Independence depends on the pseudorandom generator and stream management; distinct seed values alone do not establish independent streams. (3) The average is \((4.8+5.0+5.2)/3=5.0\) mg/L. The squared deviations sum to \(0.04+0+0.04=0.08\;(\mathrm{mg/L})^2\), so \(s=\sqrt{0.08/2}=0.2000\) mg/L and \(\widehat{SE}=0.2000/\sqrt{3}=0.1155\) mg/L. (4) The difference is three estimated standard errors, which warrants checking run settings, logs, and random-stream handling and possibly increasing the number of replicates. It is a diagnostic signal, not proof by itself of a deterministic implementation error.

Clinical Biostats