weighted_quantile function

Compute weighted quantiles

Compute weighted quantiles

weighted_quantile(x, w, probs) weighted_median(x, w)

Arguments

  • x: Observations
  • w: Case weights (optional)
  • probs: Quantiles to calculate

Returns

A vector the same length as probs with the corresponding weighted quantiles of x with weight w. For integer weights, this is equivalent to quantile(rep(x, w), probs)

The weighted median of x with weights w. For integer weights, this is equivalent to median(rep(x, w))

Examples

weighted_median(1:6) weighted_median(1:3, c(1, 4, 9)) weighted_median(1:3, c(9, 4, 1)) weighted_quantile(1:3, c(1, 4, 9), seq(0.0, 1.0, by = 0.25)) quantile(rep(1:3, c(1, 4, 9)), seq(0.0, 1.0, by = 0.25))

See Also

Other weighted statistics: weighted_moments(), weighted_tabulate()