Skip to content

ENH: Add Krippendorff's alpha to stats.inter_rater - #10738

Merged
bashtage merged 2 commits into
statsmodels:mainfrom
Allan-dq:enh-krippendorff-alpha
Nov 16, 2026
Merged

bashtage merged 2 commits into
statsmodels:mainfrom
Allan-dq:enh-krippendorff-alpha

Conversation

@Allan-dq

Copy link
Copy Markdown
Contributor

I needed Krippendorff's alpha when evaluating LLM scorers, and statsmodels doesn't have it, so I added it. The results match the original paper and R. R's irr has a bug when there are no missing values. Confidence intervals are not implemented yet; they can be added later.

  • tests added / passed.
  • code/documentation is well formatted.
  • properly formatted commit message. See
    NumPy's guide.

AI Disclosure

Contributions must comply with the statsmodels AI Policy.

Tick exactly one of the following. If AI tools were used, replace the <...>
placeholders in the second option with the tool name(s) and how the tool's output was
used.

  • No AI tools were used to develop this pull request.
  • AI tools were used.
    Tool(s): Claude Code (Claude Opus 5.5).
    Used for: drafting the implementation, the tests and the docstring, running the cross-checks against the paper, R and other implementations, and translating this description from Chinese.
    I have personally read, understood, and can explain every line of this diff, and
    have verified the statistical/numerical correctness of the change.
Details

Notes:

  • It is essential that you add a test when making code changes. Tests are not
    needed for doc changes.
  • When adding a new function, test values should usually be verified in another package (e.g., R/SAS/Stata).
  • When fixing a bug, you must add a test that would produce the bug in main and
    then show that it is fixed with the new code.
  • New code additions must be well formatted. Changes should pass ruff. You can
    verify your changes are well formatted by running
    ruff check . --fix
    
    assuming ruff is installed. While passing this test is not required, it is good practice and it help
    improve code quality in statsmodels.
  • Docstring additions must render correctly, including escapes and LaTeX.
  • If AI tools were used to help write this PR, see the
    AI Policy for what disclosure
    and review is expected of you before submitting.

krippendorff_alpha computes Krippendorff's alpha for any number of raters
with missing ratings, at the nominal, ordinal, interval and ratio levels,
following Krippendorff (2011). The tests check the values published in
that document, the exact fractions from its coincidence matrix, R irr
kripp.alpha, a pairwise computation from the definition, and the relation
to Fleiss' kappa for complete nominal data.
@Allan-dq
Allan-dq force-pushed the enh-krippendorff-alpha branch from c3cd894 to a6c99d6 Compare November 11, 2026 17:18
@bashtage

Copy link
Copy Markdown
Member

Thanks LGTM.

@bashtage
bashtage merged commit 3384ba1 into statsmodels:main Nov 16, 2026
1 of 2 checks passed
bashtage added a commit that referenced this pull request Nov 16, 2026
Follow-up to the merged #10738. The docstring now says that raters are in
columns, the transpose of R irr::kripp.alpha and DescTools::KrippAlpha, and
that a transposed matrix is accepted and gives a different alpha without an
error (with an example). It says that a single used category gives nan while
irr returns 1, that for two raters Fleiss' kappa is Scott's pi so that alpha
is 1 - (1 - pi) * (n - 1) / n instead of being equal to pi, and that memory
and time grow with the number of distinct ratings.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
bashtage added a commit that referenced this pull request Nov 16, 2026
Follow-up to the merged #10738. Replace the while loop with continue in
test_krippendorff_alpha_random_vs_pairs by a parametrization over kind,
level and seed, and compare with the pairwise definition also for
non-consecutive codes, negative codes (not for ratio) and float ratings.
The undefined cases now run with warnings as errors: numpy's 0 / 0
RuntimeWarning is not an error in this repo, so deleting the
len(values) < 2 return kept every test green. Do not match the wording of
the message of array_like.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
bashtage added a commit that referenced this pull request Nov 16, 2026
DOC: Follow up #10738 on krippendorff_alpha, with tighter tests
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.

2 participants