Skip to contents

Takes a numeric vector and will return a vector of winsorized values.

Usage

hai_winsorized_truncate_vec(.x, .fraction = 0.05)

Arguments

.x

A numeric vector

.fraction

A positive fractional between 0 and 0.5 that is passed to the stats::quantile paramater of probs.

Value

A numeric vector

Details

Takes a numeric vector and will return a winsorized vector of values that have been truncated if they are less than or greater than some defined fraction of a quantile. The intent of winsorization is to limit the effect of extreme values.

Author

Steven P. Sanderson II, MPH

Examples

suppressPackageStartupMessages(library(dplyr))

len_out <- 25
by_unit <- "month"
start_date <- as.Date("2021-01-01")

data_tbl <- tibble(
  date_col = seq.Date(from = start_date, length.out = len_out, by = by_unit),
  a = rnorm(len_out),
  b = runif(len_out)
)

vec_1 <- hai_winsorized_truncate_vec(data_tbl$a, .fraction = 0.05)

plot(data_tbl$a)
lines(data_tbl$a)
lines(vec_1, col = "blue")