Repository navigation
BUG: Fix sison-glaz confint failure for small or sparse counts - #9909
Conversation
Aniketsy
left a comment
There was a problem hiding this comment.
@Kaif10 thanks for the PR, looks good 👍
just a small suggestion from my side ...
i'm in favour of small improvement in tests and add expected values from R's MultinomialCI for at least one sparse case and compare with assert_allclose.
what you say ?
…se (statsmodels#9587) Add a focused check comparing multinomial_proportions_confint(..., method='sison-glaz') against confidence-interval values computed from R's MultinomialCI (Sison-Glaz) algorithm for a sparse count vector, following the reviewer's suggestion on PR statsmodels#9909. The vector [1, 1, 0, 0, 0, 0, 0] terminates the c-search at c = 0 (the branch added by the fix), exactly the sparse case R handles by initialising pold = 0 before testing cc = 1. Its counts are small enough that count + c never exceeds n, so no box bound is truncated and the statsmodels and R outputs are directly comparable; they agree to machine precision. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Thanks for the review and the suggestion. I've added a focused test that compares the sison-glaz output for a sparse count vector, For transparency: I did not attach R values to the other parametrized vectors ( Let me know if you'd like anything else adjusted — otherwise I'd appreciate it if you could approve/merge. |
|
@bashtage thanks for merging the companion fix #9908. This PR (#9909) is the other half — the sison-glaz |
multinomial_proportions_confint(..., method='sison-glaz') searches for the c solving nu(c) <= 1 - alpha < nu(c + 1), where nu is the Edgeworth-expansion approximation of the coverage of the box [count - c, count + c]. For small or sparse counts this search could not terminate, for two reasons: - the search started at c = 1, so no solution existed when nu(1) already exceeds 1 - alpha (possible for very small n), and - the approximation nu(c) can plateau below 1 - alpha even though the exact coverage is one once c >= n (the box then contains the full support of every cell). Start the search at c = 0 with nu(0) taken as zero, matching the reference implementation in R's MultinomialCI, and use the exact coverage of one instead of the approximation once c + 1 >= n. Results for previously working inputs are unchanged. closes statsmodels#9587 Co-Authored-By: Claude Fable 5 <[email protected]>
…se (statsmodels#9587) Add a focused check comparing multinomial_proportions_confint(..., method='sison-glaz') against confidence-interval values computed from R's MultinomialCI (Sison-Glaz) algorithm for a sparse count vector, following the reviewer's suggestion on PR statsmodels#9909. The vector [1, 1, 0, 0, 0, 0, 0] terminates the c-search at c = 0 (the branch added by the fix), exactly the sparse case R handles by initialising pold = 0 before testing cc = 1. Its counts are small enough that count + c never exceeds n, so no box bound is truncated and the statsmodels and R outputs are directly comparable; they agree to machine precision. Co-Authored-By: Claude Opus 4.8 <[email protected]>
d70532b to
2a4c640
Compare
|
Rebased onto current |
|
I'll have a look this morning. Thanks. |
|
Reviewed, LGTM. Thanks. |
closes #9587
multinomial_proportions_confint(counts, method="sison-glaz")raisedException: Couldn't find a value for 'c' ...for small or sparse inputs such as[6, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0]. The search forc(solvingnu(c) <= 1 - alpha < nu(c + 1)) failed for two reasons. First, it started atc = 1, so the legitimate solutionc = 0was unreachable whennu(1)already exceeds1 - alpha(very smalln). Second, the Edgeworth-based approximationnu(c)can be non-monotone and plateau below1 - alphafor sparse counts, even though the exact coverage is 1 oncec >= n(the box[count - c, count + c]then contains the full support of every cell), so no crossing existed.The fix starts the search at
c = 0withnu(0)taken as zero — matching the reference implementation in R's MultinomialCI package — and substitutes the exact coverage of 1 for the approximation oncec + 1 >= n. Results for all previously working inputs are unchanged (the existing tests against R MultinomialCI reference values pass unmodified); previously failing inputs now return valid intervals in [0, 1] containing the point estimates. These intervals are necessarily wide — the method's approximation is documented as needing at least 7 categories with counts of about 5 — but returning them seems preferable to raising, consistent withgoodmanhandling the same inputs.One judgment call reviewers may want to weigh: for the no-crossing case, this uses the exact saturated-box coverage rather than raising a clearer error for data outside the method's validity range. (R's own implementation silently returns invalid intervals for that case, so it was not usable as a reference there.)
A parametrized regression test covers the four vectors from the issue.
Disclosure: this patch was prepared with AI assistance and human review.