Examples


This section provides a series of examples which illustrate various tasks that can be performed with ODS Graphics. The examples are presented in increasing order of task complexity and should be read sequentially.

Example 15.1. Selecting and Excluding Graphs

This example illustrates how to select and exclude ODS graphs from your output.

The 'Getting Started' example on page 321 uses the REG procedure to produce a panel, shown in Figure 15.1, which consists of eight different diagnostics plots. The panel is produced by default. To display the plots individually, specify the PLOTS(UNPACK) option in the PROC REG statement as follows :

  ods trace on;   ods html;   ods graphics on;   proc reg data = Class plots(unpack);   model Weight = Height;   run;   quit;   ods graphics off;   ods html close;   ods trace off;  

The ODS TRACE ON statement requests a record of the output objects created by ODS, which is displayed in the SAS log as shown in Output 15.1.1.

Output 15.1.1: Partial ODS Trace Record in SAS Log
start example
  Output Added:   -------------   Name:       NObs   Label:      Number of Observations   Template:   Stat.Reg.NObs   Path:       Reg.MODEL1.Fit.Weight.NObs   -------------   .   .   .   -------------   Name:       ParameterEstimates   Label:      Parameter Estimates   Template:   Stat.REG.ParameterEstimates   Path:       Reg.MODEL1.Fit.Weight.ParameterEstimates   -------------   WARNING: Statistical graphics displays created with ODS are experimental in   this release.   Output Added:   -------------   Name:       ResidualHistogram   Label:      Residual Histogram   Template:   Stat.REG.Graphics.ResidualHistogram   Path:       Reg.MODEL1.ObswiseStats.Weight.DiagnosticPlots.ResidualHistogram   -------------   .   .   .   Output Added:   -------------   Name:       CooksD   Label:      Cook's D   Template:   Stat.REG.Graphics.CooksD   Path:       Reg.MODEL1.ObswiseStats.Weight.DiagnosticPlots.CooksD   -------------   .   .   .   Output Added:   -------------   Name:       Fit   Label:      Fit Plot   Template:   Stat.REG.Graphics.Fit   Path:       Reg.MODEL1.ObswiseStats.Weight.DiagnosticPlots.Fit   -------------  
end example
 

You can use the ODS SELECT statement to restrict your output to a particular subset of ODS tables or graphs. The following statements restrict the output to the Cook's D plot, which is shown in Output 15.1.2.

  ods html;   ods graphics on;   ods select CooksD;   proc reg data = Class plots(unpack);   model Weight = Height;   run;   quit;   ods graphics off;   ods html close;  
Output 15.1.2: Cook's D Plot
start example
  click to expand  
end example
 

Conversely, you can use the ODS EXCLUDE statement to display all the output with the exception of a particular subset of tables or graphs. For example, to exclude the fit plot from the output you specify

  ods exclude Fit;  

See the 'Selecting and Excluding Graphs' section on page 330 for further information.

A sample program named odsgr01.sas is available for this example in the SAS Sample Library for SAS/STAT software.

Example 15.2. Creating Graphs with Tool Tips in HTML

This example demonstrates how to request graphics in HTML with tool tip displays, which appear when you move a mouse over certain features of the graph. When you specify the HTML destination and the IMAGEFMT=STATICMAP option in the ODS GRAPHICS statement, then the HTML file output file is generated with an image map of coordinates for tool tips. The individual graphs are saved as GIF files. Example 46.2 and Example 46.8 of Chapter 46, 'The MIXED Procedure' analyze a data set with repeated growth measurements for twenty-seven children.

  data pr;   input Person Gender $ y1 y2 y3 y4 @@;   y=y1; Age=8;  output;   y=y2; Age=10; output;   y=y3; Age=12; output;   y=y4; Age=14; output;   drop y1-y4;   datalines;   1  F  21.0  20.0  21.5  23.0    2  F  21.0  21.5  24.0  25.5   3  F  20.5  24.0  24.5  26.0    4  F  23.5  24.5  25.0  26.5   5  F  21.5  23.0  22.5  23.5    6  F  20.0  21.0  21.0  22.5   7  F  21.5  22.5  23.0  25.0    8  F  23.0  23.0  23.5  24.0   9  F  20.0  21.0  22.0  21.5   10  F  16.5  19.0  19.0  19.5   11  F  24.5  25.0  28.0  28.0   12  M  26.0  25.0  29.0  31.0   13  M  21.5  22.5  23.0  26.5   14  M  23.0  22.5  24.0  27.5   15  M  25.5  27.5  26.5  27.0   16  M  20.0  23.5  22.5  26.0   17  M  24.5  25.5  27.0  28.5   18  M  22.0  22.0  24.5  26.5   19  M  24.0  21.5  24.5  25.5   20  M  23.0  20.5  31.0  26.0   21  M  27.5  28.0  31.0  31.5   22  M  23.0  23.0  23.5  25.0   23  M  21.5  23.5  24.0  28.0   24  M  17.0  24.5  26.0  29.5   25  M  22.5  25.5  25.5  26.0   26  M  23.0  24.5  26.0  30.0   27  M  22.0  21.5  23.5 25.0   ;  

The following statements fit a mixed model with random intercepts and slopes for each child. The BOXPLOT option in the PROC MIXED statement requests box plots of observed values and residuals for each classification main effect in the model ( Gender and Person ).

  ods html;   ods graphics on / imagefmt = staticmap;   proc mixed data=pr method=ml boxplot(npanel=15);   class Person Gender;   model y = Gender Age Gender*Age;   random intercept Age / type=un subject=Person;   run;   ods graphics off;   ods html close;  

The NPANEL=15 suboption limits the number of box plots per graph to at most fifteen. For example, the conditional residuals of the Person effect are displayed in two graphs, consisting of 15 and 12 box plots, respectively. Output 15.2.1 displays the second of these two graphs that are included in the HTML output.

Output 15.2.1: Box Plot with Tool Tips
start example
  click to expand  
end example
 

Moving the mouse over a box plot displays a tool tip with summary statistics for the corresponding person.

Note: Graphics with tool tips are only supported for the HTML destination.

A sample program named odsgr03.sas is available for this example in the SAS Sample Library for SAS/STAT software.

Example 15.3. Creating Graphs for a Presentation

The RTF destination provides the easiest way to create ODS graphs for inclusion in a document or presentation. You can specify the ODS RTF statement to create a file that is easily imported into a word processor (such as Microsoft Word or WordPerfect) or a presentation (such as Microsoft PowerPoint).

The following statements simulate 100 observations from the model y = log( x ) + w , where x = 1 ,..., 100 and w has a normal distribution with mean 0 and variance 1.

  data one;   do x = 1 to 100;   y = log(x) + rannor(12345);   output;   end;   run;  

The following statements request a loess fit and save the output in the file loess.rtf .

  ods rtf file = "loess.rtf";   ods graphics on;   proc loess data = one;   model y = x / clm residual;   run;   ods graphics off;   ods rtf close;  

The output file includes various tables and the following plots: a plot of selection criterion versus smoothing parameter, a fit plot with 95% confidence bands, a plot of residual by regressors, and a diagnostics panel. The fit plot is shown in Output 15.3.1.

Output 15.3.1: Fit Plot
start example
  click to expand  
end example
 

If you are running SAS in the Windows operating system, it is easy to include your graphs in a Microsoft PowerPoint presentation when you generate RTF output. You can open the RTF file in Microsoft Word and simply copy and paste the graphs into Microsoft PowerPoint. In general, RTF output is convenient for exchange of graphical results between Windows applications through the clipboard.

Alternatively, if you request ODS Graphics using the HTML destination, then your individual graphs are created as GIF files by default. You can insert the GIF files into a Microsoft PowerPoint presentation. See 'Naming Graphics Image Files' and 'Saving Graphics Image Files' for information on how the image files are named and saved.

A sample program named odsgr04.sas is available for this example in the SAS Sample Library for SAS/STAT software.

Example 15.4. Creating Graphs in PostScript Files

This example illustrates how to create individual graphs in PostScript files, which is particularly useful when you want to include them in a LATEX document.

The 'Getting Started' section of Chapter 62, 'The ROBUSTREG Procedure,' creates the following data set to illustrate the use of the ROBUSTREG procedure for robust regression.

  data stack;   input  x1 x2 x3 y @@;   datalines;   80  27  89  42    80  27  88  37    75  25  90  37   62  24  87  28    62  22  87  18    62  23  87  18   62  24  93  19    62  24  93  20    58  23  87  15   58  18  80  14    58  18  89  14    58  17  88  13   58  18  82  11    58  19  93  12    50  18  89   8   50  18  86   7    50  19  72   8    50  19  79   8   50  20  80   9    56  20  82  15    70  20  91  15   ;  

The following statements specify a LATEX destination [*] with the 'Journal' style, and request a histogram of standardized robust residuals computed with the ROBUSTREG procedure.

  ods latex style = Journal;   ods graphics on;   proc robustreg plot=reshistogram data=stack;   model y = x1 x2 x3;   run;   ods graphics off;   ods latex close;  

The 'Journal' style displays gray-scale graphs that are suitable for a journal. When you specify the ODS LATEX destination, ODS creates a PostScript file for each individual graph in addition to a LATEX source file that includes the tabular output and references to the PostScript files. By default these files are saved in the SAS current folder. If you run this example at the beginning of your SAS session, the histogram shown in Output 15.4.1 is saved by default in a file named ResidualHistogram0.ps . See page 335 for details about how graphics image files are named.

Output 15.4.1: Histogram Using Journal Style
start example
  click to expand  
end example
 

If you are writing a paper, you can include the graphs in your own LATEX source file by referencing the names of the individual PostScript graphics files. In this situation, you may not find necessary to use the LATEX source file created by SAS.

If you specify PATH= and GPATH= options in the ODS LATEX statement, your tabular output is saved as a LATEX source file in the directory specified with the PATH= option, and your graphs are saved as PostScript files in the directory specified with the GPATH= option. This is illustrated by the following statements:

  ods latex path  = "C:\temp"   gpath = "C:\temp\ps" (url="ps/")   style = Journal;   ods graphics on;   ...SAS statements...   ods graphics off;   ods latex close;  

The URL= suboption is specified in the GPATH= option to create relative paths for graphs referenced in the LATEX source file created by SAS. See the 'HTML Destination' section on page 336 for further information.

A sample program named odsgr05.sas is available for this example in the SAS Sample Library for SAS/STAT software.

