diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 080ebb66..7cf67639 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -118,7 +118,7 @@ coverage: # install missing and outdated packages - Rscript -e 'source(".gitlab-ci.R"); gl_update_pkg_all(repos = "https://cran.rstudio.com", quiet = TRUE, install_pkgdown = TRUE)' # codecov token is set in https://gitlab.com/msberends/AMR/settings/ci_cd - - Rscript -e "cc <- covr::package_coverage(); covr::codecov(coverage = cc, token = '$codecov'); cat('Code coverage:', covr::percent_coverage(cc))" + - Rscript -e "cc <- covr::package_coverage(); covr::codecov(coverage = cc, token = '$codecov', exclusions = c('R/atc_online.R', 'R/mo_source.R')); cat('Code coverage:', covr::percent_coverage(cc))" coverage: '/Code coverage: \d+\.\d+/' pages: diff --git a/DESCRIPTION b/DESCRIPTION index 4aef11f4..c9e995b7 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: AMR -Version: 0.6.1.9043 -Date: 2019-05-30 +Version: 0.6.1.9044 +Date: 2019-05-31 Title: Antimicrobial Resistance Analysis Authors@R: c( person( diff --git a/NEWS.md b/NEWS.md index f29b2984..8453bbf1 100755 --- a/NEWS.md +++ b/NEWS.md @@ -7,6 +7,7 @@ * Added guidelines of the WHO to determine mutli-drug resistance (MDR) for TB (`mdr_tb()`) and added a new vignette about MDR #### Changed +* Fixed a critical bug in `first_isolate()` where missing species would lead to incorrect FALSEs. This bug was not present in AMR v0.5.0, but was in v0.6.0 and v0.6.1. * Completely reworked the `antibiotics` data set: * All entries now have 3 different identifiers: * Column `ab` contains a human readable EARS-Net code, used by ECDC and WHO/WHONET - this is the primary identifier used in this package @@ -24,6 +25,7 @@ * Improved intelligence of looking up antibiotic tables in data set using `guess_ab_col()` * Added ~5,000 more old taxonomic names to the `microorganisms.old` data set, which leads to better results finding when using the `as.mo()` function * This package now honours the new EUCAST insight (2019) that S and I are but classified as susceptible, where I is defined as 'increased exposure' and not 'intermediate' anymore. For functions like `portion_df()` and `count_df()` this means that their new parameter `combine_SI` is TRUE at default. +* The `age()` function gained a new parameter `exact` to determine ages with decimals * Removed deprecated functions `guess_mo()`, `guess_atc()`, `EUCAST_rules()`, `interpretive_reading()`, `rsi()` * Frequency tables (`freq()`): * speed improvement for microbial IDs diff --git a/R/age.R b/R/age.R index bb9d4c10..5ea85226 100755 --- a/R/age.R +++ b/R/age.R @@ -24,15 +24,22 @@ #' Calculates age in years based on a reference date, which is the sytem date at default. #' @param x date(s), will be coerced with \code{\link{as.POSIXlt}} #' @param reference reference date(s) (defaults to today), will be coerced with \code{\link{as.POSIXlt}} and cannot be lower than \code{x} -#' @return Integer (no decimals) +#' @param exact a logical to indicate whether age calculation should be exact, i.e. with decimals +#' @return An integer (no decimals) if \code{exact = FALSE}, a double (with decimals) otherwise #' @seealso \code{\link{age_groups}} to split age into age groups #' @importFrom dplyr if_else #' @inheritSection AMR Read more on our website! #' @export #' @examples -#' df <- data.frame(birth_date = Sys.Date() - runif(100) * 25000) +#' # 10 random birth dates +#' df <- data.frame(birth_date = Sys.Date() - runif(10) * 25000) +#' # add ages #' df$age <- age(df$birth_date) -age <- function(x, reference = Sys.Date()) { +#' # add exact ages +#' df$age_exact <- age(df$birth_date, exact = TRUE) +#' +#' df +age <- function(x, reference = Sys.Date(), exact = FALSE) { if (length(x) != length(reference)) { if (length(reference) == 1) { reference <- rep(reference, length(x)) @@ -49,17 +56,33 @@ age <- function(x, reference = Sys.Date()) { as.integer(years_gap - 1), as.integer(years_gap)) + # add decimals + if (exact == TRUE) { + # get dates of `x` when `x` would have the year of `reference` + x_in_reference_year <- base::as.POSIXlt(paste0(format(reference, "%Y"), format(x, "-%m-%d"))) + # get differences in days + n_days_x_rest <- base::as.double(base::difftime(reference, x_in_reference_year, units = "days")) + # get numbers of days the years of `reference` has for a reliable denominator + n_days_reference_year <- base::as.POSIXlt(paste0(format(reference, "%Y"), "-12-31"))$yday + 1 + # add decimal parts of year + ages <- ages + (n_days_x_rest / n_days_reference_year) + } + if (any(ages < 0, na.rm = TRUE)) { - ages[ages < 0] <- NA_integer_ + ages[ages < 0] <- NA warning("NAs introduced for ages below 0.") } if (any(ages > 120, na.rm = TRUE)) { - warning("Some ages are > 120.") + warning("Some ages are above 120.") } ages } +age_to_toDate <- function(age) { + +} + #' Split ages into age groups #' #' Split ages into age groups defined by the \code{split} parameter. This allows for easier demographic (antimicrobial resistance) analysis. diff --git a/R/amr.R b/R/amr.R index 3c5edef9..ac76faa4 100644 --- a/R/amr.R +++ b/R/amr.R @@ -29,16 +29,17 @@ #' #' This package can be used for: #' \itemize{ -#' \item{Reference for microorganisms, since it contains almost all 60,000 microbial (sub)species from the Catalogue of Life} +#' \item{Reference for microorganisms, since it contains all microbial (sub)species from the Catalogue of Life} +#' \item{Interpreting raw MIC and disk diffusion values, based on the latest CLSI or EUCAST guidelines} #' \item{Calculating antimicrobial resistance} +#' \item{Determining multi-drug resistance (MDR) / multi-drug resistant organisms (MDRO)} #' \item{Calculating empirical susceptibility of both mono therapy and combination therapy} #' \item{Predicting future antimicrobial resistance using regression models} #' \item{Getting properties for any microorganism (like Gram stain, species, genus or family)} #' \item{Getting properties for any antibiotic (like name, ATC code, defined daily dose or trade name)} #' \item{Plotting antimicrobial resistance} #' \item{Determining first isolates to be used for AMR analysis} -#' \item{Applying EUCAST expert rules (not the translation from MIC to RSI values)} -#' \item{Determining multi-drug resistant organisms (MDRO)} +#' \item{Applying EUCAST expert rules} #' \item{Descriptive statistics: frequency tables, kurtosis and skewness} #' } #' @section Authors: @@ -48,7 +49,7 @@ #' [2] Certe Medical Diagnostics & Advice, Groningen, the Netherlands - \url{certe.nl} #' @section Read more on our website!: -#' On our website \url{https://msberends.gitlab.io/AMR} you can find \href{https://msberends.gitlab.io/AMR/articles/AMR.html}{a comprehensive tutorial} about how to conduct AMR analysis, the \href{https://msberends.gitlab.io/AMR/reference}{complete documentation of all functions} (which reads a lot easier than here in R) and \href{https://msberends.gitlab.io/AMR/articles/WHONET.html}{an example analysis using WHONET data}. +#' On our website \url{https://msberends.gitlab.io/AMR} you can find \href{https://msberends.gitlab.io/AMR/articles/AMR.html}{a tutorial} about how to conduct AMR analysis, the \href{https://msberends.gitlab.io/AMR/reference}{complete documentation of all functions} (which reads a lot easier than here in R) and \href{https://msberends.gitlab.io/AMR/articles/WHONET.html}{an example analysis using WHONET data}. #' @section Contact us: #' For suggestions, comments or questions, please contact us at: diff --git a/R/first_isolate.R b/R/first_isolate.R index ea5f2080..49a29a82 100755 --- a/R/first_isolate.R +++ b/R/first_isolate.R @@ -233,7 +233,7 @@ first_isolate <- function(x, } # -- specimen - if (is.null(col_specimen)) { + if (is.null(col_specimen) & !is.null(specimen_group)) { col_specimen <- search_type_in_df(x = x, type = "specimen") } if (isFALSE(col_specimen)) { @@ -263,7 +263,9 @@ first_isolate <- function(x, # join to microorganisms data set x <- x %>% mutate_at(vars(col_mo), as.mo) %>% - left_join_microorganisms(by = col_mo) + left_join_microorganisms(by = col_mo) %>% + # empty species will lead to first = FALSE, so put in text there if genus is available + mutate(species = ifelse(!is.na(genus) & species == "", "species", species)) col_genus <- "genus" col_species <- "species" diff --git a/R/guess_ab_col.R b/R/guess_ab_col.R index 421e84f1..2cddd3c5 100755 --- a/R/guess_ab_col.R +++ b/R/guess_ab_col.R @@ -85,12 +85,14 @@ guess_ab_col <- function(x = NULL, search_string = NULL, verbose = FALSE) { if (length(ab_result) == 0) { if (verbose == TRUE) { - message('No column found as input for `', search_string, '`.') + message(paste0("No column found as input for `", search_string, + "` (", ab_name(search_string, language = "en", tolower = TRUE), ").")) } return(NULL) } else { if (verbose == TRUE) { - message(blue(paste0("NOTE: Using column `", bold(ab_result), "` as input for `", search_string, "`."))) + message(blue(paste0("NOTE: Using column `", bold(ab_result), "` as input for `", search_string, + "` (", ab_name(search_string, language = "en", tolower = TRUE), ")."))) } return(ab_result) } diff --git a/R/misc.R b/R/misc.R index 3cc651ce..9c1236aa 100755 --- a/R/misc.R +++ b/R/misc.R @@ -190,17 +190,17 @@ get_column_abx <- function(x, if (verbose == TRUE) { for (i in 1:length(x)) { if (x[i] %in% duplies) { - message(red(paste0("NOTE: Using column `", bold(x[i]), "` as input for ", names(x)[i], - " (", ab_name(names(x)[i], language = "en", tolower = TRUE), ") [DUPLICATED USE]."))) + message(red(paste0("NOTE: Using column `", bold(x[i]), "` as input for `", names(x)[i], + "` (", ab_name(names(x)[i], language = "en", tolower = TRUE), ") [DUPLICATED USE]."))) } else { - message(blue(paste0("NOTE: Using column `", bold(x[i]), "` as input for ", names(x)[i], - " (", ab_name(names(x)[i], language = "en", tolower = TRUE), ")."))) + message(blue(paste0("NOTE: Using column `", bold(x[i]), "` as input for `", names(x)[i], + "` (", ab_name(names(x)[i], language = "en", tolower = TRUE), ")."))) } } } if (n_distinct(x) != length(x)) { - msg_txt <- paste("Column(s)", paste0("'", duplies, "'", collapse = "'"), "used for more than one antibiotic.") + msg_txt <- paste("Column(s)", paste0("`", duplies, "`", collapse = " and "), "used for more than one antibiotic.") if (verbose == FALSE) { msg_txt <- paste(msg_txt, "Use verbose = TRUE to see which antibiotics are used by which columns.") } diff --git a/codecov.yml b/codecov.yml index b637472b..50a3f625 100644 --- a/codecov.yml +++ b/codecov.yml @@ -17,3 +17,4 @@ coverage: ignore: - "R/atc_online.R" + - "R/mo_source.R" diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index 9f20e05a..42c8f8ed 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -78,7 +78,7 @@ AMR (for R) - 0.6.1.9043 + 0.6.1.9044 diff --git a/docs/articles/AMR.html b/docs/articles/AMR.html index b66f2e0c..c7918cd6 100644 --- a/docs/articles/AMR.html +++ b/docs/articles/AMR.html @@ -40,7 +40,7 @@ AMR (for R) - 0.6.1.9040 + 0.6.1.9044 @@ -199,7 +199,7 @@

