Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed code + added test #3137

Merged
merged 4 commits into from Jan 24, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/whats_new.rst
Expand Up @@ -68,6 +68,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>`_`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- 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>`_`)
- 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