Skip to content

BUG: truncate DerSimonian-Laird tau2 at zero in combine_effects - #10522

Merged
bashtage merged 1 commit into
statsmodels:mainfrom
Jason10191019999:fix-dl-tau2-truncation
Oct 24, 2026
Merged

bashtage merged 1 commit into
statsmodels:mainfrom
Jason10191019999:fix-dl-tau2-truncation

Conversation

@Jason10191019999

Copy link
Copy Markdown
Contributor

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] gave tau2 = -0.0561 and mean_effect_re = 0.4000, outside the range [0.28, 0.32] of the study effects; other inputs produced a negative var_eff_w_re and 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_mm uses max(0, tau2_new)). This PR truncates with np.maximum(0, ...) in both combine_effects and 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 new test_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.

  • No AI tools were used to develop this pull request.
  • AI tools were 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:

  • It is essential that you add a test when making code changes. Tests are not
    needed for doc changes.
  • When adding a new function, test values should usually be verified in another package (e.g., R/SAS/Stata).
  • When fixing a bug, you must add a test that would produce the bug in main and
    then show that it is fixed with the new code.
  • New code additions must be well formatted. Changes should pass ruff. You can
    verify your changes are well formatted by running
    ruff check . --fix
    
    assuming ruff is installed. While passing this test is not required, it is good practice and it help
    improve code quality in statsmodels.
  • Docstring additions must render correctly, including escapes and LaTeX.
  • If AI tools were used to help write this PR, see the
    AI Policy for what disclosure
    and review is expected of you before submitting.

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.
@bashtage
bashtage merged commit cb11bfb into statsmodels:main Oct 24, 2026
13 checks passed
@bashtage

Copy link
Copy Markdown
Member

Thanks

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]>
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: combine_effects DerSimonian-Laird tau2 not truncated at zero

2 participants