How to conduct AMR analysis

Matthijs S. Berends

-

28 May 2019

+

31 May 2019

@@ -208,7 +208,7 @@ -

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 28 May 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 31 May 2019.

Introduction

@@ -224,21 +224,21 @@ -2019-05-28 +2019-05-31 abcd Escherichia coli S S -2019-05-28 +2019-05-31 abcd Escherichia coli S R -2019-05-28 +2019-05-31 efgh Escherichia coli R @@ -334,10 +334,10 @@ -2010-08-30 -X2 +2015-03-08 +Q4 Hospital B -Staphylococcus aureus +Escherichia coli S S S @@ -345,59 +345,59 @@ F -2015-08-09 -E8 +2015-12-18 +J6 +Hospital B +Escherichia coli +S +S +S +S +M + + +2016-07-07 +W7 Hospital A Staphylococcus aureus R S S S -M - - -2014-05-04 -M8 -Hospital D -Staphylococcus aureus -R -S -R -S -M +F -2013-05-31 -J10 -Hospital B -Staphylococcus aureus -R -R -S -S -M - - -2014-07-13 -H9 +2011-12-08 +G9 Hospital C -Streptococcus pneumoniae +Staphylococcus aureus +S S S -R S M + +2012-09-08 +Y8 +Hospital B +Escherichia coli +S +S +S +S +F + -2015-03-14 -I6 -Hospital D -Staphylococcus aureus +2017-05-04 +X10 +Hospital C +Escherichia coli R S S -S -M +R +F @@ -418,8 +418,8 @@ # # Item Count Percent Cum. Count Cum. Percent # --- ----- ------- -------- ----------- ------------- -# 1 M 10,432 52.2% 10,432 52.2% -# 2 F 9,568 47.8% 20,000 100.0% +# 1 M 10,387 51.9% 10,387 51.9% +# 2 F 9,613 48.1% 20,000 100.0%

