42.5 Where an expected value may come from
What you will learn
- Rank the four independent sources of an expected value and name an example of each.
- Recognise a regression baseline and say what it can and cannot detect.
- Spot circular tests, where the program checks itself.
- Learn from a defect that was found in the test package, not in the program.
Prerequisites: 42.4 Risk scoring and Chapter 40.2 Equivalence layers.
A test is only as good as the reference it compares against. If the expected value was produced by the program under test, the test can detect change but not error: a defect present in every version passes forever. The package therefore insists that expected values come from somewhere else.
1. Closed forms
Where mathematics gives the answer, use it.
- IV bolus, one compartment. AUC∞ = Dose / CL, t½ = ln 2 / k, V_z = V_ss = V, MRT = 1/k, C₀ = Dose / V. For the first noise-free subject of the NCA fixture (dose 100, CL 5, V 50, k 0.1): AUC∞ = 20, t½ = 6.9315, MRT = 10, C₀ = 2.
- Steady state without variability. For a model with no variability, CL = 4 L/h and 100 mg every 24 h, the AUC over the interval is 100 / 4 = 25 and C_avg = 25 / 24 = 1.0417; the simulated trough (0.2721) and peak (2.2125) come from the closed-form steady-state solution.
- Linear regression written as a
$PREDmodel. The least-squares solution follows from the normal equations; OFV = n (ln(RSS/n) + 1); SE = √(s² · diag((X′X)⁻¹)).
Closed forms are the strongest evidence: they are exact, free of random error and checkable on paper.
2. Independent code
Where there is no closed form, someone writes the computation again, without reference to the program. The package ships such calculators in tools/, all in the Python standard library: the trapezoid rules of NCA, an independent one-compartment IPRED, Newton–Raphson logistic and Poisson regression, the Cox partial likelihood with Breslow ties, Kaplan–Meier medians, the log-rank test, CDC LMS z-scores, VPC bin percentiles, and the non-central chi-square power. The independence is procedural: a second implementation written from the method, not from the first implementation's source.
Independent code is only as good as its own checking. That is why the calculators themselves are small, readable, and—where possible—compared against a closed form (the trapezoid code against the exact integral of an exponential, for example).
3. Known truth
A simulation with fixed seed and known parameters supplies a truth the estimates must recover within statistical error. The reference population pop_oral1 has 150 subjects and 1500 observations simulated with CL 4 L/h, V 40 L, K_A 1.2 /h, between-subject variances 0.09 (CL) and 0.04 (V), proportional error variance 0.0225, and body weight acting on CL (exponent 0.75) and on V (exponent 1.0). Age, sex, eGFR and a pure-noise covariate are not in the model.
Truth recovery is probabilistic, so its tolerance must be derived from the estimator's own precision (page 42.11). It also makes a powerful two-sided test: the covariate screen must retain the true effects (CLWT, VWT) and reject the false ones (CLAGE, VSEX, the noise covariate). A test that can only fail one way is half a test.
4. Properties
Some requirements are properties rather than values: the same seed yields the same bytes; one thread or four yields the same bytes; a changed file is detected; an existing folder is not overwritten; a line-ending change does not alter results. The reference is the program's own earlier output—but the claim is relational (A equals B), so the test is not circular.
The weakest source: the regression baseline
Sometimes the only available reference is the output of a validated build—for example the final OFV of the reference fit. The package allows this and says so wherever it does it: such a check "detects a change of behaviour between versions, not an error present in all versions." In practice the baseline is paired with a stronger test on the same quantity:
| Quantity | Strong test | Baseline test |
|---|---|---|
| Objective function | OQ-FIT-002: exact marginal likelihood by quadrature, within 0.5 | OQ-FIT-001: final OFV equals the supplier baseline within 0.05 |
| IPRED | OQ-FIT-003: recomputed independently to 1e-5 relative | — |
| Covariate-model OFV drop | PQ-002: true effects retained, false rejected | PQ-001: OFV below −3140 after a screen that predicted a 152-unit drop |
Read the table as a design rule: a baseline is acceptable as a tripwire only when a stronger test guards the same quantity.
How to spot a circular test
| Smell | Why it is circular | Repair |
|---|---|---|
| "Expected = value in the last run's output" | the program defines its own truth | replace with a closed form or independent code; keep as a tripwire only |
| Expected value computed with the program's own library or settings | a shared defect cancels | recompute with different code |
| A tolerance chosen after seeing the result | the test cannot fail | derive the tolerance first (page 42.6) |
| A fixture generated by the program, then fitted by the same program, with no truth recorded | recovery is untestable | record the generating values (the generate command writes truth.ctl) |
The closed-loop test PQ-002 is the interesting exception that proves the rule: it uses the program's generate command as the data source, but the generating effects (CLEGFR 0.6, CLWT 0.75, V~WT 1.0) are specified by the test, written into the protocol, and the cov command is judged against them. The program's two halves check each other against a truth neither invented.
A defect found in the tests, not the program
While the package's regression data were first being written, the CSV carried six significant digits but the expected values had been computed from the unrounded numbers. The program was then fitted to rounded data and compared with a truth for different data, so it appeared to differ from the closed form in the seventh digit of the OFV—a spurious failure. Two repairs followed: the data are now written exactly (Python's repr), and the expected values are computed from the written file; and python data/make_reference_data.py --check regenerates every file in memory and compares it with the committed file, so the pair cannot drift apart again.
The lesson generalises. The data file is part of the test, and the expected value must be computed from the file as written, never from the generator's internal variables. A second package defect surfaced on an older Python: sums of floats differ in the last binary digit between Python 3.12 and earlier versions, so the byte-for-byte check was relaxed for that one JSON file to 1e-12 while every test tolerance remains 1e-9 or wider. In both cases the package's own checks were validated by the package's own discipline—and in neither case was the program at fault.
Review checklist
- Does every High-risk expected value come from a closed form, independent code or known truth?
- Is each regression baseline labelled as such and paired with a stronger test?
- Was the expected value computed from the exact file the program reads?
- Can a test fail in both directions (true effect missed and false effect accepted)?
Navigation
See the previous page, the next page and the complete validation reference.