Skip to contents

Pipeline

Main preprocessing pipeline and configuration

run_preprocess()
AMR Data Preprocessing Pipeline
amr_config()
Create AMR Preprocessing Configuration
validate_config()
Validate AMR Configuration
print(<amr_config>)
Print AMR Configuration
print(<amr_result>)
Print Method for AMR Preprocessing Results
summary(<amr_result>)
Summary Method for AMR Preprocessing Results
print(<amr_preprocessing_report>)
Print Preprocessing Report
detect_preprocessing_capabilities()
Detect Preprocessing Capabilities
prep_report_capabilities()
Report Preprocessing Capabilities

Standardization

Standardize column names, organisms, antibiotics, specimens, and values

prep_standardize_column_names()
Standardize Column Names to Package Convention
prep_standardize_organisms()
Normalize Organism Names
prep_standardize_antibiotics()
Normalize Antibiotic Names
prep_standardize_specimens()
Normalize Specimen/Sample Type
prep_standardize_sex()
Standardize Sex Values
prep_standardize_outcome()
Standardize Outcome Values (deprecated)
prep_clean_ast_values()
Clean Antibiotic Susceptibility Values
prep_recode_intermediate_ast()
Recode Intermediate (I) Susceptibility Values
prep_parse_date_column()
Detect and decode encrypted or non-standard date columns
prep_coerce_dates()
Detect and convert all date-like columns in a table
prep_standardize_final_outcome()
Standardize Final Outcome Column
prep_standardize_infection_type()
Standardize Infection Type Column
prep_harmonize_ast()
Harmonize AST Values
prep_flag_invalid_ast()
Flag Invalid AST Values
prep_decode_antibiotic_code()
Decode Antibiotic Short Codes to Full Names

Classification

MDR/XDR classification, organism grouping, AWaRe, and mortality

prep_classify_mdr_xdr()
Classify MDR and XDR
prep_assign_organism_group()
Assign Organism Group
prep_classify_antibiotic_class()
Classify Antibiotic to WHO Class
prep_classify_aware()
Classify AWaRe Category
prep_classify_mortality()
Classify Infection-Related Mortality
prep_derive_hai_cai()
Derive HAI/CAI Infection Type
prep_extract_genus()
Extract Genus from Organism Name
prep_extract_species()
Extract Species from Organism Name
prep_classify_readmission()
Classify Readmission Type
prep_flag_organism_unmatched()
Flag Organisms Unmatched in Reference

Enrichment

Derive missing variables from existing data

prep_fill_age()
Fill Missing Age Values
prep_assign_age_bins()
Assign Age Bins
prep_assign_facility_type()
Assign a facility type / sector column from a user-supplied mapping
prep_infer_department()
Infer Hospital Department
prep_clean_optional_columns()
Clean Optional Columns
prep_derive_los_from_dates()
Derive Length of Stay from Date Columns
prep_derive_icu_flag()
Derive ICU Flag
prep_derive_dob_from_components()
Derive Date of Birth from Age Components
prep_flag_hai_inferred()
Flag HAI Inferred vs Observed
prep_reconcile_hai_observed_inferred()
Reconcile Observed and Inferred HAI/CAI Classification

Deduplication and collapsing

Event IDs, deduplication, contaminant flagging, and data reshaping

prep_create_event_ids()
Create Event IDs from Patient-Level Data
prep_deduplicate_events()
Deduplicate Events
prep_flag_contaminants()
Flag Contaminant Organisms
prep_get_contaminant_list()
Get Contaminant List from Reference File
prep_is_contaminant()
Check if Organism is a Contaminant
prep_flag_polymicrobial() flag_polymicrobial()
Flag Polymicrobial Infections
prep_compute_poly_weights() compute_polymicrobial_weight()
Compute Polymicrobial Weights
prep_collapse_class_level()
Collapse to Class Level
prep_pivot_ast_wide_to_long()
Convert Wide Format to Long Format
prep_create_wide_ast_matrix()
Create Wide Format AST Matrix
prep_create_resistance_profile()
Create Resistance Profile
prep_filter_analysis_ready()
Filter Analysis-Ready Records
prep_deduplicate_ast()
Handle Duplicate AST Results
prep_split_poly_episode()
Split Polymicrobial Episodes by Strategy
prep_flag_readmission()
Flag and Classify Readmissions
prep_filter_fungal()
Filter Fungal Organisms
prep_filter_minimally_usable()
Filter Minimally Usable Records

