Skip to content

fix: run t-test on log values regardless of mean_in_log_space - #4337

Merged
flying-sheep merged 4 commits into
scverse:mainfrom
cindykrafft:fix/rank-genes-groups-ttest-log-space
Nov 10, 2026
Merged

flying-sheep merged 4 commits into
scverse:mainfrom
cindykrafft:fix/rank-genes-groups-ttest-log-space

Conversation

@cindykrafft

Copy link
Copy Markdown
Contributor

On main (and the 1.13 pre-releases; 1.12.4 is unaffected), compute_statistics computed the per-group means and variances on expm1(X) for the t-test methods whenever mean_in_log_space=False, so Welch's test ran on linear-scale values. mean_in_log_space is documented as a fold-change option only (#4037 release note), and the function expects log data. This computes the test statistics on X, materializes the test results, and only then recomputes the means on expm1(X) for logfoldchanges when requested, the same order the wilcoxon branch uses. logfoldchanges are unchanged (the existing test_mean_in_log_space still passes).


Generated by Claude Code

Cindy Krafft added 2 commits September 2, 2026 22:54
rank_genes_groups(method='t-test' | 't-test_overestim_var',
mean_in_log_space=False) computed the per-group means and variances on
expm1(X) and fed them to Welch's test, so the test ran on linear-scale values
while the docstring and release note describe mean_in_log_space as a
fold-change option only. Compute the test statistics on X, then (if
requested) the exponentiated means for the fold change, as the wilcoxon branch
already does. Adds a test asserting scores and p-values are identical for both
settings.
@codecov

codecov Bot commented Sep 2, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.14%. Comparing base (ee763e3) to head (372f2fd).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4337   +/-   ##
=======================================
  Coverage   85.14%   85.14%           
=======================================
  Files         138      138           
  Lines       12252    12254    +2     
=======================================
+ Hits        10432    10434    +2     
  Misses       1820     1820           
Flag Coverage Δ
hatch-test.low-vers 78.68% <100.00%> (+0.02%) ⬆️
hatch-test.pre 84.93% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/scanpy/tools/_rank_genes_groups.py 96.07% <100.00%> (+0.02%) ⬆️

@flying-sheep flying-sheep added this to the 1.12.7 milestone Nov 10, 2026
@flying-sheep
flying-sheep merged commit 7f37356 into scverse:main Nov 10, 2026
13 of 14 checks passed
@scverse scverse deleted a comment from lumberbot-app Bot Nov 10, 2026
@flying-sheep flying-sheep modified the milestones: 1.12.7, 1.13.0 Nov 10, 2026
@flying-sheep

Copy link
Copy Markdown
Member

thank you so much!

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.

rank_genes_groups(method="t-test", mean_in_log_space=False) runs the t-test on exponentiated values

2 participants