So, we can draw at least two conclusions immediately. From a data scientist perspective, the data looks clean: only values M and F. From a researcher 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:

data <- data %>%
@@ -449,14 +449,14 @@
 # Pasteurella multocida (no new changes)
 # Staphylococcus (no new changes)
 # Streptococcus groups A, B, C, G (no new changes)
-# Streptococcus pneumoniae (1464 new changes)
+# Streptococcus pneumoniae (1533 new changes)
 # Viridans group streptococci (no new changes)
 # 
 # EUCAST Expert Rules, Intrinsic Resistance and Exceptional Phenotypes (v3.1, 2016)
-# Table 01: Intrinsic resistance in Enterobacteriaceae (1265 new changes)
+# Table 01: Intrinsic resistance in Enterobacteriaceae (1285 new changes)
 # Table 02: Intrinsic resistance in non-fermentative Gram-negative bacteria (no new changes)
 # Table 03: Intrinsic resistance in other Gram-negative bacteria (no new changes)
-# Table 04: Intrinsic resistance in Gram-positive bacteria (2753 new changes)
+# Table 04: Intrinsic resistance in Gram-positive bacteria (2841 new changes)
 # Table 08: Interpretive rules for B-lactam agents and Gram-positive cocci (no new changes)
 # Table 09: Interpretive rules for B-lactam agents and Gram-negative rods (no new changes)
 # Table 11: Interpretive rules for macrolides, lincosamides, and streptogramins (no new changes)
@@ -464,24 +464,24 @@
 # Table 13: Interpretive rules for quinolones (no new changes)
 # 
 # Other rules
