ProtectTable {easySdcTable} | R Documentation |
Easy interface to sdcTable: Table suppression according to a frequency rule.
Description
GaussSuppression
, protectTable
or protect_linked_tables
is run with a data set as the only required input. One (stacked) or several (unstacked) input variables can hold cell counts.
ProtectTableData
is a tidy wrapper function, which returns a single data frame instead of a list (info
omitted).
Usage
ProtectTable(
data,
dimVar = 1:NCOL(data),
freqVar = NULL,
protectZeros = TRUE,
maxN = 3,
method = "Gauss",
findLinked = TRUE,
total = "Total",
addName = FALSE,
sep = "_",
removeZeros = FALSE,
dimList = NULL,
groupVarInd = NULL,
ind1 = NULL,
ind2 = NULL,
rowData = NULL,
varNames = paste("var", 1:100, sep = ""),
split = NULL,
border = sep,
revBorder = FALSE,
freqName = "values",
totalFirst = FALSE,
numericOrder = TRUE,
namesAsInput = TRUE,
orderAsInput = TRUE,
sortByReversedColumns = FALSE,
doUnstack = TRUE,
removeTotal = TRUE,
singleOutput = NULL,
suppression = NA,
outFreq = "freq",
outSdcStatus = "sdcStatus",
outSuppressed = "suppressed",
infoAsFrame = FALSE,
IncProgress = IncDefault,
verbose = FALSE,
...
)
ProtectTableData(data, ...)
Arguments
data |
data frame |
dimVar |
The main dimensional variables and additional aggregating variables (name or number). |
freqVar |
Variable(s) holding counts or NULL in the case of micro data (name or number). |
protectZeros |
When TRUE empty cells (count=0) is considered sensitive (i.e. same as allowZeros in |
maxN |
All cells having counts <= maxN are set as primary suppressed. |
method |
Parameter
Alternatively this parameter can be a named list specifying parameters for running tau-argus (see details).
See |
findLinked |
When TRUE, the function may find two linked tables and run protect_linked_tables. |
total |
String used to name totals. |
addName |
When TRUE the variable name is added to the level names, except for variables with most levels. |
sep |
A character string to separate when addName apply and when creating variable names. |
removeZeros |
When TRUE, rows with zero count will be removed from the data within the algorithm. |
dimList |
By default, hierarchies will be automatically found from data (see |
groupVarInd |
Possible manual specification of list defining the hierarchical
variable groups. When NULL (default) this information will be found automatically
by |
ind1 |
Coding of table 1 as indices referring to elements of groupVarInd. This information
will be found automatically
by |
ind2 |
Coding of table 2 as indices referring to elements of groupVarInd (as ind1 above). |
rowData |
Input to |
varNames |
The names of the extra dimVar variable(s) made when stacking in cases with several
freqvar variables. When length(varNames)>1 several variables may be found by |
split |
Parameter to |
border |
Parameter to |
revBorder |
Parameter to |
freqName |
Input to |
totalFirst |
Parameter controlling how output is sorted. |
numericOrder |
Parameter controlling how output is sorted. Output is character but sorting can be based on the numeric input variables. |
namesAsInput |
When TRUE those output variables (created by unstacking) that correspond to input will be named as input. |
orderAsInput |
When TRUE output corresponding to input will be ordered as input and kept together as one block. |
sortByReversedColumns |
When TRUE output will be sorted by variables in opposite order. |
doUnstack |
When FALSE output will not be unstacked (in cases with sever input freqvar variables) |
removeTotal |
When TRUE the total string (see total above) will be removed from the names of output variables created by unstacking (in cases with sever input freqvar variables). |
singleOutput |
When TRUE output will be in as single data set. Default is FALSE for unstacked data (in cases with sever input freqvar variables) and otherwise TRUE. |
suppression |
Value used for suppressed elements in suppressed output data. Default is NA. |
outFreq |
String used to name output variable(s) |
outSdcStatus |
String used to name output variable(s) |
outSuppressed |
String used to name output variable(s) |
infoAsFrame |
When TRUE output element info is a data frame (useful in Shiny). |
IncProgress |
A function to report progress (incProgress in Shiny). Set equal to NULL to turn it off. |
verbose |
Parameter sent to |
... |
Further parameters sent to |
Details
One or two tables are identified automatically and subjected to cell suppression
by protectTable
(single table) or protect_linked_tables
(two linked tables).
The tables can alternatively be specified manually by groupVarInd, ind1 and ind2.
The output will be on a form similiar to input depending on whether freqVar is a single variable or not.
The status of the cells are
coded as "u" (primary suppressed), "x" (secondary suppression), and "s" (can be published).
This is taken directly from the output from sdcTable. In cases with two linked tables "u" or "x"
for common cells are based on output from the first table.
-
To run tau-argus specify
method
as a named list containing the parameterexe
forrunArgusBatchFile
and other parameters forcreateArgusInput
.One may specify:
method = list(exe="C:/Tau/TauArgus.exe", typ="tabular", path= getwd(),
solver= "FREE", method= "OPT")
However these values of "exe", "path" and "solver" and "method" are set by default so in this case using "method = list(typ="tabular", method= "OPT")
" is equivalent.If
typ="microdata"
is specified. Necessary transformation to microdata will be made.
-
Wrapper methods (partly experimental): In the function
PTwrap
several additional methods are defined. If input to ProtectTable() is one of these methods ProtectTable() will be run via PTwrap(). So making explicit call to PTwrap() is not needed. -
Singleton and zeros: The parameter detectSingletons was included in protecttable to handle the so-called singleton problem that appers when
protectZeros=FALSE
. Not all problems were solved and the parameter threshold has been introduced later. The value of threshold needed depends on the number of singletons in one group. It seems thatthreshold=3
is equivalent todetectSingletons=TRUE
. WhenprotectZeros=TRUE
the related “zero problem” occurs. This problem is solved bythreshold=1
. -
NOTE: The use of numVarInd, weightInd and sampWeightInd in sdcTable is not implemented. This also limit possible input to tau-argus.
Value
When singleOutput=TRUE output is a list of two elements.
-
info
: Information as a single column character matrix. This is information about the extra dimVar variables created when stacking, information about the identified (linked) table(s) and summary output from sdcTable. Withmethod="Gauss"
, a sdcTable function is run withmaxN=0
to create a template for the real output. Some of the summary info is therefore misleading in this case. -
data
: A data frame where variables are named according to outFreq, outSdcStatus and outSuppressed. When singleOutput=FALSE output element data is replaced by three elements and these are named according to outFreq, outSdcStatus and outSuppressed.
Note
ProtectTable makes a call to the function ProtectTable1
.
See Also
See also the vignettes.
Examples
## Not run:
# ==== Example 1 , 8 regions ====
z1 <- EasyData("z1")
ProtectTable(z1,1:2, 3)
ProtectTableData(z1,1:2, 3)
ProtectTable(z1, c("region","hovedint"), "ant") # Input by name
# --- Unstacked input data ---
z1w = EasyData("z1w")
ProtectTable(z1w, 1, 2:5)
ProtectTableData(z1w, 1, 2:5)
ProtectTable(z1w, 1, 2:5, varName="hovedint")
ProtectTable(z1w, 1, 2:5, method="HITAS")
ProtectTable(z1w, 1, 2:5, totalFirst = TRUE, method ="Simple")
# ==== Example 2 , 11 regions ====
z2 <- EasyData("z2")
ProtectTable(z2,c(1,3,4), 5) # With region-variable kostragr
# --- Unstacked input data ---
z2w <- EasyData("z2w")
ProtectTable(z2w, 1:2, 4:7) # With region-variable fylke
ProtectTable(z2w, 1:3, 4:7) # Two linked tables
# ==== Example 3 , 36 regions ====
z3 <- EasyData("z3")
ProtectTable(z3, c(1,4,5), 7) # Three dimensions. No subtotals
ProtectTable(z3, 1:6, 7) # Two linked tables
# --- Unstacked input data with coded column names
z3w <- EasyData("z3w")
ProtectTable(z3w,1:3,4:15, varName="g12") # coding not used when single varName
ProtectTable(z3w,1:3,4:15, varName=c("hovedint","mnd")) # Two variables found automatically
ProtectTable(z3w,1:3,4:15, varName=c("hovedint","mnd"),
removeTotal=FALSE) # Keep "Total" in variable names
# --- Unstacked input data with three level column name coding
z3wb <- EasyData("z3wb")
ProtectTable(z3wb,1:3,4:15,varName=c("hovedint","mnd","mnd2")) # Two variables found automatically
ProtectTable(z3wb,1:3,4:15,varName=c("hovedint","mnd","mnd2"),
split="_") # Three variables when splitting
ProtectTable(z3wb,1:3,4:15,varName=c("hovedint","mnd","mnd2"),
split="_",namesAsInput=FALSE,orderAsInput=FALSE) # Alternative ouput format
# ==== Examples Tau-Argus ====
exeArgus <- "C:/TauArgus4.1.4/TauArgus.exe" # Change to TauArgus.exe-path in your computer
pathArgus <- "C:/Users/nnn/Documents" # Change to an existing folder
z1 = EasyData("z1")
ProtectTable(z1,1:2,3,method=list(exe=exeArgus, path=pathArgus, typ="tabular", method="OPT"))
ProtectTable(z1,1:2,3,method=list(exe=exeArgus, path=pathArgus, typ="tabular", method="MOD"))
ProtectTable(z1,1:2,3,method=list(exe=exeArgus, path=pathArgus, typ="tabular", method="GH"))
ProtectTable(z1,1:2,3,maxN=-1,
method=list(path=pathArgus, exe=exeArgus, method="OPT",
primSuppRules= list(list(type="freq", n=4, rg=20))))
z3 <- EasyData("z3")
ProtectTable(z3,c(1:2,4,5),7,maxN=-1,
method=list(path=pathArgus, exe=exeArgus, method="OPT",
primSuppRules=list(list(type="freq", n=4, rg=20))))
# ==== Examples with parameter dimList ====
z2 <- EasyData("z2")
dList <- FindDimLists(z2[-5])
ProtectTable(z2[, c(1,4,5)], 1:2, 3, dimList = dList[c(1,3)])
ProtectTable(z2[, c(1,4,5)], 1:2, 3, dimList = dList[2])
ProtectTable(z2[, c(1,4,5)], 1:2, 3, dimList = DimList2Hrc(dList[c(2,3)]))
## End(Not run)