weighted.quantile {cNORM}R Documentation

Weighted quantile estimator

Description

Computes weighted quantiles (code from Andrey Akinshin via https://aakinshin.net/posts/weighted-quantiles/ Code made available via the CC BY-NC-SA 4.0 license) on the basis of either the weighted Harrell-Davis quantile estimator or an adaption of the type 7 quantile estimator of the generic quantile function in the base package. Please provide a vector with raw values, the pobabilities for the quantiles and an additional vector with the weight of each observation. In case the weight vector is NULL, a normal quantile estimation is done. The vectors may not include NAs and the weights should be positive non-zero values.

Usage

weighted.quantile(x, probs, weights = NULL, type = "Type7")

Arguments

x

A numerical vector

probs

Numerical vector of quantiles

weights

A numerical vector with weights; should have the same length as x

type

Type of estimator, can either be "Harrell-Davis" using a beta function to approximate the weighted percentiles (Harrell & Davis, 1982) or "Type7" (default; Hyndman & Fan, 1996), an adaption of the generic quantile function in R, including weighting. All code based on the work of Akinshin (2020).

Value

the weighted quantiles

References

  1. Harrell, F.E. & Davis, C.E. (1982). A new distribution-free quantile estimator. Biometrika, 69(3), 635-640.

  2. Hyndman, R. J. & Fan, Y. 1996. Sample quantiles in statistical packages, American Statistician 50, 361–365.

  3. Akinshin, A. (2020). Weighted quantile estimators. https://aakinshin.net/posts/weighted-quantiles/


[Package cNORM version 2.0.3 Index]