-# Non-EUCAST: amoxicillin/clav acid = S where ampicillin = S (2272 new changes)
-# Non-EUCAST: ampicillin = R where amoxicillin/clav acid = R (108 new changes)
+# Non-EUCAST: amoxicillin/clav acid = S where ampicillin = S (2277 new changes)
+# Non-EUCAST: ampicillin = R where amoxicillin/clav acid = R (127 new changes)
 # Non-EUCAST: piperacillin = R where piperacillin/tazobactam = R (no new changes)
 # Non-EUCAST: piperacillin/tazobactam = S where piperacillin = S (no new changes)
 # Non-EUCAST: trimethoprim = R where trimethoprim/sulfa = R (no new changes)
 # Non-EUCAST: trimethoprim/sulfa = S where trimethoprim = S (no new changes)
 # 
 # --------------------------------------------------------------------------
-# EUCAST rules affected 6,521 out of 20,000 rows, making a total of 7,862 edits
+# EUCAST rules affected 6,664 out of 20,000 rows, making a total of 8,063 edits
 # => added 0 test results
 # 
-# => changed 7,862 test results
-#    - 112 test results changed from S to I
-#    - 4,682 test results changed from S to R
-#    - 1,085 test results changed from I to S
-#    - 303 test results changed from I to R
-#    - 1,657 test results changed from R to S
-#    - 23 test results changed from R to I
+# => changed 8,063 test results
+#    - 121 test results changed from S to I
+#    - 4,826 test results changed from S to R
+#    - 1,112 test results changed from I to S
+#    - 355 test results changed from I to R
+#    - 1,622 test results changed from R to S
+#    - 27 test results changed from R to I
 # --------------------------------------------------------------------------
 # 
 # Use verbose = TRUE to get a data.frame with all specified edits instead.
@@ -509,8 +509,8 @@ # 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,661 first isolates (28.3% of total)
-

So only 28.3% is suitable for resistance analysis! We can now filter on it with the filter() function, also from the dplyr package:

+# => Found 5,672 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:

data_1st <- data %>% 
   filter(first == TRUE)

For future use, the above two syntaxes can be shortened with the filter_first_isolate() function:

@@ -536,8 +536,8 @@ 1 -2010-01-13 -L3 +2010-01-20 +P7 B_ESCHR_COL S S @@ -547,52 +547,52 @@ 2 -2010-02-27 -L3 +2010-02-28 +P7 B_ESCHR_COL +R +S S S -R -R FALSE 3 -2010-04-07 -L3 +2010-04-09 +P7 B_ESCHR_COL +R S S -S -S +R FALSE 4 -2010-08-07 -L3 +2010-04-23 +P7 B_ESCHR_COL R -S +R S S FALSE 5 -2010-08-09 -L3 +2010-05-07 +P7 B_ESCHR_COL R -S +R S S FALSE 6 -2010-09-28 -L3 +2010-05-15 +P7 B_ESCHR_COL S S @@ -602,8 +602,8 @@ 7 -2010-10-07 -L3 +2010-07-16 +P7 B_ESCHR_COL R S @@ -613,8 +613,30 @@ 8 -2010-12-15 -L3 +2010-07-31 +P7 +B_ESCHR_COL +R +S +S +S +FALSE + + +9 +2010-09-10 +P7 +B_ESCHR_COL +S +S +S +S +FALSE + + +10 +2010-11-09 +P7 B_ESCHR_COL S S @@ -622,31 +644,9 @@ S FALSE - -9 -2011-10-03 -L3 -B_ESCHR_COL -S -S -S -S -TRUE - - -10 -2011-12-06 -L3 -B_ESCHR_COL -S -S -S -S -FALSE - -

Only 2 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.

+

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(.)) %>% 
@@ -657,7 +657,7 @@
 # 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,116 first weighted isolates (75.6% of total)
+# => Found 15,152 first weighted isolates (75.8% of total) @@ -674,8 +674,8 @@ - - + + @@ -686,35 +686,35 @@ - - + + + + - - - - + + + - - + - - + + - + @@ -722,11 +722,11 @@ - - + + - + @@ -734,8 +734,8 @@ - - + + @@ -746,8 +746,8 @@ - - + + @@ -758,8 +758,32 @@ - - + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -768,37 +792,13 @@ - - - - - - - - - - - - - - - - - - - - - - - -
isolate
12010-01-13L32010-01-20P7 B_ESCHR_COL S S
22010-02-27L32010-02-28P7 B_ESCHR_COLRS S SRR FALSE TRUE
32010-04-07L32010-04-09P7 B_ESCHR_COLR S SSSR FALSE TRUE
42010-08-07L32010-04-23P7 B_ESCHR_COL RSR S S FALSE
52010-08-09L32010-05-07P7 B_ESCHR_COL RSR S S FALSE
62010-09-28L32010-05-15P7 B_ESCHR_COL S S
72010-10-07L32010-07-16P7 B_ESCHR_COL R S
82010-12-15L32010-07-31P7B_ESCHR_COLRSSSFALSETRUE
92010-09-10P7B_ESCHR_COLSSSSFALSETRUE
102010-11-09P7 B_ESCHR_COL S SFALSE TRUE
92011-10-03L3B_ESCHR_COLSSSSTRUETRUE
102011-12-06L3B_ESCHR_COLSSSSFALSEFALSE
-

Instead of 2, now 8 isolates are flagged. In total, 75.6% 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 9 isolates are flagged. In total, 75.8% of all isolates are marked ‘first weighted’ - 47.4% 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 15,116 isolates for analysis.

+

So we end up with 15,152 isolates for analysis.

We can remove unneeded columns:

data_1st <- data_1st %>% 
   select(-c(first, keyab))
@@ -822,86 +822,56 @@ -2010-08-30 -X2 +2015-03-08 +Q4 Hospital B -B_STPHY_AUR +B_ESCHR_COL S S S S F +Gram negative +Escherichia +coli +TRUE + + +2015-12-18 +J6 +Hospital B +B_ESCHR_COL +S +S +S +S +M +Gram negative +Escherichia +coli +TRUE + + +2016-07-07 +W7 +Hospital A +B_STPHY_AUR +R +S +S +S +F Gram positive Staphylococcus aureus TRUE -2015-08-09 -E8 -Hospital A -B_STPHY_AUR -R -S -S -S -M -Gram positive -Staphylococcus -aureus -TRUE - - -2014-05-04 -M8 -Hospital D -B_STPHY_AUR -R -S -R -S -M -Gram positive -Staphylococcus -aureus -TRUE - - -2013-05-31 -J10 -Hospital B -B_STPHY_AUR -R -R -S -S -M -Gram positive -Staphylococcus -aureus -TRUE - - -2014-07-13 -H9 +2011-12-08 +G9 Hospital C -B_STRPT_PNE -S -S -R -R -M -Gram positive -Streptococcus -pneumoniae -TRUE - - -2015-03-14 -I6 -Hospital D B_STPHY_AUR -R +S S S S @@ -911,6 +881,36 @@ aureus TRUE + +2012-09-08 +Y8 +Hospital B +B_ESCHR_COL +S +S +S +S +F +Gram negative +Escherichia +coli +TRUE + + +2017-05-04 +X10 +Hospital C +B_ESCHR_COL +R +S +S +R +F +Gram negative +Escherichia +coli +TRUE +

Time for the analysis!

@@ -928,9 +928,9 @@
freq(paste(data_1st$genus, data_1st$species))

Or can be used like the dplyr way, which is easier readable:

data_1st %>% freq(genus, species)
-

Frequency table of genus and species from a data.frame (15,116 x 13)

+

Frequency table of genus and species from a data.frame (15,152 x 13)

Columns: 2
-Length: 15,116 (of which NA: 0 = 0.00%)
+Length: 15,152 (of which NA: 0 = 0.00%)
Unique: 4

Shortest: 16
Longest: 24

@@ -947,33 +947,33 @@ Longest: 24

1 Escherichia coli -7,472 -49.4% -7,472 -49.4% +7,455 +49.2% +7,455 +49.2% 2 Staphylococcus aureus -3,773 -25.0% -11,245 -74.4% +3,759 +24.8% +11,214 +74.0% 3 Streptococcus pneumoniae -2,296 -15.2% -13,541 -89.6% +2,398 +15.8% +13,612 +89.8% 4 Klebsiella pneumoniae -1,575 -10.4% -15,116 +1,540 +10.2% +15,152 100.0% @@ -984,7 +984,7 @@ Longest: 24

Resistance percentages

The functions portion_S(), portion_SI(), portion_I(), portion_IR() and portion_R() can be used to determine the portion of a specific antimicrobial outcome. As per the EUCAST guideline of 2019, we calculate resistance as the portion of R (portion_R()) and susceptibility as the portion of S and I (portion_SI()). These functions can be used on their own:

data_1st %>% portion_R(AMX)
-# [1] 0.4655994
+# [1] 0.467727

Or can be used in conjuction with group_by() and summarise(), both from the dplyr package:

data_1st %>% 
   group_by(hospital) %>% 
@@ -997,19 +997,19 @@ Longest: 24

Hospital A -0.4690460 +0.4577496 Hospital B -0.4633959 +0.4703985 Hospital C -0.4724376 +0.4736842 Hospital D -0.4590056 +0.4736322 @@ -1027,23 +1027,23 @@ Longest: 24

Hospital A -0.4690460 -4539 +0.4577496 +4568 Hospital B -0.4633959 -5218 +0.4703985 +5270 Hospital C -0.4724376 -2322 +0.4736842 +2280 Hospital D -0.4590056 -3037 +0.4736322 +3034 @@ -1063,27 +1063,27 @@ Longest: 24

Escherichia -0.9243844 -0.8899893 -0.9945128 +0.9238095 +0.8940309 +0.9919517 Klebsiella -0.8101587 -0.8996825 -0.9828571 +0.8285714 +0.9038961 +0.9883117 Staphylococcus -0.9207527 -0.9114763 -0.9912536 +0.9199255 +0.9159351 +0.9938814 Streptococcus -0.6276132 +0.6192661 0.0000000 -0.6276132 +0.6192661 diff --git a/docs/articles/AMR_files/figure-html/plot 1-1.png b/docs/articles/AMR_files/figure-html/plot 1-1.png index adb4667c..5dd75e5e 100644 Binary files a/docs/articles/AMR_files/figure-html/plot 1-1.png and b/docs/articles/AMR_files/figure-html/plot 1-1.png differ diff --git a/docs/articles/AMR_files/figure-html/plot 3-1.png b/docs/articles/AMR_files/figure-html/plot 3-1.png index 915bacde..204bd7d4 100644 Binary files a/docs/articles/AMR_files/figure-html/plot 3-1.png and b/docs/articles/AMR_files/figure-html/plot 3-1.png differ diff --git a/docs/articles/AMR_files/figure-html/plot 4-1.png b/docs/articles/AMR_files/figure-html/plot 4-1.png index 65aae47a..66e14f68 100644 Binary files a/docs/articles/AMR_files/figure-html/plot 4-1.png and b/docs/articles/AMR_files/figure-html/plot 4-1.png differ diff --git a/docs/articles/AMR_files/figure-html/plot 5-1.png b/docs/articles/AMR_files/figure-html/plot 5-1.png index 98f1c4be..46d7d1a8 100644 Binary files a/docs/articles/AMR_files/figure-html/plot 5-1.png and b/docs/articles/AMR_files/figure-html/plot 5-1.png differ diff --git a/docs/articles/EUCAST.html b/docs/articles/EUCAST.html index 81461b30..f18e01d0 100644 --- a/docs/articles/EUCAST.html +++ b/docs/articles/EUCAST.html @@ -40,7 +40,7 @@ AMR (for R) - 0.6.1.9040 + 0.6.1.9044
@@ -199,7 +199,7 @@

