Compute Marginal Resistance per Pathogen and Antibiotic Class
Source:R/resistance.R
compute_marginal_resistance.RdCollapses drug-level susceptibility data to antibiotic-class level per isolate (\(R_{e,k,c} = 1\) if resistant to any drug in class \(c\)), then computes marginal resistance for every pathogen x class combination found in the data.
Usage
compute_marginal_resistance(
data,
pathogen_col = "organism_name",
org_group_col = "org_group",
isolate_col = "isolate_id",
antibiotic_class_col = "antibiotic_class",
antibiotic_value_col = "antibiotic_value",
zero_threshold = 0,
min_n_tested = 30,
facility_col = NULL,
facility_name = NULL,
outcome_col = NULL,
outcome_value = NULL
)Arguments
- data
Data frame. Pre-processed AMR data at isolate x antibiotic level (one row per isolate-antibiotic combination). Results must already be binary (
"S"/"R"); no reclassification is applied.- pathogen_col
Character. Column with pathogen names. Default
"organism_name".- org_group_col
Character. Column with organism group labels. Default
"org_group".- isolate_col
Character. Column uniquely identifying each isolate. Default
"isolate_id".- antibiotic_class_col
Character. Column with the antibiotic class for each drug. Default
"antibiotic_class".- antibiotic_value_col
Character. Column with susceptibility result (
"S"or"R"). Default"antibiotic_value".- zero_threshold
Numeric. Classes with
marginal_resistance <= zero_thresholdare listed in$near_zero. Default0.- min_n_tested
Integer or
NULL. Minimum number of isolates that must have been tested for a pathogen-class combination to be retained. Combinations withn_tested < min_n_testedare dropped from$marginaland from$class_long, so the exclusion propagates automatically intocompute_pairwise_coresistance()andcompute_resistance_profiles(). Set toNULLor0to disable the filter. Default30.- facility_col
Character or
NULL. Name of the column identifying the facility/site. When provided together withfacility_name, data are filtered to the specified facility before any computation. Bothfacility_colandfacility_namemust be supplied together or both leftNULL. When provided,facility_colis also retained in$class_longand$marginalso that downstream steps can apply the same filter. DefaultNULL.- facility_name
Character or
NULL. The facility value to retain (matched via==againstfacility_col). DefaultNULL.- outcome_col
Character or
NULL. Name of the column containing patient outcomes (e.g."final_outcome"). When provided together withoutcome_value, data are filtered to isolates with the specified outcome before any computation. Bothoutcome_colandoutcome_valuemust be supplied together or both leftNULL. When provided,outcome_colis retained in$class_longand$marginalso that downstream steps can apply the same filter. DefaultNULL.- outcome_value
Character or
NULL. The outcome value to retain (e.g."discharged","dead"; matched via==againstoutcome_col). DefaultNULL.
Value
Named list:
marginalData frame with columns:
pathogen_col,org_group_col,antibiotic_class_col,n_tested,n_resistant,marginal_resistance. Sorted descending bymarginal_resistancewithin each pathogen.near_zeroSubset of
marginalwheremarginal_resistance <= zero_threshold. These classes are candidates for exclusion in downstream profiling.class_longCollapsed isolate x pathogen x class data frame (columns:
isolate_col,pathogen_col,org_group_col,antibiotic_class_col,class_result). Pass this directly tocompute_pairwise_coresistance().
Details
Classes whose marginal resistance is at or below zero_threshold are
listed in $near_zero as a flag for downstream use – they are
not removed here.
Examples
if (FALSE) { # \dontrun{
marg <- compute_marginal_resistance(
data = amr_clean,
pathogen_col = "organism_name",
org_group_col = "org_group",
isolate_col = "isolate_id",
antibiotic_class_col = "antibiotic_class",
antibiotic_value_col = "antibiotic_value"
)
marg$marginal # full marginal resistance table
marg$near_zero # classes flagged as near-zero
} # }