Skip to content

BUG: Fix sison-glaz confint failure for small or sparse counts - #9909

Merged
bashtage merged 2 commits into
statsmodels:mainfrom
Kaif10:fix/9587-sison-glaz-sparse
Jul 29, 2026
Merged

bashtage merged 2 commits into
statsmodels:mainfrom
Kaif10:fix/9587-sison-glaz-sparse

Conversation

@Kaif10

@Kaif10 Kaif10 commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

closes #9587

multinomial_proportions_confint(counts, method="sison-glaz") raised Exception: 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 for c (solving nu(c) <= 1 - alpha < nu(c + 1)) failed for two reasons. First, it started at c = 1, so the legitimate solution c = 0 was unreachable when nu(1) already exceeds 1 - alpha (very small n). Second, the Edgeworth-based approximation nu(c) can be non-monotone and plateau below 1 - alpha for sparse counts, even though the exact coverage is 1 once c >= 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 = 0 with nu(0) taken as zero — matching the reference implementation in R's MultinomialCI package — and substitutes the exact coverage of 1 for the approximation once c + 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 with goodman handling 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.

@Aniketsy Aniketsy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@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 ?

Kaif10 added a commit to Kaif10/statsmodels that referenced this pull request Jul 16, 2026
…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]>
@Kaif10

Kaif10 commented Jul 16, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review and the suggestion. I've added a focused test that compares the sison-glaz output for a sparse count vector, [1, 1, 0, 0, 0, 0, 0], against reference confidence-interval values computed from R's MultinomialCI (Sison-Glaz) algorithm. I chose this vector because it terminates the search at c = 0 — precisely the branch this fix adds — which is 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 gets truncated and the two implementations are directly comparable; they agree to machine precision (max abs diff ~4e-16). The new test passes alongside the existing ones.

For transparency: I did not attach R values to the other parametrized vectors ([6,0,0,1,...] etc.), because R's implementation does not cap the Poisson box at n whereas statsmodels does, so R produces divergent (coverage > 1) values for those concentrated cases — they aren't valid references. The cap-free [1,1,0,...] case is the honest one to cite.

Let me know if you'd like anything else adjusted — otherwise I'd appreciate it if you could approve/merge.

@Kaif10

Kaif10 commented Jul 27, 2026

Copy link
Copy Markdown
Contributor Author

@bashtage thanks for merging the companion fix #9908. This PR (#9909) is the other half — the sison-glaz multinomial_proportions_confint failure on small/sparse counts — and it's been approved. Tests pass locally, and the failing statsmodels.statsmodels Azure check looks like the same unrelated failure seen on other PRs (it doesn't touch the proportion code). Would you be able to take a look when you have a moment? Happy to rebase if that helps re-trigger CI.

Kaif10 and others added 2 commits July 29, 2026 08:57
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]>
@Kaif10
Kaif10 force-pushed the fix/9587-sison-glaz-sparse branch from d70532b to 2a4c640 Compare July 29, 2026 07:58
@Kaif10

Kaif10 commented Jul 29, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current main to refresh CI — the previous run was from 2026-07-16 and its failure was unrelated to this change. Re-verified after the rebase: all four sparse vectors return valid intervals and the R MultinomialCI reference value still matches exactly (zero-cell upper bound 0.965582). No conflicts; the diff is unchanged (two commits: the fix and the R-reference test).

@bashtage

Copy link
Copy Markdown
Member

I'll have a look this morning. Thanks.

@bashtage

Copy link
Copy Markdown
Member

Reviewed, LGTM. Thanks.

@bashtage
bashtage merged commit cccd986 into statsmodels:main Jul 29, 2026
10 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.

Sison-Glaz multinomial_proportions_confint fails for small sizes

3 participants