R/outliersMAD.R
outliersMAD.Rd
outliersMAD is used to identify outliers in vectors using Leys et al.'s (2003) median absolute deviation approach.
outliersMAD(x, MADCutOff = 3.0, replaceOutliersWith = NA, showMADValues = FALSE, outlierIndices = FALSE, bConstant = 1.4826, digits = 2)
x | a vector of numbers |
---|---|
MADCutOff | value to use as cutoff (Leys e tal. recommend 2.5 or 3.0 as default) |
replaceOutliersWith | if value is an outlier, what to replace it with? NA by default |
showMADValues | if TRUE, will show deviation score of each value |
outlierIndices | return index/position of outlier |
bConstant | a constant linked to the assumption of normality of the data, disregarding the abnormality induced by outliers |
digits | how many digits/decimals to round output to |
A vector with outliers identified (default converts outliers to NA)
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).
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)
Hause Lin
#>#>#> [1] 1 3 3 6 8 10 10 NA NAoutliersMAD(example, MADCutOff = 3.0)#>#>#> [1] 1 3 3 6 8 10 10 NA NAoutliersMAD(example, MADCutOff = 2.5, replaceOutliersWith = -999)#>#>#> [1] 1 3 3 6 8 10 10 -999 -999outliersMAD(example, MADCutOff = 1.5, outlierIndices = TRUE)#>#> [1] 8 9outliersMAD(example, MADCutOff = 1.5, showMADValues = TRUE)#>#>#> [1] -0.84 -0.51 -0.51 0.00 0.34 0.67 0.67 167.61 -169.63outliersMAD(example, MADCutOff = 1.5, showMADValues = TRUE, replaceOutliersWith = -88)#>#>#> [1] -0.84 -0.51 -0.51 0.00 0.34 0.67 0.67 167.61 -169.63