Compute Pairwise Co-resistance Matrices per Pathogen
Source:R/resistance.R
compute_pairwise_coresistance.RdFor every pathogen and every pair of antibiotic classes \((c_i, c_j)\) that were both tested: $$ T_{k,i,j} = \sum_e \mathbf{1}(c_i \text{ tested} \land c_j \text{ tested}) $$ $$ R_{k,i,j} = \sum_e \mathbf{1}(R_{e,k,c_i}=1 \land R_{e,k,c_j}=1) $$ $$ \text{Prev}_{k,i,j} = R_{k,i,j} \;/\; T_{k,i,j} $$
Usage
compute_pairwise_coresistance(
marginal_output,
pathogen_col = "organism_name",
org_group_col = "org_group",
isolate_col = "isolate_id",
antibiotic_class_col = "antibiotic_class",
min_co_tested = 10,
facility_col = NULL,
facility_name = NULL,
outcome_col = NULL,
outcome_value = NULL
)Arguments
- marginal_output
The list returned by
compute_marginal_resistance(). The$class_longelement is used as input.- pathogen_col
Character. Must match the column name used in Step 1. Default
"organism_name".- org_group_col
Character. Default
"org_group".- isolate_col
Character. Default
"isolate_id".- antibiotic_class_col
Character. Default
"antibiotic_class".- min_co_tested
Integer. Pairwise cells with fewer than
min_co_testedco-tested isolates are set toNAin the prevalence matrix. Default10.- facility_col
Character or
NULL. Column identifying the facility/site. When provided together withfacility_name, filtersclass_longto the specified facility before building matrices. For this to work,compute_marginal_resistance()must have been called with the samefacility_colargument so that the column is present in$class_long. Both must be supplied together or both leftNULL. DefaultNULL.- facility_name
Character or
NULL. Facility value to retain. DefaultNULL.- outcome_col
Character or
NULL. Column containing patient outcomes. When provided together withoutcome_value, filtersclass_longto isolates with the specified outcome before building matrices.compute_marginal_resistance()must have been called with the sameoutcome_colso that the column is present in$class_long. Both must be supplied together or both leftNULL. DefaultNULL.- outcome_value
Character or
NULL. Outcome value to retain (e.g."discharged","dead"). DefaultNULL.
Value
Named list. One entry per pathogen (keyed by pathogen name), each containing:
prevalenceSquare symmetric matrix of pairwise co-resistance rates. Diagonal and cells with
n < min_co_testedareNA.T_matrixInteger matrix of co-tested isolate counts.
R_matrixInteger matrix of co-resistant isolate counts.
classesCharacter vector of class names (row/column order).
Details
Matrices are computed for all tested classes – no filtering by marginal resistance or GBD core list is applied here.
Examples
if (FALSE) { # \dontrun{
marg <- compute_marginal_resistance(amr_clean, ...)
co_res <- compute_pairwise_coresistance(marg)
# Prevalence matrix for K. pneumoniae
co_res[["Klebsiella pneumoniae"]]$prevalence
# Co-tested counts
co_res[["Klebsiella pneumoniae"]]$T_matrix
} # }