Wald test applies lfc_null and alt_hypothesis to each coefficient instead of to the contrast
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 52/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- numpy, python
- Ambito
- bioinformatics, data
Direzione di ricerca
Start by reading wald_test() in glm.py and trace how the contrast, lfc_null, and alternative hypotheses are used to compute the statistic. The report includes a reproducible synthetic-data example comparing ~condition with ~0 + condition, plus a proposed parametrized test covering all five alternatives. Done means equivalent designs produce matching statistics and p-values for the same contrast.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Report
When lfc_null != 0 or alt_hypothesis is set, wald_test() in glm.py subtracts lfc_null from (and clips) every coefficient and only then applies the contrast vector:
stat = contrast @ np.fmax((lfc - lfc_null) / wald_se, 0) # "greater"
wald_statistic = float(contrast @ (lfc - lfc_null) / wald_se) # default
That is only right when the contrast has a single non-zero entry. As soon as it has two (a comparison between two non-reference levels, a design without intercept, or a user-supplied numeric contrast) the result tests a different hypothesis: for a contrast whose entries sum to zero, lfc_null cancels out entirely (contrast @ (lfc - lfc_null) = contrast @ lfc), and for the thresholded alternatives each coefficient is clipped separately, so the statistic can be large even when the contrasted LFC is below the threshold.
The same model written in two equivalent ways then gives different p-values. With the bundled synthetic data, contrast B vs A, lfc_null=0.5:
from pydeseq2.dds import DeseqDataSet
from pydeseq2.ds import DeseqStats
from pydeseq2.datasets import load_example_data
counts = load_example_data(modality="raw_counts", dataset="synthetic")
metadata = load_example_data(modality="metadata", dataset="synthetic")
for design in ["~condition", "~0 + condition"]:
dds = DeseqDataSet(counts=counts, metadata=metadata, design=design, quiet=True)
dds.deseq2()
ds = DeseqStats(dds, contrast=["condition", "B", "A"], lfc_null=0.5, quiet=True)
ds.summary()
r = ds.results_df.loc["gene1"]
print(design, ds.contrast_vector, r[["log2FoldChange", "lfcSE", "stat", "pvalue"]].round(4).tolist())
~condition [0. 1.] [0.6328, 0.2891, 0.4594, 0.646]
~0 + condition [-1 1] [0.6328, 0.2891, 2.1889, 0.0286]
Same estimate, same standard error, but the second statistic is 0.6328 / 0.2891 (null value dropped) instead of (0.6328 - 0.5) / 0.2891 = 0.459. Over the 10 genes, stat differs by up to 4.21 and pvalue by up to 0.89 between the two designs. With alt_hypothesis="greaterAbs" the ~0 + condition fit reports 3 genes at padj < 0.05 against 0 for ~condition. In DESeq2 (R) results(dds, contrast=..., lfcThreshold=0.5) gives identical numbers for both designs, because the threshold is applied to the contrast estimate.
The fix is to compute the scalar contrast @ lfc first and apply lfc_null and the alternative hypothesis to it, keeping the existing contrast standard error (sqrt(Hc' M Hc)). I have a branch with that change and a parametrized test (~condition vs ~0 + condition must agree for all five alternatives) that fails on main and passes with the change; I can open a PR if that is welcome. (A similar PR, #468, was closed in September without discussion; I am opening this issue first to check how you would like it handled.)
Versions
pydeseq2 0.5.4 (main 2ca3b74), pandas 3.0.6, numpy 2.5.4, scipy (current), Python 3.13.14, macOS 26.
- Lingua principale
- Python
- Stelle
- 768
- Fork
- 93
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di scverse/PyDESeq2
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 48/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
-
Difficoltà 3/5 Mezza giornata Idoneità per principianti 18/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
-
bug
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
Tutte le issue di scverse/PyDESeq2
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
-
Validate finite output clamping limits in StepPredictor.prepare_clamping_params to prevent silent NaN/Inf propagationForse già presa @muskan-creates352 l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
mllam/neural-lam#848 ·
I maintainer di solito rispondono entro 2 giorni
-
infra
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
fab-geocommuns/RNB-coeur#1166 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
deepspeedai/DeepSpeed#8951 ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
aws/context-ontology-accelerator#343 ·
I maintainer di solito rispondono entro 1 giorno