Documentation

42.6 A tolerance with a reason

A tolerance ladder with a reason for every rung

What you will learn

  • Use the three tolerance types: exact invariants, deterministic numerical, and stochastic.
  • Give every tolerance one of five origins, and refuse a tolerance that has none.
  • Derive a tolerance before looking at the result, using worked examples.
  • Understand why a global tolerance must never be widened to turn a suite green.

Prerequisites: 42.5 Sources of truth and Chapter 40.3 Why numbers differ.

"Within 1e-6" is not a tolerance; it is a number. A tolerance is a number and the reason it is that number. Chapter 40.23 stated the rule: a tolerance copied from another metric has no evidentiary basis. This page shows how the package applies it.

Three types

Type Used for Form
Exact structural invariant counts, identifiers, exit codes, file presence, byte-for-byte equality equals, or files_identical
Deterministic numerical recomputation of a closed form or independent code absolute and/or relative tolerance
Stochastic truth recovery, nominal coverage, Monte Carlo summaries a band derived from the estimator's standard error or the Monte Carlo error

Mixing the types is the commonest mistake: using an exact comparison on a stochastic quantity produces flaky failures, and a stochastic band on a structural quantity hides defects.

Five origins

Every rung of the ladder above has one of these written next to it.

  1. Analytical truth — the reference is exact, so the tolerance is the arithmetic's own precision plus a safety factor.
  2. Reference repeatability — the reference is itself a computed result, so the tolerance is how much that result varies across seeds, threads or platforms.
  3. Floating-point study — the tolerance follows from measured rounding behaviour.
  4. Monte Carlo precision — the tolerance is a multiple of the standard error of a simulated estimate.
  5. Clinical decision margin — the tolerance is how far a number may move before a decision changes.

Worked derivations

Matrix exponential versus the closed form (relative 1e-9)

The one-compartment oral model has a closed-form solution. The same model written as a linear $DES is solved by the matrix exponential; written with a zero non-linear term it falls to the adaptive ODE solver. The package requires the objective function at fixed parameters to agree to 1e-9 relative (matrix exponential) and 1e-7 relative (ODE solver). Where do those numbers come from?

Recompute the concentration for CL = 4 L/h, V = 40 L, K_A = 1.2 /h, dose 100:

Time (h) Closed form Matrix exponential Relative difference
0.5 1.097503059291 1.097503059291 2.0e-16
2 1.985489453969 1.985489453969 1.3e-15
8 1.225257914675 1.225257914675 0
24 0.247412599879 0.247412599879 1.1e-16

The measured disagreement is at the level of double-precision rounding, about 1e-15. A tolerance of 1e-9 leaves six orders of magnitude of safety: loose enough that a different CPU or compiler cannot trip it, tight enough that a wrong exponential (say an off-by-one in a series truncation) cannot hide. Origin: floating-point study.

For an adaptive solver the achievable accuracy is set by the solver's own tolerance. Solving the same two-state system with relative tolerances of 1e-6, 1e-8 and 1e-10 and comparing with the closed form at 24 h gives relative errors of 2.1e-6, 2.0e-8 and 5.7e-11: the error tracks the requested tolerance almost one for one. A solver run with TOL = 8 (1e-8) therefore justifies a comparison tolerance of 1e-7, one decade above the solver's own. Origin: reference repeatability of the solver.

Truth recovery (relative 10 %)

The reference population is fitted without the weight effect, and the test requires CL, V and K_A each within 10 % of the generating 4.0 L/h, 40 L and 1.2 /h. The package states the standard errors of those estimates—CL 3 %, V 2.4 %, K_A 1.3 %—which let us ask: how often would a correct program fail this check on a fresh data set?

For a normal estimator with relative standard error s, the probability of landing more than 10 % from the truth is 2 [1 − Φ(10 / s)]:

Parameter SE 10 % is … SE Probability of a false failure
CL 3.0 % 3.3 8.6 × 10⁻⁴
V 2.4 % 4.2 3.1 × 10⁻⁵
K_A 1.3 % 7.7 1.4 × 10⁻¹⁴

With the seed fixed, the data set is the same on every run, so these are not run-to-run flakiness rates; they say how likely it is that the one fixed data set happens to be an unlucky draw for a correct program. For K_A the band is generous; for CL the odds are about 1 in 1200, a defensible price for a check that still detects a bias of 10 %. A 5 % band for CL would be an unlucky-draw probability of 9.6 % and a poor test. Origin: Monte Carlo precision. Page 42.11 develops this.

The regression-baseline OFV (absolute 0.05)

The final OFV of the reference fit equals the supplier baseline within 0.05. The tolerance reflects reference repeatability: optimisers can stop at slightly different points across CPU architectures, shifting the OFV in the last digits. The package says explicitly that it allows for this and says where it requires tighter agreement. At the same time it flags this check as a tripwire for change, never as evidence of correctness (page 42.5).

The Laplace approximation (absolute 0.5 and 0.005)

FOCE-I and Laplace approximate the marginal likelihood, so they cannot be expected to match the exact value to rounding. The package accepts 0.5 OFV units at a between-subject variance of 0.04, and 0.005 when the variance shrinks to 1e-4, because the Laplace approximation becomes exact as the random effect vanishes. The tolerance is a mathematical property of the method, stated in the test; page 42.10 shows the convergence numerically.

The ladder, read as a whole

Looking at the figure, three clusters appear. The blue rungs, from 1e-12 to 1e-3, compare against closed forms or independent code and become looser only as the quantity becomes harder (a log-trapezoid on extreme scales is 1e-9; a forest-plot ratio compared at three decimals is 1e-3). The orange rungs are statistical or approximation-driven and are two to four orders looser. The violet rung is the baseline, kept at 0.05 as a tripwire. A suite whose tolerances were all 1e-6 would be too tight for the orange tests and too loose for the blue ones.

Rules that keep a tolerance honest

  • Derive before you look. Set the tolerance from the origin, then run. A tolerance chosen after seeing the difference cannot fail.
  • Use absolute and relative together near zero. A tiny absolute difference can be large relative to a parameter near zero; a small OFV difference can cross a likelihood-ratio threshold. Where a decision hangs on a threshold, add a decision margin around it.
  • Never widen a global tolerance to make a suite green. Investigate the failure by layer (page 42.15); change the one test whose origin changed, with a written reason, under change control.
  • Preserve raw precision. Compare unrounded values; round only for display. A reference computed with six significant digits cannot support a 1e-9 comparison (the cautionary tale of page 42.5).
  • State the direction. Systematic bias matters more than the maximum difference; record signed differences, not just absolutes.

Review checklist

  • Does each tolerance in your protocol name one of the five origins?
  • Was it derived before the first execution?
  • Is an exact comparison used on any stochastic quantity, or a stochastic band on any structural one?
  • Is there a decision margin wherever a threshold changes a conclusion?

See the previous page, the next page and the complete validation reference.