Sākums > R > Calibration in SPSS with R plugin

Calibration in SPSS with R plugin

Another example of calibration of weights in SPSS using R plugin.

*** SPSS 17.0.0 and SPSS Statistics-R Plugin 17.0.0 for Win32.

*Example data.

dataset close all.

data list free
/x1 (f8) x2 (f8) x3 (f8) weight (f8.3).
begin data
1 0 1 5
1 0 2 5
1 0 3 5
1 0 4 5
1 0 5 5
0 1 6 5
0 1 7 5
0 1 8 5
0 1 9 5
0 1 10 5
end data.

dataset name data.

data list free
/totals (f8).
begin data
24
26
290
end data.

match files
/file data
/file *.

exe.

dataset close data.

* Calibration.

begin program r.

library(sampling)

DataIn=spssdata.GetDataFromSPSS()
k=ncol(DataIn)
calvar=as.matrix(DataIn[,1:(k-2)])
weight=as.vector(DataIn[,(k-1)])
totals=as.vector(DataIn[1:(k-2),k])
g=calib(calvar,weight,totals,method=”linear”,description=T)

VarSpec=c(“g”,”g-weights”,0,”F8.3″,”scale”)
Dict=spssdictionary.CreateSPSSDictionary(VarSpec)
spssdictionary.SetDictionaryToSPSS(“gweights”,Dict)
DataOut=data.frame(g)
spssdata.SetDataToSPSS(“gweights”,DataOut)
spssdictionary.EndDataStep()

end program.

match files
/file *
/file gweights
/drop totals.

exe.

dataset close gweights.

comp calweight=weight*g.
form calweight (f8.3).

weight by calweight.

freq x1 x2 x3
/form notable
/stat sum.

var wid all (12).

KategorijasR
  1. Vēl nav komentāru.
  1. No trackbacks yet.

Komentēt

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Mainīt )

Twitter picture

You are commenting using your Twitter account. Log Out / Mainīt )

Facebook photo

You are commenting using your Facebook account. Log Out / Mainīt )

Google+ photo

You are commenting using your Google+ account. Log Out / Mainīt )

Connecting to %s

%d bloggers like this: