boxplot insists on removing outliers, is there an option to disable outlier removal?

110 views (last 30 days)
I want to completely disable outlier removal. My data is not normally distributed, so I need all the points to affect the mean.

Answers (3)

Tom Lane
Tom Lane on 30 Nov 2012
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.

Maziyar
Maziyar on 17 Apr 2017
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 Comment
Mathias Juul Sørensen
Mathias Juul Sørensen on 8 May 2017
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.

Sign in to comment.


mingqi zhao
mingqi zhao on 2 Mar 2021
Just set whisker to inf. That will work.
for example:
boxplot(mydata, 'whisker', inf);

Tags

Community Treasure Hunt

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

Start Hunting!