Multi-centre stewardship import

Joining and validating multi-centre stewardship datasets

prep_check_columns()
Check required columns exist and report types
prep_check_keys()
Check join key quality
prep_validate_table()
Run all pre-join sanity checks for one table
prep_detect_schema_drift()
Detect Schema Drift Across Centres
prep_apply_column_map()
Apply Column Map to Rename Columns
prep_assert_standard_names()
Assert Standard Names Are Present
prep_build_column_map()
Build and Validate a Column Map Against a Dataset

Diagnosis and syndrome mapping

Map free-text diagnoses to ICD-10 codes and clinical syndromes

prep_map_diagnosis_to_icd()
Map Diagnosis Text to ICD Candidates
prep_map_icd_to_syndrome()
Map ICD Codes to Infectious Syndromes
prep_diagnosis_text()
Prepare Diagnosis Text
prep_assign_patient_syndrome()
Assign One Syndrome Per Patient or Event
infer_patient_syndrome_wide()
Assign Syndrome from Wide-Format Syndrome Flags

Outcome cohorts and attrition

Build outcome cohorts and track patient counts through pipeline stages

prep_attrition_flow()
Track Attrition Through the Pipeline
prep_build_fatal_cohort()
Build Fatal Cohort
prep_build_nonfatal_cohort()
Build Non-Fatal Cohort

Resistance profiles (core)

Marginal resistance, co-resistance matrices, and low-level profile computation

compute_marginal_resistance()
Compute Marginal Resistance per Pathogen and Antibiotic Class
compute_pairwise_coresistance()
Compute Pairwise Co-resistance Matrices per Pathogen
compute_resistance_profiles()
Compute Resistance Profile Probabilities per Pathogen
select_resistance_class()
Select Resistance Class for Burden Attribution
enumerate_binary_profiles()
Enumerate All Binary Resistance Profiles for a Set of Antibiotic Classes
build_constraint_matrix()
Build QP Constraint Matrix and Target Vector

Pathway 1: Convex Profile Estimation

End-to-end pipeline for estimating resistance-profile probability distributions from facility-level or aggregate surveillance data via convex optimisation (GBD equation 7.5.1.3). Supports geography, year, and outcome stratification; optional override with externally modelled marginals (e.g. GBD ST-GPR). Use as the top-level dispatcher for both Pathway 1 and Pathway 2.

estimate_resistance_profiles()
Estimate Resistance Profiles: Pathway 1 (Convex) or Pathway 2 (Bayesian)
validate_profile_inputs()
Validate Inputs for Resistance Profile Estimation (Pathway 1)
preprocess_for_profiles()
Preprocess AST Data for Resistance Profile Estimation (Pathway 1)
validate_aggregate_inputs()
Validate Pre-computed Aggregate Marginal Inputs
compute_marginals_from_data()
Compute Marginal Resistance Rates from Preprocessed Wide Data
compute_pairwise_from_data()
Compute Pairwise Co-resistance Using Pearson Back-calculation
estimate_profiles_convex()
Estimate Resistance Profile Probabilities via Convex Optimisation
check_profile_constraints()
Formally Check Resistance Profile Probability Constraints
bootstrap_profiles_convex()
Bootstrap Uncertainty Intervals for Resistance Profile Probabilities

Pathway 2: Bayesian Profile Estimation

