# loading micro data from sdcTable
utils::data("microdata1", package="sdcTable")
microdata1$num1 <- rnorm(mean = 100, sd = 25, nrow(microdata1))
microdata1$num2 <- round(rnorm(mean = 500, sd=125, nrow(microdata1)),2)
microdata1$weight <- sample(10:100, nrow(microdata1), replace = TRUE)
dim_region <- hier_create(root = "Total", nodes = LETTERS[1:4])
dim_region_dupl <- hier_create(root = "Total", nodes = LETTERS[1:4])
dim_region_dupl <- hier_add(dim_region_dupl, root = "B", nodes = c("b1"))
dim_region_dupl <- hier_add(dim_region_dupl, root = "D", nodes = c("d1"))
dim_gender <- hier_create(root = "Total", nodes = c("male", "female"))
dimList <- list(region = dim_region, gender = dim_gender)
dimList_dupl <- list(region = dim_region_dupl, gender = dim_gender)
dimVarInd <- 1:2
numVarInd <- 3:5
sampWeightInd <- 6
# creating an object of class \code{\link{sdcProblem-class}}
obj <- makeProblem(
data = microdata1,
dimList = dimList,
dimVarInd = dimVarInd,
numVarInd = numVarInd,
sampWeightInd = sampWeightInd)
# creating an object of class \code{\link{sdcProblem-class}} containing "duplicated" codes
obj_dupl <- makeProblem(
data = microdata1,
dimList = dimList_dupl,
dimVarInd = dimVarInd,
numVarInd = numVarInd,
sampWeightInd = sampWeightInd)
## create primary suppression rules
primSuppRules <- list()
primSuppRules[[1]] <- list(type = "freq", n = 5, rg = 20)
primSuppRules[[2]] <- list(type = "p", n = 5, p = 20)
# other supported formats are:
# list(type = "nk", n=5, k=20)
# list(type = "zero", rg = 5)
# list(type = "mis", val = 1)
# list(type = "wgt", val = 1)
# list(type = "man", val = 20)
## create batchInput object
bO_md1 <- createArgusInput(
obj = obj,
typ = "microdata",
path = tempdir(),
solver = "FREE",
method = "OPT",
primSuppRules = primSuppRules,
responsevar = "num1")
bO_td1 <- createArgusInput(
obj = obj,
typ = "tabular",
path = tempdir(),
solver = "FREE",
method = "OPT")
bO_td2 <- createArgusInput(
obj = obj_dupl,
typ = "tabular",
path = tempdir(),
solver = "FREE",
method = "OPT")
if (FALSE) {
## in case CPLEX should be used, it is required to specify argument licensefile
bO_md2 <- createArgusInput(
obj = obj,
typ = "microdata1",
path = tempdir(),
solver = "CPLEX",
method = "OPT",
primSuppRules = primSuppRules,
responsevar = "num1",
licensefile = "/path/to/my/cplexlicense")
}
Run the code above in your browser using DataLab