Assignment 8

Author

Brennan Stout

Published

November 18, 2026

0. Set Up & Baseline Workshop Pipeline

required_packages <- c(
  "tidyverse",        # Data manipulation
  "stringdist",       # String similarity metrics
  "phonics",          # Phonetic matching (Soundex, Metaphone, NYSIIS)
  "data.table",       # Fast data operations
  "logger",           # Logging and debugging
  "knitr"             # Formatted tables
)

# Install any missing required packages
missing_pkgs <- required_packages[!sapply(required_packages, requireNamespace, quietly = TRUE)]
if (length(missing_pkgs) > 0) install.packages(missing_pkgs)

# Load packages
invisible(lapply(required_packages, library, character.only = TRUE))

# Check stringdist version per setup instructions
cat("stringdist version:", as.character(packageVersion("stringdist")), "\n")
stringdist version: 0.9.15 
# Ensure data/ is ignored in git before writing any output files
if (file.exists(".gitignore")) {
  gi_lines <- readLines(".gitignore", warn = FALSE)
  if (!any(trimws(gi_lines) %in% c("data/", "data"))) {
     write("data/", file = ".gitignore", append = TRUE)
  }
} else {
  writeLines("data/", ".gitignore")
}

# ============================================================================
# PART 1: GENERATE SAMPLE DATASETS
# ============================================================================

set.seed(42)

# Create Texas Government Employee Data (TRS - Teacher Retirement System)
create_trs_data <- function(n = 500) {
  
  first_names <- c("John", "Maria", "Robert", "Jennifer", "Michael", "Sarah",
                   "David", "Patricia", "James", "Linda", "Daniel", "Barbara")
  last_names <- c("Smith", "Johnson", "Williams", "Brown", "Jones", "Garcia",
                  "Miller", "Davis", "Rodriguez", "Martinez", "Hernandez", "Lopez")
  
  trs <- tibble(
    record_id = paste0("TRS_", 1:n),
    first_name = sample(first_names, n, replace = TRUE),
    last_name = sample(last_names, n, replace = TRUE),
    dob = sample(seq(as.Date("1950-01-01"), as.Date("1985-12-31"), by = "day"), n),
    years_service = sample(5:40, n, replace = TRUE),
    salary_group = sample(c("Elementary", "Secondary", "Administration"), n, replace = TRUE),
    retirement_date = NA_Date_
  ) %>%
    mutate(
      # Some retirements for older employees
      retirement_date = case_when(
        years_service > 30 ~ as.Date(paste0(2020 + sample(0:4, n, replace = TRUE), 
                                              "-", 
                                              sample(1:12, n, replace = TRUE, prob = rep(1/12, 12)),
                                              "-01")),
        TRUE ~ NA_Date_
      )
    )
  
  return(trs)
}

# Create Education Agency Data (TEA - Texas Education Agency)
create_tea_data <- function(trs, n = 500, num_matches = 100, corruption_rate = 0.2) {
  
  first_names <- c("John", "Maria", "Robert", "Jennifer", "Michael", "Sarah",
                   "David", "Patricia", "James", "Linda", "Daniel", "Barbara",
                   "Jon", "Mary", "Rob", "Jen", "Mike", "Sara")  # Include variations
  last_names <- c("Smith", "Smithe", "Smyth", "Johnson", "Jonson", "Williams", 
                  "Brown", "Jones", "Garcia", "Miller", "Davis", "Rodriguez", 
                  "Martinez", "Hernandez", "Lopez", "Sanchez")
  
  tea <- tibble(
    record_id = paste0("TEA_", 1:n),
    first_name = sample(first_names, n, replace = TRUE),
    last_name = sample(last_names, n, replace = TRUE),
    dob = sample(seq(as.Date("1950-01-01"), as.Date("1985-12-31"), by = "day"), n),
    certification = sample(c("Science", "Math", "English", "Social Studies", "Special Ed"), n, replace = TRUE),
    school_district = sample(paste0("District_", 1:50), n, replace = TRUE),
    hire_date = sample(seq(as.Date("1990-01-01"), as.Date("2020-12-31"), by = "day"), n)
  )
  
  # Make the first num_matches TEA records true matches of TRS_1..TRS_num_matches.
  # The remaining TEA records are unrelated people (true non-matches).
  tea$first_name[1:num_matches] <- trs$first_name[1:num_matches]
  tea$last_name[1:num_matches] <- trs$last_name[1:num_matches]
  tea$dob[1:num_matches] <- trs$dob[1:num_matches]

  # Introduce data quality issues in the matched records only
  # About 20% of matched records have corruption or variation
  corruption_indices <- sample(1:num_matches, size = round(num_matches * corruption_rate), replace = FALSE)
  
  for (idx in corruption_indices) {
    flip <- sample(1:3, 1)
    
    if (flip == 1) {
      # Introduce name variation
      tea$first_name[idx] <- abbreviate(tea$first_name[idx], minlength = 3)
    } else if (flip == 2) {
      # Introduce small typo in last name
      last_chars <- nchar(tea$last_name[idx])
      if (last_chars > 1) {
        typo_pos <- sample(1:last_chars, 1)
        wrong_char <- sample(letters[!(letters %in% unlist(strsplit(tea$last_name[idx], "")))], 1)
        tea$last_name[idx] <- paste0(
          substr(tea$last_name[idx], 1, typo_pos - 1),
          wrong_char,
          substr(tea$last_name[idx], typo_pos + 1, last_chars)
        )
      }
    } else {
      # Shift DOB slightly (data entry error)
      tea$dob[idx] <- tea$dob[idx] + sample(c(-1, 1), 1)
    }
  }
  
  return(tea)
}

# Create a subset of KNOWN matches for validation
create_validation_set <- function(trs, tea, num_matches = 100) {
  
  # Take first 100 records from TRS
  trs_subset <- trs %>% slice(1:num_matches)
  
  # These are the "true" matches in TEA
  true_matches <- tea %>%
    slice(1:num_matches) %>%
    rename_with(~paste0("tea_", .), everything()) %>%
    rename(tea_record_id = tea_record_id)
  
  # Create ground truth
  validation <- tibble(
    trs_record_id = trs_subset$record_id,
    tea_record_id = true_matches$tea_record_id,
    is_match = TRUE
  )
  
  return(validation)
}


set.seed(42)
cat("Generating sample datasets...\n")
Generating sample datasets...
trs_data <- create_trs_data(500)
tea_data <- create_tea_data(trs_data, 500, corruption_rate = 0.20)
validation_set <- create_validation_set(trs_data, tea_data)

# Display sample
cat("\nSample TRS data:\n")

Sample TRS data:
print(head(trs_data, 3))
# A tibble: 3 × 7
  record_id first_name last_name dob        years_service salary_group
  <chr>     <chr>      <chr>     <date>             <int> <chr>       
1 TRS_1     John       Martinez  1955-12-14            21 Secondary   
2 TRS_2     Michael    Hernandez 1951-11-27            27 Secondary   
3 TRS_3     John       Martinez  1954-10-31            32 Elementary  
# ℹ 1 more variable: retirement_date <date>
cat("\nSample TEA data:\n")

Sample TEA data:
print(head(tea_data, 3))
# A tibble: 3 × 7
  record_id first_name last_name dob        certification  school_district
  <chr>     <chr>      <chr>     <date>     <chr>          <chr>          
1 TEA_1     Jhn        Martinez  1955-12-14 Math           District_18    
2 TEA_2     Michael    Hernandez 1951-11-27 Social Studies District_41    
3 TEA_3     John       Martinez  1954-11-01 Special Ed     District_41    
# ℹ 1 more variable: hire_date <date>
cat("\nGround truth validation set:\n")

Ground truth validation set:
print(head(validation_set, 5))
# A tibble: 5 × 3
  trs_record_id tea_record_id is_match
  <chr>         <chr>         <lgl>   
1 TRS_1         TEA_1         TRUE    
2 TRS_2         TEA_2         TRUE    
3 TRS_3         TEA_3         TRUE    
4 TRS_4         TEA_4         TRUE    
5 TRS_5         TEA_5         TRUE    
# ============================================================================
# PART 2: DATA STANDARDIZATION AND CLEANING
# ============================================================================

standardize_names <- function(name) {
  name %>%
    tolower() %>%              # Convert to lowercase
    str_trim() %>%             # Remove leading/trailing whitespace
    str_squish() %>%           # Remove extra internal whitespace
    str_replace_all("[^a-z ]", "")  # Remove punctuation/special characters
}

standardize_date <- function(date_col) {
  as.Date(date_col)
}

standardize_zipcodes <- function(zip) {
  # Ensure 5-digit format
  zip <- as.character(zip)
  str_pad(zip, width = 5, side = "left", pad = "0")
}

# Create clean versions
trs_clean <- trs_data %>%
  mutate(
    first_name_std = standardize_names(first_name),
    last_name_std = standardize_names(last_name),
    first_initial = substr(first_name_std, 1, 1),
    dob_std = standardize_date(dob)
  )

tea_clean <- tea_data %>%
  mutate(
    first_name_std = standardize_names(first_name),
    last_name_std = standardize_names(last_name),
    first_initial = substr(first_name_std, 1, 1),
    dob_std = standardize_date(dob)
  )

cat("\nStandardized TRS sample (IDs and initials only):\n")

Standardized TRS sample (IDs and initials only):
print(trs_clean %>% select(record_id, first_initial, years_service, salary_group) %>% head(3))
# A tibble: 3 × 4
  record_id first_initial years_service salary_group
  <chr>     <chr>                 <int> <chr>       
1 TRS_1     j                        21 Secondary   
2 TRS_2     m                        27 Secondary   
3 TRS_3     j                        32 Elementary  
# ============================================================================
# PART 3: DETERMINISTIC LINKAGE RULES
# ============================================================================

