% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/primarySuppression.R
\name{primarySuppression}
\alias{primarySuppression}
\title{Apply primary suppression}
\usage{
primarySuppression(object, type, ...)
}
\arguments{
\item{object}{an \link[=sdcProblem-class]{sdcProblem} object.}

\item{type}{character string defining the primary suppression rule.
Allowed values are:
\itemize{
\item \code{"freq"}: apply frequency rule (uses \code{maxN} and \code{allowZeros}).
\item \code{"nk"}: apply nk-dominance rule (uses \code{n} and \code{k}).
\item \code{"p"}: apply p-percent rule (uses \code{p}).
\item \code{"pq"}: apply pq-rule (uses \code{p} and \code{q}).
}}

\item{...}{parameters for the selected primary suppression rule:
\itemize{
\item \code{maxN}: scalar integerish; cells with counts <= \code{maxN} are suppressed. Defaults to \code{3}.
\item \code{allowZeros}: scalar logical; if \code{TRUE}, empty cells (frequency \code{0}) are considered sensitive.
Defaults to \code{FALSE}. Empty cells not flagged as sensitive are marked as \code{z}
(published, but not used for secondary suppression).
\item \code{p}: scalar integerish; threshold parameter for \code{p}-percent or \code{pq}-rules.
Defaults to \code{80}.
\item \code{q}: scalar numeric; threshold parameter for pq-rule. Defaults to \code{50}.
\item \code{n}: scalar integerish; parameter \code{n} for the nk-dominance rule. Defaults to \code{2}.
\item \code{k}: scalar integerish; parameter \code{k} for the nk-dominance rule. Defaults to \code{85}.
\item \code{numVarName}: scalar character; the name of the numerical variable used
for dominance-based rules. This is mandatory for \code{nk}, \code{p}, and \code{pq} rules.
}}
}
\value{
an \link[=sdcProblem-class]{sdcProblem} object.
}
\description{
\code{\link[=primarySuppression]{primarySuppression()}} identifies and suppresses primary sensitive table cells
within \link[=sdcProblem-class]{sdcProblem} objects based on specified rules.
}
\details{
Currently, the \code{frequency} rule, \code{nk}-dominance rule, \code{p}-percent rule
and \code{pq}-rule are supported.

Note: Since version \code{0.29}, dominance-based rules (\code{"p"}, \code{"pq"}, or \code{"nk"})
require the identification of the numerical variable by name using the
\code{numVarName} argument. Identification by index is no longer supported.
}
\note{
The ``nk\verb{-dominance, }p`-percent, and `pq`-rules require microdata as input to
\code{\link[=makeProblem]{makeProblem()}}.
}
\section{Cell Status Codes}{


When an object of class \code{sdcProblem} is created, every cell is assigned an
internal anonymization state. These codes track the lifecycle of a
cell throughout the suppression process:
\itemize{
\item \code{"s"} (\emph{"Publishable"}): The cell is safe and can be published (default).
\item \code{"z"}(\emph{"Forced Publishable"}): The cell must not be suppressed under any
circumstances.
\item \code{"u"} (*"Primary Suppressed"): The cell is identified as sensitive and
requires protection (typically assigned via \code{\link[=primarySuppression]{primarySuppression()}}).
\item \code{"x"} (\emph{"Secondary Suppressed"}): The cell is suppressed to protect
primary sensitive cells (typically assigned via \code{\link[=protectTable]{protectTable()}}).
\item \code{"w"} (\emph{"Extension Cell"}): The cell exists in the object but will never
be published. It is treated as a suppressed cell by internal algorithms.
This is useful if it is known in advance that specific codes of a hierarchy
will be excluded from publication.
}

Initially in \code{\link[=makeProblem]{makeProblem()}}, cells are coded as \code{"s"} or \code{"z"}. Their
status transitions to \code{"u"} or \code{"x"} as suppression algorithms are applied.

While \code{\link[=setInfo]{setInfo()}} or \code{\link[=change_cellstatus]{change_cellstatus()}} allow for manual state
modifications, \code{\link[=primarySuppression]{primarySuppression()}} automatically identifies primary
sensitive cells and assigns state \code{"u"}. In \code{\link[=protectTable]{protectTable()}}, additional
cells are identified and set to \code{"x"} to ensure all primary sensitive
cells are adequately protected.
}

\examples{
# load micro data and create a problem instance
utils::data("microdata1", package = "sdcTable")
p <- sdc_testproblem(with_supps = FALSE)

# apply frequency rule
p1 <- primarySuppression(
  object = p,
  type = "freq",
  maxN = 2
)

# apply p-percent rule (requires specifying a numeric variable)
p2 <- primarySuppression(
  object = p,
  type = "p",
  p = 30,
  numVarName = "val"
)

# compare results
data.frame(
  p1_sdc = getInfo(p1, type = "sdcStatus"),
  p2_sdc = getInfo(p2, type = "sdcStatus")
)
}
\author{
Bernhard Meindl \email{bernhard.meindl@statistik.gv.at}
}
