wquant function

Weighted quantile function

Weighted quantile function

Estimate weighted quantiles.

wquant( x, weights = rep(1, length(x)), probs = c(`0%` = 0, `25%` = 0.25, `50%` = 0.5, `75%` = 0.75, `100%` = 1) )

Arguments

  • x: numeric; a vector of data.
  • weights: numeric; vector of weights.
  • probs: numeric; desired quantiles.

Returns

wquant returns a vector containing the estimated quantiles. If probs has names, these are inherited.

Details

wquant estimates quantiles of weighted data using the estimator of Harrell & Davis (1982), with improvements recommended by Andrey Akinshin (2023).

Examples

x <- c(1,1,1,2,2,3,3,3,3,4,5,5,6,6,6) quantile(x) wquant(x) wquant(c(1,2,3,4,5,6),weights=c(3,2,4,1,2,3)) wquant(c(1,2,3,4,5),c(1,0,0,1,1))

References

F. E. Harrell and C. E. Davis. A new distribution-free quantile estimator. Biometrika 69 , 635--640, 1982. tools:::Rd_expr_doi("10.1093/biomet/69.3.635") .

A. Akinshin. Weighted quantile estimators. arXiv:2304.07265, 2023. tools:::Rd_expr_doi("10.48550/arxiv.2304.07265") .

Author(s)

Aaron A. King

  • Maintainer: Aaron A. King
  • License: GPL-3
  • Last published: 2025-01-08