Skip to contents

Reports how much a synthetic dataset could leak about the real records it was trained on. Four complementary measures are computed:

Usage

disclosure_risk(
  real,
  syn,
  quasi = NULL,
  target = NULL,
  holdout = NULL,
  max_records = 2000L,
  seed = NULL,
  ...,
  entity_join = FALSE
)

Arguments

real

The real data.frame (or named list) the data was synthesised from.

syn

The synthetic data: a data.frame, synth() synth_result, named list, or synth_linked() synth_linked_result.

quasi

Character vector of quasi-identifier columns; defaults to all columns present in both frames.

target

Optional single sensitive column for the attribute-disclosure (TCAP) measure; the quasi-identifiers minus target are used as the keys. NULL (default) skips it. For a linked (list) input it is assessed only on the table that contains it.

holdout

Optional data.frame of real records excluded from synthesis, enabling the membership-inference check. For linked input, a named list containing a holdout data.frame for every evaluated table.

max_records

Cap on the number of rows used for the distance computations (each of real / synthetic is sampled down to this); keeps the pairwise distances tractable. Default 2000.

seed

Optional integer seed for the subsampling.

...

Unused.

entity_join

Logical; when TRUE on linked multi-table input, also computes entity-level joined identity risk across the root table and its child summaries, returned as attr(res, "entity").

Value

A flexsynth_disclosure object (or flexsynth_disclosure_list) with a print() method.

Details

  • Replicated uniques – records that are unique in the real data on the quasi-identifiers and are nonetheless reproduced exactly in the synthetic data. These are the classic identity-disclosure risks.

  • Distance to closest record (DCR) – for each synthetic record, the Gower distance to the nearest real record. A DCR of 0 is an exact copy. The synthetic-to-real distances are compared against the real-to-real nearest-neighbour distances: if synthetic records are not systematically closer to real records than real records are to each other, identity risk is low.

  • Membership inference – if a holdout of records not used for synthesis is supplied, an attacker who guesses "member" for records close to the synthetic data is simulated. The reported AUC (0.5 = no advantage) and advantage (2 * AUC - 1) measure how well training membership can be inferred.

  • Attribute disclosure (TCAP) – if a sensitive target column is named, the Target Correct Attribution Probability (Taub, Elliot et al.): an attacker who knows a real record's quasi-identifier keys reads the conditional distribution of the target off the synthetic records that share those keys. tcap is the mean synthetic probability of the true target over matched records, baseline the marginal-only attacker evaluated on those same covered records, and lift the excess the key-conditioning buys. baseline_unconditional is also returned for context. Meant for categorical keys / target.

Quasi-identifiers should be the genuinely identifying columns; exclude surrogate keys such as a regenerated unit id (a synthetic id never matches a real one, which would understate risk). If real and syn are named lists (or syn is a synth_linked_result), each table is assessed separately.

See also

diagnose() for utility.

Examples

df <- data.frame(
  id  = 1:200,
  age = round(rnorm(200, 60, 10)),
  sex = sample(c("F", "M"), 200, replace = TRUE)
)
res <- synth(df, ~ id, seed = 1)
disclosure_risk(df, res, quasi = c("age", "sex"))
#> <flexsynth_disclosure>
#>   rows            : real 200  synthetic 200 
#>   quasi-identifiers: age, sex 
#> 
#> Replicated uniques (identity risk):
#>   real sample-uniques : 24
#>   reproduced in syn   : 0  (0.00% of uniques, 0.00% of real rows)
#>   syn rows copying a real row: 0  (0.00% of syn)
#> 
#> Distance to closest record (Gower, 0 = exact copy):
#>   syn->real  : median 0.0022   5th pct 0.0003   exact copies 0.00%
#>   real->real : median 0.0000   (baseline)
#>   median syn distance is not smaller than the real-neighbour baseline
#>   descriptive only: inspect lower-tail distances and exact copies; this is not a safety guarantee
#> 
#> Membership inference: not run (supply `holdout` of non-training records).
#> 
#> Attribute disclosure: not run (supply `target` = a sensitive column).