huber2: Weighted Huber Proposal 2 Estimator

View source: R/huber2.R

huber2R Documentation

Weighted Huber Proposal 2 Estimator

Description

Weighted Huber Proposal 2 estimator of location and scatter.

Usage

huber2(x, w, k = 1.5, na.rm = FALSE, maxit = 50, tol = 1e-04, info = FALSE,
    k_Inf = 1e6, df_cor = TRUE)

Arguments

x

[numeric vector] data.

w

[numeric vector] weights (same length as x).

k

[double] robustness tuning constant (0 < k <= Inf).

na.rm

[logical] indicating whether NA values should be removed before the computation proceeds (default: FALSE).

maxit

[integer] maximum number of iterations to use (default: 50).

tol

[double] numerical tolerance criterion to stop the iterations (default: 1e-04).

info

[logical] indicating whether additional information should be returned (default: FALSE).

k_Inf

[integer] numerical value that represents Inf (default: 1e+06).

df_cor

[logical] if TRUE, the degrees of freedom of the estimate of scale is adjusted (default: TRUE).

Details

Function huber2 computes the weighted Huber (1964) Proposal 2 estimates of location and scale.

The method is initialized by the weighted median (location) and the weighted interquartile range (scale).

Value

The return value depends on info:

info = FALSE:

estimate of mean or total [double]

info = TRUE:

a [list] with items:

  • characteristic [character],

  • estimator [character],

  • estimate [double],

  • variance (default: NA),

  • robust [list],

  • residuals [numeric vector],

  • model [list],

  • design (default: NA),

  • [call]

Comparison

The huber2 estimator is initialized by the weighted median and the weighted (scaled) interquartile range. For unweighted data, this estimator differs from hubers in MASS, which is initialized by mad.

The difference between the estimators is usually negligible (for sufficiently small values of tol). See examples.

References

Huber, P. J. (1964). Robust Estimation of a Location Parameter. Annals of Mathematical Statistics 35, 73–101. doi: 10.1214/aoms/1177703732

Examples

data(workplace)

# Weighted "Proposal 2" estimator of the mean
huber2(workplace$employment, workplace$weight, k = 8)

# More information on the estimate, i.e., info = TRUE
m <- huber2(workplace$employment, workplace$weight, k = 8, info = TRUE)

# Estimate of scale
m$scale

# Comparison with MASS::hubers (without weights). We make a copy of MASS::hubers
library(MASS)
hubers_mod <- hubers

# Then we replace mad by the (scaled) IQR as initial scale estimator
body(hubers_mod)[[7]][[3]][[2]] <- substitute(s0 <- IQR(y, type = 2) * 0.7413)

# Define the numerical tolerance
TOLERANCE <- 1e-8

# Comparison
m1 <- huber2(workplace$payroll, rep(1, 142), tol = TOLERANCE)
m2 <- hubers_mod(workplace$payroll, tol = TOLERANCE)$mu
m1 / m2 - 1

# The absolute relative difference is < 4.0-09 (smaller than TOLERANCE)

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