Skip to contents

This function performs winsorization on a given vector x based on the median absolute deviation (MAD). It replaces extreme values (those beyond criteria number of MADs from the median) with the highest/lowest non-extreme value. If there are no outliers in the vector based on the MAD criterion, the function returns NULL and prints a message to the console.

Usage

get_winsorization(x, criteria = 3)

Arguments

x

A numeric vector to winsorize.

criteria

The number of MADs from the median beyond which values are considered outliers. Defaults to 3.

Value

A winsorized vector if there are outliers based on the MAD criterion, otherwise NULL.

Details

In statistical analysis, winsorization can be useful for limiting the effect of outliers in your data. This implementation uses the MAD, a robust measure of variability, to determine which data points are considered outliers.

Examples

# Generate a vector with a few extreme values
set.seed(123)
x <- c(rnorm(100), 10, -10)

# Winsorize the vector
x_winsorized <- get_winsorization(x, criteria = 3)