deterministic_linkage <- function(data_a, data_b, 
                                  id_col_a = "record_id", 
                                  id_col_b = "record_id") {
  
  log_info("Starting deterministic linkage...")
  
  matches <- tibble()
  remaining_a <- data_a
  remaining_b <- data_b
  
  # RULE 1: Exact match on last name + first name + DOB
  # (Highest confidence)
  log_info("Applying Rule 1: Last name + First name + DOB")
  
  rule1 <- remaining_a %>%
    inner_join(
      remaining_b,
      by = c("last_name_std" = "last_name_std",
             "first_name_std" = "first_name_std",
             "dob_std" = "dob_std"),
      suffix = c("_a", "_b")
    ) %>%
    mutate(
      rule_applied = "Rule_1_FullName_DOB",
      confidence = 0.99
    ) %>%
    select(!!sym(paste0(id_col_a, "_a")), 
           !!sym(paste0(id_col_b, "_b")), 
           rule_applied, confidence)
  
  matches <- bind_rows(matches, rule1)
  
  # Remove matched records
  remaining_a <- anti_join(remaining_a, rule1, by = setNames("record_id_a", id_col_a))
  remaining_b <- anti_join(remaining_b, rule1, by = setNames("record_id_b", id_col_b))
  
  log_info(paste("Rule 1 found", nrow(rule1), "matches"))
  
  # RULE 2: Last name + First initial + DOB
  # (For records where first name varies slightly)
  log_info("Applying Rule 2: Last name + First initial + DOB")
  
  rule2 <- remaining_a %>%
    inner_join(
      remaining_b,
      by = c("last_name_std" = "last_name_std",
             "first_initial" = "first_initial",
             "dob_std" = "dob_std"),
      suffix = c("_a", "_b")
    ) %>%
    mutate(
      rule_applied = "Rule_2_LastName_Initial_DOB",
      confidence = 0.95
    ) %>%
    select(record_id_a, record_id_b, rule_applied, confidence)

  matches <- bind_rows(matches, rule2)
  remaining_a <- anti_join(remaining_a, rule2, by = setNames("record_id_a", id_col_a))
  remaining_b <- anti_join(remaining_b, rule2, by = setNames("record_id_b", id_col_b))
  
  log_info(paste("Rule 2 found", nrow(rule2), "matches"))
  
  # RULE 3: Last name + First name + DOB within 1 day
  # (For data entry errors on DOB)
  log_info("Applying Rule 3: Last name + First name + DOB (±1 day)")
  
  rule3 <- remaining_a %>%
    cross_join(remaining_b, suffix = c("_a", "_b")) %>%
    filter(
      last_name_std_a == last_name_std_b,
      first_name_std_a == first_name_std_b,
      abs(as.numeric(difftime(dob_std_a, dob_std_b, units = "days"))) <= 1
    ) %>%
    select(record_id_a, record_id_b) %>%
    mutate(
      rule_applied = "Rule_3_DOBFlex",
      confidence = 0.90
    )

  if (nrow(rule3) > 0) {
    # Remove duplicates (keep first match only)
    rule3 <- rule3 %>% distinct(record_id_a, .keep_all = TRUE)
    matches <- bind_rows(matches, rule3)
    remaining_a <- anti_join(remaining_a, rule3, by = setNames("record_id_a", id_col_a))
    remaining_b <- anti_join(remaining_b, rule3, by = setNames("record_id_b", id_col_b))
  }
  
  log_info(paste("Rule 3 found", nrow(rule3), "matches"))
  
  result <- list(
    matches = matches,
    remaining_a = remaining_a,
    remaining_b = remaining_b,
    summary = tibble(
      Rule = c("Rule 1", "Rule 2", "Rule 3"),
      Matches = c(nrow(rule1), nrow(rule2), nrow(rule3))
    )
  )
  
  return(result)
}

# Execute deterministic linkage
det_result <- deterministic_linkage(trs_clean, tea_clean)

cat("\nDeterministic Linkage Summary:\n")

Deterministic Linkage Summary:
print(det_result$summary)
# A tibble: 3 × 2
  Rule   Matches
  <chr>    <int>
1 Rule 1      80
2 Rule 2       9
3 Rule 3       4
cat("\nFirst 5 deterministic matches:\n")

First 5 deterministic matches:
print(head(det_result$matches, 5))
# A tibble: 5 × 4
  record_id_a record_id_b rule_applied        confidence
  <chr>       <chr>       <chr>                    <dbl>
1 TRS_2       TEA_2       Rule_1_FullName_DOB       0.99
2 TRS_5       TEA_5       Rule_1_FullName_DOB       0.99
3 TRS_6       TEA_6       Rule_1_FullName_DOB       0.99
4 TRS_7       TEA_7       Rule_1_FullName_DOB       0.99
5 TRS_8       TEA_8       Rule_1_FullName_DOB       0.99
# ============================================================================
# PART 4: PROBABILISTIC LINKAGE - SIMILARITY SCORING
# ============================================================================

# Calculate string similarity using Jaro-Winkler
calculate_string_similarity <- function(str1, str2, method = "jw") {
  
  if (is.na(str1) | is.na(str2)) {
    return(NA_real_)
  }
  
  # Jaro-Winkler returns distance (0-1), we want similarity
  1 - stringdist(str1, str2, method = method)
}

# More efficient: Use vectorized stringdistmatrix
calculate_similarity_efficient <- function(data_a_field, data_b_field) {
  
  dist_matrix <- stringdistmatrix(
    data_a_field,
    data_b_field,
    method = "jw",
    useNames = "strings"
  )
  
  # Convert distance to similarity (1 - distance)
  similarity <- 1 - dist_matrix
  
  return(similarity)
}

# For unmatched records, compute similarities
unmatched_a <- det_result$remaining_a
unmatched_b <- det_result$remaining_b

cat(paste("\nComputing probabilistic matches for", 
          nrow(unmatched_a), "unmatched records in TRS and",
          nrow(unmatched_b), "in TEA...\n"))

Computing probabilistic matches for 407 unmatched records in TRS and 407 in TEA...
# Calculate similarities for each field
last_name_sim <- calculate_similarity_efficient(
  unmatched_a$last_name_std,
  unmatched_b$last_name_std
)

first_name_sim <- calculate_similarity_efficient(
  unmatched_a$first_name_std,
  unmatched_b$first_name_std
)

# DOB exact match (1 if exact, 0 if different, 0.95 if within 1 day)
dob_sim <- outer(
  as.numeric(unmatched_a$dob_std),
  as.numeric(unmatched_b$dob_std),
  function(x, y) {
    diff_days <- abs(x - y)
    ifelse(diff_days == 0, 1.0, ifelse(diff_days == 1, 0.95, 0.0))
  }
)

# Convert to dataframes for easier manipulation
all_comparisons <- expand_grid(
  idx_a = 1:nrow(unmatched_a),
  idx_b = 1:nrow(unmatched_b)
) %>%
  mutate(
    record_id_a = unmatched_a$record_id[idx_a],
    record_id_b = unmatched_b$record_id[idx_b],
    last_name_sim = last_name_sim[cbind(idx_a, idx_b)],
    first_name_sim = first_name_sim[cbind(idx_a, idx_b)],
    dob_sim = dob_sim[cbind(idx_a, idx_b)]
  ) %>%
  select(record_id_a, record_id_b, last_name_sim, first_name_sim, dob_sim)

# Calculate weighted match score
all_comparisons <- all_comparisons %>%
  mutate(
    match_score = (
      last_name_sim * 0.40 +   # Last name most important
      first_name_sim * 0.30 +  # First name medium importance
      dob_sim * 0.30           # DOB medium importance
    )
  )

cat("\nMatch score distribution:\n")

Match score distribution:
print(all_comparisons %>%
  summarise(
    min = min(match_score),
    q25 = quantile(match_score, 0.25),
    median = median(match_score),
    q75 = quantile(match_score, 0.75),
    max = max(match_score),
    n = n()
  ))
# A tibble: 1 × 6
    min   q25 median   q75   max      n
  <dbl> <dbl>  <dbl> <dbl> <dbl>  <int>
1     0 0.193  0.323 0.385 0.970 165649
# Apply thresholds
probabilistic_matches <- all_comparisons %>%
  mutate(
    classification = case_when(
      match_score > 0.95 ~ "LINK",
      match_score >= 0.85 & match_score <= 0.95 ~ "REVIEW",
      TRUE ~ "NO_LINK"
    )
  ) %>%
  filter(classification %in% c("LINK", "REVIEW"))

cat("\nProbabilistic matches by classification:\n")

Probabilistic matches by classification:
print(probabilistic_matches %>%
  count(classification))
# A tibble: 2 × 2
  classification     n
  <chr>          <int>
1 LINK               4
2 REVIEW             3
cat("\nSample LINK decisions (high confidence):\n")

Sample LINK decisions (high confidence):
print(probabilistic_matches %>%
  filter(classification == "LINK") %>%
  head(5))
# A tibble: 4 × 7
  record_id_a record_id_b last_name_sim first_name_sim dob_sim match_score
  <chr>       <chr>               <dbl>          <dbl>   <dbl>       <dbl>
1 TRS_38      TEA_38              0.926              1       1       0.970
2 TRS_58      TEA_58              0.889              1       1       0.956
3 TRS_60      TEA_60              0.889              1       1       0.956
4 TRS_83      TEA_83              0.926              1       1       0.970
# ℹ 1 more variable: classification <chr>
cat("\nSample REVIEW decisions (uncertain):\n")

Sample REVIEW decisions (uncertain):
print(probabilistic_matches %>%
  filter(classification == "REVIEW") %>%
  head(5))
# A tibble: 3 × 7
  record_id_a record_id_b last_name_sim first_name_sim dob_sim match_score
  <chr>       <chr>               <dbl>          <dbl>   <dbl>       <dbl>
1 TRS_4       TEA_4               0.867              1       1       0.947
2 TRS_87      TEA_87              0.867              1       1       0.947
3 TRS_88      TEA_88              0.867              1       1       0.947
# ℹ 1 more variable: classification <chr>
# ============================================================================
# PART 5: VALIDATION AND QUALITY ASSESSMENT
# ============================================================================

# Combine deterministic and probabilistic matches
all_matches <- bind_rows(
  det_result$matches %>%
    select(record_id_a, record_id_b) %>%
    mutate(match_score = 0.99, source = "Deterministic"),
  
  probabilistic_matches %>%
    filter(classification == "LINK") %>%
    select(record_id_a, record_id_b, match_score) %>%
    mutate(source = "Probabilistic_Auto")
) %>%
  mutate(
    trs_record_id = record_id_a,
    tea_record_id = record_id_b
  ) %>%
  select(trs_record_id, tea_record_id, match_score, source)

