fix(stats): correct CI formula, zAxis drop, and edge guards#160
Merged
Conversation
Math review of ui/src/lib/stats.ts found several issues:
- computeProfiles dropped zAxis for the descriptive piece, so 3D charts
silently collapsed across the z dimension while correlation used z.
Now passes zAxis through to computeDescriptive (regression test added).
- 95% CI was a z-interval (z=1.96) on the population SD — systematically
too narrow for small n. Replaced with a Student-t interval: SEM uses
the sample SD (n-1) and the critical value is t*_{n-1} from a compact
lookup table with 1/df linear interpolation (<0.15% max error across
df=1..1000, folding to z=1.95996 in the limit). CI is NaN for n<2.
- correlationMatrix diagonal is now NaN for constant (zero-spread)
columns instead of a misleading 1, consistent with the NaN those
columns produce off-diagonal.
- cqv guard changed from p25+p75 !== 0 to > 0 so negative-spanning
distributions return NaN instead of an unstable/negative ratio.
- selectCorrelationAxis doc comment corrected (picks smallest usable
axis, not 'prefer x'); mad doc notes it is unscaled (not sigma-equiv).
The over-engineered Lanczos/incomplete-beta t-quantile was replaced by
the compact table+interpolation to keep the stats worker lean.
Also fix .lefthook.yml ui-gen-check hook: `set -euo pipefail` is
bash-only and fails under sh (dash); use `set -eu` instead.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Math review of
ui/src/lib/stats.tsfound several issues. This PR fixes the real bugs and tightens edge guards, keeping the stats worker dependency-free and lean.Fixes
Bugs
computeProfilesdroppedzAxisfor descriptive stats — 3D charts silently collapsed across the z dimension while the correlation in the same bundle used z. Now passeszAxisthrough tocomputeDescriptive. (Regression test added.)z=1.96) on the population SD — systematically too narrow for smalln. Replaced with a Student-t interval: SEM uses the sample SD (n-1) and the critical value ist*_{n-1}from a compact lookup table with1/dflinear interpolation (<0.15% max error acrossdf=1…1000, folding toz=1.95996in the limit). CI is nowNaNforn<2.Edge guards
correlationMatrixdiagonal is nowNaNfor constant (zero-spread) columns instead of a misleading1, consistent with theNaNthose columns produce off-diagonal.cqvguard changed fromp25+p75 !== 0to> 0so negative-spanning distributions returnNaNinstead of an unstable/negative ratio.Docs
selectCorrelationAxiscomment corrected (picks the smallest usable axis, not "prefer x").maddoc notes it is unscaled (no1.4826factor) — not a σ-equivalent.Approach note on the t-quantile
An initial implementation used Lanczos log-gamma + Lentz continued-fraction incomplete beta + bisection inverse (~95 lines, exact to 15 digits). That was over-engineered for a UI stats panel — replaced with a 12-row lookup table +
1/dflinear interpolation (~40 lines, <0.15% max error). The error is invisible at UI render precision.Infra fix
.lefthook.ymlui-gen-checkhook usedset -euo pipefail(bash-only); failed undersh(dash). Changed toset -eu.Test plan
vitest run— 354/354 pass (78 in stats file, 4 new)vue-tsc -b --noEmit— cleanprettier --check— cleanverify-gen-sync.tsconfirmsvizb-ui.gen.goin syncformat,go-test,ui-gen-check)