Repository navigation
Commit 2240528
committed
jc: corrective slice — fix omega sign erasure + R-squared scale dependence
External review of the merged #887 found two P1 numerical defects. Both were
REPRODUCED before fixing; both now carry regression tests.
1. omega_total erased loading SIGNS.
The triad identity yields lambda_i^2, hence only |lambda_i|, and the code
took the positive root for every item. omega depends on (sum lambda)^2,
where a negatively-keyed item must SUBTRACT. On an exact signed-congeneric
fixture (loadings [+1,-1,+1], equal orthogonal residuals) the true value is
0.25 and the shipped code reported 0.75.
Fixed by recovering signs from the covariance row: under one factor
sign(sigma_ij) = s_i*s_j, so anchor s_0 = +1 and read the rest off row 0.
The anchor is free because the model is identified only up to a global flip
and (sum lambda)^2 is invariant to one — asserted as its own test.
Sign CONSISTENCY is now also checked, which is a genuine partial one-factor
structure test. At k=3 it is provably subsumed by the existing negative-
lambda^2 guard (the sign product of the single triad is -1 exactly when the
pattern is inconsistent); it only becomes reachable at k>=4 where lambda^2
is averaged. The can-it-fire test therefore uses a k=4 fixture and
pre-registers that every lambda^2 and psi is non-negative, so only the sign
guard can be what rejects.
2. multiple_r_squared was SCALE-DEPENDENT.
Normal equations were built on raw columns and a pivot was called singular
below an ABSOLUTE 1e-12 — a statement about units, not rank. Measured: an
exact linear fit at 1e-8 magnitude returned None, while the identical
relationship at unit scale returned 1.0.
Fixed by centering the response and every predictor and scaling predictors
to unit norm. R-squared is affine-invariant so no correct answer changes,
the rank test becomes relative (diagonal is exactly 1), and centering
absorbs the intercept — so "collinear with the intercept" correctly
reappears as two identical centered columns. The [0,1] clamp is now bounded
to a rounding-scale band: a materially out-of-range value means the solve
failed and surfaces as None rather than as a plausible 0 or 1.
Also corrected / added:
- omega's doc claimed rejection means "the congeneric model does not fit". It
checks three NECESSARY conditions and cannot certify a one-factor matrix;
the vanishing-tetrad constraints are not tested and k>=4 misfit can still
return a number. Doc now states what is and is not verified.
- BinaryAssociation + binary_association: counts, BOTH marginals, p_o/p_e
alongside kappa and phi. The shipped phi doc said marginals are required to
interpret it while the function returned a lone scalar; that was an internal
contradiction.
- kr20(&[Vec<bool>]): the dichotomous naming surface C2 asked for and C1b did
not ship. Enforces binary input by type, delegates arithmetic to
cronbach_alpha, does not duplicate it.
- betacf now returns Option and reports non-convergence instead of presenting
the 300th iterate as a p-value; reg_inc_beta uses ln_1p(-x) near x=1 and
clamps only a rounding-scale excursion.
Board corrections in the same commit:
- The "unblocks D3's fusion falsifier" claim was WRONG and contradicted the
plan's own C3 (validity requires an external criterion). kappa is chance-
corrected agreement under the observed marginals; it measures overlap, not
incremental value. D3 is split: D3a (descriptive overlap, unblocked) and D3b
(held-out fusion falsifier, BLOCKED on an external criterion and a
criterion-appropriate scoring rule).
- C2's Spearman wording: on non-constant binary variables the average-rank
transform is affine, so rho is REDUNDANT with phi, not degenerate.
- C4's Jirak scope: jc::stats p-values are classical independent-sample
p-values; jirak.rs is a fingerprint-specific empirical probe, not a general
uncertainty engine. A dependent-cohort claim needs its own justified
dependence model.
- The exact-zero epiphany was too broad. Narrowed to theoretically
non-negative FITTED quantities needing a scale-aware tolerance; it is not a
licence to stop testing zero, since a zero determinant or zero within-group
variance is a real degeneracy.
- New epiphany E-THE-CROSS-IDENTITY-SUITE-INHERITED-MY-BLIND-SPOT-1: five
independent cross-identities all passed while both defects were live,
because every omega fixture had positive loadings and every R-squared
fixture was O(1). A cross-identity suite inherits the blind spots of its
fixtures silently, since every check reports green. The practice that would
have caught both: name the invariances the estimator should have (affine
rescaling, global sign flip) and write one test per dimension.
116 lib tests + 13 doctests green; stats.rs clippy-clean.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K3RyLEbuNSHxxB3NTTrGki1 parent 6b975b6 commit 2240528
4 files changed
Lines changed: 587 additions & 47 deletions
File tree
- .claude
- board
- plans
- crates/jc/src
| 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 | + | |
1 | 18 | | |
2 | 19 | | |
3 | 20 | | |
| |||
18 | 35 | | |
19 | 36 | | |
20 | 37 | | |
21 | | - | |
| 38 | + | |
22 | 39 | | |
23 | 40 | | |
24 | 41 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
271 | 271 | | |
272 | 272 | | |
273 | 273 | | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
274 | 305 | | |
275 | 306 | | |
276 | 307 | | |
277 | 308 | | |
278 | 309 | | |
279 | 310 | | |
280 | | - | |
281 | | - | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
282 | 315 | | |
283 | 316 | | |
284 | 317 | | |
| |||
326 | 359 | | |
327 | 360 | | |
328 | 361 | | |
329 | | - | |
330 | | - | |
331 | | - | |
332 | | - | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
333 | 373 | | |
334 | 374 | | |
335 | 375 | | |
| |||
0 commit comments