简体   繁体   中英

reading data from spss file and using stat package

I usually use spss but needed to use a special stats package in R for the same dataset. I have found ways to read my spss data into r but I need to analyze this data with a statistical package.

The code I have to read the data is:

>RED.data<-read.spss("RED.sav", use.value.labels=TRUE, to.data.frame=TRUE)

The code for the stats package:

>library(twang)
>data(DTA)
>set.seed(1)
>mnps.RED<-mnps(treat~illact+crimjust+subprob, data=RED, estimand="ATT", verbose=FALSE, stop.method=c("es.mean", "ks.mean"), n.trees=3000)

I know I am missing a step between these but can't figure this out so far. I am confused about the formats of the data and their usage. What is the difference between the codes below and how can I use them?

>RED=read.csv("RED.csv")
>attach(RED)
>data(RED)

Thanks for your help!

Why not use the SPSS Statistics R integration apis for this? You would read the data into Statistics and then run R code like this. begin program r. dta = spssdata.GetDataFromSPSS() mnps.RED<-mnps(treat~illact+crimjust+subprob, data=data, estimand...) print(mnps.RED) # or whateverd else you need from the output. end program.

You need to install the appropriate version of R and the free R Essentials for your version of Statistics to make this work. More details can be provided if you indicate what version of Statistics and what platform you are using.

Thanks for the help, JKP and Laterow. I'm using R 3.2.3 and SPSS 23.

Also, I made a mistake in the code in the original question. Here is the code again: This is what I found for reading SPSS data into R :

require(foreign)

RED.data<-read.spss("RED.sav", use.value.labels=TRUE, to.data.frame=TRUE)

but I am not sure it is necessary to do this if I want to analyze the data with the "twang" package code below:

library(twang)

data(RED)

set.seed(1)

mnps.RED<-mnps(treat~illact+crimjust+subprob, data=RED, estimand="ATT", verbose=FALSE, stop.method=c("es.mean", "ks.mean"), n.trees=3000)

JKP, I'm a little confused about the code you provided. Do I need to enter this into SPSS syntax only?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM