Compute Pairwise Co-resistance Using Pearson Back-calculation
Source:R/daly_resistance_profiles.R
compute_pairwise_from_data.RdFor each antibiotic-class pair (A, B) and each pathogen [x stratum], this function:
Computes the Pearson correlation \(\rho_{AB}\) between binary resistance indicators across co-tested isolates.
Back-calculates pairwise prevalence using the GBD formula: $$P(A \cap B) = P(A) P(B) + \rho_{AB} \sqrt{P(A)(1-P(A)) \cdot P(B)(1-P(B))}$$ where \(P(A)\) and \(P(B)\) come from
marginals(which may include externally overridden values).Caps the result to \(\min(P(A), P(B))\) and floors it to 0. Cells below the floor use the independence product as fallback.
Usage
compute_pairwise_from_data(
data_wide,
marginals,
col_map,
panel_map,
stratify_by = NULL,
outcome_col = NULL,
min_co_tested = 10L
)Arguments
- data_wide
Tibble. Output of
preprocess_for_profiles()$data_wide.- marginals
Tibble. Output of
compute_marginals_from_data().- col_map
Named list.
col_map_resolved.- panel_map
Named list. Same panel as used in preprocessing.
- stratify_by
Character vector or
NULL. Must match what was used incompute_marginals_from_data(). DefaultNULL.- outcome_col
Character or
NULL. DefaultNULL.- min_co_tested
Integer. Pairs with fewer co-tested isolates are reported with
method = "independence_fallback". Default10L.
Value
Tibble with one row per pathogen x class-pair [x stratum]:
pathogen,antibiotic_class_1,antibiotic_class_2Keys.
n_co_testedIsolates tested for both classes.
rhoPearson correlation between binary resistance indicators.
pairwise_prevalenceBack-calculated P(AnB), capped and floored.
method"pearson_back_calc"or"independence_fallback".