Skip to content

Commit c443cbd

Browse files
committed
quantile_newton(): extract df()
1 parent efff906 commit c443cbd

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/quantilealgs.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,14 @@ quantile_bisect(d::ContinuousUnivariateDistribution, p::Real) =
4848
# http://www.statsci.org/smyth/pubs/qinvgaussPreprint.pdf
4949

5050
function quantile_newton(d::ContinuousUnivariateDistribution, p::Real, xs::Real=mode(d), tol::Real=1e-12)
51-
x = xs + (p - cdf(d, xs)) / pdf(d, xs)
51+
f(x) = (p - cdf(d, x)) / pdf(d, x)
52+
x = xs + f(xs)
5253
T = typeof(x)
5354
if 0 < p < 1
5455
x0 = T(xs)
5556
while abs(x-x0) > max(abs(x),abs(x0)) * tol
5657
x0 = x
57-
x = x0 + (p - cdf(d, x0)) / pdf(d, x0)
58+
x = x0 + f(x0)
5859
end
5960
return x
6061
elseif p == 0

0 commit comments

Comments
 (0)