Question about rmoutliers () function

20 次查看(过去 30 天)
Hello,
I wanted to remove outliers from my data when outliers defined as values greater than quartile 3+1.5IQR (the interquartile range) or smaller than quartile 1-1.5IQR.
Although the 'quartiles' method in rmoutliers function defined outliers as elements more than 1.5 interquartile ranges above the upper quartile or below the lower quartile, However, it can be edited using a threshold.
B = rmoutliers(A, 'quartiles', threshold);
For the threshold, in the documentation, it was said that: the detection factor replaces the number of interquartile ranges, which is 1.5 by default.
Now my question is how I can define outliers as values greater than quartile 3+1.5IQR (the interquartile range) or smaller than quartile 1-1.5IQR using this method and its threshold?
Thank you in advance

采纳的回答

Adam Danz
Adam Danz 2020-4-15
编辑:Adam Danz 2020-4-15
Outliers using the quartile method are usually identified as values greater than Q3+1.5*IQR or less than Q1-1.5*IQR where IQR is the interquartile range, Q1 and Q3 are the 25th and 75th percentiles.
What's the logic behind adding 3 to the upper range and adding 1 plus flipping the sign of the lower range? I don't think this is what you want to do.
Nevertheless, you can compute the outliers directly without using rmoutliers by using these simple steps.
1) Compute the interquartile range.
iqrng = iqr(data);
2) Compute Q1 and Q3
Q1Q3 = prctile(data, [25,75]);
3) Create logical array identifying outliers
isOut = data > Q1Q3(2) + 3+1.5*iqrng | data < Q1Q3(1) - 1-1.5*iqrng
% * ^^^ * ^^^^^ ???????
*I highly doubt this is how you want to define the outliers. I can't imagine how it would be useful.
To remove the outliers,
data(isOut) = [];
% or
data(isOut) = NaN;
  2 个评论
BN
BN 2020-4-15
Dear Adam Danz,
Thank you so much, It was really helpful. So if I want to define outliers as values greater than Q3+1.5*IQR or less than Q1-1.5*IQR is it enough to just use this?
B = rmoutliers(A, 'quartiles')
Thanks again
Adam Danz
Adam Danz 2020-4-15
To answer that, check out the "method" section of the rmoutliers document. It describes what the quartiles method is doing. This link should take you directly there. Q1 and Q3 are merely the 25th and 75th percentiles.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Preprocessing 的更多信息

标签

产品


版本

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by