Why Regression Tests Need an Explicit Comparison Plan
A code change can alter a QSP simulation without causing a crash or violating an obvious physical constraint. A small difference in a state trajectory may shift a threshold-crossing time; a changed interpolation routine may affect a derived exposure measure; and an unintended parameter-indexing error may alter one treatment arm but not another. Regression tests make such changes visible by comparing selected, interpretable model results before and after a change.
A regression test is not simply a demand that every output remain numerically identical. Some changes are intended: for example, a corrected implementation may deliberately change a previously incorrect event time. A useful test plan therefore identifies what should remain stable, what is expected to change, and how much numerical variation is acceptable. It treats a difference as evidence to investigate, not automatic proof of a scientific error.
The comparison is meaningful only when the reference and candidate runs represent the same test case. For a deterministic simulation, record the model version or source revision, inputs, initial conditions, parameter values, solver settings, output times, units, and relevant software environment. Keep the reference results unchanged during testing; update them only through a documented review when a change is justified. If random variation is part of the implementation, one run against one stored trajectory is generally not a suitable test of distributional behavior. That situation requires a test designed for stochastic implementations rather than an exact snapshot comparison.
The tested quantities also need stable definitions. A quantity called “response at day 14” must specify which state or derived output is measured, its unit, and how the value at day 14 is obtained. A threshold event must specify the threshold, crossing direction, and rule for a crossing that never occurs. Without these details, apparent disagreement may come from comparing different observables rather than detecting a code regression.
Choosing Comparison Rules
Exact equality is appropriate only when identical inputs and execution are expected to produce bit-for-bit identical values and the output is not affected by floating-point or platform variation. For most numerical simulation outputs, a tolerance is more useful. Set it from the quantity’s scale, units, numerical precision, and the decision the test is intended to protect. Do not choose a tolerance merely because it makes a failing comparison pass.
Here \(\mathrm{atol}\) is an absolute tolerance in the units of the quantity, and \(\mathrm{rtol}\) is a dimensionless relative tolerance. The absolute term protects comparisons near zero, where a relative difference alone can be uninformative or undefined. The relative term allows a larger absolute difference for a larger reference value. Apply the rule component by component to a vector of selected outputs; a good match in one component should not conceal a failure in another.
For a derived quantity, apply the comparison to the final quantity as well as, where useful, to its inputs or trajectory. This can reveal errors that a sparse set of state checks misses. Conversely, checking only a derived quantity can conceal compensating errors in different parts of the trajectory. Choose observables that reflect the intended use of the model rather than storing every computed value without a reason.
A Practical Test Design
Record the inputs, initial conditions, parameters, scenario, output definitions, and computational settings that make the reference run reproducible.
Choose representative states at specified times, event times or event status, and derived quantities that matter to the model’s intended use.
Choose units, absolute and relative tolerances, and rules for missing or absent events. Document the reason for each tolerance.
Before running the comparison, state which observables are expected to change and which should remain stable. Specify an expected direction or range when scientifically justified.
Trace each difference to its cause. Update a reference only after confirming and documenting that the changed result is intended and acceptable.
Worked Example: Comparing a Concentration Output
Suppose a deterministic, hypothetical QSP test case records a cytokine concentration at day 7. The trusted reference is \(12.40\) ng/L. A candidate code change produces \(12.43\) ng/L. The test was specified in advance with \(\mathrm{atol}=0.02\) ng/L and \(\mathrm{rtol}=0.002\). Assume the input, initial conditions, output definition, and computational settings are unchanged.
The allowed difference is
The observed difference is
Because \(0.03\leq0.0448\), this comparison passes. It does not establish that every trajectory value is acceptable: it establishes only that this specified day-7 output meets its stated criterion. If a second tested output were outside its own tolerance, the overall test case would still require investigation.
Events and Derived Quantities
Event time is not interchangeable with a state value at a fixed time. To test an event, define what counts as an event and compare both its status and, if it occurs, its time. For example, define the event as the first downward crossing of a biomarker threshold. The test specification should say whether a trajectory with no crossing is expected, and how the crossing time is extracted. If one run has a crossing and the other does not, a numeric time comparison cannot resolve the disagreement: the event-status change itself is a failure unless it was planned.
Derived quantities require similarly explicit definitions. An area under a concentration-time curve (AUC), for instance, depends on the time interval and the numerical integration rule. A comparison is interpretable only if those are held fixed, or if a change in them is the intentional subject of the test. Units provide a practical check: if concentration is in mg/L and time is in hours, AUC is in mg·h/L.
Worked Example: Testing an Event Time and an AUC
In a hypothetical deterministic simulation, the first downward crossing of a biomarker threshold is expected near day 10. The reference event occurs at day 10.20; the candidate event occurs at day 10.24. The test allows an absolute event-time difference of 0.10 day. Both simulations have the defined crossing, so compare their times:
The event-time comparison passes. Next, over the fixed interval from day 0 through day 14, the reference AUC is \(84.0\) mg·h/L and the candidate AUC is \(85.1\) mg·h/L. With \(\mathrm{atol}=0.5\) mg·h/L and \(\mathrm{rtol}=0.01\), the allowed difference is
The observed AUC difference is \(85.1-84.0=1.1\) mg·h/L, so \(1.1\leq1.34\) and that comparison also passes. These results support agreement for these two specified observables; they do not guarantee that all intermediate concentrations agree.
Separating Planned Changes from Regressions
When a code change is intended to alter scientific behavior, record the expectation before examining the new results. For example, a corrected parameter mapping might be expected to change exposure in one treatment arm while leaving the control arm unchanged. Test both claims: verify that the targeted exposure changes in the justified way, and retain regression checks on unaffected outputs. A test suite that merely replaces old values with new ones can erase evidence of accidental changes.
Worked Example: A Planned Parameter-Mapping Correction
A hypothetical correction changes how a dose-specific parameter is assigned to the high-dose arm. Before correction, the recorded high-dose AUC is \(80.0\) mg·h/L; after correction, it is \(92.0\) mg·h/L. The scientific review has specified that this increase is expected. The low-dose AUC should remain \(40.0\) mg·h/L, with \(\mathrm{atol}=0.2\) mg·h/L and \(\mathrm{rtol}=0.005\).
The high-dose difference is \(92.0-80.0=12.0\) mg·h/L. It is an expected change, not a failure of the unchanged-output criterion; it still needs review against the documented scientific expectation. For the low-dose check, suppose the candidate result is \(40.1\) mg·h/L. Its allowed difference is
The observed low-dose difference is \(|40.1-40.0|=0.1\) mg·h/L, which is within the 0.40 mg·h/L tolerance. Thus the tested low-dose output remains within its criterion, while the high-dose output has changed as planned. The high-dose reference should be updated only after the correction and its effect have been reviewed and recorded.
Diagnostics, Alternatives, and Limitations
A failed comparison is a diagnostic signal. First confirm that the same test case and observable were used. Then inspect the size, direction, and location of the difference: a failure limited to one output time suggests a different pattern from a shift across all treatment arms. Check units, output indexing, event definitions, derived-quantity calculations, and the reference record. If a difference is numerical, report it in context, including the reference, candidate, observed difference, tolerance, and affected scenario. Do not silently widen the tolerance before identifying its cause.
Regression checks have a different role from other verification tests. Analytical reference solutions can compare a simulation with a known solution for a tractable case; invariant and limiting-case tests check properties or expected boundary behavior; metamorphic tests examine whether related inputs and outputs obey a known relationship. A regression test instead asks whether selected results changed relative to a trusted prior implementation. These methods complement one another: agreement with an old result cannot establish that the old result was correct, and a property test may not detect a change in a clinically important endpoint.
| Approach | Primary question | Key limitation |
|---|---|---|
| Regression comparison | Did selected outputs change from a trusted reference? | Can preserve an existing error if the reference is wrong. |
| Analytical or property-based verification | Does the implementation meet a known solution or required property? | May cover only selected cases or properties. |
| Metamorphic testing | Do related runs satisfy an expected relationship when no exact answer is available? | Does not necessarily determine the correct absolute output. |
Regression tests also have coverage limits. A finite set of scenarios cannot guarantee correctness for every parameter combination, treatment regimen, or virtual individual. Sparse output checks can miss a transient discrepancy between recorded times; summary quantities can hide offsetting trajectory errors. A passing regression suite is evidence that the selected checks meet their criteria, not proof of model validity, biological truth, or suitability for every intended use.
Common Pitfall
Wrong reasoning: “The candidate differs from the reference, so the code is defective; I will loosen the tolerance until the test passes.” This confuses difference with defect and makes the pass criterion depend on the observed result. The correction is to establish the comparison conditions and tolerance before testing, classify expected changes in advance, and investigate unexpected differences. If a justified scientific correction changes an output, preserve that explanation and update the approved reference through review rather than hiding the change with a broader tolerance.
Check Your Understanding
Answer each question, then compare with the solutions below.
- A reference output is \(5.00\) mg/L and the candidate is \(5.08\) mg/L. With \(\mathrm{atol}=0.02\) mg/L and \(\mathrm{rtol}=0.01\), does the comparison pass?
- Why should an event test compare event status as well as event time?
- A planned code correction changes one dose arm. Name one test that should target the changed output and one that should protect against an unintended side effect.
- What does a passing regression test establish, and what does it not establish?
Solutions. (1) The allowed difference is \(0.02+0.01(5.00)=0.07\) mg/L. The observed difference is \(0.08\) mg/L, so the comparison fails. (2) If one run has the event and the other does not, there is no pair of event times to compare; the change in event occurrence is itself important. (3) Check the intended dose-arm output against the documented expected change, and separately check an output expected to remain stable, such as the control arm or an unaffected dose arm. (4) It establishes that the selected outputs for the specified test case meet their stated comparison criteria. It does not establish that the reference is correct, that untested scenarios are correct, or that the model is biologically valid.