Bayesian hierarchical multivariate probit model for estimating resistance-profile distributions from facility-level AST data. Fits a Stan model (via cmdstanr) with zero or an arbitrary, user-declared number of named random-intercept blocks (see – e.g. hospital, patient, admission, or any other grouping the analysis layer declares; the package does not hardcode which blocks are scientifically appropriate for a given dataset). Use for a fixed-effects-only model and supply when profiles are to be grouped. Two residual structures are supported: identity (default, no residual correlation) and correlated (full LKJ-Cholesky residual covariance). CPU and OpenCL backends are both supported as execution choices; backend selection changes compilation/sampling only, not the underlying model. Run once per pathogen; orchestrate across pathogens in the analysis repository. Use as the top-level entry point.

fit_bayesian_multivariate_probit()
Fit Bayesian Hierarchical Multivariate Probit Model for Resistance Profiles
validate_compute_backend()
Validate a selectable Stan compute backend configuration
prepare_random_effects()
Build the generic random-effect representation for an arbitrary number of blocks
re_contribution()
Compute each event's total random-effect contribution from a flattened re_effect[D, total_re_levels] matrix (as emitted by the generic Stan models' generated re_effect, or reconstructed R-side from posterior draws of z_re/tau_re/L_corr_re). This is the SINGLE generic helper every downstream mu-reconstruction site should call instead of hand-summing hospital_effect/patient_effect/admission_effect.
compute_event_profile_probabilities()
Compute Observed-Plus-Imputed Resistance Profile Probabilities
assess_gibbs_profile_stability()
Assess Numerical Stability of Correlated Profile Completion
aggregate_profiles_for_daly()
Aggregate Posterior Profile Draws into R_ALL / R_KNOWN_OUTCOME / R_NF Summaries
summarize_fit_correlation_matrix()
Summarize a posterior D x D correlation matrix from stored fit draws
plot_probit_diagnostics()
Generate diagnostic plots for a fitted Bayesian multivariate probit model
plot_omega_correlation_heatmap()
Posterior-median latent cross-class correlation heatmap (Omega)
plot_omega_convergence_heatmap()
Sampling-diagnostic (Rhat) heatmap for Omega
plot_omega_summary_table()
Full per-pair Omega summary table (rho, 95% CrI, Rhat, ESS bulk/tail)
plot_omega_degeneracy_diagnostic()
Near-degeneracy diagnostic for the posterior Omega correlation matrix
plot_probit_fixed_effect_diagnostics()
Fixed-effect coefficient diagnostics, split by contrast type and faceted by antimicrobial class
plot_probit_beta_family_diagnostics()
Fixed-effect convergence broken out by source of variation
plot_probit_worst_parameters()
Human-readable worst-converging structural parameters
plot_probit_worst_offender_diagnostics()
Trace and rank plots for the worst-converging structural parameters

Pathway 2: Model Validation

Observed-versus-model calibration checks for a fitted Bayesian multivariate probit model – a different question from profile estimation above (“does the fitted model reproduce the resistance patterns actually observed?” rather than “what is the observed-plus- imputed resistance profile?”). Kept as a distinct status () from sampler diagnostics. Gibbs profile-completion stability is a separate numerical status () assessed with .

validate_marginal_calibration()
Observed-versus-Model Marginal Resistance Validation
validate_pairwise_calibration()
Observed-versus-Model Pairwise Co-resistance Validation
validate_complete_profile_calibration()
Observed-versus-Model Complete-Profile Validation
compute_profile_validation_status()
Summarise Validation Checks into a Profile-Validation Status
mask_and_validate_ast()
Masked-AST Holdout Validation

Pathway 2: Predictive Checking

Posterior, prior, and mixed predictive checking (Stan User’s Guide, “Posterior and Prior Predictive Checks”: ), a third and distinct question from both profile estimation and model validation above: “can the fitted model generate WHOLE REPLICATED DATASETS that resemble the one actually observed?” (posterior predictive, ) and “what data are implied by the priors before conditioning on any observed outcomes?” (prior predictive, ). Kept as distinct status fields from and – never merged into one generic status anywhere in this package. Mixed predictive checking (new random-effect levels, retaining fitted hyperparameters) is available only when fitted random-effect blocks exist; fixed-only models use posterior predictive checking instead.

