|
|
|
||||
|
Help the Stat Consulting Group by
giving a gift
| |||||
|
Loading
|
|||||
Three dimensional grid graphs can help to visualize the relationships between three variables. One way to create them in SAS is using proc g3d. For this example, we will use the hsb2 data set.
First we read in the data and look at some basic descriptives.
data hsb2; set "Z:/data/hsb2"; run; /* Basic summaries of the variables */ proc means data=hsb2; var write read math; run; The MEANS Procedure Variable Label N Mean Std Dev Minimum Maximum write writing score 200 52.7750000 9.4785860 31.0000000 67.0000000 read reading score 200 52.2300000 10.2529368 28.0000000 76.0000000 math math score 200 52.6450000 9.3684478 33.0000000 75.0000000
We can also look at a basic 3d scatter plot of the raw data using the code below.
/* View a scatter plot of the data */ proc g3d data=hsb2; scatter write*read = math / shape="balloon"; run;![]()
Before we can view the 3d grid plot, we need to actually create the grid data. This is done using proc g3grid. Then we can plot using proc g3d just like we did for the scatter plot.
/* Create the grid data */ proc g3grid data=hsb2 out=a; grid write*read = math / axis1=30 to 80 by 5 axis2=30 to 80 by 5; run; /* Plot the Surface */ proc g3d data=a; plot write*read = math; run;![]()
We moved in increments of 5 for the prior grid and SAS did a linear interpolation between points. Using a different increment can give a more fine-tuned view. This may or may not be helpful, but it is useful to know what the differences are and how to try different ways.
/* We can adjust the detail in the grid */ proc g3grid data=hsb2 out=b; grid write*read=math / axis1=30 to 80 by 1 axis2=30 to 80 by 1; run; proc g3d data=b; plot write*read=math; run;![]()
Another tricky problem with 3d graphs is presenting the best angle of presentation. This depends on your data and the aspects that are most interesting. For your own use, or to present to readers, you want to pick an angle that makes it easiest to see what is happening in the data. In SAS you can control the rotation and the tilt. Here is a simple example using a 45 degree rotation and a 80 degree tilt (i.e., almost perpendicular).
/* It can be helpful to view at different angles */ proc g3d data=b; plot write*read=math / rotate=45 tilt=80; run;![]()
This demonstrates a few of the options in SAS for creating 3d plots of a surface (grid). There are many options in proc g3d to control the appearance of the plot (axes, colours, etc.). The SAS documentation for the procedure does a nice job of naming all the options.
UCLA Researchers are invited to our Statistical Consulting Services
We recommend others to our list of Other Resources for Statistical Computing Help
These pages are Copyrighted (c) by UCLA Academic Technology Services