diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7cf67639..9593a551 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -20,7 +20,7 @@ # ==================================================================== # # to check with R-Hub: -# rhub::check_for_cran(devtools::build(args = c('--no-build-vignettes'))) +# chck <- rhub::check_for_cran(devtools::build(args = c('--no-build-vignettes'))) stages: - build @@ -124,18 +124,10 @@ coverage: pages: stage: deploy when: always - #cache: - # key: "$CI_COMMIT_REF_SLUG" - # paths: - # - installed_deps/ only: - master script: - mv docs public - # 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)' - #- Rscript -e "devtools::install(build = TRUE, upgrade = FALSE)" - #- R -e "pkgdown::build_site(examples = FALSE, lazy = TRUE, override = list(destination = 'public'))" artifacts: paths: - public diff --git a/DESCRIPTION b/DESCRIPTION index 46650a03..1c5d092e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: AMR -Version: 0.7.0.9009 -Date: 2019-06-13 +Version: 0.7.0.9010 +Date: 2019-06-16 Title: Antimicrobial Resistance Analysis Authors@R: c( person( diff --git a/NAMESPACE b/NAMESPACE index 043ce300..42610ec1 100755 --- a/NAMESPACE +++ b/NAMESPACE @@ -154,6 +154,7 @@ export(mo_renamed) export(mo_shortname) export(mo_species) export(mo_subspecies) +export(mo_synonyms) export(mo_taxonomy) export(mo_type) export(mo_uncertainties) diff --git a/NEWS.md b/NEWS.md index 700f8233..57ef0325 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,7 +1,7 @@ -# AMR 0.7.0.9009 +# AMR 0.7.0.9010 #### New -* Function `rsi_df()` to transform a `data.frame` to a data set containing only the microbial interpretation (S, I, R), the antibiotic, the percentage of S/I/R and the number of available isolates. This is a convenient combinations of existing functions `count_df()` and `portion_df()` to immediately show resistance percentages and number of available isolates: +* Function `rsi_df()` to transform a `data.frame` to a data set containing only the microbial interpretation (S, I, R), the antibiotic, the percentage of S/I/R and the number of available isolates. This is a convenient combination of the existing functions `count_df()` and `portion_df()` to immediately show resistance percentages and number of available isolates: ```r septic_patients %>% select(AMX, CIP) %>% @@ -12,14 +12,31 @@ # 3 Ciprofloxacin SI 0.8381831 1181 # 4 Ciprofloxacin R 0.1618169 228 ``` -* Support for all scientifically published pathotypes of *E. coli* to date. Supported are: AIEC (Adherent-Invasive *E. coli*), ATEC (Atypical Entero-pathogenic *E. coli*), DAEC (Diffusely Adhering *E. coli*), EAEC (Entero-Aggresive *E. coli*), EHEC (Entero-Haemorrhagic *E. coli*), EIEC (Entero-Invasive *E. coli*), EPEC (Entero-Pathogenic *E. coli*), ETEC (Entero-Toxigenic *E. coli*), NMEC (Neonatal Meningitis‐causing *E. coli*), STEC (Shiga-toxin producing *E. coli*) and UPEC (Uropathogenic *E. coli*). All these lead to the microbial ID of *E. coli*: +* Support for all scientifically published pathotypes of *E. coli* to date. Supported are: + + * AIEC (Adherent-Invasive *E. coli*) + * ATEC (Atypical Entero-pathogenic *E. coli*) + * DAEC (Diffusely Adhering *E. coli*) + * EAEC (Entero-Aggresive *E. coli*) + * EHEC (Entero-Haemorrhagic *E. coli*) + * EIEC (Entero-Invasive *E. coli*) + * EPEC (Entero-Pathogenic *E. coli*) + * ETEC (Entero-Toxigenic *E. coli*) + * NMEC (Neonatal Meningitis‐causing *E. coli*) + * STEC (Shiga-toxin producing *E. coli*) + * UPEC (Uropathogenic *E. coli*) + + All these lead to the microbial ID of *E. coli*: ```r as.mo("UPEC") # B_ESCHR_COL - mo_fullname("UPEC") + mo_name("UPEC") # "Escherichia coli" + mo_gramstain("EHEC") + # "Gram-negative" ``` * Function `mo_info()` as an analogy to `ab_info()`. The `mo_info()` prints a list with the full taxonomy, authors, and the URL to the online database of a microorganism +* Function `mo_synonyms()` to get all previously accepted taxonomic names of a microorganism #### Changed * Column names of output `count_df()` and `portion_df()` are now lowercase @@ -36,6 +53,7 @@ * Removed antibiotic code `PVM1` from the `antibiotics` data set as this was a duplicate of `PME` * Fixed bug where not all old taxonomic named would not be printed when using a vector as input for `as.mo()` * Manually added *Trichomonas vaginalis* from the kingdom of Protozoa, which is missing from the Catalogue of Life +* Small improvements to `plot()` and `barplot()` for MIC and RSI classes #### Other * Fixed a note thrown by CRAN tests diff --git a/R/count.R b/R/count.R index 7c275b11..9fd8a69b 100755 --- a/R/count.R +++ b/R/count.R @@ -33,7 +33,7 @@ #' #' The function \code{count_df} takes any variable from \code{data} that has an \code{"rsi"} class (created with \code{\link{as.rsi}}) and counts the amounts of S, I and R. The resulting \emph{tidy data} (see Source) \code{data.frame} will have three rows (S/I/R) and a column for each variable with class \code{"rsi"}. #' -#' The function \code{rsi_df} works exactly like \code{count_df}, but add the percentage of S, I and R. +#' The function \code{rsi_df} works exactly like \code{count_df}, but adds the percentage of S, I and R. #' @source Wickham H. \strong{Tidy Data.} The Journal of Statistical Software, vol. 59, 2014. \url{http://vita.had.co.nz/papers/tidy-data.html} #' @seealso \code{\link{portion}_*} to calculate microbial resistance and susceptibility. #' @keywords resistance susceptibility rsi antibiotics isolate isolates diff --git a/R/mic.R b/R/mic.R index ea71c3da..0ef5206f 100755 --- a/R/mic.R +++ b/R/mic.R @@ -242,34 +242,38 @@ summary.mic <- function(object, ...) { #' @exportMethod plot.mic #' @export -#' @importFrom dplyr %>% group_by summarise -#' @importFrom graphics plot text +#' @importFrom graphics barplot axis #' @noRd -plot.mic <- function(x, ...) { - x_name <- deparse(substitute(x)) - create_barplot_mic(x, x_name, ...) +plot.mic <- function(x, + main = paste('MIC values of', deparse(substitute(x))), + ylab = 'Frequency', + xlab = 'MIC value', + axes = FALSE, + ...) { + barplot(table(droplevels.factor(x)), + ylab = ylab, + xlab = xlab, + axes = axes, + main = main, + ...) + axis(2, seq(0, max(table(droplevels.factor(x))))) } #' @exportMethod barplot.mic #' @export #' @importFrom graphics barplot axis #' @noRd -barplot.mic <- function(height, ...) { - x_name <- deparse(substitute(height)) - create_barplot_mic(height, x_name, ...) -} - -#' @importFrom graphics barplot axis -#' @importFrom dplyr %>% group_by summarise -create_barplot_mic <- function(x, x_name, ...) { - data <- data.frame(mic = droplevels(x), cnt = 1) %>% - group_by(mic) %>% - summarise(cnt = sum(cnt)) - barplot(table(droplevels.factor(x)), - ylab = 'Frequency', - xlab = 'MIC value', - main = paste('MIC values of', x_name), - axes = FALSE, +barplot.mic <- function(height, + main = paste('MIC values of', deparse(substitute(height))), + ylab = 'Frequency', + xlab = 'MIC value', + axes = FALSE, + ...) { + barplot(table(droplevels.factor(height)), + ylab = ylab, + xlab = xlab, + axes = axes, + main = main, ...) - axis(2, seq(0, max(data$cnt))) + axis(2, seq(0, max(table(droplevels.factor(height))))) } diff --git a/R/misc.R b/R/misc.R index f1ace71b..3e5f150c 100755 --- a/R/misc.R +++ b/R/misc.R @@ -307,5 +307,14 @@ translate_AMR <- function(from, language = get_locale(), only_unknown = FALSE) { } "%or%" <- function(x, y) { - ifelse(!is.na(x), x, ifelse(!is.na(y), y, NA)) + if (is.null(x) | is.null(y)) { + if (is.null(x)) { + return(y) + } else { + return(x) + } + } + ifelse(!is.na(x), + x, + ifelse(!is.na(y), y, NA)) } diff --git a/R/mo_property.R b/R/mo_property.R index 69b95e83..e02bdae8 100755 --- a/R/mo_property.R +++ b/R/mo_property.R @@ -73,6 +73,7 @@ #' mo_type("E. coli") # "Bacteria" (equal to kingdom, but may be translated) #' mo_rank("E. coli") # "species" #' mo_url("E. coli") # get the direct url to the online database entry +#' mo_synonyms("E. coli") # get previously accepted taxonomic names #' #' ## scientific reference #' mo_ref("E. coli") # "Castellani et al., 1919" @@ -312,12 +313,24 @@ mo_taxonomy <- function(x, language = get_locale(), ...) { subspecies = mo_subspecies(x, language = language)) } +#' @rdname mo_property +#' @export +mo_synonyms <- function(x, ...) { + x <- AMR::as.mo(x, ...) + col_id <- AMR::microorganisms[which(AMR::microorganisms$mo == x), "col_id"] + if (is.na(col_id) | !col_id %in% AMR::microorganisms.old$col_id_new) { + return(NULL) + } + sort(AMR::microorganisms.old[which(AMR::microorganisms.old$col_id_new == col_id), "fullname"]) +} + #' @rdname mo_property #' @export mo_info <- function(x, language = get_locale(), ...) { x <- AMR::as.mo(x, ...) c(mo_taxonomy(x, language = language), - list(url = unname(mo_url(x, open = FALSE)), + list(synonyms = mo_synonyms(x), + url = unname(mo_url(x, open = FALSE)), ref = mo_ref(x))) } diff --git a/R/portion.R b/R/portion.R index 9bf11ab4..3474b52a 100755 --- a/R/portion.R +++ b/R/portion.R @@ -40,7 +40,7 @@ #' #' The function \code{portion_df} takes any variable from \code{data} that has an \code{"rsi"} class (created with \code{\link{as.rsi}}) and calculates the portions R, I and S. The resulting \emph{tidy data} (see Source) \code{data.frame} will have three rows (S/I/R) and a column for each group and each variable with class \code{"rsi"}. #' -#' The function \code{rsi_df} works exactly like \code{portion_df}, but add the number of isolates. +#' The function \code{rsi_df} works exactly like \code{portion_df}, but adds the number of isolates. #' \if{html}{ # (created with https://www.latex4technics.com/) #' \cr\cr diff --git a/R/rsi.R b/R/rsi.R index c0f83de4..2b749987 100755 --- a/R/rsi.R +++ b/R/rsi.R @@ -387,9 +387,14 @@ summary.rsi <- function(object, ...) { #' @importFrom dplyr %>% group_by summarise filter mutate if_else n_distinct #' @importFrom graphics plot text #' @noRd -plot.rsi <- function(x, ...) { - x_name <- deparse(substitute(x)) - +plot.rsi <- function(x, + lwd = 2, + ylim = NULL, + ylab = 'Percentage', + xlab = 'Antimicrobial Interpretation', + main = paste('Susceptibility Analysis of', deparse(substitute(x))), + axes = FALSE, + ...) { suppressWarnings( data <- data.frame(x = x, y = 1, @@ -415,13 +420,12 @@ plot.rsi <- function(x, ...) { plot(x = data$x, y = data$s, - lwd = 2, - col = c('green', 'orange', 'red'), + lwd = lwd, ylim = c(0, ymax), - ylab = 'Percentage', - xlab = 'Antimicrobial Interpretation', - main = paste('Susceptibility Analysis of', x_name), - axes = FALSE, + ylab = ylab, + xlab = xlab, + main = main, + axes = axes, ...) # x axis axis(side = 1, at = 1:n_distinct(data$x), labels = levels(data$x), lwd = 0) @@ -439,24 +443,32 @@ plot.rsi <- function(x, ...) { #' @importFrom dplyr %>% group_by summarise #' @importFrom graphics barplot axis #' @noRd -barplot.rsi <- function(height, ...) { - x <- height - x_name <- deparse(substitute(height)) +barplot.rsi <- function(height, + col = c('green3', 'orange2', 'red3'), + xlab = ifelse(beside, 'Antimicrobial Interpretation', ''), + main = paste('Susceptibility Analysis of', deparse(substitute(height))), + ylab = 'Frequency', + beside = TRUE, + axes = beside, + ...) { - suppressWarnings( - data <- data.frame(rsi = x, cnt = 1) %>% - group_by(rsi) %>% - summarise(cnt = sum(cnt)) %>% - droplevels() - ) + if (axes == TRUE) { + par(mar = c(5, 4, 4, 2) + 0.1) + } else { + par(mar = c(2, 4, 4, 2) + 0.1) + } - barplot(table(x), - col = c('green3', 'orange2', 'red3'), - xlab = 'Antimicrobial Interpretation', - main = paste('Susceptibility Analysis of', x_name), - ylab = 'Frequency', + barplot(as.matrix(table(height)), + col = col, + xlab = xlab, + main = main, + ylab = ylab, + beside = beside, axes = FALSE, ...) # y axis, 0-100% - axis(side = 2, at = seq(0, max(data$cnt) + max(data$cnt) * 1.1, by = 25)) + axis(side = 2, at = seq(0, max(table(height)) + max(table(height)) * 1.1, by = 25)) + if (axes == TRUE && beside == TRUE) { + axis(side = 1, labels = levels(height), at = c(1, 2, 3) + 0.5, lwd = 0) + } } diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index 134750b1..49765907 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -78,7 +78,7 @@ AMR (for R) - 0.7.0.9009 + 0.7.0.9010 diff --git a/docs/articles/AMR.html b/docs/articles/AMR.html index 32705737..139af9fb 100644 --- a/docs/articles/AMR.html +++ b/docs/articles/AMR.html @@ -40,7 +40,7 @@ AMR (for R) - 0.7.0.9000 + 0.7.0.9009 @@ -125,13 +125,6 @@ Create frequency tables -
  • - - - - Use the G-test - -
  • @@ -199,7 +192,7 @@

    How to conduct AMR analysis

    Matthijs S. Berends

    -

    07 June 2019

    +

    15 June 2019

    @@ -208,7 +201,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 07 June 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 15 June 2019.

    Introduction

    @@ -224,21 +217,21 @@ -2019-06-07 +2019-06-15 abcd Escherichia coli S S -2019-06-07 +2019-06-15 abcd Escherichia coli S R -2019-06-07 +2019-06-15 efgh Escherichia coli R @@ -278,7 +271,7 @@

    Dates

    -

    Let’s pretend that our data consists of blood cultures isolates from 1 January 2010 until 1 January 2018.

    +

    Let’s pretend that our data consists of blood cultures isolates from between 1 January 2010 and 1 January 2018.

    dates <- seq(as.Date("2010-01-01"), as.Date("2018-01-01"), by = "day")

    This dates object now contains all days in our date range.

    @@ -318,7 +311,7 @@ )

    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:

    -

    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:

    +

    The resulting data set contains 20,000 blood culture isolates. With the head() function we can preview the first 6 values of this data set:

    head(data)
    @@ -334,71 +327,71 @@ - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - - - - - - - - - - - + - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    2010-01-26S3Hospital BEscherichia coliRIRSF
    2010-08-26G7Hospital DEscherichia coliRSSSM
    2016-05-04B82010-06-23R10 Hospital AEscherichia coliSSRSM
    2016-11-19E10Hospital D Streptococcus pneumoniae S S S SM
    2013-07-13G3Hospital AEscherichia coliRSSSMF
    2017-05-23V3Hospital CStaphylococcus aureus2016-04-09R1Hospital DKlebsiella pneumoniae S S S S F
    2017-01-27U10Hospital AStreptococcus pneumoniaeRSRSF
    2017-05-23C4Hospital BKlebsiella pneumoniaeRSRSM
    2015-03-27W3Hospital BEscherichia coliSSSSF
    2014-06-14L5Hospital AEscherichia coliSSSSM

    Now, let’s start the cleaning and the analysis!

    @@ -418,9 +411,9 @@ # # Item Count Percent Cum. Count Cum. Percent # --- ----- ------- -------- ----------- ------------- -# 1 M 10,368 51.8% 10,368 51.8% -# 2 F 9,632 48.2% 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.

    +# 1 M 10,341 51.7% 10,341 51.7% +# 2 F 9,659 48.3% 20,000 100.0% +

    So, we can draw at least two conclusions immediately. From a data scientists perspective, the data looks clean: only values M and F. From a researchers perspective: there are slightly more men. Nothing we didn’t already know.

    The data is already quite clean, but we still need to transform some variables. The bacteria column now consists of text, and we want to add more variables based on microbial IDs later on. So, we will transform this column to valid IDs. The mutate() function of the dplyr package makes this really easy:

    data <- data %>%
       mutate(bacteria = as.mo(bacteria))
    @@ -437,8 +430,8 @@ # EUCAST Clinical Breakpoints (v9.0, 2019) # Aerococcus sanguinicola (no new changes) # Aerococcus urinae (no new changes) -# Anaerobic Gram negatives (no new changes) -# Anaerobic Gram positives (no new changes) +# Anaerobic Gram-negatives (no new changes) +# Anaerobic Gram-positives (no new changes) # Campylobacter coli (no new changes) # Campylobacter jejuni (no new changes) # Enterobacteriales (Order) (no new changes) @@ -449,14 +442,14 @@ # Pasteurella multocida (no new changes) # Staphylococcus (no new changes) # Streptococcus groups A, B, C, G (no new changes) -# Streptococcus pneumoniae (1,496 new changes) +# Streptococcus pneumoniae (1,478 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 (1,276 new changes) +# Table 01: Intrinsic resistance in Enterobacteriaceae (1,340 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 (2,809 new changes) +# Table 04: Intrinsic resistance in Gram-positive bacteria (2,785 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 +457,24 @@ # Table 13: Interpretive rules for quinolones (no new changes) # # Other rules -# Non-EUCAST: amoxicillin/clav acid = S where ampicillin = S (2,244 new changes) -# Non-EUCAST: ampicillin = R where amoxicillin/clav acid = R (111 new changes) +# Non-EUCAST: amoxicillin/clav acid = S where ampicillin = S (2,164 new changes) +# Non-EUCAST: ampicillin = R where amoxicillin/clav acid = R (105 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,565 out of 20,000 rows, making a total of 7,936 edits +# EUCAST rules affected 6,519 out of 20,000 rows, making a total of 7,872 edits # => added 0 test results # -# => changed 7,936 test results -# - 116 test results changed from S to I -# - 4,801 test results changed from S to R -# - 1,059 test results changed from I to S -# - 347 test results changed from I to R -# - 1,596 test results changed from R to S -# - 17 test results changed from R to I +# => changed 7,872 test results +# - 122 test results changed from S to I +# - 4,775 test results changed from S to R +# - 1,060 test results changed from I to S +# - 316 test results changed from I to R +# - 1,581 test results changed from R to S +# - 18 test results changed from R to I # -------------------------------------------------------------------------- # # Use verbose = TRUE to get a data.frame with all specified edits instead.
    @@ -509,8 +502,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,692 first isolates (28.5% of total)
    -

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

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

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

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

    @@ -520,7 +513,7 @@

    First weighted isolates

    -

    We made a slight twist to the CLSI algorithm, to take into account the antimicrobial susceptibility profile. Imagine this data, sorted on date:

    +

    We made a slight twist to the CLSI algorithm, to take into account the antimicrobial susceptibility profile. Have a look at all isolates of patient V3, sorted on date:

    @@ -536,21 +529,21 @@ - - + + - + - - + + - + @@ -558,10 +551,10 @@ - - + + - + @@ -569,19 +562,19 @@ - - + + + - - + - - + + @@ -591,41 +584,41 @@ - - + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - + + @@ -635,18 +628,18 @@ - - + + + - - +
    isolate
    12010-01-16V92010-01-06V3 B_ESCHR_COL S S SSR TRUE
    22010-02-23V92010-07-24V3 B_ESCHR_COLSR S S S
    32010-04-05V92010-07-26V3 B_ESCHR_COLSR S S S
    42010-04-28V92011-05-06V3 B_ESCHR_COLR S S SSFALSETRUE
    52010-05-20V92011-06-04V3 B_ESCHR_COL S S
    62010-07-07V92011-07-22V3 B_ESCHR_COL S SSSFALSE
    72011-08-15V3B_ESCHR_COLIISRFALSE
    82011-09-20V3B_ESCHR_COLRS R S FALSE
    72010-09-11V9B_ESCHR_COLSSSSFALSE
    82010-09-19V9B_ESCHR_COLSSSSFALSE
    92010-10-07V92012-03-26V3 B_ESCHR_COL S S
    102011-01-14V92012-06-01V3 B_ESCHR_COL RI S SSFALSETRUE
    -

    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.

    +

    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:

    +# => Found 15,202 first weighted isolates (76.0% of total)
    @@ -674,34 +667,34 @@ - - + + - + - - + + - + - + - - + + - + @@ -710,95 +703,95 @@ - - + + + - - - + + - - + + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - - + + + - - + - + - - + + - - - - - - - - - - - - + + + + + + + + + + + +
    isolate
    12010-01-16V92010-01-06V3 B_ESCHR_COL S S SSR TRUE TRUE
    22010-02-23V92010-07-24V3 B_ESCHR_COLSR S S S FALSEFALSETRUE
    32010-04-05V92010-07-26V3 B_ESCHR_COLSR S S S
    42010-04-28V92011-05-06V3 B_ESCHR_COLR S S SSFALSEFALSETRUETRUE
    52010-05-20V92011-06-04V3 B_ESCHR_COL S S S S FALSEFALSE
    62010-07-07V9B_ESCHR_COLSSRSFALSE TRUE
    72010-09-11V9
    62011-07-22V3 B_ESCHR_COL S S S S FALSEFALSE
    72011-08-15V3B_ESCHR_COLIISRFALSE TRUE
    82010-09-19V92011-09-20V3 B_ESCHR_COLR SSSR S FALSEFALSETRUE
    92010-10-07V92012-03-26V3 B_ESCHR_COL S S S S FALSEFALSE
    102011-01-14V9B_ESCHR_COLRSSSFALSETRUE
    102012-06-01V3B_ESCHR_COLRISSTRUE TRUE
    -

    Instead of 1, now 4 isolates are flagged. In total, 75.4% of all isolates are marked ‘first weighted’ - 46.9% 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 8 isolates are flagged. In total, 76% of all isolates are marked ‘first weighted’ - 47.7% 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,072 isolates for analysis.

    +

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

    We can remove unneeded columns:

    data_1st <- data_1st %>% 
       select(-c(first, keyab))
    @@ -806,7 +799,6 @@
    head(data_1st)
    - @@ -823,89 +815,68 @@ - - - - - - - - + + + + + + + - - - + + + - - - + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - - - + + + + + + + + + + + + + + + + + @@ -913,7 +884,22 @@ - + + + + + + + + + + + + + + + + @@ -935,9 +921,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 data_1st (15,072 x 13)

    +

    Frequency table of genus and species from data_1st (15,202 x 13)

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

    Shortest: 16
    Longest: 24

    @@ -954,33 +940,33 @@ Longest: 24

    - - - - + + + + - - - - + + + + - - - - + + + + - - - + + + @@ -991,7 +977,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.4620488
    +# [1] 0.4678332

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

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

    - + - + - + - +
    date patient_id hospital
    12010-01-26S3Hospital BB_ESCHR_COLRIR2010-06-23R10Hospital AB_STRPT_PNE SSSR FGram negativeEscherichiacoliGram-positiveStreptococcuspneumoniae TRUE
    22010-08-26G72016-04-09R1 Hospital DB_ESCHR_COLB_KLBSL_PNE R S S SMGram negativeEscherichiacoliTRUE
    32016-05-04B8Hospital AB_ESCHR_COLSSRSMGram negativeEscherichiacoliTRUE
    52013-07-13G3Hospital AB_ESCHR_COLRSSSMGram negativeEscherichiacoliTRUE
    82016-11-20Y6Hospital AB_ESCHR_COLSSRS FGram negativeEscherichiacoliGram-negativeKlebsiellapneumoniaeTRUE
    2017-01-27U10Hospital AB_STRPT_PNERRRRFGram-positiveStreptococcuspneumoniae TRUE
    102015-11-03W82017-05-23C4Hospital BB_KLBSL_PNERSRSMGram-negativeKlebsiellapneumoniaeTRUE
    2015-03-27W3 Hospital B B_ESCHR_COL SS S FGram negativeGram-negativeEscherichiacoliTRUE
    2014-06-14L5Hospital AB_ESCHR_COLSSSSMGram-negative Escherichia coli TRUE
    1 Escherichia coli7,45149.4%7,45149.4%7,48549.2%7,48549.2%
    2 Staphylococcus aureus3,71324.6%11,16474.1%3,75824.7%11,24374.0%
    3 Streptococcus pneumoniae2,36715.7%13,53189.8%2,37115.6%13,61489.6%
    4 Klebsiella pneumoniae1,54110.2%15,0721,58810.4%15,202 100.0%
    Hospital A0.44721980.4688237
    Hospital B0.46845640.4693374
    Hospital C0.46624940.4641460
    Hospital D0.47049070.4664644
    @@ -1034,23 +1020,23 @@ Longest: 24

    Hospital A -0.4472198 -4604 +0.4688237 +4667 Hospital B -0.4684564 -5215 +0.4693374 +5267 Hospital C -0.4662494 -2237 +0.4641460 +2301 Hospital D -0.4704907 -3016 +0.4664644 +2967 @@ -1070,27 +1056,27 @@ Longest: 24

    Escherichia -0.9256476 -0.8916924 -0.9938263 +0.9249165 +0.8956580 +0.9929192 Klebsiella -0.8208955 -0.8974692 -0.9883193 +0.8413098 +0.8992443 +0.9911839 Staphylococcus -0.9237813 -0.9165096 -0.9929976 +0.9169771 +0.9161788 +0.9949441 Streptococcus -0.6138572 +0.6280051 0.0000000 -0.6138572 +0.6280051 @@ -1100,10 +1086,10 @@ Longest: 24

    summarise("1. Amoxi/clav" = portion_SI(AMC), "2. Gentamicin" = portion_SI(GEN), "3. Amoxi/clav + genta" = portion_SI(AMC, GEN)) %>% - tidyr::gather("Antibiotic", "S", -genus) %>% + tidyr::gather("antibiotic", "S", -genus) %>% ggplot(aes(x = genus, y = S, - fill = Antibiotic)) + + fill = antibiotic)) + geom_col(position = "dodge2")

    @@ -1127,7 +1113,7 @@ Longest: 24

    ggplot(data_1st) +
       geom_rsi(translate_ab = FALSE)

    -

    Omit the translate_ab = FALSE to have the antibiotic codes (AMX, AMC, CIP, GEN) translated to official WHO names (amoxicillin, amoxicillin and betalactamase inhibitor, ciprofloxacin, gentamicin).

    +

    Omit the translate_ab = FALSE to have the antibiotic codes (AMX, AMC, CIP, GEN) translated to official WHO names (amoxicillin, amoxicillin/clavulanic acid, ciprofloxacin, gentamicin).

    If we group on e.g. the genus column and add some additional functions from our package, we can create this:

    # group the data on `genus`
     ggplot(data_1st %>% group_by(genus)) + 
    @@ -1136,7 +1122,7 @@ Longest: 24

    # of which we have 4 (earlier created with `as.rsi`) geom_rsi(x = "genus") + # split plots on antibiotic - facet_rsi(facet = "Antibiotic") + + facet_rsi(facet = "antibiotic") + # make R red, I yellow and S green scale_rsi_colours() + # show percentages on y axis @@ -1154,7 +1140,7 @@ Longest: 24

    @@ -1164,48 +1150,35 @@ Longest: 24

    Independence test

    The next example uses the included septic_patients, which is an anonymised data set containing 2,000 microbial blood culture isolates with their full antibiograms found in septic patients in 4 different hospitals in the Netherlands, between 2001 and 2017. It is true, genuine data. This data.frame can be used to practice AMR analysis.

    -

    We will compare the resistance to fosfomycin (column FOS) in hospital A and D. The input for the final fisher.test() will be this:

    - - - - - - - - - - - - - - - - - - -
    AD
    IR2577
    S2433
    -

    We can transform the data and apply the test in only a couple of lines:

    -
    septic_patients %>%
    +

    We will compare the resistance to fosfomycin (column FOS) in hospital A and D. The input for the fisher.test() can be retrieved with a transformation like this:

    +
    check_FOS <- septic_patients %>%
       filter(hospital_id %in% c("A", "D")) %>% # filter on only hospitals A and D
       select(hospital_id, FOS) %>%             # select the hospitals and fosfomycin
       group_by(hospital_id) %>%                # group on the hospitals
    -  count_df(combine_IR = TRUE) %>%          # count all isolates per group (hospital_id)
    -  tidyr::spread(hospital_id, Value) %>%    # transform output so A and D are columns
    +  count_df(combine_SI = TRUE) %>%          # count all isolates per group (hospital_id)
    +  tidyr::spread(hospital_id, value) %>%    # transform output so A and D are columns
       select(A, D) %>%                         # and select these only
    -  as.matrix() %>%                          # transform to good old matrix for fisher.test()
    -  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:
    -#  0.2111489 0.9485124
    -# sample estimates:
    -# odds ratio 
    -#  0.4488318
    -

    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.

    + as.matrix() # transform to good old matrix for fisher.test() + +check_FOS +# A D +# [1,] 25 77 +# [2,] 24 33
    +

    We can apply the test now with:

    + +

    As can be seen, the p value is 0.031, which means that the fosfomycin resistances found in hospital A and D are really different.

    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 cdba2c03..7779e67f 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 0da9a2a4..ea7fc39e 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 65f4096e..7a389df4 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 1d5f719a..ce42294a 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/index.html b/docs/articles/index.html index 671aade0..44019d58 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -78,7 +78,7 @@ AMR (for R) - 0.7.0.9009 + 0.7.0.9010 diff --git a/docs/authors.html b/docs/authors.html index 805227fc..16f3829b 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -78,7 +78,7 @@ AMR (for R) - 0.7.0.9009 + 0.7.0.9010 diff --git a/docs/index.html b/docs/index.html index ec2301ca..49e9f15e 100644 --- a/docs/index.html +++ b/docs/index.html @@ -42,7 +42,7 @@ AMR (for R) - 0.7.0.9009 + 0.7.0.9010 diff --git a/docs/news/index.html b/docs/news/index.html index fc8a7f2a..335dad40 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -78,7 +78,7 @@ AMR (for R) - 0.7.0.9009 + 0.7.0.9010 @@ -232,16 +232,16 @@ -
    +

    -AMR 0.7.0.9009 Unreleased +AMR 0.7.0.9010 Unreleased

    New

    • -

      Function rsi_df() to transform a data.frame to a data set containing only the microbial interpretation (S, I, R), the antibiotic, the percentage of S/I/R and the number of available isolates. This is a convenient combinations of existing functions count_df() and portion_df() to immediately show resistance percentages and number of available isolates:

      +

      Function rsi_df() to transform a data.frame to a data set containing only the microbial interpretation (S, I, R), the antibiotic, the percentage of S/I/R and the number of available isolates. This is a convenient combination of the existing functions count_df() and portion_df() to immediately show resistance percentages and number of available isolates:

    • -

      Support for all scientifically published pathotypes of E. coli to date. Supported are: AIEC (Adherent-Invasive E. coli), ATEC (Atypical Entero-pathogenic E. coli), DAEC (Diffusely Adhering E. coli), EAEC (Entero-Aggresive E. coli), EHEC (Entero-Haemorrhagic E. coli), EIEC (Entero-Invasive E. coli), EPEC (Entero-Pathogenic E. coli), ETEC (Entero-Toxigenic E. coli), NMEC (Neonatal Meningitis‐causing E. coli), STEC (Shiga-toxin producing E. coli) and UPEC (Uropathogenic E. coli). All these lead to the microbial ID of E. coli:

      +

      Support for all scientifically published pathotypes of E. coli to date. Supported are:

      +
        +
      • AIEC (Adherent-Invasive E. coli)
      • +
      • ATEC (Atypical Entero-pathogenic E. coli)
      • +
      • DAEC (Diffusely Adhering E. coli)
      • +
      • EAEC (Entero-Aggresive E. coli)
      • +
      • EHEC (Entero-Haemorrhagic E. coli)
      • +
      • EIEC (Entero-Invasive E. coli)
      • +
      • EPEC (Entero-Pathogenic E. coli)
      • +
      • ETEC (Entero-Toxigenic E. coli)
      • +
      • NMEC (Neonatal Meningitis‐causing E. coli)
      • +
      • STEC (Shiga-toxin producing E. coli)
      • +
      • UPEC (Uropathogenic E. coli)
      • +
      +

      All these lead to the microbial ID of E. coli:

      +mo_name("UPEC") +# "Escherichia coli" +mo_gramstain("EHEC") +# "Gram-negative"
  • -
  • Function mo_info() as an analogy to ab_info(). The mo_info() prints a list with the full taxonomy, authors, and the URL to the online database of a microorganism

  • +
  • Function mo_info() as an analogy to ab_info(). The mo_info() prints a list with the full taxonomy, authors, and the URL to the online database of a microorganism
  • +
  • Function mo_synonyms() to get all previously accepted taxonomic names of a microorganism

  • @@ -283,6 +300,7 @@
  • Fixed bug where not all old taxonomic named would not be printed when using a vector as input for as.mo()
  • Manually added Trichomonas vaginalis from the kingdom of Protozoa, which is missing from the Catalogue of Life
  • +
  • Small improvements to plot() and barplot() for MIC and RSI classes
  • @@ -1121,7 +1139,7 @@ Using as.mo(..., allow_uncertain = 3)

    Contents

    @@ -165,13 +165,6 @@ Create frequency tables -
  • - - - - Use the G-test - -
  • diff --git a/docs/reference/AMR.html b/docs/reference/AMR.html index 777e2b5d..41e0f71f 100644 --- a/docs/reference/AMR.html +++ b/docs/reference/AMR.html @@ -80,7 +80,7 @@ AMR (for R) - 0.7.0.9000 + 0.7.0.9009 @@ -165,13 +165,6 @@ Create frequency tables
  • -
  • - - - - Use the G-test - -
  • diff --git a/docs/reference/WHOCC.html b/docs/reference/WHOCC.html index 346a8304..b8d90fe8 100644 --- a/docs/reference/WHOCC.html +++ b/docs/reference/WHOCC.html @@ -80,7 +80,7 @@ AMR (for R) - 0.7.0.9000 + 0.7.0.9009 @@ -165,13 +165,6 @@ Create frequency tables
  • -
  • - - - - Use the G-test - -
  • diff --git a/docs/reference/WHONET.html b/docs/reference/WHONET.html index 3889679d..a6e962a9 100644 --- a/docs/reference/WHONET.html +++ b/docs/reference/WHONET.html @@ -80,7 +80,7 @@ AMR (for R) - 0.7.0.9000 + 0.7.0.9009 @@ -165,13 +165,6 @@ Create frequency tables
  • -
  • - - - - Use the G-test - -
  • diff --git a/docs/reference/ab_property.html b/docs/reference/ab_property.html index a05a094e..b31e4131 100644 --- a/docs/reference/ab_property.html +++ b/docs/reference/ab_property.html @@ -80,7 +80,7 @@ AMR (for R) - 0.7.0.9000 + 0.7.0.9009 @@ -165,13 +165,6 @@ Create frequency tables
  • -
  • - - - - Use the G-test - -
  • diff --git a/docs/reference/age.html b/docs/reference/age.html index d54be194..b0657a03 100644 --- a/docs/reference/age.html +++ b/docs/reference/age.html @@ -80,7 +80,7 @@ AMR (for R) - 0.7.0.9000 + 0.7.0.9009 @@ -165,13 +165,6 @@ Create frequency tables
  • -
  • - - - - Use the G-test - -
  • diff --git a/docs/reference/age_groups.html b/docs/reference/age_groups.html index 53f0970a..2932d4c6 100644 --- a/docs/reference/age_groups.html +++ b/docs/reference/age_groups.html @@ -80,7 +80,7 @@ AMR (for R) - 0.7.0.9000 + 0.7.0.9009 @@ -165,13 +165,6 @@ Create frequency tables
  • -
  • - - - - Use the G-test - -
  • diff --git a/docs/reference/antibiotics.html b/docs/reference/antibiotics.html index 9a966624..8fd92f2e 100644 --- a/docs/reference/antibiotics.html +++ b/docs/reference/antibiotics.html @@ -80,7 +80,7 @@ AMR (for R) - 0.7.0.9005 + 0.7.0.9009 diff --git a/docs/reference/as.ab.html b/docs/reference/as.ab.html index 7a0f6b22..da9d3743 100644 --- a/docs/reference/as.ab.html +++ b/docs/reference/as.ab.html @@ -80,7 +80,7 @@ AMR (for R) - 0.7.0.9000 + 0.7.0.9009 @@ -165,13 +165,6 @@ Create frequency tables
  • -
  • - - - - Use the G-test - -
  • diff --git a/docs/reference/as.atc.html b/docs/reference/as.atc.html index ae03b133..9743ac63 100644 --- a/docs/reference/as.atc.html +++ b/docs/reference/as.atc.html @@ -80,7 +80,7 @@ AMR (for R) - 0.7.0.9000 + 0.7.0.9009 @@ -165,13 +165,6 @@ Create frequency tables
  • -
  • - - - - Use the G-test - -
  • diff --git a/docs/reference/as.disk.html b/docs/reference/as.disk.html index 9b5b2bde..13691eed 100644 --- a/docs/reference/as.disk.html +++ b/docs/reference/as.disk.html @@ -80,7 +80,7 @@ AMR (for R) - 0.7.0.9000 + 0.7.0.9009 @@ -165,13 +165,6 @@ Create frequency tables
  • -
  • - - - - Use the G-test - -
  • diff --git a/docs/reference/as.mic.html b/docs/reference/as.mic.html index 050ee0de..d666316e 100644 --- a/docs/reference/as.mic.html +++ b/docs/reference/as.mic.html @@ -80,7 +80,7 @@ AMR (for R) - 0.7.0.9000 + 0.7.0.9009 @@ -165,13 +165,6 @@ Create frequency tables
  • -
  • - - - - Use the G-test - -
  • diff --git a/docs/reference/as.mo.html b/docs/reference/as.mo.html index 7b6c4c50..c40288d4 100644 --- a/docs/reference/as.mo.html +++ b/docs/reference/as.mo.html @@ -80,7 +80,7 @@ AMR (for R) - 0.7.0.9000 + 0.7.0.9009 @@ -165,13 +165,6 @@ Create frequency tables
  • -
  • - - - - Use the G-test - -
  • diff --git a/docs/reference/as.rsi.html b/docs/reference/as.rsi.html index b1575447..0fc87a5b 100644 --- a/docs/reference/as.rsi.html +++ b/docs/reference/as.rsi.html @@ -80,7 +80,7 @@ AMR (for R) - 0.7.0.9000 + 0.7.0.9009 @@ -165,13 +165,6 @@ Create frequency tables
  • -
  • - - - - Use the G-test - -
  • diff --git a/docs/reference/atc_online.html b/docs/reference/atc_online.html index abeca252..3db83e71 100644 --- a/docs/reference/atc_online.html +++ b/docs/reference/atc_online.html @@ -80,7 +80,7 @@ AMR (for R) - 0.7.0.9000 + 0.7.0.9009 @@ -165,13 +165,6 @@ Create frequency tables
  • -
  • - - - - Use the G-test - -
  • diff --git a/docs/reference/availability.html b/docs/reference/availability.html index 87a4ed80..8fa96a1f 100644 --- a/docs/reference/availability.html +++ b/docs/reference/availability.html @@ -80,7 +80,7 @@ AMR (for R) - 0.7.0.9000 + 0.7.0.9009 @@ -165,13 +165,6 @@ Create frequency tables
  • -
  • - - - - Use the G-test - -
  • diff --git a/docs/reference/catalogue_of_life.html b/docs/reference/catalogue_of_life.html index 76812308..e18b85f2 100644 --- a/docs/reference/catalogue_of_life.html +++ b/docs/reference/catalogue_of_life.html @@ -80,7 +80,7 @@ AMR (for R) - 0.7.0.9005 + 0.7.0.9009 diff --git a/docs/reference/catalogue_of_life_version.html b/docs/reference/catalogue_of_life_version.html index 785c0aae..f31976e9 100644 --- a/docs/reference/catalogue_of_life_version.html +++ b/docs/reference/catalogue_of_life_version.html @@ -80,7 +80,7 @@ AMR (for R) - 0.7.0.9005 + 0.7.0.9009 diff --git a/docs/reference/count.html b/docs/reference/count.html index 86edb721..1c696b20 100644 --- a/docs/reference/count.html +++ b/docs/reference/count.html @@ -81,7 +81,7 @@ count_R and count_IR can be used to count resistant isolates, count_S and count_ AMR (for R) - 0.7.0.9008 + 0.7.0.9009 diff --git a/docs/reference/eucast_rules.html b/docs/reference/eucast_rules.html index a27d729a..c9558b24 100644 --- a/docs/reference/eucast_rules.html +++ b/docs/reference/eucast_rules.html @@ -80,7 +80,7 @@ AMR (for R) - 0.7.0.9000 + 0.7.0.9009 @@ -165,13 +165,6 @@ Create frequency tables
  • -
  • - - - - Use the G-test - -
  • diff --git a/docs/reference/extended-functions.html b/docs/reference/extended-functions.html index 7bb4019a..ad3c83a5 100644 --- a/docs/reference/extended-functions.html +++ b/docs/reference/extended-functions.html @@ -80,7 +80,7 @@ AMR (for R) - 0.7.0.9003 + 0.7.0.9009 @@ -165,13 +165,6 @@ Create frequency tables
  • -
  • - - - - Use the G-test - -
  • diff --git a/docs/reference/filter_ab_class.html b/docs/reference/filter_ab_class.html index 83ff16bb..46639864 100644 --- a/docs/reference/filter_ab_class.html +++ b/docs/reference/filter_ab_class.html @@ -80,7 +80,7 @@ AMR (for R) - 0.7.0.9000 + 0.7.0.9009 @@ -165,13 +165,6 @@ Create frequency tables
  • -
  • - - - - Use the G-test - -
  • diff --git a/docs/reference/first_isolate.html b/docs/reference/first_isolate.html index df152276..748e086e 100644 --- a/docs/reference/first_isolate.html +++ b/docs/reference/first_isolate.html @@ -80,7 +80,7 @@ AMR (for R) - 0.7.0.9000 + 0.7.0.9009 @@ -165,13 +165,6 @@ Create frequency tables
  • -
  • - - - - Use the G-test - -
  • diff --git a/docs/reference/freq.html b/docs/reference/freq.html index 0b3eb902..8b9c6824 100644 --- a/docs/reference/freq.html +++ b/docs/reference/freq.html @@ -81,7 +81,7 @@ top_freq can be used to get the top/bottom n items of a frequency table, with co AMR (for R) - 0.7.0.9000 + 0.7.0.9009 @@ -166,13 +166,6 @@ top_freq can be used to get the top/bottom n items of a frequency table, with co Create frequency tables
  • -
  • - - - - Use the G-test - -
  • diff --git a/docs/reference/g.test.html b/docs/reference/g.test.html index 73c9a79b..7ca7beba 100644 --- a/docs/reference/g.test.html +++ b/docs/reference/g.test.html @@ -80,7 +80,7 @@ AMR (for R) - 0.7.0.9000 + 0.7.0.9009 @@ -165,13 +165,6 @@ Create frequency tables
  • -
  • - - - - Use the G-test - -
  • diff --git a/docs/reference/ggplot_rsi.html b/docs/reference/ggplot_rsi.html index fbfff211..bb7fe742 100644 --- a/docs/reference/ggplot_rsi.html +++ b/docs/reference/ggplot_rsi.html @@ -80,7 +80,7 @@ AMR (for R) - 0.7.0.9008 + 0.7.0.9009 diff --git a/docs/reference/guess_ab_col.html b/docs/reference/guess_ab_col.html index 53cd0964..28494847 100644 --- a/docs/reference/guess_ab_col.html +++ b/docs/reference/guess_ab_col.html @@ -80,7 +80,7 @@ AMR (for R) - 0.7.0.9000 + 0.7.0.9009 @@ -165,13 +165,6 @@ Create frequency tables
  • -
  • - - - - Use the G-test - -
  • diff --git a/docs/reference/index.html b/docs/reference/index.html index f0003488..e83858dd 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -78,7 +78,7 @@ AMR (for R) - 0.7.0.9009 + 0.7.0.9010 @@ -373,7 +373,7 @@ -

    mo_name() mo_fullname() mo_shortname() mo_subspecies() mo_species() mo_genus() mo_family() mo_order() mo_class() mo_phylum() mo_kingdom() mo_type() mo_gramstain() mo_ref() mo_authors() mo_year() mo_rank() mo_taxonomy() mo_info() mo_url() mo_property()

    +

    mo_name() mo_fullname() mo_shortname() mo_subspecies() mo_species() mo_genus() mo_family() mo_order() mo_class() mo_phylum() mo_kingdom() mo_type() mo_gramstain() mo_ref() mo_authors() mo_year() mo_rank() mo_taxonomy() mo_synonyms() mo_info() mo_url() mo_property()

    Property of a microorganism

    diff --git a/docs/reference/join.html b/docs/reference/join.html index 0d1fdd4c..4b400f16 100644 --- a/docs/reference/join.html +++ b/docs/reference/join.html @@ -80,7 +80,7 @@ AMR (for R) - 0.7.0.9000 + 0.7.0.9009 @@ -165,13 +165,6 @@ Create frequency tables
  • -
  • - - - - Use the G-test - -
  • diff --git a/docs/reference/key_antibiotics.html b/docs/reference/key_antibiotics.html index 5cc65ab1..d71dc71f 100644 --- a/docs/reference/key_antibiotics.html +++ b/docs/reference/key_antibiotics.html @@ -80,7 +80,7 @@ AMR (for R) - 0.7.0.9005 + 0.7.0.9009 diff --git a/docs/reference/kurtosis.html b/docs/reference/kurtosis.html index 0d8f6403..5c824b5a 100644 --- a/docs/reference/kurtosis.html +++ b/docs/reference/kurtosis.html @@ -80,7 +80,7 @@ AMR (for R) - 0.7.0.9000 + 0.7.0.9009 @@ -165,13 +165,6 @@ Create frequency tables
  • -
  • - - - - Use the G-test - -
  • diff --git a/docs/reference/like.html b/docs/reference/like.html index facf19f3..bca87135 100644 --- a/docs/reference/like.html +++ b/docs/reference/like.html @@ -80,7 +80,7 @@ AMR (for R) - 0.7.0.9000 + 0.7.0.9009 @@ -165,13 +165,6 @@ Create frequency tables
  • -
  • - - - - Use the G-test - -
  • diff --git a/docs/reference/mdro.html b/docs/reference/mdro.html index 498df3d2..4c518ce1 100644 --- a/docs/reference/mdro.html +++ b/docs/reference/mdro.html @@ -80,7 +80,7 @@ AMR (for R) - 0.7.0.9000 + 0.7.0.9009 @@ -165,13 +165,6 @@ Create frequency tables
  • -
  • - - - - Use the G-test - -
  • diff --git a/docs/reference/microorganisms.codes.html b/docs/reference/microorganisms.codes.html index 25ec1f57..73a6c795 100644 --- a/docs/reference/microorganisms.codes.html +++ b/docs/reference/microorganisms.codes.html @@ -80,7 +80,7 @@ AMR (for R) - 0.7.0.9000 + 0.7.0.9009 @@ -165,13 +165,6 @@ Create frequency tables
  • -
  • - - - - Use the G-test - -
  • diff --git a/docs/reference/microorganisms.html b/docs/reference/microorganisms.html index 7c0f2a1e..0cbffeb4 100644 --- a/docs/reference/microorganisms.html +++ b/docs/reference/microorganisms.html @@ -80,7 +80,7 @@ AMR (for R) - 0.7.0.9008 + 0.7.0.9009 diff --git a/docs/reference/microorganisms.old.html b/docs/reference/microorganisms.old.html index 9fd9860e..81d197bb 100644 --- a/docs/reference/microorganisms.old.html +++ b/docs/reference/microorganisms.old.html @@ -80,7 +80,7 @@ AMR (for R) - 0.7.0.9000 + 0.7.0.9009 @@ -165,13 +165,6 @@ Create frequency tables
  • -
  • - - - - Use the G-test - -
  • diff --git a/docs/reference/mo_property.html b/docs/reference/mo_property.html index 8acbf27c..453923bd 100644 --- a/docs/reference/mo_property.html +++ b/docs/reference/mo_property.html @@ -80,7 +80,7 @@ AMR (for R) - 0.7.0.9005 + 0.7.0.9010 @@ -277,6 +277,8 @@ mo_taxonomy(x, language = get_locale(), ...) +mo_synonyms(x, ...) + mo_info(x, language = get_locale(), ...) mo_url(x, open = FALSE, ...) @@ -377,6 +379,7 @@ This package contains the complete taxonomic tree of almost all microorganisms ( mo_type("E. coli") # "Bacteria" (equal to kingdom, but may be translated) mo_rank("E. coli") # "species" mo_url("E. coli") # get the direct url to the online database entry +mo_synonyms("E. coli") # get previously accepted taxonomic names ## scientific reference mo_ref("E. coli") # "Castellani et al., 1919" diff --git a/docs/reference/mo_source.html b/docs/reference/mo_source.html index 9a1d90fe..3362275b 100644 --- a/docs/reference/mo_source.html +++ b/docs/reference/mo_source.html @@ -81,7 +81,7 @@ This is the fastest way to have your organisation (or analysis) specific codes p AMR (for R) - 0.7.0.9000 + 0.7.0.9009 @@ -166,13 +166,6 @@ This is the fastest way to have your organisation (or analysis) specific codes p Create frequency tables
  • -
  • - - - - Use the G-test - -
  • diff --git a/docs/reference/p.symbol.html b/docs/reference/p.symbol.html index bb3b58f2..db83ed22 100644 --- a/docs/reference/p.symbol.html +++ b/docs/reference/p.symbol.html @@ -80,7 +80,7 @@ AMR (for R) - 0.7.0.9000 + 0.7.0.9009 @@ -165,13 +165,6 @@ Create frequency tables
  • -
  • - - - - Use the G-test - -
  • diff --git a/docs/reference/portion.html b/docs/reference/portion.html index ff3984a5..481c85ba 100644 --- a/docs/reference/portion.html +++ b/docs/reference/portion.html @@ -81,7 +81,7 @@ portion_R and portion_IR can be used to calculate resistance, portion_S and port AMR (for R) - 0.7.0.9008 + 0.7.0.9009 diff --git a/docs/reference/read.4D.html b/docs/reference/read.4D.html index 37f6f7ab..ed9931dd 100644 --- a/docs/reference/read.4D.html +++ b/docs/reference/read.4D.html @@ -80,7 +80,7 @@ AMR (for R) - 0.7.0.9000 + 0.7.0.9009 @@ -165,13 +165,6 @@ Create frequency tables
  • -
  • - - - - Use the G-test - -
  • diff --git a/docs/reference/resistance_predict.html b/docs/reference/resistance_predict.html index 8027d992..045aba48 100644 --- a/docs/reference/resistance_predict.html +++ b/docs/reference/resistance_predict.html @@ -80,7 +80,7 @@ AMR (for R) - 0.7.0.9000 + 0.7.0.9009 @@ -165,13 +165,6 @@ Create frequency tables
  • -
  • - - - - Use the G-test - -
  • diff --git a/docs/reference/rsi_translation.html b/docs/reference/rsi_translation.html index ca7a3fc3..55fea168 100644 --- a/docs/reference/rsi_translation.html +++ b/docs/reference/rsi_translation.html @@ -80,7 +80,7 @@ AMR (for R) - 0.7.0.9000 + 0.7.0.9009 @@ -165,13 +165,6 @@ Create frequency tables
  • -
  • - - - - Use the G-test - -
  • diff --git a/docs/reference/septic_patients.html b/docs/reference/septic_patients.html index dc7dcbff..2f9c1827 100644 --- a/docs/reference/septic_patients.html +++ b/docs/reference/septic_patients.html @@ -80,7 +80,7 @@ AMR (for R) - 0.7.0.9000 + 0.7.0.9009 @@ -165,13 +165,6 @@ Create frequency tables
  • -
  • - - - - Use the G-test - -
  • diff --git a/docs/reference/skewness.html b/docs/reference/skewness.html index 9a53d605..7b928cc0 100644 --- a/docs/reference/skewness.html +++ b/docs/reference/skewness.html @@ -81,7 +81,7 @@ When negative: the left tail is longer; the mass of the distribution is concentr AMR (for R) - 0.7.0.9000 + 0.7.0.9009 @@ -166,13 +166,6 @@ When negative: the left tail is longer; the mass of the distribution is concentr Create frequency tables
  • -
  • - - - - Use the G-test - -
  • diff --git a/docs/reference/translate.html b/docs/reference/translate.html index 21a5d223..1455c090 100644 --- a/docs/reference/translate.html +++ b/docs/reference/translate.html @@ -80,7 +80,7 @@ AMR (for R) - 0.7.0.9000 + 0.7.0.9009 @@ -165,13 +165,6 @@ Create frequency tables
  • -
  • - - - - Use the G-test - -
  • diff --git a/git_merge.sh b/git_merge.sh index 3631323d..cc6755f7 100755 --- a/git_merge.sh +++ b/git_merge.sh @@ -13,15 +13,15 @@ git add . git commit -a -m "website update" --quiet git checkout master --quiet -echo "changed branch to master" +echo "• changed branch to master" # import everything from premaster git merge premaster --quiet # and send it to git git push --quiet -echo "pushed changes to master" +echo "• pushed changes to master" # return to premaster git checkout premaster --quiet -echo "changed branch back to premaster" +echo "• changed branch back to premaster" git status --short diff --git a/man/count.Rd b/man/count.Rd index e38f7252..0dc75372 100644 --- a/man/count.Rd +++ b/man/count.Rd @@ -62,7 +62,7 @@ The function \code{n_rsi} is an alias of \code{count_all}. They can be used to c The function \code{count_df} takes any variable from \code{data} that has an \code{"rsi"} class (created with \code{\link{as.rsi}}) and counts the amounts of S, I and R. The resulting \emph{tidy data} (see Source) \code{data.frame} will have three rows (S/I/R) and a column for each variable with class \code{"rsi"}. -The function \code{rsi_df} works exactly like \code{count_df}, but add the percentage of S, I and R. +The function \code{rsi_df} works exactly like \code{count_df}, but adds the percentage of S, I and R. } \section{Interpretation of S, I and R}{ diff --git a/man/mo_property.Rd b/man/mo_property.Rd index b4fcb2be..7b8195a6 100644 --- a/man/mo_property.Rd +++ b/man/mo_property.Rd @@ -20,6 +20,7 @@ \alias{mo_year} \alias{mo_rank} \alias{mo_taxonomy} +\alias{mo_synonyms} \alias{mo_info} \alias{mo_url} \title{Property of a microorganism} @@ -60,6 +61,8 @@ mo_rank(x, ...) mo_taxonomy(x, language = get_locale(), ...) +mo_synonyms(x, ...) + mo_info(x, language = get_locale(), ...) mo_url(x, open = FALSE, ...) @@ -147,6 +150,7 @@ mo_gramstain("E. coli") # "Gram-negative" mo_type("E. coli") # "Bacteria" (equal to kingdom, but may be translated) mo_rank("E. coli") # "species" mo_url("E. coli") # get the direct url to the online database entry +mo_synonyms("E. coli") # get previously accepted taxonomic names ## scientific reference mo_ref("E. coli") # "Castellani et al., 1919" diff --git a/man/portion.Rd b/man/portion.Rd index eefc4028..208f0100 100644 --- a/man/portion.Rd +++ b/man/portion.Rd @@ -73,7 +73,7 @@ These functions are not meant to count isolates, but to calculate the portion of The function \code{portion_df} takes any variable from \code{data} that has an \code{"rsi"} class (created with \code{\link{as.rsi}}) and calculates the portions R, I and S. The resulting \emph{tidy data} (see Source) \code{data.frame} will have three rows (S/I/R) and a column for each group and each variable with class \code{"rsi"}. -The function \code{rsi_df} works exactly like \code{portion_df}, but add the number of isolates. +The function \code{rsi_df} works exactly like \code{portion_df}, but adds the number of isolates. \if{html}{ \cr\cr To calculate the probability (\emph{p}) of susceptibility of one antibiotic, we use this formula: diff --git a/tests/testthat/test-mo_property.R b/tests/testthat/test-mo_property.R index 38f13d16..4ef7080d 100644 --- a/tests/testthat/test-mo_property.R +++ b/tests/testthat/test-mo_property.R @@ -22,34 +22,37 @@ context("mo_property.R") test_that("mo_property works", { - expect_equal(mo_kingdom("E. coli"), "Bacteria") - expect_equal(mo_phylum("E. coli"), "Proteobacteria") - expect_equal(mo_class("E. coli"), "Gammaproteobacteria") - expect_equal(mo_order("E. coli"), "Enterobacteriales") - expect_equal(mo_family("E. coli"), "Enterobacteriaceae") - expect_equal(mo_genus("E. coli"), "Escherichia") - expect_equal(mo_species("E. coli"), "coli") - expect_equal(mo_subspecies("E. coli"), "") - expect_equal(mo_fullname("E. coli"), "Escherichia coli") - expect_equal(mo_name("E. coli"), "Escherichia coli") - expect_equal(mo_type("E. coli", language = "en"), "Bacteria") - expect_equal(mo_gramstain("E. coli", language = "en"), "Gram-negative") - expect_equal(class(mo_taxonomy("E. coli")), "list") - expect_equal(names(mo_taxonomy("E. coli")), c("kingdom", "phylum", "class", "order", + expect_equal(mo_kingdom("Escherichia coli"), "Bacteria") + expect_equal(mo_phylum("Escherichia coli"), "Proteobacteria") + expect_equal(mo_class("Escherichia coli"), "Gammaproteobacteria") + expect_equal(mo_order("Escherichia coli"), "Enterobacteriales") + expect_equal(mo_family("Escherichia coli"), "Enterobacteriaceae") + expect_equal(mo_genus("Escherichia coli"), "Escherichia") + expect_equal(mo_species("Escherichia coli"), "coli") + expect_equal(mo_subspecies("Escherichia coli"), "") + expect_equal(mo_fullname("Escherichia coli"), "Escherichia coli") + expect_equal(mo_name("Escherichia coli"), "Escherichia coli") + expect_equal(mo_type("Escherichia coli", language = "en"), "Bacteria") + expect_equal(mo_gramstain("Escherichia coli", language = "en"), "Gram-negative") + expect_equal(class(mo_taxonomy("Escherichia coli")), "list") + expect_equal(names(mo_taxonomy("Escherichia coli")), c("kingdom", "phylum", "class", "order", "family", "genus", "species", "subspecies")) - expect_equal(names(mo_info("E. coli")), c("kingdom", "phylum", "class", "order", + expect_equal(mo_synonyms("Escherichia coli"), NULL) + expect_gt(length(mo_synonyms("C. albicans")), 1) + expect_equal(names(mo_info("Escherichia coli")), c("kingdom", "phylum", "class", "order", "family", "genus", "species", "subspecies", - "url", "ref")) + "synonyms", "url", "ref")) - expect_equal(mo_ref("E. coli"), "Castellani et al., 1919") - expect_equal(mo_authors("E. coli"), "Castellani et al.") - expect_equal(mo_year("E. coli"), 1919) + expect_equal(mo_ref("Escherichia coli"), "Castellani et al., 1919") + expect_equal(mo_authors("Escherichia coli"), "Castellani et al.") + expect_equal(mo_year("Escherichia coli"), 1919) - expect_equal(mo_shortname("MRSA"), "S. aureus") - expect_equal(mo_shortname("MRSA", Becker = TRUE), "S. aureus") - expect_equal(mo_shortname("MRSA", Becker = "all", language = "en"), "CoPS") - expect_equal(mo_shortname("S. agalac"), "S. agalactiae") - expect_equal(mo_shortname("S. agalac", Lancefield = TRUE), "GBS") + expect_equal(mo_shortname("Escherichia coli"), "E. coli") + expect_equal(mo_shortname("Staphylococcus aureus"), "S. aureus") + expect_equal(mo_shortname("Staphylococcus aureus", Becker = TRUE), "S. aureus") + expect_equal(mo_shortname("Staphylococcus aureus", Becker = "all", language = "en"), "CoPS") + expect_equal(mo_shortname("Streptococcus agalactiae"), "S. agalactiae") + expect_equal(mo_shortname("Streptococcus agalactiae", Lancefield = TRUE), "GBS") expect_true(mo_url("Escherichia coli") %like% "www.catalogueoflife.org") @@ -58,28 +61,28 @@ test_that("mo_property works", { expect_identical(MOs$fullname, mo_fullname(MOs$fullname, language = "en")) # check languages - expect_equal(mo_type("E. coli", language = "de"), "Bakterien") - expect_equal(mo_gramstain("E. coli", language = "nl"), "Gram-negatief") + expect_equal(mo_type("Escherichia coli", language = "de"), "Bakterien") + expect_equal(mo_gramstain("Escherichia coli", language = "nl"), "Gram-negatief") - expect_output(print(mo_gramstain("E. coli", language = "en"))) - expect_output(print(mo_gramstain("E. coli", language = "de"))) - expect_output(print(mo_gramstain("E. coli", language = "nl"))) - expect_output(print(mo_gramstain("E. coli", language = "es"))) - expect_output(print(mo_gramstain("E. coli", language = "pt"))) - expect_output(print(mo_gramstain("E. coli", language = "it"))) - expect_output(print(mo_gramstain("E. coli", language = "fr"))) + expect_output(print(mo_gramstain("Escherichia coli", language = "en"))) + expect_output(print(mo_gramstain("Escherichia coli", language = "de"))) + expect_output(print(mo_gramstain("Escherichia coli", language = "nl"))) + expect_output(print(mo_gramstain("Escherichia coli", language = "es"))) + expect_output(print(mo_gramstain("Escherichia coli", language = "pt"))) + expect_output(print(mo_gramstain("Escherichia coli", language = "it"))) + expect_output(print(mo_gramstain("Escherichia coli", language = "fr"))) - expect_error(mo_gramstain("E. coli", language = "UNKNOWN")) + expect_error(mo_gramstain("Escherichia coli", language = "UNKNOWN")) # manual property function - expect_error(mo_property("E. coli", property = c("tsn", "fullname"))) - expect_error(mo_property("E. coli", property = "UNKNOWN")) - expect_identical(mo_property("E. coli", property = "fullname"), - mo_fullname("E. coli")) - expect_identical(mo_property("E. coli", property = "genus"), - mo_genus("E. coli")) - expect_identical(mo_property("E. coli", property = "species"), - mo_species("E. coli")) + expect_error(mo_property("Escherichia coli", property = c("tsn", "fullname"))) + expect_error(mo_property("Escherichia coli", property = "UNKNOWN")) + expect_identical(mo_property("Escherichia coli", property = "fullname"), + mo_fullname("Escherichia coli")) + expect_identical(mo_property("Escherichia coli", property = "genus"), + mo_genus("Escherichia coli")) + expect_identical(mo_property("Escherichia coli", property = "species"), + mo_species("Escherichia coli")) expect_identical(suppressWarnings(mo_ref("Chlamydia psittaci")), "Page, 1968") expect_identical(mo_ref("Chlamydophila psittaci"), "Everett et al., 1999") @@ -87,14 +90,13 @@ test_that("mo_property works", { # outcome of mo_fullname must always return the fullname from the data set library(dplyr) - a <- microorganisms %>% + x <- microorganisms %>% transmute(mo, # fullname from the original data: f1 = fullname, # newly created fullname based on MO code: f2 = mo_fullname(mo, language = "en")) %>% filter(f1 != f2) - - expect_equal(nrow(a), 0) + expect_equal(nrow(x), 0) }) diff --git a/vignettes/AMR.Rmd b/vignettes/AMR.Rmd index 44cd5a31..97fbef2e 100755 --- a/vignettes/AMR.Rmd +++ b/vignettes/AMR.Rmd @@ -78,7 +78,7 @@ patients_table <- data.frame(patient_id = patients, The first 135 patient IDs are now male, the other 125 are female. ## Dates -Let's pretend that our data consists of blood cultures isolates from 1 January 2010 until 1 January 2018. +Let's pretend that our data consists of blood cultures isolates from between 1 January 2010 and 1 January 2018. ```{r create dates} dates <- seq(as.Date("2010-01-01"), as.Date("2018-01-01"), by = "day") @@ -131,7 +131,7 @@ Using the `left_join()` function from the `dplyr` package, we can 'map' the gend 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: +The resulting data set contains `r format(nrow(data), big.mark = ",")` blood culture isolates. With the `head()` function we can preview the first 6 values of this data set: ```{r preview data set 1, eval = FALSE} head(data) @@ -154,7 +154,7 @@ data %>% freq(gender) # this would be the same: freq(data$gender) data %>% freq(gender, markdown = FALSE, header = TRUE) ``` -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. +So, we can draw at least two conclusions immediately. From a data scientists perspective, the data looks clean: only values `M` and `F`. From a researchers perspective: there are slightly more men. Nothing we didn't already know. The data is already quite clean, but we still need to transform some variables. The `bacteria` column now consists of text, and we want to add more variables based on microbial IDs later on. So, we will transform this column to valid IDs. The `mutate()` function of the `dplyr` package makes this really easy: @@ -219,7 +219,6 @@ data_1st <- data %>% ``` ## First *weighted* isolates -We made a slight twist to the CLSI algorithm, to take into account the antimicrobial susceptibility profile. Imagine this data, sorted on date: ```{r, echo = FALSE, message = FALSE, warning = FALSE, results = 'asis'} weighted_df <- data %>% @@ -232,7 +231,11 @@ weighted_df <- data %>% .[1:min(10, nrow(.)),] %>% mutate(isolate = row_number()) %>% select(isolate, everything()) +``` +We made a slight twist to the CLSI algorithm, to take into account the antimicrobial susceptibility profile. Have a look at all isolates of patient `r as.data.frame(weighted_df[1, 'patient_id'])`, sorted on date: + +```{r, echo = FALSE, message = FALSE, warning = FALSE, results = 'asis'} weighted_df %>% knitr::kable(align = "c") ``` @@ -378,10 +381,10 @@ data_1st %>% summarise("1. Amoxi/clav" = portion_SI(AMC), "2. Gentamicin" = portion_SI(GEN), "3. Amoxi/clav + genta" = portion_SI(AMC, GEN)) %>% - tidyr::gather("Antibiotic", "S", -genus) %>% + tidyr::gather("antibiotic", "S", -genus) %>% ggplot(aes(x = genus, y = S, - fill = Antibiotic)) + + fill = antibiotic)) + geom_col(position = "dodge2") ``` @@ -410,7 +413,7 @@ ggplot(data_1st) + geom_rsi(translate_ab = FALSE) ``` -Omit the `translate_ab = FALSE` to have the antibiotic codes (AMX, AMC, CIP, GEN) translated to official WHO names (amoxicillin, amoxicillin and betalactamase inhibitor, ciprofloxacin, gentamicin). +Omit the `translate_ab = FALSE` to have the antibiotic codes (AMX, AMC, CIP, GEN) translated to official WHO names (amoxicillin, amoxicillin/clavulanic acid, ciprofloxacin, gentamicin). If we group on e.g. the `genus` column and add some additional functions from our package, we can create this: @@ -422,7 +425,7 @@ ggplot(data_1st %>% group_by(genus)) + # of which we have 4 (earlier created with `as.rsi`) geom_rsi(x = "genus") + # split plots on antibiotic - facet_rsi(facet = "Antibiotic") + + facet_rsi(facet = "antibiotic") + # make R red, I yellow and S green scale_rsi_colours() + # show percentages on y axis @@ -443,7 +446,7 @@ To simplify this, we also created the `ggplot_rsi()` function, which combines al data_1st %>% group_by(genus) %>% ggplot_rsi(x = "genus", - facet = "Antibiotic", + facet = "antibiotic", breaks = 0:4 * 25, datalabels = FALSE) + coord_flip() @@ -453,33 +456,26 @@ data_1st %>% The next example uses the included `septic_patients`, which is an anonymised data set containing 2,000 microbial blood culture isolates with their full antibiograms found in septic patients in 4 different hospitals in the Netherlands, between 2001 and 2017. It is true, genuine data. This `data.frame` can be used to practice AMR analysis. -We will compare the resistance to fosfomycin (column `FOS`) in hospital A and D. The input for the final `fisher.test()` will be this: +We will compare the resistance to fosfomycin (column `FOS`) in hospital A and D. The input for the `fisher.test()` can be retrieved with a transformation like this: -```{r, echo = FALSE, results = 'asis'} -septic_patients %>% - filter(hospital_id %in% c("A", "D")) %>% - select(hospital_id, FOS) %>% - group_by(hospital_id) %>% - count_df(combine_IR = TRUE) %>% - tidyr::spread(hospital_id, Value) %>% - select(A, D) %>% - bind_cols(tibble(" " = c("IR", "S")), .) %>% - as.matrix() %>% - knitr::kable() -``` - -We can transform the data and apply the test in only a couple of lines: - -```{r} -septic_patients %>% +```{r, results = 'markup'} +check_FOS <- septic_patients %>% filter(hospital_id %in% c("A", "D")) %>% # filter on only hospitals A and D select(hospital_id, FOS) %>% # select the hospitals and fosfomycin group_by(hospital_id) %>% # group on the hospitals - count_df(combine_IR = TRUE) %>% # count all isolates per group (hospital_id) - tidyr::spread(hospital_id, Value) %>% # transform output so A and D are columns + count_df(combine_SI = TRUE) %>% # count all isolates per group (hospital_id) + tidyr::spread(hospital_id, value) %>% # transform output so A and D are columns select(A, D) %>% # and select these only - as.matrix() %>% # transform to good old matrix for fisher.test() - fisher.test() # do Fisher's Exact Test + as.matrix() # transform to good old matrix for fisher.test() + +check_FOS ``` -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. +We can apply the test now with: + +```{r} +# do Fisher's Exact Test +fisher.test(check_FOS) +``` + +As can be seen, the p value is `r round(fisher.test(check_FOS)$p.value, 3)`, which means that the fosfomycin resistances found in hospital A and D are really different.