simulate_probit_posterior_predictive()
Simulate posterior predictive replicate datasets from a fitted probit model
compute_probit_ppc_statistics()
Compute AMR-specific posterior predictive discrepancy statistics
plot_probit_posterior_predictive_checks()
Plot posterior predictive checks for a fitted probit model
compute_posterior_predictive_status()
Classify overall posterior predictive fit from a discrepancy-statistics table
simulate_probit_prior_predictive()
Simulate prior predictive replicate datasets for a probit model
compute_prior_predictive_status()
Classify plausibility of the prior predictive distribution
compute_prior_predictive_fingerprint()
Fingerprint the prior-generative configuration of a fitted model
simulate_probit_mixed_predictive()
Simulate mixed predictive replicate datasets: new random-effect levels for a requested block, retaining fitted hyperparameters

Burden estimation (YLL/YLD/DALY)

GBD-methodology burden calculations

daly_add_rr_mappings()
Add RR Pathogen and Drug Class Mappings
daly_assign_rr_to_profiles()
Assign Per-Class LOS RR to Resistance Profiles (Max Rule)
daly_calc_case_fatality()
Calculate case fatality ratio by syndrome and pathogen (CFR_{Lk})
daly_calc_cr_l()
Calculate the CFR adjustment factor (CR_L)
daly_calc_deaths_by_cause()
Calculate Deaths by Underlying Cause (D_J)
daly_calc_deaths_by_syndrome()
Calculate Deaths by Infectious Syndrome (D_L)
daly_calc_fraction_associated_yld()
Compute Associated-Burden Fractions per Resistance Profile
daly_calc_incidence_from_cfr()
Calculate syndrome incidence from deaths, CFR, and CR_L (formula-based)
daly_calc_infection_fraction()
Calculate Infection Fraction of Deaths by Cause (S_J)
daly_calc_paf_los()
Compute PAF for length of stay per resistance profile
daly_calc_paf_mortality()
Compute Mortality Population Attributable Fraction per Resistance Profile
daly_calc_pathogen_fraction_fatal()
Calculate fatal pathogen distribution (P_{Lk})
daly_calc_resistance_prevalence_fatal()
Calculate Fatal Resistance Prevalence (R_k)
daly_calc_syndrome_fraction()
Calculate Infectious Syndrome Fraction (M_LJ)
daly_calc_yld_attributable()
Compute YLDs Attributable to Resistance
daly_calc_yll_associated()
Compute YLL Associated with AMR (Patient-Level, Facility-Direct)
daly_calc_yll_attributable()
Compute YLL Attributable to AMR
daly_compute_patient_los()
Compute Patient-Level Post-Infection LOS
daly_count_incident_cases()
Count incident cases by syndrome from facility data
daly_derive_hai_cai_for_los()
Derive Infection Type (HAI / CAI) per Patient
daly_derive_hai_cai_for_mortality()
Classify HAI/CAI Infection Type for the Mortality Cohort
daly_filter_profiles_to_rr_classes()
Filter Resistance Profiles to Classes with RR Estimates
daly_fit_los_rr()
Fit relative LOS using Gamma GLM with log link
daly_fit_los_rr_distribution()
Estimate Per-Class LOS Relative Risk via Parametric Distribution Fitting
daly_fit_mortality_rr()
Fit mortality model and derive adjusted relative risk of death
daly_get_top_pathogens()
Identify top N pathogens by occurrence
daly_load_rr_reference()
Load RR (Relative Risk) Reference Data
compute_hospital_daly()
Compute Hospital-Level DALY Breakdown

LOS modeling

Length-of-stay distribution fitting and comparison

