Fix Kruskal-Wallis test reporting failure with degenerate cases (one observation per group)#512
Draft
Fix Kruskal-Wallis test reporting failure with degenerate cases (one observation per group)#512
Conversation
Co-authored-by: rempsyc <13123390+rempsyc@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fail to compute report for Kruskal test in some cases
Fix Kruskal-Wallis test reporting failure with degenerate cases (one observation per group)
Aug 31, 2025
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.
When a nominal vector has many levels with one observation per level, calling
report()on a Kruskal-Wallis test would fail with a data frame construction error because the confidence interval calculation for the effect size would fail when all bootstrapped values are identical.Problem
The original issue occurred when:
as.factor(1:n))kruskal.test()works fine and is fastreport()on the result would fail with:"arguments imply differing number of rows: 1, 0"This happened because
effectsize::rank_epsilon_squared()uses bootstrap methods to compute confidence intervals, but when there's one observation per group, all bootstrapped effect sizes equal 1, making CI calculation impossible.Solution
Added error handling in
.report_effectsize_kruskal()to:ci = NULLwhen bootstrap CI failsBefore and After
Before (fails):
After (works):
Key Improvements
Note: For optimal results, users should provide data manually
report(test, data = df)or use the formula interfacekruskal.test(y ~ group, data = df)as suggested by existing warning messages in the report package.Fixes #454.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.