Skip to contents

score a distribution column ("A:B:C") by quantile-vector distance

Usage

score_dist(
  dat_raw_anon,
  target,
  row_number = "ROW_NUMBER",
  split = ":",
  generalized = c("stop", "warn", "ignore"),
  .fn_name = "score_dist"
)

Arguments

dat_raw_anon

dataframe of raw_anon form

target

target column

row_number

name of the row-number column *before* the RAW_/ANON_ prefixing done by [join_raw_anon_data()] (default: "ROW_NUMBER")

split

character separating the elements of the distribution column (default ":"). Treated as a **literal string**, never as a regular expression, so metacharacters such as `"|"`, `"."` or `"$"` are safe to use as separators. Must be a single non-empty string.

generalized

what to do when `target` turns out to hold generalised values on the ANON side: `"stop"` (default), `"warn"` or `"ignore"`. A generalised value has no distribution to compare, so this normally only replaces the coercion error raised further down with one that names the score to use instead (Issue #40).

.fn_name

name used in error messages; a function that wraps this one passes its own name so the message points at the function the user actually called

Value

a "reid_scores" table whose SCORE is [distribution_distance()] between the RAW and ANON distributions (a distance: smaller is a better match).

Examples

# each record carries a whole distribution, written as "A:B:C"
raw  <- data.frame(ROW_NUMBER = 1:3,
                   SPEND = c("1:2:3", "10:11:12", "20:21:22"))
anon <- data.frame(ROW_NUMBER = 1:3,
                   SPEND = c("1:2:4", "10:12:13", "19:21:23"))
d <- join_raw_anon_data(raw, anon)
score_dist(d, "SPEND")
#> reid scores (distance): 9 candidate pair(s), 3 ANON x 3 RAW record(s)
#>   RAW_ROW_NUMBER ANON_ROW_NUMBER       SCORE
#> 1              1               1    2.037037
#> 2              2               1  762.037037
#> 3              3               1 3506.481481
#> 4              1               2  946.481481
#> 5              2               2    6.481481
#> 6              3               2  862.037037
#> # ... 3 more pair(s)