Week 05 Class Activities File: week-05-24sep05.doc Directory (hp/compaq): C:\baileraj\Classes\Fall 2005\sta402\handouts Previously part of . . . File: week-04-05-19sep04.doc Directory: C:\Documents and Settings\John Bailer\My Documents\baileraj\Classes\Fall 2004\sta402\handouts Based on: C:\Documents and Settings\John Bailer\My Documents\baileraj\Classes\Fall 2003\sta402\handouts\day10- and-11-17sep03.doc Better Graphics in SAS via SAS/Graph Based on: C:\Documents and Settings\John Bailer\My Documents\baileraj\Classes\Fall 2003\sta402\handouts\week5- 23sep03.doc HIGH-RESOLUTION GRAPHICS AND FORMATS * Introduce concepts related to high-resolution graphs * PROC GCHART and PROC GPLOT for producing high-resolution graphs other SAS high resolution graphics procedures … GCHART (bar charts, pie charts, star charts) GPLOT (line plot, scatter plot, regression plot, high-low plots, bubble plots) G3D (3-dimensional surface plots) GCONTOUR, G3GRID (interpolate/smooth data) GMAP (block, choropleth, prism, surface) GSLIDE (create text slide)
35
Embed
Week 05 Class Activities€¦ · • corr sas/ets • arima • autoreg • entropy • expand • model • syslin • timeseries • ucm • varmax • x12 sas high-performance
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Week 05 Class Activities
File: week-05-24sep05.doc Directory (hp/compaq): C:\baileraj\Classes\Fall 2005\sta402\handouts Previously part of . . . File: week-04-05-19sep04.doc Directory: C:\Documents and Settings\John Bailer\My
Documents\baileraj\Classes\Fall 2004\sta402\handouts Based on: C:\Documents and Settings\John Bailer\My
/* example sas program that does simple linear regression */ /* defines library location for permanently storing a SAS data set */ libname class “\\Muserver2\USERS\B\BAILERAJ\public.www\classes\sta402\examples”; options ls=75; data class.manatee; input year nboats manatees; cards; 77 447 13 78 460 21 79 481 24
80 498 16 81 513 24 82 512 20 83 526 15 84 559 34 85 585 33 86 614 33 87 645 39 88 675 43 89 711 50 90 719 47 ; proc print data=class.manatee; title “Manatee mortality data”; run; /* Line printer scatterplot */ proc plot data=class.manatee; title2 “PROC PLOT: manatees killed plotted vs. # boats registered”; plot manatees*nboats; run; /* SAS has an experimental ODS procedures for Statistical Graphics Using ODS */
ODS GRAPHICS (experimental in SAS 9) From http://support.sas.com/rnd/base/topics/statgraph/ …
On an experimental basis in SAS 9.1, a number of SAS/STAT procedures support an extension to the Output Delivery System (ODS) to create statistical graphics as automatically as tables. This facility is referred to as ODS Statistical Graphics (or ODS Graphics for short).
With ODS Graphics, a procedure creates the graphs that are most commonly needed for a particular analysis. Using ODS Graphics eliminates the need to save numerical results in an output data set, manipulate them with a DATA step program, and display them with a graphics procedure.
http://support.sas.com/91doc/getDoc/statug.hlp/odsgraph_sect4.htm ODS Graph produces graphs similar in nature to what Minitab does. [Thanks to Dr. Schaefer for the links] SAS Procedures with ODS Graphics support
In many ways, creating graphics with ODS is analogous to creating tables with ODS. You use
• procedure options and defaults to determine which graphs are created • ODS destination statements (such as ODS HTML) to specify the output
destination for graphics
Additionally, you can use
• graph names in ODS SELECT and ODS EXCLUDE statements to select or exclude graphs from your output
• ODS styles to control the general appearance and consistency of all graphs • ODS templates to control the layout and details of individual graphs . A default
template is provided by SAS for each graph.
In SAS 9.1, the ODS destinations that support ODS Graphics include HTML, LATEX, PRINTER, and RTF.
ODS html; ODS graphics on; proc reg data=class.manatee plots(unpack); title2 “Stat graphics with ODS”; model manatees=nboats;
run; quit; ODS graphics off; ODS html close; Manatee mortality data Stat graphics with ODS The REG Procedure Model: MODEL1 Dependent Variable: manatees
Number of Observations Read 14
Number of Observations Used 14
Analysis of Variance
Source DF Sum of Squares
Mean Square
F Value Pr > F
Model 1 1711.97866 1711.97866 93.61 <.0001
Error 12 219.44991 18.28749
Corrected Total 13 1931.42857
Root MSE 4.27639 R-Square 0.8864
Dependent Mean 29.42857 Adj R-Sq 0.8769
Coeff Var 14.53141
Parameter Estimates
Variable DF ParameterEstimate
StandardError
t Value Pr > |t|
Intercept 1 -41.43044 7.41222 -5.59 0.0001
nboats 1 0.12486 0.01290 9.68 <.0001
Manatee mortality data Stat graphics with ODS The REG Procedure Model: MODEL1 Dependent Variable: manatees
/* Now look at what ODS graphics does with GLM */ data meat; input condition $ logcount @@; datalines; Plastic 7.66 Plastic 6.98 Plastic 7.80 Vacuum 5.26 Vacuum 5.44 Vacuum 5.80 Mixed 7.41 Mixed 7.33 Mixed 7.04 Co2 3.51 Co2 2.91 Co2 3.66 ; title bacteria growth under 4 packaging conditions; ods html; ods graphics on; proc glm data=meat order=data; title2 fitting the one-way anova model via GLM;
class condition; model logcount = condition; run; quit; ods graphics off; ods html close; bacteria growth under 4 packaging conditions fitting the one-way anova model via GLM The GLM Procedure
Class Level Information
Class Levels Values
condition 4 Plastic Vacuum Mixed Co2
Number of Observations Read 12
Number of Observations Used 12
bacteria growth under 4 packaging conditions fitting the one-way anova model via GLM The GLM Procedure Dependent Variable: logcount
Source DF Sum of Squares Mean Square F Value Pr > F
Model 3 32.87280000 10.95760000 94.58 <.0001
Error 8 0.92680000 0.11585000
Corrected Total 11 33.79960000
R-Square Coeff Var Root MSE logcount Mean
0.972580 5.768940 0.340367 5.900000
Source DF Type I SS Mean Square F Value Pr > F
condition 3 32.87280000 10.95760000 94.58 <.0001
Source DF Type III SS Mean Square F Value Pr > F
condition 3 32.87280000 10.95760000 94.58 <.0001
/* Now how about specifying graphs in SAS/Graph */ ODS RTF file= “\\Muserver2\USERS\B\BAILERAJ\public.www\classes\sta402\examples\week05-fig1A.rtf”; proc gplot data=class.manatee; title ‘Number of Manatees killed regressed on the number of boats registered in Florida’; plot manatees*nboats; run; ODS RTF CLOSE;
/* Let’s now add bells and whistles to this plot */ ODS RTF file= “\\Muserver2\USERS\B\BAILERAJ\public.www\classes\sta402\examples\week05-fig2.rtf”; proc gplot data=class.manatee; title h=1.5 'A plot of the number of manatee deaths versus the number of boats registered in Florida';
title2 h=1 '[Regression line with CI for mean along with smoothing spline fit displayed]'; symbol1 interpol=rlclm95 /* r=regression, l=linear (q,c also possible), clm=conf. int. mean (cli option), 95= conf. level */ value=diamond height=3 cv=red ci=blue co=green width=2; symbol2 interpol=SM55s /* smoothing spline (SM) that first sorts the x-axis data */ ; plot manatees*nboats manatees*nboats / hminor=1 overlay regeqn; /* adds regression eqn to bottom left of plot */ run; ODS RTF CLOSE;
/* The NITROFEN data set revisited … */ data class.nitrofen; infile 'M:\public.www\classes\sta402\SAS-programs\ch2-dat.txt' firstobs=16 expandtabs missover pad ; input @9 animal 2. @17 conc 3. @25 brood1 2. @33 brood2 2.
@41 brood3 2. @49 total 2.; /* creates character variable based on format */ * cbrood3 = put(brood3,totfmt.); label animal = animal ID number; label conc = Nitrofen concentration; label brood1 = number of young in first brood; label brood2 = number of young in 2nd brood; label brood3 = number of young in 3rd brood; *label total = total young produced in three broods; proc print data=class.nitrofen; run; * ODS RTF file='D:\baileraj\Classes\Fall 2003\sta402\SAS-programs\week5-fig2.rtf'; ODS RTF file= “\\Muserver2\USERS\B\BAILERAJ\public.www\classes\sta402\examples\week05-fig2.rtf”; /* SYMBOL = defines characteristics of plotted symbols */ proc gplot data=class.nitrofen; title h=1.5 'A plot of the number of C. dubia produced at different Nitrofen concentrations'; title2 h=1 '[mean +/- 2SD is plotted for each concentration]'; symbol1 interpol=STD2T /* plots +/- 2 SD from the mean at each conc */ /* T= add top and bottom to each 2 SD diff */ value=dot; plot total*conc / hminor=1 /* hminor=# tick markets before x values */ haxis=0 to 350 by 50; run; ODS RTF CLOSE;
goptions reset=global gunit=pct border cback=white colors=(black blue green red) ftext=swiss ftitle=swissb htitle=5 htext=3.5; title1 'Average Total Young by Nitrofen concentration'; axis1 label=('Total Young' j=c 'Error Bar Confidence Limits: 95%') minor=(number=1); axis2 label=('Nitrofen' j=r 'Concentration'); pattern1 color=cyan; proc gchart data=class.nitrofen; hbar conc / type=mean sumvar=total /* freqlabel='Number in Group' */ /* meanlabel='Mean Number Young' */ errorbar=bars clm=95 midpoints=(0 80 160 235 310) raxis=axis1 maxis=axis2 noframe coutline=black; run; ODS RTF CLOSE;
ODS RTF file= “\\Muserver2\USERS\B\BAILERAJ\public.www\classes\sta402\examples\week05-fig5.rtf”; * ODS RTF file='D:\baileraj\Classes\Fall 2003\sta402\SAS-programs\week5-fig5.rtf'; proc gchart data=class.nitrofen; title1 'Total Young by Nitrofen concentration'; star conc / sumvar=total; run; proc gchart data=class.nitrofen; title1 'Total Young by Nitrofen concentration';
pie conc / sumvar=total; run; ODS RTF CLOSE;
GREPLAY figures
/* now trying something fancy using templates and GREPLAY to get multiple figures on a page REF: http://www.units.muohio.edu/doc/sassystem/sasonlinedocv8/sasdoc/sashtml/gref/z61-ex.htm */
* libname class 'D:\baileraj\Classes\Fall 2003\sta402\data’; libname class “\\Muserver2\USERS\B\BAILERAJ\public.www\classes\sta402\examples”; /* libname class previously defined */ goptions reset=global gunit=pct border cback=white colors=(black blue green red) ftext=swissb htitle=6 htext=3; proc greplay tc=class.tempcat nofs; tdef newtemp des='Five panel template' 1/llx=0 10 lly= ulx=0 uly=50 urx=50 ury=50 lrx=50 lry=10 color=blue 2/llx=0 50 lly= ulx=0 uly=90 urx=50 ury=90 lrx=50 lry=50 color=red 3/llx=50 lly=50 ulx=50 uly=90 urx=100 ury=90 lrx=100 lry=50 color=green 4/llx=50 lly=10 ulx=50 uly=50 urx=100 ury=50 lrx=100 lry=10 color=cyan; template newtemp; list template; quit; proc gplot data=class.nitrofen gout=class.graph; title c=red 'Brood 1'; plot brood1*conc; run; title 'Brood 2'; plot brood2*conc; run; title 'Brood 3'; plot brood3*conc; run; title 'TOTAL'; plot total*conc; run; goptions hsize=0in vsize=0in;
proc gslide gout=class.graph; title 'PLOT of brood and total responses versus nitrofen concentration'; run; goptions display; ODS RTF file= “\\Muserver2\USERS\B\BAILERAJ\public.www\classes\sta402\examples\week05-fig6.rtf”; * ODS RTF file='D:\baileraj\Classes\Fall 2003\sta402\SAS-programs\week5-fi tg6.r f'; proc greplay igout=class.graph gout=class.excat tc=class.tempcat nofs template=newtemp; treplay 3:gplot2 /* plot bottom left - brood 3 */ 1:gplot /* top left - brood 1 */ 2:gplot1 /* top right - brood 2 */ 4:gplot3 ; /* bottom right - total */ quit; ODS RTF CLOSE;
G3D figures libname class “\\Muserver2\USERS\B\BAILERAJ\public.www\classes\sta402\examples”; * libname class 'D:\baileraj\Classes\Fall 2003\sta402\data’; data new; set class.nitrofen; retain conc; brood=1; young=brood1; output; brood=2; young=brood2; output; brood=3; young=brood3; output;
keep conc brood young; data new2; set new; jconc = conc + (10-20*ranuni(0)); jbrood = brood + (1-2*ranuni(0)); run; ODS RTF file= “\\Muserver2\USERS\B\BAILERAJ\public.www\classes\sta402\examples\week05-fig7.rtf”; * ODS RTF file='D:\baileraj\Classes\Fall 2003\sta402\SAS-programs\week5-fig7.rtf'; proc g3d data=new2; title h=1 ‘Scatter plot of # young by conc. and brood (jittered)’; scatter jconc*jbrood=young / xticknum=2 yticknum=2; run; quit; ODF RTF CLOSE;
proc means data=new; class conc brood; var young; output out=new3 mean=ymean; run; ODS RTF file= “\\Muserver2\USERS\B\BAILERAJ\public.www\classes\sta402\examples\week05-fig8.rtf”; * ODS RTF file='D:\baileraj\Classes\Fall 2003\sta402\SAS-programs\week5-fig8.rtf';
proc g3d data=new3; title h=1 'Surface plot of mean # young by conc. and brood'; plot conc*brood=ymean / xticknum=2 yticknum=2 tilt=80; run; quit; ODS RTF CLOSE;