quantile_w: Weighted Sample Quantiles

View source: R/quantile_w.R

quantile_wR Documentation

Weighted Sample Quantiles

Description

quantile_w computes the weighted population quantiles.

Usage

quantile_w(x, w, probs, na.rm = FALSE)

Arguments

x

[numeric vector] observations.

w

[numeric vector] weights (same length as vector x).

probs

[numeric vector] vector of probabilities with values in [0,1].

na.rm

[logical] indicating whether NA values should be removed before the computation proceeds (default: FALSE).

Details

Overview.

quantile_w computes the weighted sample quantiles; argument probs allows vector inputs.

Implementation.

The function is based on a weighted version of the quickselect algorithm with the Bentley and McIlroy (1993) 3-way partitioning scheme. For very small arrays, we use insertion sort.

Compatibility.

For equal weighting, i.e. when all elements in w are equal, quantile_w computes quantiles that are identical with type = 2 in stats::quantile; see also Hyndman and Fan (1996).

Value

Weighted estimate of the population quantiles.

References

Bentley, J.L. and D.M. McIlroy (1993). Engineering a Sort Function, Software - Practice and Experience, 23, 1249–1265. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1002/spe.4380231105")}

Hyndman, R.J. and Y. Fan (1996). Sample Quantiles in Statistical Packages, The American Statistician, 50, 361–365.\Sexpr[results=rd]{tools:::Rd_expr_doi("10.2307/2684934")}

See Also

median_w


wbacon documentation built on June 8, 2025, 10:07 a.m.