42.11 Statistical checks and Monte Carlo tolerance
What you will learn
- Design a truth-recovery test whose chance of failing a correct program is known and small.
- Use two-sided tests: true effects retained and false effects rejected.
- Compute a Wilson interval for a small number of replicates and read its width honestly.
- Know why fixing the seed makes a test repeatable but not automatically valid.
Prerequisites: 42.6 Tolerance policy and Chapter 30 trial-design theory.
Numerical tests ask whether arithmetic is right. Statistical tests ask whether an estimator behaves as theory says: that it recovers the truth, controls false positives, and attains nominal coverage. Their reference is a distribution, so their tolerance must be a probability statement, not a decimal place.
The central quantity: the false-failure probability
For any statistical check, define
false-failure probability = P(the check fails | the program is correct).
A check with a high false-failure probability is useless for validation (it fails correct programs and trains testers to re-run until green); a check with a zero false-failure probability usually has a band so wide it cannot fail at all. The art is in between. For an estimator that is approximately normal with standard error s, a symmetric band of ±t around the truth fails a correct program with probability 2 [1 − Φ(t/s)]. The figure plots this against k = t/s.
| k | False-failure probability |
|---|---|
| 1 | 0.317 |
| 2 | 0.0455 |
| 3 | 2.7 × 10⁻³ |
| 4 | 6.3 × 10⁻⁵ |
| 5 | 5.7 × 10⁻⁷ |
| 6 | 2.0 × 10⁻⁹ |
The package's recovery test, with a 10 % band for estimates that have standard errors of 3 % (CL), 2.4 % (V) and 1.3 % (K_A), sits at k = 3.3, 4.2 and 7.7: false-failure probabilities of 8.6 × 10⁻⁴, 3.1 × 10⁻⁵ and 1.4 × 10⁻¹⁴ (the markers in the figure). A band of k ≥ 3 is a good working rule for a data set that is fixed by seed: it is wide enough that an unlucky draw is rare, narrow enough that a 10 % bias is caught.
Fixing the seed: repeatable, not automatically valid
With a fixed seed, the simulated data set is identical on every run, so a deterministic program gives the same estimates and the test never flickers. That solves repeatability. It does not solve validity: the one fixed data set might, by bad luck, sit in the tail of the sampling distribution, and a correct program would then fail the test on every machine for ever. The false-failure probability is the odds of having picked such a data set. This is why a band of k ≥ 3, not k = 1, is used, and why a failing statistical test should be investigated with a second seed before a defect is declared: a defect fails both, bad luck fails one.
Two-sided design: retained and rejected
A check that can only fail in one direction is half a test. The covariate screen test (OQ-COV-001) and the closed-loop test (PQ-002) are two-sided:
| Candidate | Truth | Must be |
|---|---|---|
| CL~WT, power form | in the generating model (exponent 0.75) | retained |
| CL~EGFR, power form | in the generating model (exponent 0.6) | retained |
| V~WT, power form | in the generating model (exponent 1.0) | retained |
| CL~AGE | not in the generating model | rejected |
| CL~SEX, proportional | not in the generating model | rejected |
| V~AGE | not in the generating model | rejected |
| V~SEX, proportional | not in the generating model | rejected |
| CL~CRCL | a near-copy of EGFR | uncertain or rejected, not retained as an independent effect |
The last row is the interesting one. A correlated surrogate of a true covariate should not be reported as a second independent effect, but it is not "wrong" to call it uncertain; the test accepts either of the two non-retained classifications, a regex ^(uncertain|rejected)$, instead of pretending the program knows more than the data can say. Matching the test to what the statistics can support is part of the design.
Few replicates, wide intervals
Simulation-based tests such as power by simulation–estimation (SSE) estimate a proportion from a small number of replicates. The correct summary of a proportion is an interval, not a point. The Wilson interval for k successes in n trials is
(p̂ + z²/2n ± z √(p̂(1−p̂)/n + z²/4n²)) / (1 + z²/n), with z = 1.96 for 95 %.
Recomputing the Chapter 31 executed examples:
| Replicates (successes / n) | Point estimate | 95 % Wilson interval |
|---|---|---|
| 5 / 6 | 0.833 | 0.436 – 0.970 |
| 9 / 12 | 0.750 | 0.468 – 0.911 |
| 7 / 12 | 0.583 | 0.320 – 0.807 |
These reproduce the intervals printed in the book's frozen Chapter 31 evidence (0.436–0.970 for the six-replicate uncertainty example; 0.468–0.911 and 0.320–0.807 at N = 30 and N = 45 of the twelve-replicate comparison). They also show why that evidence is labelled teaching evidence, not qualification: an interval running from 0.44 to 0.97 cannot distinguish a power of 0.5 from a power of 0.95. In the same evidence the SSE point estimates are non-monotone (0.750 at N = 30, 0.583 at N = 45, 0.917 at N = 60) while the exact closed-form power increases smoothly (0.646, 0.816, 0.910). A validation test that asserted "power is monotone in N" on twelve replicates would fail a correct program.
Design consequence. Use few replicates only for smoke tests (the command runs and the result is in the right region). For a quantitative claim, choose n so that the Monte Carlo standard error is a fraction of the tolerance: with the SE of a proportion √(p(1−p)/n), a power near 0.8 needs n = 400 for an SE of 0.02, and n = 1600 for 0.01. Pair the stochastic claim with a deterministic one wherever possible: the closed-form Wald power (next section) is exact for a given standard error and costs nothing.
Pair stochastic claims with deterministic ones
Two tests in the package check power. OQ-PWR-002 runs SSE and asks only that the simulation and re-estimation recover the model (a Low-risk smoke test). OQ-PWR-003 is High-risk and deterministic: from each standard error in the Fisher-information power table it recomputes the non-centrality λ = (β − β₀)² / se², the power Φ(√λ − z) + Φ(−√λ − z), and the number of subjects for the target power (λ scales with N), and compares them with the program's table to 1e-4.
Applied to the executed Chapter 31 table:
| N | SE of the CL~WT effect | λ = (0.75 / SE)² | Power | N for power 0.8 |
|---|---|---|---|---|
| 30 | 0.32110 | 5.4554 | 0.6464 | 43.16 |
| 45 | 0.26218 | 8.1832 | 0.8161 | 43.16 |
| 60 | 0.22706 | 10.9109 | 0.9104 | 43.16 |
All three rows agree with the program's table to every printed digit. Note the structure of the check: the same required N (43.16, reported as 44 subjects after rounding up) falls out of three different sample sizes, because the information is proportional to N. That invariance is itself a test of the design calculation, and it needs no simulation at all.
Truth recovery and shrinkage, honestly
Recovery tests inherit estimator behaviour. Three cautions keep the check honest:
- Test what the estimator can identify. The reference fit omits the weight effect, so the variance estimates are inflated; the bands for OMEGA(1,1) (0.08–0.20) and OMEGA(2,2) (0.03–0.12) are wider than the truth (0.09, 0.04) because the test author knows this.
- Do not test unidentified quantities. A parameter the model never uses must be flagged and must not spoil the other standard errors (OQ-FIT-014); the test asserts the flag, not a number.
- Respect the sampling distribution of the quantity. Variances are positively skewed at small n; a symmetric ±10 % band is wrong for them and a band derived from the simulation is right.
Review checklist
- For each statistical check, is the false-failure probability written down and below about 10⁻³?
- Is it two-sided (true retained, false rejected)?
- Where a proportion is estimated from few replicates, is it reported with an interval?
- Is there a deterministic companion for every stochastic power or coverage claim?
- Does a failing statistical test trigger a second-seed run before a defect is declared?
Navigation
See the previous page, the next page and the complete validation reference.