% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/create_perturbed_table.R
\name{create_perturbed_table}
\alias{create_perturbed_table}
\title{Create a frequency table with cell key perturbation applied}
\usage{
create_perturbed_table(
  data,
  ptable,
  geog,
  tab_vars,
  record_key,
  use_existing_ons_id = TRUE,
  threshold = 10
)
}
\arguments{
\item{data}{A \code{data.table} containing the data to be tabulated and perturbed

The data should contain one row per statistical unit (person, household,
business or other) and one column per variable (age, sex, health status)}

\item{ptable}{A \code{data.table} containing the \code{ptable} file which determines
when perturbation is applied.}

\item{geog}{A \verb{character vector} giving the column name in \code{data} that
contains the desired geography level for the frequency table. This can be an
empty vector, \code{c()}, if no geography level is required.}

\item{tab_vars}{A \verb{character vector} giving the column names in \code{data} of the
variables to be tabulated.
This can be an empty vector, \code{c()}, provided a geography level is supplied.}

\item{record_key}{A \code{character} containing the column name in \code{data} giving
the record keys required for perturbation.
If data contains "ons_id" and use_existing_ons_id = TRUE,
set (record_key = NULL), as record key will be generated from "ons_id".}

\item{use_existing_ons_id}{A \code{logical} on whether to create record keys
from ons_id, if ons_id exists in data.
It will be irrelevant if microdata does not contain ons_id.
Default is TRUE.}

\item{threshold}{An \code{integer} specifying the value below which counts are
suppressed, with a default value of 10.}
}
\value{
Returns a \code{data.table} giving a frequency table which has had
cell key perturbation applied according to the ptable supplied.
}
\description{
\code{create_perturbed_table()} creates a frequency table which has had
cell key perturbation applied to the counts.
A p-table file needs to be supplied which determines which cells are
perturbed.
The data needs to contain a 'record key' variable which along with the
ptable allows the process to be repeatable and consistent.
}
\examples{
if (requireNamespace("data.table", quietly = TRUE)) {
  data.table::setDTthreads(1)
}

geog <- "var1"
tab_vars <- c("var5","var8")
record_key <- "record_key"
perturbed_table <- create_perturbed_table(micro,
                                          ptable_10_5,
                                          geog,
                                          tab_vars,
                                          record_key)

# Alternatively
perturbed_table <- create_perturbed_table(data = micro,
                                          ptable = ptable_10_5,
                                          geog = c(),
                                          tab_vars = c("var1","var5","var8"),
                                          record_key = "record_key",
                                          threshold = 10)

}
