Repository navigation
Conversation
Allan-dq
force-pushed
the
enh-krippendorff-bootstrap
branch
from
November 25, 2026 01:11
901e96b to
b8cf8d1
Compare
Add krippendorff_alpha_bootstrap to stats.inter_rater, which returns Krippendorff's alpha with a percentile bootstrap confidence interval. The subjects with at least two ratings are resampled with replacement and alpha is computed for each sample; samples in which alpha is undefined are counted and left out of the interval. The result is a frozen dataclass that unpacks as (statistic, ci_low, ci_upp). The computation of krippendorff_alpha is split into a helper that counts the ratings and one that computes alpha from the counts with optional subject frequencies, so a bootstrap sample needs no new tabulation. krippendorff_alpha returns the same values as before.
Allan-dq
force-pushed
the
enh-krippendorff-bootstrap
branch
from
November 26, 2026 23:02
b8cf8d1 to
8d7f7a3
Compare
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.
This adds
krippendorff_alpha_bootstrap, which returns Krippendorff's alpha and its bootstrap confidence interval. The result unpacks directly asstatistic, ci_low, ci_upp, and it also hasnboot_valid, the number of valid bootstrap samples.The method is a percentile bootstrap that resamples subjects (rows): each time, N subjects are drawn with replacement from the N subjects, all ratings of a subject are drawn together, and the interval is given by quantiles of the bootstrap values. This is the approach recommended by Zapf et al. (2016). I did not implement the bootstrap of Hayes and Krippendorff (2007), because the simulations of Zapf et al. showed that its coverage is far below the nominal level.
If all ratings in a bootstrap sample are equal, alpha is undefined. Such a sample is recorded as nan and left out of the interval. This is consistent with the current rule in
krippendorff_alpha.To avoid recounting the ratings in every sample, I split the body of
krippendorff_alphainto two private functions. The results ofkrippendorff_alphaare unchanged, and the existing tests all pass without changes.Verification: the tests reproduce the subjects drawn in each sample with the same random seed and call
krippendorff_alphadirectly on the drawn data; the results agree for all four levels of measurement. I also compared it case by case with the percentile method ofscipy.stats.bootstrap, and the results are identical. In a coverage simulation with a nominal 95% level, the coverage was between 0.925 and 0.950 with 200 subjects and between 0.900 and 0.930 with 20 subjects, so the interval is too narrow with few subjects; the docstring says so. All 172 tests ininter_raterpass.One question I'd like the maintainers' opinion on: statsmodels usually uses the parameter name
alphafor the significance level, but the statistic this function computes is also called alpha. I added a note in the docstring; if you think it should be renamed, I can change it.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.
Tool(s): Claude Code (Claude Opus 5.5).
Used for: drafting the implementation, the tests and the docstrings, running the coverage simulation and the comparison with scipy, 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:
needed for doc changes.
then show that it is fixed with the new code.
verify your changes are well formatted by running
ruffis installed. While passing this test is not required, it is good practice and it helpimprove code quality in
statsmodels.AI Policy for what disclosure
and review is expected of you before submitting.