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 primarySuppression).

maxN

All cells having counts <= maxN are set as primary suppressed.

method

Parameter method in protectTable, protect_linked_tables or wrapper methods via PTwrap. Gauss (default) is implemented independently of sdcTable. There is also a similar variant implemented in sdcTable as GAUSS. But this implementation is not as optimal and Gauss is recommended instead.

  • "SIMPLEHEURISTIC": This method is default in protectable.

  • "SIMPLEHEURISTIC_OLD": As "SIMPLEHEURISTIC" in sdcTable versions prior to 0.32.

  • "OPT", "HITAS", "HYPERCUBE", "GAUSS": Other methods in protectable. "HYPERCUBE" is not possible in cases with two linked tables.

  • "SimpleSingle": "SIMPLEHEURISTIC_OLD" with detectSingletons=TRUE when protectZeros=FALSE and "SIMPLEHEURISTIC_OLD" with threshold=1 (can be overridden by input) when protectZeros=TRUE.

  • "SIMPLEHEURISTICSingle": As "SimpleSingle" with "SIMPLEHEURISTIC" instead of "SIMPLEHEURISTIC_OLD".

  • "Simple": "SIMPLEHEURISTIC_OLD" with detectSingletons=FALSE.

  • "Gauss": GaussSuppression is called with parameters x, candidates, primary and singleton automatically generated. Other parameters (singletonMethod, printInc) can be specified.

Alternatively this parameter can be a named list specifying parameters for running tau-argus (see details). See PTwrap for other (experimental) wrapper methods (see details).

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 FindDimLists). With non-NULL dimList, these will be changed. In practice this is done by the function ReplaceDimList.

groupVarInd

Possible manual specification of list defining the hierarchical variable groups. When NULL (default) this information will be found automatically by FindTableGroup.

ind1

Coding of table 1 as indices referring to elements of groupVarInd. This information will be found automatically by FindTableGroup when groupVarInd=NULL.

ind2

Coding of table 2 as indices referring to elements of groupVarInd (as ind1 above).

rowData

Input to Stack used to generate extra dimVar variables when stacking in cases with several freqvar variables. When NULL rowData will be created automatically by AutoSplit using varNames (see below) and the the freqvar names as input.

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 AutoSplit.

split

Parameter to AutoSplit - see varNames and rowData above. When NULL (default), automatic splitting without needing a split string.

border

Parameter to AutoSplit - see varNames and rowData above.

revBorder

Parameter to AutoSplit - see varNames and rowData above..

freqName

Input to Stack. The name of the new freqvar variable obtained when stacking in cases with several input freqvar variables.

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 protectTable, protect_linked_tables or runArgusBatchFile.

...

Further parameters sent to protectTable (possibly via protect_linked_tables) such as timeLimit. Parameters to GaussSuppression, createArgusInput and PTwrap is also possible (see details).

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.

Value

When singleOutput=TRUE output is a list of two elements.

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)
              

[Package easySdcTable version 1.0.7 Index]