Repository navigation
BUG: fix power_equivalence_poisson_2indep and power_equivalence_neginb_2indep for nobs_ratio != 1 - #10521
Merged
bashtage merged 2 commits intoOct 24, 2026
Conversation
power_equivalence_poisson_2indep passed nobs2 where the per-nobs1 variance definitions require nobs1, and the score (constrained null) variance used (1 + margin * nobs_ratio)**2 instead of the correct constrained-CMLE factor (margin + nobs_ratio)**2, matching power_poisson_ratio_2indep. power_equivalence_neginb_2indep had rate1 and rate2 swapped in the alternative variance relative to the per-nobs1 scaling. All three bugs are invisible at nobs_ratio = 1. Regression tests use nobs_ratio != 1 with reference values from an independent closed-form implementation, cross-checked against Monte Carlo simulation.
4 of 6 tasks
bashtage
added a commit
that referenced
this pull request
Oct 25, 2026
…ower The ftotal null variance used (1 + value * nobs_ratio)**2 where the score variance has (value + nobs_ratio)**2, so ftotal differed from score at dispersion 0 for nobs_ratio != 1 (0.7121 versus 0.7841 for rates 1.1 and 1, nobs_ratio 4, nobs1 400, and 0.7874 in an exact enumeration of the Poisson TOST). This is fixed in power_equivalence_neginb_2indep and power_negbin_ratio_2indep. power_equivalence_poisson_2indep and power_equivalence_neginb_2indep now require a positive finite nobs_ratio, which gave nan or a ZeroDivisionError. Add versionchanged notes. Follow up to gh-10521, see gh-10519. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
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.
NumPy's guide.
Summary
Fixes three bugs in the equivalence (TOST) power functions in
statsmodels/stats/rates.py, all invisible atnobs_ratio = 1(which is the only case the existing tests covered):power_equivalence_poisson_2indeppassednobs2to_power_equivalence_hetwhere the per-nobs1variance definitions requirenobs1(consistent withpower_poisson_ratio_2indepand with the siblingpower_equivalence_neginb_2indep). Atnobs_ratio=2, nobs1=100, rate1=rate2=1.0, low=0.8, upp=1.25, method_var='alt'this gave power 0.6486 vs a Monte Carlo reference of 0.143 (50k reps, MC se 0.002); the corrected value 0.1406 matches.method_var='score': the constrained-null variance used(1 + margin * nobs_ratio)**2instead of the correct constrained-CMLE factor(margin + nobs_ratio)**2(verified by brute-force constrained MLE, and matchingpower_poisson_ratio_2indep).power_equivalence_neginb_2indep:rate1/rate2swapped in the alternative variance relative to the per-nobs1delta-method variance of the log rate ratio (matchingpower_negbin_ratio_2indep).Regression tests use
nobs_ratio != 1with reference values computed from an independent closed-form implementation (described in the test comments) and cross-checked against Monte Carlo simulation, plus a consistency test thatpower_equivalence_neginb_2indep(dispersion=0)agrees with the Poisson version.Tests:
pytest statsmodels/stats/tests/test_rates_poisson.py— 1232 passed, 4 skipped (full file, including the 12 new tests).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): Kimi Code CLI (AI coding agent).
Used for: drafting the fix and the regression tests, and running the numerical verification.
I have personally read, understood, and can explain every line of this diff, and
have verified the statistical/numerical correctness of the change.
This contribution was developed with the assistance of an AI coding tool; all changes were verified against independent numerical references (Monte Carlo simulation, brute-force constrained MLE, and a from-scratch closed-form implementation).
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.