19.R Integration Package For IBM SPSS Statistics

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

R Integration Package for IBM SPSS

Statistics

IBM
Result

Figure 1. Model Coefficients

• The R variable model contains the results of the generalized linear model analysis.
• The R summary function takes the results of the glm analysis and produces an R object with a number
of attributes that summarize the model. In particular, the coefficients attribute contains a table of the
model coefficients and associated statistics.
Note: You can obtain a list of the attributes available for an object using attributes(object).
• The spsspivottable.Display function creates the pivot table. The first and only required argument
is the data to be displayed as a pivot table. This can be a data frame, matrix, table, or any R object that
can be converted to a data frame. In the present example, the coefficients attribute of the summary
object is a matrix.
• The format argument specifies the format to be used for displaying numeric values, including cell
values, row labels, and column labels. The argument is of the form formatSpec.format, as in
formatSpec.GeneralStat. A list of available formats as well as a brief guide to choosing a format is
provided in the topic on the spsspivottable.Display function.
Optional arguments to the spsspivottable.Display function allow you to customize the pivot table.
By default, the name that appears in the outline pane of the Viewer associated with the pivot table is R.
You can customize the name and nest multiple pivot tables under a common heading by wrapping the
pivot table generation in a StartProcedure-EndProcedure block. See the topic
“spsspkg.StartProcedure Function ” on page 58 for more information.
The spsspivottable.Display is limited to pivot tables with one row dimension and one column
dimension. To create more complex pivot tables, use the BasePivotTable class.

Attribute 1.14, 2.14


Displaying Graphical Output from R
By default, graphical output from R--for instance, from the R plot function--is displayed in the IBM SPSS
Statistics Viewer. You can display a specified R graphics file, from disk, in the IBM SPSS Statistics Viewer
using the spssRGraphics.Submit function, and you can turn display of R graphics on or off using the
spssRGraphics.SetOutput function. You can also set the outline title for R graphics displayed in IBM SPSS
Statistics with the spssRGraphics.SetGraphicsLabel function. R graphics displayed in the IBM SPSS
Statistics Viewer cannot be edited and do not use the graphics preference settings in IBM SPSS Statistics.
Example
This example makes use of the default behavior for rendering graphical output from R in the Viewer. It
produces a scatterplot, along with fit lines computed from a linear model and separately from a
smoothing algorithm.

COMPUTE filter_$=(nvalid(mpg, curb_wgt) = 2).


FILTER BY filter_$.
BEGIN PROGRAM R.
data <- spssdata.GetDataFromSPSS()
spssRGraphics.SetGraphicsLabel("MyGraphicsLabel")
plot(data$curb_wgt, data$mpg, col="blue", pch=19)
abline(lm(data$mpg ~ data$curb_wgt), lwd=3 )
lines(lowess(data$mpg ~ data$curb_wgt), lwd=3, lty=2)
END PROGRAM.

Result

Chapter 1. Using the R Integration Package for IBM SPSS Statistics 11


Figure 2. R graphic displayed in the Viewer

Note on Generating Multiple Graphics


When invoking a graphics command that generates multiple graphics, you will need to add the parameter
ask=FALSE, as in: plot(result,ask=FALSE).

Retrieving Output from Syntax Commands


Functionality provided with the IBM SPSS Statistics - Integration Plug-in for R allows you to access output
from IBM SPSS Statistics syntax commands in a programmatic fashion. To retrieve command output, you
first route it via the Output Management System (OMS) to an area in memory referred to as the XML
workspace where it is stored as an XPath DOM that conforms to the Output XML Schema (xml.spss.com/
spss/oms). Output is retrieved from this workspace with functions that employ XPath expressions.
Constructing the correct XPath expression (IBM SPSS Statistics currently supports XPath 1.0) requires an
understanding of the Output XML schema. Documentation for the output schema is available from the
Help system.
Example
In this example, we'll use output from the DESCRIPTIVES command to determine the percentage of valid
cases for a specified variable.

*Route output to the XML workspace.


OMS SELECT TABLES
/IF COMMANDS=['Descriptives'] SUBTYPES=['Descriptive Statistics']
/DESTINATION FORMAT=OXML XMLWORKSPACE='desc_table'

12 R Integration Package for IBM SPSS Statistics

You might also like