<?xml version="1.0" encoding="utf-8"?><!DOCTYPE article  PUBLIC '-//OASIS//DTD DocBook XML V4.4//EN'  'http://www.docbook.org/xml/4.4/docbookx.dtd'><article><articleinfo><title>FAQ/spsspoly</title><revhistory><revision><revnumber>14</revnumber><date>2013-03-08 10:17:37</date><authorinitials>localhost</authorinitials><revremark>converted to 1.6 markup</revremark></revision><revision><revnumber>13</revnumber><date>2011-09-16 11:05:58</date><authorinitials>PeterWatson</authorinitials></revision><revision><revnumber>12</revnumber><date>2011-09-16 11:04:21</date><authorinitials>PeterWatson</authorinitials></revision><revision><revnumber>11</revnumber><date>2011-09-16 11:03:49</date><authorinitials>PeterWatson</authorinitials></revision><revision><revnumber>10</revnumber><date>2011-09-16 11:03:20</date><authorinitials>PeterWatson</authorinitials></revision><revision><revnumber>9</revnumber><date>2011-09-16 11:02:59</date><authorinitials>PeterWatson</authorinitials></revision><revision><revnumber>8</revnumber><date>2011-09-16 10:59:44</date><authorinitials>PeterWatson</authorinitials></revision><revision><revnumber>7</revnumber><date>2011-09-16 09:09:20</date><authorinitials>PeterWatson</authorinitials></revision><revision><revnumber>6</revnumber><date>2011-09-16 09:09:07</date><authorinitials>PeterWatson</authorinitials></revision><revision><revnumber>5</revnumber><date>2011-09-16 09:08:29</date><authorinitials>PeterWatson</authorinitials></revision><revision><revnumber>4</revnumber><date>2009-01-16 16:18:03</date><authorinitials>PeterWatson</authorinitials></revision><revision><revnumber>3</revnumber><date>2009-01-16 16:16:24</date><authorinitials>PeterWatson</authorinitials></revision><revision><revnumber>2</revnumber><date>2009-01-16 16:15:46</date><authorinitials>PeterWatson</authorinitials></revision><revision><revnumber>1</revnumber><date>2009-01-16 16:13:48</date><authorinitials>PeterWatson</authorinitials></revision></revhistory></articleinfo><section><title>Using R within SPSS to obtain polychoric correlations</title><para>Thanks to Jarlath Quinn of SPSS for the syntax below. You need SPSS version 16 or above to use this syntax and follow <ulink url="https://lsr-wiki-02.mrc-cbu.cam.ac.uk/statswiki/FAQ/spsspoly/statswiki/FAQ/spsspoly?action=AttachFile&amp;do=get&amp;target=RinSPSS.pdf">these guidelines</ulink> for using R code in SPSS. Details and examples of using R within SPSS are in the programming and data management guide which may downloaded for free from <ulink url="http://www.spss.com/statistics/base/data_management_book.htm">here.</ulink> You can alternatively run the R code in R version <emphasis role="strong">2.5</emphasis> to produce polychoric correlations from a SPSS data file without needing SPSS (see later example syntax further down this page). Further details of the R example are in the Graduate Statistics Talk on Factor Analysis located <ulink url="https://lsr-wiki-02.mrc-cbu.cam.ac.uk/statswiki/FAQ/spsspoly/statswiki/StatsCourse2011#">here.</ulink> </para><para>The example SPSS data file for use in SPSS is <ulink url="https://lsr-wiki-02.mrc-cbu.cam.ac.uk/statswiki/FAQ/spsspoly/statswiki/FAQ/spsspoly?action=AttachFile&amp;do=get&amp;target=polydat.sav">given here.</ulink> </para><screen><![CDATA[GET
  FILE='C:\SE demos\Assess\demo dataset v4.sav'.
DATASET NAME $DataSet WINDOW=FRONT.
]]><![CDATA[
begin program r.
library(polycor)
casedata <- spssdata.GetDataFromSPSS(variables=c(9,10,11,12))
satcat<-as.factor(casedata$satcat)
sat <- casedata$sat
perf_2 <- casedata$perf_2
perf_3 <- casedata$perf_3
res <- hetcor(satcat, sat, perf_2, perf_3, ML = FALSE,std.err = FALSE, bins=4)
spsspivottable.Display(res$correlations,
                                          title="Correlation Matrix",
                                          rowdim=" ",
                                          coldim="col",
                                          format=formatSpec.Correlation)
end program.]]></screen><para>The below R syntax can be run in R version <emphasis role="strong">2.5</emphasis> to produce polychoric correlations from a SPSS data file without the need to use SPSS. <emphasis role="underline">Note</emphasis> : This example may not work in later versions of R. You will need to change the directory location and filename in the 'read.spss' command, the variable names replacing PTCI1, PTCI2 etc. and amend the list of variable names inputted into 'hetcor'. </para><screen><![CDATA[library(foreign)
library(mvtnorm)
library(sfsmisc)
library(polycor)
x <- read.spss("C:\\Documents and Settings\\peterw\\Desktop\\POLYCHORIC DEMO IN SPSS\\example33.sav")
p1 <- as.factor(x$PTCI1)
p2 <- as.factor(x$PTCI2)
p3 <- as.factor(x$PTCI3)
p4 <- as.factor(x$PTCI4)
p5 <- as.factor(x$PTCI5)
p6 <- as.factor(x$PTCI6)
res <- hetcor(p1, p2, p3, p4, p5, p6, ML=FALSE, std.err=FALSE)
res$correlation
res$type]]></screen></section></article>