Skip to contents

Matches the rows of two data frames on a key and reports, for every shared column, how far the two derivations agree: marginal differences, missingness discrepancies and concordance statistics. Generic: it needs two data frames and a key.

Usage

audit_matrix_parity(
  legacy_df,
  omop_df,
  key_col,
  columns = NULL,
  tolerance = 0,
  smd_threshold = 0.1,
  missingness_gap_threshold = 0.05,
  kappa_threshold = 0.8,
  ccc_threshold = 0.9,
  max_levels = 50L,
  min_cell = 11L
)

Arguments

legacy_df, omop_df

The two tables. Duplicate keys in either one are an error.

key_col

Key column name(s) present in both.

columns

Columns to compare (default: all shared columns except the key).

tolerance

Numeric pairs agree when |a - b| <= tolerance.

smd_threshold, missingness_gap_threshold, kappa_threshold, ccc_threshold

Thresholds that set flagged.

max_levels

Categorical columns with more levels than this are compared but not tabulated in levels.

min_cell

Suppression threshold (NULL or 1 keeps exact counts; only for use inside the site).

Value

A list with ledger (one row per column), levels, keys (match counts) and flagged (column names).

Details

Numeric columns: matched N, means, SDs, standardized mean difference (SMD), Pearson correlation, Lin's concordance correlation coefficient (CCC), mean absolute difference and the share of pairs within tolerance. Other columns: percent agreement, Cohen's kappa and the total variation distance between the two marginal distributions. All columns: missingness in each table and the gap. levels gives each category's count in each table. Counts below min_cell (default 11) and the statistics computed from them are blanked (suppress_small_counts()); key values are never written.

This is the R counterpart of Python's omop_etl.audit_matrix_parity(); the R version reports the pooled (ALL) stratum only.

Examples

legacy <- data.frame(id = 1:40, sbp = seq(100, 139), sex = rep(c("F", "M"), 20))
omop <- legacy; omop$sbp <- omop$sbp + 6
audit_matrix_parity(legacy, omop, "id", min_cell = NULL)$ledger[, c("column", "smd", "ccc", "flagged")]
#>   column        smd       ccc flagged
#> 1    sbp -0.5132394 0.8809917    TRUE
#> 2    sex         NA        NA   FALSE