Numerically calculate a quantile from a distribution function.
cdf2quantile(p, cdf, interval = c(-3, 3), lower = min(interval), upper = max(interval), …)
a number in the interval (0,1).
cumulative distribution function, a function.
interval in which to look for the root, see Details.
lower end point of the interval.
upper end point of the interval.
any further arguments to be passed to the root finding function and the cdf, see Details.
The quantile, \(q\), is computed numerically as the solution of the equation \(cdf(q)-p=0\).
uniroot is used to find the root. To request higher
precision, set argument
tol. Other arguments in
passed on to
uniroot needs an interval where to look for the root.
There is a default one, which is extended automatically if it does not
contain the quantile. This assumes that argument
cdf is an
increasing function (as it should be).
To override the default interval, use argument
vector of two numbers) or
upper. This may
be necessary if the support of the distribution is not the whole real
cdf does not cope with values outside the support of
The computed quantile as a number.
cdf2quantile(0.95, pnorm)#>  1.644851cdf2quantile(0.05, pexp) # support [0,Inf) is no problem for#>  0.05129361cdf2quantile(0.05, plnorm) # for built-in distributions.#>  0.1930405## default predicision is about 4 digits after decimal point cdf2quantile(0.95, pnorm, mean = 3, sd = 1)#>  4.644829cdf2quantile(0.05, pnorm, mean = 3, sd = 1)#>  1.355143qnorm(c(0.95, 0.05), mean = 3, sd = 1)#>  4.644854 1.355146## request a higher precision: cdf2quantile(0.05, pnorm, mean = 3, sd = 1, tol = 1e-8)#>  1.355146cdf2quantile(0.05, pnorm, mean = 3, sd = 1, tol = 1e-12)#>  1.355146## see also examples for plotpdf()