This function detects outliers in a numeric vector using the MAD (Median Absolute Deviation) method. It calculates the median and the MAD, and determines the boundaries for outliers based on the median and the selected number of MADs.
Usage
is_outlier(
x,
nmads = 2.5,
constant = 1.4826,
type = c("both", "lower", "higher")
)Arguments
- x
Numeric vector.
- nmads
Number of median absolute deviations (MADs) from the median to define the boundaries for outliers. Default is
2.5.- constant
Constant factor to convert the MAD to a standard deviation. Default is
1.4826, which is consistent with the MAD of a normal distribution.- type
Type of outliers to detect. Available options are
"both","lower", or"higher". Iftypeis"both", it detects both lower and higher outliers. Iftypeis"lower", it detects only lower outliers. Iftypeis"higher", it detects only higher outliers.