A (generalized) Huber M-estimator of location with MAD scale that handles
the degenerate case of zero scale gracefully, where
MASS::huber() would return an error.
Arguments
- x
numeric vector of data values
- conf.level
confidence level of the interval. If set to
NA(the default), only the point estimate is returned.- sides
character string specifying the sidedness of the confidence interval (one of
"two.sided"(default),"left"or"right"). SeeConfidenceIntervals().- method
confidence interval method:
"wald"(default) or"boot".- k
positive tuning constant; the algorithm winsorizes at
kstandard deviations. Default is1.345.- mu
initial location estimate.
NULL(default) usesmedian(x), computed afterna.rmis applied.- s
scale estimate held constant through the iterations.
NULL(default) usesmad(x, center = mu), computed afterna.rmis applied.- na.rm
logical; whether to remove missing values before computation; default is
FALSE- ...
further arguments passed to the bootstrap engine when
method = "boot":R,type,parallel, andncpus; see Details
Value
if conf.level = NA, a numeric scalar. Otherwise a named
numeric vector with elements:
estlocation estimate from Huber's M-estimator
lcilower confidence interval bound
uciupper confidence interval bound
Details
Wald interval (method = "wald")
Uses an empirical sandwich standard error for the Huber M-estimator: $$ \hat\mu \;\pm\; t_{1-\alpha/2,\,n-1} \hat s \sqrt{\frac{\hat\tau}{n}}, $$ where $$ \hat\tau = \frac{n \sum_{i=1}^n \psi_k(r_i)^2} {\left\{\sum_{i=1}^n I(|r_i| \leq k)\right\}^2}, \qquad r_i = \frac{x_i-\hat\mu}{\hat s}. $$ Here, \(\psi_k\) denotes the Huber score function. No additional small-sample adjustment is applied beyond use of the t-quantile.
Bootstrap interval (method = "boot")
The statistic \(\hat\mu\) is resampled \(R\) times. Note that
mu and s are fixed at their initial values (computed from
the full data before resampling) and are not re-estimated on each
resample. The bootstrap therefore targets the variability of the
location estimator with fixed scale initialization, not a fully
re-estimated robust estimator. Bootstrap
arguments are passed through ... and extracted via
.extractBootArgs():
Rnumber of bootstrap replicates (default
999)typeconfidence interval type:
"perc"or"bca"(default)parallelparallelization mode:
"no","multicore", or"snow"(default"no")ncpusnumber of CPUs for parallel bootstrap (default
getOption("boot.ncpus", 1L))
The original internal estimator is accessible as
DescToolsX:::.huberM.
Random number generation
method = "boot" resamples and therefore advances R's global
random number generator. Call base::set.seed() beforehand
for reproducible intervals.
See also
MASS::huber(), mad(),
tukeyBiweight()
Other location:
gmean(),
hmean(),
hodgesLehmann(),
meanX(),
medianX(),
modeX(),
tukeyBiweight()
Examples
huberM(c(1:9, 1000))
#> [1] 5.553915
mad(c(1:9, 1000))
#> [1] 3.7065
set.seed(7)
x <- c(round(rnorm(1000), 1), round(rnorm(50, mean = 10, sd = 10)))
huberM(x, conf.level = 0.95)
#> est lci uci
#> 0.05600116 -0.01020176 0.12220408
huberM(x, conf.level = 0.95, method = "boot", R = 499, type = "bca")
#> est lci uci
#> 0.05600116 -0.01018489 0.12185434
# degenerate case: scale zero
huberM(rep(9, 100))
#> Warning: scale 's' is zero -- returning initial 'mu'
#> [1] 9
