refactor(statistics): consolidate divergent pearsonR copies into one shared helper#273
Merged
Conversation
…e shared helper Seven files each carried a private Pearson-correlation implementation with divergent edge-case handling: n<2 returned 0 in some copies and NaN in others; zero-variance returned 0 in two copies and 1 in five; one copy had no length guard at all and one allowed n=1. The same divergence existed for the rank-with-ties and Spearman helpers. Add a single edge-cased pearsonR/spearmanR/ranks to the canonical statistics module (already the home of the project's stat primitives) and route every call site through it. Contract: length-mismatch or n<2 -> NaN (undefined, not a measured 0); both series constant -> 1; exactly one constant -> 0. analyze-runs' inter-rater kappa now averages only the finite pair correlations, so a degenerate pair (single jointly-rated run, or a constant rater) no longer drags the mean toward an artificial 0. Net -52 LOC; pearsonR/spearmanR/ranks newly exported from the root entry.
tangletools
previously approved these changes
Jun 22, 2026
tangletools
left a comment
Contributor
There was a problem hiding this comment.
✅ Auto-approved PR — 4b72e2ae
Blanket team auto-approval is enabled for this reviewer service.
The full PR reviewer audit still runs separately and will publish findings if it detects issues.
tangletools · auto-approval · reason: blanket_auto_approve · 2026-06-22T13:40:02Z
Version trio bumped together (npm package.json + clients/python/pyproject.toml + agent_eval_rpc.__version__) per the npm<->PyPI lock.
tangletools
approved these changes
Jun 22, 2026
tangletools
left a comment
Contributor
There was a problem hiding this comment.
✅ Auto-approved PR — e7ca9d1c
Blanket team auto-approval is enabled for this reviewer service.
The full PR reviewer audit still runs separately and will publish findings if it detects issues.
tangletools · auto-approval · reason: blanket_auto_approve · 2026-06-22T13:42:38Z
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.
Closes the pearsonR-consolidation item from #77 (the named post-#263 follow-up).
Problem
Seven source files each carried a private Pearson-correlation implementation, with divergent edge-case handling:
n < 2rl/reward-hacking.ts000pipelines/judge-agreement.tsNaN10judge-calibration.tsNaN10builder-eval/correlation.ts10contract/analyze-runs.ts0(allows n=1)00meta-eval/rubric-predictive-validity.tsNaN10meta-eval/correlation-study.tsNaN10The rank-with-ties and Spearman helpers were duplicated alongside them (4
ranks/rankWithTiescopies).Change
One
pearsonR/spearmanR/ranksadded tosrc/statistics.ts— already the home of the project's stat primitives (pairedBootstrap,cohensD,mcnemar, …) — and every call site routed through it. Newly exported from the root entry.Edge-case contract (explicit, documented in-file):
n < 2→NaN(correlation is undefined; distinct from a measured0)1(degenerate perfect agreement)0(no covariation to detect)This matches the dominant (5/7) convention and is the statistically defensible one.
analyze-runsinter-rater kappa now averages only the finite pair correlations, so a degenerate pair (a single jointly-rated run, or a constant rater) yieldsNaNand is dropped rather than dragging the mean toward an artificial0— the same patternjudge-calibration'savgPairwiseandcorrelation-study's bootstrap already use.All 7 local copies (
pearson/pearsonR/spearman/spearmanR/ranks/rank/rankWithTies) deleted. Net -52 LOC.Verification
pnpm run typecheck— cleanpnpm run lint— exit 0 (pre-existing warnings only, none in touched files)pnpm run build— clean (tsup + openapi)pnpm test— 246 files, 2515 pass, 2 skippeddescribeblocks forpearsonR/ranks/spearmanRcover the full edge-case contract (n<2 → NaN, both/one constant, length mismatch, ±1 linear, non-linear monotone Spearman, average ranks for ties).