How to apply EUCAST rules

Matthijs S. Berends

-

28 May 2019

+

31 May 2019

diff --git a/docs/articles/G_test.html b/docs/articles/G_test.html index d2295463..a53fe4f4 100644 --- a/docs/articles/G_test.html +++ b/docs/articles/G_test.html @@ -40,7 +40,7 @@ AMR (for R) - 0.6.1.9040 + 0.6.1.9044 @@ -199,7 +199,7 @@

How to use the G-test

Matthijs S. Berends

-

28 May 2019

+

31 May 2019

diff --git a/docs/articles/MDR.html b/docs/articles/MDR.html index 366e073d..6b0deeca 100644 --- a/docs/articles/MDR.html +++ b/docs/articles/MDR.html @@ -40,7 +40,7 @@ AMR (for R) - 0.6.1.9040 + 0.6.1.9044 @@ -199,7 +199,7 @@

How to determine multi-drug resistance (MDR)

Matthijs S. Berends

-

28 May 2019

+

31 May 2019

@@ -242,19 +242,19 @@

The data set looks like this now:

head(my_TB_data)
 #   rifampicin isoniazid gatifloxacin ethambutol pyrazinamide moxifloxacin
-# 1          S         S            R          R            S            R
-# 2          R         S            S          S            S            R
-# 3          S         S            S          S            I            I
-# 4          S         I            R          I            I            S
-# 5          S         R            S          R            R            R
-# 6          R         R            R          R            S            S
+# 1          R         R            S          R            R            S
+# 2          I         S            R          R            I            I
+# 3          S         I            R          R            R            R
+# 4          S         R            S          R            R            S
+# 5          S         S            I          S            S            S
+# 6          R         R            S          S            R            S
 #   kanamycin
-# 1         S
-# 2         R
-# 3         R
+# 1         I
+# 2         S
+# 3         S
 # 4         S
-# 5         R
-# 6         I
+# 5 S +# 6 R

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.
@@ -285,40 +285,40 @@ Unique: 5

1 Mono-resistance -3,214 -64.3% -3,214 -64.3% +3,232 +64.6% +3,232 +64.6% 2 Negative -685 -13.7% -3,899 -78.0% +693 +13.9% +3,925 +78.5% 3 Multidrug resistance -576 -11.5% -4,475 -89.5% +603 +12.1% +4,528 +90.6% 4 Poly-resistance -294 -5.9% -4,769 -95.4% +276 +5.5% +4,804 +96.1% 5 Extensive drug resistance -231 -4.6% +196 +3.9% 5,000 100.0% diff --git a/docs/articles/SPSS.html b/docs/articles/SPSS.html index 824388fe..3933169b 100644 --- a/docs/articles/SPSS.html +++ b/docs/articles/SPSS.html @@ -40,7 +40,7 @@ AMR (for R) - 0.6.1.9040 + 0.6.1.9044
@@ -199,7 +199,7 @@

How to import data from SPSS / SAS / Stata

Matthijs S. Berends

-

28 May 2019

+

31 May 2019

diff --git a/docs/articles/WHONET.html b/docs/articles/WHONET.html index 4b86c68f..9e00f2e4 100644 --- a/docs/articles/WHONET.html +++ b/docs/articles/WHONET.html @@ -40,7 +40,7 @@ AMR (for R) - 0.6.1.9040 + 0.6.1.9044 @@ -199,7 +199,7 @@

How to work with WHONET data

Matthijs S. Berends

-

28 May 2019

+

31 May 2019

diff --git a/docs/articles/ab_property.html b/docs/articles/ab_property.html index 8a0fc6ae..4202bd9b 100644 --- a/docs/articles/ab_property.html +++ b/docs/articles/ab_property.html @@ -40,7 +40,7 @@ AMR (for R) - 0.6.1.9040 + 0.6.1.9044 @@ -199,7 +199,7 @@

How to get properties of an antibiotic

Matthijs S. Berends

-

28 May 2019

+

31 May 2019

diff --git a/docs/articles/benchmarks.html b/docs/articles/benchmarks.html index 54d11fea..1242d63c 100644 --- a/docs/articles/benchmarks.html +++ b/docs/articles/benchmarks.html @@ -40,7 +40,7 @@ AMR (for R) - 0.6.1.9040 + 0.6.1.9044 @@ -199,7 +199,7 @@

