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

Do not zero out one-tailed z-statistics for p-values > 0.5 #693

Merged
merged 7 commits into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
12 changes: 8 additions & 4 deletions nimare/tests/test_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,18 +247,22 @@ def test_ddimages_to_coordinates_merge_strategy(testdata_ibma):


@pytest.mark.parametrize(
"z,tail,expected_p",
"expected_z,tail,expected_p",
[
(0.0, "two", 1.0),
(0.0, "one", 0.5),
(1.959963, "two", 0.05),
(1.959963, "one", 0.025),
(-1.959963, "two", 0.05),
(-1.959963, "one", 0.025),
Copy link
Contributor

Choose a reason for hiding this comment

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

This test case should be (-1.959964, "one", 0.0975). I think I've corrected in issue #748

([0.0, 1.959963, -1.959963], "two", [1.0, 0.05, 0.05]),
([0.0, 1.959963, -1.959963], "one", [0.5, 0.025, 0.025]),
Copy link
Contributor

Choose a reason for hiding this comment

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

([0.0, 1.959963, -1.959963], "one", [0, 0.025, 0.975])

],
)
def test_z_to_p(z, tail, expected_p):
"""Test z to p conversion."""
p = transforms.z_to_p(z, tail)
def test_z_to_p(expected_z, tail, expected_p):
"""Test z to p, and p to z conversion."""
p = transforms.z_to_p(expected_z, tail)
z = transforms.p_to_z(expected_p, tail) * np.sign(expected_z)

assert np.all(np.isclose(p, expected_p))
assert np.all(np.isclose(z, expected_z))
8 changes: 6 additions & 2 deletions nimare/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,12 +670,16 @@ def p_to_z(p, tail="two"):
Z-statistics (unsigned)
"""
p = np.array(p)

# Ensure that no p-values are converted to Inf/NaNs
p = np.clip(p, 1.0e-300, 1.0 - 1.0e-16)
tsalo marked this conversation as resolved.
Show resolved Hide resolved
if tail == "two":
z = stats.norm.isf(p / 2)
elif tail == "one":
z = stats.norm.isf(p)
z = np.array(z)
z[z < 0] = 0
# Replace negative values in z with values estimated by CDF
zval_cdf = stats.norm.ppf(p)
z[np.atleast_1d(z < 0)] = zval_cdf[z < 0]
else:
raise ValueError('Argument "tail" must be one of ["one", "two"]')

Expand Down