diff --git a/pingouin/power.py b/pingouin/power.py index 5f2c4426..45e5589d 100644 --- a/pingouin/power.py +++ b/pingouin/power.py @@ -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 diff --git a/pingouin/tests/test_power.py b/pingouin/tests/test_power.py index 60025c64..f16fbe31 100644 --- a/pingouin/tests/test_power.py +++ b/pingouin/tests/test_power.py @@ -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)