Learn R Programming

weibullness (version 2.26.9)

wmedian: Weighted median

Description

Calculates the weighted median of a vector x with its corresponding w.

Usage

wmedian(x, w, a=0.5)

Value

a numeric value.

Arguments

x

a numeric vector of observations.

w

a numeric vector of weights corresponding to x.

a

the offset fraction in [0,1]. A value of zero calculates the left quantile of the weighted empirical cumulative distribution function (CDF), while a value of one calculates the right quantile of the weighted empirical CDF.

Author

Chanseok Park

Details

The weighted empirical CDF is defined by $$ F_w(t) = \sum_{j=1}^{n} w_j I(x_j \le t),$$ where \(I\) is the indicator function. For more details, see Section 2.1 of Park et al. (2024).

The left quantile is given by \(Q_L(u) = \inf\{t: F_w(t) \ge u\}\), and the right quantile is given by \(Q_R(u) = \inf\{t: F_w(t) > u\}\). Then, wmedian calculates \((1-a)Q_L(u) + aQ_R(u)\), where \(a\) is the interpolation value.

References

F. Y. Edgeworth (1888). On a New Method of Reducing Observations Relating to Several Quantities. The London, Edinburgh, and Dublin Philosophical Magazine and Journal of Science, 25(154), 184-191.

Park, C., X. Gao, and M. Wang (2024). Robust explicit estimators using the power-weighted repeated medians. Journal of Applied Statistics, 51(8), 1590-1608. tools:::Rd_expr_doi("10.1080/02664763.2023.2229969")

See Also

median for the conventional median.

Examples

Run this code
wmedian( c(1,2,3,4,5), c(0.15, 0.1, 0.2, 0.3, 0.25) )
wmedian( c(1,2,3,4,5) )  # is the same as median( c(1,2,3,4,5) ) 

Run the code above in your browser using DataLab