Skip to content

Commit

Permalink
hotfix: CI crash in test_power_chi2 [WIP] (#344)
Browse files Browse the repository at this point in the history
* disable power_chi2 test

* Add back first test

* Add back second test

* Add third test

* "Effect size" is causing the failure!

* Fix segmentation error
  • Loading branch information
raphaelvallat authored Feb 22, 2023
1 parent 596f122 commit 8c92b6d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pingouin/power.py
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,7 @@ def _eval_w(w, n, power, alpha):
return func(w, n, power, alpha) - power

try:
return brenth(_eval_w, 1e-10, 1e07, args=(n, power, alpha))
return brenth(_eval_w, 1e-10, 100, args=(n, power, alpha))
except ValueError: # pragma: no cover
return np.nan

Expand Down
7 changes: 5 additions & 2 deletions pingouin/tests/test_power.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,20 +235,23 @@ def test_power_chi2(self):
"""Test function power_chi2.
Values are compared to the pwr R package.
"""
w = 0.30
# Power
assert np.isclose(power_chi2(dof=1, w=0.3, n=20), 0.2686618)
assert np.isclose(power_chi2(dof=2, w=0.3, n=100), 0.7706831)

# Sample size
assert np.isclose(power_chi2(dof=1, w=0.3, power=0.80), 87.20954)
assert np.isclose(power_chi2(dof=3, w=0.3, power=0.80), 121.1396)

# Effect size
assert np.isclose(power_chi2(dof=4, n=50, power=0.80), 0.4885751)
assert np.isclose(power_chi2(dof=1, n=50, power=0.80), 0.3962023)

# Alpha
assert np.isclose(
power_chi2(dof=1, w=0.3, n=100, power=0.80, alpha=None), 0.03089736, atol=1e-03
)

# Error
with pytest.raises(ValueError):
power_chi2(1, w=w)
power_chi2(1, w=0.3)

0 comments on commit 8c92b6d

Please sign in to comment.