Skip to content

Commit

Permalink
Merge pull request #4806 from argriffing/cauchy-fit-iqr
Browse files Browse the repository at this point in the history
MAINT: use an informed initial guess for cauchy fit
  • Loading branch information
ev-br committed May 6, 2015
2 parents 7443c29 + b6f5af1 commit 2df0168
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion scipy/stats/_continuous_distns.py
Expand Up @@ -736,7 +736,9 @@ def _entropy(self):
return log(4*pi)

def _fitstart(self, data, args=None):
return (0, 1)
# Initialize ML guesses using quartiles instead of moments.
p25, p50, p75 = np.percentile(data, [25, 50, 75])
return p50, (p75 - p25)/2
cauchy = cauchy_gen(name='cauchy')


Expand Down
10 changes: 10 additions & 0 deletions scipy/stats/tests/test_distributions.py
Expand Up @@ -1793,6 +1793,16 @@ def test_regression_ticket_1530():
assert_almost_equal(params, expected, decimal=1)


def test_gh_pr_4806():
# Check starting values for Cauchy distribution fit.
np.random.seed(1234)
x = np.random.randn(42)
for offset in 10000.0, 1222333444.0:
loc, scale = stats.cauchy.fit(x + offset)
assert_allclose(loc, offset, atol=1.0)
assert_allclose(scale, 0.6, atol=1.0)


def test_tukeylambda_stats_ticket_1545():
# Some test for the variance and kurtosis of the Tukey Lambda distr.
# See test_tukeylamdba_stats.py for more tests.
Expand Down

0 comments on commit 2df0168

Please sign in to comment.