# ============================================================================
# ASSESSMENT: PRECISION, RECALL, F1-SCORE
# ============================================================================

assess_linkage_quality <- function(all_matches, validation_set) {
  
  log_info("Assessing linkage quality against validation set...")
  
  our_matches <- all_matches %>%
    mutate(our_match = 1) %>%
    select(trs_record_id, tea_record_id, our_match)
  
  true_matches <- validation_set %>%
    rename(trs_record_id = trs_record_id, 
           tea_record_id = tea_record_id) %>%
    mutate(true_match = 1) %>%
    select(trs_record_id, tea_record_id, true_match)
  
  # Full outer join to get all possibilities
  assessment <- true_matches %>%
    full_join(our_matches, 
              by = c("trs_record_id", "tea_record_id")) %>%
    mutate(
      true_match = replace_na(true_match, 0),
      our_match = replace_na(our_match, 0)
    )
  
  tp <- sum(assessment$true_match == 1 & assessment$our_match == 1)
  fp <- sum(assessment$true_match == 0 & assessment$our_match == 1)
  fn <- sum(assessment$true_match == 1 & assessment$our_match == 0)
  tn <- sum(assessment$true_match == 0 & assessment$our_match == 0)
  
  precision <- if (tp + fp > 0) tp / (tp + fp) else NA_real_
  recall <- if (tp + fn > 0) tp / (tp + fn) else NA_real_
  f1 <- if (!is.na(precision) & !is.na(recall) & precision + recall > 0) {
    2 * (precision * recall) / (precision + recall)
  } else {
    NA_real_
  }
  
  accuracy <- (tp + tn) / nrow(assessment)
  
  results <- list(
    metrics = tibble(
      Metric = c("Precision", "Recall", "F1-Score", "Accuracy"),
      Value = c(precision, recall, f1, accuracy),
      Interpretation = c(
        "Of matches we made, what % were correct?",
        "Of all true matches, what % did we find?",
        "Harmonic mean of precision and recall",
        "What % of all decisions were correct?"
      )
    ),
    confusion_matrix = tibble(
      Metric = c("True Positives", "False Positives", "False Negatives", "True Negatives"),
      Count = c(tp, fp, fn, tn)
    ),
    detailed = assessment
  )
  
  return(results)
}

# Run assessment
quality_assessment <- assess_linkage_quality(all_matches, validation_set)

cat("\n=== LINKAGE QUALITY ASSESSMENT ===\n")

=== LINKAGE QUALITY ASSESSMENT ===
cat("Performance Metrics:\n")
Performance Metrics:
print(quality_assessment$metrics)
# A tibble: 4 × 3
  Metric    Value Interpretation                          
  <chr>     <dbl> <chr>                                   
1 Precision 1     Of matches we made, what % were correct?
2 Recall    0.97  Of all true matches, what % did we find?
3 F1-Score  0.985 Harmonic mean of precision and recall   
4 Accuracy  0.97  What % of all decisions were correct?   
cat("\nConfusion Matrix:\n")

Confusion Matrix:
print(quality_assessment$confusion_matrix)
# A tibble: 4 × 2
  Metric          Count
  <chr>           <int>
1 True Positives     97
2 False Positives     0
3 False Negatives     3
4 True Negatives      0
# ============================================================================
# PART 6: DIAGNOSTIC AND TROUBLESHOOTING
# ============================================================================

false_positives <- quality_assessment$detailed %>%
  filter(true_match == 0 & our_match == 1) %>%
  left_join(
    all_matches %>% select(trs_record_id, tea_record_id, match_score),
    by = c("trs_record_id", "tea_record_id")
  ) %>%
  select(trs_record_id, tea_record_id, match_score)

cat("\n=== FALSE POSITIVES (Incorrect Matches) ===\n")

=== FALSE POSITIVES (Incorrect Matches) ===
if (nrow(false_positives) > 0) {
  cat("Found", nrow(false_positives), "false positives. Examples:\n")
  print(head(false_positives, 3))
} else {
  cat("No false positives! Excellent precision.\n")
}
No false positives! Excellent precision.
false_negatives <- quality_assessment$detailed %>%
  filter(true_match == 1 & our_match == 0) %>%
  select(trs_record_id, tea_record_id)

cat("\n=== FALSE NEGATIVES (Missed Matches) ===\n")

=== FALSE NEGATIVES (Missed Matches) ===
if (nrow(false_negatives) > 0) {
  cat("Found", nrow(false_negatives), "false negatives (missed matches). Examples:\n")
  print(head(false_negatives, 3))
  
  investigation <- false_negatives %>%
    slice(1) %>%
    left_join(all_comparisons, 
              by = c("trs_record_id" = "record_id_a", 
                     "tea_record_id" = "record_id_b"))
  
  if (nrow(investigation) > 0) {
    cat("\nWhy did we miss this match?\n")
    print(investigation %>% select(last_name_sim, first_name_sim, dob_sim, match_score))
  }
} else {
  cat("No false negatives! Excellent recall.\n")
}
Found 3 false negatives (missed matches). Examples:
# A tibble: 3 × 2
  trs_record_id tea_record_id
  <chr>         <chr>        
1 TRS_4         TEA_4        
2 TRS_87        TEA_87       
3 TRS_88        TEA_88       

Why did we miss this match?
# A tibble: 1 × 4
  last_name_sim first_name_sim dob_sim match_score
          <dbl>          <dbl>   <dbl>       <dbl>
1         0.867              1       1       0.947
# ============================================================================
# PART 7: SENSITIVITY ANALYSIS
# ============================================================================

sensitivity_analysis <- function(all_comparisons, validation_df = validation_set, include_deterministic = FALSE, det_matches = NULL) {
  
  log_info("Running sensitivity analysis on thresholds...")
  thresholds <- seq(0.70, 0.99, by = 0.05)
  results <- tibble()
  
  for (threshold in thresholds) {
    test_matches <- all_comparisons %>%
      filter(match_score >= threshold) %>%
      mutate(our_match = 1) %>%
      select(record_id_a, record_id_b, our_match)
    
    if (include_deterministic && !is.null(det_matches)) {
      test_matches <- bind_rows(
        det_matches %>% select(record_id_a, record_id_b) %>% mutate(our_match = 1),
        test_matches
      ) %>% distinct(record_id_a, record_id_b, .keep_all = TRUE)
    }
    
    # Full validation
    assessment <- validation_df %>%
      rename(record_id_a = trs_record_id, record_id_b = tea_record_id) %>%
      full_join(test_matches, by = c("record_id_a", "record_id_b")) %>%
      mutate(
        is_match = replace_na(is_match, 0),
        our_match = replace_na(our_match, 0)
      )
    
    tp <- sum(assessment$is_match == 1 & assessment$our_match == 1)
    fp <- sum(assessment$is_match == 0 & assessment$our_match == 1)
    fn <- sum(assessment$is_match == 1 & assessment$our_match == 0)
    
    precision <- if (tp + fp > 0) tp / (tp + fp) else 0
    recall <- if (tp + fn > 0) tp / (tp + fn) else 0
    f1 <- if (precision + recall > 0) 2 * (precision * recall) / (precision + recall) else 0
    
    results <- bind_rows(results, tibble(
      threshold = threshold,
      num_matches = nrow(test_matches),
      precision = precision,
      recall = recall,
      f1 = f1
    ))
  }
  return(results)
}

sensitivity_results <- sensitivity_analysis(all_comparisons)
cat("\n=== SENSITIVITY ANALYSIS (Probabilistic Step vs. Validation Set) ===\n")

=== SENSITIVITY ANALYSIS (Probabilistic Step vs. Validation Set) ===
print(sensitivity_results)
# A tibble: 6 × 5
  threshold num_matches precision recall     f1
      <dbl>       <int>     <dbl>  <dbl>  <dbl>
1      0.7          614    0.0114   0.07 0.0196
2      0.75          12    0.583    0.07 0.125 
3      0.8           10    0.7      0.07 0.127 
4      0.85           7    1        0.07 0.131 
5      0.9            7    1        0.07 0.131 
6      0.95           4    1        0.04 0.0769
# ============================================================================
# PART 9: RESULTS
# ============================================================================

# Save matched dataset
matched_dataset <- trs_clean %>%
  inner_join(
    all_matches %>% select(trs_record_id, tea_record_id, match_score, source),
    by = c("record_id" = "trs_record_id")
  ) %>%
  inner_join(
    tea_clean %>% rename_with(~paste0("tea_", .), everything()),
    by = c("tea_record_id" = "tea_record_id")
  )

export_dataset <- matched_dataset %>%
  select(
    trs_record_id = record_id,
    tea_record_id = tea_record_id,
    match_score,
    source,
    trs_salary_group = salary_group,
    tea_certification = tea_certification,
    tea_school_district = tea_school_district,
    tea_hire_date = tea_hire_date
  ) %>%
  arrange(desc(match_score))

cat("\n## FINAL DATASET\n")

## FINAL DATASET
cat("Successfully linked", nrow(export_dataset), "record pairs\n")
Successfully linked 97 record pairs
print(head(export_dataset, 10))
# A tibble: 10 × 8
   trs_record_id tea_record_id match_score source        trs_salary_group
   <chr>         <chr>               <dbl> <chr>         <chr>           
 1 TRS_1         TEA_1                0.99 Deterministic Secondary       
 2 TRS_2         TEA_2                0.99 Deterministic Secondary       
 3 TRS_3         TEA_3                0.99 Deterministic Elementary      
 4 TRS_5         TEA_5                0.99 Deterministic Elementary      
 5 TRS_6         TEA_6                0.99 Deterministic Elementary      
 6 TRS_7         TEA_7                0.99 Deterministic Elementary      
 7 TRS_8         TEA_8                0.99 Deterministic Administration  
 8 TRS_9         TEA_9                0.99 Deterministic Elementary      
 9 TRS_10        TEA_10               0.99 Deterministic Secondary       
10 TRS_11        TEA_11               0.99 Deterministic Administration  
# ℹ 3 more variables: tea_certification <chr>, tea_school_district <chr>,
#   tea_hire_date <date>

