Skip to content

Commit

Permalink
[FIX] fixed code + added test (#3137)
Browse files Browse the repository at this point in the history
* fixed code + added test

* pep8

* Added to whatsnew

* string fix
  • Loading branch information
bthirion committed Jan 24, 2022
1 parent a508977 commit 4e9ef3b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions doc/whats_new.rst
Expand Up @@ -83,6 +83,8 @@ Fixes
index (See PR `#3078 <https://github.com/nilearn/nilearn/issues/3078>`_).
- Convert reference in `nilearn/regions/region_extractor.py` to use footcite / footbibliography.
(See issue `#2787 <https://github.com/nilearn/nilearn/issues/2787>`_ and PR `#3111 <https://github.com/nilearn/nilearn/pull/3111>`_).
- Computation of Benjamini-Hocheberg threshold fixed in `nilearn/glm/thresholding.py` function (see issue `#2879 <https://github.com/nilearn/nilearn/issues/2879>`_ and PR `#3137 <https://github.com/nilearn/nilearn/pull/3137>`_)


Enhancements
------------
Expand Down
5 changes: 5 additions & 0 deletions nilearn/glm/tests/test_thresholding.py
Expand Up @@ -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():
Expand Down
3 changes: 1 addition & 2 deletions nilearn/glm/thresholding.py
Expand Up @@ -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)

Expand Down

0 comments on commit 4e9ef3b

Please sign in to comment.