Quantiles for objects of class density
# S3 method for density
quantile(x, probs = seq(0.25, 0.75, 0.25), names = TRUE, normalize = TRUE, ...)
a object of class density
or a list of densities
numeric vector of probabilities with values in [0,1]. Note that
elements very close to the boundaries return Inf
or -Inf
logical; if TRUE
, the result has a names attribute, resp.
a rownames and colnames attributes. Set to FALSE
for speedup with
many probabilities
logical; if TRUE
then the values in x$y
are
multiplied with a factor such that their integral is equal to one.
further arguments passed to or from other methods (currently unused)
If x is of class density
(or a list with exactly one element),
a vector with quantiles. If x is a list of densities, then the output is a
matrix of quantiles, with each matrix row corresponding to the respective
density.
This function is a near-exact copy of the quantile.density
function from package BMS (https://CRAN.R-project.org/package=BMS).
In spring of 2022, CRAN informed us that the BMS has been orphaned, so we
copied the code (and corresponding documentation) we needed from it. See
10.18637/jss.v068.i04 for their paper.
The function quantile.density()
applies generically to the built-in
class density
(as least for versions where there is no such method
in the pre-configured packages). Note that this function relies on
trapezoidal integration in order to compute the cumulative densities
necessary for the calculation of quantiles.
# NOT RUN {
rNorm_dens <- density(rnorm(100000))
quantile(rNorm_dens)
# }
Run the code above in your browser using DataLab