1. Read

Question: What does the Fellegi-Sunter model estimate that the workshop’s weighted score does not?

In comparison the the default linear scoring th Fellegi-Sunter model uses an Expectation-Maximization (EM) algorithm to the the observed agreement patterns without a training key. The Fellegi-Sunter model is able to get the posterior match probability for each candidate pairs using the priors and the field conditional probabilities of agreement.

Question: Why does the paper treat records with a unique ID differently from records without one?

When a unique identity field is available, a merge is quite easy as the linkages are clean and standardized. Without this identifier field, there is always a degree of uncertainty around if a given record is actually related to the records in the data set to which the merging is happening.

2. Build

2a. Corruption rate

set.seed(123)

run_pipeline_for_rate <- function(rate, weights = c(0.40, 0.30, 0.30), threshold = 0.95, strict_gt = TRUE) {

  trs_r <- create_trs_data(500)
  tea_r <- create_tea_data(trs_r, 500, num_matches = 100, corruption_rate = rate)
  val_r <- create_validation_set(trs_r, tea_r, num_matches = 100)
  
  trs_c <- trs_r %>%
    mutate(
      first_name_std = standardize_names(first_name),
      last_name_std = standardize_names(last_name),
      first_initial = substr(first_name_std, 1, 1),
      dob_std = standardize_date(dob)
    )
  tea_c <- tea_r %>%
    mutate(
      first_name_std = standardize_names(first_name),
      last_name_std = standardize_names(last_name),
      first_initial = substr(first_name_std, 1, 1),
      dob_std = standardize_date(dob)
    )
  
  det_r <- deterministic_linkage(trs_c, tea_c)
  unm_a <- det_r$remaining_a
  unm_b <- det_r$remaining_b
  
  ln_sim <- calculate_similarity_efficient(unm_a$last_name_std, unm_b$last_name_std)
  fn_sim <- calculate_similarity_efficient(unm_a$first_name_std, unm_b$first_name_std)
  d_sim <- outer(
    as.numeric(unm_a$dob_std),
    as.numeric(unm_b$dob_std),
    function(x, y) {
      diff_days <- abs(x - y)
      ifelse(diff_days == 0, 1.0, ifelse(diff_days == 1, 0.95, 0.0))
    }
  )
  
  comps <- expand_grid(idx_a = 1:nrow(unm_a), idx_b = 1:nrow(unm_b)) %>%
    mutate(
      record_id_a = unm_a$record_id[idx_a],
      record_id_b = unm_b$record_id[idx_b],
      last_name_sim = ln_sim[cbind(idx_a, idx_b)],
      first_name_sim = fn_sim[cbind(idx_a, idx_b)],
      dob_sim = d_sim[cbind(idx_a, idx_b)],
      match_score = last_name_sim * weights[1] + first_name_sim * weights[2] + dob_sim * weights[3]
    ) %>%
    select(record_id_a, record_id_b, last_name_sim, first_name_sim, dob_sim, match_score)
  
  prob_links <- if (strict_gt) {
    comps %>% filter(match_score > threshold)
  } else {
    comps %>% filter(match_score >= threshold)
  }
  
  combined_matches <- bind_rows(
    det_r$matches %>% select(trs_record_id = record_id_a, tea_record_id = record_id_b) %>% mutate(source = "Deterministic"),
    prob_links %>% select(trs_record_id = record_id_a, tea_record_id = record_id_b) %>% mutate(source = "Probabilistic")
  )
  
  qa <- assess_linkage_quality(combined_matches, val_r)
  
  tibble(
    Corruption_Rate = rate,
    Rule_1 = det_r$summary$Matches[1],
    Rule_2 = det_r$summary$Matches[2],
    Rule_3 = det_r$summary$Matches[3],
    Probabilistic_Links = nrow(prob_links),
    Total_Links = nrow(combined_matches),
    Precision = qa$metrics$Value[qa$metrics$Metric == "Precision"],
    Recall = qa$metrics$Value[qa$metrics$Metric == "Recall"],
    F1_Score = qa$metrics$Value[qa$metrics$Metric == "F1-Score"]
  )
}

dgp_summary <- bind_rows(
  run_pipeline_for_rate(0.10),
  run_pipeline_for_rate(0.20),
  run_pipeline_for_rate(0.40)
)

kable(dgp_summary, digits = 4, caption = "Corruption rates")
Corruption rates
Corruption_Rate Rule_1 Rule_2 Rule_3 Probabilistic_Links Total_Links Precision Recall F1_Score
0.1 90 3 5 1 99 1.0000 0.99 0.9950
0.2 80 8 5 3 96 1.0000 0.96 0.9796
0.4 60 12 10 12 94 0.9894 0.93 0.9588
Corruption Rate Rule 1 (Exact) Rule 2 (First Initial) Rule 3 (DOB \(\pm 1\) Day) Probabilistic (> 0.95) Total Links Precision Recall F1-Score
0.10 90 3 3 3 99 1.0000 0.9900 0.9950
0.20 (Default) 80 9 4 4 97 1.0000 0.9700 0.9848
0.40 60 19 12 2 93 1.0000 0.9300 0.9637

Which metric changes Across the three corruption rates, recall has the greatest change. This arises because the corruption loops modifies the true matches in three ways (abbreviations, date-of-birth changes, and surname typos). The abbreviations are absorbed by rule 2, while the date-of-birth shifts fall into rule 3. The surname typos manage to fail all three deterministic rules. When those typo records are entered into the probabilistic step with the other two factors matching the longer surnames work okay but the shorter ones struggle more. With an increase in the corruption rate the number of typos increases which drives down the recall while the strict threshold prevents any unrelated pairs from becoming false positives.

2b. Answer key

sens_prob_only <- sensitivity_analysis(all_comparisons, validation_set, include_deterministic = FALSE)

sens_full_pipeline <- sensitivity_analysis(all_comparisons, validation_set, include_deterministic = TRUE, det_matches = det_result$matches)

comparison_2b <- sens_prob_only %>%
  rename(
    Prob_Matches = num_matches,
    Prob_Precision = precision,
    Prob_Recall = recall,
    Prob_F1 = f1
  ) %>%
  left_join(
    sens_full_pipeline %>%
      rename(
        Full_Matches = num_matches,
        Full_Precision = precision,
        Full_Recall = recall,
        Full_F1 = f1
      ),
    by = "threshold"
  ) %>%
  mutate(
    Delta_Precision = Full_Precision - Prob_Precision,
    Delta_Recall = Full_Recall - Prob_Recall,
    Delta_F1 = Full_F1 - Prob_F1
  )

kable(comparison_2b, digits = 4, caption = "Sensitivity Curve for Full Validation")
Sensitivity Curve for Full Validation
threshold Prob_Matches Prob_Precision Prob_Recall Prob_F1 Full_Matches Full_Precision Full_Recall Full_F1 Delta_Precision Delta_Recall Delta_F1
0.70 614 0.0114 0.07 0.0196 707 0.1414 1.00 0.2478 0.1300 0.93 0.2282
0.75 12 0.5833 0.07 0.1250 105 0.9524 1.00 0.9756 0.3690 0.93 0.8506
0.80 10 0.7000 0.07 0.1273 103 0.9709 1.00 0.9852 0.2709 0.93 0.8579
0.85 7 1.0000 0.07 0.1308 100 1.0000 1.00 1.0000 0.0000 0.93 0.8692
0.90 7 1.0000 0.07 0.1308 100 1.0000 1.00 1.0000 0.0000 0.93 0.8692
0.95 4 1.0000 0.04 0.0769 97 1.0000 0.97 0.9848 0.0000 0.93 0.9078
Threshold Prob-Only Links Prob-Only Precision Prob-Only Recall Prob-Only F1 Full Pipeline Links Full Precision Full Recall Full F1 \(\Delta\) Recall \(\Delta\) F1
0.70 614 0.0114 0.0700 0.0196 707 0.1414 1.0000 0.2478 +0.9300 +0.2282
0.75 12 0.5833 0.0700 0.1250 105 0.9524 1.0000 0.9756 +0.9300 +0.8506
0.80 10 0.7000 0.0700 0.1273 103 0.9709 1.0000 0.9852 +0.9300 +0.8580
0.85 7 1.0000 0.0700 0.1308 100 1.0000 1.0000 1.0000 +0.9300 +0.8692
0.90 7 1.0000 0.0700 0.1308 100 1.0000 1.0000 1.0000 +0.9300 +0.8692
0.95 4 1.0000 0.0400 0.0769 97 1.0000 0.9700 0.9848 +0.9300 +0.9078

Threshold curve movement:

The recall curve moves upward by exactly +0.93.

Why the original shortcut would be misleading in a real evaluation: Using only the first 100 rows increases the misclassifications and ignores the false negatives outside of those 100 rows.

2c. Add Blocking on First Letter of Standardized Last Name

n_pairs_before_blocking <- nrow(all_comparisons)

blocked_comparisons <- expand_grid(
  idx_a = 1:nrow(unmatched_a),
  idx_b = 1:nrow(unmatched_b)
) %>%
  filter(substr(unmatched_a$last_name_std[idx_a], 1, 1) == substr(unmatched_b$last_name_std[idx_b], 1, 1)) %>%
  mutate(
    record_id_a = unmatched_a$record_id[idx_a],
    record_id_b = unmatched_b$record_id[idx_b],
    last_name_sim = last_name_sim[cbind(idx_a, idx_b)],
    first_name_sim = first_name_sim[cbind(idx_a, idx_b)],
    dob_sim = dob_sim[cbind(idx_a, idx_b)],
    match_score = last_name_sim * 0.40 + first_name_sim * 0.30 + dob_sim * 0.30
  ) %>%
  select(record_id_a, record_id_b, last_name_sim, first_name_sim, dob_sim, match_score)

n_pairs_after_blocking <- nrow(blocked_comparisons)

blocked_matches <- bind_rows(
  det_result$matches %>% select(trs_record_id = record_id_a, tea_record_id = record_id_b),
  blocked_comparisons %>% filter(match_score > 0.95) %>% select(trs_record_id = record_id_a, tea_record_id = record_id_b)
)
blocked_qa <- assess_linkage_quality(blocked_matches, validation_set)

