Skip to content

Commit 672e46b

Browse files
committed
cquantile_newton(): extract df()
1 parent c826476 commit 672e46b

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
@@ -68,13 +68,14 @@ function quantile_newton(d::ContinuousUnivariateDistribution, p::Real, xs::Real=
6868
end
6969

7070
function cquantile_newton(d::ContinuousUnivariateDistribution, p::Real, xs::Real=mode(d), tol::Real=1e-12)
71-
x = xs + (ccdf(d, xs)-p) / pdf(d, xs)
71+
f(x) = (ccdf(d, x)-p) / pdf(d, x)
72+
x = xs + f(xs)
7273
T = typeof(x)
7374
if 0 < p < 1
7475
x0 = T(xs)
7576
while abs(x-x0) > max(abs(x),abs(x0)) * tol
7677
x0 = x
77-
x = x0 + (ccdf(d, x0)-p) / pdf(d, x0)
78+
x = x0 + f(x0)
7879
end
7980
return x
8081
elseif p == 1

0 commit comments

Comments
 (0)