data(patient_records)
# An exact match on surname followed by an exact match on forename
stages <- as.list(patient_records[c("surname", "forename")])
pids_1 <- links(criteria = stages)
# An exact match on forename followed by an exact match on surname
pids_2 <- links(criteria = rev(stages))
# Nested matches
# Same sex OR year of birth
multi_cond1 <- sub_criteria(format(patient_records$dateofbirth, "%Y"),
patient_records$sex,
operator = "or")
# Same middle name AND a 10 year age difference
age_diff <- function(x, y){
diff <- abs(as.numeric(x) - as.numeric(y))
wgt <- diff %in% 0:(365 * 10) & !is.na(diff)
wgt
}
multi_cond2 <- sub_criteria(patient_records$dateofbirth,
patient_records$middlename,
operator = "and",
match_funcs = c(age_diff, exact_match))
# 'multi_cond1' OR 'multi_cond2'
nested_cond1 <- sub_criteria(multi_cond1,
multi_cond2,
operator = "or")
# Record linkage with nested conditions
pids_3 <- links(criteria = stages,
sub_criteria = list(cr1 = multi_cond1,
cr2 = multi_cond2))
# Record linkage with multiple (two) layers of nested conditions
pids_4 <- links(criteria = stages,
sub_criteria = list(cr1 = nested_cond1,
cr2 = nested_cond1))
# Record linkage without group expansion
pids_5 <- links(criteria = stages,
sub_criteria = list(cr1 = multi_cond1,
cr2 = multi_cond2),
expand = FALSE)
# Record linkage with shrinking record groups
pids_6 <- links(criteria = stages,
sub_criteria = list(cr1 = multi_cond1,
cr2 = multi_cond2),
shrink = TRUE)
Run the code above in your browser using DataLab