Why Separate Diagnostics Matter
A stochastic simulation can produce plausible-looking trajectories and still be wrong in more than one way. Event times may be generated from the wrong rate, a reaction may violate a conserved quantity, a numerical approximation may distort the distribution, or a small number of replicates may leave the estimated mean imprecise. These problems require different checks: increasing the replicate count does not repair a biased algorithm, and reducing a step size does not correct an incorrectly implemented event rate.
The diagnostics here apply to stochastic cellular models described by reaction channels, state changes, and propensities, including the continuous-time Markov chain (CTMC) formulation used in earlier material on cellular CTMCs and Gillespie’s direct method. They are checks against a specified model, not evidence that the model represents biology adequately.
For a CTMC in state \(x\), let reaction channel \(j\) have propensity \(a_j(x)\), and let \(a_0(x)=\sum_j a_j(x)\) be the total propensity. In a state where these propensities remain constant until the next event, the exact waiting time \(\Delta t\) has an exponential distribution with rate \(a_0(x)\). Conditional on an event occurring, channel \(j\) is selected with probability \(a_j(x)/a_0(x)\). These statements provide direct checks of event timing and channel selection.
Check Event Timing and Event Selection
A useful event-time diagnostic transforms each observed waiting time into a dimensionless residual:
For an exact direct-method simulation with fixed propensities between events, the residuals should follow an exponential distribution with rate 1, written \(R_i\sim \mathrm{Exp}(1)\). Its mean and variance are both 1. If propensities vary continuously with time, the corresponding residual is the integrated total hazard over the waiting interval, \(\int_{t_i}^{t_{i+1}} a_0(X(t),t)\,dt\). Residuals that are consistently too large or too small can indicate that waiting times are being generated at the wrong rate. Also inspect their spread and distribution: matching the mean alone is not enough to establish a good fit.
Event selection can be checked separately. At a fixed state \(x\), repeated events should select channel \(j\) with probability \(a_j(x)/a_0(x)\). Compare observed channel proportions with these probabilities in controlled tests or in groups of events where the state and rate structure make the comparison meaningful. In an unconstrained trajectory, state changes alter the probabilities, so pooling all events and comparing with a single probability can be misleading.
Worked Example: Checking Simulated Event Times
In a hypothetical CTMC test, the state is held fixed and the total propensity is \(2.00\) events per minute. A simulation records 1,000 waiting times. Their mean is \(0.520\) minutes. Check the mean waiting time using the integrated-hazard residuals.
The model predicts a mean waiting time of \(1/a_0=1/2.00=0.500\) minutes. The mean residual is
Under the exact model, the mean residual is 1 and its standard error for 1,000 independent exponential residuals is \(1/\sqrt{1000}=0.0316\). The observed difference is \(1.04-1=0.04\), or \(0.04/0.0316=1.27\) standard errors. This result does not show a conspicuous mean-rate discrepancy, but it does not prove that the implementation is correct. The residual distribution, channel selection, and other controlled cases still need checking.
Check Conservation Laws Against the State Changes
Some reaction networks conserve a total amount, such as the combined number of free and bound molecules. Write the state change for channel \(j\) as a column of the stoichiometric matrix \(S\). A vector \(c\) defines a conserved quantity when \(c^\mathsf{T}S=0\): every permitted reaction leaves \(c^\mathsf{T}x\) unchanged. Thus, if no external input, removal, or other explicitly modeled process changes that quantity, every simulated state should satisfy \(c^\mathsf{T}x(t)=c^\mathsf{T}x(0)\).
For a delayed reaction, the quantity being checked may need to include material in a pending event or an intermediate state. A molecule that has left one compartment but has not yet completed its delayed transition should not be counted as lost if the model treats it as still part of the conserved total. Define the accounting boundary from the model’s reaction scheme before interpreting a discrepancy.
Worked Example: Detecting a Conservation Violation
In a hypothetical closed binding model, a ligand moves between free state \(F\) and bound state \(B\). Each binding or unbinding reaction changes one state by \(+1\) and the other by \(-1\), so \(F+B\) is conserved. The initial state is \(F=100\), \(B=0\) molecules. A simulated trajectory reports \(F=61\), \(B=39\) at one time, then \(F=58\), \(B=39\) later.
At the first time, \(F+B=61+39=100\) molecules, consistent with the initial total. At the later time, \(F+B=58+39=97\) molecules. The residual from the conserved total is \(97-100=-3\) molecules. Since the model is closed and neither reaction changes the total, this is not ordinary stochastic variation: it points to an event-accounting, state-update, or output-recording error. The diagnostic identifies an inconsistency, though further investigation is needed to locate its source.
Diagnose Step-Size Bias in Tau-Leaping
The exact SSA advances from one reaction event to the next; it does not approximate the event process by taking a fixed time step. Tau-leaping instead advances by intervals of length \(\tau\) and approximates reaction counts over each interval. Its results can therefore depend systematically on \(\tau\). A practical check is to simulate the same model and outputs with successively smaller step sizes, using enough replicates that Monte Carlo uncertainty does not obscure the differences. Where possible, compare with an exact SSA result or an analytical benchmark.
Consider a pure-birth process in which each cell produces one additional cell at rate \(k\) per cell, so the propensity is \(a(x)=kx\). Over a step of length \(\tau\), a Poisson tau-leap draws a number of births with mean \(kx\tau\). Consequently, its conditional mean at the end of the step is \(x+kx\tau=x(1+k\tau)\). The exact process instead has mean \(xe^{k\tau}\) after that interval. The local difference follows from the exponential expansion:
For positive \(k\) and small \(\tau\), the exact conditional mean exceeds the one-step tau-leap mean. Across multiple steps the discrepancy accumulates. This comparison is a justification for checking step-size sensitivity, not a universal direction-of-bias rule for every reaction network or every output.
Worked Example: Measuring Step-Size Sensitivity
Suppose a hypothetical pure-birth model starts with \(X(0)=10\) cells, has \(k=0.200\) per hour, and is simulated to \(T=5.00\) hours. The exact mean is \(10e^{kT}=10e^1=27.18\) cells. Consider tau-leap simulations with step sizes of 1.00, 0.500, and 0.250 hours.
With \(m=T/\tau\) steps, the tau-leap expected mean is \(10(1+k\tau)^m\). For \(\tau=1.00\) hour, this is \(10(1.2)^5=24.88\) cells. For \(\tau=0.500\) hours, it is \(10(1.1)^{10}=25.94\) cells. For \(\tau=0.250\) hours, it is \(10(1.05)^{20}=26.53\) cells. The sequence moves toward the exact mean of \(27.18\) cells as the step shrinks.
For illustration, suppose 4,000 replicate simulations at these step sizes produced means of 24.90, 25.95, and 26.54 cells, with sample standard deviations of 7.90, 8.25, and 8.55 cells. Their standard errors are \(7.90/\sqrt{4000}=0.125\), \(8.25/\sqrt{4000}=0.130\), and \(8.55/\sqrt{4000}=0.135\) cells. The finest-step mean remains \(27.18-26.54=0.64\) cells below the exact benchmark, about \(0.64/0.135=4.74\) Monte Carlo standard errors. The observed gap is too large to attribute comfortably to replicate noise alone under this example’s assumptions. The analytic calculation confirms that step-size bias remains; simply adding replicates would estimate that biased mean more precisely.
Separate Replicate Convergence From Algorithmic Accuracy
For \(n\) independent replicate outputs \(Y_1,\ldots,Y_n\), the estimated mean is \(\bar{x}\), the sample standard deviation is \(s\), and the Monte Carlo standard error is \(SE=s/\sqrt{n}\). Under conditions that make the sampling distribution of the mean approximately normal, an approximate 95% Monte Carlo interval for the expected output is \(\bar{x}\pm1.96SE\). It describes uncertainty in the estimated expectation due to finite replication, conditional on the simulator and model being used. It is not an interval for an individual trajectory, and it does not account for algorithmic bias or model uncertainty.
A useful convergence check is to track the estimate and its standard error as independent replicates accumulate, and to inspect important outputs separately. A stable estimate with a small standard error indicates good Monte Carlo precision for that summary, not that the simulation algorithm is unbiased. For probabilities of rare events, the number of observed events and the uncertainty in the estimated probability matter; a narrow-looking interval for a common outcome does not establish precision for a rare one.
Worked Example: Interpreting Replicate Precision
In a hypothetical SSA analysis, 100 independent runs produce a terminal cell count with mean \(\bar{x}=12.4\) cells and sample standard deviation \(s=3.00\) cells. Estimate the Monte Carlo precision for the expected terminal count.
The standard error is \(SE=3.00/\sqrt{100}=0.300\) cells. Using the approximate 95% interval, \(12.4\pm1.96(0.300)=12.4\pm0.588\), giving 11.81 to 12.99 cells. Under the simulation model and the normal approximation for the replicate mean, this interval summarizes the Monte Carlo uncertainty in the expected terminal count. It does not mean that 95% of individual runs end in this range, nor does it establish that the simulator has no bias.
If the number of independent runs were increased to 400 while the standard deviation remained near 3.00 cells, the standard error would be \(3.00/\sqrt{400}=0.150\) cells, half as large. That gain improves precision, but only for the output of the algorithm being run.
A Practical Diagnostic Sequence and Its Limits
Check waiting-time residuals and channel probabilities against the propensities in controlled states. For delayed events, also check that the event is scheduled and completed at the intended time.
Evaluate conserved totals and other model-implied restrictions at every event or saved time, with delayed material included where required by the model.
For tau-leaping, compare key summaries across decreasing step sizes and against an exact or analytical reference when available. Investigate negative counts, large jumps, and abrupt changes in results.
Report \(n\), \(\bar{x}\), \(s\), and \(SE\) for mean outputs, and choose enough replicates for the precision required by the decision.
These checks complement rather than replace one another. Comparing an approximate method with SSA can reveal disagreement but cannot, by itself, identify which result is wrong if the model or implementation is flawed. Agreement across step sizes can also be misleading if all runs share the same event-handling error. The exact SSA is exact for the specified CTMC under its assumptions; it is not automatically exact for a different biological system. Likewise, conservation checks apply only to quantities the model truly conserves. A quantity can change legitimately when the model includes sources, sinks, or material outside the chosen accounting boundary.
Common Pitfall
Wrong reasoning: “The mean changed very little when I doubled the number of replicates, so the algorithm has converged and is unbiased.” Replicate stability addresses Monte Carlo variability in an estimate; it does not test whether event rates, stoichiometric updates, or tau-leap approximations are correct.
Correction: Check event timing and state updates against the model, assess conserved quantities where applicable, and test step-size sensitivity for approximate algorithms. Then use replicate standard errors to quantify the remaining Monte Carlo uncertainty. Report these as distinct diagnostics.
Check Your Understanding
Answer each question, then compare with the brief solutions.
- A fixed state has total propensity \(4.00\) events per minute. A simulated waiting time is \(0.300\) minutes. What is its integrated-hazard residual, and what is the reference distribution?
- A closed model conserves \(A+B=80\) molecules. A saved state reports \(A=47\) and \(B=31\). What diagnostic discrepancy is present?
- Why can increasing replicate count fail to remove the difference between a tau-leap estimate and an exact SSA expectation?
- If \(s=2.40\) cells across 144 independent runs, calculate the Monte Carlo standard error of the sample mean.
Solutions: (1) \(R=(4.00\ \mathrm{min}^{-1})(0.300\ \mathrm{min})=1.20\); under the exact fixed-state event-time model, residuals follow \(\mathrm{Exp}(1)\). (2) The reported total is \(47+31=78\), which is 2 molecules below the conserved total of 80; the discrepancy requires investigation rather than being explained by stochastic variation. (3) Replication reduces Monte Carlo error around the algorithm’s expected output, but does not eliminate systematic step-size bias in that output. (4) \(SE=2.40/\sqrt{144}=2.40/12=0.200\) cells.