boxplot insists on removing outliers, is there an option to disable outlier removal?
70 次查看(过去 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!