From 4e9ef3b4d2980d8c31d14a828c3387a97b17e523 Mon Sep 17 00:00:00 2001 From: bthirion Date: Mon, 24 Jan 2022 10:32:38 +0100 Subject: [PATCH] [FIX] fixed code + added test (#3137) * fixed code + added test * pep8 * Added to whatsnew * string fix --- doc/whats_new.rst | 2 ++ nilearn/glm/tests/test_thresholding.py | 5 +++++ nilearn/glm/thresholding.py | 3 +-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/doc/whats_new.rst b/doc/whats_new.rst index 3c2b81dcf7..ec0fdca4a9 100644 --- a/doc/whats_new.rst +++ b/doc/whats_new.rst @@ -83,6 +83,8 @@ Fixes index (See PR `#3078 `_). - Convert reference in `nilearn/regions/region_extractor.py` to use footcite / footbibliography. (See issue `#2787 `_ and PR `#3111 `_). +- Computation of Benjamini-Hocheberg threshold fixed in `nilearn/glm/thresholding.py` function (see issue `#2879 `_ and PR `#3137 `_) + Enhancements ------------ diff --git a/nilearn/glm/tests/test_thresholding.py b/nilearn/glm/tests/test_thresholding.py index 94418b4ac8..340676c90e 100644 --- a/nilearn/glm/tests/test_thresholding.py +++ b/nilearn/glm/tests/test_thresholding.py @@ -24,6 +24,11 @@ def test_fdr(): fdr_threshold(x, -.1) with pytest.raises(ValueError): fdr_threshold(x, 1.5) + # addresses #2879 + n = 10 + pvals = np.linspace(1 / n, 1, n) + pvals[0] = 0.007 + assert np.isfinite(fdr_threshold(norm.isf(pvals), .1)) def test_threshold_stats_img(): diff --git a/nilearn/glm/thresholding.py b/nilearn/glm/thresholding.py index c5b67be4c0..ca0dd124be 100644 --- a/nilearn/glm/thresholding.py +++ b/nilearn/glm/thresholding.py @@ -98,8 +98,7 @@ def fdr_threshold(z_vals, alpha): z_vals_ = - np.sort(- z_vals) p_vals = norm.sf(z_vals_) n_samples = len(p_vals) - pos = p_vals < alpha * np.linspace( - .5 / n_samples, 1 - .5 / n_samples, n_samples) + pos = p_vals < alpha * np.linspace(1 / n_samples, 1, n_samples) if pos.any(): return (z_vals_[pos][-1] - 1.e-12)