Error in get(paste0(generic, “.”, class), envir = get_method_env()) :
+object ‘type_sum.accel’ not found
+
+library(ggplot2)library(AMR)# (if not yet installed, install with:)
@@ -185,7 +189,7 @@ for cleaning data and creating frequency tables.
The AMR package contains a data set
example_isolates_unclean, which might look data that users
have extracted from their laboratory systems:
-
+
example_isolates_unclean#> # A tibble: 3,000 × 8#> patient_id hospital date bacteria AMX AMC CIP GEN
@@ -218,7 +222,7 @@ included data were retrieved on 24 Jun 2024.
The codes of the AMR packages that come from as.mo() are
short, but still human readable. More importantly, as.mo()
supports all kinds of input:
-
+
as.mo("Klebsiella pneumoniae")#> Class 'mo'#> [1] B_KLBSL_PNMN
@@ -238,7 +242,7 @@ retrieve taxonomic properties, such as the name, genus, species, family,
order, and even Gram-stain. They all start with mo_ and
they use as.mo() internally, so that still any arbitrary
user input can be used:
-
+
mo_family("K. pneumoniae")#> [1] "Enterobacteriaceae"mo_genus("K. pneumoniae")
@@ -257,14 +261,14 @@ user input can be used:
#> [1] "1098101000112102" "446870005" "1098201000112108" "409801009" #> [5] "56415008" "714315002" "713926009"
Now we can thus clean our data:
-
+
our_data$bacteria<-as.mo(our_data$bacteria, info =TRUE)#> ℹ Microorganism translation was uncertain for four microorganisms. Run#> mo_uncertainties() to review these uncertainties, or use#> add_custom_microorganisms() to add custom entries.
Apparently, there was some uncertainty about the translation to
taxonomic codes. Let’s check this:
-
+
mo_uncertainties()#> Matching scores are based on the resemblance between the input and the full#> taxonomic name, and the pathogenicity in humans. See ?mo_matching_score.
@@ -321,10 +325,10 @@ diffusion values, read more about that on the
The outcome of the function can easily be added to our data:
-
+
our_data<-our_data%>%mutate(first =first_isolate(info =TRUE))#> ℹ Determining first isolates using an episode length of 365 days
@@ -403,16 +407,16 @@ the methods on the first_isolate
So we end up with 2 724 isolates for analysis. Now our data looks
like:
-
+
our_data_1st#> # A tibble: 2,724 × 9#> patient_id hospital date bacteria AMX AMC CIP GEN first
@@ -437,7 +441,7 @@ like:
The base R summary() function gives a good first
impression, as it comes with support for the new mo and
sir classes that we now have in our data set:
-
+
summary(our_data_1st)#> patient_id hospital date #> Length:2724 Length:2724 Min. :2011-01-01
@@ -486,7 +490,7 @@ impression, as it comes with support for the new mo and
To just get an idea how the species are distributed, create a
frequency table with count() based on the name of the
microorganisms:
Using so-called antibiotic class selectors, you can select or filter
columns based on the antibiotic class that your antibiotic results are
in:
-
+
our_data_1st%>%select(date, aminoglycosides())#> ℹ For aminoglycosides() using column 'GEN' (gentamicin)
@@ -658,7 +662,7 @@ failure
function to create any of the above antibiogram types. For starters,
this is what the included example_isolates data set looks
like:
-
+
example_isolates#> # A tibble: 2,000 × 46#> date patient age gender ward mo PEN OXA FLC AMX
@@ -687,7 +691,7 @@ like:
should be used. The antibiotics argument in the
antibiogram() function supports any (combination) of the
previously mentioned antibiotic class selectors:
-
+
antibiogram(example_isolates, antibiotics =c(aminoglycosides(), carbapenems()))#> ℹ The function aminoglycosides() should be used inside a dplyr verb or
@@ -831,7 +835,7 @@ Chinese, Czech, Danish, Dutch, Finnish, French, German, Greek, Italian,
Japanese, Norwegian, Polish, Portuguese, Romanian, Russian, Spanish,
Swedish, Turkish, or Ukrainian. In this next example, we force the
language to be Spanish using the language argument:
-
+
antibiogram(example_isolates, mo_transform ="gramstain", antibiotics =aminoglycosides(),
@@ -885,7 +889,7 @@ language to be Spanish using the language argument:
To create a combined antibiogram, use antibiotic codes or names with
a plus + character like this:
To create a syndromic antibiogram, the syndromic_group
argument must be used. This can be any column in the data, or e.g. an
ifelse() with calculations based on certain columns:
-
+
antibiogram(example_isolates, antibiotics =c(aminoglycosides(), carbapenems()), syndromic_group ="ward")
@@ -1165,7 +1169,7 @@ Antibiogram) in which cases are predefined based on clinical or
demographic characteristics (e.g., endocarditis in 75+ females). This
next example is a simplification without clinical characteristics, but
just gives an idea of how a WISCA can be created:
-
+
wisca<-antibiogram(example_isolates, antibiotics =c("AMC", "AMC+CIP", "TZP", "TZP+TOB"), mo_transform ="gramstain",
@@ -1233,7 +1237,7 @@ just gives an idea of how a WISCA can be created:
Antibiograms can be plotted using autoplot() from the
ggplot2 packages, since this AMR package
provides an extension to that function:
To calculate antimicrobial resistance in a more sensible way, also by
@@ -1262,12 +1266,12 @@ proportion of R (proportion_R()
I (proportion_SI(), equal to
susceptibility()). These functions can be used on their
own:
Antimicrobial resistance (AMR) is a global health crisis, and
+understanding resistance patterns is crucial for managing effective
+treatments. The AMR R package provides robust tools for
+analysing AMR data, including convenient antibiotic selector functions
+like aminoglycosides() and betalactams(). In
+this post, we will explore how to use the tidymodels
+framework to predict resistance patterns in the
+example_isolates dataset.
+
By leveraging the power of tidymodels and the
+AMR package, we’ll build a reproducible machine learning
+workflow to predict resistance to two important antibiotic classes:
+aminoglycosides and beta-lactams.
+
+
+
+Objective
+
+
Our goal is to build a predictive model using the
+tidymodels framework to determine resistance patterns based
+on microbial data. We will:
Define a logistic regression model for prediction.
+
Use a structured tidymodels workflow to preprocess,
+train, and evaluate the model.
+
+
+
+
+
+Data Preparation
+
+
We begin by loading the required libraries and preparing the
+example_isolates dataset from the AMR
+package.
+
+# Load required libraries
+library(tidymodels)# For machine learning workflows, and data manipulation (dplyr, tidyr, ...)
+#> Error in get(paste0(generic, ".", class), envir = get_method_env()) :
+#> object 'type_sum.accel' not found
+#> ── Attaching packages ────────────────────────────────────── tidymodels 1.2.0 ──
+#> ✔broom 1.0.7 ✔recipes 1.1.0
+#> ✔dials 1.3.0 ✔rsample 1.2.1
+#> ✔dplyr 1.1.4 ✔tibble 3.2.1
+#> ✔ggplot2 3.5.1 ✔tidyr 1.3.1
+#> ✔infer 1.0.7 ✔tune 1.2.1
+#> ✔modeldata 1.4.0 ✔workflows 1.1.4
+#> ✔parsnip 1.2.1 ✔workflowsets 1.1.0
+#> ✔purrr 1.0.2 ✔yardstick 1.3.1
+#> ── Conflicts ───────────────────────────────────────── tidymodels_conflicts() ──
+#> ✖purrr::discard() masks scales::discard()
+#> ✖dplyr::filter() masks stats::filter()
+#> ✖dplyr::lag() masks stats::lag()
+#> ✖recipes::step() masks stats::step()
+#> • Use tidymodels_prefer() to resolve common conflicts.
+library(AMR)# For AMR data analysis
+
+# Load the example_isolates dataset
+data("example_isolates")# Preloaded dataset with AMR results
+
+# Select relevant columns for prediction
+data<-example_isolates%>%
+# select AB results dynamically
+select(mo, aminoglycosides(), betalactams())%>%
+# replace NAs with NI (not-interpretable)
+mutate(across(where(is.sir),
+~replace_na(.x, "NI")),
+# make factors of SIR columns
+across(where(is.sir),
+as.integer),
+# get Gramstain of microorganisms
+ mo =as.factor(mo_gramstain(mo)))%>%
+# drop NAs - the ones without a Gramstain (fungi, etc.)
+drop_na()# %>%
+#> ℹ For aminoglycosides() using columns 'GEN' (gentamicin), 'TOB'
+#> (tobramycin), 'AMK' (amikacin), and 'KAN' (kanamycin)
+#> ℹ For betalactams() using columns 'PEN' (benzylpenicillin), 'OXA'
+#> (oxacillin), 'FLC' (flucloxacillin), 'AMX' (amoxicillin), 'AMC'
+#> (amoxicillin/clavulanic acid), 'AMP' (ampicillin), 'TZP'
+#> (piperacillin/tazobactam), 'CZO' (cefazolin), 'FEP' (cefepime), 'CXM'
+#> (cefuroxime), 'FOX' (cefoxitin), 'CTX' (cefotaxime), 'CAZ' (ceftazidime),
+#> 'CRO' (ceftriaxone), 'IPM' (imipenem), and 'MEM' (meropenem)
+# Cefepime is not reliable
+#select(-FEP)
+
Explanation: - aminoglycosides() and
+betalactams() dynamically select columns for antibiotics in
+these classes. - drop_na() ensures the model receives
+complete cases for training.
+
+
+
+
+Defining the Workflow
+
+
We now define the tidymodels workflow, which consists of
+three steps: preprocessing, model specification, and fitting.
+
+
1. Preprocessing with a Recipe
+
+
We create a recipe to preprocess the data for modelling. This
+includes: - Encoding resistance results (S, I,
+R) as binary (resistant or not resistant). - Converting
+microbial organism names (mo) into numerical features using
+one-hot encoding.
+
+# Define the recipe for data preprocessing
+resistance_recipe<-recipe(mo~., data =data)%>%
+step_corr(c(aminoglycosides(), betalactams()), threshold =0.9)
+resistance_recipe
+#>
+#> ──Recipe──────────────────────────────────────────────────────────────────────
+#>
+#> ── Inputs
+#> Number of variables by role
+#> outcome: 1
+#> predictor: 20
+#>
+#> ── Operations
+#> • Correlation filter on: c(aminoglycosides(), betalactams())
+
Explanation: - step_mutate() transforms
+resistance results (R) into binary variables (TRUE/FALSE).
+- step_dummy() converts categorical organism
+(mo) names into one-hot encoded numerical features, making
+them compatible with the model.
+
+
+
2. Specifying the Model
+
+
We define a logistic regression model since resistance prediction is
+a binary classification task.
+
+# Specify a logistic regression model
+logistic_model<-logistic_reg()%>%
+set_engine("glm")# Use the Generalized Linear Model engine
+logistic_model
+#> Logistic Regression Model Specification (classification)
+#>
+#> Computational engine: glm
+
Explanation: - logistic_reg() sets up a
+logistic regression model. - set_engine("glm") specifies
+the use of R’s built-in GLM engine.
+
+
+
3. Building the Workflow
+
+
We bundle the recipe and model together into a workflow,
+which organizes the entire modeling process.
+
+# Combine the recipe and model into a workflow
+resistance_workflow<-workflow()%>%
+add_recipe(resistance_recipe)%>%# Add the preprocessing recipe
+add_model(logistic_model)# Add the logistic regression model
+resistance_workflow
+#> ══ Workflow ════════════════════════════════════════════════════════════════════
+#> Preprocessor: Recipe
+#> Model: logistic_reg()
+#>
+#> ── Preprocessor ────────────────────────────────────────────────────────────────
+#> 1 Recipe Step
+#>
+#> • step_corr()
+#>
+#> ── Model ───────────────────────────────────────────────────────────────────────
+#> Logistic Regression Model Specification (classification)
+#>
+#> Computational engine: glm
+
+
+
+
+
+Training and Evaluating the Model
+
+
To train the model, we split the data into training and testing sets.
+Then, we fit the workflow on the training set and evaluate its
+performance.
+
+# Split data into training and testing sets
+set.seed(123)# For reproducibility
+data_split<-initial_split(data, prop =0.8)# 80% training, 20% testing
+training_data<-training(data_split)# Training set
+testing_data<-testing(data_split)# Testing set
+
+# Fit the workflow to the training data
+fitted_workflow<-resistance_workflow%>%
+fit(training_data)# Train the model
+#> ℹ For aminoglycosides() using columns 'GEN' (gentamicin), 'TOB'
+#> (tobramycin), 'AMK' (amikacin), and 'KAN' (kanamycin)
+#> ℹ For betalactams() using columns 'PEN' (benzylpenicillin), 'OXA'
+#> (oxacillin), 'FLC' (flucloxacillin), 'AMX' (amoxicillin), 'AMC'
+#> (amoxicillin/clavulanic acid), 'AMP' (ampicillin), 'TZP'
+#> (piperacillin/tazobactam), 'CZO' (cefazolin), 'FEP' (cefepime), 'CXM'
+#> (cefuroxime), 'FOX' (cefoxitin), 'CTX' (cefotaxime), 'CAZ' (ceftazidime),
+#> 'CRO' (ceftriaxone), 'IPM' (imipenem), and 'MEM' (meropenem)
+
+fitted_workflow
+#> ══ Workflow [trained] ══════════════════════════════════════════════════════════
+#> Preprocessor: Recipe
+#> Model: logistic_reg()
+#>
+#> ── Preprocessor ────────────────────────────────────────────────────────────────
+#> 1 Recipe Step
+#>
+#> • step_corr()
+#>
+#> ── Model ───────────────────────────────────────────────────────────────────────
+#>
+#> Call: stats::glm(formula = ..y ~ ., family = stats::binomial, data = data)
+#>
+#> Coefficients:
+#> (Intercept) GEN TOB AMK KAN PEN
+#> 101.11641 -3.69738 4.55879 1.86703 -23.37497 -0.57182
+#> OXA FLC AMC AMP TZP CZO
+#> -4.68575 -11.69742 0.79748 -1.56197 0.87667 -2.28424
+#> FEP CXM FOX CAZ CRO IPM
+#> -0.19847 0.02659 10.32455 10.27248 0.97321 -0.93096
+#> MEM
+#> -0.88753
+#>
+#> Degrees of Freedom: 1573 Total (i.e. Null); 1555 Residual
+#> Null Deviance: 2071
+#> Residual Deviance: 74.91 AIC: 112.9
+
Explanation: - initial_split() splits
+the data into training and testing sets. - fit() trains the
+workflow on the training set.
In this post, we demonstrated how to build a machine learning
+pipeline with the tidymodels framework and the
+AMR package. By combining selector functions like
+aminoglycosides() and betalactams() with
+tidymodels, we efficiently prepared data, trained a model,
+and evaluated its performance.
+
This workflow is extensible to other antibiotic classes and
+resistance patterns, empowering users to analyse AMR data systematically
+and reproducibly.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/articles/AMR_with_tidymodels_files/figure-html/unnamed-chunk-7-1.png b/articles/AMR_with_tidymodels_files/figure-html/unnamed-chunk-7-1.png
new file mode 100644
index 00000000..b341894f
Binary files /dev/null and b/articles/AMR_with_tidymodels_files/figure-html/unnamed-chunk-7-1.png differ
diff --git a/articles/EUCAST.html b/articles/EUCAST.html
index 13372d26..72afb48e 100644
--- a/articles/EUCAST.html
+++ b/articles/EUCAST.html
@@ -29,7 +29,7 @@
AMR (for R)
- 2.1.1.9120
+ 2.1.1.9121
@@ -45,6 +45,7 @@
@@ -107,6 +108,8 @@ the tidyverse for all of my analyses. All of them. If you don’t know it
yet, I suggest you read about it on their website: https://www.tidyverse.org/.
library(dplyr)# part of tidyverse
+#> Error in get(paste0(generic, ".", class), envir = get_method_env()) :
+#> object 'type_sum.accel' not foundlibrary(ggplot2)# part of tidyverselibrary(AMR)# this packagelibrary(cleaner)# to create frequency tables
(this beta version will eventually become v3.0. We’re happy to reach a new major milestone soon, which will be all about the new One Health support! Install this beta using the instructions here.)
-
A New Milestone: AMR v3.0 with One Health Support (= Human + Veterinary + Environmental)
+
A New Milestone: AMR v3.0 with One Health Support (= Human + Veterinary + Environmental)
This package now supports not only tools for AMR data analysis in clinical settings, but also for veterinary and environmental microbiology. This was made possible through a collaboration with the University of Prince Edward Island’s Atlantic Veterinary College, Canada. To celebrate this great improvement of the package, we also updated the package logo to reflect this change.
-
Breaking
+
Breaking
Removed all functions and references that used the deprecated rsi class, which were all replaced with their sir equivalents over a year ago
-
New
+
New
One Health implementation
Function as.sir() now has extensive support for veterinary breakpoints from CLSI. Use breakpoint_type = "animal" and set the host argument to a variable that contains animal species names.
@@ -94,12 +95,16 @@
While using R for the heavy lifting, our ‘AMR’ Python Package was developed to run the AMR R package natively in Python. The Python package will always have the same version number as the R package, as it is built automatically with every code change.
+Support for tidymodels
+
All antimicrobial selectors (such as aminoglycosides() and betalactams()) are now supported in tidymodels packages such as recipe and parsnip. See for more info our tutorial on using AMR function for predictive modelling.
+
+
Other
New function mo_group_members() to retrieve the member microorganisms of a microorganism group. For example, mo_group_members("Strep group C") returns a vector of all microorganisms that belong to that group.
-
Changed
+
Changed
SIR interpretation
It is now possible to use column names for argument ab, mo, and uti: as.sir(..., ab = "column1", mo = "column2", uti = "column3"). This greatly improves the flexibility for users.
Users can now set their own criteria (using regular expressions) as to what should be considered S, I, R, SDD, and NI.
@@ -153,17 +158,20 @@
Improved algorithm of first_isolate() when using the phenotype-based method, to prioritise records with the highest availability of SIR values
Implemented the new Dutch national MDRO guideline (SRI-richtlijn BRMO, Nov 2024)
+
Added arguments esbl, carbapenemase, mecA, mecC, vanA, vanB to denote column names or logical values indicating presence of these genes (or production of their proteins)
+
-
Other
+
Other
Greatly improved vctrs integration, a Tidyverse package working in the background for many Tidyverse functions. For users, this means that functions such as dplyr’s bind_rows(), rowwise() and c_across() are now supported for e.g. columns of class mic. Despite this, this AMR package is still zero-dependent on any other package, including dplyr and vctrs.
Greatly updated and expanded documentation
Added Larisse Bolton, Jordan Stull, Matthew Saab, and Javier Sanchez as contributors, to thank them for their valuable input
Stopped support for SAS (.xpt) files, since their file structure and extremely inefficient and requires more disk space than GitHub allows in a single commit.
-
Older Versions
+
Older Versions
This changelog only contains changes from AMR v3.0 (October 2024) and later.
diff --git a/reference/AMR.html b/reference/AMR.html
index 519f9f06..cd4d1955 100644
--- a/reference/AMR.html
+++ b/reference/AMR.html
@@ -21,7 +21,7 @@ The AMR package is available in English, Chinese, Czech, Danish, Dutch, Finnish,
AMR (for R)
- 2.1.1.9120
+ 2.1.1.9121
@@ -35,6 +35,7 @@ The AMR package is available in English, Chinese, Czech, Danish, Dutch, Finnish,
column name of the names or codes of the microorganisms (see as.mo()) - the default is the first column of class mo. Values will be coerced using as.mo().
+
esbl
+
logical values, or a column name containing logical values, indicating the presence of an ESBL gene (or production of its proteins)
+
+
+
carbapenemase
+
logical values, or a column name containing logical values, indicating the presence of a carbapenemase gene (or production of its proteins)
+
+
+
mecA
+
logical values, or a column name containing logical values, indicating the presence of a mecA gene (or production of its proteins)
+
+
+
mecC
+
logical values, or a column name containing logical values, indicating the presence of a mecC gene (or production of its proteins)
+
+
+
vanA
+
logical values, or a column name containing logical values, indicating the presence of a vanA gene (or production of its proteins)
+
+
+
vanB
+
logical values, or a column name containing logical values, indicating the presence of a vanB gene (or production of its proteins)
+
+
info
a logical to indicate whether progress should be printed to the console - the default is only print while in interactive sessions
diff --git a/reference/microorganisms.html b/reference/microorganisms.html
index c6614a14..54a4c579 100644
--- a/reference/microorganisms.html
+++ b/reference/microorganisms.html
@@ -9,7 +9,7 @@ This data set is carefully crafted, yet made 100% reproducible from public and a
AMR (for R)
- 2.1.1.9120
+ 2.1.1.9121
@@ -23,6 +23,7 @@ This data set is carefully crafted, yet made 100% reproducible from public and a
diff --git a/reference/mo_source.html b/reference/mo_source.html
index 631115c4..5dad8ead 100644
--- a/reference/mo_source.html
+++ b/reference/mo_source.html
@@ -9,7 +9,7 @@ This is the fastest way to have your organisation (or analysis) specific codes p
AMR (for R)
- 2.1.1.9120
+ 2.1.1.9121
@@ -23,6 +23,7 @@ This is the fastest way to have your organisation (or analysis) specific codes p
diff --git a/reference/plot.html b/reference/plot.html
index b88ccf79..7976902f 100644
--- a/reference/plot.html
+++ b/reference/plot.html
@@ -9,7 +9,7 @@ Especially the scale_*_mic() functions are relevant wrappers to plot MIC values
AMR (for R)
- 2.1.1.9120
+ 2.1.1.9121
@@ -23,6 +23,7 @@ Especially the scale_*_mic() functions are relevant wrappers to plot MIC values
diff --git a/reference/proportion.html b/reference/proportion.html
index 0996317a..3e042dbf 100644
--- a/reference/proportion.html
+++ b/reference/proportion.html
@@ -9,7 +9,7 @@ resistance() should be used to calculate resistance, susceptibility() should be
AMR (for R)
- 2.1.1.9120
+ 2.1.1.9121
@@ -23,6 +23,7 @@ resistance() should be used to calculate resistance, susceptibility() should be
diff --git a/reference/skewness.html b/reference/skewness.html
index 563019fb..82ce1db7 100644
--- a/reference/skewness.html
+++ b/reference/skewness.html
@@ -9,7 +9,7 @@ When negative ('left-skewed'): the left tail is longer; the mass of the distribu
AMR (for R)
- 2.1.1.9120
+ 2.1.1.9121
@@ -23,6 +23,7 @@ When negative ('left-skewed'): the left tail is longer; the mass of the distribu
diff --git a/search.json b/search.json
index 6fb8ab72..eb643b98 100644
--- a/search.json
+++ b/search.json
@@ -1 +1 @@
-[{"path":"https://msberends.github.io/AMR/articles/AMR.html","id":"introduction","dir":"Articles","previous_headings":"","what":"Introduction","title":"How to conduct AMR data analysis","text":"Conducting AMR data analysis unfortunately requires -depth knowledge different scientific fields, makes hard right. least, requires: Good questions (always start !) reliable data thorough understanding (clinical) epidemiology, understand clinical epidemiological relevance possible bias results thorough understanding (clinical) microbiology/infectious diseases, understand microorganisms causal infections implications pharmaceutical treatment, well understanding intrinsic acquired microbial resistance Experience data analysis microbiological tests results, understand determination limitations MIC values interpretations SIR values Availability biological taxonomy microorganisms probably normalisation factors pharmaceuticals, defined daily doses (DDD) Available (inter-)national guidelines, profound methods apply course, instantly provide knowledge experience. AMR package, aimed providing (1) tools simplify antimicrobial resistance data cleaning, transformation analysis, (2) methods easily incorporate international guidelines (3) scientifically reliable reference data, including requirements mentioned . AMR package enables standardised reproducible AMR data analysis, application evidence-based rules, determination first isolates, translation various codes microorganisms antimicrobial agents, determination (multi-drug) resistant microorganisms, calculation antimicrobial resistance, prevalence future trends.","code":""},{"path":"https://msberends.github.io/AMR/articles/AMR.html","id":"preparation","dir":"Articles","previous_headings":"","what":"Preparation","title":"How to conduct AMR data analysis","text":"tutorial, create fake demonstration data work . can skip Cleaning data already data ready. start analysis, try make structure data generally look like :","code":""},{"path":"https://msberends.github.io/AMR/articles/AMR.html","id":"needed-r-packages","dir":"Articles","previous_headings":"Preparation","what":"Needed R packages","title":"How to conduct AMR data analysis","text":"many uses R, need additional packages AMR data analysis. package works closely together tidyverse packages dplyr ggplot2 RStudio. tidyverse tremendously improves way conduct data science - allows natural way writing syntaxes creating beautiful plots R. also use cleaner package, can used cleaning data creating frequency tables. AMR package contains data set example_isolates_unclean, might look data users extracted laboratory systems: AMR data analysis, like microorganism column contain valid, --date taxonomy, antibiotic columns cleaned SIR values well.","code":"library(dplyr) library(ggplot2) library(AMR) # (if not yet installed, install with:) # install.packages(c(\"dplyr\", \"ggplot2\", \"AMR\")) example_isolates_unclean #> # A tibble: 3,000 × 8 #> patient_id hospital date bacteria AMX AMC CIP GEN #> #> 1 J3 A 2012-11-21 E. coli R I S S #> 2 R7 A 2018-04-03 K. pneumoniae R I S S #> 3 P3 A 2014-09-19 E. coli R S S S #> 4 P10 A 2015-12-10 E. coli S I S S #> 5 B7 A 2015-03-02 E. coli S S S S #> 6 W3 A 2018-03-31 S. aureus R S R S #> 7 J8 A 2016-06-14 E. coli R S S S #> 8 M3 A 2015-10-25 E. coli R S S S #> 9 J3 A 2019-06-19 E. coli S S S S #> 10 G6 A 2015-04-27 S. aureus S S S S #> # ℹ 2,990 more rows # we will use 'our_data' as the data set name for this tutorial our_data <- example_isolates_unclean"},{"path":"https://msberends.github.io/AMR/articles/AMR.html","id":"taxonomy-of-microorganisms","dir":"Articles","previous_headings":"Preparation","what":"Taxonomy of microorganisms","title":"How to conduct AMR data analysis","text":".mo(), users can transform arbitrary microorganism names codes current taxonomy. AMR package contains --date taxonomic data. specific, currently included data retrieved 24 Jun 2024. codes AMR packages come .mo() short, still human readable. importantly, .mo() supports kinds input: first character codes denote taxonomic kingdom, Bacteria (B), Fungi (F), Protozoa (P). AMR package also contain functions directly retrieve taxonomic properties, name, genus, species, family, order, even Gram-stain. start mo_ use .mo() internally, still arbitrary user input can used: Now can thus clean data: Apparently, uncertainty translation taxonomic codes. Let’s check : ’s good.","code":"as.mo(\"Klebsiella pneumoniae\") #> Class 'mo' #> [1] B_KLBSL_PNMN as.mo(\"K. pneumoniae\") #> Class 'mo' #> [1] B_KLBSL_PNMN as.mo(\"KLEPNE\") #> Class 'mo' #> [1] B_KLBSL_PNMN as.mo(\"KLPN\") #> Class 'mo' #> [1] B_KLBSL_PNMN mo_family(\"K. pneumoniae\") #> [1] \"Enterobacteriaceae\" mo_genus(\"K. pneumoniae\") #> [1] \"Klebsiella\" mo_species(\"K. pneumoniae\") #> [1] \"pneumoniae\" mo_gramstain(\"Klebsiella pneumoniae\") #> [1] \"Gram-negative\" mo_ref(\"K. pneumoniae\") #> [1] \"Trevisan, 1887\" mo_snomed(\"K. pneumoniae\") #> [[1]] #> [1] \"1098101000112102\" \"446870005\" \"1098201000112108\" \"409801009\" #> [5] \"56415008\" \"714315002\" \"713926009\" our_data$bacteria <- as.mo(our_data$bacteria, info = TRUE) #> ℹ Microorganism translation was uncertain for four microorganisms. Run #> mo_uncertainties() to review these uncertainties, or use #> add_custom_microorganisms() to add custom entries. mo_uncertainties() #> Matching scores are based on the resemblance between the input and the full #> taxonomic name, and the pathogenicity in humans. See ?mo_matching_score. #> #> -------------------------------------------------------------------------------- #> \"E. coli\" -> Escherichia coli (B_ESCHR_COLI, 0.688) #> Also matched: Enterococcus crotali (0.650), Escherichia coli coli #> (0.643), Escherichia coli expressing (0.611), Enterobacter cowanii #> (0.600), Enterococcus columbae (0.595), Enterococcus camelliae (0.591), #> Enterococcus casseliflavus (0.577), Enterobacter cloacae cloacae #> (0.571), Enterobacter cloacae complex (0.571), and Enterobacter cloacae #> dissolvens (0.565) #> -------------------------------------------------------------------------------- #> \"K. pneumoniae\" -> Klebsiella pneumoniae (B_KLBSL_PNMN, 0.786) #> Also matched: Klebsiella pneumoniae ozaenae (0.707), Klebsiella #> pneumoniae pneumoniae (0.688), Klebsiella pneumoniae rhinoscleromatis #> (0.658), Klebsiella pasteurii (0.500), Klebsiella planticola (0.500), #> Kingella potus (0.400), Kluyveromyces pseudotropicale (0.386), #> Kluyveromyces pseudotropicalis (0.363), Kosakonia pseudosacchari #> (0.361), and Kluyveromyces pseudotropicalis pseudotropicalis (0.361) #> -------------------------------------------------------------------------------- #> \"S. aureus\" -> Staphylococcus aureus (B_STPHY_AURS, 0.690) #> Also matched: Staphylococcus aureus aureus (0.643), Staphylococcus #> argenteus (0.625), Staphylococcus aureus anaerobius (0.625), #> Staphylococcus auricularis (0.615), Salmonella Aurelianis (0.595), #> Salmonella Aarhus (0.588), Salmonella Amounderness (0.587), #> Staphylococcus argensis (0.587), Streptococcus australis (0.587), and #> Salmonella choleraesuis arizonae (0.562) #> -------------------------------------------------------------------------------- #> \"S. pneumoniae\" -> Streptococcus pneumoniae (B_STRPT_PNMN, 0.750) #> Also matched: Streptococcus pseudopneumoniae (0.700), Streptococcus #> phocae salmonis (0.552), Serratia proteamaculans quinovora (0.545), #> Streptococcus pseudoporcinus (0.536), Staphylococcus piscifermentans #> (0.533), Staphylococcus pseudintermedius (0.532), Serratia #> proteamaculans proteamaculans (0.526), Streptococcus gallolyticus #> pasteurianus (0.526), Salmonella Portanigra (0.524), and Streptococcus #> periodonticum (0.519) #> #> Only the first 10 other matches of each record are shown. Run #> print(mo_uncertainties(), n = ...) to view more entries, or save #> mo_uncertainties() to an object."},{"path":"https://msberends.github.io/AMR/articles/AMR.html","id":"antibiotic-results","dir":"Articles","previous_headings":"Preparation","what":"Antibiotic results","title":"How to conduct AMR data analysis","text":"column antibiotic test results must also cleaned. AMR package comes three new data types work test results: mic minimal inhibitory concentrations (MIC), disk disk diffusion diameters, sir SIR data interpreted already. package can also determine SIR values based MIC disk diffusion values, read .sir() page. now, just clean SIR columns data using dplyr: basically cleaning, time start data inclusion.","code":"# method 1, be explicit about the columns: our_data <- our_data %>% mutate_at(vars(AMX:GEN), as.sir) # method 2, let the AMR package determine the eligible columns our_data <- our_data %>% mutate_if(is_sir_eligible, as.sir) # result: our_data #> # A tibble: 3,000 × 8 #> patient_id hospital date bacteria AMX AMC CIP GEN #> #> 1 J3 A 2012-11-21 B_ESCHR_COLI R I S S #> 2 R7 A 2018-04-03 B_KLBSL_PNMN R I S S #> 3 P3 A 2014-09-19 B_ESCHR_COLI R S S S #> 4 P10 A 2015-12-10 B_ESCHR_COLI S I S S #> 5 B7 A 2015-03-02 B_ESCHR_COLI S S S S #> 6 W3 A 2018-03-31 B_STPHY_AURS R S R S #> 7 J8 A 2016-06-14 B_ESCHR_COLI R S S S #> 8 M3 A 2015-10-25 B_ESCHR_COLI R S S S #> 9 J3 A 2019-06-19 B_ESCHR_COLI S S S S #> 10 G6 A 2015-04-27 B_STPHY_AURS S S S S #> # ℹ 2,990 more rows"},{"path":"https://msberends.github.io/AMR/articles/AMR.html","id":"first-isolates","dir":"Articles","previous_headings":"Preparation","what":"First isolates","title":"How to conduct AMR data analysis","text":"need know isolates can actually use analysis without repetition bias. conduct analysis antimicrobial resistance, must include first isolate every patient per episode (Hindler et al., Clin Infect Dis. 2007). , easily get overestimate underestimate resistance antibiotic. Imagine patient admitted MRSA found 5 different blood cultures following weeks (yes, countries like Netherlands blood drawing policies). resistance percentage oxacillin isolates overestimated, included MRSA . clearly selection bias. Clinical Laboratory Standards Institute (CLSI) appoints follows: (…) preparing cumulative antibiogram guide clinical decisions empirical antimicrobial therapy initial infections, first isolate given species per patient, per analysis period (eg, one year) included, irrespective body site, antimicrobial susceptibility profile, phenotypical characteristics (eg, biotype). first isolate easily identified, cumulative antimicrobial susceptibility test data prepared using first isolate generally comparable cumulative antimicrobial susceptibility test data calculated methods, providing duplicate isolates excluded. M39-A4 Analysis Presentation Cumulative Antimicrobial Susceptibility Test Data, 4th Edition. CLSI, 2014. Chapter 6.4 AMR package includes methodology first_isolate() function able apply four different methods defined Hindler et al. 2007: phenotype-based, episode-based, patient-based, isolate-based. right method depends goals analysis, default phenotype-based method case method properly correct duplicate isolates. Read methods first_isolate() page. outcome function can easily added data: 91% suitable resistance analysis! can now filter filter() function, also dplyr package: future use, two syntaxes can shortened: end 2 724 isolates analysis. Now data looks like: Time analysis.","code":"our_data <- our_data %>% mutate(first = first_isolate(info = TRUE)) #> ℹ Determining first isolates using an episode length of 365 days #> ℹ Using column 'bacteria' as input for col_mo. #> ℹ Using column 'date' as input for col_date. #> ℹ Using column 'patient_id' as input for col_patient_id. #> ℹ Basing inclusion on all antimicrobial results, using a points threshold #> of 2 #> => Found 2,724 'phenotype-based' first isolates (90.8% of total where a #> microbial ID was available) our_data_1st <- our_data %>% filter(first == TRUE) our_data_1st <- our_data %>% filter_first_isolate() our_data_1st #> # A tibble: 2,724 × 9 #> patient_id hospital date bacteria AMX AMC CIP GEN first #> #> 1 J3 A 2012-11-21 B_ESCHR_COLI R I S S TRUE #> 2 R7 A 2018-04-03 B_KLBSL_PNMN R I S S TRUE #> 3 P3 A 2014-09-19 B_ESCHR_COLI R S S S TRUE #> 4 P10 A 2015-12-10 B_ESCHR_COLI S I S S TRUE #> 5 B7 A 2015-03-02 B_ESCHR_COLI S S S S TRUE #> 6 W3 A 2018-03-31 B_STPHY_AURS R S R S TRUE #> 7 M3 A 2015-10-25 B_ESCHR_COLI R S S S TRUE #> 8 J3 A 2019-06-19 B_ESCHR_COLI S S S S TRUE #> 9 G6 A 2015-04-27 B_STPHY_AURS S S S S TRUE #> 10 P4 A 2011-06-21 B_ESCHR_COLI S S S S TRUE #> # ℹ 2,714 more rows"},{"path":"https://msberends.github.io/AMR/articles/AMR.html","id":"analysing-the-data","dir":"Articles","previous_headings":"","what":"Analysing the data","title":"How to conduct AMR data analysis","text":"base R summary() function gives good first impression, comes support new mo sir classes now data set:","code":"summary(our_data_1st) #> patient_id hospital date #> Length:2724 Length:2724 Min. :2011-01-01 #> Class :character Class :character 1st Qu.:2013-04-07 #> Mode :character Mode :character Median :2015-06-03 #> Mean :2015-06-09 #> 3rd Qu.:2017-08-11 #> Max. :2019-12-27 #> bacteria AMX AMC #> Class :mo Class:sir Class:sir #> :0 %S :41.6% (n=1133) %S :52.6% (n=1432) #> Unique:4 %SDD : 0.0% (n=0) %SDD : 0.0% (n=0) #> #1 :B_ESCHR_COLI %I :16.4% (n=446) %I :12.2% (n=333) #> #2 :B_STPHY_AURS %R :42.0% (n=1145) %R :35.2% (n=959) #> #3 :B_STRPT_PNMN %NI : 0.0% (n=0) %NI : 0.0% (n=0) #> CIP GEN first #> Class:sir Class:sir Mode:logical #> %S :52.5% (n=1431) %S :61.0% (n=1661) TRUE:2724 #> %SDD : 0.0% (n=0) %SDD : 0.0% (n=0) #> %I : 6.5% (n=176) %I : 3.0% (n=82) #> %R :41.0% (n=1117) %R :36.0% (n=981) #> %NI : 0.0% (n=0) %NI : 0.0% (n=0) glimpse(our_data_1st) #> Rows: 2,724 #> Columns: 9 #> $ patient_id \"J3\", \"R7\", \"P3\", \"P10\", \"B7\", \"W3\", \"M3\", \"J3\", \"G6\", \"P4\"… #> $ hospital \"A\", \"A\", \"A\", \"A\", \"A\", \"A\", \"A\", \"A\", \"A\", \"A\", \"A\", \"A\",… #> $ date 2012-11-21, 2018-04-03, 2014-09-19, 2015-12-10, 2015-03-02… #> $ bacteria \"B_ESCHR_COLI\", \"B_KLBSL_PNMN\", \"B_ESCHR_COLI\", \"B_ESCHR_COL… #> $ AMX R, R, R, S, S, R, R, S, S, S, S, R, S, S, R, R, R, R, S, R,… #> $ AMC I, I, S, I, S, S, S, S, S, S, S, S, S, S, S, S, S, R, S, S,… #> $ CIP S, S, S, S, S, R, S, S, S, S, S, S, S, S, S, S, S, S, S, S,… #> $ GEN S, S, S, S, S, S, S, S, S, S, S, R, S, S, S, S, S, S, S, S,… #> $ first TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,… # number of unique values per column: sapply(our_data_1st, n_distinct) #> patient_id hospital date bacteria AMX AMC CIP #> 260 3 1854 4 3 3 3 #> GEN first #> 3 1"},{"path":"https://msberends.github.io/AMR/articles/AMR.html","id":"availability-of-species","dir":"Articles","previous_headings":"Analysing the data","what":"Availability of species","title":"How to conduct AMR data analysis","text":"just get idea species distributed, create frequency table count() based name microorganisms:","code":"our_data %>% count(mo_name(bacteria), sort = TRUE) #> # A tibble: 4 × 2 #> `mo_name(bacteria)` n #> #> 1 Escherichia coli 1518 #> 2 Staphylococcus aureus 730 #> 3 Streptococcus pneumoniae 426 #> 4 Klebsiella pneumoniae 326 our_data_1st %>% count(mo_name(bacteria), sort = TRUE) #> # A tibble: 4 × 2 #> `mo_name(bacteria)` n #> #> 1 Escherichia coli 1321 #> 2 Staphylococcus aureus 682 #> 3 Streptococcus pneumoniae 402 #> 4 Klebsiella pneumoniae 319"},{"path":"https://msberends.github.io/AMR/articles/AMR.html","id":"select-and-filter-with-antibiotic-selectors","dir":"Articles","previous_headings":"Analysing the data","what":"Select and filter with antibiotic selectors","title":"How to conduct AMR data analysis","text":"Using -called antibiotic class selectors, can select filter columns based antibiotic class antibiotic results :","code":"our_data_1st %>% select(date, aminoglycosides()) #> ℹ For aminoglycosides() using column 'GEN' (gentamicin) #> # A tibble: 2,724 × 2 #> date GEN #> #> 1 2012-11-21 S #> 2 2018-04-03 S #> 3 2014-09-19 S #> 4 2015-12-10 S #> 5 2015-03-02 S #> 6 2018-03-31 S #> 7 2015-10-25 S #> 8 2019-06-19 S #> 9 2015-04-27 S #> 10 2011-06-21 S #> # ℹ 2,714 more rows our_data_1st %>% select(bacteria, betalactams()) #> ℹ For betalactams() using columns 'AMX' (amoxicillin) and 'AMC' #> (amoxicillin/clavulanic acid) #> # A tibble: 2,724 × 3 #> bacteria AMX AMC #> #> 1 B_ESCHR_COLI R I #> 2 B_KLBSL_PNMN R I #> 3 B_ESCHR_COLI R S #> 4 B_ESCHR_COLI S I #> 5 B_ESCHR_COLI S S #> 6 B_STPHY_AURS R S #> 7 B_ESCHR_COLI R S #> 8 B_ESCHR_COLI S S #> 9 B_STPHY_AURS S S #> 10 B_ESCHR_COLI S S #> # ℹ 2,714 more rows our_data_1st %>% select(bacteria, where(is.sir)) #> # A tibble: 2,724 × 5 #> bacteria AMX AMC CIP GEN #> #> 1 B_ESCHR_COLI R I S S #> 2 B_KLBSL_PNMN R I S S #> 3 B_ESCHR_COLI R S S S #> 4 B_ESCHR_COLI S I S S #> 5 B_ESCHR_COLI S S S S #> 6 B_STPHY_AURS R S R S #> 7 B_ESCHR_COLI R S S S #> 8 B_ESCHR_COLI S S S S #> 9 B_STPHY_AURS S S S S #> 10 B_ESCHR_COLI S S S S #> # ℹ 2,714 more rows # filtering using AB selectors is also possible: our_data_1st %>% filter(any(aminoglycosides() == \"R\")) #> ℹ For aminoglycosides() using column 'GEN' (gentamicin) #> # A tibble: 981 × 9 #> patient_id hospital date bacteria AMX AMC CIP GEN first #> #> 1 J5 A 2017-12-25 B_STRPT_PNMN R S S R TRUE #> 2 X1 A 2017-07-04 B_STPHY_AURS R S S R TRUE #> 3 B3 A 2016-07-24 B_ESCHR_COLI S S S R TRUE #> 4 V7 A 2012-04-03 B_ESCHR_COLI S S S R TRUE #> 5 C9 A 2017-03-23 B_ESCHR_COLI S S S R TRUE #> 6 R1 A 2018-06-10 B_STPHY_AURS S S S R TRUE #> 7 S2 A 2013-07-19 B_STRPT_PNMN S S S R TRUE #> 8 P5 A 2019-03-09 B_STPHY_AURS S S S R TRUE #> 9 Q8 A 2019-08-10 B_STPHY_AURS S S S R TRUE #> 10 K5 A 2013-03-15 B_STRPT_PNMN S S S R TRUE #> # ℹ 971 more rows our_data_1st %>% filter(all(betalactams() == \"R\")) #> ℹ For betalactams() using columns 'AMX' (amoxicillin) and 'AMC' #> (amoxicillin/clavulanic acid) #> # A tibble: 462 × 9 #> patient_id hospital date bacteria AMX AMC CIP GEN first #> #> 1 M7 A 2013-07-22 B_STRPT_PNMN R R S S TRUE #> 2 R10 A 2013-12-20 B_STPHY_AURS R R S S TRUE #> 3 R7 A 2015-10-25 B_STPHY_AURS R R S S TRUE #> 4 R8 A 2019-10-25 B_STPHY_AURS R R S S TRUE #> 5 B6 A 2016-11-20 B_ESCHR_COLI R R R R TRUE #> 6 I7 A 2015-08-19 B_ESCHR_COLI R R S S TRUE #> 7 N3 A 2014-12-29 B_STRPT_PNMN R R R S TRUE #> 8 Q2 A 2019-09-22 B_ESCHR_COLI R R S S TRUE #> 9 X7 A 2011-03-20 B_ESCHR_COLI R R S R TRUE #> 10 V1 A 2018-08-07 B_STPHY_AURS R R S S TRUE #> # ℹ 452 more rows # even works in base R (since R 3.0): our_data_1st[all(betalactams() == \"R\"), ] #> ℹ For betalactams() using columns 'AMX' (amoxicillin) and 'AMC' #> (amoxicillin/clavulanic acid) #> # A tibble: 462 × 9 #> patient_id hospital date bacteria AMX AMC CIP GEN first #> #> 1 M7 A 2013-07-22 B_STRPT_PNMN R R S S TRUE #> 2 R10 A 2013-12-20 B_STPHY_AURS R R S S TRUE #> 3 R7 A 2015-10-25 B_STPHY_AURS R R S S TRUE #> 4 R8 A 2019-10-25 B_STPHY_AURS R R S S TRUE #> 5 B6 A 2016-11-20 B_ESCHR_COLI R R R R TRUE #> 6 I7 A 2015-08-19 B_ESCHR_COLI R R S S TRUE #> 7 N3 A 2014-12-29 B_STRPT_PNMN R R R S TRUE #> 8 Q2 A 2019-09-22 B_ESCHR_COLI R R S S TRUE #> 9 X7 A 2011-03-20 B_ESCHR_COLI R R S R TRUE #> 10 V1 A 2018-08-07 B_STPHY_AURS R R S S TRUE #> # ℹ 452 more rows"},{"path":"https://msberends.github.io/AMR/articles/AMR.html","id":"generate-antibiograms","dir":"Articles","previous_headings":"Analysing the data","what":"Generate antibiograms","title":"How to conduct AMR data analysis","text":"Since AMR v2.0 (March 2023), easy create different types antibiograms, support 20 different languages. four antibiogram types, proposed Klinker et al. (2021, DOI 10.1177/20499361211011373), supported new antibiogram() function: Traditional Antibiogram (TA) e.g, susceptibility Pseudomonas aeruginosa piperacillin/tazobactam (TZP) Combination Antibiogram (CA) e.g, sdditional susceptibility Pseudomonas aeruginosa TZP + tobramycin versus TZP alone Syndromic Antibiogram (SA) e.g, susceptibility Pseudomonas aeruginosa TZP among respiratory specimens (obtained among ICU patients ) Weighted-Incidence Syndromic Combination Antibiogram (WISCA) e.g, susceptibility Pseudomonas aeruginosa TZP among respiratory specimens (obtained among ICU patients ) male patients age >=65 years heart failure section, show use antibiogram() function create antibiogram types. starters, included example_isolates data set looks like:","code":"example_isolates #> # A tibble: 2,000 × 46 #> date patient age gender ward mo PEN OXA FLC AMX #> #> 1 2002-01-02 A77334 65 F Clinical B_ESCHR_COLI R NA NA NA #> 2 2002-01-03 A77334 65 F Clinical B_ESCHR_COLI R NA NA NA #> 3 2002-01-07 067927 45 F ICU B_STPHY_EPDR R NA R NA #> 4 2002-01-07 067927 45 F ICU B_STPHY_EPDR R NA R NA #> 5 2002-01-13 067927 45 F ICU B_STPHY_EPDR R NA R NA #> 6 2002-01-13 067927 45 F ICU B_STPHY_EPDR R NA R NA #> 7 2002-01-14 462729 78 M Clinical B_STPHY_AURS R NA S R #> 8 2002-01-14 462729 78 M Clinical B_STPHY_AURS R NA S R #> 9 2002-01-16 067927 45 F ICU B_STPHY_EPDR R NA R NA #> 10 2002-01-17 858515 79 F ICU B_STPHY_EPDR R NA S NA #> # ℹ 1,990 more rows #> # ℹ 36 more variables: AMC , AMP , TZP , CZO , FEP , #> # CXM , FOX , CTX , CAZ , CRO , GEN , #> # TOB , AMK , KAN , TMP , SXT , NIT , #> # FOS , LNZ , CIP , MFX , VAN , TEC , #> # TCY , TGC , DOX , ERY , CLI , AZM , #> # IPM , MEM , MTR , CHL , COL , MUP , …"},{"path":"https://msberends.github.io/AMR/articles/AMR.html","id":"traditional-antibiogram","dir":"Articles","previous_headings":"Analysing the data > Generate antibiograms","what":"Traditional Antibiogram","title":"How to conduct AMR data analysis","text":"create traditional antibiogram, simply state antibiotics used. antibiotics argument antibiogram() function supports (combination) previously mentioned antibiotic class selectors: Notice antibiogram() function automatically prints right format using Quarto R Markdown (page), even applies italics taxonomic names (using italicise_taxonomy() internally). also uses language OS either English, Chinese, Czech, Danish, Dutch, Finnish, French, German, Greek, Italian, Japanese, Norwegian, Polish, Portuguese, Romanian, Russian, Spanish, Swedish, Turkish, Ukrainian. next example, force language Spanish using language argument:","code":"antibiogram(example_isolates, antibiotics = c(aminoglycosides(), carbapenems())) #> ℹ The function aminoglycosides() should be used inside a dplyr verb or #> data.frame call, e.g.: #> • your_data %>% select(aminoglycosides()) #> • your_data %>% select(column_a, column_b, aminoglycosides()) #> • your_data %>% filter(any(aminoglycosides() == \"R\")) #> • your_data[, aminoglycosides()] #> • your_data[, c(\"column_a\", \"column_b\", aminoglycosides())] #> #> Now returning a vector of all possible antimicrobials that #> aminoglycosides() can select. #> ℹ The function carbapenems() should be used inside a dplyr verb or #> data.frame call, e.g.: #> • your_data %>% select(carbapenems()) #> • your_data %>% select(column_a, column_b, carbapenems()) #> • your_data %>% filter(any(carbapenems() == \"R\")) #> • your_data[, carbapenems()] #> • your_data[, c(\"column_a\", \"column_b\", carbapenems())] #> #> Now returning a vector of all possible antimicrobials that carbapenems() #> can select. antibiogram(example_isolates, mo_transform = \"gramstain\", antibiotics = aminoglycosides(), ab_transform = \"name\", language = \"es\") #> ℹ The function aminoglycosides() should be used inside a dplyr verb or #> data.frame call, e.g.: #> • your_data %>% select(aminoglycosides()) #> • your_data %>% select(column_a, column_b, aminoglycosides()) #> • your_data %>% filter(any(aminoglycosides() == \"R\")) #> • your_data[, aminoglycosides()] #> • your_data[, c(\"column_a\", \"column_b\", aminoglycosides())] #> #> Now returning a vector of all possible antimicrobials that #> aminoglycosides() can select."},{"path":"https://msberends.github.io/AMR/articles/AMR.html","id":"combined-antibiogram","dir":"Articles","previous_headings":"Analysing the data > Generate antibiograms","what":"Combined Antibiogram","title":"How to conduct AMR data analysis","text":"create combined antibiogram, use antibiotic codes names plus + character like :","code":"antibiogram(example_isolates, antibiotics = c(\"TZP\", \"TZP+TOB\", \"TZP+GEN\"))"},{"path":"https://msberends.github.io/AMR/articles/AMR.html","id":"syndromic-antibiogram","dir":"Articles","previous_headings":"Analysing the data > Generate antibiograms","what":"Syndromic Antibiogram","title":"How to conduct AMR data analysis","text":"create syndromic antibiogram, syndromic_group argument must used. can column data, e.g. ifelse() calculations based certain columns:","code":"antibiogram(example_isolates, antibiotics = c(aminoglycosides(), carbapenems()), syndromic_group = \"ward\") #> ℹ The function aminoglycosides() should be used inside a dplyr verb or #> data.frame call, e.g.: #> • your_data %>% select(aminoglycosides()) #> • your_data %>% select(column_a, column_b, aminoglycosides()) #> • your_data %>% filter(any(aminoglycosides() == \"R\")) #> • your_data[, aminoglycosides()] #> • your_data[, c(\"column_a\", \"column_b\", aminoglycosides())] #> #> Now returning a vector of all possible antimicrobials that #> aminoglycosides() can select. #> ℹ The function carbapenems() should be used inside a dplyr verb or #> data.frame call, e.g.: #> • your_data %>% select(carbapenems()) #> • your_data %>% select(column_a, column_b, carbapenems()) #> • your_data %>% filter(any(carbapenems() == \"R\")) #> • your_data[, carbapenems()] #> • your_data[, c(\"column_a\", \"column_b\", carbapenems())] #> #> Now returning a vector of all possible antimicrobials that carbapenems() #> can select."},{"path":"https://msberends.github.io/AMR/articles/AMR.html","id":"weighted-incidence-syndromic-combination-antibiogram-wisca","dir":"Articles","previous_headings":"Analysing the data > Generate antibiograms","what":"Weighted-Incidence Syndromic Combination Antibiogram (WISCA)","title":"How to conduct AMR data analysis","text":"create WISCA, must state combination therapy antibiotics argument (similar Combination Antibiogram), define syndromic group syndromic_group argument (similar Syndromic Antibiogram) cases predefined based clinical demographic characteristics (e.g., endocarditis 75+ females). next example simplification without clinical characteristics, just gives idea WISCA can created:","code":"wisca <- antibiogram(example_isolates, antibiotics = c(\"AMC\", \"AMC+CIP\", \"TZP\", \"TZP+TOB\"), mo_transform = \"gramstain\", minimum = 10, # this should be >= 30, but now just as example syndromic_group = ifelse(example_isolates$age >= 65 & example_isolates$gender == \"M\", \"WISCA Group 1\", \"WISCA Group 2\")) wisca"},{"path":"https://msberends.github.io/AMR/articles/AMR.html","id":"plotting-antibiograms","dir":"Articles","previous_headings":"Analysing the data > Generate antibiograms","what":"Plotting antibiograms","title":"How to conduct AMR data analysis","text":"Antibiograms can plotted using autoplot() ggplot2 packages, since AMR package provides extension function: calculate antimicrobial resistance sensible way, also correcting results, use resistance() susceptibility() functions.","code":"autoplot(wisca)"},{"path":"https://msberends.github.io/AMR/articles/AMR.html","id":"resistance-percentages","dir":"Articles","previous_headings":"Analysing the data","what":"Resistance percentages","title":"How to conduct AMR data analysis","text":"functions resistance() susceptibility() can used calculate antimicrobial resistance susceptibility. specific analyses, functions proportion_S(), proportion_SI(), proportion_I(), proportion_IR() proportion_R() can used determine proportion specific antimicrobial outcome. functions contain minimum argument, denoting minimum required number test results returning value. functions otherwise return NA. default minimum = 30, following CLSI M39-A4 guideline applying microbial epidemiology. per EUCAST guideline 2019, calculate resistance proportion R (proportion_R(), equal resistance()) susceptibility proportion S (proportion_SI(), equal susceptibility()). functions can used : can used conjunction group_by() summarise(), dplyr package: Author: Dr. Matthijs Berends, 26th Feb 2023","code":"our_data_1st %>% resistance(AMX) #> [1] 0.4203377 our_data_1st %>% group_by(hospital) %>% summarise(amoxicillin = resistance(AMX)) #> # A tibble: 3 × 2 #> hospital amoxicillin #> #> 1 A 0.340 #> 2 B 0.551 #> 3 C 0.370"},{"path":"https://msberends.github.io/AMR/articles/AMR_for_Python.html","id":"introduction","dir":"Articles","previous_headings":"","what":"Introduction","title":"AMR for Python","text":"AMR package R powerful tool antimicrobial resistance (AMR) analysis. provides extensive features handling microbial antimicrobial data. However, work primarily Python, now intuitive option available: AMR Python Package Index. Python package wrapper round AMR R package. uses rpy2 package internally. Despite need R installed, Python users can now easily work AMR data directly Python code.","code":""},{"path":"https://msberends.github.io/AMR/articles/AMR_for_Python.html","id":"install","dir":"Articles","previous_headings":"","what":"Install","title":"AMR for Python","text":"Since Python package available official Python Package Index, can just run: Make sure R installed. need install AMR R package, installed automatically. Linux: macOS (using Homebrew): Windows, visit CRAN download page download install R.","code":"pip install AMR # Ubuntu / Debian sudo apt install r-base # Fedora: sudo dnf install R # CentOS/RHEL sudo yum install R brew install r"},{"path":[]},{"path":"https://msberends.github.io/AMR/articles/AMR_for_Python.html","id":"cleaning-taxonomy","dir":"Articles","previous_headings":"Examples of Usage","what":"Cleaning Taxonomy","title":"AMR for Python","text":"’s example demonstrates clean microorganism drug names using AMR Python package:","code":"import pandas as pd import AMR # Sample data data = { \"MOs\": ['E. coli', 'ESCCOL', 'esco', 'Esche coli'], \"Drug\": ['Cipro', 'CIP', 'J01MA02', 'Ciproxin'] } df = pd.DataFrame(data) # Use AMR functions to clean microorganism and drug names df['MO_clean'] = AMR.mo_name(df['MOs']) df['Drug_clean'] = AMR.ab_name(df['Drug']) # Display the results print(df)"},{"path":"https://msberends.github.io/AMR/articles/AMR_for_Python.html","id":"explanation","dir":"Articles","previous_headings":"Examples of Usage > Cleaning Taxonomy","what":"Explanation","title":"AMR for Python","text":"mo_name: function standardises microorganism names. , different variations Escherichia coli (“E. coli”, “ESCCOL”, “esco”, “Esche coli”) converted correct, standardised form, “Escherichia coli”. ab_name: Similarly, function standardises antimicrobial names. different representations ciprofloxacin (e.g., “Cipro”, “CIP”, “J01MA02”, “Ciproxin”) converted standard name, “Ciprofloxacin”.","code":""},{"path":"https://msberends.github.io/AMR/articles/AMR_for_Python.html","id":"taxonomic-data-sets-now-in-python","dir":"Articles","previous_headings":"Examples of Usage","what":"Taxonomic Data Sets Now in Python!","title":"AMR for Python","text":"Python user, might like important data sets AMR R package, microorganisms, antibiotics, clinical_breakpoints, example_isolates, now available regular Python data frames:","code":"AMR.microorganisms AMR.antibiotics"},{"path":"https://msberends.github.io/AMR/articles/AMR_for_Python.html","id":"calculating-amr","dir":"Articles","previous_headings":"Examples of Usage","what":"Calculating AMR","title":"AMR for Python","text":"","code":"import AMR import pandas as pd df = AMR.example_isolates result = AMR.resistance(df[\"AMX\"]) print(result) [0.59555556]"},{"path":"https://msberends.github.io/AMR/articles/AMR_for_Python.html","id":"generating-antibiograms","dir":"Articles","previous_headings":"Examples of Usage","what":"Generating Antibiograms","title":"AMR for Python","text":"One core functions AMR package generating antibiogram, table summarises antimicrobial susceptibility bacterial isolates. ’s can generate antibiogram Python: example, generate antibiogram selecting various antibiotics.","code":"result2a = AMR.antibiogram(df[[\"mo\", \"AMX\", \"CIP\", \"TZP\"]]) print(result2a) result2b = AMR.antibiogram(df[[\"mo\", \"AMX\", \"CIP\", \"TZP\"]], mo_transform = \"gramstain\") print(result2b)"},{"path":"https://msberends.github.io/AMR/articles/AMR_for_Python.html","id":"conclusion","dir":"Articles","previous_headings":"","what":"Conclusion","title":"AMR for Python","text":"AMR Python package, Python users can now effortlessly call R functions AMR R package. eliminates need complex rpy2 configurations provides clean, easy--use interface antimicrobial resistance analysis. examples provided demonstrate can applied typical workflows, standardising microorganism antimicrobial names calculating resistance. just running import AMR, users can seamlessly integrate robust features R AMR package Python workflows. Whether ’re cleaning data analysing resistance patterns, AMR Python package makes easy work AMR data Python.","code":""},{"path":"https://msberends.github.io/AMR/articles/EUCAST.html","id":"introduction","dir":"Articles","previous_headings":"","what":"Introduction","title":"How to apply EUCAST rules","text":"EUCAST rules? European Committee Antimicrobial Susceptibility Testing (EUCAST) states website: EUCAST expert rules tabulated collection expert knowledge intrinsic resistances, exceptional resistance phenotypes interpretive rules may applied antimicrobial susceptibility testing order reduce errors make appropriate recommendations reporting particular resistances. Europe, lot medical microbiological laboratories already apply rules (Brown et al., 2015). package features latest insights intrinsic resistance unusual phenotypes (v3.1, 2016). Moreover, eucast_rules() function use purpose can also apply additional rules, like forcing ampicillin = R isolates amoxicillin/clavulanic acid = R.","code":""},{"path":"https://msberends.github.io/AMR/articles/EUCAST.html","id":"examples","dir":"Articles","previous_headings":"","what":"Examples","title":"How to apply EUCAST rules","text":"rules can used discard impossible bug-drug combinations data. example, Klebsiella produces beta-lactamase prevents ampicillin (amoxicillin) working . words, practically every strain Klebsiella resistant ampicillin. Sometimes, laboratory data can still contain strains ampicillin susceptible ampicillin. antibiogram available identification available, antibiogram re-interpreted based identification (namely, Klebsiella). EUCAST expert rules solve , can applied using eucast_rules(): convenient function mo_is_intrinsic_resistant() uses guideline, allows check one specific microorganisms antibiotics: EUCAST rules can used correction, can also used filling known resistance susceptibility based results antimicrobials drugs. process called interpretive reading, basically form imputation, part eucast_rules() function well:","code":"oops <- data.frame( mo = c( \"Klebsiella\", \"Escherichia\" ), ampicillin = \"S\" ) oops #> mo ampicillin #> 1 Klebsiella S #> 2 Escherichia S eucast_rules(oops, info = FALSE) #> mo ampicillin #> 1 Klebsiella R #> 2 Escherichia S mo_is_intrinsic_resistant( c(\"Klebsiella\", \"Escherichia\"), \"ampicillin\" ) #> [1] TRUE FALSE mo_is_intrinsic_resistant( \"Klebsiella\", c(\"ampicillin\", \"kanamycin\") ) #> [1] TRUE FALSE data <- data.frame( mo = c( \"Staphylococcus aureus\", \"Enterococcus faecalis\", \"Escherichia coli\", \"Klebsiella pneumoniae\", \"Pseudomonas aeruginosa\" ), VAN = \"-\", # Vancomycin AMX = \"-\", # Amoxicillin COL = \"-\", # Colistin CAZ = \"-\", # Ceftazidime CXM = \"-\", # Cefuroxime PEN = \"S\", # Benzylenicillin FOX = \"S\", # Cefoxitin stringsAsFactors = FALSE ) data eucast_rules(data)"},{"path":"https://msberends.github.io/AMR/articles/MDR.html","id":"type-of-input","dir":"Articles","previous_headings":"","what":"Type of input","title":"How to determine multi-drug resistance (MDR)","text":"mdro() function takes data set input, regular data.frame. tries automatically determine right columns info isolates, name species columns results antimicrobial agents. See help page info set right settings data command ?mdro. WHONET data (data), settings automatically set correctly.","code":""},{"path":"https://msberends.github.io/AMR/articles/MDR.html","id":"guidelines","dir":"Articles","previous_headings":"","what":"Guidelines","title":"How to determine multi-drug resistance (MDR)","text":"mdro() function support multiple guidelines. can select guideline guideline parameter. Currently supported guidelines (case-insensitive): guideline = \"CMI2012\" (default) Magiorakos AP, Srinivasan et al. “Multidrug-resistant, extensively drug-resistant pandrug-resistant bacteria: international expert proposal interim standard definitions acquired resistance.” Clinical Microbiology Infection (2012) (link) guideline = \"EUCAST3.2\" (simply guideline = \"EUCAST\") European international guideline - EUCAST Expert Rules Version 3.2 “Intrinsic Resistance Unusual Phenotypes” (link) guideline = \"EUCAST3.1\" European international guideline - EUCAST Expert Rules Version 3.1 “Intrinsic Resistance Exceptional Phenotypes Tables” (link) guideline = \"TB\" international guideline multi-drug resistant tuberculosis - World Health Organization “Companion handbook guidelines programmatic management drug-resistant tuberculosis” (link) guideline = \"MRGN\" German national guideline - Mueller et al. (2015) Antimicrobial Resistance Infection Control 4:7. DOI: 10.1186/s13756-015-0047-6 guideline = \"BRMO\" Dutch national guideline - Rijksinstituut voor Volksgezondheid en Milieu “WIP-richtlijn BRMO (Bijzonder Resistente Micro-Organismen) (ZKH)” (link) Please suggest (country-specific) guidelines letting us know: https://github.com/msberends/AMR/issues/new.","code":""},{"path":"https://msberends.github.io/AMR/articles/MDR.html","id":"custom-guidelines","dir":"Articles","previous_headings":"Guidelines","what":"Custom Guidelines","title":"How to determine multi-drug resistance (MDR)","text":"can also use custom guideline. Custom guidelines can set custom_mdro_guideline() function. great importance custom rules determine MDROs hospital, e.g., rules dependent ward, state contact isolation variables data. familiar case_when() dplyr package, recognise input method set rules. Rules must set using R considers ‘formula notation’: row/isolate matches first rule, value first ~ (case ‘Elderly Type ’) set MDRO value. Otherwise, second rule tried . maximum number rules unlimited. can print rules set console overview. Colours help reading console supports colours. outcome function can used guideline argument mdro() function: rules set (custom object case) exported shared file location using saveRDS() collaborate multiple users. custom rules set imported using readRDS().","code":"custom <- custom_mdro_guideline( CIP == \"R\" & age > 60 ~ \"Elderly Type A\", ERY == \"R\" & age > 60 ~ \"Elderly Type B\" ) custom #> A set of custom MDRO rules: #> 1. If CIP is \"R\" and age is higher than 60 then: Elderly Type A #> 2. If ERY is \"R\" and age is higher than 60 then: Elderly Type B #> 3. Otherwise: Negative #> #> Unmatched rows will return NA. #> Results will be of class 'factor', with ordered levels: Negative < Elderly Type A < Elderly Type B x <- mdro(example_isolates, guideline = custom) table(x) #> x #> Negative Elderly Type A Elderly Type B #> 1070 198 732"},{"path":"https://msberends.github.io/AMR/articles/MDR.html","id":"examples","dir":"Articles","previous_headings":"","what":"Examples","title":"How to determine multi-drug resistance (MDR)","text":"mdro() function always returns ordered factor predefined guidelines. example, output default guideline Magiorakos et al. returns factor levels ‘Negative’, ‘MDR’, ‘XDR’ ‘PDR’ order. next example uses example_isolates data set. data set included package contains full antibiograms 2,000 microbial isolates. reflects reality can used practise AMR data analysis. test MDR/XDR/PDR guideline data set, get: Frequency table Class: factor > ordered (numeric) Length: 2,000 Levels: 4: Negative < Multi-drug-resistant (MDR) < Extensively drug-resistant … Available: 1,745 (87.25%, NA: 255 = 12.75%) Unique: 2 another example, create data set determine multi-drug resistant TB: column names automatically verified valid drug names codes, worked exactly way: data set now looks like : can now add interpretation MDR-TB data set. can use: shortcut mdr_tb(): Create frequency table results: Frequency table Class: factor > ordered (numeric) Length: 5,000 Levels: 5: Negative < Mono-resistant < Poly-resistant < Multi-drug-resistant <… Available: 5,000 (100%, NA: 0 = 0%) Unique: 5","code":"library(dplyr) # to support pipes: %>% library(cleaner) # to create frequency tables example_isolates %>% mdro() %>% freq() # show frequency table of the result #> Warning: in mdro(): NA introduced for isolates where the available percentage of #> antimicrobial classes was below 50% (set with pct_required_classes) # random_sir() is a helper function to generate # a random vector with values S, I and R my_TB_data <- data.frame( rifampicin = random_sir(5000), isoniazid = random_sir(5000), gatifloxacin = random_sir(5000), ethambutol = random_sir(5000), pyrazinamide = random_sir(5000), moxifloxacin = random_sir(5000), kanamycin = random_sir(5000) ) my_TB_data <- data.frame( RIF = random_sir(5000), INH = random_sir(5000), GAT = random_sir(5000), ETH = random_sir(5000), PZA = random_sir(5000), MFX = random_sir(5000), KAN = random_sir(5000) ) head(my_TB_data) #> rifampicin isoniazid gatifloxacin ethambutol pyrazinamide moxifloxacin #> 1 I R S S S S #> 2 S S I R R S #> 3 R I I I R I #> 4 I S S S S S #> 5 I I I S I S #> 6 R S R S I I #> kanamycin #> 1 R #> 2 I #> 3 S #> 4 I #> 5 I #> 6 I mdro(my_TB_data, guideline = \"TB\") my_TB_data$mdr <- mdr_tb(my_TB_data) #> ℹ No column found as input for col_mo, assuming all rows contain #> Mycobacterium tuberculosis. freq(my_TB_data$mdr)"},{"path":[]},{"path":"https://msberends.github.io/AMR/articles/PCA.html","id":"transforming","dir":"Articles","previous_headings":"","what":"Transforming","title":"How to conduct principal component analysis (PCA) for AMR","text":"PCA, need transform AMR data first. example_isolates data set package looks like: Now transform data set resistance percentages per taxonomic order genus:","code":"library(AMR) library(dplyr) glimpse(example_isolates) #> Rows: 2,000 #> Columns: 46 #> $ date 2002-01-02, 2002-01-03, 2002-01-07, 2002-01-07, 2002-01-13, 2… #> $ patient \"A77334\", \"A77334\", \"067927\", \"067927\", \"067927\", \"067927\", \"4… #> $ age 65, 65, 45, 45, 45, 45, 78, 78, 45, 79, 67, 67, 71, 71, 75, 50… #> $ gender \"F\", \"F\", \"F\", \"F\", \"F\", \"F\", \"M\", \"M\", \"F\", \"F\", \"M\", \"M\", \"M… #> $ ward \"Clinical\", \"Clinical\", \"ICU\", \"ICU\", \"ICU\", \"ICU\", \"Clinical\"… #> $ mo \"B_ESCHR_COLI\", \"B_ESCHR_COLI\", \"B_STPHY_EPDR\", \"B_STPHY_EPDR\",… #> $ PEN R, R, R, R, R, R, R, R, R, R, R, R, R, R, R, R, R, R, R, R, S,… #> $ OXA NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA… #> $ FLC NA, NA, R, R, R, R, S, S, R, S, S, S, NA, NA, NA, NA, NA, R, R… #> $ AMX NA, NA, NA, NA, NA, NA, R, R, NA, NA, NA, NA, NA, NA, R, NA, N… #> $ AMC I, I, NA, NA, NA, NA, S, S, NA, NA, S, S, I, I, R, I, I, NA, N… #> $ AMP NA, NA, NA, NA, NA, NA, R, R, NA, NA, NA, NA, NA, NA, R, NA, N… #> $ TZP NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA… #> $ CZO NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, R, NA,… #> $ FEP NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA… #> $ CXM I, I, R, R, R, R, S, S, R, S, S, S, S, S, NA, S, S, R, R, S, S… #> $ FOX NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, R, NA,… #> $ CTX NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, S, S, NA, S, S… #> $ CAZ NA, NA, R, R, R, R, R, R, R, R, R, R, NA, NA, NA, S, S, R, R, … #> $ CRO NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, S, S, NA, S, S… #> $ GEN NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA… #> $ TOB NA, NA, NA, NA, NA, NA, S, S, NA, NA, NA, NA, S, S, NA, NA, NA… #> $ AMK NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA… #> $ KAN NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA… #> $ TMP