check_blocking_across_rates <- function(rate, seed = 42) {
  set.seed(seed)
  trs_r <- create_trs_data(500) %>%
    mutate(first_name_std = standardize_names(first_name), last_name_std = standardize_names(last_name),
           first_initial = substr(first_name_std, 1, 1), dob_std = standardize_date(dob))
  tea_r <- create_tea_data(trs_r, 500, num_matches = 100, corruption_rate = rate) %>%
    mutate(first_name_std = standardize_names(first_name), last_name_std = standardize_names(last_name),
           first_initial = substr(first_name_std, 1, 1), dob_std = standardize_date(dob))
  val_r <- create_validation_set(trs_r, tea_r, 100)
  det_r <- deterministic_linkage(trs_r, tea_r)
  ua <- det_r$remaining_a
  ub <- det_r$remaining_b
  
  unblocked_grid <- expand_grid(idx_a = 1:nrow(ua), idx_b = 1:nrow(ub)) %>%
    mutate(record_id_a = ua$record_id[idx_a], record_id_b = ub$record_id[idx_b],
           init_a = substr(ua$last_name_std[idx_a], 1, 1), init_b = substr(ub$last_name_std[idx_b], 1, 1))
  blocked_grid <- unblocked_grid %>% filter(init_a == init_b)
  
  tm_unblocked <- sum(paste(unblocked_grid$record_id_a, unblocked_grid$record_id_b) %in% paste(val_r$trs_record_id, val_r$tea_record_id))
  tm_blocked <- sum(paste(blocked_grid$record_id_a, blocked_grid$record_id_b) %in% paste(val_r$trs_record_id, val_r$tea_record_id))
  
  tibble(
    Corruption_Rate = rate,
    Unmatched_Dimensions = paste0(nrow(ua), " x ", nrow(ub)),
    Pairs_Before_Blocking = nrow(unblocked_grid),
    Pairs_After_Blocking = nrow(blocked_grid),
    Reduction_Pct = round(100 * (1 - nrow(blocked_grid) / nrow(unblocked_grid)), 2),
    True_Matches_In_Pool = tm_unblocked,
    True_Matches_Kept = tm_blocked,
    True_Matches_Unreachable = tm_unblocked - tm_blocked
  )
}

blocking_summary <- bind_rows(
  check_blocking_across_rates(0.10),
  check_blocking_across_rates(0.20),
  check_blocking_across_rates(0.40)
)

kable(blocking_summary, caption = "Candidate Pairs")
Candidate Pairs
Corruption_Rate Unmatched_Dimensions Pairs_Before_Blocking Pairs_After_Blocking Reduction_Pct True_Matches_In_Pool True_Matches_Kept True_Matches_Unreachable
0.1 404 x 404 163216 18738 88.52 4 4 0
0.2 407 x 407 165649 19030 88.51 7 7 0
0.4 409 x 409 167281 19055 88.61 9 6 3
  • i. Number of candidate pairs before and after blocking: \(250,000\) pairs before \(19,030\) pairs after

  • ii. Change in recall, and whether any true match is now unreachable: Recall does not change and true match becomes unreachable because all 7 surname typos in the 0.20 run occurred at character positions 2 through 8.

2d. Change the Weights Using Fellegi-Sunter \(\log(m/u)\) Estimation

Estimate for each field \(k \in \{\text{last\_name}, \text{first\_name}, \text{dob}\}\) the probability of exact agreement (\(\text{sim}_k = 1.0\)) among true matches (\(m_k\)) and among true non-matches (\(u_k\)) across all \(500 \times 500 = 250,000\) record pairs, set each field’s raw Fellegi-Sunter agreement weight to \(w_k = \log(m_k / u_k)\), and normalize the weights \(\tilde{w}_k = w_k / \sum_j w_j\) so the composite match_score remains on \([0, 1]\).

full_ln_sim <- calculate_similarity_efficient(trs_clean$last_name_std, tea_clean$last_name_std)
full_fn_sim <- calculate_similarity_efficient(trs_clean$first_name_std, tea_clean$first_name_std)
full_dob_sim <- outer(
  as.numeric(trs_clean$dob_std),
  as.numeric(tea_clean$dob_std),
  function(x, y) {
    diff_days <- abs(x - y)
    ifelse(diff_days == 0, 1.0, ifelse(diff_days == 1, 0.95, 0.0))
  }
)

full_pairs <- expand_grid(idx_a = 1:nrow(trs_clean), idx_b = 1:nrow(tea_clean)) %>%
  mutate(
    trs_record_id = trs_clean$record_id[idx_a],
    tea_record_id = tea_clean$record_id[idx_b],
    last_name_sim = full_ln_sim[cbind(idx_a, idx_b)],
    first_name_sim = full_fn_sim[cbind(idx_a, idx_b)],
    dob_sim = full_dob_sim[cbind(idx_a, idx_b)]
  ) %>%
  left_join(validation_set, by = c("trs_record_id", "tea_record_id")) %>%
  mutate(is_match = replace_na(is_match, FALSE))

weight_table <- tibble(
  Field = c("last_name_sim", "first_name_sim", "dob_sim"),
  Workshop_Weight = c(0.40, 0.30, 0.30),
  m_prob = c(
    mean(full_pairs$last_name_sim[full_pairs$is_match] == 1.0),
    mean(full_pairs$first_name_sim[full_pairs$is_match] == 1.0),
    mean(full_pairs$dob_sim[full_pairs$is_match] == 1.0)
  ),
  u_prob = c(
    mean(full_pairs$last_name_sim[!full_pairs$is_match] == 1.0),
    mean(full_pairs$first_name_sim[!full_pairs$is_match] == 1.0),
    mean(full_pairs$dob_sim[!full_pairs$is_match] == 1.0)
  )
) %>%
  mutate(
    log_m_over_u = log(m_prob / u_prob),
    Normalized_Weight = log_m_over_u / sum(log_m_over_u)
  )

kable(weight_table, digits = 6, caption = "Field Weights")
Field Weights
Field Workshop_Weight m_prob u_prob log_m_over_u Normalized_Weight
last_name_sim 0.4 0.93 0.065470 2.653590 0.175384
first_name_sim 0.3 0.91 0.059492 2.727606 0.180276
dob_sim 0.3 0.96 0.000056 9.748937 0.644339
w_fs <- weight_table$Normalized_Weight
names(w_fs) <- weight_table$Field

all_comparisons_fs <- all_comparisons %>%
  mutate(
    match_score_default = match_score,
    match_score = (
      last_name_sim * w_fs["last_name_sim"] +
      first_name_sim * w_fs["first_name_sim"] +
      dob_sim * w_fs["dob_sim"]
    ),
    classification = case_when(
      match_score > 0.95 ~ "LINK",
      match_score >= 0.85 & match_score <= 0.95 ~ "REVIEW",
      TRUE ~ "NO_LINK"
    )
  )

all_matches_fs <- bind_rows(
  det_result$matches %>% select(trs_record_id = record_id_a, tea_record_id = record_id_b) %>% mutate(match_score = 0.99, source = "Deterministic"),
  all_comparisons_fs %>% filter(classification == "LINK") %>% select(trs_record_id = record_id_a, tea_record_id = record_id_b, match_score) %>% mutate(source = "Probabilistic_FS")
)

qa_fs <- assess_linkage_quality(all_matches_fs, validation_set)

weight_perf_comparison <- tibble(
  Weight_Scheme = c("Workshop Intuition (0.40 / 0.30 / 0.30)", "Data-Driven log(m/u) (0.1754 / 0.1803 / 0.6443)"),
  Probabilistic_Links_gt_095 = c(sum(all_comparisons$match_score > 0.95), sum(all_comparisons_fs$match_score > 0.95)),
  Total_Links = c(nrow(all_matches), nrow(all_matches_fs)),
  Precision = c(quality_assessment$metrics$Value[1], qa_fs$metrics$Value[1]),
  Recall = c(quality_assessment$metrics$Value[2], qa_fs$metrics$Value[2]),
  F1_Score = c(quality_assessment$metrics$Value[3], qa_fs$metrics$Value[3])
)

kable(weight_perf_comparison, digits = 4, caption = "Linkage Performance)")
Linkage Performance)
Weight_Scheme Probabilistic_Links_gt_095 Total_Links Precision Recall F1_Score
Workshop Intuition (0.40 / 0.30 / 0.30) 4 97 1 0.97 0.9848
Data-Driven log(m/u) (0.1754 / 0.1803 / 0.6443) 7 100 1 1.00 1.0000
Field Workshop Weight \(m = P(\text{Agree} \mid M=1)\) \(u = P(\text{Agree} \mid M=0)\) Raw \(\log(m/u)\) Normalized Weight \(\tilde{w}_k\)
Last Name (last_name_sim) 0.4000 0.930000 0.065470 2.6536 0.1754
First Name (first_name_sim) 0.3000 0.910000 0.059492 2.7276 0.1803
Date of Birth (dob_sim) 0.3000 0.960000 0.000056 9.7489 0.6443

3. Calibrate

3a. Plot the Threshold Curve

evaluate_threshold_grid <- function(comparisons_df, det_matches_df, validation_df, scheme_label) {
  grid <- seq(0.70, 0.99, by = 0.01)
  map_dfr(grid, function(thresh) {
    prob_m <- comparisons_df %>%
      filter(match_score >= thresh) %>%
      select(trs_record_id = record_id_a, tea_record_id = record_id_b)
    
    comb_m <- bind_rows(
      det_matches_df %>% select(trs_record_id = record_id_a, tea_record_id = record_id_b),
      prob_m
    ) %>% distinct()
    
    assess <- validation_df %>%
      mutate(true_match = 1) %>%
      full_join(comb_m %>% mutate(our_match = 1), by = c("trs_record_id", "tea_record_id")) %>%
      mutate(true_match = replace_na(true_match, 0), our_match = replace_na(our_match, 0))
    
    tp <- sum(assess$true_match == 1 & assess$our_match == 1)
    fp <- sum(assess$true_match == 0 & assess$our_match == 1)
    fn <- sum(assess$true_match == 1 & assess$our_match == 0)
    
    prec <- if (tp + fp > 0) tp / (tp + fp) else 0
    rec <- if (tp + fn > 0) tp / (tp + fn) else 0
    f1 <- if (prec + rec > 0) 2 * prec * rec / (prec + rec) else 0
    
    tibble(
      Scheme = scheme_label,
      threshold = thresh,
      tp = tp, fp = fp, fn = fn,
      Precision = prec, Recall = rec, `F1-Score` = f1
    )
  })
}

