绘制修正箱线图的具体方法见盛骤等,《概率论与数理统计》第四版,高等教育出版社P134-135. 下面给出图形和程序:红*表示异常值。
%%% 修正箱线图
x = [7,9,-1,4,10,8,12,10,15];%[1,2,3,3,4,4,5,6,6,7,7,9,9,10,12,12,13,15,18,23,55];
xs = sort(x);
n = length(x); p = [0.25,0.50,0.75]; xnp = zeros(size(p));
np = floor(n*p); r = n*p-np;
id = (r ==0); xnp(id) = (xs(np(id))+xs(np(id)+1))/2;
idn = (r~=0); xnp(idn) = xs(np(idn)+1);
iqs = xnp(3)-xnp(1);% 四分位数间距
xout = [xs(xs<(xnp(1)-1.5*iqs)),xs(xs>(xnp(3)+1.5*iqs))];% 异常值
xp = [xs(1),xnp,xs(n)];
xs(xs<(xnp(1)-1.5*iqs))=[];xs(xs>(xnp(3)+1.5*iqs))=[];%删除异常值
figure('color',[1,1,1]);plot([xs(1),xp(2)],[2,2],'b-','linewidth',1.5);hold on;
plot([xp(2),xp(4),xp(4),xp(2),xp(2)],[1,1,3,3,1],'b-','linewidth',1.5);%盒子
plot([xp(3),xp(3)],[1,3],'r-','linewidth',1.5); %均值M
plot([xp(4),xs(end)],[2,2],'b-','linewidth',1.5); %修正
plot(xout,2*ones(size(xout)),'r*')%异常值
axis([xp(1)-0.5,xp(5)+0.5,0,4])
text(xp(1)-0.5,0.5,'Min','interpreter','latex');
text(xp(2)-0.1,0.5,'$$Q_1$$','interpreter','latex');
text(xp(3)-0.1,0.5,'$$M$$','interpreter','latex');
text(xp(4)-0.1,0.5,'$$Q_3$$','interpreter','latex');
text(xp(5)-0.1,0.5,'Max','interpreter','latex');
plot([xp(1)-0.5,xp,xp(5)+0.5],0.82*ones(1,7),'k-','linewidth',1.5)
plot(xp,0.82*ones(1,5),'k.','markersize',15)
axis off
https://blog.sciencenet.cn/blog-292361-1100955.html
上一篇:
箱线图的绘制下一篇:
卡方分布的密度曲线