diff --git a/DESCRIPTION b/DESCRIPTION index c438c08b..a56411ca 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: AMR Version: 0.5.0.9016 -Date: 2019-02-01 +Date: 2019-02-04 Title: Antimicrobial Resistance Analysis Authors@R: c( person( diff --git a/NAMESPACE b/NAMESPACE index 50cf58d0..0965661a 100755 --- a/NAMESPACE +++ b/NAMESPACE @@ -66,6 +66,7 @@ export(atc_property) export(atc_tradenames) export(atc_trivial_nl) export(atc_umcg) +export(availability) export(brmo) export(count_I) export(count_IR) diff --git a/NEWS.md b/NEWS.md index c04ebab5..8f2e9770 100755 --- a/NEWS.md +++ b/NEWS.md @@ -77,7 +77,7 @@ * A note to the manual pages of the `portion` functions, that low counts can influence the outcome and that the `portion` functions may camouflage this, since they only return the portion (albeit being dependent on the `minimum` parameter) * Merged data sets `microorganisms.certe` and `microorganisms.umcg` into `microorganisms.codes` * Function `mo_taxonomy()` now contains the kingdom too -* Reduce false positives for `is.rsi.eligible()` +* Reduce false positives for `is.rsi.eligible()` using the new `threshold` parameter * New colours for `scale_rsi_colours()` * Summaries of class `mo` will now return the top 3 and the unique count, e.g. using `summary(mo)` * Small text updates to summaries of class `rsi` and `mic` diff --git a/R/availability.R b/R/availability.R new file mode 100644 index 00000000..a120430d --- /dev/null +++ b/R/availability.R @@ -0,0 +1,61 @@ +# ==================================================================== # +# TITLE # +# Antimicrobial Resistance (AMR) Analysis # +# # +# SOURCE # +# https://gitlab.com/msberends/AMR # +# # +# LICENCE # +# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) # +# # +# This R package is free software; you can freely use and distribute # +# it for both personal and commercial purposes under the terms of the # +# GNU General Public License version 2.0 (GNU GPL-2), as published by # +# the Free Software Foundation. # +# # +# This R package was created for academic research and was publicly # +# released in the hope that it will be useful, but it comes WITHOUT # +# ANY WARRANTY OR LIABILITY. # +# Visit our website for more info: https://msberends.gitab.io/AMR. # +# ==================================================================== # + +#' Check availability of columns +#' +#' Easy check for availability of columns in a data set. This makes it easy to get an idea of which antibiotic combination can be used for calculation with e.g. \code{\link{portion_IR}}. +#' @param tbl a \code{data.frame} or \code{list} +#' @return \code{data.frame} with column names of \code{tbl} as row names and columns: \code{percent_IR}, \code{count}, \code{percent}, \code{visual_availability}. +#' @export +#' @examples +#' availability(septic_patients) +#' +#' library(dplyr) +#' septic_patients %>% availability() +#' +#' septic_patients %>% +#' select_if(is.rsi) %>% +#' availability() +#' +#' septic_patients %>% +#' filter(mo == as.mo("E. coli")) %>% +#' select_if(is.rsi) %>% +#' availability() +availability <- function(tbl) { + x <- base::sapply(tbl, function(x) { 1 - base::sum(base::is.na(x)) / base::length(x) }) + n <- base::sapply(tbl, function(x) base::length(x[!base::is.na(x)])) + IR <- base::sapply(tbl, function(x) base::ifelse(is.rsi(x), base::round(portion_IR(x, minimum = 0) * 100, 1), "NaN")) + IR <- paste0(IR, "%") + IR <- gsub("NaN%", "", IR) + max_chars <- 50 + x_chars <- strrep("#", round(x, digits = 2) / (1 / max_chars)) + x_chars_empty <- strrep("-", max_chars - nchar(x_chars)) + # x_abnames <- character(length(x)) + # for (i in 1:length(x)) { + # if (tbl %>% pull(i) %>% is.rsi()) { + # x_abnames[i] <- atc_name(colnames(tbl)[i]) + # } + # } + data.frame(percent_IR = IR, + count = n, + percent = paste0(round(x * 100, 1), "%"), + visual_availabilty = paste0("|", x_chars, x_chars_empty, "|")) +} diff --git a/R/data.R b/R/data.R index 673d381f..53150089 100755 --- a/R/data.R +++ b/R/data.R @@ -211,7 +211,7 @@ #' \describe{ #' \item{\code{Identification number}}{ID of the sample} #' \item{\code{Specimen number}}{ID of the specimen} -#' \item{\code{Organism}}{Microorganisms, can be coerced with \code{\link{as.mo}}} +#' \item{\code{Organism}}{Name of the microorganism. Before analysis, you should transform this to a valid microbial class, using \code{\link{as.mo}}.} #' \item{\code{Country}}{Country of origin} #' \item{\code{Laboratory}}{Name of laboratory} #' \item{\code{Last name}}{Last name of patient} @@ -234,7 +234,7 @@ #' \item{\code{Inducible clindamycin resistance}}{Clindamycin can be induced?} #' \item{\code{Comment}}{Other comments} #' \item{\code{Date of data entry}}{Date this data was entered in WHONET} -#' \item{\code{AMP_ND10:CIP_EE}}{27 different antibiotics. You can lookup the abbreviatons in the \code{\link{antibiotics}} data set, or use e.g. \code{\link{atc_name}("AMP")} to get the official name immediately.} +#' \item{\code{AMP_ND10:CIP_EE}}{27 different antibiotics. You can lookup the abbreviatons in the \code{\link{antibiotics}} data set, or use e.g. \code{\link{atc_name}("AMP")} to get the official name immediately. Before analysis, you should transform this to a valid antibiotic class, using \code{\link{as.rsi}}.} #' } #' @inheritSection AMR Read more on our website! "WHONET" diff --git a/R/first_isolate.R b/R/first_isolate.R index 46e16bd5..7e9faa5e 100755 --- a/R/first_isolate.R +++ b/R/first_isolate.R @@ -381,7 +381,7 @@ first_isolate <- function(tbl, if (abs(row.start) == Inf | abs(row.end) == Inf) { if (info == TRUE) { - message('No isolates found.') + message(paste("=> Found", bold("no isolates"))) } # NAs where genus is unavailable return(tbl %>% diff --git a/R/rsi.R b/R/rsi.R index 4d93bf02..e3e7b0f0 100755 --- a/R/rsi.R +++ b/R/rsi.R @@ -24,6 +24,7 @@ #' This transforms a vector to a new class \code{rsi}, which is an ordered factor with levels \code{S < I < R}. Invalid antimicrobial interpretations will be translated as \code{NA} with a warning. #' @rdname as.rsi #' @param x vector +#' @param threshold maximum fraction of \code{x} that is allowed to fail transformation, see Examples #' @details The function \code{is.rsi.eligible} returns \code{TRUE} when a columns contains only valid antimicrobial interpretations (S and/or I and/or R), and \code{FALSE} otherwise. #' @return Ordered factor with new class \code{rsi} #' @keywords rsi @@ -48,10 +49,15 @@ #' septic_patients %>% #' mutate_at(vars(peni:rifa), as.rsi) #' +#' #' # fastest way to transform all columns with already valid AB results to class `rsi`: #' septic_patients %>% #' mutate_if(is.rsi.eligible, #' as.rsi) +#' +#' # default threshold of `is.rsi.eligible` is 5%. +#' is.rsi.eligible(WHONET$`First name`) # fails, >80% is invalid +#' is.rsi.eligible(WHONET$`First name`, threhold = 0.9) # succeeds as.rsi <- function(x) { if (is.rsi(x)) { x @@ -99,28 +105,37 @@ as.rsi <- function(x) { #' @rdname as.rsi #' @export -#' @importFrom dplyr %>% is.rsi <- function(x) { - class(x) %>% identical(c('rsi', 'ordered', 'factor')) + identical(class(x), + c('rsi', 'ordered', 'factor')) } #' @rdname as.rsi #' @export -#' @importFrom dplyr %>% -is.rsi.eligible <- function(x) { - if (is.logical(x) - | is.numeric(x) - | is.mo(x) - | identical(class(x), "Date") - | is.rsi(x)) { +is.rsi.eligible <- function(x, threshold = 0.05) { + if (NCOL(x) > 1) { + stop('`x` must be a one-dimensional vector.') + } + if (any(c("logical", + "numeric", + "integer", + "mo", + "Date", + "POSIXct", + "rsi", + "raw", + "hms") + %in% class(x))) { # no transformation needed FALSE } else { - # check all but a-z - y <- unique(gsub("[^RSIrsi]+", "", unique(x))) - !all(y %in% c("", NA_character_)) & - all(y %in% c("R", "I", "S", "", NA_character_)) & - max(nchar(as.character(x)), na.rm = TRUE) < 8 + x <- x[!is.na(x) & !is.null(x) & !identical(x, "")] + if (length(x) == 0) { + return(FALSE) + } + checked <- suppressWarnings(as.rsi(x)) + outcome <- sum(is.na(checked)) / length(x) + outcome <= threshold } } diff --git a/data/WHONET.rda b/data/WHONET.rda index 4c642251..0a777481 100644 Binary files a/data/WHONET.rda and b/data/WHONET.rda differ diff --git a/docs/articles/AMR.html b/docs/articles/AMR.html index 9854b148..ee872f5a 100644 --- a/docs/articles/AMR.html +++ b/docs/articles/AMR.html @@ -185,7 +185,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 RMarkdown. However, the methodology remains unchanged. This page was generated on 01 February 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 RMarkdown. However, the methodology remains unchanged. This page was generated on 04 February 2019.
As with many uses in R, we need some additional packages for AMR analysis. Our package works closely together with the tidyverse packages dplyr
and ggplot2
by Dr Hadley Wickham. The tidyverse tremendously improves the way we conduct data science - it allows for a very natural way of writing syntaxes and creating beautiful plots in R.
Our AMR
package depends on these packages and even extends their use and functions.
library(dplyr)
-library(ggplot2)
-library(AMR)
-
-# (if not yet installed, install with:)
-# install.packages(c("tidyverse", "AMR"))
library(dplyr)
+library(ggplot2)
+library(AMR)
+
+# (if not yet installed, install with:)
+# install.packages(c("tidyverse", "AMR"))
To start with patients, we need a unique list of patients.
- +The LETTERS
object is available in R - it’s a vector with 26 characters: A
to Z
. The patients
object we just created is now a vector of length 260, with values (patient IDs) varying from A1
to Z10
. Now we we also set the gender of our patients, by putting the ID and the gender in a table:
patients_table <- data.frame(patient_id = patients,
- gender = c(rep("M", 135),
- rep("F", 125)))
The first 135 patient IDs are now male, the other 125 are female.
Let’s pretend that our data consists of blood cultures isolates from 1 January 2010 until 1 January 2018.
- +This dates
object now contains all days in our date range.
For this tutorial, we will uses four different microorganisms: Escherichia coli, Staphylococcus aureus, Streptococcus pneumoniae, and Klebsiella pneumoniae:
-bacteria <- c("Escherichia coli", "Staphylococcus aureus",
- "Streptococcus pneumoniae", "Klebsiella pneumoniae")
For completeness, we can also add the hospital where the patients was admitted and we need to define valid antibmicrobial results for our randomisation:
- +Using the sample()
function, we can randomly select items from all objects we defined earlier. To let our fake data reflect reality a bit, we will also approximately define the probabilities of bacteria and the antibiotic results with the prob
parameter.
data <- data.frame(date = sample(dates, 5000, replace = TRUE),
- patient_id = sample(patients, 5000, replace = TRUE),
- hospital = sample(hospitals, 5000, replace = TRUE, prob = c(0.30, 0.35, 0.15, 0.20)),
- bacteria = sample(bacteria, 5000, replace = TRUE, prob = c(0.50, 0.25, 0.15, 0.10)),
- amox = sample(ab_interpretations, 5000, replace = TRUE, prob = c(0.60, 0.05, 0.35)),
- amcl = sample(ab_interpretations, 5000, replace = TRUE, prob = c(0.75, 0.10, 0.15)),
- cipr = sample(ab_interpretations, 5000, replace = TRUE, prob = c(0.80, 0.00, 0.20)),
- gent = sample(ab_interpretations, 5000, replace = TRUE, prob = c(0.92, 0.00, 0.08))
- )
data <- data.frame(date = sample(dates, 5000, replace = TRUE),
+ patient_id = sample(patients, 5000, replace = TRUE),
+ hospital = sample(hospitals, 5000, replace = TRUE, prob = c(0.30, 0.35, 0.15, 0.20)),
+ bacteria = sample(bacteria, 5000, replace = TRUE, prob = c(0.50, 0.25, 0.15, 0.10)),
+ amox = sample(ab_interpretations, 5000, replace = TRUE, prob = c(0.60, 0.05, 0.35)),
+ amcl = sample(ab_interpretations, 5000, replace = TRUE, prob = c(0.75, 0.10, 0.15)),
+ cipr = sample(ab_interpretations, 5000, replace = TRUE, prob = c(0.80, 0.00, 0.20)),
+ gent = sample(ab_interpretations, 5000, replace = TRUE, prob = c(0.92, 0.00, 0.08))
+ )
Using the left_join()
function from the dplyr
package, we can ‘map’ the gender to the patient ID using the patients_table
object we created earlier:
data <- data %>% left_join(patients_table)
The resulting data set contains 5,000 blood culture isolates. With the head()
function we can preview the first 6 values of this data set:
head(data)
date | @@ -313,70 +313,70 @@ ab_interpretations <- -2014-06-07 | -Y9 | -Hospital A | -Klebsiella pneumoniae | -S | -S | -S | -S | -F | -|||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
2010-06-10 | -Z1 | -Hospital B | -Escherichia coli | -R | -S | -S | -S | -F | -||||||
2012-03-20 | -J6 | +2010-05-26 | +E8 | Hospital C | -Streptococcus pneumoniae | +Escherichia coli | +R | S | +R | +S | +M | +|||
2016-11-27 | +D6 | +Hospital B | +Streptococcus pneumoniae | +R | +S | +S | +S | +M | +||||||
2015-03-24 | +J2 | +Hospital A | +Escherichia coli | +R | S | S | S | M | ||||||
2016-10-31 | -M5 | +2014-09-12 | +Y4 | Hospital A | -Escherichia coli | -S | -R | +Staphylococcus aureus | S | S | -M | +S | +S | +F |
2016-05-05 | -W8 | +2015-05-27 | +M8 | Hospital B | Escherichia coli | R | S | S | S | -F | +M | |||
2016-03-10 | -G8 | -Hospital A | -Streptococcus pneumoniae | +2017-10-14 | +R8 | +Hospital C | +Staphylococcus aureus | S | S | S | S | -M | +F |
Use the frequency table function freq()
to look specifically for unique values in any variable. For example, for the gender
variable:
data %>% freq(gender) # this would be the same: freq(data$gender)
# Frequency table of `gender` from a `data.frame` (5,000 x 9) # Class: factor (numeric) # Levels: F, M @@ -396,67 +396,67 @@ ab_interpretations <- mutate()
function of thedplyr
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. Themutate_at()
will run theas.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 forcingampicillin = R whenamoxicillin/clavulanic acid = R.Because the amoxicillin (column
-amox
) and amoxicillin/clavulanic acid (columnamcl
) in our data were generated randomly, some rows will undoubtedly contain amox = S and amcl = R, which is technically impossible. Theeucast_rules()
fixes this:+data <- eucast_rules(data, col_mo = "bacteria") -# -# Rules by the European Committee on Antimicrobial Susceptibility Testing (EUCAST) -# -# EUCAST Clinical Breakpoints (v9.0, 2019) -# Enterobacteriales (Order) (no changes) -# Staphylococcus (no changes) -# Enterococcus (no changes) -# Streptococcus groups A, B, C, G (no changes) -# Streptococcus pneumoniae (no changes) -# Viridans group streptococci (no changes) -# Haemophilus influenzae (no changes) -# Moraxella catarrhalis (no changes) -# Anaerobic Gram positives (no changes) -# Anaerobic Gram negatives (no changes) -# Pasteurella multocida (no changes) -# Campylobacter jejuni and C. coli (no changes) -# Aerococcus sanguinicola and A. urinae (no changes) -# Kingella kingae (no changes) -# -# EUCAST Expert Rules, Intrinsic Resistance and Exceptional Phenotypes (v3.1, 2016) -# Table 1: Intrinsic resistance in Enterobacteriaceae (340 changes) -# Table 2: Intrinsic resistance in non-fermentative Gram-negative bacteria (no changes) -# Table 3: Intrinsic resistance in other Gram-negative bacteria (no changes) -# Table 4: Intrinsic resistance in Gram-positive bacteria (681 changes) -# Table 8: Interpretive rules for B-lactam agents and Gram-positive cocci (no changes) -# Table 9: Interpretive rules for B-lactam agents and Gram-negative rods (no changes) -# Table 10: Interpretive rules for B-lactam agents and other Gram-negative bacteria (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: ampicillin = R where amoxicillin/clav acid = R (no changes) -# Non-EUCAST: piperacillin = R where piperacillin/tazobactam = R (no changes) -# Non-EUCAST: trimethoprim = R where trimethoprim/sulfa = R (no changes) -# Non-EUCAST: amoxicillin/clav acid = S where ampicillin = S (no changes) -# Non-EUCAST: piperacillin/tazobactam = S where piperacillin = S (no changes) -# Non-EUCAST: trimethoprim/sulfa = S where trimethoprim = S (no changes) -# -# => EUCAST rules affected 1,858 out of 5,000 rows -> changed 1,021 test results.
data <- eucast_rules(data, col_mo = "bacteria") +# +# Rules by the European Committee on Antimicrobial Susceptibility Testing (EUCAST) +# +# EUCAST Clinical Breakpoints (v9.0, 2019) +# Enterobacteriales (Order) (no changes) +# Staphylococcus (no changes) +# Enterococcus (no changes) +# Streptococcus groups A, B, C, G (no changes) +# Streptococcus pneumoniae (no changes) +# Viridans group streptococci (no changes) +# Haemophilus influenzae (no changes) +# Moraxella catarrhalis (no changes) +# Anaerobic Gram positives (no changes) +# Anaerobic Gram negatives (no changes) +# Pasteurella multocida (no changes) +# Campylobacter jejuni and C. coli (no changes) +# Aerococcus sanguinicola and A. urinae (no changes) +# Kingella kingae (no changes) +# +# EUCAST Expert Rules, Intrinsic Resistance and Exceptional Phenotypes (v3.1, 2016) +# Table 1: Intrinsic resistance in Enterobacteriaceae (348 changes) +# Table 2: Intrinsic resistance in non-fermentative Gram-negative bacteria (no changes) +# Table 3: Intrinsic resistance in other Gram-negative bacteria (no changes) +# Table 4: Intrinsic resistance in Gram-positive bacteria (702 changes) +# Table 8: Interpretive rules for B-lactam agents and Gram-positive cocci (no changes) +# Table 9: Interpretive rules for B-lactam agents and Gram-negative rods (no changes) +# Table 10: Interpretive rules for B-lactam agents and other Gram-negative bacteria (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: ampicillin = R where amoxicillin/clav acid = R (no changes) +# Non-EUCAST: piperacillin = R where piperacillin/tazobactam = R (no changes) +# Non-EUCAST: trimethoprim = R where trimethoprim/sulfa = R (no changes) +# Non-EUCAST: amoxicillin/clav acid = S where ampicillin = S (no changes) +# Non-EUCAST: piperacillin/tazobactam = S where piperacillin = S (no changes) +# Non-EUCAST: trimethoprim/sulfa = S where trimethoprim = S (no changes) +# +# => EUCAST rules affected 1,820 out of 5,000 rows -> changed 1,050 test results.
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))
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 2,956 first isolates (59.1% of total)
So only 59.1% is suitable for resistance analysis! We can now filter on it with the filter()
function, also from the dplyr
package:
data_1st <- data %>%
- filter(first == TRUE)
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 2,951 first isolates (59.0% of total)
So only 59% 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:
data_1st <- data %>%
- filter_first_isolate()
Only 3 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 4,383 first weighted isolates (87.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 4,424 first weighted isolates (88.5% of total)
Instead of 3, now 9 isolates are flagged. In total, 87.7% of all isolates are marked ‘first weighted’ - 28.5% 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 3, now 9 isolates are flagged. In total, 88.5% of all isolates are marked ‘first weighted’ - 29.5% 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:
data_1st <- data %>%
- filter_first_weighted_isolate()
So we end up with 4,383 isolates for analysis.
+ +So we end up with 4,424 isolates for analysis.
We can remove unneeded columns:
- +Now our data looks like:
-head(data_1st)
date | @@ -785,41 +785,26 @@ ab_interpretations <- -2014-06-07 | -Y9 | -Hospital A | -B_KLBSL_PNE | -R | -S | -S | -S | -F | -Gram negative | -Klebsiella | -pneumoniae | -TRUE | -|||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
2010-06-10 | -Z1 | -Hospital B | -B_ESCHR_COL | -R | -S | -S | -S | -F | -Gram negative | -Escherichia | -coli | -TRUE | -||||||||
2012-03-20 | -J6 | +2010-05-26 | +E8 | Hospital C | -B_STRPTC_PNE | +B_ESCHR_COL | +R | S | +R | +S | +M | +Gram negative | +Escherichia | +coli | +TRUE | +|||||
2016-11-27 | +D6 | +Hospital B | +B_STRPTC_PNE | +R | S | S | R | @@ -829,49 +814,64 @@ ab_interpretations <- pneumoniaeTRUE | ||||||||||||
2016-10-31 | -M5 | +|||||||||||||||||||
2015-03-24 | +J2 | Hospital A | B_ESCHR_COL | -S | R | S | S | +S | M | Gram negative | Escherichia | coli | TRUE | |||||||
2014-09-12 | +Y4 | +Hospital A | +B_STPHY_AUR | +S | +S | +S | +S | +F | +Gram positive | +Staphylococcus | +aureus | +TRUE | +||||||||
2016-05-05 | -W8 | +2015-05-27 | +M8 | Hospital B | B_ESCHR_COL | R | S | S | S | -F | +M | Gram negative | Escherichia | coli | TRUE | |||||
2016-03-10 | -G8 | -Hospital A | -B_STRPTC_PNE | +2017-10-14 | +R8 | +Hospital C | +B_STPHY_AUR | S | S | S | -R | -M | +S | +F | Gram positive | -Streptococcus | -pneumoniae | +Staphylococcus | +aureus | TRUE |
1 | Escherichia coli | -2,128 | -48.6% | -2,128 | -48.6% | +2,141 | +48.4% | +2,141 | +48.4% | |||||||||||
2 | Staphylococcus aureus | -1,110 | -25.3% | -3,238 | -73.9% | +1,126 | +25.5% | +3,267 | +73.8% | |||||||||||
3 | Streptococcus pneumoniae | -684 | -15.6% | -3,922 | -89.5% | +699 | +15.8% | +3,966 | +89.6% | |||||||||||
4 | Klebsiella pneumoniae | -461 | -10.5% | -4,383 | +458 | +10.4% | +4,424 | 100.0% |
hospital | @@ -960,27 +960,27 @@ Longest: 24||
---|---|---|
Hospital A | -0.4959169 | +0.4566642 |
Hospital B | -0.4690956 | +0.4615894 |
Hospital C | -0.5075529 | +0.4807122 |
Hospital D | -0.4695341 | +0.4579008 |
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_IR(amox),
- available = n_rsi(amox))
data_1st %>%
+ group_by(hospital) %>%
+ summarise(amoxicillin = portion_IR(amox),
+ available = n_rsi(amox))
hospital | @@ -990,32 +990,32 @@ Longest: 24||||
---|---|---|---|---|
Hospital A | -0.4959169 | -1347 | +0.4566642 | +1373 |
Hospital B | -0.4690956 | -1537 | +0.4615894 | +1510 |
Hospital C | -0.5075529 | -662 | +0.4807122 | +674 |
Hospital D | -0.4695341 | -837 | +0.4579008 | +867 |
These functions can also be used to get the portion of multiple antibiotics, to calculate co-resistance very easily:
-data_1st %>%
- group_by(genus) %>%
- summarise(amoxicillin = portion_S(amcl),
- gentamicin = portion_S(gent),
- "amox + gent" = portion_S(amcl, gent))
data_1st %>%
+ group_by(genus) %>%
+ summarise(amoxicillin = portion_S(amcl),
+ gentamicin = portion_S(gent),
+ "amox + gent" = portion_S(amcl, gent))
genus | @@ -1026,94 +1026,94 @@ Longest: 24||||||
---|---|---|---|---|---|---|
Escherichia | -0.7481203 | -0.9163534 | -0.9765038 | +0.7356376 | +0.9033162 | +0.9729099 |
Klebsiella | -0.7722343 | -0.9240781 | -0.9913232 | +0.7445415 | +0.8930131 | +0.9694323 |
Staphylococcus | -0.7567568 | -0.9234234 | -0.9864865 | +0.7566607 | +0.9174067 | +0.9760213 |
Streptococcus | -0.7383041 | +0.7668097 | 0.0000000 | -0.7383041 | +0.7668097 |
To make a transition to the next part, let’s see how this difference could be plotted:
-data_1st %>%
- group_by(genus) %>%
- summarise("1. Amoxicillin" = portion_S(amcl),
- "2. Gentamicin" = portion_S(gent),
- "3. Amox + gent" = portion_S(amcl, gent)) %>%
- tidyr::gather("Antibiotic", "S", -genus) %>%
- ggplot(aes(x = genus,
- y = S,
- fill = Antibiotic)) +
- geom_col(position = "dodge2")
data_1st %>%
+ group_by(genus) %>%
+ summarise("1. Amoxicillin" = portion_S(amcl),
+ "2. Gentamicin" = portion_S(gent),
+ "3. Amox + gent" = portion_S(amcl, gent)) %>%
+ 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")
-
-ggplot(a_data_set,
- aes(year, value) +
- geom_bar()
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")
+
+ggplot(a_data_set,
+ aes(year, value) +
+ geom_bar()
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 (amox, amcl, cipr, gent) translated to official WHO names (amoxicillin, amoxicillin and betalactamase inhibitor, 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, 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, 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:
data_1st %>%
- group_by(genus) %>%
- ggplot_rsi(x = "genus",
- facet = "Antibiotic",
- breaks = 0:4 * 25,
- datalabels = FALSE) +
- coord_flip()
We can transform the data and apply the test in only a couple of lines:
-septic_patients %>%
- filter(hospital_id %in% c("A", "D")) %>% # filter on only hospitals A and D
- select(hospital_id, fosf) %>% # select the hospitals and fosfomycin
- group_by(hospital_id) %>% # group on the hospitals
- count_df(combine_IR = 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()
- fisher.test() # do Fisher's Exact Test
-#
-# Fisher's Exact Test for Count Data
-#
-# data: .
-# p-value = 0.03104
-# alternative hypothesis: true odds ratio is not equal to 1
-# 95 percent confidence interval:
-# 1.054283 4.735995
-# sample estimates:
-# odds ratio
-# 2.228006
septic_patients %>%
+ filter(hospital_id %in% c("A", "D")) %>% # filter on only hospitals A and D
+ select(hospital_id, fosf) %>% # select the hospitals and fosfomycin
+ group_by(hospital_id) %>% # group on the hospitals
+ count_df(combine_IR = 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()
+ fisher.test() # do Fisher's Exact Test
+#
+# Fisher's Exact Test for Count Data
+#
+# data: .
+# p-value = 0.03104
+# alternative hypothesis: true odds ratio is not equal to 1
+# 95 percent confidence interval:
+# 1.054283 4.735995
+# sample estimates:
+# odds ratio
+# 2.228006
As can be seen, the p value is 0.03, which means that the fosfomycin resistances found in hospital A and D are really different.
(
AMR
is a free and open-source R package to simplify the analysis and prediction of Antimicrobial Resistance (AMR) and to work with microbial and antimicrobial properties by using evidence-based methods. It supports any table format, including WHONET/EARS-Net data.
After installing this package, R knows almost all ~20.000 microorganisms and ~500 antibiotics by name and code, and knows all about valid RSI and MIC values.
We created this package for both academic research and routine analysis at the Faculty of Medical Sciences of the University of Groningen and the Medical Microbiology & Infection Prevention (MMBI) department of the University Medical Center Groningen (UMCG). This R package is actively maintained and free software; you can freely use and distribute it for both personal and commercial (but not patent) purposes under the terms of the GNU General Public License version 2.0 (GPL-2), as published by the Free Software Foundation. Read the full license here.
This package can be used for:
This package is available on the official R network (CRAN), which has a peer-reviewed submission process. Install this package in R with:
-install.packages("AMR")
It will be downloaded and installed automatically. For RStudio, click on the menu Tools > Install Packages… and then type in “AMR” and press Install.
The latest and unpublished development version can be installed with (precaution: may be unstable):
-install.packages("devtools")
-devtools::install_gitlab("msberends/AMR")
The AMR
package basically does four important things:
It cleanses existing data by providing new classes for microoganisms, antibiotics and antimicrobial results (both S/I/R and MIC). By installing this package, you teach R everything about microbiology that is needed for analysis. These functions all use artificial intelligence to guess results that you would expect:
as.mo()
to get an ID of a microorganism. The IDs are human readable for the trained eye - the ID of Klebsiella pneumoniae is “B_KLBSL_PNE” (B stands for Bacteria) and the ID of S. aureus is “B_STPHY_AUR”. The function takes almost any text as input that looks like the name or code of a microorganism like “E. coli”, “esco” or “esccol” and tries to find expected results using artificial intelligence (AI) on the included ITIS data set, consisting of almost 20,000 microorganisms. It is very fast, please see our benchmarks. Moreover, it can group Staphylococci into coagulase negative and positive (CoNS and CoPS, see source) and can categorise Streptococci into Lancefield groups (like beta-haemolytic Streptococcus Group B, source).as.rsi()
to transform values to valid antimicrobial results. It produces just S, I or R based on your input and warns about invalid values. Even values like “<=0.002; S” (combined MIC/RSI) will result in “S”.as.mic()
to cleanse your MIC values. It produces a so-called factor (called ordinal in SPSS) with valid MIC values as levels. A value like “<=0.002; S” (combined MIC/RSI) will result in “<=0.002”.as.atc()
to get the ATC code of an antibiotic as defined by the WHO. This package contains a database with most LIS codes, official names, DDDs and even trade names of antibiotics. For example, the values “Furabid”, “Furadantin”, “nitro” all return the ATC code of Nitrofurantoine.It enhances existing data and adds new data from data sets included in this package.
eucast_rules()
to apply EUCAST expert rules to isolates.first_isolate()
to identify the first isolates of every patient using guidelines from the CLSI (Clinical and Laboratory Standards Institute).
@@ -306,9 +308,9 @@ devtools::install_gitlab("msberends/AMR
microorganisms
contains the complete taxonomic tree of almost 20,000 microorganisms (bacteria, fungi/yeasts and protozoa). Furthermore, the colloquial name and Gram stain are available, which enables resistance analysis of e.g. different antibiotics per Gram stain. The package also contains functions to look up values in this data set like mo_genus()
, mo_family()
, mo_gramstain()
or even mo_phylum()
. As they use as.mo()
internally, they also use artificial intelligence. For example, mo_genus("MRSA")
and mo_genus("S. aureus")
will both return "Staphylococcus"
. They also come with support for German, Dutch, Spanish, Italian, French and Portuguese. These functions can be used to add new variables to your data.antibiotics
contains almost 500 antimicrobial drugs with their ATC code, EARS-Net code, common LIS codes, official name, trivial name and DDD of both oral and parenteral administration. It also contains hundreds of trade names. Use functions like atc_name()
and atc_tradenames()
to look up values. The atc_*
functions use as.atc()
internally so they support AI to guess your expected result. For example, atc_name("Fluclox")
, atc_name("Floxapen")
and atc_name("J01CF05")
will all return "Flucloxacillin"
. These functions can again be used to add new variables to your data.It analyses the data with convenient functions that use well-known methods.
portion_R()
, portion_IR()
, portion_I()
, portion_SI()
and portion_S()
functions. Similarly, the number of isolates can be determined with the count_R()
, count_IR()
, count_I()
, count_SI()
and count_S()
functions. All these functions can be used with the dplyr
package (e.g. in conjunction with summarise()
)geom_rsi()
, a function made for the ggplot2
packagekurtosis()
, skewness()
and create frequency tables with freq()
It teaches the user how to use all the above actions.
septic_patients
. This data set contains:
@@ -329,6 +331,8 @@ devtools::install_gitlab("msberends/AMR
as.mo()
to identify an MO code.first_isolate()
and eucast_rules()
, all parameters will be filled in automatically.antibiotics
data set now contains a column ears_net
.ab_*
functions are deprecated and replaced by atc_*
functions: r ab_property -> atc_property() ab_name -> atc_name() ab_official -> atc_official() ab_trivial_nl -> atc_trivial_nl() ab_certe -> atc_certe() ab_umcg -> atc_umcg() ab_tradenames -> atc_tradenames()
These functions use as.atc()
internally. The old atc_property
has been renamed atc_online_property()
. This is done for two reasons: firstly, not all ATC codes are of antibiotics (ab) but can also be of antivirals or antifungals. Secondly, the input must have class atc
or must be coerable to this class. Properties of these classes should start with the same class name, analogous to as.mo()
and e.g. mo_genus
.pkgdown
)All ab_*
functions are deprecated and replaced by atc_*
functions:
ab_property -> atc_property()
+ab_name -> atc_name()
+ab_official -> atc_official()
+ab_trivial_nl -> atc_trivial_nl()
+ab_certe -> atc_certe()
+ab_umcg -> atc_umcg()
+ab_tradenames -> atc_tradenames()
as.atc()
internally. The old atc_property
has been renamed atc_online_property()
. This is done for two reasons: firstly, not all ATC codes are of antibiotics (ab) but can also be of antivirals or antifungals. Secondly, the input must have class atc
or must be coerable to this class. Properties of these classes should start with the same class name, analogous to as.mo()
and e.g. mo_genus
.pkgdown
)
+set_mo_source()
and get_mo_source()
to use your own predefined MO codes as input for as.mo()
and consequently all mo_*
functionsdplyr
version 0.8.0guess_ab_col()
to find an antibiotic column in a tablemo_renamed()
to get a list of all returned values from as.mo()
that have had taxonomic renamingage()
to calculate the (patients) age in yearsage_groups()
to split ages into custom or predefined groups (like children or elderly). This allows for easier demographic antimicrobial resistance analysis per age group.ggplot_rsi_predict()
as well as the base R plot()
function can now be used for resistance prediction calculated with resistance_predict()
: r x <- resistance_predict(septic_patients, col_ab = "amox") plot(x) ggplot_rsi_predict(x)
+New function ggplot_rsi_predict()
as well as the base R plot()
function can now be used for resistance prediction calculated with resistance_predict()
:
filter_first_isolate()
and filter_first_weighted_isolate()
to shorten and fasten filtering on data sets with antimicrobial results, e.g.: r septic_patients %>% filter_first_isolate(...) # or filter_first_isolate(septic_patients, ...)
is equal to: r septic_patients %>% mutate(only_firsts = first_isolate(septic_patients, ...)) %>% filter(only_firsts == TRUE) %>% select(-only_firsts)
+Functions filter_first_isolate()
and filter_first_weighted_isolate()
to shorten and fasten filtering on data sets with antimicrobial results, e.g.:
is equal to:
+New vignettes about how to conduct AMR analysis, predict antimicrobial resistance, use the G-test and more. These are also available (and even easier readable) on our website: https://msberends.gitlab.io/AMR.
atc_ddd()
and atc_groups()
have been renamed atc_online_ddd()
and atc_online_groups()
. The old functions are deprecated and will be removed in a future version.guess_mo()
is now deprecated in favour of as.mo()
and will be removed in future versionsguess_atc()
is now deprecated in favour of as.atc()
and will be removed in future versionseucast_rules()
:eucast_rules()
:
+as.mo()
:as.mo()
:
+first_isolate()
:first_isolate()
:
+septic_patients
data set this yielded a difference of 0.15% more isolatescol_patientid
), when this parameter was left blankcol_keyantibiotics()
), when this parameter was left blankoutput_logical
, the function will now always return a logical valuefilter_specimen
to specimen_group
, although using filter_specimen
will still workportion
functions, that low counts can influence the outcome and that the portion
functions may camouflage this, since they only return the portion (albeit being dependent on the minimum
parameter)microorganisms.certe
and microorganisms.umcg
into microorganisms.codes
mo_taxonomy()
now contains the kingdom toois.rsi.eligible()
-is.rsi.eligible()
using the new threshold
parameterscale_rsi_colours()
mo
will now return the top 3 and the unique count, e.g. using summary(mo)
rsi
and mic
freq()
function):freq()
function):
+Support for tidyverse quasiquotation! Now you can create frequency tables of function outcomes:
-# Determine genus of microorganisms (mo) in `septic_patients` data set:
-# OLD WAY
-septic_patients %>%
- mutate(genus = mo_genus(mo)) %>%
- freq(genus)
-# NEW WAY
-septic_patients %>%
- freq(mo_genus(mo))
-
-# Even supports grouping variables:
-septic_patients %>%
- group_by(gender) %>%
- freq(mo_genus(mo))
# Determine genus of microorganisms (mo) in `septic_patients` data set:
+# OLD WAY
+septic_patients %>%
+ mutate(genus = mo_genus(mo)) %>%
+ freq(genus)
+# NEW WAY
+septic_patients %>%
+ freq(mo_genus(mo))
+
+# Even supports grouping variables:
+septic_patients %>%
+ group_by(gender) %>%
+ freq(mo_genus(mo))
header
functionheader
is now set to TRUE
at default, even for markdowndroplevels
to exclude empty factor levels when input is a factorselect()
on frequency tablesscale_y_percent()
now contains the limits
parametermdro()
, key_antibiotics()
and eucast_rules()
resistance_predict()
function)Fix for as.mic()
to support more values ending in (several) zeroes
as.mic()
to support more values ending in (several) zeroesEUCAST_rules
was renamed to eucast_rules
, the old function still exists as a deprecated functioneucast_rules
function:eucast_rules
function:
+rules
to specify which rules should be applied (expert rules, breakpoints, others or all)verbose
which can be set to TRUE
to get very specific messages about which columns and rows were affectedseptic_patients
now reflects these changespipe
for piperacillin (J01CA12), also to the mdro
functionkingdom
to the microorganisms data set, and function mo_kingdom
to look up valuesas.mo
(and subsequently all mo_*
functions), as empty values wil be ignored a priori
as.mo
will return NAas.mo
(and all mo_*
wrappers) now supports genus abbreviations with “species” attached r as.mo("E. species") # B_ESCHR mo_fullname("E. spp.") # "Escherichia species" as.mo("S. spp") # B_STPHY mo_fullname("S. species") # "Staphylococcus species"
+Function as.mo
(and all mo_*
wrappers) now supports genus abbreviations with “species” attached
combine_IR
(TRUE/FALSE) to functions portion_df
and count_df
, to indicate that all values of I and R must be merged into one, so the output only consists of S vs. IR (susceptible vs. non-susceptible)portion_*(..., as_percent = TRUE)
when minimal number of isolates would not be metportion_*
functions now throws a warning when total available isolate is below parameter minimum
as.mo
, as.rsi
, as.mic
, as.atc
and freq
will not set package name as attribute anymorefreq()
:freq()
:
+Support for grouping variables, test with:
-septic_patients %>%
- group_by(hospital_id) %>%
- freq(gender)
Support for (un)selecting columns:
-septic_patients %>%
- freq(hospital_id) %>%
- select(-count, -cum_count) # only get item, percent, cum_percent
hms::is.hms
na
, to choose which character to print for empty valuesheader
to turn the header info off (default when markdown = TRUE
)title
to manually setbthe title of the frequency tablefirst_isolate
now tries to find columns to use as input when parameters are left blankmdro
)ggplot_rsi
and scale_y_percent
have breaks
parameteras.mo
:as.mo
:
+"CRS"
-> Stenotrophomonas maltophilia
"MSSE"
-> Staphylococcus epidermidis
join
functionsis.rsi.eligible
, now 15-20 times fasterg.test
, when sum(x)
is below 1000 or any of the expected values is below 5, Fisher’s Exact Test will be suggestedmicroorganisms
now contains all microbial taxonomic data from ITIS (kingdoms Bacteria, Fungi and Protozoa), the Integrated Taxonomy Information System, available via https://itis.gov. The data set now contains more than 18,000 microorganisms with all known bacteria, fungi and protozoa according ITIS with genus, species, subspecies, family, order, class, phylum and subkingdom. The new data set microorganisms.old
contains all previously known taxonomic names from those kingdoms.mo_property
:mo_property
:
+mo_phylum
, mo_class
, mo_order
, mo_family
, mo_genus
, mo_species
, mo_subspecies
mo_fullname
, mo_shortname
@@ -475,22 +529,52 @@ septic_patients %>%
mo_ref
They also come with support for German, Dutch, French, Italian, Spanish and Portuguese: r mo_gramstain("E. coli") # [1] "Gram negative" mo_gramstain("E. coli", language = "de") # German # [1] "Gramnegativ" mo_gramstain("E. coli", language = "es") # Spanish # [1] "Gram negativo" mo_fullname("S. group A", language = "pt") # Portuguese # [1] "Streptococcus grupo A"
Furthermore, former taxonomic names will give a note about the current taxonomic name: r mo_gramstain("Esc blattae") # Note: 'Escherichia blattae' (Burgess et al., 1973) was renamed 'Shimwellia blattae' (Priest and Barker, 2010) # [1] "Gram negative"
They also come with support for German, Dutch, French, Italian, Spanish and Portuguese:
+mo_gramstain("E. coli")
+# [1] "Gram negative"
+mo_gramstain("E. coli", language = "de") # German
+# [1] "Gramnegativ"
+mo_gramstain("E. coli", language = "es") # Spanish
+# [1] "Gram negativo"
+mo_fullname("S. group A", language = "pt") # Portuguese
+# [1] "Streptococcus grupo A"
Furthermore, former taxonomic names will give a note about the current taxonomic name:
+ +count_R
, count_IR
, count_I
, count_SI
and count_S
to selectively count resistant or susceptible isolates
count_R
, count_IR
, count_I
, count_SI
and count_S
to selectively count resistant or susceptible isolatescount_df
(which works like portion_df
) to get all counts of S, I and R of a data set with antibiotic columns, with support for grouped variablesis.rsi.eligible
to check for columns that have valid antimicrobial results, but do not have the rsi
class yet. Transform the columns of your raw data with: data %>% mutate_if(is.rsi.eligible, as.rsi)
as.mo
and is.mo
as replacements for as.bactid
and is.bactid
(since the microoganisms
data set not only contains bacteria). These last two functions are deprecated and will be removed in a future release. The as.mo
function determines microbial IDs using Artificial Intelligence (AI): r as.mo("E. coli") # [1] B_ESCHR_COL as.mo("MRSA") # [1] B_STPHY_AUR as.mo("S group A") # [1] B_STRPTC_GRA
And with great speed too - on a quite regular Linux server from 2007 it takes us less than 0.02 seconds to transform 25,000 items: r thousands_of_E_colis <- rep("E. coli", 25000) microbenchmark::microbenchmark(as.mo(thousands_of_E_colis), unit = "s") # Unit: seconds # min median max neval # 0.01817717 0.01843957 0.03878077 100
+Functions as.mo
and is.mo
as replacements for as.bactid
and is.bactid
(since the microoganisms
data set not only contains bacteria). These last two functions are deprecated and will be removed in a future release. The as.mo
function determines microbial IDs using Artificial Intelligence (AI):
as.mo("E. coli")
+# [1] B_ESCHR_COL
+as.mo("MRSA")
+# [1] B_STPHY_AUR
+as.mo("S group A")
+# [1] B_STRPTC_GRA
And with great speed too - on a quite regular Linux server from 2007 it takes us less than 0.02 seconds to transform 25,000 items:
+reference_df
for as.mo
, so users can supply their own microbial IDs, name or codes as a reference tablebactid
to mo
, like:bactid
to mo
, like:
+EUCAST_rules
, first_isolate
and key_antibiotics
microorganisms
and septic_patients
labels_rsi_count
to print datalabels on a RSI ggplot2
modelFunctions as.atc
and is.atc
to transform/look up antibiotic ATC codes as defined by the WHO. The existing function guess_atc
is now an alias of as.atc
.
ab_property
and its aliases: ab_name
, ab_tradenames
, ab_certe
, ab_umcg
and ab_trivial_nl
@@ -505,7 +589,14 @@ septic_patients %>%
Changed
antibiotics
data set: Terbinafine (D01BA02), Rifaximin (A07AA11) and Isoconazole (D01AC05)antibiotics
data set, it now contains 298 different trade names in total, e.g.: r ab_official("Bactroban") # [1] "Mupirocin" ab_name(c("Bactroban", "Amoxil", "Zithromax", "Floxapen")) # [1] "Mupirocin" "Amoxicillin" "Azithromycin" "Flucloxacillin" ab_atc(c("Bactroban", "Amoxil", "Zithromax", "Floxapen")) # [1] "R01AX06" "J01CA04" "J01FA10" "J01CF05"
+Added 163 trade names to the antibiotics
data set, it now contains 298 different trade names in total, e.g.:
first_isolate
, rows will be ignored when there’s no species availableratio
is now deprecated and will be removed in a future release, as it is not really the scope of this packageprevalence
column to the microorganisms
data setminimum
and as_percent
to portion_df
count_*
and portions_*
, and n_rsi
. This allows to check for more than 2 vectors or columns. ```r septic_patients %>% select(amox, cipr) %>% count_IR() # which is the same as: septic_patients %>% count_IR(amox, cipr)Support for quasiquotation in the functions series count_*
and portions_*
, and n_rsi
. This allows to check for more than 2 vectors or columns.
ggplot_rsi
and geom_rsi
so they can cope with count_df
. The new fun
parameter has value portion_df
at default, but can be set to count_df
.ggplot_rsi
when the ggplot2
package was not loadedlabels_rsi_count
to ggplot_rsi
+geom_rsi
(and ggplot_rsi
) so you can set your own preferencesquote
to the freq
functiondiff
for frequency tablesfreq
) header of class character
+Support for types (classes) list and matrix for freq
For lists, subsetting is possible:
+ +septic_patients %>% portion_S(amcl) septic_patients %>% portion_S(amcl, gent) septic_patients %>% portion_S(amcl, gent, pita) * Edited `ggplot_rsi` and `geom_rsi` so they can cope with `count_df`. The new `fun` parameter has value `portion_df` at default, but can be set to `count_df`. * Fix for `ggplot_rsi` when the `ggplot2` package was not loaded * Added datalabels function `labels_rsi_count` to `ggplot_rsi` * Added possibility to set any parameter to `geom_rsi` (and `ggplot_rsi`) so you can set your own preferences * Fix for joins, where predefined suffices would not be honoured * Added parameter `quote` to the `freq` function * Added generic function `diff` for frequency tables * Added longest en shortest character length in the frequency table (`freq`) header of class `character` * Support for types (classes) list and matrix for `freq`
r my_matrix = with(septic_patients, matrix(c(age, gender), ncol = 2)) freq(my_matrix) For lists, subsetting is possible:
r my_list = list(age = septic_patients$age, gender = septic_patients$gender) my_list %>% freq(age) my_list %>% freq(gender) ```
rsi_df
was removed in favour of new functions portion_R
, portion_IR
, portion_I
, portion_SI
and portion_S
to selectively calculate resistance or susceptibility. These functions are 20 to 30 times faster than the old rsi
function. The old function still works, but is deprecated.rsi_df
was removed in favour of new functions portion_R
, portion_IR
, portion_I
, portion_SI
and portion_S
to selectively calculate resistance or susceptibility. These functions are 20 to 30 times faster than the old rsi
function. The old function still works, but is deprecated.
+portion_df
to get all portions of S, I and R of a data set with antibiotic columns, with support for grouped variablesggplot2
+ggplot2
+geom_rsi
, facet_rsi
, scale_y_percent
, scale_rsi_colours
and theme_rsi
ggplot_rsi
to apply all above functions on a data set:
@@ -554,22 +678,32 @@ septic_patients %>%
as.bactid
and is.bactid
to transform/ look up microbial ID’s.guess_bactid
is now an alias of as.bactid
kurtosis
and skewness
that are lacking in base R - they are generic functions and have support for vectors, data.frames and matricesg.test
to perform the Χ2 distributed G-test, which use is the same as chisq.test
ratio
to transform a vector of values to a preset ratioratio
to transform a vector of values to a preset ratioratio(c(10, 500, 10), ratio = "1:2:1")
would return 130, 260, 130
%in%
or %like%
(and give them keyboard shortcuts), or to view the datasets that come with this packagep.symbol
to transform p values to their related symbols: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
clipboard_import
and clipboard_export
as helper functions to quickly copy and paste from/to software like Excel and SPSS. These functions use the clipr
package, but are a little altered to also support headless Linux servers (so you can use it in RStudio Server)freq
):freq
):
+rsi
(antimicrobial resistance) to use as inputtable
to use as input: freq(table(x, y))
@@ -584,6 +718,8 @@ septic_patients %>%
options(max.print.freq = n)
where n is your preset valuemicroorganisms
dataset (especially for Salmonella) and the column bactid
now has the new class "bactid"
rsi
and mic
functions:rsi
and mic
functions:
+as.rsi("<=0.002; S")
will return S
as.mic("<=0.002; S")
will return <=0.002
as.mic("<= 0.002")
now worksrsi
and mic
do not add the attribute package.version
anymore"groups"
option for atc_property(..., property)
. It will return a vector of the ATC hierarchy as defined by the WHO. The new function atc_groups
is a convenient wrapper around this.atc_property
as it requires the host set by url
to be responsivefirst_isolate
algorithm to exclude isolates where bacteria ID or genus is unavailable924b62
) from the dplyr
package v0.7.5 and aboveguess_bactid
(now called as.bactid
)guess_bactid
(now called as.bactid
)
+yourdata %>% select(genus, species) %>% as.bactid()
now also worksguess_bactid
to determine the ID of a microorganism based on genus/species or known abbreviations like MRSAguess_atc
to determine the ATC of an antibiotic based on name, trade name, or known abbreviationsfreq
to create frequency tables, with additional info in a headerMDRO
to determine Multi Drug Resistant Organisms (MDRO) with support for country-specific guidelines.MDRO
to determine Multi Drug Resistant Organisms (MDRO) with support for country-specific guidelines.
+BRMO
and MRGN
are wrappers for Dutch and German guidelines, respectively"points"
or "keyantibiotics"
, see ?first_isolate
tibble
s and data.table
sA data.frame
with 500 observations and 53 variables:
Identification number
ID of the sample
Specimen number
ID of the specimen
Organism
Microorganisms, can be coerced with as.mo
Organism
Name of the microorganism. Before analysis, you should transform this to a valid microbial class, using as.mo
.
Country
Country of origin
Laboratory
Name of laboratory
Last name
Last name of patient
Inducible clindamycin resistance
Clindamycin can be induced?
Comment
Other comments
Date of data entry
Date this data was entered in WHONET
AMP_ND10:CIP_EE
27 different antibiotics. You can lookup the abbreviatons in the antibiotics
data set, or use e.g. atc_name("AMP")
to get the official name immediately.
AMP_ND10:CIP_EE
27 different antibiotics. You can lookup the abbreviatons in the antibiotics
data set, or use e.g. atc_name("AMP")
to get the official name immediately. Before analysis, you should transform this to a valid antibiotic class, using as.rsi
.
x | vector |
+
---|---|
threshold | +maximum fraction of |
+