Learn R Programming

sdcMicro (version 4.6.0)

pram: Post Randomization

Description

To be used on categorical data. It randomly change the values of variables on selected records (usually the risky ones) according to an invariant probability transition matrix.

Usage

pram(obj, variables = NULL, strata_variables = NULL, pd = 0.8, alpha = 0.5)

Arguments

obj
Input data. Allowed input data are objects of class 'matrix', 'data.frame', 'vector' or sdcMicroObj-class.
variables
Names of variables in 'obj' on which post-randomization should be applied. If obj is a vector, this argument is ignored.
strata_variables
Names of variables for stratification (will be set automatically for an object of class sdcMicroObj-class. One can also specify an integer vector or factor that specifies that desired groups. This vector must match the dimension of the input data set, however. For a possible use case, have a look at the examples.
pd
minimum diagonal entries for the generated transition matrix P. Either a vector of length 1 or a vector of length ( number of categories ).
alpha
amount of perturbation for the invariant Pram method
...
further input, currently ignored.

Value

a modified sdcMicroObj-class object or a new object containing original and post-randomized variables (with suffix "_pram").

Methods

list("signature(obj = \"sdcMicroObj\")")
...
list("signature(obj = \"data.frame\")")
...
list("signature(obj = \"matrix\")")
...
list("signature(obj = \"vector\")")
...

References

http://www.gnu.org/software/glpk

http://www.ccsr.ac.uk/sars/guide/2001/pram.pdf

Examples

Run this code
data(testdata)
res <- pram(testdata,
  variables="roof",
  strata_variables=c("urbrur","sex"))
print(res)

res1 <- pram(testdata,variables=c("roof","walls","water"),strata_variables=c("urbrur","sex"))
print(res1)

res2 <- pram(testdata,variables=c("roof","walls","water"),
  strata_variables=NULL)
print(res2)

## for objects of class sdcMicro:
data(testdata2)
sdc <- createSdcObj(testdata2,
  keyVars=c('roof','walls','water','electcon','relat','sex'),
  numVars=c('expend','income','savings'), w='sampling_weight')
sdc <- pram(sdc, variables=c("urbrur"))

# this is equal to the previous application:
sdc <- createSdcObj(testdata2,
  keyVars=c('roof','walls','water','electcon','relat','sex'),
  numVars=c('expend','income','savings'), w='sampling_weight',
  pramVars="urbrur")
sdc <- pram(sdc)

## using a custom strata variable
# we want to apply pram to variable 'urbrur' for each group of variable 'urbrur'
# however: values no value should be changed where roof==4
# thus, we are creating a new value for these observations
data(testdata)
sdc <- createSdcObj(testdata,
  keyVars=c('walls','water','electcon','relat','sex'),
  numVars=c('expend','income','savings'), w='sampling_weight')
sv <- testdata$urbrur
# new category for those that observations that should not change:
sv[testdata$roof==4] <- max(sv)+1
sdc <- pram(sdc, variables=c("roof"), strata_variables=sv)
orig <- get.sdcMicroObj(sdc, "origData")$roof
pramed <- get.sdcMicroObj(sdc, "manipPramVars")$roof
all(pramed[orig==4]==4) # nothing has changed!

Run the code above in your browser using DataLab