Skip to content

feat(stats): rank-based effect size for ordinal scores - #177

Merged
k-dickinson merged 2 commits into
k-dickinson:mainfrom
pnascimento9596:feat/166-rank-based-effect-size
Aug 5, 2026
Merged

k-dickinson merged 2 commits into
k-dickinson:mainfrom
pnascimento9596:feat/166-rank-based-effect-size

Conversation

@pnascimento9596

@pnascimento9596 pnascimento9596 commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

What and why

Ordinal judge ratings now use paired rank effect sizes. Binary and clearly continuous scores keep their existing handling.

Closes #166.

Implementation

  • Adds dependent-groups probability of superiority. It reports how often the leader wins a paired example, with ties counting as half.
  • Adds matched-pairs rank-biserial correlation. Zeros are dropped and tied absolute differences receive midranks.
  • Bootstraps the rank-biserial interval with the existing seeded paired resampler.
  • Uses r-family magnitude thresholds of 0.1, 0.3, and 0.5. It does not reuse Cohen's d thresholds.
  • Keeps the decision and precision findings unchanged. The audit still returns exactly three findings.
  • Advances METHODOLOGY_VERSION from 1.0 to 1.1 because the stored audit method changed.

Flagged decision

The automatic ordinal rule requires integer-valued scores within a 1e-9 absolute tolerance and 3 to 10 observed levels. Two levels stay on the binary or continuous path. More than 10 integer levels and all noninteger scales stay on the continuous path. This version does not add a declaration key because the current input and configuration contracts have no metric-type surface.

This rule can be narrowed, widened, or replaced with an explicit declaration if the automatic boundary is not the intended policy.

Worked example

A 1 to 5 rating fixture has nine +1 paired differences, two -4 differences, and one tie. Cohen's d is +0.043, which is negligible. Matched-pairs rank-biserial r is +0.364, which is medium, and probability of superiority is 79.2%. Cohen's d treated the rating gaps as interval data and reduced the many paired wins to a negligible label.

Issue mapping

  • Detect ordinal or small-integer scales: the audit detects 3 to 10 integer levels.
  • Report a rank-based effect size: the finding reports matched-pairs rank-biserial r, its seeded interval, and paired probability of superiority.
  • Preserve binary and continuous handling: representative serialized findings have the same pre-change and post-change SHA-256 hashes.

Validation

  • pytest tests/test_effect.py tests/test_statistical.py tests/test_versions.py: 75 passed.
  • pytest: 1129 passed, 1 skipped.
  • Python 3.10, 3.11, 3.12, and 3.13: 1129 passed, 1 skipped on each version.
  • SciPy wilcoxon validates rank-biserial r on seeded randomized data with ties and zeros.
  • SciPy mannwhitneyu and brute-force enumeration validate probability of superiority.
  • Binary serialization SHA-256 stayed 0eadbda82bd1b630e26487fc91b562d7e9841728dd1e07b6239fd4ed76cc2501.
  • Continuous serialization SHA-256 stayed 1561fe933525c99c9fd2f93bdfb561fe5cd334989697c3736fc0df5f89eb1695.
  • Independent external adversarial review: completed. It found two routing edge cases. Both were fixed, and the final pass had no blockers or warnings.

Fixture grounding

The fixtures are grounded in k-dickinson/evaltrust at d508963ce1940b30a2d510b7f496c97ffc0dbdf0. They extend the paired helpers and effect contracts in tests/test_statistical.py, tests/test_effect.py, src/evaltrust/audit/statistical.py, src/evaltrust/stats/effect.py, and src/evaltrust/versions.py.

Checklist

  • Tests added or updated (written test-first)
  • pytest is green
  • Statistical changes are validated against a reference implementation
  • Any new finding answers why it matters, how it was detected, and how to fix it
  • Docs updated if behavior or formats changed

Summary by CodeRabbit

  • New Features

    • Added ordinal-scale analysis for integer rating scales with 3–10 observed levels.
    • Results now include paired rank-biserial correlation, probability of superiority, confidence intervals, magnitude labels, and detected scale details.
    • Improved handling of ties, zero differences, and near-integer scores.
  • Documentation

    • Added guidance on ordinal effect sizes, interpretation thresholds, and fallback behavior for unsupported scales.
    • Updated the methodology version to 1.1.

@coderabbitai

coderabbitai Bot commented Aug 4, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@pnascimento9596, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 48 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: acf1821b-7965-4ed6-b663-4f09e4318d1a

📥 Commits

Reviewing files that changed from the base of the PR and between 02523ca and ec93a92.

📒 Files selected for processing (2)
  • src/evaltrust/audit/statistical.py
  • tests/test_statistical.py
📝 Walkthrough

Walkthrough

