Matlab IoSR统计箱线图-显示分位数的胡须错误?

Matlab IoSR统计箱线图-显示分位数的胡须错误?,matlab,boxplot,quantile,Matlab,Boxplot,Quantile,我在Matlab中有一些数据,我想用箱线图绘制。由于标准的boxplot不够可定制,我决定使用IoSR统计工具箱中的boxplot函数。我希望箱线图有显示0.025和0.975分位数的胡须,而方框本身显示四分位数范围和中间值(这是默认情况)。例如,典型的数据集是 p = [60.1 93 135.2 69 107.1 98.4 118.9 83.9 67 74.5 102.5 120.8 103.7 114.3 102.4 139.9 110.4 119.3 105.1 79.8 222.7 1

我在Matlab中有一些数据,我想用箱线图绘制。由于标准的boxplot不够可定制,我决定使用IoSR统计工具箱中的boxplot函数。我希望箱线图有显示0.025和0.975分位数的胡须,而方框本身显示四分位数范围和中间值(这是默认情况)。例如,典型的数据集是

p = [60.1 93 135.2 69 107.1 98.4 118.9 83.9 67 74.5 102.5 120.8 103.7 114.3 102.4 139.9 110.4 119.3 105.1 79.8 222.7 185.3 76.4 100.2 61.2 131.6 87.2 96 113.3 52.9 78.5 163.3 65.4 64.4];
我使用标准Matlab方法
prctile()
以及工具箱
quantile()
的分位数函数计算了0.025-和0.975-分位数,箱线图法应使用该分位数函数,并得到完全相同的结果:

prctile(p,2.5,2) -> ans = 55.4200
prctile(p,97.5,2) -> ans = 209.6100
iosr.statistics.quantile(p,0.025,2,'R-5') -> ans = 55.4200
iosr.statistics.quantile(p,0.975,2,'R-5') -> ans = 209.6100
然而,当我用下面的代码创建一个箱线图时,我得到的胡须在某种程度上太短了。上部晶须末端为185.3,而非209.61,下部晶须延伸至60.1,而非55.42。胡须现在正好在数据集的第二大/最小值处结束,而手动计算的分位数似乎利用某种插值方案来获得它们的值

我怎么会错了?如何使箱线图显示与手动计算的分位数相同的分位数

iosr.statistics.boxPlot(["data"],p'...
    ,'limit',[2.5, 97.5],'boxColor',[0.5 0.5 0.5],'lineColor','k'...
    ,'medianColor',[0.2 0.2 0.2],'method','R-5','showOutliers',false...
    ,'xspacing','equal')

事实上,
prctile
在计算准确的百分位值时起作用

同时,根据IoSR箱线图功能的说明:

胡须延伸到不被视为异常值的最极端数据

因此,选项
“limit”
并没有设置胡须直接结束的位置,而是设置标记异常值的位置

我去了,这里红线是你想要的分位数,蓝点是你的数据。我已经标记了最远的数据点,果然,这就是你的胡须的尽头


至于如何让它显示所需的百分位标记,我不确定,因为我没有工具箱,但我建议您查看他们添加百分位的选项;查看帮助或文档?(不确定文件在哪里)可能的相关选项包括:

%       addPrctiles         - Show additional percentiles using markers and
%                             labels. The property should be a vector of
%                             percentiles; each percentile will be plotted
%                             for each box. The property is empty by
%                             default.
...
%       addPrctilesLabels   - Specify labels for the additional
%                             percentiles. The property should be a cell
%                             array of strings. By defualt no label
%                             is shown.
%       addPrctilesMarkers  - Specify markers for the additional
%                             percentiles. The property should be a cell
%                             array of strings indicating the shape of each
%                             percentile; the markers will be repeated for
%                             each box. The default is '*'.
或者,您可以使用对象控制柄直接操纵胡须:

%       handles             - Structure containing handles to the various
%                             objects that constitute the plot. The
%                             fields/handles are:
%                                 'axes'            : the parent axes of 
%                                                     the box plot
%                                 'fig'             : the parent figure of
%                                                     the box plot
%                                 'addPrctiles'     : chart line objects
%                                                     for each additional
%                                                     percentile marker
%                                 'addPrctilesTxt'  : text objects for each
%                                                     additional percentile
%                                                     marker
...
%                                 'upperWhiskers'   : line objects for each
%                                                     upper whisker line
%                                 'lowerWhiskers'   : line objects for each
%                                                     lower whisker line
%                                 'upperWhiskerTips': line objects for each
%                                                     upper whisker tip
%                                 'lowerWhiskerTips': line objects for each
通过可能使用如下语法:

h = iosr.statistics.boxPlot(["data"],p',...)
h.upperWhiskers = % XY coordinates for desired line
h.lowerWhiskers = % XY coordinates for desired line

非常感谢你向我指出这一点!我认为胡须应该延伸到“极限”中给出的实际百分位数。要手动设置胡须,您确实可以只设置
h.handles.uppershabbers(1).YData=[prctile(p,97.5,2)h.handles.uppershabbers(1).YData(2)];h、 手柄.上须(1).YData=[prctile(p,97.5,2)prctile(p,97.5,2)]
(对于较低的胡须也是如此)
addPrctiles
选项不会改变胡须,但会为分位数添加额外的标记。我用它来确认手动移动胡须确实给出了正确的分位数。