`prior_LFC_var` is squared in the Wald test's ridge
维护者通常 1 天内回复
还没有人认领这个 Issue。
- #537 来自 @VamikaSinghal —— 已关闭,未合并
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 72/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- numpy, python
调研方向
ridge 在 DeseqStats 中的 ds.py:293 处按 np.diag(1 / self.prior_LFC_var**2) 构建;先阅读该构造函数和 prior_LFC_var 的 docstring。运行 issue 中的复现,确认 DeseqStats.SE 当前匹配的是 I / 16 的 Wald SE(1.098596),而不是 prior_LFC_var=[4, 4] 对应的 0.841471。去掉平方是最小修复;还要权衡是否需要对 log(2)^2 做尺度校正,然后在 tests/ 下运行 Wald 检验的测试,检查没有其他东西发生变化。
由索引模型根据 Issue 内容生成。
描述
DeseqStats(prior_LFC_var=...) uses the reciprocal of the square of each value as the Wald test's ridge: with prior_LFC_var=[4, 4] the lowest-count gene's standard error is 1.098596, the one with ridge I / 16, not 0.841471, the one with ridge I / 4; the docstring calls it the "Prior variance for LFCs, used for ridge regularization", and a normal prior with variance v has penalty 1 / v, as in DESeq2's fitGLMsWithPrior (lambda <- 1/betaPriorVar). ds.py:293 sets ridge_factor = np.diag(1 / self.prior_LFC_var**2); np.diag(1 / self.prior_LFC_var) would match the docstring, which could also give the scale (DESeq2's prior variance is on the log2 scale and fitNbinomGLMs divides lambda by log(2)^2, while this ridge applies to natural-log coefficients).
Source line numbers refer to commit 2ca3b74.
Reproduction
import numpy as np
import pandas as pd
from pydeseq2.dds import DeseqDataSet
def simulate(n_genes=200, groups=(4, 4), seed=0):
"""Counts (samples x genes) and metadata; dispersion 0.05 + 1 / mean."""
rng = np.random.default_rng(seed)
group = np.repeat(np.arange(len(groups)), groups)
base = rng.lognormal(4, 1.5, n_genes)
lfc = rng.normal(0, 0.5, (len(groups), n_genes))
lfc[0] = 0
mu = base * np.exp(lfc[group])
disp = 0.05 + 1 / base
counts = rng.negative_binomial(1 / disp, 1 / (1 + disp * mu))
samples = [f"s{i}" for i in range(len(group))]
counts = pd.DataFrame(counts, index=samples, columns=[f"g{j}" for j in range(n_genes)])
metadata = pd.DataFrame({"condition": np.array(list("ABCDEF"))[group]}, index=samples)
return counts, metadata
def dataset(counts, metadata, **kwargs):
return DeseqDataSet(counts=counts, metadata=metadata, n_cpus=1, quiet=True, **kwargs)
import numpy as np
from pydeseq2.ds import DeseqStats
from pydeseq2.glm import wald_test
dds = dataset(*simulate(n_genes=50, groups=(4, 4), seed=6))
dds.deseq2()
ds = DeseqStats(dds, contrast=["condition", "B", "A"], prior_LFC_var=np.array([4.0, 4.0]), n_cpus=1, quiet=True)
ds.run_wald_test()
gene = dds.var["_normed_means"].idxmin()
X = dds.obsm["design_matrix"].to_numpy()
lfc = dds.varm["LFC"].loc[gene].to_numpy()
mu = dds.obs["size_factors"].to_numpy() * np.exp(X @ lfc)
for v in [4.0, 16.0]:
se = wald_test(X, dds.var.loc[gene, "dispersions"], lfc, mu, np.eye(2) / v, np.array([0.0, 1.0]), 0.0, None)[2]
print(f"Wald SE with ridge I / {v:g}: {se:.6f}")
print(f"DeseqStats.SE with prior_LFC_var=[4, 4]: {ds.SE[gene]:.6f}")
Expected: DeseqStats.SE equal to the standard error with ridge I / 4.
Actual, with PyDESeq2 0.6.0:
Wald SE with ridge I / 4: 0.841471
Wald SE with ridge I / 16: 1.098596
DeseqStats.SE with prior_LFC_var=[4, 4]: 1.098596
Split out from #491.
- 主要语言
- Python
- 星标
- 770
- 派生
- 98
- 平均合并
- 19 小时 55 分钟
- 30 天内合并 PR
- 45
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
scverse/PyDESeq2 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
`lowess` returns 0 for points of an exact fit after robustness iterations可能重新可做 @aviralgarg05 于 15 天前认领,目前没有进行中的 PR。 未关闭bug
难度 2/5 1-3 小时 新手友好度 74/100
scverse/PyDESeq2#520 · 1 条评论 ·
维护者通常 1 天内回复
-
`irls_solver` does not enforce `min_beta` when IRLS converges, and documents `max_beta`'s default as -30可能重新可做 @aviralgarg05 于 15 天前认领,目前没有进行中的 PR。 未关闭bug
难度 2/5 1-3 小时 新手友好度 85/100
scverse/PyDESeq2#521 · 1 条评论 ·
维护者通常 1 天内回复
-
`MAP_dispersions` of refitted genes keep the value from before outlier replacement可能重新可做 @aviralgarg05 于 15 天前认领,目前没有进行中的 PR。 未关闭bug
难度 2/5 1-3 小时 新手友好度 75/100
scverse/PyDESeq2#519 · 1 条评论 ·
维护者通常 1 天内回复
相似的 Issue
-
Make the "%" unit spacing the same in the web and in A10可能已有人在做 @kragent66-glitch 今天认领。 未关闭bug good first issue
难度 2/5 1-3 小时 新手友好度 74/100
maiychrus25/OpenTea-DX-OS#226 · 1 条评论 ·
-
ci severity: low
难度 2/5 1-3 小时 新手友好度 78/100
TMHSDigital/Spackle#205 ·
维护者通常 1 天内回复
-
pkg:lgm type:chore upstream-gaussx
难度 2/5 1-3 小时 新手友好度 76/100
jejjohnson/pyrox#610 ·
维护者通常 1 天内回复
-
changelog investigate
难度 2/5 1-3 小时 新手友好度 62/100
ramnes/notion-sdk-py#523 ·
-
feature-request
难度 2/5 1-3 小时 新手友好度 78/100
open-telemetry/opentelemetry-python#5994 ·
维护者通常 2 天内回复