Swapping values within a range so that, first, the correlation structure of original variables are preserved, and second, the values in each record are disturbed. To be used on numeric or ordinal variables where the rank can be determined and the correlation coefficient makes sense.
rankSwap(
obj,
variables = NULL,
TopPercent = 5,
BottomPercent = 5,
K0 = NULL,
R0 = NULL,
P = NULL,
missing = NA,
seed = NULL
)a sdcMicroObj-class-object or a data.frame
names or index of variables for that rank swapping is
applied. For an object of class sdcMicroObj-class, all numeric key variables are
selected if variables=NULL.
Percentage of largest values that are grouped together before rank swapping is applied.
Percentage of lowest values that are grouped together before rank swapping is applied.
Subset-mean preservation factor. Preserves the means before and after rank swapping within a range based on K0. K0 is the subset-mean preservation factor such that \(| X_1 -X_2 | \leq \frac{2 K_0 X_1}{\sqrt(N_S)}\), where \(X_1\) and \(X_2\) are the subset means of the field before and after swapping, and \(N_S\) is the sample size of the subset.
Multivariate preservation factor. Preserves the correlation between variables within a certain range based on the given constant R0. We can specify the preservation factor as \(R_0=\frac{R_1}{R_2}\) where \(R_1\) is the correlation coefficient of the two fields after swapping, and \(R_2\) is the correlation coefficient of the two fields before swapping.
Rank range as a proportion (not a percentage) of the number of
swappable records, a value between 0 and 1; use P = 0.1 for a 10%
rank range. For the value at rank \(j\) among the swappable values, the
swap partner is drawn at random from the not yet swapped values at ranks
\(k\) with \(j < k < j + P N_s\), where
\(N_s\) is the number of swappable records: the number of
observations minus missing values and the values grouped by
TopPercent and BottomPercent.
missing - the value to be used as missing value in the C++ routine instead of NA. If NA, a suitable value is calculated internally. Note that in the returned dataset, all NA-values (if any) will be replaced with this value.
Seed.
The rank-swapped data set or a modified sdcMicroObj-class object.
Rank swapping sorts the values of one numeric variable by their numerical
values (ranking). The restricted range is determined by the rank of two
swapped values, which cannot differ by more than a proportion P of
the number of swappable records. Missing values and the values grouped by
TopPercent and BottomPercent are not swapped and do not count
as swappable records. Only non-negative P, R0 and K0 are used and only one
of them must be supplied. If none is supplied, sdcMicro sets parameter R0 to
0.95 internally. If R0 or K0 is supplied, the rank range is
derived from it for each variable.
Note that P is a proportion, whereas TopPercent and
BottomPercent are percentages: a 10% rank range is P = 0.1,
while 5% top coding is TopPercent = 5. Values of P larger
than 1 do not restrict the rank range at all and raise a warning.
Moore, Jr.R. (1996) Controlled data-swapping techniques for masking public use microdata, U.S. Bureau of the Census Statistical Research Division Report Series, RR 96-04.
Kowarik, A. and Templ, M. and Meindl, B. and Fonteneau, F. and Prantner, B.: Testing of IHSN Cpp Code and Inclusion of New Methods into sdcMicro, in: Lecture Notes in Computer Science, J. Domingo-Ferrer, I. Tinnirello (editors.); Springer, Berlin, 2012, ISBN: 978-3-642-33626-3, pp. 63-77. doi:10.1007/978-3-642-33627-0_6
data(testdata2)
data_swap <- rankSwap(
obj = testdata2,
variables = c("age", "income", "expend", "savings")
)
#> setting parameter R0 = 0.95 as no inputs have been specified.
## for objects of class sdcMicro:
data(testdata2)
sdc <- createSdcObj(
dat = testdata2,
keyVars = c("urbrur", "roof", "walls", "water", "electcon", "relat", "sex"),
numVars = c("expend", "income", "savings"),
w = "sampling_weight")
sdc <- rankSwap(sdc)
#> setting parameter R0 = 0.95 as no inputs have been specified.