Skip to content

BUG: remove fixed bounds from discrete GOF binning - #10529

Merged
bashtage merged 1 commit into
statsmodels:mainfrom
Don-Yin:fix-statsmodels-gof-support-4359
Oct 24, 2026
Merged

bashtage merged 1 commit into
statsmodels:mainfrom
Don-Yin:fix-statsmodels-gof-support-4359

Conversation

@Don-Yin

@Don-Yin Don-Yin commented Oct 22, 2026

Copy link
Copy Markdown

Discrete GOF binning only scans integers in [-1000, 1000], so a Poisson(2000) sample falls into one bin and the test returns chi2=0, pvalue=NaN.

Bin edges now come from the distribution's support and ppf; expected counts are still CDF differences. gof_chisquare_discrete reuses gof_binning_discrete instead of its own copy.

Tests cover large and shifted Poisson, finite supports and custom bin counts, and match R's chisq.test on the same bins (reference code in a test comment). The stats suite and ruff check . pass.

Observed and expected bin counts before and after the fix

AI Disclosure

Contributions must comply with the statsmodels AI Policy.

  • No AI tools were used to develop this pull request.
  • AI tools were used.
    Tool(s): ChatGPT / OpenAI Codex, Claude.
    Used for: reproducing the bug, drafting the fix and tests, and the R cross-check.
    I have personally read, understood, and can explain every line of this diff, and
    have verified the statistical/numerical correctness of the change.

Find successive bin edges using the distribution's support and quantiles.
Keep CDF-based expected masses and use the same binning in both helpers.
Add regression tests and an independent R chisq.test reference.

Fixes statsmodels#4359.

Signed-off-by: Don Yin <[email protected]>
Assisted-by: ChatGPT (OpenAI Codex)
Assisted-by: Claude <[email protected]>
@bashtage
bashtage merged commit c30b137 into statsmodels:main Oct 24, 2026
10 of 12 checks passed
@bashtage

Copy link
Copy Markdown
Member

Thanks

bashtage added a commit that referenced this pull request Oct 25, 2026
The generic discrete ppf of SciPy can raise RuntimeError (skellam with large parameters), which worked before gh-10529. Fall back to a search using only the cdf. The bin edges were moved by a fixed 1e-8, which is lost for edges of about 1e9 and larger, so use np.nextafter. Validate nsupp, remove a dead cdf call and a commented line, and document the change of the support in gof_binning_discrete and gof_chisquare_discrete.

Follow up to gh-10529, see gh-4359.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
bashtage added a commit that referenced this pull request Oct 25, 2026
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.

BUG/ENH: hard coded settings in stats.gof.gof_chisquare_discrete

2 participants