Benchmarks

Matthijs S. Berends

-

28 May 2019

+

31 May 2019

@@ -224,14 +224,14 @@ times = 10) print(S.aureus, unit = "ms", signif = 2) # Unit: milliseconds -# expr min lq mean median uq max neval -# as.mo("sau") 18.0 18 28 18 18.0 76 10 -# as.mo("stau") 48.0 48 70 48 92.0 130 10 -# as.mo("staaur") 18.0 18 18 18 18.0 19 10 -# as.mo("STAAUR") 17.0 17 27 18 18.0 63 10 -# as.mo("S. aureus") 28.0 28 29 28 29.0 29 10 -# as.mo("S. aureus") 28.0 28 29 28 29.0 30 10 -# as.mo("Staphylococcus aureus") 7.9 8 17 8 8.1 52 10
+# expr min lq mean median uq max neval +# as.mo("sau") 17 18 24 18 18 78.0 10 +# as.mo("stau") 48 48 52 48 48 92.0 10 +# as.mo("staaur") 18 18 27 18 18 62.0 10 +# as.mo("STAAUR") 18 18 18 18 18 18.0 10 +# as.mo("S. aureus") 28 29 46 29 73 73.0 10 +# as.mo("S. aureus") 28 29 42 29 29 110.0 10 +# as.mo("Staphylococcus aureus") 8 8 8 8 8 8.1 10

In the table above, all measurements are shown in milliseconds (thousands of seconds). A value of 5 milliseconds means it can determine 200 input values per second. It case of 100 milliseconds, this is only 10 input values per second. The second input is the only one that has to be looked up thoroughly. All the others are known codes (the first one is a WHONET code) or common laboratory codes, or common full organism names like the last one. Full organism names are always preferred.

To achieve this speed, the as.mo function also takes into account the prevalence of human pathogenic microorganisms. The downside is of course that less prevalent microorganisms will be determined less fast. See this example for the ID of Thermus islandicus (B_THERMS_ISL), a bug probably never found before in humans:

T.islandicus <- microbenchmark(as.mo("theisl"),
@@ -244,10 +244,10 @@
 # Unit: milliseconds
 #                         expr min  lq mean median  uq max neval
 #              as.mo("theisl") 470 470  500    520 520 520    10
-#              as.mo("THEISL") 470 470  490    470 520 520    10
-#       as.mo("T. islandicus")  74  74   79     74  75 120    10
-#      as.mo("T.  islandicus")  74  74   92     74 120 120    10
-#  as.mo("Thermus islandicus")  73  73   80     73  73 140    10
+# as.mo("THEISL") 470 470 500 500 520 520 10 +# as.mo("T. islandicus") 74 74 79 75 76 120 10 +# as.mo("T. islandicus") 74 74 90 74 120 140 10 +# as.mo("Thermus islandicus") 73 73 83 74 76 120 10

That takes 8.1 times as much time on average. A value of 100 milliseconds means it can only determine ~10 different input values per second. We can conclude that looking up arbitrary codes of less prevalent microorganisms is the worst way to go, in terms of calculation performance. Full names (like Thermus islandicus) are almost fast - these are the most probable input from most data sets.

In the figure below, we compare Escherichia coli (which is very common) with Prevotella brevis (which is moderately common) and with Thermus islandicus (which is very uncommon):

par(mar = c(5, 16, 4, 2)) # set more space for left margin text (16)
@@ -294,8 +294,8 @@
 print(run_it, unit = "ms", signif = 3)
 # Unit: milliseconds
 #            expr min  lq mean median  uq max neval
-#  mo_fullname(x) 637 674  745    720 764 936    10
-

So transforming 500,000 values (!!) of 50 unique values only takes 0.72 seconds (720 ms). You only lose time on your unique input values.

+# mo_fullname(x) 725 767 825 792 903 944 10 +

So transforming 500,000 values (!!) of 50 unique values only takes 0.79 seconds (791 ms). You only lose time on your unique input values.

@@ -307,10 +307,10 @@ times = 10) print(run_it, unit = "ms", signif = 3) # Unit: milliseconds -# expr min lq mean median uq max neval -# A 13.10 13.2 13.50 13.40 13.60 14.30 10 -# B 25.50 25.8 30.60 25.80 26.70 70.70 10 -# C 1.62 1.8 1.85 1.81 1.92 2.04 10

+# expr min lq mean median uq max neval +# A 13.20 13.30 17.90 13.40 13.40 58.30 10 +# B 25.60 25.80 26.00 26.00 26.20 26.50 10 +# C 1.62 1.81 1.78 1.81 1.82 1.86 10

So going from mo_fullname("Staphylococcus aureus") to "Staphylococcus aureus" takes 0.0018 seconds - it doesn’t even start calculating if the result would be the same as the expected resulting value. That goes for all helper functions:

