weighted_median: Weighted Median

Description Usage Arguments Details References See Also Examples

Description

Function to compute the weighted median.

Usage

1
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

1
2
3
4
5
6
7
8
9
## 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 documentation built on June 16, 2018, 1:37 p.m.