Skip to contents

Replace extreme values by absolute or quantile threshold

Usage

winsorize(
  x,
  lo = NULL,
  hi = NULL,
  prob_lo = 0.025,
  prob_hi = 0.975,
  quantile_type = 7,
  verbosity = 1L
)

Arguments

x

Numeric vector: Input data

lo

Numeric: If not NULL, replace any values in x lower than this with this.

hi

Numeric: If not NULL, replace any values in x higher than this with this.

prob_lo

Numeric (0, 1): If not NULL and lo = NULL, find sample quantile that corresponds to this probability and set as lo.

prob_hi

Numeric (0, 1): If not NULL and hi = NULL, find sample quantile that corresponds to this probability and set as hi.

quantile_type

Integer: passed to stats::quantile

verbosity

Integer: Verbosity level.

Details

If both lo and prob_lo or both hi and prob_hi are NULL, cut-off is set to min(x) and max(x) respectively, i.e. no values are changed

Author

EDG

Examples

if (FALSE) { # \dontrun{
# Winsorize a normally distributed variable
x <- rnorm(500)
xw <- winsorize(x)
# Winsorize an exponentially distributed variable only on
# the top 5% highest values
x <- rexp(500)
xw <- winsorize(x, prob_lo = NULL, prob_hi = .95)
} # }