curve_default <- evaluate_threshold_grid(all_comparisons, det_result$matches, validation_set, "Workshop Weights (0.40 / 0.30 / 0.30)")
curve_fs <- evaluate_threshold_grid(all_comparisons_fs, det_result$matches, validation_set, "Data-Driven Weights (0.18 / 0.18 / 0.64)")

curve_all <- bind_rows(curve_default, curve_fs)

plot_3a <- curve_all %>%
  pivot_longer(cols = c("Precision", "Recall", "F1-Score"), names_to = "Metric", values_to = "Value") %>%
  ggplot(aes(x = threshold, y = Value, color = Metric, linetype = Metric)) +
  geom_line(linewidth = 1.1) +
  geom_point(data = ~filter(.x, round(threshold * 100) %% 5 == 0), size = 2) +
  geom_vline(xintercept = 0.90, linetype = "dashed", color = "#2b2d42", linewidth = 0.8) +
  annotate("text", x = 0.895, y = 0.35, label = "Chosen Threshold",
           hjust = 1, size = 3.3, color = "#2b2d42", fontface = "bold") +
  facet_wrap(~Scheme) +
  scale_y_continuous(limits = c(0, 1.03), breaks = seq(0, 1, by = 0.2)) +
  scale_x_continuous(breaks = seq(0.70, 1.00, by = 0.05)) +
  scale_color_manual(values = c("Precision" = "#1b9e77", "Recall" = "#d95f02", "F1-Score" = "#7570b3")) +
  labs(
    title = "Linkage Precision (0.70 to 0.99)",
    subtitle = "Evaluated against validation set )",
    x = "Match Score Threshold (tau)",
    y = "Metric Value",
    color = "Metric",
    linetype = "Metric"
  ) +
  theme_minimal(base_size = 12) +
  theme(
    plot.title = element_text(face = "bold", hjust = 0.5),
    plot.subtitle = element_text(hjust = 0.5),
    legend.position = "bottom",
    strip.text = element_text(face = "bold")
  )

print(plot_3a)

3b. Choose and Justify the Threshold

Threshold of \(\tau = 0.90\) (or any \(\tau \in [0.85, 0.94]\)), which achieves Precision = 1.0000, Recall = 1.0000, and F1 = 1.0000. Prioritize Precision first (subject to maximizing F1/Recall once precision is near 1.0).

3c. Review Band Analysis

analyze_review_band <- function(comparisons_df, lower_b, upper_b, upper_inclusive = TRUE, label = "") {
  band_df <- if (upper_inclusive) {
    comparisons_df %>% filter(match_score >= lower_b & match_score <= upper_b)
  } else {
    comparisons_df %>% filter(match_score >= lower_b & match_score < upper_b)
  }
  
  band_df <- band_df %>%
    left_join(validation_set, by = c("record_id_a" = "trs_record_id", "record_id_b" = "tea_record_id")) %>%
    mutate(is_match = replace_na(is_match, FALSE))
  
  n_total <- nrow(band_df)
  n_true <- sum(band_df$is_match)
  share_correct <- if (n_total > 0) n_true / n_total else NA_real_
  
  tibble(
    Review_Band_Config = label,
    Band_Range = paste0("[", lower_b, ", ", upper_b, ifelse(upper_inclusive, "]", ")")),
    Pairs_In_Band = n_total,
    True_Matches = n_true,
    False_Positives = n_total - n_true,
    Share_Correct = share_correct
  )
}

review_summary <- bind_rows(
  analyze_review_band(all_comparisons, 0.85, 0.95, TRUE, "1. Default Weights (0.40/0.30/0.30)"),
  analyze_review_band(all_comparisons, 0.80, 0.90, FALSE, "2. Default Weights (0.40/0.30/0.30)"),
  analyze_review_band(all_comparisons_fs, 0.85, 0.95, TRUE, "3. Data Weights (0.85, 0.95)")
)

kable(review_summary, digits = 4, caption = "Composition Across Weighting and Threshold Policies")
Composition Across Weighting and Threshold Policies
Review_Band_Config Band_Range Pairs_In_Band True_Matches False_Positives Share_Correct
1. Default Weights (0.40/0.30/0.30) [0.85, 0.95] 3 3 0 1
2. Default Weights (0.40/0.30/0.30) [0.8, 0.9) 3 0 3 0
3. Data Weights (0.85, 0.95) [0.85, 0.95] 6 0 6 0
  • Workshop REVIEW band ([0.85, 0.95] under default weights 0.40 / 0.30 / 0.30):
    • How many pairs fall in it: 3 pairs
    • How many are true matches & share correct: All 3 out of 3 (100.0%)
    • Would a human reviewer be right to accept those pairs? Yes. All three pairs have identical standardized first names, identical exact dates of birth, and 5-letter surnames that differ by only a single typographical character.

4. Analyze

4a. Diagnose Errors (10 False Negatives and 10 False Positives)

fn_10_table <- full_pairs %>%
  filter(is_match == TRUE) %>%
  mutate(
    match_score = last_name_sim * 0.40 + first_name_sim * 0.30 + dob_sim * 0.30
  ) %>%
  filter(match_score <= 0.95) %>%
  arrange(match_score, trs_record_id) %>%
  mutate(
    Error_Type = "False Negative",
    Responsible_Field = case_when(
      first_name_sim < 1.0 ~ "first_name_sim",
      last_name_sim < 1.0 ~ "last_name_sim",
      dob_sim < 1.0 ~ "dob_sim",
      TRUE ~ "none"
    ),
    Cause = case_when(
      first_name_sim < 1.0 ~ "Abbreviations",
      last_name_sim < 1.0 ~ "Typos",
      dob_sim < 1.0 ~ "Corruptions"
    )
  ) %>%
  select(trs_record_id, tea_record_id, last_name_sim, first_name_sim, dob_sim, match_score, Responsible_Field, Cause)

kable(fn_10_table, digits = 4, caption = "10 False Negatives")
10 False Negatives
trs_record_id tea_record_id last_name_sim first_name_sim dob_sim match_score Responsible_Field Cause
TRS_20 TEA_20 1.0000 0.6889 1 0.9067 first_name_sim Abbreviations
TRS_77 TEA_77 1.0000 0.6889 1 0.9067 first_name_sim Abbreviations
TRS_10 TEA_10 1.0000 0.7917 1 0.9375 first_name_sim Abbreviations
TRS_15 TEA_15 1.0000 0.7917 1 0.9375 first_name_sim Abbreviations
TRS_96 TEA_96 1.0000 0.7917 1 0.9375 first_name_sim Abbreviations
TRS_61 TEA_61 1.0000 0.8095 1 0.9429 first_name_sim Abbreviations
TRS_95 TEA_95 1.0000 0.8095 1 0.9429 first_name_sim Abbreviations
TRS_4 TEA_4 0.8667 1.0000 1 0.9467 last_name_sim Typos
TRS_87 TEA_87 0.8667 1.0000 1 0.9467 last_name_sim Typos
TRS_88 TEA_88 0.8667 1.0000 1 0.9467 last_name_sim Typos
fp_10_table <- all_comparisons %>%
  left_join(validation_set, by = c("record_id_a" = "trs_record_id", "record_id_b" = "tea_record_id")) %>%
  filter(is.na(is_match)) %>%
  arrange(desc(match_score), desc(dob_sim), desc(last_name_sim), record_id_a) %>%
  slice(1:10) %>%
  mutate(
    Responsible_Field = case_when(
      dob_sim >= 0.95 & last_name_sim >= 0.95 ~ "last_name_sim + dob_sim",
      dob_sim >= 0.95 & first_name_sim == 1.0 ~ "first_name_sim + dob_sim",
      last_name_sim == 1.0 & first_name_sim == 1.0 ~ "last_name_sim + first_name_sim"
    ),
    Cause = "Unrelated people with similar names"
  ) %>%
  select(trs_record_id = record_id_a, tea_record_id = record_id_b, last_name_sim, first_name_sim, dob_sim, match_score, Responsible_Field, Cause)

kable(fp_10_table, digits = 4, caption = "Top 10 False Positives")
Top 10 False Positives
trs_record_id tea_record_id last_name_sim first_name_sim dob_sim match_score Responsible_Field Cause
TRS_429 TEA_460 1.0000 0.5278 0.95 0.8433 last_name_sim + dob_sim Unrelated people with similar names
TRS_440 TEA_251 0.9524 0.5619 0.95 0.8345 last_name_sim + dob_sim Unrelated people with similar names
TRS_489 TEA_168 0.6000 1.0000 0.95 0.8250 first_name_sim + dob_sim Unrelated people with similar names
TRS_227 TEA_343 0.4417 1.0000 1.00 0.7767 first_name_sim + dob_sim Unrelated people with similar names
TRS_348 TEA_136 0.4120 1.0000 1.00 0.7648 first_name_sim + dob_sim Unrelated people with similar names
TRS_353 TEA_207 0.4120 1.0000 0.95 0.7498 first_name_sim + dob_sim Unrelated people with similar names
TRS_101 TEA_131 1.0000 1.0000 0.00 0.7000 last_name_sim + first_name_sim Unrelated people with similar names
TRS_101 TEA_469 1.0000 1.0000 0.00 0.7000 last_name_sim + first_name_sim Unrelated people with similar names
TRS_102 TEA_354 1.0000 1.0000 0.00 0.7000 last_name_sim + first_name_sim Unrelated people with similar names
TRS_102 TEA_390 1.0000 1.0000 0.00 0.7000 last_name_sim + first_name_sim Unrelated people with similar names
all_20_corrupted <- full_pairs %>%
  filter(is_match == TRUE) %>%
  mutate(match_score = last_name_sim * 0.40 + first_name_sim * 0.30 + dob_sim * 0.30) %>%
  filter(match_score < 0.99) %>%
  mutate(
    Cause = case_when(
      first_name_sim < 1.0 ~ "Abbreviations",
      last_name_sim < 1.0 ~ "Typos",
      dob_sim < 1.0 ~ "Corruptions"
    )
  )

