Matlab绘制相邻值的方框图



我发现,根据箱图的工作方式计算索引以指定数据集的异常值并不能得到相同的结果。请在下面找到一个示例,我在其中创建一些数据,从方框图中提取值(如图窗口中的数据提示所示(,并将它们与我计算的值进行比较。

虽然中位数和四分位数匹配,但上下相邻值不匹配。根据"晶须"下的Matlab帮助,相邻值计算为q3 + w*(q3-q1),其中q3q1是分位数,w是指定的晶须长度。

我算错了还是有其他错误?我希望能够解释这个错误。

结果表截图(请注意,结果因随机数据而异(

%Boxplot test
% create random, normally distributed dataset
data = round(randn(1000,1)*10,2);
figure(10)
clf
boxplot(data,'Whisker',1.5)
clear stats tmp
% read data from boxplot, same values as can be seen in datatips in the figure window
h = findobj(gcf,'tag','Median');
tmp = get(h,'YData');
stats(1,1) = tmp(1);
h = findobj(gcf,'tag','Box');
tmp = get(h,'YData');
stats(1,2) = tmp(1);
stats(1,3) = tmp(2);
h = findobj(gcf,'tag','Upper Adjacent Value');
tmp = get(h,'YData');
stats(1,4) = tmp(1);
h = findobj(gcf,'tag','Lower Adjacent Value');
tmp = get(h,'YData');
stats(1,5) = tmp(1);
% calculated data
stats(2,1) = median(data);
stats(2,2) = quantile(data,0.25);
stats(2,3) = quantile(data,0.75);
range = stats(2,3) - stats(2,2);
stats(2,4) = stats(2,3) + 1.5*range;
stats(2,5) = stats(2,2) - 1.5*range;
% error calculation
for k=1:size(stats,2)
stats(3,k) = stats(2,k)-stats(1,k);
end %for k
% convert results to table with labels
T = array2table(stats,'VariableNames',{'Median','P25','P75','Upper','Lower'}, ...
'RowNames',{'Boxplot','Calculation','Error'});

虽然边界的计算(例如q3 = q3 + w*(q3-q1)(是正确的,但它不会显示在方框图中。实际显示和标记为上/下相邻值的是上述边界内的值的最小值和最大值。

关于导致问题的初始任务:对于应用与箱图中相同的异常值过滤,可以使用计算的边界。

最新更新