| dcr | R Documentation |
For every synthetic record (in a subsample of at most max_rows), the
Gower distance to the closest real record is computed. As a baseline the
same is done for real records with respect to the other real records.
Synthetic records that are much closer to real records than real records
are to each other, and in particular exact copies (distance 0), indicate
a disclosure risk.
dcr(
real,
synthetic,
vars = NULL,
max_rows = 2000L,
seed = NULL,
close_quantile = 0.05,
na = c("category", "exclude")
)
real, synthetic |
Data frames with common columns. |
vars |
Optional subset of variables. |
max_rows |
Maximum number of records used from each data set. |
seed |
Optional random seed (subsampling). |
close_quantile |
Quantile of the real-to-real distances that defines
a synthetic record as "too close" to a real record (see |
na |
Treatment of missing values: |
Numeric variables contribute their absolute difference divided by the
range in the real data, categorical variables 0 (equal) or 1 (different).
Missing values are handled according to na:
"category" (default): missingness is treated as a category of its own
– two missing values match, a missing and an observed value differ –
and the distance is averaged over all variables. Because the
synthesizer reproduces missingness patterns, and an intruder sees them,
this is the appropriate view for disclosure risk.
"exclude": the standard Gower (1971) coefficient; a variable missing in
either record is left out of the comparison and the distance is averaged
over the variables observed in both. Records with no variable in common
have no distance (NA) and are ignored.
A list with the distance vectors synthetic and real,
their quantiles, the share of synthetic records that are exact copies
of a real record on all variables (exact_match_rate), the share at
distance zero on the variables compared (zero_distance_rate; with
na = "exclude" this can include records that agree with a real record
only on the few variables observed in both), the average share of
variables on which the nearest real record was compared
(compared_share; always 1 with na = "category"), the share of exact
duplicates within the real data (real_duplicate_rate) and ratio,
the median synthetic distance
divided by the median real-to-real distance (values well below 1 are a
warning sign), and close_share, the share of synthetic records that
are closer to a real record than close_quantile (5\
are to their nearest real neighbour. For synthetic records that are as
far from real ones as real records are from each other, close_share
is about close_quantile; larger values indicate records that may be
recognised as near-copies of real persons.
Gower, J. C. (1971). A general coefficient of similarity and some of its properties. Biometrics, 27(4), 857–871. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.2307/2528823")}
syn <- synthesize(iris, seed = 1)
str(dcr(iris, syn, seed = 1)[c("exact_match_rate", "ratio")])
# data with missing values: missingness as a category, or standard Gower
aq <- synthesize(airquality, seed = 1)
dcr(airquality, aq, seed = 1)$ratio
dcr(airquality, aq, seed = 1, na = "exclude")$ratio
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.