SAS9作图

更新时间:2024-05-10 04:15:01 阅读量: 综合文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

SAS9.2 统计作图

SAS92后,针对常规统计作图,开发了以下三个过程:SGPLOT, SGPANEL, SGSCATTER, 针对特殊情况,用户也可以自定义统计图(TEMPLETE过程),然后用过程SGRENDER过程进行调用。

在所给出的三个常用统计过程中,SGPLOT的一些基本特性,在其他过程均相似,因此对该过程详述,其他的过程只要注意其特点就可以了。

1 PROC SGPLOT

SGPLOT在同一作图单元上进行作图,可以画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 >= \ and stock = \));

title \; *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 \; scatter x=petallength y=petalwidth; ellipse x=petallength y=petalwidth;

keylegend / location=inside position=bottomright; run;

/*例5*/

proc sgplot data=sashelp.classfit;

title \;

band x=height lower=lower upper=upper / legendlabel=\ name=\;

band x=height lower=lowermean upper=uppermean / fillattrs=GraphConfidence2

legendlabel=\ name=\; scatter x=height y=weight;

series x=height y=predict / lineattrs=GraphPrediction legendlabel=\ name=\;

keylegend \ \ \ / location=inside position=bottomright; run;

/*例6*/

proc sgplot data=sashelp.class(where=(age<16));

dot age / response=height stat=mean limitstat=stddev numstd=1; run;

/*例7*/

proc sgplot data=sashelp.heart; title \; histogram cholesterol; density cholesterol;

density cholesterol / type=kernel;

keylegend / location=inside position=topright; run;

/*例8*/

proc sgplot data=sashelp.heart;

title \; hbox cholesterol / category=weight_status; run;

/*例9*/

proc sgplot data=sashelp.stocks (where=(date >= \ and date <= \and stock = \)); title \; vbar date / response=volume;

vline date / response=close y2axis; run;

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 \; RUN;

注:对生成的图形要进行编辑,需要下载SAS的图形编辑器。

注:ODS 统计图形的展现形式是由GTL语言编写的程序规定的。定义了 layouts(图形布局): lattices, overlays

types(作图类型): scatter plot,histograms titles(标题) 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 8 12 109.4 run;

proc reg data=regdata; model y=x1-x4; run;

/*识别多重共线性*/

proc reg data=regdata; model y=x1-x4/ vif collin; run;

/*⑶多重共线性的处理 ①选择变量法*/

/*逐步回归*/

proc reg data=regdata;

model y=x1-x4/selection=stepwise; run;

/*全子集法*/

proc reg data=regdata;

model y=x1-x4/selection=rsquare adjrsq cp aic bic rmse; run;

/*岭嵴回归*/

proc reg data=regdata outest=rghald outvif graphics corr; model y=x1-x4/ridge=0 to 1 by 0.1 2 3 4 5 6 ; plot/ridgeplot; run;

proc print data=rghald; run;

/*主成分回归*/

proc princomp data=regdata; var x1-x4; run;

proc reg data=regdata outest=pchald outvif; model y=x1-x4/pcomit=1,2 ; run;

proc print data=pchald;

run;

/*回归诊断*/

proc reg data=regdata graphics; model y=x1-x2/r ; plot student.*p.; run;

本文来源:https://www.bwwdw.com/article/lnrg.html

Top