`lowess` returns 0 for points of an exact fit after robustness iterations

オープン 初心者向け
#520 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@aviralgarg05 がすでに取り組んでいます。

2026年11月17日 から。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
74/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
numpy, python
領域
data

調査の方向性

stats.py の 116-121 行目から始めます。ここではロバスト性の反復が、絶対残差の中央値がちょうど 0 であることが完全なフィットを意味するかどうかを判断します。そのしきい値が修正点です。再現スニペットを実行して、iter=1 は通る一方で iter=5 はポイント 44-49 で 0 を返すことを確認し、次に傾きと切片を変化させて許容範囲が広すぎないか確認します。ds.py:480 は独立フィルタリングにおける呼び出し元を示していますが、issue では padj の影響は未検証とされているので、lowess のテストを狙います。完了とは、両方の反復回数がラインから 1e-6 以内に収まり、既存の stats テストが通ることを意味します。

索引モデルが issue の本文から書いたものです。

説明

bug

After a robustness iteration, stats.lowess weights points by their residual over six times the median absolute residual; on an exact fit the residuals are rounding noise, so some points get weight 0, and where a whole neighbourhood does, lstsq returns beta = 0 and the fitted value is 0, as at points 46 to 49 of the line y = 3 - 7.5x with frac=0.1, iter=5; a local linear regression of points on a line should return the line, as the same call does with iter=1. stats.py:116-121 treats only a median of exactly 0 as an exact fit; treating a median below a small multiple of the targets' scale as zero would fix it.
lowess smooths the rejection counts of independent filtering (ds.py:480), whose plateaus are locally exact fits; we have not looked for a dataset where this changes padj.

Source line numbers refer to commit 2ca3b74.

Reproduction
import numpy as np
from pydeseq2.stats import lowess
x = np.linspace(0.1, 0.95, 50)
y = 3 - 7.5 * x
for iterations in [1, 5]:
	fit = lowess(x, y, frac=0.1, iter=iterations)
	off = np.flatnonzero(np.abs(fit - y) > 1e-6)
	print(f"iter={iterations}: points off the line {off.tolist()}")
	if len(off):
		print("fitted:", fit[off].round(4).tolist())
		print("line:", y[off].round(4).tolist())

Expected: no points off the line for either number of iterations.

Actual, with PyDESeq2 0.6.0:

iter=1: points off the line []
iter=5: points off the line [44, 45, 46, 47, 48, 49]
fitted: [-3.373, -3.4016, 0.0, 0.0, 0.0, 0.0]
line: [-3.4745, -3.6046, -3.7347, -3.8648, -3.9949, -4.125]

Split out from #491.

主要言語
Python
スター
770
フォーク
98
平均マージ
19時間 55分
マージ済み PR(30日)
45

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

scverse/PyDESeq2 のほかの issue

scverse/PyDESeq2 の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。