Example 15.5. Creating Graphs in Multiple Destinations

This example illustrates how to send your output to more than one destination with a single execution of your SAS statements.

For instance, to create both HTML and RTF output, you can specify the ODS HTML and the ODS RTF statements before your procedure statements.

  ods html;   ods rtf;    ...SAS statements...    ods _all_ close;  

The ODS _ALL_ CLOSE statement closes all open destinations.

You can also specify multiple instances of the same destination. For example, using the data in the 'Using the ODS GRAPHICS Statement and Procedure Options' section on page 324, the following statements save the contour plot to the file con- tour.pdf and the surface plot to the file surface.pdf .

  ods pdf file = "contour.pdf";   ods pdf select Contour;   ods pdf(id=srf) file = "surface.pdf";   ods pdf(id=srf) select SurfacePlot;   ods graphics on;   proc kde data = bivnormal;   bivar x y / plots = contour surface;   run;   ods graphics off;   ods _all_ close;  

The ID= option assigns the name srf to the second instance of the PDF destination. Without the ID= option, the second ODS PDF statement would close the destination that was opened by the previous ODS PDF statement, and it would open a new instance of the PDF destination. In that case, the file contour.pdf would contain no output. For more information, refer to the Example 1 of the ODS PDF statement in the 'Dictionary of ODS Language Statements' ( SAS Output Delivery System User 's Guide ).

Example 15.6. Displaying Graphs Using the DOCUMENT Procedure

This example illustrates the use of the DOCUMENT destination and the DOCUMENT procedure to display your ODS graphs. In particular, this is useful when you want to display your output (both tables and graphs) in one or more ODS destinations, or when you want to use different styles without rerunning your SAS program.

In general, when you send your output to the DOCUMENT destination you can use the DOCUMENT procedure to rearrange, duplicate, or remove output from the results of a procedure or a database query. You can also generate output for one or more ODS destinations. For more information, refer to the ODS DOCUMENT statement in the 'Dictionary of ODS Language Statements' and 'The DOCUMENT Procedure' ( SAS Output Delivery System User's Guide ).

The following statements request a Q-Q plot using PROC ROBUSTREG with the stack data from Example 15.4. The ODS DOCUMENT statement stores the data for the tables and the residual Q-Q plot from this analysis in an ODS document named QQDoc . Neither the tables nor the plot are displayed.

  ods listing close;   ods document name = QQDoc(write);   ods graphics on;   proc robustreg plot=resqqplot data=stack;   model y = x1 x2 x3;   run;   quit;   ods graphics off;   ods document close;   ods listing;  

In order to display the Q-Q plot using PROC DOCUMENT, you first need to determine its name. You can do this by specifying the ODS TRACE ON statement prior to the procedure statements (see page 330 for more information). Alternatively, you can type odsdocuments (or odsd for short) in the command line to open the Documents window, which you can then use to manage your ODS documents.

The following statements specify an HTML destination and display the residual Q-Q plot using the REPLAY statement in PROC DOCUMENT.

  ods html;   ods select ResidualQQPlot;   proc document name = QQDoc;   replay;   run;   quit;   ods html close;  

By default, the REPLAY statement attempts to replay every output object stored in the document, but only the Q-Q plot is displayed as specified by the ODS SELECT statement. The plot is displayed in Output 15.6.1.

Output 15.6.1: Q-Q Plot Displayed by PROC DOCUMENT
start example
  click to expand  
end example
 

As an alternative to running PROC DOCUMENT with an ODS SELECT statement, you can run PROC DOCUMENT specifying a document path for the Q-Q plot in the REPLAY statement. This approach is preferable when the document contains a large volume of output, because PROC DOCUMENT does not attempt to process every piece of output stored in the document.

You can determine the document path for the Q-Q plot by specifying the LIST statement with the LEVELS=ALL option in PROC DOCUMENT.

  proc document name = QQDoc;   list / levels = all;   run;   quit;  

This lists the entries of the QQDoc document, as shown in Output 15.6.2.

Output 15.6.2: Contents of QQDoc
start example
  Listing of: \Work.Qqdoc\   Order by: Insertion   Number of levels: All   Obs    Path                                                           Type   -------------------------------------------------------------------------------   1 \Robustreg#1                                                   Dir   2 \Robustreg#1\ModelInfo#1                                       Table   3 \Robustreg#1\NObs#1                                            Table   4 \Robustreg#1\SummaryStatistics#1                               Table   5 \Robustreg#1\ParameterEstimates#1                              Table   6 \Robustreg#1\DiagSummary#1                                     Table   7 \Robustreg#1\ResidualQQPlot#1                                  Graph   8 \Robustreg#1\GoodFit#1                                         Table  
end example
 

The document path of the 'ResidualQQPlot' entry in QQDoc , as shown in Output 15.6.2, is

  \Robustreg#1\ResidualQQPlot#1  

You can specify this path to display the residual Q-Q plot with PROC DOCUMENT as follows.

  ods html;   proc document name = QQDoc;   replay \Robustreg#1\ResidualQQPlot#1;   run;   quit;   ods html close;  

You can also determine the document path from the Results window or the Documents window. Right-click on the object icon and select Properties .

A sample program named odsgr06.sas is available for this example in the SAS Sample Library for SAS/STAT software.

Example 15.7. Customizing Graph Titles and Axes Labels

This example shows how to use PROC TEMPLATE to customize the appearance and content of an ODS graph. It illustrates the discussion in the section 'Customizing Graphics with Templates' on page 338 in the context of changing the default title and y-axis label for a Q-Q plot created with the ROBUSTREG procedure.

The following statements request a Q-Q plot for robust residuals using PROC ROBUSTREG with the stack data from Example 15.4.

  ods trace on;   ods html;   ods graphics on;   ods select ResidualQQPlot;   proc robustreg plot=resqqplot data=stack;   model y = x1 x2 x3;   run;   ods graphics off;   ods html close;   ods trace off;  

The Q-Q plot is shown in Output 15.7.1.

Output 15.7.1: Default Q-Q Plot from PROC ROBUSTREG
start example
  click to expand  
end example
 

The ODS TRACE ON statement requests a record of all the ODS output objects created by PROC ROBUSTREG. A partial listing of the trace record, which is displayed in the SAS log, is shown in Output 15.7.2.

Output 15.7.2: Trace Record for Q-Q Plot
start example
  Output Added:   -------------   Name:       ResidualQQPlot   Label:      ResidualQQPlot   Template:   Stat.Robustreg.Graphics.ResidualQQPlot   Path:       Robustreg.Graphics.ResidualQQPlot   -------------  
end example
 

As shown in Output 15.7.2, ODS Graphics creates the Q-Q plot using an ODS output data object named 'ResidualQQPlot' and a graph template named 'Stat.Robustreg.Graphics.ResidualQQPlot,' which is the default template provided by SAS. Default templates supplied by SAS are saved in the Sashelp.Tmplmst template store (see page 338).

To display the default template definition, open the Templates window by typing odstemplates (or odst for short) in the command line. Expand Sashelp.Tmplmst and click on the Stat folder, as shown in Output 15.7.3.

Output 15.7.3: The Templates Window
start example
  click to expand  
end example
 

Next , open the Robustreg folder and then open the Graphics folder. Then right-click on the 'ResidualQQPlot' template icon and select Edit , as shown in Output 15.7.4.

Output 15.7.4: Editing Templates in the Template Window
start example
  click to expand  
end example
 

Selecting Edit opens a Template Editor window, as shown in Output 15.7.5. You can use this window to edit the template.

Output 15.7.5: Default Template Definition for Q-Q Plot
start example
  click to expand  
end example
 

The template definition in Output 15.7.5 is discussed below and in subsequent examples. It is listed in a more convenient format by the following statements:

  proc template;   define statgraph Stat.Robustreg.Graphics.ResidualQQPlot;   notes "Q-Q Plot for Standardized Robust Residuals";   dynamic _DEPLABEL Residual;   layout Gridded;   layout Gridded / columns = 2;   ENTRYTITLE "Q-Q Plot of Robust Residuals for" / padbottom = 5;   ENTRYTITLE _DEPLABEL / padbottom = 5;   EndLayout;   layout Lattice;   layout Overlay /   yaxisopts = (label = "Standardized Robust Residual")   xaxisopts = (label = "Normal Quantile")   XGrid = True YGrid = True;   SCATTERPLOT   y = eval(SORT(DROPMISSING(RESIDUAL)))   x = eval(PROBIT((NUMERATE(SORT(DROPMISSING(RESIDUAL)))   -0.375)/(0.25+N(RESIDUAL)))) /   markersize   = GraphDataDefault:markersize   markersymbol = GraphDataDefault:markersymbol   markercolor  = GraphDataDefault:contrastcolor   legendlabel  = "Residual"   name         = "Data";   lineparm   slope      = eval(STDDEV(RESIDUAL))   Yintercept = eval(MEAN(RESIDUAL)) /   linecolor     = StatGraphFitLine:contrastcolor   linepattern   = StatGraphFitLine:linestyle   linethickness = StatGraphFitLine:linethickness   legendlabel   = "Normal"   name          = "Fit"   extreme       = true;   EndLayout;   column2header;   layout Gridded / padtop = 5;   DiscreteLegend "Fit" "Data" /   border     = true   across     = 2   background = GraphWalls:background;   EndLayout;   endcolumn2header;   EndLayout;   EndLayout;   end;   run;  

As an alternative to using the Template Editor window, you can submit the following statements, which display the 'ResidualQQPlot' template definition in the SAS log.

  proc template;   source Stat.Robustreg.Graphics.ResidualQQPlot;   run;  

The SOURCE statement specifies the fully qualified template name. You can copy and paste the template source into the Program Editor, modify it, and submit it us-ing PROC TEMPLATE. See the 'Editing Templates' section on page 340 for more information.

In the template, the default title of the Q-Q plot is specified by the two ENTRYTITLE statements. Note that _DEPLABEL is a dynamic variable that provides the name of the dependent variable in the regression analysis (the name happens to be y in Output 15.7.1). The default label for the y-axis is specified by the LABEL= suboption of the YAXISOPTS= option for the LAYOUT OVERLAY statement.

Suppose you want to change the default title to My Favorite Title , and you want the y-axis label to display the name of the dependent variable. First, replace the two ENTRYTITLE statements with the single statement

  ENTRYTITLE "My Favorite Title" / padbottom = 5;  

The PADBOTTOM= option specifies the amount of empty space (in pixel units) at the bottom of the layout component. In this case it creates an empty space of 5 pixels between the title and the adjacent layout component, which defines the plot itself.

Next, replace the LABEL= suboption with the following:

  label = _DEPLABEL  

Note that you can reuse dynamic text variables such as _DEPLABEL in any text element.

You can then submit the modified template definition as you would any SAS program, for example, by selecting Submit from the Run menu.

After submitting the PROC TEMPLATE statements you should see the following message in the SAS log:

  NOTE: STATGRAPH 'Stat.Robustreg.Graphics.ResidualQQPlot' has been   saved to: SASUSER.TEMPLAT  

Note: Graph definitions are self-contained and do not support parenting as do table definitions. For more information about graph definitions and the graph template language, see the 'Introducing the Template Language for Graphics' sectionon page 342.

Finally, resubmit the PROC ROBUSTREG statements on page 363 to display the Q-Q plot created with your modified template, as shown in Output 15.7.6.

Output 15.7.6: Q-Q Plot with Modified Title and Y-Axis Label
start example
  click to expand  
end example
 

If you have not changed the default ODS path, the modified template 'ResidualQQPlot' is used automatically because Sasuser.Templat occurs before Sashelp.Tmplmst in the ODS search path. See the 'Using Customized Templates' section on page 341 for additional information.

Note that you do not need to rerun the PROC ROBUSTREG analysis after you modify a graph template. After you modify your template, you can submit the PROC DOCUMENT statements in Example 15.6 to replay the Q-Q plot with the modified template.

See the 'Reverting to Default Templates' section on page 341 for information on how to revert to the default template.

A sample program named odsgr07.sas is available for this example in the SAS Sample Library for SAS/STAT software.

Example 15.8. Modifying Colors, Line Styles, and Markers

This example is a continuation of Example 15.7. Here the objective is to customize colors, line attributes, and marker symbol attributes by modifying the graph template.

In the 'ResidualQQPlot' template definition shown in Output 15.7.5, the SCATTERPLOT statement specifies a scatter plot of normal quantiles versus ordered standardized residuals. The default marker symbol in the scatter plot is specified by the MARKERSYMBOL= option of the SCATTERPLOT statement:

  markersymbol = GraphDataDefault:markersymbol  

The default value is a reference to the style attribute markersymbol of the style element GraphDataDefault . See the 'Introducing Style Elements for Graphics' section on page 344 for more information. The actual value of the marker symbol depends on the style that you are using. In this case, since the 'Default' style is used, the value of the marker symbol is Circle.

You can specify a filled circle as the marker symbol by modifying the value of the MARKERSYMBOL= option as follows.

  markersymbol = CircleFilled  

Note that the value of the option can be any valid marker symbol or a reference to a style attribute of the form style-element:attribute . It is recommended that you use style attributes since these are chosen to provide consistency and appropriate emphasis based on display principles for statistical graphics. If you specify values directly in a template, you are overriding the style and run the risk of creating a graph that is inconsistent with the style definition.

For more information about the syntax of the graphics template language and style elements for graphics, refer to the sections 'TEMPLATE Procedure: Creating ODS Statistical Graphics Output (Experimental)' and 'ODS Statistical Graphics and ODS Styles: Usage and Reference (Experimental)' at http://support.sas.com/documentation/onlinedoc/base/.

Similarly, you can change the line color and pattern with the LINECOLOR= and LINEPATTERN= options in the LINEPARM statement. The LINEPARM statement displays a straight line specified by slope and intercept parameters. The following statements change the default color of the Q-Q plot line to red, and the line pattern to dashed.

  linecolor   = red   linepattern = dash  

To display these modifications, shown in Output 15.8.1, submit the modified template definition and then resubmit the PROC ROBUSTREG statements on page 363. Alternatively, you can replay the plot using PROC DOCUMENT, as in Example 15.6.

Output 15.8.1: Q-Q Plot with Modified Marker Symbols and Line
start example
  click to expand  
end example
 

A sample program named odsgr08.sas is available for this example in the SAS Sample Library for SAS/STAT software.

Example 15.9. Swapping the Axes in a Graph

Sometimes a Q-Q plot is displayed with the normal quantiles plotted along the y-axis and the ordered variable values plotted along the x-axis. This example, which is a continuation of Example 15.7 and Example 15.8, illustrates how to interchange the axes with a simple modification of the graph template.

Begin by swapping the YAXISOPTS= and XAXISOPTS= options, and by swapping the X= and Y= options in the SCATTERPLOT statement.

Next, modify the LINEPARM statement. In Output 15.8.1, the slope of the line in the Q-Q plot is , and y-intercept is . When you swap the axes, the values of the slope and y-intercept become and , respectively. The modified template definition (including the changes from Example 15.7 and Example 15.8) is as follows:

  proc template;   define statgraph Stat.Robustreg.Graphics.ResidualQQPlot;   notes "Q-Q Plot for Standardized Robust Residuals";   dynamic _DEPLABEL Residual;   layout Gridded;   layout Gridded / columns = 2;   ENTRYTITLE "My Favorite Title" / padbottom=5;   EndLayout;   layout Lattice;   layout Overlay /   xaxisopts = (label = _DEPLABEL)   yaxisopts = (label = "Normal Quantile")   XGrid = True YGrid = True;   SCATTERPLOT   x = eval(SORT(DROPMISSING(RESIDUAL)))   y = eval(PROBIT((NUMERATE(SORT(DROPMISSING(RESIDUAL)))   -0.375)/(0.25+N(RESIDUAL)))) /   markersize   = GraphDataDefault:markersize   markersymbol = CircleFilled   markercolor  = GraphDataDefault:contrastcolor   legendlabel  = "Residual"   name         = "Data";   lineparm   slope      = eval(1/STDDEV(RESIDUAL))   Yintercept = eval(-MEAN(RESIDUAL)/STDDEV(RESIDUAL)) /   linecolor     = red   linepattern   = dash   linethickness = StatGraphFitLine:linethickness   legendlabel   = "Normal"   name          = "Fit"   extreme       = true;   EndLayout;   column2header;   layout Gridded / padtop = 5;   DiscreteLegend "Fit" "Data" /   border     = true   across     = 2   background = GraphWalls:background;   EndLayout;   endcolumn2header;   EndLayout;   EndLayout;   end;   run;  

The resulting Q-Q plot, after submitting the preceding statements and the PROC ROBUSTREG statements on page 363, is shown in Output 15.9.1.

Output 15.9.1: Q-Q Plot with Swapped Axes
start example
  click to expand  
end example
 

A sample program named odsgr09.sas is available for this example in the SAS Sample Library for SAS/STAT software.

Example 15.10. Modifying Tick Marks and Suppressing Grid Lines

This example, which is a continuation of Example 15.7, Example 15.8,andExample 15.9, illustrates how to modify the tick marks for an axis and suppress grid lines.

You can use the TICKS = suboption in the XAXISOPTS= or YAXISOPTS= options to specify the tick marks for an axis. For example, you can specify the following to request tick marks ranging from ˆ’ 3 to 3 in the y-axis for the Q-Q plots in Output 15.9.1:

  yaxisopts = (label = "Normal Quantile"   ticks = (   3   2   1 0 1 2))  

By default, the Q-Q plot in Output 15.9.1 displays grid lines since XGRID=TRUE and YGRID=TRUE are specified in the LAYOUT OVERLAY statement in the 'ResidualQQPlot' template definition. You can suppress the grid lines by specifying

  XGrid = False  

The result of these changes, after submitting the modified template definition and the corresponding PROC ROBUSTREG statements on page 363, is displayed in Output 15.10.1.

Output 15.10.1: Q-Q Plot with Modified Y-Axis Tick Marks and Grids
start example
  click to expand  
end example
 

A sample program named odsgr10.sas is available for this example in the SAS Sample Library for SAS/STAT software.

Example 15.11. Modifying Graph Fonts in Styles

You can modify an ODS style to customize the general appearance of ODS Graphics, just as you can modify a style to customize the general appearance of ODS tables. The goal of this example is to customize the fonts used in ODS graphs. It is a continuation of Example 15.10.

The following statements define a style named NewStyle that replaces the graph fonts in the 'Default' style with italic Times New Roman fonts.

  proc template;   define style Styles.NewStyle;   parent = Styles.Default;   replace GraphFonts   "Fonts used in graph styles" /   'GraphDataFont'     = ("Times New Roman",8pt,Italic)   'GraphValueFont'    = ("Times New Roman",10pt,Italic)   'GraphLabelFont'    = ("Times New Roman",12pt,Italic)   'GraphFootnoteFont' = ("Times New Roman",12pt,Italic)   'GraphTitleFont'    = ("Times New Roman",14pt,Italic Bold);   end;   run;  

In general, the following graph fonts are specified in the ODS styles provided by SAS:

  • 'GraphDataFont' is the smallest font. It is used for text that needs to be small (labels for points in scatter plots, labels for contours , and so on)

  • 'GraphValueFont' is the next largest font. It is used for axis value (tick marks) labels and legend entry labels.

  • 'GraphLabelFont' is the next largest font. It is used for axis labels and legend titles.

  • 'GraphFootnoteFont' is the next largest font. It is used for all footnotes.

  • 'GraphTitleFont' is the largest font. It is used for all titles.

For more information about the DEFINE, PARENT, and REPLACE statements, refer to the 'TEMPLATE Procedure: Creating a Style Definition' in the SAS Output Delivery System User's Guide .

The Q-Q plots in the preceding examples, beginning with Example 15.6, were created with the 'Default' style; see, for instance, Output 15.10.1. In contrast, the Q-Q plot displayed in Output 15.11.1 was produced by specifying the NewStyle style in the following statements.

  ods html style = NewStyle;   ods graphics on;   ods select ResidualQQPlot;   proc robustreg plot=resqqplot data=stack;   model y = x1 x2 x3;   run;   ods graphics off;   ods html close;  
Output 15.11.1: Q-Q Plot Using NewStyle
start example
  click to expand  
end example
 

Although this example illustrates the use of a style with output from a particular procedure, note that a style is applied to all of your output (graphs and tables) in the destination for which you specify the style. See the 'Specifying a Default Style' section on page 346 for information about specifying a default style for all your output.

A sample program named odsgr11.sas is available for this example in the SAS Sample Library for SAS/STAT software.

Example 15.12. Modifying Other Graph Elements in Styles

This example, which is a continuation of Example 15.11, illustrates how to modify additional style elements for graphics, such as the thickness of a line.

The attributes of fitted lines in ODS Graphics are controlled by the style element StatGraphFitLine , which is defined in the 'Default' style. For example, the line thickness of the normal distribution reference line in Output 15.11.1 is specified in the graph template by

  linethickness = StatGraphFitLine:linethickness  

To specify a line thickness of 4 pixels for the line, add the following statements to the definition of the NewStyle style in Example 15.11.

  replace StatGraphFitLine /   linethickness = 4px;  

The complete revised NewStyle style is now defined by the following statements:

  proc template;   define style Styles.NewStyle;   parent = Styles.Default;   replace GraphFonts   "Fonts used in graph styles" /   'GraphDataFont'     = ("Times New Roman",8pt,Italic)   'GraphValueFont'    = ("Times New Roman",10pt,Italic)   'GraphLabelFont'    = ("Times New Roman",12pt,Italic)   'GraphFootnoteFont' = ("Times New Roman",12pt,Italic)   'GraphTitleFont'    = ("Times New Roman",14pt,Italic Bold);   replace StatGraphFitLine /   linethickness = 4px;   end;   run;  

Output 15.12.1 shows the Q-Q plot created by the ROBUSTREG statements on page 375 with the new version of NewStyle .

Output 15.12.1: Q-Q Plot Using NewStyle with Thicker Line
start example
  click to expand  
end example
 

You can use this approach to modify other attributes of the line, such as trans parency , linestyle , contrastcolor , and foreground .

Note: Values specified directly in a graph template override style attributes. If you have customized a template, changes in a style may not have any effect. For more information, refer to the 'ODS Statistical Graphics and ODS Styles: Usage and Reference (Experimental)' at http://support.sas.com/documentation/onlinedoc/base/.

A sample program named odsgr12.sas is available for this example in the SAS Sample Library for SAS/STAT software.

Example 15.13. Modifying Graph Sizes Using Styles

This example demonstrates how to modify the size of your ODS graphs using a style definition.

You can specify the size of a graph in a graph template definition or in a style definition:

  • To modify the size of a particular graph, specify the dimensions with the HEIGHT= and WIDTH= options in the outermost layout of the graph template definition.

  • To modify the size of all your ODS graphs, specify the dimensions with the OUTPUTHEIGHT= and OUTPUTWIDTH= options in the style definition.

Dimensions specified in a graph template override those specified in a style.

Continuing the discussion in Example 15.12, you can add the following style element to the definition of NewStyle to change the size of all your graphs:

  style Graph from Graph /   outputwidth = 400px   outputheight = 300px;  

With all the changes introduced so far, NewStyle is defined as follows:

  proc template;   define style Styles.NewStyle;   parent = Styles.Default;   replace GraphFonts   "Fonts used in graph styles" /   'GraphDataFont'     = ("Times New Roman",8pt,Italic)   'GraphValueFont'    = ("Times New Roman",10pt,Italic)   'GraphLabelFont'    = ("Times New Roman",12pt,Italic)   'GraphFootnoteFont' = ("Times New Roman",12pt,Italic)   'GraphTitleFont'    = ("Times New Roman",14pt,Italic Bold);   replace StatGraphFitLine /   linethickness = 4px;   style Graph from Graph /   outputwidth  = 400px   outputheight = 300px;   end;   run;  

The dimensions of the graph must be specified in pixels. The actual size of the graph in inches depends on your printer or display device. For example, if the resolution of your printer is 100 dpi (100 dots per inch) and you want a graph that is 4 inches wide, you should set the width to 400 pixels.

You can create a smaller version of Output 15.12.1, shown in Output 15.13.1, by specifying the preceding PROC TEMPLATE statements followed by the ROBUSTREG statements on page 375.

Output 15.13.1: Q-Q Plot Using NewStyle with Smaller Dimensions
start example
  click to expand  
end example
 

An alternative method for including smaller graphs in a document is to start with a style provided by SAS and define a modified style that increases the size of the graph fonts while preserving the default width and height attributes. Then you can include the graph in a document (for example in Microsoft Word) and manually rescale the graph to a smaller size while maintaining the fonts in a size that is still readable. [*]

The following style increases the size of the fonts but retains all the other style elements as assigned in the 'Default' style:

  proc template;   define style Styles.BigFontStyle;   parent = Styles.Default;   replace GraphFonts   "Fonts used in graph styles" /   'GraphDataFont'     = ("Arial",12pt)   'GraphValueFont'    = ("Arial",15pt)   'GraphLabelFont'    = ("Arial",18pt)   'GraphFootnoteFont' = ("Arial",18pt)   'GraphTitleFont'    = ("Arial",21pt);   end;   run;  

A sample program named odsgr13.sas is available for this example in the SAS Sample Library for SAS/STAT software.

Example 15.14. Modifying Panels

This example illustrates how to modify the regression fit diagnostics panel in Figure 15.1 so that it displays a subset of component plots. The original panel consists of eight plots and a summary statistics box. These components are labeled 1 to 9 in the annotated version of Figure 15.1, which is shown in Output 15.14.1.

Output 15.14.1: Diagnostics Panel Annotated to Indicate Layout Structure
start example
  click to expand  
end example
 

In the discussion that follows, the panel is modified so that it includes only the following components:

  • 1. residual by predicted plot

  • 4. residual Q-Q plot

  • 6. Cook's D plot

  • 7. residual histogram

  • 9. summary statistics box

The panel to be produced is shown in Output 15.14.2. It displays components 1, 4, 6, and 7 in a 2 — 2 lattice, and it displays four of the summary statistics in component 9 in a box at the bottom.

Output 15.14.2: Simplified Diagnostics Panel
start example
  click to expand  
end example
 

The template that defines the original panel is 'Stat.Reg.Graphics.DiagnosticPanel.' The following listing is abbreviated to show the main structure of the template definition (see page 339 for details on how to display the complete template definition).

  proc template;   define statgraph Stat.Reg.Graphics.DiagnosticsPanel;   /* Dynamic variables */   dynamic _TITLE _MODELLABEL _DEPLABEL _NOBS _NPARM _EDF _MSE   _RSquare _AdjRSq;   /* 3x3 LATTICE layout */   layout lattice / columns = 3 rows = 3 ... ;   sidebar / align=top;   /* Statements for model label and graph title */   endsidebar;   /* 1. Residual By Predicted */   layout overlay / ... ;   lineparm slope = 0 yintercept = 0;   scatterplot y = RESIDUAL x = PREDICTEDVALUE;   endlayout;   ...   /* LAYOUT statements for components 2-8 */   ...   /* 9. Summary Statistics Box */   layout overlay;   layout gridded / ... ;   entry "NObs";   entry _NOBS / format=best6.;   .   .   .   entry "AdjRSq";   entry _ADJRSQ / format=best6.;   endlayout;   endlayout;   endlayout;   /* End of 3x3 LATTICE layout */   end;   run;  

The overall display is defined by the LAYOUT LATTICE statement, which specifies a lattice of components, indicated by the solid grid annotated in Output 15.14.1.The COLUMNS=3 and ROWS=3 options in the LAYOUT LATTICE statement specify a 3 — 3 lattice, indicated by the dashed grid.

The model label and the graph title (top rectangle in Output 15.14.1) are specified inside the LATTICE layout with a SIDEBAR statement. The ALIGN=TOP option positions the sidebar at the top.

Each of the nine components of the lattice is defined by a LAYOUT statement. These statements define the components from left to right and top to bottom. Components 1 through 7 are defined with LAYOUT OVERLAY statements. Component 8 (RF plot) is defined with a LAYOUT LATTICE statement. The last LAYOUT OVERLAY statement defines a box with summary statistics for the fitted model.

The following abbreviated listing shows the basic structure of the template definition for a simplified panel that displays components 1, 4, 6, and 7 in a 2 — 2 lattice. [*] For the complete template definition, refer to the sample program odsgr14.sas in the SAS Sample Library for SAS/STAT software.

  proc template;   define statgraph Stat.Reg.Graphics.DiagnosticsPanel;   dynamic _TITLE _MODELLABEL _DEPLABEL _NOBS _NPARM _EDF _MSE   _RSquare _AdjRSq;   /* 2x2 LATTICE layout */   /* Change COLUMNS= and ROWS= options */   layout lattice / columns = 2 rows = 2 ... ;   sidebar / align=top;   /* Statements for model label and graph title */   endsidebar;   /* 1. Residual By Predicted */   layout overlay / ... ;   lineparm slope = 0 yintercept = 0;   scatterplot y = RESIDUAL x = PREDICTEDVALUE;   endlayout;   /* 4. Q-Q Plot */   layout overlay / ... ;   lineparm slope      = eval(STDDEV(RESIDUAL))   yintercept = eval(...);   scatterplot y = eval(...) x = eval(...);   endlayout;   /* Statements for components 6 and 7 (not listed) */   /* Summary Statistics Box in a SIDEBAR */   sidebar / align=bottom;   layout gridded;   layout lattice / rows=1 columns=4 ... ;   .   .   .   endlayout;   endlayout;   endsidebar;   endlayout;   /* End of 2x2 LATTICE layout */   end;   run;  

This template is a straightforward modification of the original template. The COLUMNS=2 and ROWS=2 options in the LAYOUT LATTICE statement request a 2 — 2 lattice. The LAYOUT statements for components 2, 3, 5, and 8 are deleted. A subset of the summary statistics are displayed at the bottom of the graph using a SIDEBAR statement with the ALIGN=BOTTOM option.

After submitting the preceding statements, which create the modified template and save it in Sasuser.Templat , you can run the following PROC REG statements to obtain the simplified panel, which is shown in Output 15.14.2.

  ods html;   ods graphics on;   ods select DiagnosticsPanel;   proc reg data = Class;   model Weight = Height;   run;   quit;   ods graphics off;   ods html close;  

A sample program named odsgr14.sas is available for this example in the SAS Sample Library for SAS/STAT software.

[*] The LATEX destination in ODS is experimental in SAS 9.1.

[*] In a markup language, such as HTML or LATEX, you can use a resize command.

[*] See page 340 for details on how to edit the template definition.




SAS.STAT 9.1 Users Guide (Vol. 1)
SAS/STAT 9.1 Users Guide, Volumes 1-7
ISBN: 1590472438
EAN: 2147483647
Year: 2004
Pages: 156

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net