From 6707aa1b01ecebf47d2be068cf32b8e754a5b30a Mon Sep 17 00:00:00 2001 From: alex Date: Fri, 10 Jun 2016 14:39:42 -0400 Subject: [PATCH] MAINT: logistic accuracy --- scipy/stats/_continuous_distns.py | 8 +++++++- scipy/stats/tests/test_distributions.py | 22 ++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/scipy/stats/_continuous_distns.py b/scipy/stats/_continuous_distns.py index 0ae8ecd23212..142a228061da 100644 --- a/scipy/stats/_continuous_distns.py +++ b/scipy/stats/_continuous_distns.py @@ -2967,7 +2967,13 @@ def _cdf(self, x): return special.expit(x) def _ppf(self, q): - return -log(1.0/q-1) + return special.logit(q) + + def _sf(self, x): + return special.expit(-x) + + def _isf(self, q): + return -special.logit(q) def _stats(self): return 0, pi*pi/3.0, 0, 6.0/5.0 diff --git a/scipy/stats/tests/test_distributions.py b/scipy/stats/tests/test_distributions.py index d76547c2f58a..490aa0e09c01 100644 --- a/scipy/stats/tests/test_distributions.py +++ b/scipy/stats/tests/test_distributions.py @@ -470,6 +470,28 @@ def test_stats(self): decimal=4) +class TestLogistic(TestCase): + # gh-6226 + def test_cdf_ppf(self): + x = np.linspace(-20, 20) + y = stats.logistic.cdf(x) + xx = stats.logistic.ppf(y) + assert_allclose(x, xx) + + def test_sf_isf(self): + x = np.linspace(-20, 20) + y = stats.logistic.sf(x) + xx = stats.logistic.isf(y) + assert_allclose(x, xx) + + def test_extreme_values(self): + # p is chosen so that 1 - (1 - p) == p in double precision + p = 9.992007221626409e-16 + desired = 34.53957599234088 + assert_allclose(stats.logistic.ppf(1 - p), desired) + assert_allclose(stats.logistic.isf(p), desired) + + class TestLogser(TestCase): def test_rvs(self): vals = stats.logser.rvs(0.75, size=(2, 50))