ci_quantile: Distribution-free confidence interval for a sample quantile

View source: R/utils-helpers.R

ci_quantileR Documentation

Distribution-free confidence interval for a sample quantile

Description

Computes a nonparametric confidence interval for a sample quantile using the order-statistic method: the interval endpoints are order statistics of x, chosen via the binomial distribution of ranks so that no assumption is made about the shape of x's distribution.

Usage

ci_quantile(x, prob = 0.5, conf_level = 0.95)

Arguments

x

Numeric vector of observations

prob

Quantile probability (e.g. 0.1 for the tenth percentile)

conf_level

Confidence level

Details

Used by er_vpc_add_observed() to compute a confidence interval for each requested percentile of the observed response within an exposure bin (the observed-side analogue of the across-replicate percentile interval er_vpc_add_simulated() gets from simulated data, powering er_style_vpc_observed_quantile_errorbar()). Like ci_clopper_pearson(), this interval is exact for its target coverage but conservative – the discreteness of the binomial rank distribution means the achieved coverage can exceed the nominal conf_level, especially for a small bin or an extreme prob. The candidate rank indices are clipped to ⁠[1, length(x)]⁠, so a very small or extreme-prob bin returns a (still valid, but wider-than-nominal) interval built from the most extreme order statistics available rather than NA.

Value

Named numeric vector (lower, upper), with confidence level stored as an attribute. Returns c(lower = NA, upper = NA) if fewer than 2 non-missing values are supplied.

References

Conover, W. J. (1999). Practical Nonparametric Statistics (Third edition). New York: John Wiley & Sons. ISBN 0-471-16068-7.

Examples

ci_quantile(rnorm(100), prob = 0.1)


erplots documentation built on Oct. 4, 2026, 5:06 p.m.