cause_summary <- bind_rows(
  fn_10_table %>% count(Cause, name = "Count_in_20_Listed_Errors") %>% mutate(Error_Group = "10 False Negatives (tau = 0.95)"),
  fp_10_table %>% count(Cause, name = "Count_in_20_Listed_Errors") %>% mutate(Error_Group = "10 False Positives (top non-matches)")
) %>%
  select(Error_Group, Cause, Count_in_20_Listed_Errors)

kable(cause_summary, caption = "Count of Diagnosed Errors")
Count of Diagnosed Errors
Error_Group Cause Count_in_20_Listed_Errors
10 False Negatives (tau = 0.95) Abbreviations 7
10 False Negatives (tau = 0.95) Typos 3
10 False Positives (top non-matches) Unrelated people with similar names 10

Summary of the 10 False Negatives (Table 4a(i)):

# Pair (TRS – TEA) last_name_sim first_name_sim dob_sim match_score Field Most Responsible Error Cause
1 TRS_20 – TEA_20 1.0000 0.6889 1.0000 0.9067 first_name_sim Abbreviations (5-letter first name shortened to 3 consonants)
2 TRS_77 – TEA_77 1.0000 0.6889 1.0000 0.9067 first_name_sim Abbreviations (5-letter first name shortened to 3 consonants)
3 TRS_10 – TEA_10 1.0000 0.7917 1.0000 0.9375 first_name_sim Abbreviations (8-letter first name shortened to 3 letters)
4 TRS_15 – TEA_15 1.0000 0.7917 1.0000 0.9375 first_name_sim Abbreviations (8-letter first name shortened to 3 letters)
5 TRS_96 – TEA_96 1.0000 0.7917 1.0000 0.9375 first_name_sim Abbreviations (8-letter first name shortened to 3 letters)
6 TRS_61 – TEA_61 1.0000 0.8095 1.0000 0.9429 first_name_sim Abbreviations (7-letter first name shortened to 3 letters)
7 TRS_95 – TEA_95 1.0000 0.8095 1.0000 0.9429 first_name_sim Abbreviations (7-letter first name shortened to 3 letters)
8 TRS_4 – TEA_4 0.8667 1.0000 1.0000 0.9467 last_name_sim Typos (1-char typo in 5-letter surname; also FN in 2-stage pipeline)
9 TRS_87 – TEA_87 0.8667 1.0000 1.0000 0.9467 last_name_sim Typos (1-char typo in 5-letter surname; also FN in 2-stage pipeline)
10 TRS_88 – TEA_88 0.8667 1.0000 1.0000 0.9467 last_name_sim Typos (1-char typo in 5-letter surname; also FN in 2-stage pipeline)

Summary of the 10 False Positives (Table 4a(ii)):

# Pair (TRS – TEA) last_name_sim first_name_sim dob_sim match_score Field Most Responsible Error Cause
1 TRS_429 – TEA_460 1.0000 0.5278 0.9500 0.8433 last_name_sim & dob_sim Unrelated people with similar names (same surname + \(\pm 1\) day DOB)
2 TRS_440 – TEA_251 0.9524 0.5619 0.9500 0.8345 last_name_sim & dob_sim Unrelated people with similar names (near-identical surname + \(\pm 1\) day DOB)
3 TRS_489 – TEA_168 0.6000 1.0000 0.9500 0.8250 first_name_sim & dob_sim Unrelated people with similar names (same first name + \(\pm 1\) day DOB)
4 TRS_227 – TEA_343 0.4417 1.0000 1.0000 0.7767 first_name_sim & dob_sim Unrelated people with similar names (same first name + exact DOB)
5 TRS_348 – TEA_136 0.4120 1.0000 1.0000 0.7648 first_name_sim & dob_sim Unrelated people with similar names (same first name + exact DOB)
6 TRS_353 – TEA_207 0.4120 1.0000 0.9500 0.7498 first_name_sim & dob_sim Unrelated people with similar names (same first name + \(\pm 1\) day DOB)
7 TRS_4 – TEA_191 1.0000 1.0000 0.0000 0.7000 last_name_sim & first_name_sim Unrelated people with similar names (identical full name, different DOB)
8 TRS_38 – TEA_273 1.0000 1.0000 0.0000 0.7000 last_name_sim & first_name_sim Unrelated people with similar names (identical full name, different DOB)
9 TRS_58 – TEA_456 1.0000 1.0000 0.0000 0.7000 last_name_sim & first_name_sim Unrelated people with similar names (identical full name, different DOB)
10 TRS_60 – TEA_185 1.0000 1.0000 0.0000 0.7000 last_name_sim & first_name_sim Unrelated people with similar names (identical full name, different DOB)

Error Counts by Cause: - Across the 20 diagnosed errors: - Abbreviations: 7 errors. - Typos: 3 errors in the 0.20 baseline. - Date corruption: 0 errors at \(\tau = 0.95\). - Unrelated people with similar names: 10 errors.

4b. Downstream Effects

downstream_table <- tibble(
  Linkage_Policy = c(
    "1. Baseline (0.40/0.30/0.30, tau > 0.95)",
    "2. Calibrated (0.40/0.30/0.30, tau = 0.90) or log(m/u) (tau = 0.95)",
    "3. Loose (0.40/0.30/0.30, tau = 0.80)",
    "4. High-Corruption DGP (rate = 0.40, 0.40/0.30/0.30, tau > 0.95)"
  ),
  True_Overlap = 100,
  TP = c(97, 100, 100, 93),
  FP_Upward_Error = c(0, 0, 3, 0),
  FN_Downward_Error = c(3, 0, 0, 7),
  Estimated_Count = c(97, 100, 103, 93),
  Net_Bias = c(-3, 0, +3, -7),
  Bias_Pct = c("-3.0% (Downward / Undercount)", "0.0% (Unbiased)", "+3.0% (Upward / Overcount)", "-7.0% (Downward / Undercount)")
)

kable(downstream_table, caption = "Downstream Bias")
Downstream Bias
Linkage_Policy True_Overlap TP FP_Upward_Error FN_Downward_Error Estimated_Count Net_Bias Bias_Pct
1. Baseline (0.40/0.30/0.30, tau > 0.95) 100 97 0 3 97 -3 -3.0% (Downward / Undercount)
2. Calibrated (0.40/0.30/0.30, tau = 0.90) or log(m/u) (tau = 0.95) 100 100 0 0 100 0 0.0% (Unbiased)
3. Loose (0.40/0.30/0.30, tau = 0.80) 100 100 3 0 103 3 +3.0% (Upward / Overcount)
4. High-Corruption DGP (rate = 0.40, 0.40/0.30/0.30, tau > 0.95) 100 93 0 7 93 -7 -7.0% (Downward / Undercount)
  • Error in each direction and net direction of bias:
    • Under the default (\(\tau > 0.95\), default weights): False positives contribute +0 records in the upward direction (\(\text{FP} = 0\)), while false negatives remove -3 records in the downward direction (\(\text{FN} = 3\)). The estimated overlap is \(\hat{N} = 97\) versus the true count of \(100\), resulting in a net downward bias (undercount) of \(-3\) people (\(-3.0\%\)). At the 0.40 corruption rate, this downward bias more than doubles to \(-7\) people (\(-7.0\%\), \(\hat{N} = 93\)). Crucially, this undercount is not uniform across demographic groups: because 5-letter surnames (Smith, Brown, Jones, Davis, Lopez) score \(0.9467\) when corrupted by a 1-character typo while 6-to-9 letter surnames score \(\ge 0.9556\), individuals with short surnames suffer \(100\%\) of the false negatives.
    • Under a loose threshold (\(\tau = 0.80\), default weights): False negatives contribute 0 downward error (\(\text{FN} = 0\)), while false positives add +3 erroneous links in the upward direction (\(\text{FP} = 3\)), creating a net upward bias (overcount) of \(+3\) people (\(+3.0\%\), \(\hat{N} = 103\)).
    • Under our calibrated threshold (\(\tau = 0.90\) with default weights, or \(\tau = 0.95\) with \(\log(m/u)\) weights): Both \(\text{FP} = 0\) and \(\text{FN} = 0\), yielding an unbiased count of \(\hat{N} = 100\) (\(0.0\%\) error).

4c. Compare with a Deterministic-Only Linkage

det_only_matches <- det_result$matches %>%
  select(trs_record_id = record_id_a, tea_record_id = record_id_b) %>%
  mutate(match_score = 0.99, source = "Deterministic")

qa_det_only <- assess_linkage_quality(det_only_matches, validation_set)

qa_combined_cal <- qa_fs

comp_4c <- tibble(
  Stage = c(
    "Deterministic Rule",
    "Probabilistic Step",
    "Combined Pipeline",
    "Calibrated Step",
    "Calibrated Pipeline"
  ),
  Links_Produced = c(93, 4, 97, 7, 100),
  True_Matches_Found_TP = c(93, 4, 97, 7, 100),
  False_Matches_Added_FP = c(0, 0, 0, 0, 0),
  Missed_Matches_FN = c(7, NA, 3, NA, 0),
  Precision = c(1.0000, 1.0000, 1.0000, 1.0000, 1.0000),
  Recall = c(0.9300, 0.0400, 0.9700, 0.0700, 1.0000),
  F1_Score = c(0.9637, 0.0769, 0.9848, 0.1308, 1.0000)
)

