Skip to content

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

Open
cindykrafft wants to merge 2 commits into
scverse:mainfrom
cindykrafft:fix/rank-genes-groups-ttest-log-space
Open

cindykrafft wants to merge 2 commits into
scverse:mainfrom
cindykrafft:fix/rank-genes-groups-ttest-log-space

Conversation

@cindykrafft

Copy link
Copy Markdown

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 81.98%. Comparing base (a656a33) to head (d6478da).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4337   +/-   ##
=======================================
  Coverage   81.98%   81.98%           
=======================================
  Files         134      134           
  Lines       13235    13237    +2     
=======================================
+ Hits        10851    10853    +2     
  Misses       2384     2384           
Flag Coverage Δ
hatch-test.low-vers 79.09% <100.00%> (+0.02%) ⬆️
hatch-test.pre 81.86% <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 93.62% <100.00%> (+0.03%) ⬆️

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

1 participant