Skip to content

Fix Wald thresholds for multi-coefficient and reversed contrasts - #468

Closed
dnncha wants to merge 2 commits into
scverse:mainfrom
dnncha:fix/wald-scalar-contrast
Closed

dnncha wants to merge 2 commits into
scverse:mainfrom
dnncha:fix/wald-scalar-contrast

Conversation

@dnncha

@dnncha dnncha commented Sep 8, 2026 •

Copy link
Copy Markdown

Wald thresholds and directional truncation currently operate on each fitted coefficient before applying the contrast. For a multi-coefficient or reversed contrast, this tests a different hypothesis from the scalar effect contrast @ lfc and can make significance depend on the model reference level.

Apply the null and all four alternative-hypothesis transformations to the scalar contrast effect, retaining the existing contrast standard error. The ordinary nonzero-null calculation is corrected in the same way.

A public-API reproduction with fixed synthetic negative-binomial counts (90 samples, three groups, 100 genes) compares C versus B with lfc_null=1.5 and alt_hypothesis="greaterAbs". The estimated log2 fold change is approximately 0.986 with SE 0.0366 in both encodings. Before this patch, reference A produces p=1.53e-159 while reference B produces p=1; after it, both produce p=1. This reproduces in released 0.5.4 and the affected logic is present at current base 95ace12cfa39b6d5982c1867d8127a6b5e9e5134.

Validation: 40 added scalar-normal-reference cases cover all five test modes, zero/nonzero nulls, multi-coefficient contrasts, reversed contrasts and positive singleton controls. Before the patch, 20 fail and 20 pass; all 40 pass after. Full local suite: 105 passed on Python 3.12. Ruff passes for the changed files. Existing R-derived reference fixtures pass; no live R/DESeq2 execution is claimed. This does not establish an effect on a published analysis.

Prepared with AI assistance. Audit and downloadable reproduction inputs, patches and execution records.

The upstream pre-commit.ci formatting-only commit was pulled locally; all 40 focused checks pass on final head 68f16c538f4e93ce3f2880aa4e713a330496a898. The full-suite result above is from authored commit a779e7bee6dc6791c1ff9666e781e4ec83e03c62.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.90%. Comparing base (95ace12) to head (68f16c5).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #468      +/-   ##
==========================================
+ Coverage   85.89%   85.90%   +0.01%     
==========================================
  Files          15       15              
  Lines        1276     1277       +1     
==========================================
+ Hits         1096     1097       +1     
  Misses        180      180              
Files with missing lines Coverage Δ
src/pydeseq2/glm.py 81.52% <100.00%> (+0.20%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Zethson Zethson closed this Sep 9, 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.

3 participants