outliers_mad | R Documentation |
outliers_mad is used to identify outliers in vectors using Leys et al.'s (2003) median absolute deviation approach.
outliers_mad(x, threshold = 3.0, replace_outlier_value = NA, show_mad_values = FALSE, show_outlier_indices = FALSE, b_constant = 1.4826, digits = 2, debug = FALSE)
x |
a vector of numbers |
threshold |
value to use as cutoff (Leys et al. recommend 2.5 or 3.0 as default) |
replace_outlier_value |
if value is an outlier, what to replace it with? NA by default |
show_mad_values |
if TRUE, will show deviation score of each value |
show_outlier_indices |
if TRUE, return index/position of outliers |
b_constant |
a constant linked to the assumption of normality of the data, disregarding the abnormality induced by outliers |
digits |
how many digits to round output to |
debug |
if TRUE, print messages (FALSE by default) |
We can identify and remove outliers in our data by identifying data points that are too extreme—either too many standard deviations (SD) away from the mean or too many median absolute deviations (MAD) away from the median. The SD approach might not be ideal with extreme outliers, whereas the MAD approach is much more robust (for comparison of both approaches, see Leys et al., 2013, Journal of Experimental Social Psychology).
b_constant is usually 1.4826, a constant linked to the assumption of normality of the data, disregarding the abnormality induced by outliers (Rousseeuw & Croux, 1993).
A vector with outliers identified (default converts outliers to NA)
Hause Lin
Leys, C., Ley, C., Klein, O., Bernard, P., & Licata, L. (2013). Detecting outliers: Do not use standard deviation around the mean, use absolute deviation around the median. Journal of Experimental Social Psychology, 49(4), 764-766. doi:10.1016/j.jesp.2013.03.013 (https://www.sciencedirect.com/science/article/pii/S0022103113000668)
outliersZ
x <- c(1, 3, 3, 6, 8, 10, 10, 1000, -1000) # 1000 is an outlier outliers_mad(x) outliers_mad(x, threshold = 3.0) outliers_mad(x, threshold = 2.5, replace_outlier_value = -999) outliers_mad(x, threshold = 1.5, show_outlier_indices = TRUE) outliers_mad(x, threshold = 1.5, show_mad_values = TRUE) outliers_mad(x, threshold = 1.5, show_mad_values = TRUE, replace_outlier_value = -88)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.