R/weighted_mad.R

Defines functions weighted_mad

Documented in weighted_mad

# weighted median absolute deviations about the weighted median
weighted_mad <- function(x, w, na.rm = FALSE, constant = 1.482602)
{
    dat <- .check_data_weights(x, w, na.rm)
    if (is.null(dat))
        return(NA)
    med <- weighted_quantile(dat$x, dat$w, probs = 0.5, na.rm)
    mad <- weighted_quantile(abs(dat$x - med), dat$w, probs = 0.5, na.rm)
    unname(mad * constant)
}

Try the robsurvey package in your browser

Any scripts or data that you put into this service are public.

robsurvey documentation built on Jan. 6, 2023, 5:09 p.m.