The first of the three layers: it reports how far apart every (RAW, ANON) candidate pair is and decides nothing. Feed the result to [match_greedy()] or [match_optimal()].
Usage
score_num(
dat_raw_anon,
target,
row_number = "ROW_NUMBER",
generalized = c("stop", "warn", "ignore"),
.fn_name = "score_num"
)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")
- generalized
what to do when `target` turns out to hold generalised values on the ANON side: `"stop"` (default), `"warn"` or `"ignore"`. Accepted for symmetry with the other scores, but it changes nothing here: a published region is a string, and there is no arithmetic to do on a character column, so the type check refuses it first and no escape hatch can produce a number.
- .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: one row per (RAW, ANON) candidate pair with columns RAW_ROW_NUMBER, ANON_ROW_NUMBER and SCORE, where SCORE is `abs(RAW - ANON)` (a distance: smaller is a better match).
Examples
raw <- data.frame(ROW_NUMBER = 1:5, V = c(10, 20, 30, 40, 50))
anon <- data.frame(ROW_NUMBER = 1:5, V = c(11, 19, 33, 38, 52))
d <- join_raw_anon_data(raw, anon)
score_num(d, "V")
#> reid scores (distance): 25 candidate pair(s), 5 ANON x 5 RAW record(s)
#> RAW_ROW_NUMBER ANON_ROW_NUMBER SCORE
#> 1 1 1 1
#> 2 2 1 9
#> 3 3 1 19
#> 4 4 1 29
#> 5 5 1 39
#> 6 1 2 9
#> # ... 19 more pair(s)
# the score layer only ranks candidates; the assignment layer picks one
match_greedy(score_num(d, "V"))
#> ANON_ROW_NUMBER RAW_ROW_NUMBER CONFIDENCE RESULT
#> 1 1 1 0.5265894 TRUE
#> 2 2 2 0.6890410 TRUE
#> 3 3 3 0.5047545 TRUE
#> 4 4 4 0.6036327 TRUE
#> 5 5 5 0.6324555 TRUE