|
|
|
||||
|
|
|||||
There are at least two ways to make a scatterplot with a regression line in SPSS. One way is to use the graph command, and another way is to use the igraph command. Both are illustrated below.
Let's read in an example dataset, hsb2, which contains data from the High School and Beyond study.
get file 'c:\hsb2.sav'.
Let's do a scatterplot of the variables write with read. Note that after running the code below, you need to double click on the graph, which will open up the chart editor window. Select "chart" from the menu at the top and then "options" (which is the first item in the menu). On the right of the dialogue box is a check box called "Total" under the heading "Fit Line". Click on the box to put in the check, or click on "Fit Options" to select a different type of fit method, such as lowess, quadratic or cubic. Close the chart editor so that the changes to take effect on your graph.
graph /scatterplot(bivar)=read with write.
Now let's try the same scatterplot using igraph.
igraph /x1 = var(read) /y = var(write) /fitline method = regression linear line = total /scatter.
As you can see, this sequence of commands produces exactly the same scatterplot with regression line as does the graph command (after using the chart editor to add the regression line).
Here is how the igraph command works. The x1 = var() subcommand tells SPSS which variable to plot on the X axis, while the y = var() subcommand tells SPSS which variable to plot on the Y axis. The fitline method = subcommand tells SPSS which method to use when drawing the fitline (in this case, the regression line). The line = total option is necessary to tell SPSS to use all of the data when drawing the regression line. If this option is omitted, SPSS will not draw in the regression line on this graph. The scatter subcommand tells SPSS to include the data points (shown as red dots) on the graph.
The ggraph command was introduced in version 14 of SPSS. This command can also be used to create and edit scatterplots. Below is the syntax for creating the scatterplot. To add the fit line, you need to open the graph editor (by double-clicking on the graph), and then select the Elements pull-down menu at the top, and then selecting Fit Line at Total.
GGRAPH
/GRAPHDATASET NAME="graphdataset" VARIABLES=read[LEVEL=SCALE] write
/GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
SOURCE: s=userSource(id("graphdataset"))
DATA: read=col(source(s), name("read"))
DATA: write=col(source(s), name("write"))
GUIDE: axis(dim(1), label("reading score"))
GUIDE: axis(dim(2), label("writing score"))
ELEMENT: point(position(read*write))
END GPL.
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