Skip to content

MAINT: Follow up on #10521, #10522, #10529 and #10554 - #10555

Merged
bashtage merged 11 commits into
statsmodels:mainfrom
bashtage:wip-nits-merged-4
Oct 25, 2026
Merged

bashtage merged 11 commits into
statsmodels:mainfrom
bashtage:wip-nits-merged-4

Conversation

@bashtage

Copy link
Copy Markdown
Member
  • closes #xxxx
  • tests added / passed.
  • code/documentation is well formatted.
  • properly formatted commit message. See
    NumPy's guide.

Follow up to the four PRs that were merged without changes after the review: #10521, #10522, #10529 and #10554. It addresses the points that were left open in the reviews. Each PR has its own commits (code, tests) and the release notes are the last commit. The tests of the touched files pass (2188 passed, 11 skipped, 1 xfailed) and ruff check is clean.

#10554 (BayesMixedGLM.predict, which)

  • which is case sensitive, as in GLM.predict.
  • A list exog raised AttributeError; it is now converted with array_like. A 1-d exog raises a ValueError.
  • The docstrings say that only the fixed effects are used, so that "mean" is the mean given zero random effects and not the marginal mean, and that fit_map gives the posterior mode and fit_vb the variational posterior mean.
  • The test is parametrized over fit_map and fit_vb, Binomial and Poisson, both values of which and the call forms of the deprecated linear argument. The references are computed by hand from fe_mean.

#10522 (combine_effects, DerSimonian-Laird tau2)

  • With tau2 truncated at zero, h2 = q / (k - 1) was still below 1 and i2 negative (-inf for q = 0) when q < k - 1. They are floored at 1 and 0, which is what metafor::rma reports. The data of BUG: combine_effects DerSimonian-Laird tau2 not truncated at zero #10520 gave i2 = -211.6 and h2 = 0.0047.
  • Lists and tuples are accepted (the docstring says array_like, but a list raised). sum(0) is sum(axis=0) for pandas input.
  • The docstring documents the truncation and the floors. R references from metafor 5.2.1 rma(yi, vi, method="DL") for the data of BUG: combine_effects DerSimonian-Laird tau2 not truncated at zero #10520 and a heterogeneous data set with 6 studies are in results_meta.py with the R calls. New tests: both DL methods, _fit_tau_mm with uniform weights, the boundary q == k - 1, the floors.

#10529 (gof_binning_discrete)

  • The generic discrete ppf of SciPy can raise RuntimeError (skellam with large parameters, 131 of 420 random parameter sets); this worked before BUG: remove fixed bounds from discrete GOF binning #10529. The function now falls back to a search that only uses the cdf.
  • The bin edges were moved by a fixed 1e-8, which is lost for edges of about 1e9 and larger (Poisson with mean 1e9). They use np.nextafter.
  • nsupp is validated (it must be at least 1), a dead cdf call and a commented line are removed, and the docstrings of both functions document that the support comes from distfn.support, the small expected count of the tail bin and the dropped observations outside the support. The test comment says that the check is an internal equivalence with the old rule.

#10521 (power_equivalence_* for nobs_ratio != 1)

  • The ftotal null variance used (1 + value * nobs_ratio)**2 where the score variance has (value + nobs_ratio)**2. With dispersion=0 the two must agree: for rates 1.1 and 1, nobs_ratio=4 and nobs1=400 the powers were 0.7121 (ftotal) and 0.7841 (score), and an exact enumeration of the Poisson TOST gives 0.7874. The fix is in power_equivalence_neginb_2indep and power_negbin_ratio_2indep (one line in the ftotal branch). Results for nobs_ratio=1 are unchanged.
  • nobs_ratio is validated in both equivalence functions (positive and finite, scalar or array_like, as before); 0 and -1 gave nan or a ZeroDivisionError.
  • New tests compare with an exact enumeration of the Poisson TOST for nobs_ratio in 0.5, 2 and 4, the negbin to Poisson limit test is parametrized over method_var, and the comments cite BUG: power_equivalence_poisson_2indep and power_equivalence_neginb_2indep wrong for nobs_ratio != 1 #10519.

Not changed

  • gof_chisquare_discrete still uses 20 bins; BUG/ENH: hard coded settings in stats.gof.gof_chisquare_discrete #4359 also asks for options.
  • A single ppf call for zipf(1.2) can use a lot of time and memory in gof_binning_discrete; the cdf search takes about 2 s for the same quantile, but switching the normal path is a design decision.
  • combine_effects with a single study still gives nan for h2, i2 and tau2; the max(0, .) in _fit_tau_iter_mm stays because it also handles that case.

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.

  • No AI tools were used to develop this pull request.
  • AI tools were used.
    Tool(s): Claude Code (Claude Sonnet 5.5).
    Used for: reviewing the four merged PRs, drafting the code, docstring and release note changes, writing the tests, and checking values against R.
    I have personally read, understood, and can explain every line of this diff, and
    have verified the statistical/numerical correctness of the change.

🤖 Generated with Claude Code

bashtage and others added 9 commits October 24, 2026 22:02
which is now case sensitive like in GLM.predict, a list exog is converted with array_like (it raised AttributeError) and a 1-d exog raises a ValueError. The predict docstrings say that only the fixed effects are used, so that mean is the mean given zero random effects, and which estimate fit_map and fit_vb provide. The tests cover fit_map and fit_vb, Binomial and Poisson, both values of which and all call forms of the deprecated linear argument.

Follow up to statsmodelsgh-10554.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
With the DerSimonian-Laird tau2 truncated at zero (statsmodelsgh-10522), h2 = q / (k - 1) was still below 1 and i2 negative (-inf for q = 0) when q < k - 1. Floor them at 1 and 0 like metafor. combine_effects failed for plain lists although the docstring says array_like, so lists and tuples are converted. Use the axis keyword in sum for pandas input. The docstring documents the truncation of tau2 and the floors.

Follow up to statsmodelsgh-10522, see statsmodelsgh-10520.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Reference values from metafor 5.2.1 rma(method='DL') for the data of statsmodelsgh-10520 and a heterogeneous k=6 data set, tests of the truncation for both DL methods and _fit_tau_mm with uniform weights, the q == k - 1 boundary, the h2 and i2 floors and list input.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The generic discrete ppf of SciPy can raise RuntimeError (skellam with large parameters), which worked before statsmodelsgh-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 statsmodelsgh-10529, see statsmodelsgh-4359.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…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 statsmodelsgh-10521, see statsmodelsgh-10519.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Enumerate the counts of the Poisson TOST for nobs_ratio of 0.5, 2 and 4, parametrize the negbin to Poisson limit test over method_var, and test the validation of nobs_ratio.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The next release is 0.15.1.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
bashtage and others added 2 commits October 25, 2026 06:42
The Azure python_310 job failed test_combine_effects_dl_metafor[ex_het6-*] (the t quantile differs from R by 2e-9 relative) and test_gof_binning_discrete_large_mean_edges (the Poisson ppf of that SciPy is off by up to 7 for a mean of 1e9). Compare the t interval with rtol=1e-7, and take the edges from gof_binning_discrete itself, checked against the scan of the cdf with rtol=1e-7, so that the test of the exact edges does not depend on the accuracy of ppf.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@bashtage
bashtage marked this pull request as ready for review October 25, 2026 08:33
@bashtage
bashtage merged commit d8d8a97 into statsmodels:main Oct 25, 2026
12 of 13 checks passed
@bashtage
bashtage deleted the wip-nits-merged-4 branch October 25, 2026 19:33
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.

1 participant