diff --git a/DESCRIPTION b/DESCRIPTION index 7de38f74..3f55eb76 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: AMR -Version: 0.8.0.9017 -Date: 2019-11-06 +Version: 0.8.0.9021 +Date: 2019-11-09 Title: Antimicrobial Resistance Analysis Authors@R: c( person(role = c("aut", "cre"), diff --git a/NEWS.md b/NEWS.md index 8c1bcb95..245594e8 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,5 @@ -# AMR 0.8.0.9017 -Last updated: 06-Nov-2019 +# AMR 0.8.0.9021 +Last updated: 09-Nov-2019 ### New * Support for a new MDRO guideline: Magiorakos AP, Srinivasan A *et al.* "Multidrug-resistant, extensively drug-resistant and pandrug-resistant bacteria: an international expert proposal for interim standard definitions for acquired resistance." Clinical Microbiology and Infection (2012). diff --git a/R/ab.R b/R/ab.R index ec6bf1de..d898a378 100755 --- a/R/ab.R +++ b/R/ab.R @@ -75,7 +75,7 @@ as.ab <- function(x, ...) { # remove suffices x_bak_clean <- gsub("_(mic|rsi|dis[ck])$", "", x, ignore.case = TRUE) # remove disk concentrations, like LVX_NM -> LVX - x_bak_clean <- gsub("_[A-Z]{2}[0-9_]{0,3}$", "", x_bak_clean, ignore.case = TRUE) + x_bak_clean <- gsub("_[A-Z]{2}[0-9_.]{0,3}$", "", x_bak_clean, ignore.case = TRUE) # remove part between brackets if that's followed by another string x_bak_clean <- gsub("(.*)+ [(].*[)]", "\\1", x_bak_clean) # keep only max 1 space diff --git a/R/eucast_rules.R b/R/eucast_rules.R index 472209e3..38375369 100755 --- a/R/eucast_rules.R +++ b/R/eucast_rules.R @@ -241,11 +241,11 @@ eucast_rules <- function(x, warned <- FALSE txt_error <- function() { - cat("", bgRed(white(" ERROR ")), "\n\n") + if (info == TRUE) cat("", bgRed(white(" ERROR ")), "\n\n") } txt_warning <- function() { if (warned == FALSE) { - cat("", bgYellow(black(" WARNING "))) + if (info == TRUE) cat("", bgYellow(black(" WARNING "))) } warned <<- TRUE } diff --git a/appveyor.yml b/appveyor.yml index 65d7a8e6..24c366db 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -42,8 +42,10 @@ environment: USE_RTOOLS: true matrix: + - R_VERSION: oldrel - R_VERSION: release - - R_VERSION: devel + allow_failures: + - R_VERSION: devel build_script: - travis_tool.sh install_deps diff --git a/docs/404.html b/docs/404.html index ed984d46..d7879f87 100644 --- a/docs/404.html +++ b/docs/404.html @@ -84,7 +84,7 @@
diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index 783ceac4..1153159c 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -84,7 +84,7 @@ diff --git a/docs/articles/AMR.html b/docs/articles/AMR.html index dce1f69e..a65f8394 100644 --- a/docs/articles/AMR.html +++ b/docs/articles/AMR.html @@ -41,7 +41,7 @@ @@ -187,7 +187,7 @@AMR.Rmd
Note: values on this page will change with every website update since they are based on randomly created values and the page was written in R Markdown. However, the methodology remains unchanged. This page was generated on 16 October 2019.
+Note: values on this page will change with every website update since they are based on randomly created values and the page was written in R Markdown. However, the methodology remains unchanged. This page was generated on 09 November 2019.
We also created a package dedicated to data cleaning and checking, called the clean
package. It gets automatically installed with the AMR
package, so we only have to load it:
Use the frequency table function freq()
from this clean
package to look specifically for unique values in any variable. For example, for the gender
variable:
We also created a package dedicated to data cleaning and checking, called the cleaner
package. It gets automatically installed with the AMR
package. For its freq()
function to create frequency tables, you don’t even need to load it yourself as it is available through the AMR
package as well.
For example, for the gender
variable:
# Frequency table
#
# Class: factor (numeric)
@@ -407,82 +406,82 @@
#
# Item Count Percent Cum. Count Cum. Percent
# --- ----- ------- -------- ----------- -------------
-# 1 M 10,380 51.9% 10,380 51.9%
-# 2 F 9,620 48.1% 20,000 100.0%
+# 1 M 10,398 51.99% 10,398 51.99%
+# 2 F 9,602 48.01% 20,000 100.00%
So, we can draw at least two conclusions immediately. From a data scientists perspective, the data looks clean: only values M
and F
. From a researchers perspective: there are slightly more men. Nothing we didn’t already know.
The data is already quite clean, but we still need to transform some variables. The bacteria
column now consists of text, and we want to add more variables based on microbial IDs later on. So, we will transform this column to valid IDs. The mutate()
function of the dplyr
package makes this really easy:
We also want to transform the antibiotics, because in real life data we don’t know if they are really clean. The as.rsi()
function ensures reliability and reproducibility in these kind of variables. The mutate_at()
will run the as.rsi()
function on defined variables:
Finally, we will apply EUCAST rules on our antimicrobial results. In Europe, most medical microbiological laboratories already apply these rules. Our package features their latest insights on intrinsic resistance and exceptional phenotypes. Moreover, the eucast_rules()
function can also apply additional rules, like forcing
Because the amoxicillin (column AMX
) and amoxicillin/clavulanic acid (column AMC
) in our data were generated randomly, some rows will undoubtedly contain AMX = S and AMC = R, which is technically impossible. The eucast_rules()
fixes this:
data <- eucast_rules(data, col_mo = "bacteria")
-#
-# Rules by the European Committee on Antimicrobial Susceptibility Testing (EUCAST)
-# http://eucast.org/
-#
-# EUCAST Clinical Breakpoints (v9.0, 2019)
-# Aerococcus sanguinicola (no changes)
-# Aerococcus urinae (no changes)
-# Anaerobic Gram-negatives (no changes)
-# Anaerobic Gram-positives (no changes)
-# Campylobacter coli (no changes)
-# Campylobacter jejuni (no changes)
-# Enterobacteriales (Order) (no changes)
-# Enterococcus (no changes)
-# Haemophilus influenzae (no changes)
-# Kingella kingae (no changes)
-# Moraxella catarrhalis (no changes)
-# Pasteurella multocida (no changes)
-# Staphylococcus (no changes)
-# Streptococcus groups A, B, C, G (no changes)
-# Streptococcus pneumoniae (1,483 values changed)
-# Viridans group streptococci (no changes)
-#
-# EUCAST Expert Rules, Intrinsic Resistance and Exceptional Phenotypes (v3.1, 2016)
-# Table 01: Intrinsic resistance in Enterobacteriaceae (1,268 values changed)
-# Table 02: Intrinsic resistance in non-fermentative Gram-negative bacteria (no changes)
-# Table 03: Intrinsic resistance in other Gram-negative bacteria (no changes)
-# Table 04: Intrinsic resistance in Gram-positive bacteria (2,755 values changed)
-# Table 08: Interpretive rules for B-lactam agents and Gram-positive cocci (no changes)
-# Table 09: Interpretive rules for B-lactam agents and Gram-negative rods (no changes)
-# Table 11: Interpretive rules for macrolides, lincosamides, and streptogramins (no changes)
-# Table 12: Interpretive rules for aminoglycosides (no changes)
-# Table 13: Interpretive rules for quinolones (no changes)
-#
-# Other rules
-# Non-EUCAST: amoxicillin/clav acid = S where ampicillin = S (2,282 values changed)
-# Non-EUCAST: ampicillin = R where amoxicillin/clav acid = R (122 values changed)
-# Non-EUCAST: piperacillin = R where piperacillin/tazobactam = R (no changes)
-# Non-EUCAST: piperacillin/tazobactam = S where piperacillin = S (no changes)
-# Non-EUCAST: trimethoprim = R where trimethoprim/sulfa = R (no changes)
-# Non-EUCAST: trimethoprim/sulfa = S where trimethoprim = S (no changes)
-#
-# --------------------------------------------------------------------------
-# EUCAST rules affected 6,530 out of 20,000 rows, making a total of 7,910 edits
-# => added 0 test results
-#
-# => changed 7,910 test results
-# - 109 test results changed from S to I
-# - 4,678 test results changed from S to R
-# - 1,098 test results changed from I to S
-# - 322 test results changed from I to R
-# - 1,676 test results changed from R to S
-# - 27 test results changed from R to I
-# --------------------------------------------------------------------------
-#
-# Use eucast_rules(..., verbose = TRUE) (on your original data) to get a data.frame with all specified edits instead.
data <- eucast_rules(data, col_mo = "bacteria")
+#
+# Rules by the European Committee on Antimicrobial Susceptibility Testing (EUCAST)
+# http://eucast.org/
+#
+# EUCAST Clinical Breakpoints (v9.0, 2019)
+# Aerococcus sanguinicola (no changes)
+# Aerococcus urinae (no changes)
+# Anaerobic Gram-negatives (no changes)
+# Anaerobic Gram-positives (no changes)
+# Campylobacter coli (no changes)
+# Campylobacter jejuni (no changes)
+# Enterobacterales (Order) (no changes)
+# Enterococcus (no changes)
+# Haemophilus influenzae (no changes)
+# Kingella kingae (no changes)
+# Moraxella catarrhalis (no changes)
+# Pasteurella multocida (no changes)
+# Staphylococcus (no changes)
+# Streptococcus groups A, B, C, G (no changes)
+# Streptococcus pneumoniae (1,452 values changed)
+# Viridans group streptococci (no changes)
+#
+# EUCAST Expert Rules, Intrinsic Resistance and Exceptional Phenotypes (v3.1, 2016)
+# Table 01: Intrinsic resistance in Enterobacteriaceae (1,294 values changed)
+# Table 02: Intrinsic resistance in non-fermentative Gram-negative bacteria (no changes)
+# Table 03: Intrinsic resistance in other Gram-negative bacteria (no changes)
+# Table 04: Intrinsic resistance in Gram-positive bacteria (2,721 values changed)
+# Table 08: Interpretive rules for B-lactam agents and Gram-positive cocci (no changes)
+# Table 09: Interpretive rules for B-lactam agents and Gram-negative rods (no changes)
+# Table 11: Interpretive rules for macrolides, lincosamides, and streptogramins (no changes)
+# Table 12: Interpretive rules for aminoglycosides (no changes)
+# Table 13: Interpretive rules for quinolones (no changes)
+#
+# Other rules
+# Non-EUCAST: amoxicillin/clav acid = S where ampicillin = S (2,287 values changed)
+# Non-EUCAST: ampicillin = R where amoxicillin/clav acid = R (107 values changed)
+# Non-EUCAST: piperacillin = R where piperacillin/tazobactam = R (no changes)
+# Non-EUCAST: piperacillin/tazobactam = S where piperacillin = S (no changes)
+# Non-EUCAST: trimethoprim = R where trimethoprim/sulfa = R (no changes)
+# Non-EUCAST: trimethoprim/sulfa = S where trimethoprim = S (no changes)
+#
+# --------------------------------------------------------------------------
+# EUCAST rules affected 6,525 out of 20,000 rows, making a total of 7,861 edits
+# => added 0 test results
+#
+# => changed 7,861 test results
+# - 100 test results changed from S to I
+# - 4,694 test results changed from S to R
+# - 1,140 test results changed from I to S
+# - 302 test results changed from I to R
+# - 1,594 test results changed from R to S
+# - 31 test results changed from R to I
+# --------------------------------------------------------------------------
+#
+# Use eucast_rules(..., verbose = TRUE) (on your original data) to get a data.frame with all specified edits instead.
Now that we have the microbial ID, we can add some taxonomic properties:
-data <- data %>%
- mutate(gramstain = mo_gramstain(bacteria),
- genus = mo_genus(bacteria),
- species = mo_species(bacteria))
data <- data %>%
+ mutate(gramstain = mo_gramstain(bacteria),
+ genus = mo_genus(bacteria),
+ species = mo_species(bacteria))
(…) When preparing a cumulative antibiogram to guide clinical decisions about empirical antimicrobial therapy of initial infections, only the first isolate of a given species per patient, per analysis period (eg, one year) should be included, irrespective of body site, antimicrobial susceptibility profile, or other phenotypical characteristics (eg, biotype). The first isolate is easily identified, and cumulative antimicrobial susceptibility test data prepared using the first isolate are generally comparable to cumulative antimicrobial susceptibility test data calculated by other methods, providing duplicate isolates are excluded.
M39-A4 Analysis and Presentation of Cumulative Antimicrobial Susceptibility Test Data, 4th Edition. CLSI, 2014. Chapter 6.4
This AMR
package includes this methodology with the first_isolate()
function. It adopts the episode of a year (can be changed by user) and it starts counting days after every selected isolate. This new variable can easily be added to our data:
data <- data %>%
- mutate(first = first_isolate(.))
-# NOTE: Using column `bacteria` as input for `col_mo`.
-# NOTE: Using column `date` as input for `col_date`.
-# NOTE: Using column `patient_id` as input for `col_patient_id`.
-# => Found 5,688 first isolates (28.4% of total)
data <- data %>%
+ mutate(first = first_isolate(.))
+# NOTE: Using column `bacteria` as input for `col_mo`.
+# NOTE: Using column `date` as input for `col_date`.
+# NOTE: Using column `patient_id` as input for `col_patient_id`.
+# => Found 5,670 first isolates (28.4% of total)
So only 28.4% is suitable for resistance analysis! We can now filter on it with the filter()
function, also from the dplyr
package:
For future use, the above two syntaxes can be shortened with the filter_first_isolate()
function:
We made a slight twist to the CLSI algorithm, to take into account the antimicrobial susceptibility profile. Have a look at all isolates of patient I4, sorted on date:
+We made a slight twist to the CLSI algorithm, to take into account the antimicrobial susceptibility profile. Have a look at all isolates of patient Y8, sorted on date:
isolate | @@ -525,8 +524,8 @@|||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | -2010-02-10 | -I4 | +2010-04-05 | +Y8 | B_ESCHR_COLI | R | S | @@ -536,10 +535,10 @@||||||
2 | -2010-02-19 | -I4 | +2010-04-09 | +Y8 | B_ESCHR_COLI | -S | +R | S | S | S | @@ -547,8 +546,8 @@|||
3 | -2010-03-09 | -I4 | +2010-04-14 | +Y8 | B_ESCHR_COLI | S | S | @@ -558,21 +557,21 @@||||||
4 | -2010-04-06 | -I4 | +2010-05-23 | +Y8 | B_ESCHR_COLI | -I | S | -R | +S | +S | S | FALSE | |
5 | -2010-07-14 | -I4 | +2010-07-05 | +Y8 | B_ESCHR_COLI | -S | +R | S | S | S | @@ -580,43 +579,43 @@|||
6 | -2010-08-03 | -I4 | +2010-07-05 | +Y8 | B_ESCHR_COLI | -I | +R | +S | +S | S | -R | -R | FALSE |
7 | -2010-09-19 | -I4 | +2010-07-10 | +Y8 | B_ESCHR_COLI | S | S | -S | +R | S | FALSE | ||
8 | -2010-09-19 | -I4 | +2010-08-07 | +Y8 | B_ESCHR_COLI | -S | -S | +R | +R | S | S | FALSE | |
9 | -2010-10-05 | -I4 | +2010-09-24 | +Y8 | B_ESCHR_COLI | -S | +R | S | S | S | @@ -624,12 +623,12 @@|||
10 | -2010-12-30 | -I4 | +2011-02-13 | +Y8 | B_ESCHR_COLI | S | S | -S | +R | S | FALSE |
Only 1 isolates are marked as ‘first’ according to CLSI guideline. But when reviewing the antibiogram, it is obvious that some isolates are absolutely different strains and should be included too. This is why we weigh isolates, based on their antibiogram. The key_antibiotics()
function adds a vector with 18 key antibiotics: 6 broad spectrum ones, 6 small spectrum for Gram negatives and 6 small spectrum for Gram positives. These can be defined by the user.
If a column exists with a name like ‘key(…)ab’ the first_isolate()
function will automatically use it and determine the first weighted isolates. Mind the NOTEs in below output:
data <- data %>%
- mutate(keyab = key_antibiotics(.)) %>%
- mutate(first_weighted = first_isolate(.))
-# NOTE: Using column `bacteria` as input for `col_mo`.
-# NOTE: Using column `bacteria` as input for `col_mo`.
-# NOTE: Using column `date` as input for `col_date`.
-# NOTE: Using column `patient_id` as input for `col_patient_id`.
-# NOTE: Using column `keyab` as input for `col_keyantibiotics`. Use col_keyantibiotics = FALSE to prevent this.
-# [Criterion] Inclusion based on key antibiotics, ignoring I
-# => Found 15,143 first weighted isolates (75.7% of total)
data <- data %>%
+ mutate(keyab = key_antibiotics(.)) %>%
+ mutate(first_weighted = first_isolate(.))
+# NOTE: Using column `bacteria` as input for `col_mo`.
+# NOTE: Using column `bacteria` as input for `col_mo`.
+# NOTE: Using column `date` as input for `col_date`.
+# NOTE: Using column `patient_id` as input for `col_patient_id`.
+# NOTE: Using column `keyab` as input for `col_keyantibiotics`. Use col_keyantibiotics = FALSE to prevent this.
+# [Criterion] Inclusion based on key antibiotics, ignoring I
+# => Found 15,079 first weighted isolates (75.4% of total)
isolate | @@ -663,8 +662,8 @@|||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | -2010-02-10 | -I4 | +2010-04-05 | +Y8 | B_ESCHR_COLI | R | S | @@ -675,124 +674,124 @@||||||||
2 | -2010-02-19 | -I4 | +2010-04-09 | +Y8 | B_ESCHR_COLI | -S | +R | S | S | S | FALSE | -TRUE | +FALSE | ||
3 | -2010-03-09 | -I4 | +2010-04-14 | +Y8 | B_ESCHR_COLI | S | S | S | S | FALSE | -FALSE | -||||
4 | -2010-04-06 | -I4 | -B_ESCHR_COLI | -I | -S | -R | -S | -FALSE | TRUE | ||||||
5 | -2010-07-14 | -I4 | +|||||||||||||
4 | +2010-05-23 | +Y8 | B_ESCHR_COLI | S | S | S | S | FALSE | +FALSE | +||||||
5 | +2010-07-05 | +Y8 | +B_ESCHR_COLI | +R | +S | +S | +S | +FALSE | TRUE | ||||||
6 | -2010-08-03 | -I4 | +2010-07-05 | +Y8 | B_ESCHR_COLI | -I | +R | +S | +S | S | -R | -R | FALSE | -TRUE | +FALSE |
7 | -2010-09-19 | -I4 | +2010-07-10 | +Y8 | B_ESCHR_COLI | S | S | -S | +R | S | FALSE | TRUE | |||
8 | -2010-09-19 | -I4 | +2010-08-07 | +Y8 | B_ESCHR_COLI | -S | -S | +R | +R | S | S | FALSE | -FALSE | +TRUE | |
9 | -2010-10-05 | -I4 | +2010-09-24 | +Y8 | B_ESCHR_COLI | -S | +R | S | S | S | FALSE | -FALSE | +TRUE | ||
10 | -2010-12-30 | -I4 | +2011-02-13 | +Y8 | B_ESCHR_COLI | S | S | -S | +R | S | FALSE | -FALSE | +TRUE |
Instead of 1, now 6 isolates are flagged. In total, 75.7% of all isolates are marked ‘first weighted’ - 47.3% more than when using the CLSI guideline. In real life, this novel algorithm will yield 5-10% more isolates than the classic CLSI guideline.
+Instead of 1, now 7 isolates are flagged. In total, 75.4% of all isolates are marked ‘first weighted’ - 47.0% more than when using the CLSI guideline. In real life, this novel algorithm will yield 5-10% more isolates than the classic CLSI guideline.
As with filter_first_isolate()
, there’s a shortcut for this new algorithm too:
So we end up with 15,143 isolates for analysis.
+ +So we end up with 15,079 isolates for analysis.
We can remove unneeded columns:
- +Now our data looks like:
- +@@ -813,30 +812,30 @@ | |||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | -2012-05-14 | -G6 | -Hospital B | -B_ESCHR_COLI | -R | +2011-07-25 | +L6 | +Hospital D | +B_STPHY_AURS | +S | S | R | -R | +S | M | -Gram-negative | -Escherichia | -coli | +Gram-positive | +Staphylococcus | +aureus | TRUE | |
3 | -2010-04-06 | -F7 | +2012-04-04 | +C3 | Hospital B | B_ESCHR_COLI | -I | +R | +S | +S | S | -R | -R | M | Gram-negative | Escherichia | @@ -844,67 +843,67 @@TRUE | ||||||
5 | -2017-05-22 | -T6 | -Hospital A | -B_STPHY_AURS | -R | +4 | +2017-10-06 | +W8 | +Hospital B | +B_ESCHR_COLI | +S | S | S | S | F | -Gram-positive | -Staphylococcus | -aureus | +Gram-negative | +Escherichia | +coli | TRUE | |
6 | -2012-06-06 | -X7 | +5 | +2013-07-22 | +Q6 | Hospital D | -B_STPHY_AURS | +B_ESCHR_COLI | R | -S | +I | S | S | F | -Gram-positive | -Staphylococcus | -aureus | +Gram-negative | +Escherichia | +coli | TRUE | ||
7 | -2010-02-15 | -O1 | -Hospital A | -B_STPHY_AURS | -S | -S | +6 | +2011-06-05 | +W7 | +Hospital B | +B_ESCHR_COLI | R | S | +S | +S | F | -Gram-positive | -Staphylococcus | -aureus | +Gram-negative | +Escherichia | +coli | TRUE |
9 | -2016-11-25 | -C6 | +2013-04-24 | +D1 | Hospital B | -B_ESCHR_COLI | +B_STPHY_AURS | S | S | S | S | M | -Gram-negative | -Escherichia | -coli | +Gram-positive | +Staphylococcus | +aureus | TRUE | ||||
1 | Escherichia coli | -7,512 | -49.61% | -7,512 | -49.61% | +7,442 | +49.35% | +7,442 | +49.35% | ||||||||||||||
2 | Staphylococcus aureus | -3,819 | -25.22% | -11,331 | -74.83% | +3,732 | +24.75% | +11,174 | +74.10% | ||||||||||||||
3 | Streptococcus pneumoniae | -2,243 | -14.81% | -13,574 | -89.64% | +2,323 | +15.41% | +13,497 | +89.51% | ||||||||||||||
4 | Klebsiella pneumoniae | -1,569 | -10.36% | -15,143 | +1,582 | +10.49% | +15,079 | 100.00% |
hospital | @@ -993,27 +992,27 @@ Longest: 24||
---|---|---|
Hospital A | -0.4672547 | +0.4627198 |
Hospital B | -0.4670225 | +0.4745283 |
Hospital C | -0.4648625 | +0.4721269 |
Hospital D | -0.4669489 | +0.4549763 |
Of course it would be very convenient to know the number of isolates responsible for the percentages. For that purpose the n_rsi()
can be used, which works exactly like n_distinct()
from the dplyr
package. It counts all isolates available for every group (i.e. values S, I or R):
data_1st %>%
- group_by(hospital) %>%
- summarise(amoxicillin = portion_R(AMX),
- available = n_rsi(AMX))
data_1st %>%
+ group_by(hospital) %>%
+ summarise(amoxicillin = portion_R(AMX),
+ available = n_rsi(AMX))
hospital | @@ -1023,32 +1022,32 @@ Longest: 24||||
---|---|---|---|---|
Hospital A | -0.4672547 | -4535 | +0.4627198 | +4493 |
Hospital B | -0.4670225 | -5246 | +0.4745283 | +5300 |
Hospital C | -0.4648625 | -2291 | +0.4721269 | +2332 |
Hospital D | -0.4669489 | -3071 | +0.4549763 | +2954 |
These functions can also be used to get the portion of multiple antibiotics, to calculate empiric susceptibility of combination therapies very easily:
-data_1st %>%
- group_by(genus) %>%
- summarise(amoxiclav = portion_SI(AMC),
- gentamicin = portion_SI(GEN),
- amoxiclav_genta = portion_SI(AMC, GEN))
data_1st %>%
+ group_by(genus) %>%
+ summarise(amoxiclav = portion_SI(AMC),
+ gentamicin = portion_SI(GEN),
+ amoxiclav_genta = portion_SI(AMC, GEN))
genus | @@ -1059,94 +1058,94 @@ Longest: 24||||||
---|---|---|---|---|---|---|
Escherichia | -0.9247870 | -0.8880458 | -0.9928115 | +0.9250202 | +0.8972051 | +0.9965063 |
Klebsiella | -0.8132569 | -0.8986616 | -0.9859783 | +0.8160556 | +0.8982301 | +0.9841972 |
Staphylococcus | -0.9138518 | -0.9185651 | -0.9934538 | +0.9217578 | +0.9161308 | +0.9930332 |
Streptococcus | -0.6290682 | +0.6147223 | 0.0000000 | -0.6290682 | +0.6147223 |
To make a transition to the next part, let’s see how this difference could be plotted:
-data_1st %>%
- group_by(genus) %>%
- summarise("1. Amoxi/clav" = portion_SI(AMC),
- "2. Gentamicin" = portion_SI(GEN),
- "3. Amoxi/clav + genta" = portion_SI(AMC, GEN)) %>%
- tidyr::gather("antibiotic", "S", -genus) %>%
- ggplot(aes(x = genus,
- y = S,
- fill = antibiotic)) +
- geom_col(position = "dodge2")
data_1st %>%
+ group_by(genus) %>%
+ summarise("1. Amoxi/clav" = portion_SI(AMC),
+ "2. Gentamicin" = portion_SI(GEN),
+ "3. Amoxi/clav + genta" = portion_SI(AMC, GEN)) %>%
+ tidyr::gather("antibiotic", "S", -genus) %>%
+ ggplot(aes(x = genus,
+ y = S,
+ fill = antibiotic)) +
+ geom_col(position = "dodge2")
To show results in plots, most R users would nowadays use the ggplot2
package. This package lets you create plots in layers. You can read more about it on their website. A quick example would look like these syntaxes:
ggplot(data = a_data_set,
- mapping = aes(x = year,
- y = value)) +
- geom_col() +
- labs(title = "A title",
- subtitle = "A subtitle",
- x = "My X axis",
- y = "My Y axis")
-
-# or as short as:
-ggplot(a_data_set) +
- geom_bar(aes(year))
ggplot(data = a_data_set,
+ mapping = aes(x = year,
+ y = value)) +
+ geom_col() +
+ labs(title = "A title",
+ subtitle = "A subtitle",
+ x = "My X axis",
+ y = "My Y axis")
+
+# or as short as:
+ggplot(a_data_set) +
+ geom_bar(aes(year))
The AMR
package contains functions to extend this ggplot2
package, for example geom_rsi()
. It automatically transforms data with count_df()
or portion_df()
and show results in stacked bars. Its simplest and shortest example:
Omit the translate_ab = FALSE
to have the antibiotic codes (AMX, AMC, CIP, GEN) translated to official WHO names (amoxicillin, amoxicillin/clavulanic acid, ciprofloxacin, gentamicin).
If we group on e.g. the genus
column and add some additional functions from our package, we can create this:
# group the data on `genus`
-ggplot(data_1st %>% group_by(genus)) +
- # create bars with genus on x axis
- # it looks for variables with class `rsi`,
- # of which we have 4 (earlier created with `as.rsi`)
- geom_rsi(x = "genus") +
- # split plots on antibiotic
- facet_rsi(facet = "antibiotic") +
- # make R red, I yellow and S green
- scale_rsi_colours() +
- # show percentages on y axis
- scale_y_percent(breaks = 0:4 * 25) +
- # turn 90 degrees, to make it bars instead of columns
- coord_flip() +
- # add labels
- labs(title = "Resistance per genus and antibiotic",
- subtitle = "(this is fake data)") +
- # and print genus in italic to follow our convention
- # (is now y axis because we turned the plot)
- theme(axis.text.y = element_text(face = "italic"))
# group the data on `genus`
+ggplot(data_1st %>% group_by(genus)) +
+ # create bars with genus on x axis
+ # it looks for variables with class `rsi`,
+ # of which we have 4 (earlier created with `as.rsi`)
+ geom_rsi(x = "genus") +
+ # split plots on antibiotic
+ facet_rsi(facet = "antibiotic") +
+ # make R red, I yellow and S green
+ scale_rsi_colours() +
+ # show percentages on y axis
+ scale_y_percent(breaks = 0:4 * 25) +
+ # turn 90 degrees, to make it bars instead of columns
+ coord_flip() +
+ # add labels
+ labs(title = "Resistance per genus and antibiotic",
+ subtitle = "(this is fake data)") +
+ # and print genus in italic to follow our convention
+ # (is now y axis because we turned the plot)
+ theme(axis.text.y = element_text(face = "italic"))
To simplify this, we also created the ggplot_rsi()
function, which combines almost all above functions:
The next example uses the included example_isolates
, which is an anonymised data set containing 2,000 microbial blood culture isolates with their full antibiograms found in septic patients in 4 different hospitals in the Netherlands, between 2001 and 2017. This data.frame
can be used to practice AMR analysis.
We will compare the resistance to fosfomycin (column FOS
) in hospital A and D. The input for the fisher.test()
can be retrieved with a transformation like this:
check_FOS <- example_isolates %>%
- filter(hospital_id %in% c("A", "D")) %>% # filter on only hospitals A and D
- select(hospital_id, FOS) %>% # select the hospitals and fosfomycin
- group_by(hospital_id) %>% # group on the hospitals
- count_df(combine_SI = TRUE) %>% # count all isolates per group (hospital_id)
- tidyr::spread(hospital_id, value) %>% # transform output so A and D are columns
- select(A, D) %>% # and select these only
- as.matrix() # transform to good old matrix for fisher.test()
-
-check_FOS
-# A D
-# [1,] 25 77
-# [2,] 24 33
check_FOS <- example_isolates %>%
+ filter(hospital_id %in% c("A", "D")) %>% # filter on only hospitals A and D
+ select(hospital_id, FOS) %>% # select the hospitals and fosfomycin
+ group_by(hospital_id) %>% # group on the hospitals
+ count_df(combine_SI = TRUE) %>% # count all isolates per group (hospital_id)
+ tidyr::spread(hospital_id, value) %>% # transform output so A and D are columns
+ select(A, D) %>% # and select these only
+ as.matrix() # transform to good old matrix for fisher.test()
+
+check_FOS
+# A D
+# [1,] 25 77
+# [2,] 24 33
We can apply the test now with:
-# do Fisher's Exact Test
-fisher.test(check_FOS)
-#
-# Fisher's Exact Test for Count Data
-#
-# data: check_FOS
-# p-value = 0.03104
-# alternative hypothesis: true odds ratio is not equal to 1
-# 95 percent confidence interval:
-# 0.2111489 0.9485124
-# sample estimates:
-# odds ratio
-# 0.4488318
# do Fisher's Exact Test
+fisher.test(check_FOS)
+#
+# Fisher's Exact Test for Count Data
+#
+# data: check_FOS
+# p-value = 0.03104
+# alternative hypothesis: true odds ratio is not equal to 1
+# 95 percent confidence interval:
+# 0.2111489 0.9485124
+# sample estimates:
+# odds ratio
+# 0.4488318
As can be seen, the p value is 0.031, which means that the fosfomycin resistances found in hospital A and D are really different.
EUCAST.Rmd
EUCAST expert rules are a tabulated collection of expert knowledge on intrinsic resistances, exceptional resistance phenotypes and interpretive rules that may be applied to antimicrobial susceptibility testing in order to reduce errors and make appropriate recommendations for reporting particular resistances.
In Europe, a lot of medical microbiological laboratories already apply these rules (Brown et al., 2015). Our package features their latest insights on intrinsic resistance and exceptional phenotypes (version 9.0, 2019). Moreover, the eucast_rules()
function we use for this purpose can also apply additional rules, like forcing
(more will be available soon)
-(will be available soon)
+These rules can be used to discard impossible bug-drug combinations in your data. For example, Klebsiella produces beta-lactamase that prevents ampicillin (or amoxicillin) from working against it. In other words, every strain of Klebsiella is resistant to ampicillin.
+Sometimes, laboratory data can still contain such strains with ampicillin being susceptible to ampicillin. This could be because an antibiogram is available before an identification is available, and the antibiogram is then not re-interpreted based on the identification (namely, Klebsiella). EUCAST expert rules solves this:
+MDR.Rmd
With the function mdro()
, you can determine multi-drug resistant organisms (MDRO). It currently support these guidelines:
With the function mdro()
, you can determine multi-drug resistant organisms (MDRO).
The mdro()
takes a data set as input, such as a regular data.frame
. It automatically determines the right columns for info about your isolates, like the name of the species and all columns with results of antimicrobial agents. See the help page for more info about how to set the right settings for your data with the command ?mdro
.
For WHONET data (and most other data), all settings are automatically set correctly.
+The function support multiple guidelines. You can select a guideline with the guideline
parameter. Currently supported guidelines are (case-insensitive):
guideline = "CMI2012"
(default)
guideline = "EUCAST"
guideline = "TB"
guideline = "MRGN"
guideline = "BRMO"
The Dutch national guideline - Rijksinstituut voor Volksgezondheid en Milieu “WIP-richtlijn BRMO (Bijzonder Resistente Micro-Organismen) [ZKH]” (link)
+As an example, I will make a data set to determine multi-drug resistant TB:
-# a helper function to get a random vector with values S, I and R
-# with the probabilities 50% - 10% - 40%
-sample_rsi <- function() {
- sample(c("S", "I", "R"),
- size = 5000,
- prob = c(0.5, 0.1, 0.4),
- replace = TRUE)
-}
-
-my_TB_data <- data.frame(rifampicin = sample_rsi(),
- isoniazid = sample_rsi(),
- gatifloxacin = sample_rsi(),
- ethambutol = sample_rsi(),
- pyrazinamide = sample_rsi(),
- moxifloxacin = sample_rsi(),
- kanamycin = sample_rsi())
The mdro()
function always returns an ordered factor
. For example, the output of the default guideline by Magiorakos et al. returns a factor
with levels ‘Negative’, ‘MDR’, ‘XDR’ or ‘PDR’ in that order. If we test that guideline on the included example_isolates
data set, we get:
example_isolates %>%
+ mdro() %>%
+ freq() # show frequency table of the result
+# NOTE: Using column `mo` as input for `col_mo`.
+# NOTE: Auto-guessing columns suitable for analysis...OK.
+# NOTE: Reliability will be improved if these antimicrobial results would be available too: SAM (ampicillin/sulbactam), ATM (aztreonam), CTT (cefotetan), CPT (ceftaroline), DAP (daptomycin), DOR (doripenem), ETP (ertapenem), FUS (fusidic acid), GEH (gentamicin-high), LVX (levofloxacin), MNO (minocycline), NET (netilmicin), PLB (polymyxin B), QDA (quinupristin/dalfopristin), STH (streptomycin-high), TLV (telavancin), TCC (ticarcillin/clavulanic acid)
+# Table 1 - S. aureus ... OK
+# Table 2 - Enterococcus spp. ... OK
+# Table 3 - Enterobacteriaceae ... OK
+# Table 4 - Pseudomonas aeruginosa ... OK
+# Table 5 - Acinetobacter spp. ... OK
+# Warning in mdro(.): NA introduced for isolates where the available
+# percentage of antimicrobial classes was below 50% (set with
+# `pct_required_classes`)
Frequency table
+Class: factor > ordered (numeric)
+Length: 2,000 (of which NA: 289 = 14.45%)
+Levels: 4: Negative < Multi-drug-resistant (MDR) < Extensively drug-resistant …
+Unique: 2
+ | Item | +Count | +Percent | +Cum. Count | +Cum. Percent | +
---|---|---|---|---|---|
1 | +Negative | +1596 | +93.28% | +1596 | +93.28% | +
2 | +Multi-drug-resistant (MDR) | +115 | +6.72% | +1711 | +100.00% | +
For another example, I will create a data set to determine multi-drug resistant TB:
+# a helper function to get a random vector with values S, I and R
+# with the probabilities 50% - 10% - 40%
+sample_rsi <- function() {
+ sample(c("S", "I", "R"),
+ size = 5000,
+ prob = c(0.5, 0.1, 0.4),
+ replace = TRUE)
+}
+
+my_TB_data <- data.frame(rifampicin = sample_rsi(),
+ isoniazid = sample_rsi(),
+ gatifloxacin = sample_rsi(),
+ ethambutol = sample_rsi(),
+ pyrazinamide = sample_rsi(),
+ moxifloxacin = sample_rsi(),
+ kanamycin = sample_rsi())
Because all column names are automatically verified for valid drug names or codes, this would have worked exactly the same:
-my_TB_data <- data.frame(RIF = sample_rsi(),
- INH = sample_rsi(),
- GAT = sample_rsi(),
- ETH = sample_rsi(),
- PZA = sample_rsi(),
- MFX = sample_rsi(),
- KAN = sample_rsi())
The data set looks like this now:
-head(my_TB_data)
-# rifampicin isoniazid gatifloxacin ethambutol pyrazinamide moxifloxacin
-# 1 S S R S R S
-# 2 S R R S S R
-# 3 R R S S R S
-# 4 R R R S S S
-# 5 R R R R R R
-# 6 R R R I S R
-# kanamycin
-# 1 I
-# 2 S
-# 3 R
-# 4 S
-# 5 R
-# 6 S
We can now add the interpretation of MDR-TB to our data set:
-my_TB_data$mdr <- mdr_tb(my_TB_data)
-# NOTE: No column found as input for `col_mo`, assuming all records contain Mycobacterium tuberculosis.
-# Determining multidrug-resistant organisms (MDRO), according to:
-# Guideline: Companion handbook to the WHO guidelines for the programmatic management of drug-resistant tuberculosis
-# Version: WHO/HTM/TB/2014.11
-# Author: WHO (World Health Organization)
-# Source: https://www.who.int/tb/publications/pmdt_companionhandbook/en/
-# NOTE: Auto-guessing columns suitable for analysis...
-# NOTE: Reliability might be improved if these antimicrobial results would be available too: CAP (capreomycin), RIB (rifabutin), RFP (rifapentine)
We also created a package dedicated to data cleaning and checking, called the clean
package. It gets automatically installed with the AMR
package, so we only have to load it:
It contains the freq()
function, to create a frequency table:
my_TB_data <- data.frame(RIF = sample_rsi(),
+ INH = sample_rsi(),
+ GAT = sample_rsi(),
+ ETH = sample_rsi(),
+ PZA = sample_rsi(),
+ MFX = sample_rsi(),
+ KAN = sample_rsi())
The data set now looks like this:
+head(my_TB_data)
+# rifampicin isoniazid gatifloxacin ethambutol pyrazinamide moxifloxacin
+# 1 S S R R S R
+# 2 S R S S R S
+# 3 R S R S R R
+# 4 S S R S S I
+# 5 R R S R S S
+# 6 S S R R R S
+# kanamycin
+# 1 S
+# 2 S
+# 3 R
+# 4 R
+# 5 S
+# 6 R
We can now add the interpretation of MDR-TB to our data set. You can use:
+ +or its shortcut mdr_tb()
:
my_TB_data$mdr <- mdr_tb(my_TB_data)
+# NOTE: No column found as input for `col_mo`, assuming all records contain Mycobacterium tuberculosis.
+# NOTE: Auto-guessing columns suitable for analysis...OK.
+# NOTE: Reliability will be improved if these antimicrobial results would be available too: CAP (capreomycin), RIB (rifabutin), RFP (rifapentine)
+#
+# Only results with 'R' are considered as resistance. Use `combine_SI = FALSE` to also consider 'I' as resistance.
+#
+# Determining multidrug-resistant organisms (MDRO), according to:
+# Guideline: Companion handbook to the WHO guidelines for the programmatic management of drug-resistant tuberculosis
+# Version: WHO/HTM/TB/2014.11
+# Author: WHO (World Health Organization)
+# Source: https://www.who.int/tb/publications/pmdt_companionhandbook/en/
+#
+# => Found 4371 MDROs out of 5000 tested isolates (87.4%)
Create a frequency table of the results:
+Frequency table
Class: factor > ordered (numeric)
Length: 5,000 (of which NA: 0 = 0%)
@@ -275,46 +356,47 @@ Unique: 5
WHONET.Rmd
This tutorial assumes you already imported the WHONET data with e.g. the readxl
package. In RStudio, this can be done using the menu button ‘Import Dataset’ in the tab ‘Environment’. Choose the option ‘From Excel’ and select your exported file. Make sure date fields are imported correctly.
An example syntax could look like this:
This package comes with an example data set WHONET
. We will use it for this analysis.
First, load the relevant packages if you did not yet did this. I use 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
library(ggplot2) # part of tidyverse
@@ -224,18 +224,16 @@
# transform everything from "AMP_ND10" to "CIP_EE" to the new `rsi` class
mutate_at(vars(AMP_ND10:CIP_EE), as.rsi)
No errors or warnings, so all values are transformed succesfully.
-We created a package dedicated to data cleaning and checking, called the clean
package. It gets automatically installed with the AMR
package, so we only have to load it:
It contains the freq()
function, to create frequency tables.
We also created a package dedicated to data cleaning and checking, called the cleaner
package. It gets automatically installed with the AMR
package. For its freq()
function to create frequency tables, you don’t even need to load it yourself as it is available through the AMR
package as well.
So let’s check our data, with a couple of frequency tables:
- +Frequency table
Class: mo (character)
Length: 500 (of which NA: 0 = 0%)
Unique: 39
Gram-negative: 281 (56.20%)
-Gram-positive: 219 (43.80%)
+
Gram-negative: 280 (56.00%)
+Gram-positive: 220 (44.00%)
Nr of genera: 17
Nr of species: 39
(omitted 29 entries, n = 57 [11.40%])
-
-# our transformed antibiotic columns
-# amoxicillin/clavulanic acid (J01CR02) as an example
-data %>% freq(AMC_ND2)
+# our transformed antibiotic columns
+# amoxicillin/clavulanic acid (J01CR02) as an example
+data %>% freq(AMC_ND2)
Frequency table
Class: factor > ordered > rsi (numeric)
Length: 500 (of which NA: 19 = 3.8%)
@@ -378,24 +376,17 @@ Unique: 3
(more will be available soon)
+An easy ggplot will already give a lot of information, using the included ggplot_rsi()
function:
(
18 October 2019
+A methods paper about this package has been preprinted at bioRxiv. It was updated on 8 November 2019. Please click here for the publishers page.
METHODS PAPER PREPRINTED
-A methods paper about this package has been preprinted at bioRxiv. Please see here for the publishers page or click here for the PDF.
Last updated: 06-Nov-2019
+Last updated: 09-Nov-2019
as.mo(..., allow_uncertain = 3)
Contents