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

Small correction of average p-value merger #1191

Merged
merged 1 commit into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions dowhy/gcm/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def merge_p_values_average(p_values: Union[np.ndarray, List[float]], randomizati
"""
if len(p_values) == 0:
raise ValueError("Given list of p-values is empty!")
if len(p_values) == 1:
return p_values[0]

if np.all(np.isnan(p_values)):
return float(np.nan)
Expand Down
2 changes: 2 additions & 0 deletions tests/gcm/test_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def test_given_invalid_inputs_when_merge_p_values_quantile_then_raises_error():
def test_when_merge_p_values_average_without_randomization_then_returns_expected_results():
assert merge_p_values_average([0]) == 0
assert merge_p_values_average([1]) == 1
assert merge_p_values_average([0.3]) == 0.3
assert merge_p_values_average([0, 1]) == approx(1.0)
assert merge_p_values_average([0, 0, 1]) == 0
assert merge_p_values_average([0, 0.5, 0.5, np.nan, 1, np.nan]) == approx(1.0)
Expand All @@ -83,6 +84,7 @@ def test_when_merge_p_values_average_without_randomization_then_returns_expected
def test_when_merge_p_values_average_with_randomization_then_returns_expected_results():
assert merge_p_values_average([0], randomization=True) == 0
assert merge_p_values_average([1], randomization=True) == 1
assert merge_p_values_average([0.3], randomization=True) == 0.3
assert merge_p_values_average([0, 1], randomization=True) == approx(0.0, abs=0.01)
assert merge_p_values_average([0, 0, 1], randomization=True) == approx(0.0, abs=0.01)
assert merge_p_values_average([0, np.nan, 0, np.nan, 1, 1], randomization=True) == approx(0.0, abs=0.01)
Expand Down