safe_fit()
Safely Fit a Distribution
fit_distributions()
Fit Multiple Distributions
compare_distribution_aic()
Compare Distribution Fits by AIC
summarise_distribution()
Summarise a Fitted Distribution
plot_los_distributions()
Plot LOS Distribution with Fitted Overlays
prepare_los_data()
Prepare LOS Dataset
get_los_by_resistance()
Extract LOS Vectors by Resistance Status

Burden plots

Hospital-level and organism-level burden visualizations

plot_burden_by_hospital()
Plot YLL or YLD Associated vs Attributable per Hospital
plot_burden_by_organism()
Plot YLL or YLD Associated vs Attributable by Organism
plot_yll_heatmap()
Heatmap of YLL per 1 000 Admissions by Resistance Class and Pathogen Group
plot_yld_heatmap()
Heatmap of YLD per 1 000 Admissions by Organism Group

EDA plots

Exploratory plots for AMR surveillance data

plot_top_organisms()
Plot Top Pathogens by Unique Patients
plot_abx_susceptibility()
Plot Antibiotic Susceptibility Pattern (Stacked R/S Bars)
plot_abx_heatmap()
Plot Antibiotic Resistance Heatmap
plot_outcome_distribution()
Plot Distribution of Final Outcomes
plot_outcome_by_organism()
Plot Final Outcome Proportions for Resistant or Susceptible Patients
plot_death_discharged()
Plot Death vs Discharged Counts for Top Pathogens
plot_resistance_by_sample()
Plot Distribution of Antibiotic Resistance Across Sample Types
plot_outcome_by_agebin()
Plot Final Outcome Proportions by Age Bin
plot_mono_poly_by_facility()
Plot Mono vs Polymicrobial Infections by Facility
plot_hai_cai_by_facility()
Plot HAI vs CAI Infection Distribution by Facility
plot_location_by_facility()
Plot Patient Distribution by Location Type Across Facilities
plot_infection_type_by_location()
Plot Infection Type (HAI/CAI) by Location (ICU/Ward), Faceted by Hospital
plot_los_ridge()
Ridge / Density Plot of Length of Stay (LOS)
plot_age_ridge()
Ridge / Density Plot of Patient Age
plot_los_by_agebin()
Boxplot of Length of Stay by Age Group
plot_outcome_by_year()
Plot Distribution of Final Outcomes by Year
plot_patients_by_hospital()
Plot Unique Patient Count by Hospital
plot_syndrome_distribution()
Plot Syndrome Distribution
plot_resistance_by_agebin()
Resistance proportion by age group
plot_resistance_by_organism()
Resistance proportion for top N organisms

Visualization

Generic AMR plotting utilities

eda_theme()
EDA ggplot2 Theme
class_display_label()
Human-readable antimicrobial class label
class_short_label()
Short antimicrobial class label (for dense facet strips)
class_pair_label()
Human-readable class-pair label
hospital_display_label()
Human-readable hospital/site display label

Validation and reporting

Data quality checks and reports

validate_data_quality()
Validate Data Quality
validate_required_fields()
Validate required fields exist and meet completeness threshold
summarize_column_mapping()
Summarize Column Mapping
summarize_data_quality()
Summarize Data Quality
summarize_raw_data()
Summarize Raw Data
summarize_transformations()
Summarize Data Transformations
compute_processing_statistics()
Compute Processing Statistics
generate_preprocessing_report()
Generate Preprocessing Report
export_report()
Export Report to File
prep_check_organism_ast_consistency()
Check Organism-AST Consistency
prep_validate_analysis_ready()
Validate Analysis-Ready Dataset
prep_validate_date_logic()
Validate Date Logic
prep_missingness_report()
Missingness Report

Utilities

Helper functions

round_to_sum()
Largest-Remainder Rounding
shorten_drug_class()
Shorten Antibiotic Class Names
default_column_mappings
Default column name mappings for fuzzy matching
get_age_bins()
Get Age Bin Labels
prep_inventory_columns()
Inventory Columns
prep_log_source()
Log Data Source Provenance