Skip to contents

Rank ties are resolved with `ties.method = "min"`: genuinely tied values are indistinguishable in the data, so they collapse to the same rank instead of being split into a fake total order by incidental row position.

Usage

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

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"`. A generalised column is also non-numeric, so this normally only decides which of the two errors is raised.

.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 the absolute difference between the ANON-side and RAW-side ranks of `target` (a distance: smaller is a better match).

Details

**The target column must be numeric.** `rank()` accepts a character column and orders it lexicographically, so a generalised or categorical column used to come back as a full set of plausible rank gaps with no error at all – the same silent under-report as [score_char()] (Issue #40).

Examples

# the published values are on a different scale, but the order survives,
# and the order is enough: every rank gap on the diagonal is 0
raw  <- data.frame(ROW_NUMBER = 1:5, V = c(10, 20, 30, 40, 50))
anon <- data.frame(ROW_NUMBER = 1:5, V = c(1.2, 2.5, 3.1, 4.4, 5.0))
d <- join_raw_anon_data(raw, anon)
score_num_rank(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     0
#> 2              2               1     1
#> 3              3               1     2
#> 4              4               1     3
#> 5              5               1     4
#> 6              1               2     1
#> # ... 19 more pair(s)
match_greedy(score_num_rank(d, "V"))
#>   ANON_ROW_NUMBER RAW_ROW_NUMBER CONFIDENCE RESULT
#> 1               1              1  0.6324555   TRUE
#> 2               2              2  0.8770580   TRUE
#> 3               3              3  1.1952286   TRUE
#> 4               4              4  0.8770580   TRUE
#> 5               5              5  0.6324555   TRUE