run_it <- microbenchmark(A = mo_species("aureus"),
                          B = mo_genus("Staphylococcus"),
@@ -324,14 +324,14 @@
 print(run_it, unit = "ms", signif = 3)
 # Unit: milliseconds
 #  expr   min    lq  mean median    uq   max neval
-#     A 0.517 0.559 0.605  0.582 0.648 0.771    10
-#     B 0.549 0.602 0.681  0.684 0.720 0.856    10
-#     C 1.640 1.710 1.830  1.790 2.000 2.090    10
-#     D 0.620 0.672 0.768  0.759 0.846 0.985    10
-#     E 0.487 0.576 0.659  0.673 0.749 0.834    10
-#     F 0.489 0.590 0.639  0.637 0.692 0.751    10
-#     G 0.471 0.478 0.646  0.689 0.753 0.856    10
-#     H 0.200 0.251 0.348  0.341 0.454 0.531    10
+# A 0.517 0.550 0.608 0.588 0.637 0.839 10 +# B 0.540 0.548 0.666 0.679 0.744 0.829 10 +# C 1.690 1.790 1.880 1.860 1.990 2.050 10 +# D 0.588 0.632 0.704 0.694 0.731 0.944 10 +# E 0.487 0.504 0.629 0.614 0.703 0.920 10 +# F 0.477 0.540 0.587 0.579 0.640 0.754 10 +# G 0.505 0.550 0.628 0.605 0.755 0.768 10 +# H 0.189 0.266 0.294 0.297 0.362 0.379 10

Of course, when running mo_phylum("Firmicutes") the function has zero knowledge about the actual microorganism, namely S. aureus. But since the result would be "Firmicutes" too, there is no point in calculating the result. And because this package ‘knows’ all phyla of all known bacteria (according to the Catalogue of Life), it can just return the initial value immediately.

@@ -358,13 +358,13 @@ print(run_it, unit = "ms", signif = 4) # Unit: milliseconds # expr min lq mean median uq max neval -# en 18.47 18.50 23.02 18.55 18.75 62.99 10 -# de 23.26 23.35 23.55 23.52 23.75 23.93 10 -# nl 36.79 36.90 50.46 37.27 81.55 81.90 10 -# es 23.28 23.40 27.94 23.50 23.64 67.84 10 -# it 23.12 23.23 23.38 23.33 23.60 23.67 10 -# fr 23.30 23.38 23.61 23.47 23.86 24.32 10 -# pt 23.33 23.38 23.63 23.64 23.87 23.95 10
+# en 18.45 18.51 18.69 18.72 18.78 19.01 10 +# de 23.32 23.41 23.67 23.45 24.00 24.41 10 +# nl 36.79 36.88 41.71 37.39 37.57 81.66 10 +# es 23.32 23.39 23.75 23.65 23.93 24.82 10 +# it 23.31 23.33 33.07 23.38 29.77 69.13 10 +# fr 23.33 23.38 27.93 23.43 23.55 67.91 10 +# pt 23.35 23.38 28.12 23.47 23.82 67.82 10

Currently supported are German, Dutch, Spanish, Italian, French and Portuguese.

diff --git a/docs/articles/benchmarks_files/figure-html/unnamed-chunk-5-1.png b/docs/articles/benchmarks_files/figure-html/unnamed-chunk-5-1.png index 1644365b..7b546a3d 100644 Binary files a/docs/articles/benchmarks_files/figure-html/unnamed-chunk-5-1.png and b/docs/articles/benchmarks_files/figure-html/unnamed-chunk-5-1.png differ diff --git a/docs/articles/freq.html b/docs/articles/freq.html index b0a3dd52..a7055f34 100644 --- a/docs/articles/freq.html +++ b/docs/articles/freq.html @@ -40,7 +40,7 @@ AMR (for R) - 0.6.1.9042 + 0.6.1.9044 @@ -199,7 +199,7 @@

How to create frequency tables

Matthijs S. Berends

-

29 May 2019

+

31 May 2019

diff --git a/docs/articles/index.html b/docs/articles/index.html index 94f10ec0..c7404fc2 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -78,7 +78,7 @@ AMR (for R) - 0.6.1.9043 + 0.6.1.9044 diff --git a/docs/articles/mo_property.html b/docs/articles/mo_property.html index b8d982e0..48aa0834 100644 --- a/docs/articles/mo_property.html +++ b/docs/articles/mo_property.html @@ -40,7 +40,7 @@ AMR (for R) - 0.6.1.9040 + 0.6.1.9044 @@ -199,7 +199,7 @@

How to get properties of a microorganism

Matthijs S. Berends

-

28 May 2019

+

31 May 2019

diff --git a/docs/articles/resistance_predict.html b/docs/articles/resistance_predict.html index 554ed231..6b303754 100644 --- a/docs/articles/resistance_predict.html +++ b/docs/articles/resistance_predict.html @@ -40,7 +40,7 @@ AMR (for R) - 0.6.1.9040 + 0.6.1.9044 @@ -199,7 +199,7 @@

How to predict antimicrobial resistance

Matthijs S. Berends

-

28 May 2019

+

31 May 2019

diff --git a/docs/authors.html b/docs/authors.html index 8a1fd759..5221cdff 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -78,7 +78,7 @@ AMR (for R) - 0.6.1.9043 + 0.6.1.9044 diff --git a/docs/index.html b/docs/index.html index e0e6061f..03d64f74 100644 --- a/docs/index.html +++ b/docs/index.html @@ -42,7 +42,7 @@ AMR (for R) - 0.6.1.9043 + 0.6.1.9044 diff --git a/docs/news/index.html b/docs/news/index.html index 75e59ab8..d50c1034 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -78,7 +78,7 @@ AMR (for R) - 0.6.1.9043 + 0.6.1.9044 @@ -258,6 +258,7 @@

Changed