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 -1.01   0.465         -1.01  
#>  2 2021-02-01  0.433  0.271          0.433 
#>  3 2021-03-01  0.164  0.531          0.164 
#>  4 2021-04-01 -1.51   0.110         -1.51  
#>  5 2021-05-01  0.0977 0.224          0.0977
#>  6 2021-06-01 -1.80   0.148         -1.80  
#>  7 2021-07-01 -1.14   0.750         -1.14  
#>  8 2021-08-01  1.11   0.313          1.11  
#>  9 2021-09-01 -3.16   0.0751        -3.16  
#> 10 2021-10-01 -1.44   0.664         -1.44  
#> # ℹ 14 more rows