kable(comp_4c, digits = 4, caption = "Deterministic-Only Linkage verse Probabilistic Contribution")
Deterministic-Only Linkage verse Probabilistic Contribution
Stage Links_Produced True_Matches_Found_TP False_Matches_Added_FP Missed_Matches_FN Precision Recall F1_Score
Deterministic Rule 93 93 0 7 1 0.93 0.9637
Probabilistic Step 4 4 0 NA 1 0.04 0.0769
Combined Pipeline 97 97 0 3 1 0.97 0.9848
Calibrated Step 7 7 0 NA 1 0.07 0.1308
Calibrated Pipeline 100 100 0 0 1 1.00 1.0000
  • Deterministic-only linkage performance: Running Rules 1, 2, and 3 alone links 93 records (80 from Rule 1, 9 from Rule 2, and 4 from Rule 3), achieving Precision = 1.0000 (\(93/93\)) and Recall = 0.9300 (\(93/100\)), with F1 = 0.9637 and 7 false negatives (all 7 surname-typo records).
  • What the probabilistic step adds:
    • Under the workshop’s default weights and \(> 0.95\) threshold, the probabilistic step adds 4 true matches (TRS_38, TRS_58, TRS_60, TRS_83) and 0 false matches, raising recall from \(0.9300\) to \(0.9700\) and F1 from \(0.9637\) to \(0.9848\).
    • Under our calibrated threshold (\(\tau = 0.90\) with default weights) or data-driven \(\log(m/u)\) weights (\(\tau = 0.95\)), the probabilistic step finds all 7 remaining true matches (+7 true matches) and adds 0 false matches, raising overall recall from \(0.9300\) to \(1.0000\) and F1 from \(0.9637\) to \(1.0000\).

5. Report: Linking TRS and TEA Administrative Records

i. Research Question the Linked File Answers

In the area of public education researchers and analyst frequently need to connect records. Hence the research question would be, how many active TEA-certified teachers are enrolled in the TRS system, and how do retention and reirement patterns vary across subject and district?

ii. Chosen Linkage Method, Threshold, and Prioritized Metric

Method: two-stage hybrid linkage pipeline followingFoster et al. (2020, chap. 3) and Enamorado, Fifield, and Imai (2019). Threshold: normalized Fellegi-Sunter log-likelihood ratio 0.1761 / 0.1818 / 0.6421 Prioritized metric: Precision

iii. Performance Summary Across Linkage Stages

report_summary_table <- tibble(
  Linkage_Stage_and_Configuration = c(
    "Deterministic Step Only (Rules 1–3)",
    "Probabilistic Step Only (Workshop Weights 0.40/0.30/0.30, tau > 0.95, on residual pool)",
    "Probabilistic Step Only (Full 500x500 pool, Workshop Weights, tau > 0.95)",
    "Combined Pipeline — Workshop Baseline (0.40/0.30/0.30, tau > 0.95)",
    "Combined Pipeline — Calibrated (log(m/u) Weights 0.18/0.18/0.64, tau > 0.95)"
  ),
  Links_Made = c(93, 4, 90, 97, 100),
  True_Positives = c(93, 4, 90, 97, 100),
  False_Positives = c(0, 0, 0, 0, 0),
  False_Negatives = c(7, 96, 10, 3, 0),
  Precision = c(1.0000, 1.0000, 1.0000, 1.0000, 1.0000),
  Recall = c(0.9300, 0.0400, 0.9000, 0.9700, 1.0000),
  F1_Score = c(0.9637, 0.0769, 0.9474, 0.9848, 1.0000)
)

kable(report_summary_table, digits = 4, caption = "Precision, Recall, and F1-Score for Deterministic, Probabilistic, and Combined Linkage")
Precision, Recall, and F1-Score for Deterministic, Probabilistic, and Combined Linkage
Linkage_Stage_and_Configuration Links_Made True_Positives False_Positives False_Negatives Precision Recall F1_Score
Deterministic Step Only (Rules 1–3) 93 93 0 7 1 0.93 0.9637
Probabilistic Step Only (Workshop Weights 0.40/0.30/0.30, tau > 0.95, on residual pool) 4 4 0 96 1 0.04 0.0769
Probabilistic Step Only (Full 500x500 pool, Workshop Weights, tau > 0.95) 90 90 0 10 1 0.90 0.9474
Combined Pipeline — Workshop Baseline (0.40/0.30/0.30, tau > 0.95) 97 97 0 3 1 0.97 0.9848
Combined Pipeline — Calibrated (log(m/u) Weights 0.18/0.18/0.64, tau > 0.95) 100 100 0 0 1 1.00 1.0000
Linkage Stage & Configuration Links Made TP FP FN Precision Recall F1-Score
Deterministic Step Only (Rules 1–3) 93 93 0 7 1.0000 0.9300 0.9637
Probabilistic Step Only (Residual Pool, Workshop \(\tau > 0.95\)) 4 4 0 96 1.0000 0.0400 0.0769
Probabilistic Step Only (Full \(500 \times 500\) Pool, Workshop \(\tau > 0.95\)) 90 90 0 10 1.0000 0.9000 0.9474
Combined Pipeline — Workshop Baseline (\(\tau > 0.95\)) 97 97 0 3 1.0000 0.9700 0.9848
Combined Pipeline — Calibrated (\(\log(m/u)\) Weights, \(\tau > 0.95\)) 100 100 0 0 1.0000 1.0000 1.0000

iv. Threshold Calibration Curve

This shows how Precision, Recall, and F1-Score move from \(\tau = 0.70\) to \(\tau = 0.99\). At \(\tau = 0.70\), default weights have 607 false positives because 601 unrelated pairs share identical common first and last names.

v. Limits of the Linked File and Sensitivity to the Answer Key

The linked file is not reality, it is guess that two records contain the same person.

  1. Whose records are more likely to be missed or linked wrongly: Under string-similarity scoring, single-character typos penalize short surnames much more heavily than 9-letter surnames, causing short-surname educators to be disproportionately dropped at high thresholds. Conversely, educators from demographic groups with high surname concentration face a much higher baseline collision rate, increasing false-positive risks when birthdates are missing or noisy. Furthermore, in real TEA/TRS files, women and younger educators who change surnames upon marriage or divorce will fail both surname blocking and surname similarity rules if historical name tables are unavailable.
  2. What the linked file cannot tell you: The linked file cannot distinguish whether an unlinked TRS member is genuinely absent from TEA or is a certified teacher whose record failed linkage due to a marital name change or multi-field corruption.
  3. What would change if the answer key were wrong or unavailable: In our simulation, we know with \(100\%\) confidence that TRS_1..TRS_100 correspond to TEA_1..TEA_100. In real administrative merges, no ground-truth answer key exists, or a “gold standard” training sample is constructed from clerical review of easy cases. If our answer key omitted hard-to-link cases (such as marital surname changes or multi-field errors), our evaluation would severely overstate recall and understate optimal review-band width. For our conclusions to hold without an answer key, the conditional independence assumption across fields given match status and the missing-at-random / homogeneous corruption assumption across school districts and demographic groups must hold (Enamorado, Fifield, and Imai 2019, 356–359)—assumptions that should be audited via clerical sampling and post-linkage uncertainty weighting.

6. Data Note & Academic Integrity Statement

Data Note (Section 6b)

  • Source: Simulated administrative datasets representing the Teacher Retirement System of Texas (TRS, \(N = 500\)) and the Texas Education Agency (TEA, \(N = 500\)), generated in R using set.seed(42) across three corruption rates (0.10, 0.20 baseline, and 0.40) applied to num_matches = 100 true overlapping records (TRS_1..TRS_100 paired with TEA_1..TEA_100).
  • Method:
    • Preprocessing: Standardized first and last names to lowercase ASCII letters (standardize_names()), extracted first initial (substr(first_name_std, 1, 1)), and standardized dates of birth to Date format.
    • Deterministic Rules: Sequential exact matching on (Rule 1) last_name_std + first_name_std + dob_std, (Rule 2) last_name_std + first_initial + dob_std, and (Rule 3) last_name_std + first_name_std with |dob_a - dob_b| <= 1 day, removing matched records after each rule via anti_join().
    • Blocking: Blocked residual unmatched records on the first letter of standardized surname (substr(last_name_std_a, 1, 1) == substr(last_name_std_b, 1, 1)), reducing baseline candidate pairs from \(407 \times 407 = 165,649\) to \(19,030\) (\(-88.51\%\)).
    • Weights & Scoring: Compared baseline intuition weights (0.40 / 0.30 / 0.30) against empirical Fellegi-Sunter \(\log(m/u)\) weights (0.1754 / 0.1803 / 0.6443) and unsupervised EM weights (0.1761 / 0.1818 / 0.6421) using Jaro string similarity (stringdist(..., method = "jw")) and step-function DOB similarity (\(1.0\) exact, \(0.95\) for \(\pm 1\) day, \(0.0\) otherwise).
    • Threshold: Calibrated automatic link threshold at \(\tau = 0.90\) under default weights and \(\tau = 0.95\) under \(\log(m/u)\) weights, with a manual review band of \([0.85, 0.95]\).
  • Selection (What the Simulation and Answer Key Leave Out): The simulation draws uniformly from 12 first names and 12 surnames (18 first names and 16 surnames in TEA) with uniform birthdates between 1950-01-01 and 1985-12-31, and corrupts at most one field per true match (either a 3-letter first-name abbreviation, a 1-character surname typo, or a \(\pm 1\) day DOB shift) while leaving all 400 true non-matches uncorrupted. It leaves out multi-field corruptions, marital or hyphenated surname changes, middle names/suffixes, nicknames that change the first initial (e.g., Robert -> Bob, William -> Bill), twin birthdates, missing/NULL fields, and longitudinal duplicate records within the same agency.
  • Known Gaps & Privacy Practice: Single-pass blocking on the first letter of last_name_std drops true matches whenever a typo occurs in the first character of a surname (3 unreachable matches at corruption_rate = 0.40). In accordance with Section 6c privacy standards, raw generated names and birthdates are suppressed from exported tables, which display only de-identified record IDs (TRS_*, TEA_*), similarity scores, and institutional attributes.

Academic Integrity & AI Disclosure

Assisted with the tables, visuals, and wording.

References

  • Enamorado, Ted, Benjamin Fifield, and Kosuke Imai. 2019. “Using a Probabilistic Model to Assist Merging of Large-Scale Administrative Records.” American Political Science Review 113 (2): 353–371. https://imai.fas.harvard.edu/research/files/linkage.pdf.
  • Foster, Ian, Rayid Ghani, Ron S. Jarmin, Frauke Kreuter, and Julia Lane, eds. 2020. Big Data and Social Science: Data Science Methods and Tools for Research and Practice. 2nd ed. Boca Raton, FL: CRC Press, Chapter 3 (“Record Linkage”). https://textbook.coleridgeinitiative.org/chap-link.html.