boxplot insists on removing outliers, is there an option to disable outlier removal?
조회 수: 69 (최근 30일)
이전 댓글 표시
I want to completely disable outlier removal. My data is not normally distributed, so I need all the points to affect the mean.
댓글 수: 0
답변 (3개)
Tom Lane
2012년 11월 30일
Can you explain more about what you want? Ordinarily the boxplot doesn't remove outliers, but instead shows them as separate markers on the plot. Is that what you want to prevent? Here are two invocations of boxplot, one of which includes the outlier in the box-like part rather than as a separate marker:
boxplot([1:10,100]')
boxplot([1:10,100]','whisker',1000)
The line across the center of the box is at the median, not the mean, so the outlier doesn't really affect its value directly.
댓글 수: 0
Maziyar
2017년 4월 17일
If you just want not to see the outliers use the following and make them invisible.
h = boxplot(NC,'positions',0.25,'Colors','k','Notch','off','OutlierSize',7,'Symbol','k+') set(h(7,:),'Visible','off');
Otherwise, press ctrl+D on the "boxplot" function in MATLAB. Make a copy of the function and save it with a different name. Then manually adjust the algorithm not to compute any outlier. For doing this you can go to line ~ 2195 where you see the following piece of code (note I am using 2015b and it may be in a different line in your version).
% Calculate whisker endpoints. maxw = p75+whisker*(p75-p25); if ~isfinite(maxw) maxw = inf; end minw = p25-whisker*(p75-p25); if ~isfinite(minw) minw = -inf; end
whi = find(xSorted1group<=maxw,1,'last'); if isempty(whi) whi = lastind; end wlo = find(xSorted1group>=minw,1,'first'); if isempty(wlo) wlo = firstind; end
Right after this section add the following 2 lines: wlo = firstind; whi = lastind;
This way the algorithm will set the min and max value for outlier detection equal to min and max value of your data, and hence no outlier will be detected.
Hope it helps!
댓글 수: 1
Mathias Juul Sørensen
2017년 5월 8일
Hi,
I have the same problem, and the code fix provided in your answer does not work entirely for me. I still want the outliers to be represented as whiskers. This is the error I recieve:
Undefined function 'boxrenderer' for input arguments of type 'matlab.graphics.primitive.Group'.
Error in MATboxplot>renderBoxes (line 3182)
hwhisker = ...
Error in MATboxplot (line 401)
[hdata,houtliers] = renderBoxes(axhg,gPos,maxGuaranteedGap,orientation,...
Best Regards Mathias.
mingqi zhao
2021년 3월 2일
Just set whisker to inf. That will work.
for example:
boxplot(mydata, 'whisker', inf);
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!