SAS9作图.doc_第1页
SAS9作图.doc_第2页
SAS9作图.doc_第3页
SAS9作图.doc_第4页
SAS9作图.doc_第5页
已阅读5页,还剩13页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

SAS9.2 统计作图SAS92后,针对常规统计作图,开发了以下三个过程:SGPLOT, SGPANEL, SGSCATTER, 针对特殊情况,用户也可以自定义统计图(TEMPLETE过程),然后用过程SGRENDER过程进行调用。在所给出的三个常用统计过程中,SGPLOT的一些基本特性,在其他过程均相似,因此对该过程详述,其他的过程只要注意其特点就可以了。1 PROC SGPLOTSGPLOT在同一作图单元上进行作图,可以画16种图形,分为五类:(一)basic X Y plots: scatter x=var y=var/options; -散点图 series x=var y=var/options; -序列图,事先要按x指定变量从小到大排序 step x=var y=var/options; -阶梯图 needle x=var y=var/options; -火柴棒图 vector x=var y=var/options; -方向图 (二)band plots: (带状图) band x=var upper=var lower=var/options; -带状图(变量值,最小值,最大值)(三)fit and confidence plots: (拟合与置信区间)reg x=var y=var /options; -回归线图loess x=var y=var/options; -局部线性回归图pbspline x=var y=var/options; -惩罚样条回归图ellipse x=var y=var/options; -椭园图注:以上三种类型图均可重叠画在一幅图上(四)distribution graphs for continuous DATA: (连续)hbox|vbox response-var/options; -水平|垂直盒形图histogram response-var/options; - 直方图density response-var/options; -密度函数图注:直方图与密度函数图形可以画在一起;(五)distribution graphs for categorical DATA:(离散)hbar|vbar category-var/options; -水平|垂直柱状图hline|vline category-var/options; -水平|垂直 线图(与上图表示相似,柱子用线表示)dot category-var/options; -点图表1,可以重叠的作图语句,及其相关选项的关系表2:SGPLOT的作图语句及其常用选项 表3 图形辅助语句及其选项如参考线的设置,x,y轴的设置,图形上插入文字等表4:作图语句中关于填充,线的特征,数据点标签等的设置如填充的颜色,线的特征(线型,线的粗细,线的颜色),数据标签(颜色,大小,符号)注:MARKERATTRS的一些常用符号:LINEATTRS的一些常用符号:例子:/*例1*/proc sgplot data=sashelp.class;scatter x=height y=weight / group=sex;run;/*例2*/proc sgplot data=sashelp.stocks(where=(date = 01jan2000d and stock = IBM);title Stock Trend;*Create the series plots;series x=date y=close;series x=date y=low;series x=date y=high;run;/*例3*/proc sgplot data=sashelp.class;reg x=height y=weight / CLM CLI;run;/*例4*/proc sgplot data=sashelp.iris;title Iris Petal Dimensions;scatter x=petallength y=petalwidth;ellipse x=petallength y=petalwidth;keylegend / location=inside position=bottomright;run;/*例5*/proc sgplot data=sashelp.classfit;title Fit and Confidence Band from Precomputed Data;band x=height lower=lower upper=upper /legendlabel=95% CLI name=band1;band x=height lower=lowermean upper=uppermean /fillattrs=GraphConfidence2legendlabel=95% CLM name=band2;scatter x=height y=weight;series x=height y=predict / lineattrs=GraphPredictionlegendlabel=Predicted Fit name=series;keylegend series band1 band2 / location=inside position=bottomright;run;/*例6*/proc sgplot data=sashelp.class(where=(age= 01jan2000dand date = 01jan2001d and stock = IBM);title Stock Volume vs. Close;vbar date / response=volume;vline date / response=close y2axis;run;2 PROC SGPANEL该过程可以分多个作图区域同时进行作图,其他的作图语句与sgplot一样。PROC SGPANEL;PANELBY category-var/options;-据此分类变量将作图区域分组;选项确定分组布局。作图语句(与sgplot过程相同,少一个ellipse作图语句);其他语句;run;PANELBY category-var/options;中的选项: columns=n -分n列layout=lattice|panel|columnlattice|rowlatticerows=n -分n行spacing=n-定义分组间的距离(单位为pixels)作图类型:Basic plots scatter, series, step, band, needle plots, and vector plotsFit and confidence plots loess, regression, and penalized B-spline curvesDistribution plots box plots, histograms, normal density curves, and kernel density estimatesCategorization plots dot plots, bar charts, and line plots例子:/*example 1*/proc sgpanel data=sashelp.heart noautolegend;title Cholesterol Distribution in Heart Study;*Specify the classification variable for the panel.;panelby sex;histogram cholesterol;density cholesterol;run;/*example 2*/proc sgpanel data=sashelp.iris;title Scatter plot for Fisher iris data;panelby species / columns=3;reg x=sepallength y=sepalwidth / cli clm;run;/*example 3*/proc sgpanel data=sashelp.prdsale;title Yearly Sales by Product;panelby year / novarname columns=1;hbar product / response=actual;run;3 PROC SGSCATTER主要作散点图,也可加其他选项作其他类型的图。作图布局:三种方式来设置PLOT (变量组1)*(变量组2)/options; 通过变量的交叉进行分组,分组各自有自己的独立坐标。COMPARE (变量组1)*(变量组2)/options; 为比较而设置,x轴,y轴均可以相互比较;MATRIX 变量组/options; 矩阵方式给出散点图,对角线上可以画直方图,密度图等作图选项,则可以作以下类型的图形:Basic plots scatter, series, step, band, needle plots, and vector plotsFit and confidence plots loess, regression, and penalized B-spline curvesDistribution plots box plots, histograms, normal density curves, and kernel density estimatesCategorization plots dot plots, bar charts, and line plots例子:例1:用矩阵语句形成画图布局,并用group选项将数据分组proc sgscatter data=sashelp.iris;title Scatterplot Matrix for Iris Data;matrix sepallength petallength sepalwidth petalwidth/ group=species;run;例2:用PLOT语句设置作图布局,用pbspline选项叠加罚样条回归proc sgscatter data=sashelp.iris(where=(species=Virginica);title Multi-Celled Spline Curve for Species Virginica;plot (sepallength sepalwidth)*(petallength petalwidth)/ pbspline;run;例3:用compare语句设置作图布局用于比较,group选项将数据分组显示proc sgscatter data=sashelp.iris;title Iris Data: Length and Width;compare x=(sepallength petallength) y=(sepalwidth petalwidth)/ group=species;run;注:x,y轴均可以进行比较。例4:注意选项的设置proc sgscatter data=sashelp.iris(where=(species=Versicolor);title Versicolor Length and Width;compare y=(sepalwidth petalwidth) x=(sepallength petallength)/ reg ellipse=(type=mean) spacing=4;run;4 图形文件的设置/*图形名,图形类型,图形大小*/ODS GRAPHICS ON / RESET IMAGENAME = Final IMAGEFMT =JPEG HEIGHT = 2in WIDTH = 3in; /*注意:RESET重新设置图形格式变为缺省设置 IMAGENAME设置图形文件名 IMAGEFMT设置图形文件的类型(PNG,BMP,GIF,JPEG,JPG,PDF,PS,TIFF等) HEIGHT,WIDTH-设置图形的长,高(单位为CM, IN, MM, PT, or PX.,缺省为640*480pixels*/*图形存放位置的设置,图形存放的风格*/ODS LISTING GPATH = E:dcai2007_lecturestat ;/*GPATH设置存放图形文件的位置*/*ODS LISTING STYLE=joural;注:通过STYLE=来设置不同风格,满足不同杂志的要求。* Histograms;PROC SGPLOT DATA = sashelp.class;HISTOGRAM weight;TITLE Mens weight;RUN;ODS GRAPHICS OFF;/*作椭园图*/PROC SGPLOT DATA = sashelp.class;scatter x=height y=weight;ellipse x=height y=weight/alpha=0.3182;ellipse x=height y=weight/alpha=0.05;ellipse x=height y=weight/alpha=0.0027;TITLE Mens weight;RUN;注:对生成的图形要进行编辑,需要下载SAS的图形编辑器。注:ODS 统计图形的展现形式是由GTL语言编写的程序规定的。定义了layouts(图形布局): lattices, overlaystypes(作图类型): scatter plot,histogramstitles(标题)footnotes(脚注)insets(图形里插入符号和文字)colors(颜色)symbols(符号)lines(线的属性):线类,线宽,颜色other elements:坐标轴的设置,背景,前景,等/*回归分析*/*reg step 1 建立回归方程*/data regdata;input x1-x4 y;datalines;7 26 6 60 78.5 1 29 15 52 74.3 11 56 8 20 104.3 11 31 8 47 87.6 7 52 6 33 95.9 11 55 9 22 109.2 3 71 17 6 102.7 1 31 22 44 72.5 2 54 18 22 93.1 21 47 4 26 115.9 1 40 23 34 83.8 11 66 9 12 113.3 10 68

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论