Weighted quantiles
wquantile.RdFunctions to compute weighted quantiles and the weighted interquartile range.
Arguments
- wt
Vector of weights
- x
Vector of data, same length as
wt- probs
Numeric vector of probabilities with values in [0,1].
- already.sorted
If FALSE, sort
wtandxin increasing order ofx. If TRUE, it is assumed thatwtandxare already sorted.- already.normalized
If FALSE, normalize
wtby diving each entry by the sum of all entries. If TRUE, it is assumed thatsum(wt)==1
Details
wquantile uses the findInterval function. wIQR
calls the wquantile function.
Value
Returns the sample quantiles or interquartile range of a discrete distribution with
support points x and corresponding probability masses wt
Examples
IQR(1:10)
#> [1] 4.5
wIQR(x=1:10) # Note: Different algorithm than IQR function
#> [1] 5
wIQR(1:10,1:10) # Weighted quartiles are now 4 and 8
#> [1] 4