Compute Marginal Resistance Rates from Preprocessed Wide Data
Source:R/daly_resistance_profiles.R
compute_marginals_from_data.RdTakes the wide-format tibble produced by preprocess_for_profiles()
and computes marginal resistance rates per pathogen x antibiotic class,
optionally stratified by geography, year, and/or patient outcome. The
counting unit is always isolate_id: a patient with multiple isolates
contributes one count per isolate.
Usage
compute_marginals_from_data(
data_wide,
col_map,
panel_map,
stratify_by = NULL,
outcome_col = NULL,
min_n_tested = 30L,
external_marginals = NULL,
ext_col_map = list(pathogen_col = "pathogen", class_col = "antibiotic_class",
geography_col = "geography", year_col = "year", rate_col = "resistance_prevalence")
)Arguments
- data_wide
Tibble. Output of
preprocess_for_profiles()$data_wide. One row per isolate; antibiotic-class columns contain"S","R", orNA(not tested).- col_map
Named list.
col_map_resolvedfrompreprocess_for_profiles().- panel_map
Named list. Same panel used in
preprocess_for_profiles().- stratify_by
Character vector or
NULL. Dimensions to stratify over. Valid:"geography","year". DefaultNULL.- outcome_col
Character or
NULL. Column name for patient outcome. When supplied, separate marginals are computed for each outcome value (e.g. Died vs Discharged). DefaultNULL.- min_n_tested
Integer. Minimum tested-isolate count per (stratum x pathogen x class) cell. Cells below this threshold are dropped with a logged reason. Default
30L.- external_marginals
Data frame or
NULL. Pre-modelled marginal resistance rates (e.g. GBD ST-GPR estimates). When provided, locally computed rates are replaced where a match exists on pathogen x class [x geography x year]. Must have columns matchingext_col_map. DefaultNULL.- ext_col_map
Named list. Column names in
external_marginals. Defaultlist(pathogen_col="pathogen", class_col="antibiotic_class", geography_col="geography", year_col="year", rate_col="resistance_prevalence").