|
Size: 1380
Comment:
|
Size: 2210
Comment:
|
| 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. Details with an 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 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 27: | Line 27: |
| The below R syntax can be run in R to produce polychoric correlations from a SPSS data file without the need to use SPSS. You will need to change the directory location and filename in the read.spss command and the variable names replacing PTCI1, PTCI2 etc. {{{ 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 }}} |
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 [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 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.]
The example SPSS data file is [attachment:polydat.sav 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 to produce polychoric correlations from a SPSS data file without the need to use SPSS. You will need to change the directory location and filename in the read.spss command and the variable names replacing PTCI1, PTCI2 etc.
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