Method new()
Create a new table instance
Usage
ck_class$new(x, rkey, dims, w = NULL, countvars = NULL, numvars = NULL)
Arguments
x
an object coercible to a data.frame
rkey
either a column name within x referring to a variable containing record keys
or a single integer(ish) number > 5 that referns to the number of digits for record keys that
will be generated internally.
dims
a list containing slots for each variable that should be
tabulated. Each slot consists should be created/modified using sdcHierarchies::hier_create(),
sdcHierarchies::hier_add() and other functionality from package sdcHierarchies.
w
(character) a scalar character referring to a variable in x holding sampling
weights. If w is NULL (the default), all weights are assumed to be 1
countvars
(character) an optional vector containing names of binary (0/1 coded)
variables withing x that should be included in the problem instance.
These variables can later be perturbed.
numvars
(character) an optional vector of numerical variables that can later be tabulated.
Returns
A new cellkey_obj object. Such objects (internally) contain the fully computed
statistical tables given input microdata (x), the hierarchical definitionals (dims) as
well as the remaining inputs. Intermediate results are stored internally and can only be
modified / accessed via the exported public methods described below.
Method perturb()
Perturb a count- or magnitude variable
Usage
ck_class$perturb(v)
Arguments
v
name(s) of count- or magnitude variables that should be perturbed.
Returns
A modified cellkey_obj object in which private slots were
updated for side-effects. Updated data can be accessed using other exported
methods like $freqtab() or $numtab().
Method freqtab()
Extract results from already perturbed count variables as a
data.table
Usage
ck_class$freqtab(v = NULL, path = NULL)
Arguments
v
a vector of variable names for count variables. If NULL
(the default), the results are returned for all available count
variables. For variables that have not yet perturbed, columns
puwc and pwc are filled with NA.
path
if not NULL, a scalar character defining a (relative
or absolute) path to which the result table should be written. A csv
file will be generated and, if specified, path must have
".csv" as file-ending
Returns
This method returns a data.table containing all combinations of the dimensional variables in
the first n columns. Additionally, the following columns are shown:
vname: name of the perturbed variable
uwc: unweighted counts
wc: weighted counts
puwc: perturbed unweighted counts or NA if vname was not yet perturbed
pwc: perturbed weighted counts or NA if vname was not yet perturbed
Method numtab()
Extract results from already perturbed continuous variables
as a data.table.
Usage
ck_class$numtab(v = NULL, mean_before_sum = FALSE, path = NULL)
Arguments
v
a vector of variable names of continuous variables. If NULL
(the default), the results are returned for all available numeric variables.
mean_before_sum
(logical); if TRUE, the perturbed values are adjusted
by a factor ((n+p))⁄n with
This makes sense if the the accuracy of the variable mean is considered to be
more important than accuracy of sums of the variable. The default value is
FALSE (no adjustment is done)
path
if not NULL, a scalar character defining a (relative or absolute)
path to which the result table should be written. A csv file will be generated
and, if specified, path must have ".csv" as file-ending
Returns
This method returns a data.table containing all combinations of the
dimensional variables in the first n columns. Additionally, the following
columns are shown:
vname: name of the perturbed variable
uws: unweighted sum of the given variable
ws: weighted cellsum
pws: perturbed weighted sum of the given cell or NA if vname
has not not perturbed
Method measures_cnts()
Utility measures for perturbed count variables
Usage
ck_class$measures_cnts(v, exclude_zeros = TRUE)
Arguments
v
name of a count variable for which utility measures
should be computed.
exclude_zeros
should empty (zero) cells in the original values
be excluded when computing distance measures
Returns
This method returns a list containing a set of utility
measures based on some distance functions. For a detailed description
of the computed measures, see ck_cnt_measures()
Method measures_nums()
Utility measures for continuous variables (not yet implemented)
Usage
ck_class$measures_nums(v)
Arguments
v
name of a continuous variable for which utility measures
should be computed.
Returns
for (now) an empty list; In future versions of the package, the
Method will return utility measures for perturbed magnitude tables.
Method allvars()
Names of variables that can be perturbed / tabulated
Returns
returns a list with the following two elements:
Method cntvars()
Names of count variables that can be perturbed
Returns
a character vector containing variable names
Method numvars()
Names of continuous variables that can be perturbed
Returns
a character vector containing variable names
Method hierarchy_info()
Information about hierarchies
Usage
ck_class$hierarchy_info()
Returns
a list (for each dimensional variable) with
information on the hierarchies. This may be used to restrict output tables to
specific levels or codes. Each list element is a data.table containing
the following variables:
code: the name of a code within the hierarchy
level: number defining the level of the code; the higher the number,
the lower the hierarchy with 1 being the overall total
is_leaf: if TRUE, this code is a leaf node which means no other codes
contribute to it
parent: name of the parent code
Method mod_cnts()
Modifications applied to count variables
Usage
ck_class$mod_cnts()
Returns
a data.table containing modifications applied to count variables
Method mod_nums()
Modifications applied to numerical variables
Usage
ck_class$mod_nums()
Returns
a data.table containing modifications applied to numerical variables
Method supp_freq()
Identify sensitive cells based on minimum frequency rule
Usage
ck_class$supp_freq(v, n, weighted = TRUE)
Arguments
v
a single variable name of a continuous variable (see method numvars())
n
a number defining the threshold. All cells <= n are considered as unsafe.
weighted
if TRUE, the weighted number of contributors to a cell are compared to
the threshold specified in n (default); else the unweighted number of contributors is used.
Returns
A modified cellkey_obj object in which private slots were
updated for side-effects. These updated values are used by other methods (e.g $perturb()).
Method supp_val()
Identify sensitive cells based on weighted or unweighted cell value
Usage
ck_class$supp_val(v, n, weighted = TRUE)
Arguments
v
a single variable name of a continuous variable (see method numvars())
n
a number defining the threshold. All cells <= n are considered as unsafe.
weighted
if TRUE, the weighted cell value of variable v is compared to
the threshold specified in n (default); else the unweighted number is used.
Returns
A modified cellkey_obj object in which private slots were
updated for side-effects. These updated values are used by other methods (e.g $perturb()).
Method supp_cells()
Identify sensitive cells based on their names
Usage
ck_class$supp_cells(v, inp)
Arguments
v
a single variable name of a continuous variable (see method numvars())
inp
a data.frame where each colum represents a dimensional variable. Each row of
this input is then used to compute the relevant cells to be identified as sensitive where
NA-values are possible and used to match any characteristics of the dimensional variable.
Returns
A modified cellkey_obj object in which private slots were
updated for side-effects. These updated values are used by other methods (e.g $perturb()).
Method supp_p()
Identify sensitive cells based on the p%-rule rule. Please note that this rule
can only be applied to positive-only variables.
Usage
ck_class$supp_p(v, p)
Arguments
v
a single variable name of a continuous variable (see method numvars())
p
a number defining a percentage between 1 and 99.
Returns
A modified cellkey_obj object in which private slots were
updated for side-effects. These updated values are used by other methods (e.g $perturb()).
Method supp_pq()
Identify sensitive cells based on the pq-rule. Please note that this rule
can only be applied to positive-only variables.
Usage
ck_class$supp_pq(v, p, q)
Arguments
v
a single variable name of a continuous variable (see method numvars())
p
a number defining a percentage between 1 and 99.
q
a number defining a percentage between 1 and 99. This value must be larger than p.
Returns
A modified cellkey_obj object in which private slots were
updated for side-effects. These updated values are used by other methods (e.g $perturb()).
Method supp_nk()
Identify sensitive cells based on the nk-dominance rule. Please note that this rule
can only be applied to positive-only variables.
Usage
ck_class$supp_nk(v, n, k)
Arguments
v
a single variable name of a continuous variable (see method numvars())
n
an integerish number >= 2
k
a number defining a percentage between 1 and 99. All cells to which the top n
contributers contribute more than k% is considered unsafe
Returns
A modified cellkey_obj object in which private slots were
updated for side-effects. These updated values are used by other methods (e.g $perturb()).
Method params_cnts_get()
Return perturbation parameters of count variables
Usage
ck_class$params_cnts_get()
Returns
a named list in which each list-element contains the
active perturbation parameters for the specific count variable
defined by the list-name.
Method params_cnts_set()
Set perturbation parameters for count variables
Usage
ck_class$params_cnts_set(val, v = NULL)
Arguments
val
a perturbation object created with ck_params_cnts()
v
a character vector (or NULL). If NULL (the default),
the perturbation parameters provided in val are set for all
count variables; otherwise one may specify the names of
the count variables for which the parameters should be set.
Returns
A modified cellkey_obj object in which private slots were
updated for side-effects. These updated values are used by other
methods (e.g $perturb()).
Method reset_cntvars()
reset results and parameters for already perturbed
count variables
Usage
ck_class$reset_cntvars(v = NULL)
Arguments
v
if v equals NULL (the default), the results are reset
for all perturbed count variables; otherwise it is possible to specify
the names of already perturbed count variables.
Returns
A modified cellkey_obj object in which private slots were
updated for side-effects. These updated values are used by other
methods (e.g $perturb() or $freqtab()).
Method reset_numvars()
reset results and parameters for already perturbed
numerical variables
Usage
ck_class$reset_numvars(v = NULL)
Arguments
v
if v equals NULL (the default), the results are reset for all perturbed
numerical variables; otherwise it is possible to specify the names of already
perturbed continuous variables.
Returns
A modified cellkey_obj object in which private slots were
updated for side-effects. These updated values are used by other
methods (e.g $perturb() or $numtab()).
Method reset_allvars()
reset results and parameters for all already perturbed variables.
Usage
ck_class$reset_allvars()
Returns
A modified cellkey_obj object in which private slots were
updated for side-effects. These updated values are used by other
methods (e.g $perturb(), $freqtab() or $numtab()).
Method params_nums_get()
Return perturbation parameters of continuous variables
Usage
ck_class$params_nums_get()
Returns
a named list in which each list-element contains the
active perturbation parameters for the specific continuous variable
defined by the list-name.
Method params_nums_set()
set perturbation parameters for continuous variables.
Usage
ck_class$params_nums_set(val, v = NULL)
Arguments
val
a perturbation object created with ck_params_nums()
v
a character vector (or NULL); if NULL (the default), the
perturbation parameters provided in val are set for all continuous
variables; otherwise one may specify the names of the numeric variables for
which the parameters should be set.
Returns
A modified cellkey_obj object in which private slots were
updated for side-effects. These updated values are used by other
methods (e.g $perturb()).
some aggregated summary statistics about perturbed variables
prints information about the current table