(Generalized) Huber M-estimator of location with MAD scale, being sensible also when the scale is zero where huber()
returns an error.
huberM(x, k =1.5, weights =NULL, tol =1e-06, mu =if(is.null(weights)) median(x)else wgt.himedian(x, weights), s =if(is.null(weights)) mad(x, center=mu)else wgt.himedian(abs(x - mu), weights), se =FALSE, warn0scale = getOption("verbose"))
Arguments
x: numeric vector.
k: positive factor; the algorithm winsorizes at k
standard deviations.
weights: numeric vector of non-negative weights of same length as x, or NULL.
tol: convergence tolerance.
mu: initial location estimator.
s: scale estimator held constant through the iterations.
se: logical indicating if the standard error should be computed and returned (as SE component). Currently only available when weights is NULL.
warn0scale: logical; if true, and s is 0 and length(x) > 1, this will be warned about.
Returns
list of location and scale parameters, and number of iterations used. - mu: location estimate
s: the s argument, typically the mad.
it: the number of Huber iterations used.
Details
Note that currently, when non-NULLweights are specified, the default for initial location mu and scale s is wgt.himedian, where strictly speaking a weighted non-hi median should be used for consistency. Since s is not updated, the results slightly differ, see the examples below.
When se = TRUE, the standard error is computed using the τ correction factor but no finite sample correction.
Author(s)
Martin Maechler, building on the MASS code mentioned.