现在的位置: 首页 > 综合 > 正文

箱线图

2018年10月22日 ⁄ 综合 ⁄ 共 2955字 ⁄ 字号 评论关闭

箱线图可以直观表现数据分布的特征,它在描绘属性数据上有着自己独特的优势,比如可以数据集中、分散、偏态、异常等情况。箱线图与描述统计中的最大、最小、分位数等密切有着密切的关系,箱线图正是利用这些统计量来呈现数据的离散集中情况。

网络上将箱线图的绘制划为5个步骤:

       (1)画数轴

  (2)画矩形盒 两端边的位置分别对应数据的上下四分位数矩形盒:端边的位置分别对应数据的上下四分位数(Q1和Q3)。在矩形盒内部中位数位置画一条线段为中位线。

  (3)在Q3+1.5IQR(四分位距)和Q1-1.5IQR处画两条与中位线一样的线段,这两条线段为异常值截断点,称其为内限;在Q3+3IQR和Q1-3IQR处画两条线段,称其为外限。处于内限以外位置的点表示的数据都是异常值,其中在内限与外限之间的异常值为温和的异常值(mild outliers),在外限以外的为极端的异常值(li)的异常值extreme outliers。

  (4)从矩形盒两端边向外各画一条线段直到不是异常值的最远点 表示该批数据正常值的分布区间点,示该批数据正常值的分布区间。

  (5)用“〇”标出温和的异常值,用“*”标出极端的异常值。

箱线图作法:

1.sas/qc 模块的SHEWHART 语句同样可以制作箱线图,其语法为:

BOXCHART processes * subgroup-variable < (block-variables) > <=symbol-variable  / =‘character’ > / < options > ;

文档有例:

data Oilsum;
   input Day KWattsL KWatts1 KWattsX KWattsM
             KWatts3 KWattsH KWattsR KWattsN;
   informat Day date7. ;
   format Day date5. ;
   label Day    ='Date of Measurement'
         KWattsL='Minimum Power Output'
         KWatts1='25th Percentile'
         KWattsX='Average Power Output'
         KWattsM='Median Power Output'
         KWatts3='75th Percentile'
         KWattsH='Maximum Power Output'
         KWattsR='Range of Power Output'
         KWattsN='Subgroup Sample Size';
   datalines;
 04JUL94 3180 3340.0 3487.40 3490.0 3610.0 4050 870 20
 05JUL94 3179 3333.5 3471.65 3419.5 3605.0 3849 670 20
 06JUL94 3304 3376.0 3488.30 3456.5 3604.5 3781 477 20
 07JUL94 3045 3390.5 3434.20 3447.0 3550.0 3629 584 20
 08JUL94 2968 3321.0 3475.80 3487.0 3611.5 3916 948 20
 09JUL94 3047 3425.5 3518.10 3576.0 3615.0 3881 834 20
 10JUL94 3002 3368.5 3492.65 3495.5 3621.5 3787 785 20
 11JUL94 3196 3346.0 3496.40 3473.5 3592.5 3994 798 20
 12JUL94 3115 3188.5 3398.50 3426.0 3568.5 3731 616 20
 13JUL94 3263 3340.0 3456.05 3444.0 3505.5 4040 777 20
 14JUL94 3215 3336.0 3493.60 3441.5 3616.0 3872 657 20
 15JUL94 3182 3409.5 3563.30 3561.0 3719.5 3850 668 20
 16JUL94 3212 3378.0 3519.05 3515.0 3682.5 3769 557 20
 17JUL94 3077 3329.0 3474.20 3501.5 3599.5 3812 735 20
 18JUL94 3061 3315.5 3443.60 3435.0 3614.5 3815 754 20
 19JUL94 3288 3426.5 3586.35 3546.0 3762.5 3877 589 20
 20JUL94 3114 3373.0 3486.45 3474.5 3635.5 3928 814 20
 21JUL94 3167 3400.5 3492.90 3488.0 3582.5 3801 634 20
 22JUL94 3056 3322.0 3432.80 3460.0 3561.0 3800 744 20
 23JUL94 3145 3308.5 3496.90 3495.0 3652.0 3917 772 20
 ;

   title 'Summary Data Set for Power Outputs';
   proc print data=Oilsum noobs;
   run;

   options nogstyle;
   goptions ftext=swiss;
   symbol v = plus color = salmon h = .8;
   title 'Box Chart for Power Output';
   proc shewhart history=Oilsum;
      boxchart KWatts*Day / cinfill  = ligr
                            cboxfill = ywh
                            cboxes   = dagr
                            cframe   = vligb
                            ranges;
   run;

 

 boxchart结果:

2.proc sgplot;*proc plot;

proc sgplot data = sashelp.class  ;
   vbox weight/category=sex ;
run;
quit;

3.proc boxplot;

options nogstyle;
   goptions ftext=swiss;
   symbol v = plus color = salmon h = .8;
   title 'Box Chart for Power Output';
   proc boxplot history=Oilsum;
      plot KWatts*Day /
                            cboxfill = ywh
                            cboxes   = dagr
                            cframe   = vligb;
run;

4.proc univariate

proc sort data=sashelp.class out=class;by sex ;run;

ods select SSPlots;

proc univariate data=sashelp.class;

     var weight;

     by sex;

run;quit;

 

 

抱歉!评论已关闭.