Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

weighted_median

Weighted Median


Description

Function to compute the weighted median.

Usage

weighted.median(x, w = 1, na.rm = FALSE)

Arguments

x

a numeric vector containing the values whose median is to be computed.

w

weights that are used to compute the median. This can be either a single value (which will be used as weight for all observations) or a numeric vector of the same length as x.

na.rm

logical. Should NAs (from weights w and/or data x) be removed?

Details

The weighted median is computed as the value where the cumulative relative weights (relative to the sum of all weights) crosses 0.5.

This function is used in the stabilization of the negative gradient via the meadian absolute deviation (MAD). For details see Hofner et al (2015).

References

B. Hofner, A. Mayr, M. Schmid (2016). gamboostLSS: An R Package for Model Building and Variable Selection in the GAMLSS Framework. Journal of Statistical Software, 74(1), 1-31.

Available as vignette("gamboostLSS_Tutorial").

See Also

glmboostLSS, gamboostLSS and blackboostLSS for fitting of GAMLSS where the standardization is explained in more detail.

Examples

## compute the weighted median with case weights
x <- c(1, 2, 3, 4)
w <- c(0, 1, 2, 3)
weighted.median(x, w)

## compute the weighted median with arbitrary weights
x <- rnorm(100)
w <- runif(100)
weighted.median(x, w)

gamboostLSS

Boosting Methods for 'GAMLSS'

v2.0-5
GPL-2
Authors
Benjamin Hofner [aut, cre] (<https://orcid.org/0000-0003-2810-3186>), Andreas Mayr [aut], Nora Fenske [aut], Janek Thomas [aut], Matthias Schmid [aut]
Initial release
2021-01-20

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.