synthesize_table: Synthesise one table

View source: R/synthesize.r

synthesize_tableR Documentation

Synthesise one table

Description

Synthesise one table

Usage

synthesize_table(
  src,
  spec = NULL,
  n_folds = 10,
  n_cycles = 1,
  censor_mode = c("cell", "row"),
  lock_threshold = 0.95,
  max_predictors = 25,
  minbucket = 5,
  cp = 1e-04,
  aux = NULL,
  aux_always = TRUE,
  nonsubject = c("blank", "keep"),
  seed = NULL,
  verbose = TRUE
)

Arguments

src

A synth_source from read_source().

spec

Column spec; inferred with infer_spec() when NULL.

n_folds

Number of folds; each round censors 1/n_folds of every column (default 10, i.e. 10%).

n_cycles

Full sweeps over all folds.

censor_mode

The privacy-utility dial.

  • "cell" (default): folds are drawn per column; each censored cell is redrawn given the row's other current values. Within-row and cross-table associations survive well, but a pair of columns that determine each other (death flag and death date) cannot change, so such attributes stay real per identifier.

  • "row": whole rows are censored together and rebuilt column by column from already redrawn columns and aux only (sequential synthesis as in synthpop). Rows become fully synthetic; their link to the identifier survives only through aux.

lock_threshold

Cell mode only: columns whose screening association (largest absolute correlation between value, missingness and level signals) reaches this value form a lock group, share a fold and are redrawn in sequence without seeing each other's censored cells. This re-rolls coupled pairs (flag + date) that would otherwise stay real. NULL switches it off.

max_predictors

Predictors per target after screening.

minbucket, cp

rpart controls (minimum donor pool per leaf, complexity).

aux

Optional auxiliary predictors from make_aux().

aux_always

If TRUE (default) every aux column is offered to every target's tree in addition to the max_predictors screened ones; if FALSE aux columns compete in the screening like any other column.

nonsubject

What to do with non-subject rows (totals, site headers): "blank" keeps their identifiers and empties the rest, "keep" leaves them verbatim. They are never donors.

seed

Random seed.

verbose

Print progress.

Value

A synth_result: synthetic (raw character data.frame in the source layout), spec, log, nonsubject rows, settings, and the source metadata needed to write it out.

Examples

df <- data.frame(id = sprintf("AB%03d", 1:60), value = 1:60,
                 code = rep(c(0, 1, NA), 20), group = rep(c("A", "B"), 30))
path <- file.path(tempdir(), "synthesize_table.csv")
utils::write.csv(df, path, row.names = FALSE, na = "")
src <- read_source(path)
res <- synthesize_table(src, n_folds = 2, seed = 1, verbose = FALSE)
head(res$synthetic)

cellsynth documentation built on Oct. 31, 2026, 1:07 a.m.