Add Kendall (1940) circular-triads consistency test and coefficient of agreement u - #296
Merged
Merged
Conversation
Implements the Kendall & Babington Smith (1940) circular-triad consistency test and coefficient of agreement u, as implemented by the eba R package 1.10-0 (circular.R / kendall.u.R, source READ; the 1940 paper and Alway's exact tables NOT READ, cited as origins per eba's manual pages). - Rust core scaling::circular_triads: T = C(n,3) - sum_j C(d_j,2) (integer arithmetic), T_max, T_exp = C(n,3)/4, zeta = 1 - T/T_max; EXACT null p-values for n <= 10 from embedded distributions (dyadic rationals, assert_eq!-pinned), continuity-corrected chi-square for n >= 11 (df = n(n-1)(n-2)/(n-4)^2). Documented divergences from eba: n = 2 and malformed/incomplete tournaments are rejected. - Rust core scaling::kendall_u: Sigma, u = 2*Sigma/(C(m,2)*C(n,2)) - 1, min_u, RAW chi-square (can be negative under continuity correction; only the p-value clamps), df = C(n,2)m(m-1)/(m-2)^2. Stricter than eba: every pair must have the same m >= 3 judges. - PyO3 bindings + Python wrappers circular_triads / kendall_u with CircularTriadsResult / KendallUResult dataclasses; input validation before casts. - 11 Rust tests (exact-Fraction oracle pins: 1940 dog example, n = 12 chi-square path vs scipy, table integrity sum = 2^C(n,2), negative raw chi2, error contracts, MC-500 invariants #[ignore]); 8 Python tests. Five mutants (drop pairing, T_max parity swap, drop opposite-tail, corr sign flip, drop Sigma correction) all EXECUTED and killed. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
3 tasks
Contributor
Author
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.
Iteration 57 of the autonomous paper-implementation loop. Stacked on #295 (seonghobae-top1).
Kendall & Babington Smith (1940): circular triads + coefficient of agreement u
Source governance: CRAN eba 1.10-0
R/circular.R,R/kendall.u.R,man/circular.Rd,man/kendall.u.Rd— READ (implementation source). Kendall & Babington Smith (1940, Biometrika 31, 324-345) and Alway (1962, exact null tables) — NOT READ (acquisition failed); cited as origins as described by the eba source.What
scaling::circular_triads(mat, n, alternative, correct)— number of circular triadsT = C(n,3) - sum_j C(d_j,2)(integer form, proves integrality; algebraically equal to eba'sn(n-1)(2n-1)/12 - sum(d^2)/2),T_max(parity-split),T_exp = C(n,3)/4,zeta = 1 - T/T_max; EXACT null p-values forn <= 10from embedded null distributions (p-values are dyadic rationalsk/2^C(n,2), pinned withassert_eq!), continuity-corrected chi-square forn >= 11with tail inversion (less= upper chi-square tail per eba).scaling::kendall_u(mat, n, correct)—Sigma,u = 2 Sigma / (C(m,2) C(n,2)) - 1,min_u(-1/modd,-1/(m-1)even), RAW chi-square (can be negative under the continuity correction — pinned at exactly -1 in a fixture; only the p-value clamps),df = C(n,2) m(m-1)/(m-2)^2.CircularTriadsResult/KendallUResultdataclasses; validation before casts (complex, object dtype, square 2-D, n cap).Documented divergences from eba
circular(): n = 2 rejected (T_max = 0 makes zeta undefined); incomplete/non-binary tournaments and nonzero diagonals rejected instead of returning garbage.kendall.u(): eba derives m from the FIRST pair only and never checks its equal-observations assumption — here every pair must satisfyM_ij + M_ji = m >= 3; entries capped at 1e6 so all binomials stay exact in u64.Evidence discipline
kendall_oracle.py) EXECUTED all-pass before spec review: 1940 dog example (T=5, zeta=3/8, p_less=1043/2048), transitive n=5 two-sided (9/64), n=12 chi-square path (chi2=121/8, df=165/8 vs scipy), agreement fixtures (Sigma=11, u=2/9, chi2=11, df=9; perfect u=1; negative raw chi2=-1).sum(freq) = 2^C(n,2)for all n = 2..10.Adversarial impl-review outcome (post-merge-of-review)
Independent adversarial review (background agent, full report in session files
kendall_impl_review.md): CLEAN — round 1, no confirmed findings.Verified by execution: Rust kd_ tests 10 pass + MC-500 ignored pass; Python 8 pass; line-by-line fidelity vs eba
circular.R/kendall.u.R(T integer form, T_max parity, exact-table indexing, chi-square + tail directions, kendall.u Sigma/u/min_u/chi2/df); adversarial probes (NaN/inf/complex/object/non-contiguous/Fortran/case-sensitive alternative/huge n) all ValueError or correct; brute-force exact p-values over all tournaments for small n match the crate for all alternatives; scipy chi-square cross-check n=15 all alternatives, correct=True/False; 2 mutation spot-checks re-executed and killed.