% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/protectLinkedTables.R,
%   R/protect_linked_tables.R
\name{protectLinkedTables}
\alias{protectLinkedTables}
\alias{protect_linked_tables}
\title{Protect two tables with common cells}
\usage{
protectLinkedTables(
  objectA,
  objectB,
  commonCells,
  method = "SIMPLEHEURISTIC",
  ...
)

protect_linked_tables(x, y, common_cells, method = "SIMPLEHEURISTIC", ...)
}
\arguments{
\item{objectA}{maps to argument \code{x} in \code{\link[=protect_linked_tables]{protect_linked_tables()}}}

\item{objectB}{maps to argument \code{y} in \code{\link[=protect_linked_tables]{protect_linked_tables()}}}

\item{commonCells}{maps to argument \code{common_cells} in \code{\link[=protect_linked_tables]{protect_linked_tables()}}}

\item{method}{which protection algorithm should be used; choices are
\code{"SIMPLEHEURISTIC"} and \code{"SIMPLEHEURISTIC_OLD"}}

\item{...}{additional arguments to control the secondary cell suppression
algorithm. For details, see \code{\link[=protectTable]{protectTable()}}.}

\item{x}{a \link[=sdcProblem-class]{sdcProblem} object}

\item{y}{a \link[=sdcProblem-class]{sdcProblem} object}

\item{common_cells}{a list object defining common cells in
\code{x} and \code{y}. For each variable that has one or more common
codes in both tables, a list element needs to be specified.
\itemize{
\item List-elements of length \code{3}: Variable has exact same levels and structure
in both input tables
\itemize{
\item \verb{first element}: scalar character vector specifying the variable
name in argument \code{x}
\item \verb{second element}: scalar character vector specifying the variable
name in argument \code{y}
\item \verb{third element}: scalar character vector being with keyword \code{"ALL"}
}
\item List-elements of length \code{4}: Variable has different codes and levels
in inputs \code{x} and \code{y}
\itemize{
\item \verb{first element}: scalar character vector specifying the variable
name in argument \code{x}
\item \verb{second element}: scalar character vector specifying the variable
name in argument \code{y}
\item \verb{third element}: character vector defining codes within \code{x}
\item \verb{fourth element}: character vector with length that equals the length
of the third list-element. This vector defines codes of the dimensional
variable in \code{y} that match the codes given in the third list-element
for \code{x}.
}
}}
}
\value{
a list elements \code{x} and \code{y} containing protected \code{sdcProblem} objects
}
\description{
\code{\link[=protect_linked_tables]{protect_linked_tables()}} can be used to protect tables that have
common cells. It is of course required that after the anonymization process
has finished, all common cells have the same anonymization state in both
tables.
}
\examples{
\dontrun{
# load micro data for further processing
utils::data("microdata2", package = "sdcTable")

# table1: defined by variables 'gender' and 'ecoOld'
md1 <- microdata2[,c(2,3,5)]

# table2: defined by variables 'region', 'gender' and 'ecoNew'
md2 <- microdata2[,c(1,2,4,5)]

# we need to create information on the hierarchies
# variable 'region': exists only in md2
d_region <- hier_create(root = "Tot", nodes = c("R1", "R2"))

# variable 'gender': exists in both datasets
d_gender <- hier_create(root = "Tot", nodes = c("m", "f"))

# variable 'eco1': exists only in md1
d_eco1 <- hier_create(root = "Tot", nodes = c("A", "B"))
d_eco1 <- hier_add(d_eco1, root = "A", nodes = c("Aa", "Ab"))
d_eco1 <- hier_add(d_eco1, root = "B", nodes = c("Ba", "Bb"))

# variable 'ecoNew': exists only in md2
d_eco2 <- hier_create(root = "Tot", nodes = c("C", "D"))
d_eco2 <- hier_add(d_eco2, root = "C", nodes = c("Ca", "Cb", "Cc"))
d_eco2 <- hier_add(d_eco2, root = "D", nodes = c("Da", "Db", "Dc"))

# creating objects holding information on dimensions
dl1 <- list(gender = d_gender, ecoOld = d_eco1)
dl2 <- list(region = d_region, gender = d_gender, ecoNew = d_eco2)

# creating input objects for further processing.
# For details, see ?makeProblem.
p1 <- makeProblem(
  data = md1,
  dimList = dl1,
  dimVarInd = 1:2,
  numVarInd = 3)

p2 <- makeProblem(
  data = md2,
  dimList = dl2,
  dimVarInd = 1:3,
  numVarInd = 4)

# the cell specified by gender == "Tot" and ecoOld == "A"
# is one of the common cells! -> we mark it as primary suppression
p1 <- change_cellstatus(
  object = p1,
  specs = data.frame(gender = "Tot", ecoOld = "A"),
  rule = "u",
  verbose = FALSE)

# the cell specified by region == "Tot" and gender == "f" and ecoNew == "C"
# is one of the common cells! -> we mark it as primary suppression
p2 <- change_cellstatus(
  object = p2,
  specs = data.frame(region = "Tot", gender = "f", ecoNew = "C"),
  rule = "u",
  verbose = FALSE)

# specifying input to define common cells
common_cells <- list()

# variable "gender"
common_cells$v.gender <- list()
common_cells$v.gender[[1]] <- "gender" # variable name in "p1"
common_cells$v.gender[[2]] <- "gender" # variable name in "p2"

# "gender" has equal characteristics on both datasets -> keyword "ALL"
common_cells$v.gender[[3]] <- "ALL"

# variables: "ecoOld" and "ecoNew"
common_cells$v.eco <- list()
common_cells$v.eco[[1]] <- "ecoOld" # variable name in "p1"
common_cells$v.eco[[2]] <- "ecoNew" # variable name in "p2"

# vector of common characteristics:
# "A" and "B" in variable "ecoOld" in "p1"
common_cells$v.eco[[3]] <- c("A", "B")

# correspond to codes "C" and "D" in variable "ecoNew" in "p2"
common_cells$v.eco[[4]] <- c("C", "D")

# protect the linked data
result <- protect_linked_tables(
  x = p1,
  y = p2,
  common_cells = common_cells,
  verbose = TRUE)

# having a look at the results
result_tab1 <- result$x
result_tab2 <- result$y
summary(result_tab1)
summary(result_tab2)
}
}
\seealso{
\code{\link[=protectTable]{protectTable()}}
}
\author{
Bernhard Meindl \email{bernhard.meindl@statistik.gv.at}
}
