Skip to contents

Takes a numeric vector and will return a tibble with the winsorized values.

Usage

hai_winsorized_move_augment(.data, .value, .multiple, .names = "auto")

Arguments

.data

The data being passed that will be augmented by the function.

.value

This is passed rlang::enquo() to capture the vectors you want to augment.

.multiple

A positive number indicating how many times the the zero center mean absolute deviation should be multiplied by for the scaling parameter.

.names

The default is "auto"

Value

An augmented tibble

Details

Takes a numeric vector and will return a winsorized vector of values that have been moved some multiple from the mean absolute deviation zero center of some vector. The intent of winsorization is to limit the effect of extreme values.

Author

Steven P. Sanderson II, MPH

Examples

suppressPackageStartupMessages(library(dplyr))

len_out <- 24
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)
)

hai_winsorized_move_augment(data_tbl, a, .multiple = 3)
#> # A tibble: 24 × 4
#>    date_col        a     b winsor_scale_a
#>    <date>      <dbl> <dbl>          <dbl>
#>  1 2021-01-01 -2.79  0.104         -2.79 
#>  2 2021-02-01  0.194 0.708          0.194
#>  3 2021-03-01 -0.754 0.816         -0.754
#>  4 2021-04-01 -1.43  0.395         -1.43 
#>  5 2021-05-01  0.855 0.282          0.855
#>  6 2021-06-01  1.03  0.561          1.03 
#>  7 2021-07-01 -0.802 0.621         -0.802
#>  8 2021-08-01 -0.546 0.556         -0.546
#>  9 2021-09-01  0.365 0.900          0.365
#> 10 2021-10-01 -0.445 0.800         -0.445
#> # ℹ 14 more rows