Learn R Programming

DescTools (version 0.99.57)

QuantileCI: Confidence Interval for Any Quantile

Description

Calculates the confidence interval for any quantile. Although bootstrapping might be a good approach for getting senisble confidence intervals there's sometimes need to have a nonparameteric alternative. This function offers one.

Usage

QuantileCI(x, probs=seq(0, 1, .25), conf.level = 0.95, 
           sides = c("two.sided", "left", "right"),
           na.rm = FALSE, method = c("exact", "boot"), R = 999)

Value

if probs was of length 1 a numeric vector with 3 elements:

est

est

lwr.ci

lower bound of the confidence interval

upr.ci

upper bound of the confidence interval

or, if probs was a vector, a matrix with 3 columns consisting of estimate, lower ci, upper ci

est, lwr.ci, upr.ci

Arguments

x

a (non-empty) numeric vector of data values.

probs

numeric vector of probabilities with values in [0,1]. (Values up to 2e-14 outside that range are accepted and moved to the nearby endpoint.)

conf.level

confidence level of the interval

sides

a character string specifying the side of the confidence interval, must be one of "two.sided" (default), "left" or "right" (abbreviations allowed).
"left" would be analogue to a "greater" hypothesis in a t.test.

na.rm

logical. Should missing values be removed? Defaults to FALSE.

method

defining the type of interval that should be calculated (one out of "exact", "boot"). Default is "exact". See Details.

R

The number of bootstrap replicates. Usually this will be a single positive integer. See boot.ci for details.

Author

Andri Signorell <andri@signorell.net> based on code of W Huber on StackExchange

Details

The "exact" method corresponds to the way the confidence interval for the median is calculated in SAS.
The boot confidence interval type is calculated by means of boot.ci with default type "basic".

See Also

Quantile, quantile, MedianCI

Examples

Run this code
QuantileCI(d.pizza$price, probs=0.25, na.rm=TRUE)

QuantileCI(d.pizza$price, na.rm=TRUE)
QuantileCI(d.pizza$price, conf.level=0.99, na.rm=TRUE)

# multiple probs
QuantileCI(1:100, method="exact" , probs = c(0.25, 0.75, .80, 0.95))
QuantileCI(1:100, method="boot" , probs = c(0.25, 0.75, .80, 0.95))

Run the code above in your browser using DataLab