Learn R Programming

DescTools (version 0.99.56)

HuberM: Safe (generalized) Huber M-Estimator of Location

Description

(Generalized) Huber M-estimator of location with MAD scale, being sensible also when the scale is zero where huber() returns an error.

Usage

HuberM(x, k = 1.345, mu = median(x), s = mad(x, center = mu), 
       na.rm = FALSE, conf.level = NA, ci.type = c("wald", "boot"), ...)

Value

If conf.level is set to NA then the result will be

a

single numeric value

and if a conf.level is provided, a named numeric vector with 3 elements:

huberm

the estimate for location

lwr.ci

lower bound of the confidence interval

upr.ci

upper bound of the confidence interval

Arguments

x

numeric vector.

k

positive factor; the algorithm winsorizes at k standard deviations.

mu

initial location estimator.

s

scale estimator held constant through the iterations.

na.rm

logical, indicating whether NA values should be stripped before the computation proceeds. Defaults to FALSE.

conf.level

confidence level of the interval. If set to NA (which is the default) no confidence interval will be calculated.

ci.type

The type of confidence interval required. The value should be any subset of the values "wald", "boot".

...

the dots are passed to the function boot.ci, when confidence intervalls are calculated.

Author

Martin Maechler, building on the MASS code mentioned.
Andri Signorell <andri@signorell.net> (confidence intervals and interface)

Details

The standard error is computed using the \(\tau\) correction factor but no finite sample correction.
The original function is not exported, but can be accessed as DescTools::.huberM.

References

Huber, P. J. (1981) Robust Statistics. Wiley.

See Also

hubers (and huber) in package MASS; mad.

Examples

Run this code
HuberM(c(1:9, 1000))
mad   (c(1:9, 1000))

set.seed(7)
x <- c(round(rnorm(1000), 1), round(rnorm(50, m=10, sd = 10)))
HuberM(x, conf.level=0.95)


if (FALSE) {

# scale zero
HuberM(rep(9, 100))
mad   (rep(9, 100))

# bootstrap confidence intervals
HuberM(x, conf.level=0.95, ci.type="boot")
}
 

Run the code above in your browser using DataLab