Commit 7a06a5c
test: extend ground-truth reference validation to advanced modules (W2-5) (#46)
## What changed & why
Per `.claude/tasks/prod-readiness/w2-5-reference-validation.md`: before
this PR,
`test/reference_validation_test.jl` covered only ~7 of ~40 stat modules
with
hand-derived ground truth. The advanced surface had only `isa
Dict`/`haskey`
smoke tests — a wrong-but-deterministic number there is exactly the
failure
class this project exists to prevent.
Adds `test/reference_validation_advanced_test.jl` (new file, 170 lines)
with
ground-truth reference assertions for 5 advanced tools (6 testsets,
since
fixed- and random-effects meta-analysis are exercised separately):
- **Kruskal-Wallis H test** — exact hand-computed H, tie_correction, df,
and
p-value via the closed-form df=2 chi-square survival function, on an
engineered no-ties 3-group design.
- **Multiple linear regression** — orthogonal 2-predictor design
(X1⊥X2⊥intercept)
makes XᵀX exactly diagonal, so coefficients/SE/t-stats/R²/adj-R² are
hand-computable in closed form without matrix inversion; p-values
checked
against a closed-form Student's-t(df=3) CDF (Gradshteyn & Ryzhik 2.103),
self-checked against the standard df=3, α=0.05 two-tailed critical value
t=3.182446305.
- **Logistic regression** — saturated single-dichotomous-covariate case
(Hosmer & Lemeshow, *Applied Logistic Regression* 3rd ed., §1.2), where
the
MLE reproduces the empirical log-odds per cell exactly (β = [-ln 3, 2 ln
3]);
cross-checked against an independent Newton/IRLS solve in Python 3.13.5
+
NumPy run locally (not committed — only the constants entered the repo).
- **Kaplan-Meier survival** — hand-computed product-limit estimator
(Kaplan &
Meier 1958) on a 5-point design with one censored tie.
- **Meta-analysis, fixed-effects** — inverse-variance weights chosen for
clean
arithmetic (w = [20,50,100]); combined effect and SE cross-checked with
Python `fractions.Fraction` exact rational arithmetic, run locally.
- **Meta-analysis, random-effects (DerSimonian-Laird)** — Q, τ²,
combined
effect, and I² on the same 3 studies, also cross-checked with
`fractions.Fraction` exact rational arithmetic, run locally.
Wired in via `test/runtests.jl` (+5 lines), `include`d at the end of the
existing include list per the overlap note with the parallel
`test/executor-router-coverage` work (trivial-rebase-friendly).
**Result: no bugs found.** All 42 assertions pass against the current
implementation — every advanced-module function checked reproduces its
independently-derived ground truth to the stated tolerance
(`atol`/`rtol` documented per case). No `@test_broken` cases were
needed.
## Scope change (per finalize review)
`chi_square` / `goodness_of_fit` were in the work order's *suggested*
first
tranche but are **out of scope for this PR** — they're being extended by
a
separate, dedicated PR (`test/chi-square-validation`). This PR does not
touch
chi-square in any way.
For the record, chi-square already has *some* ground-truth reference
coverage
today, predating this PR, in `test/reference_validation_test.jl` (lines
120–169 on `main`): a 2×2 contingency table (`chi_squared == 4.0`)
exercised
through `chi_square_test`, `chi_square_goodness_of_fit`, and the
`execute_tool("chi_square", …)` executor-dispatch path. I did not extend
or
re-derive that coverage, and did not find or fix any bug in chi-square
as
part of this work — that's the dedicated PR's job.
## Verification run & result
Ran the full suite exactly per the work order's Local verification step,
in
the WSL Debian login shell, serialized with flock:
```
flock /tmp/statistikles-julia.lock -c "cd <repo> && julia --project=. -e 'using Pkg; Pkg.test()'"
```
All green, no regressions:
```
Statistikles Full Test Suite | 424 424 21.8s
Statistikles E2E Pipeline Tests | 155 155 0.2s
Statistikles Property-Based Tests | 3800 3800 0.0s
Reference Validation (ground truth) | 62 62 6.8s
Degenerate Input Guards | 943 943 0.8s
Neural-Boundary Guardrail | 80 80 2.4s
Executor Router Coverage | 131 131 1.5s
Reference Validation — Advanced Modules | 42 42 0.1s
```
## Skipped / out of scope
- `chi_square` / `goodness_of_fit` — see "Scope change" above; handled
by
`test/chi-square-validation`.
- Bayesian, SEM, and causality modules — not in this PR's named tranche
(Kruskal-Wallis, multiple/logistic regression, Kaplan-Meier,
meta-analysis);
left for a future follow-up per the work order's "Out of scope" note.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Signed-off-by: Jonathan D.A. Jewell <6759885+hyperpolymath@users.noreply.github.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent 2e16724 commit 7a06a5c
2 files changed
Lines changed: 174 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1354 | 1354 | | |
1355 | 1355 | | |
1356 | 1356 | | |
1357 | | - | |
1358 | | - | |
1359 | | - | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
0 commit comments