iqrMethod | R Documentation |
This function identifies potential outliers in a numeric vector using the interquartile range (IQR) method.
iqrMethod(x, k = 1.5, skew = FALSE, drop.na = FALSE)
x |
A numeric vector. |
k |
A numeric value specifying the fence factor. |
skew |
A logical value indicating whether to calculate the version of
the fences that accounts for moderate skewness in the underlying data distribution.
By default, |
drop.na |
A logical value indicating whether to remove missing values ( |
For symmetric distributions, observations that fall outside the range defined by the lower fence (Q1 - k × IQR) and upper fence (Q3 + k × IQR) are considered as potential outliers, where Q1 and Q3 are the 25th and 75th percentiles, respectively. The fence factor can be adjusted to make the method more or less robust (often 1.5 or 3). Optionally, the method can account for moderate skewness in data distributions by incorporating the medcouple. In such a case, the lower and upper fences are expressed in terms of the medcouple, adjusting the fences asymmetrically to better accommodate skewed distributions. Note that the implemented method does not explicitly account for tail heaviness. While the medcouple can provide some robustness against heavy tails, the method may still struggle to accurately identify potential outliers in distributions with extreme kurtosis or long-tailed behavior.
A tibble with two columns:
data
: The original numeric values.
flag
: A logical vector indicating whether each value is a potential outlier or not.
Christian L. Goueguel
Everitt, B. S., and Skrondal, A. (2010). The Cambridge Dictionary of Statistics. Cambridge University Press.
Tukey, J. (1977). Exploratory Data Analysis. Addison-Wesley
Hubert M., and Vandervieren E. (2008). An Adjusted Boxplot for Skewed Distributions. Computational Statistics & Data Analysis, 52(12):5186-5201
set.seed(3317)
x <- stats::rexp(7, rate = 0.5)
iqrMethod(x)
iqrMethod(x, skew = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.