Diff for "FAQ/spsspoly" - CBU statistics Wiki
location: Diff for "FAQ/spsspoly"
Differences between revisions 13 and 14
Revision 13 as of 2011-09-16 11:05:58
Size: 2385
Editor: PeterWatson
Comment:
Revision 14 as of 2013-03-08 10:17:37
Size: 2392
Editor: localhost
Comment: converted to 1.6 markup
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
Thanks to Jarlath Quinn of SPSS for the syntax below. You need SPSS version 16 or above to use this syntax and follow [attachment:RinSPSS.pdf these guidelines] 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 [http://www.spss.com/statistics/base/data_management_book.htm here.] You can alternatively run the R code in R version '''2.5''' 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 [:StatsCourse2011: here.] Thanks to Jarlath Quinn of SPSS for the syntax below. You need SPSS version 16 or above to use this syntax and follow [[attachment:RinSPSS.pdf|these guidelines]] 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 [[http://www.spss.com/statistics/base/data_management_book.htm|here.]] You can alternatively run the R code in R version '''2.5''' 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 [[StatsCourse2011| here.]]
Line 5: Line 5:
The example SPSS data file for use in SPSS is [attachment:polydat.sav given here.] The example SPSS data file for use in SPSS is [[attachment:polydat.sav|given here.]]

Using R within SPSS to obtain polychoric correlations

Thanks to Jarlath Quinn of SPSS for the syntax below. You need SPSS version 16 or above to use this syntax and follow these guidelines 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 here. You can alternatively run the R code in R version 2.5 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 here.

The example SPSS data file for use in SPSS is given here.

GET
  FILE='C:\SE demos\Assess\demo dataset v4.sav'.
DATASET NAME $DataSet WINDOW=FRONT.

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.

The below R syntax can be run in R version 2.5 to produce polychoric correlations from a SPSS data file without the need to use SPSS. Note : 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'.

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

None: FAQ/spsspoly (last edited 2013-03-08 10:17:37 by localhost)