The audit now detects supported ordinal scales and reports paired rank-biserial correlation, probability of superiority, confidence intervals, magnitude labels, and scale metadata. New effect-size utilities and tests cover ties, zero differences, invalid inputs, and continuous fallbacks. Documentation and methodology version updates describe the behavior.

Changes

Ordinal effect-size support

Layer / File(s) Summary
Paired rank-statistic utilities
src/evaltrust/stats/effect.py, tests/test_effect.py
Added paired probability of superiority, scalar and row-wise rank-biserial correlation, tie and zero handling, empty-input validation, and r-family magnitude thresholds.
Ordinal classification and audit reporting
src/evaltrust/audit/statistical.py, tests/test_statistical.py
Added ordinal detection for 3–10-level integer scores. Ordinal audits now report rank-based effects and bootstrap intervals. Invalid, noninteger, and larger-scale inputs retain continuous handling.
Methodology metadata and documentation
src/evaltrust/versions.py, CHANGELOG.md, docs/checks.md
Incremented the methodology version to 1.1 and documented ordinal effect-size behavior and fallback conditions.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Audit
  participant Classifier
  participant EffectUtilities
  participant Bootstrap
  Audit->>Classifier: Extract and classify scores
  Classifier-->>Audit: Ordinal status and scale levels
  Audit->>EffectUtilities: Compute paired rank effects
  EffectUtilities-->>Audit: Rank-biserial correlation and probability of superiority
  Audit->>Bootstrap: Generate ordinal confidence interval
  Bootstrap-->>Audit: Confidence interval and audit result
Loading

Possibly related PRs

Suggested reviewers: k-dickinson

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 4.76% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding rank-based effect sizes for ordinal scores.
Linked Issues check ✅ Passed The changes satisfy issue #166 by detecting ordinal scores, adding rank-based effect sizes, and preserving binary and continuous handling.
Out of Scope Changes check ✅ Passed The changelog, documentation, implementation, version update, and tests directly support the ordinal effect-size objectives.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/evaltrust/audit/statistical.py`:
- Around line 68-75: Normalize tolerance-matched ordinal scores in the analysis
flow after ordinal detection and before leader selection, deriving raw paired
differences from rounded scores so values equivalent under _INTEGER_SCORE_ATOL
remain tied. Update the cluster-resampling path to use the same normalized
differences when clusters are present, including the logic around the ordinal
metrics. Extend
test_ordinal_detection_accepts_integer_values_within_float_tolerance with the
specified tied-pair case and verify rank-biserial is 0.0 and probability of
superiority is 50%.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: d77a2461-d43a-4650-be2f-ae2e832fed47

📥 Commits

Reviewing files that changed from the base of the PR and between d508963 and 02523ca.

📒 Files selected for processing (7)
  • CHANGELOG.md
  • docs/checks.md
  • src/evaltrust/audit/statistical.py
  • src/evaltrust/stats/effect.py
  • src/evaltrust/versions.py
  • tests/test_effect.py
  • tests/test_statistical.py

Comment on lines +68 to +75
score_values = _score_values(data, model_a, model_b)
binary = _is_binary(data, model_a, model_b, values=score_values)
ordinal_levels = _ordinal_levels(
data, model_a, model_b, values=score_values
)
ordinal = not binary and _is_ordinal(
data, model_a, model_b, levels=ordinal_levels
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Normalize tolerance-matched ordinal scores before analysis.

At Line 59, raw is created before Lines 68-75 classify the scale. Lines 290-296 therefore send unrounded differences to the ordinal metrics.

With A=[1+5e-10, 2+5e-10, 3+5e-10] and B=[1, 2, 3], every pair is the same ordinal rating under _INTEGER_SCORE_ATOL. The current path reports rank-biserial +1.0 and probability of superiority 100% after leader orientation, instead of 0.0 and 50%.

After ordinal detection, derive raw from rounded paired scores before leader selection. When clusters exist, normalize the differences used for cluster resampling too. Extend test_ordinal_detection_accepts_integer_values_within_float_tolerance with this tied-pair case.

Also applies to: 173-186, 290-296

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/evaltrust/audit/statistical.py` around lines 68 - 75, Normalize
tolerance-matched ordinal scores in the analysis flow after ordinal detection
and before leader selection, deriving raw paired differences from rounded scores
so values equivalent under _INTEGER_SCORE_ATOL remain tied. Update the
cluster-resampling path to use the same normalized differences when clusters are
present, including the logic around the ordinal metrics. Extend
test_ordinal_detection_accepts_integer_values_within_float_tolerance with the
specified tied-pair case and verify rank-biserial is 0.0 and probability of
superiority is 50%.

@k-dickinson k-dickinson left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@k-dickinson
k-dickinson merged commit 47f88ad into k-dickinson:main Aug 5, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use a rank-based effect size for ordinal / Likert scores

2 participants