OMOP CDM v5.4 stores only raw address fields; it defines no RUCA or SDI. These functions derive both for each
index stay from the address in effect at admission (person_address_history, filled by load_location(); without
it person.location_id is used), a USDA ZIP -> RUCA crosswalk and a Robert Graham Center ZCTA -> SDI table, using
the fixed SDI quintile cut points of the training cohort. Cutting at quantiles of the local population would move
patients between quintiles whenever the local SDI distribution differs from training, so
derive_geography_features() errors without sdi_cut_points unless fit_cut_points = TRUE (training site only; the
fitted cuts are returned in attr(result, "sdi_cut_points")).
Usage
ruca_category(code, code_99_missing = TRUE)
validate_sdi_cut_points(cut_points)
fit_sdi_cut_points(scores)
assign_sdi_quintile(scores, cut_points)
read_ruca_crosswalk(source)
read_sdi_table(source)
derive_geography_features(
con,
ruca_crosswalk,
sdi_table,
sdi_cut_points = NULL,
stays = NULL,
address_table = "auto",
fit_cut_points = FALSE,
code_99_missing = TRUE,
tie_break = "deterministic",
undated = "last"
)Arguments
- code
Primary RUCA code (numeric or string such as
"4.2").- code_99_missing
Logical; treat RUCA 99 as unknown.
- cut_points
Four finite, strictly ascending SDI scores.
- scores
Numeric SDI scores.
- source
A data frame or CSV path.
- con
A DBI connection to an OMOP DuckDB.
- ruca_crosswalk, sdi_table
Data frame or CSV path (see
read_ruca_crosswalk(),read_sdi_table()).- sdi_cut_points
Fixed SDI quintile cut points from the training cohort; required unless
fit_cut_points.- stays
Optional data frame with
person_id,admit_dateand optionally a uniquestay_id; defaults to every inpatient visit (concepts 9201, 262) withstay_id = visit_occurrence_id.- address_table
"auto"(the one non-empty dated address table, seeresolve_address_table(); elseperson.location_idwhen it holds ZIPs; stops otherwise), a table name, orNULLfor the person's location.- fit_cut_points
Logical; fit cut points from these stays (training reference only).
- undated
Rank of an address with no start date among those in effect:
"last"(default; a dated address wins) or"first"(an undated address wins, as in the study's pandas pipeline and the delivered 2026-11-11 geography).- tie_break
Addresses that tie on every rule key:
"deterministic"(default; later start, lowest ZIP),"highest_zip","ambiguous_missing"(no ZIP, ruleambiguous, when the tied ZIPs differ) or"arbitrary"(engine order; not reproducible) or"first_listed"(the address stored first in the address table, bylocation_id; reproduces a pandas pipeline's stable sort).
Value
ruca_category(): a character vector of categories.
validate_sdi_cut_points(): the cut points as numeric, or an error.
fit_sdi_cut_points(): the 20/40/60/80th percentiles of the known scores (type 7, like NumPy).
assign_sdi_quintile(): quintile labels; a score equal to a cut point goes to the higher quintile.
read_ruca_crosswalk(): data frame zip5, ruca_code. read_sdi_table(): data frame zip5, sdi_score.
derive_geography_features(): data frame person_id, stay_id, zip5, rule, ruca_code, ruca_category, sdi_score, sdi_quintile, with the cut points used in attr(, "sdi_cut_points").
Details
Address rule (reference study): the address whose period contains the admission date; else the latest that started
before it; else the earliest that started after it. Addresses with a ZIP beat those without; ties go to
preferred = 'Y', then the nearest start date. RUCA: primary code 1 = Metropolitan, 2 = Micropolitan, 3+ = Small Town
/ Rural. USDA 99 ("not coded": unpopulated tracts, PO-box ZIPs) is "RUCA: Missing / Unknown" since 0.34.2; the reference
put it in Small Town / Rural, which code_99_missing = FALSE restores.
