Repository navigation
BUG: truncate DerSimonian-Laird tau2 at zero in combine_effects - #10522
Merged
bashtage merged 1 commit intoOct 24, 2026
Merged
Conversation
combine_effects(method_re='dl') did not truncate the DerSimonian-Laird tau^2 estimate at zero. For nearly homogeneous studies this produced a negative tau^2, a random-effects combined mean outside the range of the study effects, and for other inputs a negative var_eff_w_re and NaN standard deviation. The published DL estimator and R metafor truncate at zero, as does the Paule-Mandel path in this module (_fit_tau_iter_mm). The one-step moment estimate _fit_tau_mm is guarded as well. Regression test: with tau2 == 0 the random-effects results coincide with the fixed-effects results and the combined estimate lies within the range of the study effects.
Member
|
Thanks |
4 of 6 tasks
bashtage
added a commit
that referenced
this pull request
Oct 25, 2026
With the DerSimonian-Laird tau2 truncated at zero (gh-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 gh-10522, see gh-10520. 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
combine_effects(method_re='dl')did not truncate the DerSimonian-Laird tau^2 estimate at zero (tau2 = (q - df) / c). For nearly homogeneous studies the raw estimate is negative, e.g.eff=[0.30, 0.32, 0.28, 0.31],var=[0.04, 0.09, 0.05, 0.06]gavetau2 = -0.0561andmean_effect_re = 0.4000, outside the range[0.28, 0.32]of the study effects; other inputs produced a negativevar_eff_w_reand NaN standard deviations.The published DL estimator (DerSimonian & Laird 1986) and R metafor truncate tau^2 at zero, as does this module's own Paule-Mandel path (
_fit_tau_iter_mmusesmax(0, tau2_new)). This PR truncates withnp.maximum(0, ...)in bothcombine_effectsand the one-step moment estimator_fit_tau_mm.The regression test checks that for nearly homogeneous studies tau^2 == 0, the random-effects results coincide with the fixed-effects results, and the combined mean lies within the range of the study effects.
Tests:
pytest statsmodels/stats/tests/test_meta.py— all tests pass, including the newtest_combine_effects_dl_tau2_truncated.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 test.
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.
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.