This function computes the biweight scale, a robust measure of scale or dispersion for a numeric vector. The biweight scale is less sensitive to outliers than the sample standard deviation.
Usage
biweight_scale(
x,
loc = stats::median(x),
c = 9,
reduced = FALSE,
tol = 1e-06,
max_iter = 50,
drop.na = FALSE
)
Arguments
- x
A numeric vector.
- loc
Initial guess for the location (default: median of
x
).- c
A numeric value specifying the tuning constant for the biweight estimator (
c = 9
by default).- reduced
A logical value specifying whether the sample size, n, should be reduced to the number of non-rejected values. If
TRUE
, n is reduced to the number of observations that pass a rejection criteria. IfFALSE
(default), n is equal to the length ofx
(the input data).- tol
Convergence tolerance for the iterative computation (default: 1e-6).
- max_iter
Maximum number of iterations (default: 50).
- drop.na
A logical value indicating whether to remove missing values (
NA
) from the calculations. IfTRUE
, missing values will be removed. IfFALSE
(the default), missing values will be included in the calculations.
References
Mosteller, F., and Tukey, J. W. (1977). Data Analysis and Regression: A Second Course in Statistics. Addison-Wesley, pp. 203-209.
Examples
# Example 1: Compute biweight scale for a vector
x <- c(seq(1,100))
tibble::tibble(
sd = stats::sd(x),
mad = stats::mad(x),
biscale = biweight_scale(x)
)
#> # A tibble: 1 × 3
#> sd mad biscale
#> <dbl> <dbl> <dbl>
#> 1 29.0 37.1 29.6
# Example 2: Biweight scale is robust to outliers
x <- c(seq(1,99), 1e3) # An outlier at 1000
tibble::tibble(
sd = stats::sd(x),
mad = stats::mad(x),
biscale = biweight_scale(x)
)
#> # A tibble: 1 × 3
#> sd mad biscale
#> <dbl> <dbl> <dbl>
#> 1 99.2 37.1 29.5