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

Open Beginner friendly
#520 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@aviralgarg05 is already working on this.

Since Nov 17, 2026.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
74/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
numpy, python
Domain
data

Research direction

Start at stats.py lines 116-121, where the robustness iteration decides whether a median absolute residual of exactly 0 means an exact fit; that threshold is the fix. Run the reproduction snippet to confirm iter=1 passes while iter=5 returns 0 at points 44-49, then vary the slope and intercept to check the tolerance is not over-broad. ds.py:480 shows the caller in independent filtering, but the issue says the padj effect is unverified, so aim at lowess tests. Done means both iteration counts stay within 1e-6 of the line and existing stats tests pass.

Written by the indexing model from the issue text.

Description

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.

Dominant language
Python
Stars
770
Forks
98
Avg merge
19h 55m
Merged PRs (30d)
45

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from scverse/PyDESeq2

All issues in scverse/PyDESeq2

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.