diff --git a/.gitignore b/.gitignore index a3e30bee..778fdaa4 100755 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ Meta doc +.Renviron .Rproj.user .Rhistory .RData diff --git a/DESCRIPTION b/DESCRIPTION index 83bdcb56..5f5043e0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: AMR Version: 0.5.0.9009 -Date: 2019-01-06 +Date: 2019-01-08 Title: Antimicrobial Resistance Analysis Authors@R: c( person( diff --git a/NEWS.md b/NEWS.md index 7b26b020..254bcc06 100755 --- a/NEWS.md +++ b/NEWS.md @@ -28,9 +28,13 @@ * New vignettes about how to conduct AMR analysis, predict antimicrobial resistance, use the *G*-test and more. These are also available (and even easier readable) on our website: https://msberends.gitlab.io/AMR. #### Changed -* Function `guess_mo()` is now deprecated in favour of `as.mo()` and will be remover in future versions -* Fixed a critical bug in `eucast_rules()` where some rules that depend on previous applied rules would not be applied adequately +* Function `eucast_rules()`: + * Updated EUCAST Clinical breakpoints to [version 9.0 of 1 January 2019](http://www.eucast.org/clinical_breakpoints/) + * Fixed a critical bug where some rules that depend on previous applied rules would not be applied adequately + * Emphasised in manual that penicillin is meant as benzylpenicillin (ATC [J01CE01](https://www.whocc.no/atc_ddd_index/?code=J01CE01)) +* Function `guess_mo()` is now deprecated in favour of `as.mo()` and will be removed in future versions * Improvements for `as.mo()`: + * Fix for vector containing only empty values * Finds better results when input is in other languages * Better handling for subspecies * Better handling for *Salmonellae* diff --git a/R/data.R b/R/data.R index a9ee2f1c..b1ad6748 100755 --- a/R/data.R +++ b/R/data.R @@ -127,7 +127,7 @@ #' Data set with taxonomic data from ITIS #' #' A data set containing the complete microbial taxonomy of the kingdoms Bacteria, Fungi and Protozoa. MO codes can be looked up using \code{\link{as.mo}}. -#' @inheritSection itis ITIS +#' @inheritSection ITIS ITIS #' @format A \code{\link{data.frame}} with 18,833 observations and 15 variables: #' \describe{ #' \item{\code{mo}}{ID of microorganism} diff --git a/R/eucast_rules.R b/R/eucast_rules.R index 616b8da9..9cc57146 100755 --- a/R/eucast_rules.R +++ b/R/eucast_rules.R @@ -34,68 +34,68 @@ #' #' Abbrevations of the column containing antibiotics in the form: \strong{abbreviation}: generic name (\emph{ATC code}) #' -#' \strong{amcl}: amoxicillin+clavulanic acid (\emph{J01CR02}), -#' \strong{amik}: amikacin (\emph{J01GB06}), -#' \strong{amox}: amoxicillin (\emph{J01CA04}), -#' \strong{ampi}: ampicillin (\emph{J01CA01}), -#' \strong{azit}: azithromycin (\emph{J01FA10}), -#' \strong{azlo}: azlocillin (\emph{J01CA09}), -#' \strong{aztr}: aztreonam (\emph{J01DF01}), -#' \strong{cefa}: cefaloridine (\emph{J01DB02}), -#' \strong{cfep}: cefepime (\emph{J01DE01}), -#' \strong{cfot}: cefotaxime (\emph{J01DD01}), -#' \strong{cfox}: cefoxitin (\emph{J01DC01}), -#' \strong{cfra}: cefradine (\emph{J01DB09}), -#' \strong{cfta}: ceftazidime (\emph{J01DD02}), -#' \strong{cftr}: ceftriaxone (\emph{J01DD04}), -#' \strong{cfur}: cefuroxime (\emph{J01DC02}), -#' \strong{chlo}: chloramphenicol (\emph{J01BA01}), -#' \strong{cipr}: ciprofloxacin (\emph{J01MA02}), -#' \strong{clar}: clarithromycin (\emph{J01FA09}), -#' \strong{clin}: clindamycin (\emph{J01FF01}), -#' \strong{clox}: flucloxacillin (\emph{J01CF05}), -#' \strong{coli}: colistin (\emph{J01XB01}), -#' \strong{czol}: cefazolin (\emph{J01DB04}), -#' \strong{dapt}: daptomycin (\emph{J01XX09}), -#' \strong{doxy}: doxycycline (\emph{J01AA02}), -#' \strong{erta}: ertapenem (\emph{J01DH03}), -#' \strong{eryt}: erythromycin (\emph{J01FA01}), -#' \strong{fosf}: fosfomycin (\emph{J01XX01}), -#' \strong{fusi}: fusidic acid (\emph{J01XC01}), -#' \strong{gent}: gentamicin (\emph{J01GB03}), -#' \strong{imip}: imipenem (\emph{J01DH51}), -#' \strong{kana}: kanamycin (\emph{J01GB04}), -#' \strong{levo}: levofloxacin (\emph{J01MA12}), -#' \strong{linc}: lincomycin (\emph{J01FF02}), -#' \strong{line}: linezolid (\emph{J01XX08}), -#' \strong{mero}: meropenem (\emph{J01DH02}), -#' \strong{mezl}: mezlocillin (\emph{J01CA10}), -#' \strong{mino}: minocycline (\emph{J01AA08}), -#' \strong{moxi}: moxifloxacin (\emph{J01MA14}), -#' \strong{nali}: nalidixic acid (\emph{J01MB02}), -#' \strong{neom}: neomycin (\emph{J01GB05}), -#' \strong{neti}: netilmicin (\emph{J01GB07}), -#' \strong{nitr}: nitrofurantoin (\emph{J01XE01}), -#' \strong{norf}: norfloxacin (\emph{J01MA06}), -#' \strong{novo}: novobiocin (an ATCvet code: \emph{QJ01XX95}), -#' \strong{oflo}: ofloxacin (\emph{J01MA01}), -#' \strong{peni}: penicillin (\emph{J01RA01}), -#' \strong{pipe}: piperacillin (\emph{J01CA12}), -#' \strong{pita}: piperacillin+tazobactam (\emph{J01CR05}), -#' \strong{poly}: polymyxin B (\emph{J01XB02}), -#' \strong{pris}: pristinamycin (\emph{J01FG01}), -#' \strong{qida}: quinupristin/dalfopristin (\emph{J01FG02}), -#' \strong{rifa}: rifampicin (\emph{J04AB02}), -#' \strong{roxi}: roxithromycin (\emph{J01FA06}), -#' \strong{siso}: sisomicin (\emph{J01GB08}), -#' \strong{teic}: teicoplanin (\emph{J01XA02}), -#' \strong{tetr}: tetracycline (\emph{J01AA07}), -#' \strong{tica}: ticarcillin (\emph{J01CA13}), -#' \strong{tige}: tigecycline (\emph{J01AA12}), -#' \strong{tobr}: tobramycin (\emph{J01GB01}), -#' \strong{trim}: trimethoprim (\emph{J01EA01}), -#' \strong{trsu}: sulfamethoxazole and trimethoprim (\emph{J01EE01}), -#' \strong{vanc}: vancomycin (\emph{J01XA01}). +#' \strong{amcl}: amoxicillin+clavulanic acid (\href{https://www.whocc.no/atc_ddd_index/?code=J01CR02}{J01CR02}), +#' \strong{amik}: amikacin (\href{https://www.whocc.no/atc_ddd_index/?code=J01GB06}{J01GB06}), +#' \strong{amox}: amoxicillin (\href{https://www.whocc.no/atc_ddd_index/?code=J01CA04}{J01CA04}), +#' \strong{ampi}: ampicillin (\href{https://www.whocc.no/atc_ddd_index/?code=J01CA01}{J01CA01}), +#' \strong{azit}: azithromycin (\href{https://www.whocc.no/atc_ddd_index/?code=J01FA10}{J01FA10}), +#' \strong{azlo}: azlocillin (\href{https://www.whocc.no/atc_ddd_index/?code=J01CA09}{J01CA09}), +#' \strong{aztr}: aztreonam (\href{https://www.whocc.no/atc_ddd_index/?code=J01DF01}{J01DF01}), +#' \strong{cefa}: cefaloridine (\href{https://www.whocc.no/atc_ddd_index/?code=J01DB02}{J01DB02}), +#' \strong{cfep}: cefepime (\href{https://www.whocc.no/atc_ddd_index/?code=J01DE01}{J01DE01}), +#' \strong{cfot}: cefotaxime (\href{https://www.whocc.no/atc_ddd_index/?code=J01DD01}{J01DD01}), +#' \strong{cfox}: cefoxitin (\href{https://www.whocc.no/atc_ddd_index/?code=J01DC01}{J01DC01}), +#' \strong{cfra}: cefradine (\href{https://www.whocc.no/atc_ddd_index/?code=J01DB09}{J01DB09}), +#' \strong{cfta}: ceftazidime (\href{https://www.whocc.no/atc_ddd_index/?code=J01DD02}{J01DD02}), +#' \strong{cftr}: ceftriaxone (\href{https://www.whocc.no/atc_ddd_index/?code=J01DD04}{J01DD04}), +#' \strong{cfur}: cefuroxime (\href{https://www.whocc.no/atc_ddd_index/?code=J01DC02}{J01DC02}), +#' \strong{chlo}: chloramphenicol (\href{https://www.whocc.no/atc_ddd_index/?code=J01BA01}{J01BA01}), +#' \strong{cipr}: ciprofloxacin (\href{https://www.whocc.no/atc_ddd_index/?code=J01MA02}{J01MA02}), +#' \strong{clar}: clarithromycin (\href{https://www.whocc.no/atc_ddd_index/?code=J01FA09}{J01FA09}), +#' \strong{clin}: clindamycin (\href{https://www.whocc.no/atc_ddd_index/?code=J01FF01}{J01FF01}), +#' \strong{clox}: flucloxacillin (\href{https://www.whocc.no/atc_ddd_index/?code=J01CF05}{J01CF05}), +#' \strong{coli}: colistin (\href{https://www.whocc.no/atc_ddd_index/?code=J01XB01}{J01XB01}), +#' \strong{czol}: cefazolin (\href{https://www.whocc.no/atc_ddd_index/?code=J01DB04}{J01DB04}), +#' \strong{dapt}: daptomycin (\href{https://www.whocc.no/atc_ddd_index/?code=J01XX09}{J01XX09}), +#' \strong{doxy}: doxycycline (\href{https://www.whocc.no/atc_ddd_index/?code=J01AA02}{J01AA02}), +#' \strong{erta}: ertapenem (\href{https://www.whocc.no/atc_ddd_index/?code=J01DH03}{J01DH03}), +#' \strong{eryt}: erythromycin (\href{https://www.whocc.no/atc_ddd_index/?code=J01FA01}{J01FA01}), +#' \strong{fosf}: fosfomycin (\href{https://www.whocc.no/atc_ddd_index/?code=J01XX01}{J01XX01}), +#' \strong{fusi}: fusidic acid (\href{https://www.whocc.no/atc_ddd_index/?code=J01XC01}{J01XC01}), +#' \strong{gent}: gentamicin (\href{https://www.whocc.no/atc_ddd_index/?code=J01GB03}{J01GB03}), +#' \strong{imip}: imipenem (\href{https://www.whocc.no/atc_ddd_index/?code=J01DH51}{J01DH51}), +#' \strong{kana}: kanamycin (\href{https://www.whocc.no/atc_ddd_index/?code=J01GB04}{J01GB04}), +#' \strong{levo}: levofloxacin (\href{https://www.whocc.no/atc_ddd_index/?code=J01MA12}{J01MA12}), +#' \strong{linc}: lincomycin (\href{https://www.whocc.no/atc_ddd_index/?code=J01FF02}{J01FF02}), +#' \strong{line}: linezolid (\href{https://www.whocc.no/atc_ddd_index/?code=J01XX08}{J01XX08}), +#' \strong{mero}: meropenem (\href{https://www.whocc.no/atc_ddd_index/?code=J01DH02}{J01DH02}), +#' \strong{mezl}: mezlocillin (\href{https://www.whocc.no/atc_ddd_index/?code=J01CA10}{J01CA10}), +#' \strong{mino}: minocycline (\href{https://www.whocc.no/atc_ddd_index/?code=J01AA08}{J01AA08}), +#' \strong{moxi}: moxifloxacin (\href{https://www.whocc.no/atc_ddd_index/?code=J01MA14}{J01MA14}), +#' \strong{nali}: nalidixic acid (\href{https://www.whocc.no/atc_ddd_index/?code=J01MB02}{J01MB02}), +#' \strong{neom}: neomycin (\href{https://www.whocc.no/atc_ddd_index/?code=J01GB05}{J01GB05}), +#' \strong{neti}: netilmicin (\href{https://www.whocc.no/atc_ddd_index/?code=J01GB07}{J01GB07}), +#' \strong{nitr}: nitrofurantoin (\href{https://www.whocc.no/atc_ddd_index/?code=J01XE01}{J01XE01}), +#' \strong{norf}: norfloxacin (\href{https://www.whocc.no/atc_ddd_index/?code=J01MA06}{J01MA06}), +#' \strong{novo}: novobiocin (an ATCvet code: \href{https://www.whocc.no/atc_ddd_index/?code=QJ01XX95}{QJ01XX95}), +#' \strong{oflo}: ofloxacin (\href{https://www.whocc.no/atc_ddd_index/?code=J01MA01}{J01MA01}), +#' \strong{peni}: (benzyl)penicillin (\href{https://www.whocc.no/atc_ddd_index/?code=J01CE01}{J01CE01}), +#' \strong{pipe}: piperacillin (\href{https://www.whocc.no/atc_ddd_index/?code=J01CA12}{J01CA12}), +#' \strong{pita}: piperacillin+tazobactam (\href{https://www.whocc.no/atc_ddd_index/?code=J01CR05}{J01CR05}), +#' \strong{poly}: polymyxin B (\href{https://www.whocc.no/atc_ddd_index/?code=J01XB02}{J01XB02}), +#' \strong{pris}: pristinamycin (\href{https://www.whocc.no/atc_ddd_index/?code=J01FG01}{J01FG01}), +#' \strong{qida}: quinupristin/dalfopristin (\href{https://www.whocc.no/atc_ddd_index/?code=J01FG02}{J01FG02}), +#' \strong{rifa}: rifampicin (\href{https://www.whocc.no/atc_ddd_index/?code=J04AB02}{J04AB02}), +#' \strong{roxi}: roxithromycin (\href{https://www.whocc.no/atc_ddd_index/?code=J01FA06}{J01FA06}), +#' \strong{siso}: sisomicin (\href{https://www.whocc.no/atc_ddd_index/?code=J01GB08}{J01GB08}), +#' \strong{teic}: teicoplanin (\href{https://www.whocc.no/atc_ddd_index/?code=J01XA02}{J01XA02}), +#' \strong{tetr}: tetracycline (\href{https://www.whocc.no/atc_ddd_index/?code=J01AA07}{J01AA07}), +#' \strong{tica}: ticarcillin (\href{https://www.whocc.no/atc_ddd_index/?code=J01CA13}{J01CA13}), +#' \strong{tige}: tigecycline (\href{https://www.whocc.no/atc_ddd_index/?code=J01AA12}{J01AA12}), +#' \strong{tobr}: tobramycin (\href{https://www.whocc.no/atc_ddd_index/?code=J01GB01}{J01GB01}), +#' \strong{trim}: trimethoprim (\href{https://www.whocc.no/atc_ddd_index/?code=J01EA01}{J01EA01}), +#' \strong{trsu}: sulfamethoxazole and trimethoprim (\href{https://www.whocc.no/atc_ddd_index/?code=J01EE01}{J01EE01}), +#' \strong{vanc}: vancomycin (\href{https://www.whocc.no/atc_ddd_index/?code=J01XA01}{J01XA01}). #' @keywords interpretive eucast reading resistance #' @rdname eucast_rules #' @export @@ -114,8 +114,8 @@ #' \url{http://www.eucast.org/fileadmin/src/media/PDFs/EUCAST_files/Expert_Rules/Expert_rules_intrinsic_exceptional_V3.1.pdf} #' } #' \item{ -#' EUCAST Breakpoint tables for interpretation of MICs and zone diameters. Version 8.1, 2018. \cr -#' \url{http://www.eucast.org/fileadmin/src/media/PDFs/EUCAST_files/Breakpoint_tables/v_8.1_Breakpoint_Tables.xlsx} +#' EUCAST Breakpoint tables for interpretation of MICs and zone diameters. Version 9.0, 2019. \cr +#' \url{http://www.eucast.org/fileadmin/src/media/PDFs/EUCAST_files/Breakpoint_tables/v_9.0_Breakpoint_Tables.xlsx} #' } #' } #' @inheritSection AMR Read more on our website! diff --git a/R/itis.R b/R/itis.R index 6b3e78fa..e4bc2477 100644 --- a/R/itis.R +++ b/R/itis.R @@ -30,12 +30,12 @@ #' #' ITIS is a partnership of U.S., Canadian, and Mexican agencies and taxonomic specialists [3]. #' @inheritSection AMR Read more on our website! -#' @name itis -#' @rdname itis +#' @name ITIS +#' @rdname ITIS #' @examples #' # Get a note when a species was renamed #' mo_shortname("Chlamydia psittaci") -#' # Note: 'Chlamydia psittaci' (Page, 1968) was renamed +#' # Note: 'Chlamydia psittaci' (Page, 1968) was renamed #' # 'Chlamydophila psittaci' (Everett et al., 1999) #' # [1] "C. psittaci" #' diff --git a/R/mo.R b/R/mo.R index 666f64c7..fe7702f3 100644 --- a/R/mo.R +++ b/R/mo.R @@ -76,7 +76,7 @@ #' \item{\code{"D. spartina"}. This is the abbreviation of an old taxonomic name: \emph{Didymosphaeria spartinae} (the last "e" was missing from the input). This fungus was renamed to \emph{Leptosphaeria obiones}, so a warning will be thrown that this result (\code{F_LPTSP_OBI}) needs review.} #' } #' -#' @inheritSection itis ITIS +#' @inheritSection ITIS ITIS # (source as a section, so it can be inherited by other man pages) #' @section Source: #' [1] Becker K \emph{et al.} \strong{Coagulase-Negative Staphylococci}. 2014. Clin Microbiol Rev. 27(4): 870–926. \url{https://dx.doi.org/10.1128/CMR.00109-13} @@ -211,8 +211,16 @@ exec_as.mo <- function(x, Becker = FALSE, Lancefield = FALSE, reference_df[] <- lapply(reference_df, as.character) ) } - - if (all(x %in% microorganismsDT[["mo"]])) { + if (all(identical(trimws(x_input), "") | is.na(x_input))) { + # all empty + if (property == "mo") { + return(structure(rep(NA_character_, length(x_input)), class = "mo")) + } else if (property == "tsn") { + return(rep(NA_integer_, length(x_input))) + } else { + return(rep(NA_character_, length(x_input))) + } + } else if (all(x %in% microorganismsDT[["mo"]])) { # existing mo codes when not looking for property "mo", like mo_genus("B_ESCHR_COL") x <- microorganismsDT[data.table(mo = x), on = "mo", ..property][[1]] } else if (!is.null(reference_df) @@ -665,6 +673,16 @@ exec_as.mo <- function(x, Becker = FALSE, Lancefield = FALSE, } } + # (4) not yet implemented taxonomic changes in ITIS + found <- suppressMessages(suppressWarnings(exec_as.mo(temp_changes(b.x_trimmed), clear_options = FALSE, allow_uncertain = FALSE))) + if (!is.na(found)) { + found <- microorganismsDT[mo == found, ..property][[1]] + warning(red(paste0('UNCERTAIN - "', + a.x_backup, '" -> ', italic(microorganismsDT[mo == found[1L], fullname][[1]]), " (", found[1L], ")")), + call. = FALSE, immediate. = FALSE) + return(found[1L]) + } + # didn't found in uncertain results too return(NA_character_) } @@ -780,6 +798,10 @@ exec_as.mo <- function(x, Becker = FALSE, Lancefield = FALSE, x } +temp_changes <- function(x) { + x[x %like% 'Cutibacterium'] <- gsub('Cutibacterium', 'Propionibacterium', x[x %like% 'Cutibacterium']) +} + #' @importFrom crayon blue italic renamed_note <- function(name_old, name_new, ref_old = "", ref_new = "", mo = "") { if (!is.na(ref_old)) { diff --git a/R/mo_property.R b/R/mo_property.R index 3d0493c0..ae8bb176 100644 --- a/R/mo_property.R +++ b/R/mo_property.R @@ -33,7 +33,7 @@ #' \item{\code{mo_ref("Chlamydophila psittaci")} will return \code{"Everett et al., 1999"} (without a warning)} #' } #' @inheritSection get_locale Supported languages -#' @inheritSection itis ITIS +#' @inheritSection ITIS ITIS #' @inheritSection as.mo Source #' @rdname mo_property #' @name mo_property @@ -480,6 +480,12 @@ mo_validate <- function(x, property, ...) { | Lancefield %in% c(TRUE, "all")) { exec_as.mo(x, property = property, ...) } else { - x + if (property == "mo") { + return(structure(x, class = "mo")) + } else if (property == "tsn") { + return(as.integer(x)) + } else { + return(x) + } } } diff --git a/_pkgdown.yml b/_pkgdown.yml index 76aa269a..b2197338 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -71,13 +71,13 @@ navbar: href: 'LICENSE-text.html' reference: -- title: Backround information +- title: 'Background information' desc: > Some pages about our package and its external sources. contents: - '`AMR`' - - '`itis`' -- title: Cleaning your data + - '`ITIS`' +- title: 'Cleaning your data' desc: > Functions for cleaning and optimising your data, to be able to add variables later on (like taxonomic properties) or to @@ -87,7 +87,7 @@ reference: - '`eucast_rules`' - '`guess_ab`' - '`read.4D`' -- title: Adding variables to your data +- title: 'Adding variables to your data' desc: > Functions to add new data to existing data, like the determination of first isolates, @@ -103,7 +103,7 @@ reference: - '`age_groups`' - '`p.symbol`' - '`join`' -- title: Analysing your data +- title: 'Analysing your data' desc: > Functions for conducting AMR analysis contents: @@ -116,7 +116,7 @@ reference: - '`resistance_predict`' - '`rsi`' - '`skewness`' -- title: Included data sets +- title: 'Included data sets' desc: > References for microorganisms and antibiotics, and even a genuine data set with isolates from septic patients. diff --git a/docs/articles/AMR.html b/docs/articles/AMR.html index 8b3a9a1a..9e9b3092 100644 --- a/docs/articles/AMR.html +++ b/docs/articles/AMR.html @@ -171,6 +171,7 @@
AMR.Rmd
Note: values on this page will change with every website update since they are based on randomly created values and the page was written in RMarkdown. However, the methodology remains unchanged. This page was generated on 04 January 2019.
+Note: values on this page will change with every website update since they are based on randomly created values and the page was written in RMarkdown. However, the methodology remains unchanged. This page was generated on 08 January 2019.
As with many uses in R, we need some additional packages for AMR analysis. The most important one is dplyr
, which tremendously improves the way we work with data - it allows for a very natural way of writing syntaxes in R. Another important dependency is ggplot2
. This package can be used to create beautiful plots in R.
Our AMR
package depends on these packages and even extends their use and functions.
library(dplyr) # the data science package
-library(AMR) # this package, to simplify and automate AMR analysis
-library(ggplot2) # for appealing plots
library(dplyr) # the data science package
+library(AMR) # this package, to simplify and automate AMR analysis
+library(ggplot2) # for appealing plots
To start with patients, we need a unique list of patients.
- +The LETTERS
object is available in R - it’s a vector with 26 characters: A
to Z
. The patients
object we just created is now a vector of length 260, with values (patient IDs) varying from A1
to Z10
. Now we we also set the gender of our patients, by putting the ID and the gender in a table:
patients_table <- data.frame(patient_id = patients,
- gender = c(rep("M", 135),
- rep("F", 125)))
The first 135 patient IDs are now male, the other 125 are female.
Let’s pretend that our data consists of blood cultures isolates from 1 January 2010 until 1 January 2018.
- +This dates
object now contains all days in our date range.
For this tutorial, we will uses four different microorganisms: Escherichia coli, Staphylococcus aureus, Streptococcus pneumoniae, and Klebsiella pneumoniae:
-bacteria <- c("Escherichia coli", "Staphylococcus aureus",
- "Streptococcus pneumoniae", "Klebsiella pneumoniae")
For completeness, we can also add the hospital where the patients was admitted and we need to define valid antibmicrobial results for our randomisation:
- +Using the sample()
function, we can randomly select items from all objects we defined earlier. To let our fake data reflect reality a bit, we will also approximately define the probabilities of bacteria and the antibiotic results with the prob
parameter.
data <- data.frame(date = sample(dates, 5000, replace = TRUE),
- patient_id = sample(patients, 5000, replace = TRUE),
- hospital = sample(hospitals, 5000, replace = TRUE, prob = c(0.30, 0.35, 0.15, 0.20)),
- bacteria = sample(bacteria, 5000, replace = TRUE, prob = c(0.50, 0.25, 0.15, 0.10)),
- amox = sample(ab_interpretations, 5000, replace = TRUE, prob = c(0.60, 0.05, 0.35)),
- amcl = sample(ab_interpretations, 5000, replace = TRUE, prob = c(0.75, 0.10, 0.15)),
- cipr = sample(ab_interpretations, 5000, replace = TRUE, prob = c(0.80, 0.00, 0.20)),
- gent = sample(ab_interpretations, 5000, replace = TRUE, prob = c(0.92, 0.00, 0.08))
- )
Using the left_join()
function from the dplyr
package, we can ‘map’ the gender to the patient ID using the patients_table
object we created earlier:
data <- data %>% left_join(patients_table)
Using the sample()
function, we can randomly select items from all objects we defined earlier. To let our fake data reflect reality a bit, we will also approximately define the probabilities of bacteria and the antibiotic results with the prob
parameter.
data <- data.frame(date = sample(dates, 5000, replace = TRUE),
+ patient_id = sample(patients, 5000, replace = TRUE),
+ hospital = sample(hospitals, 5000, replace = TRUE, prob = c(0.30, 0.35, 0.15, 0.20)),
+ bacteria = sample(bacteria, 5000, replace = TRUE, prob = c(0.50, 0.25, 0.15, 0.10)),
+ amox = sample(ab_interpretations, 5000, replace = TRUE, prob = c(0.60, 0.05, 0.35)),
+ amcl = sample(ab_interpretations, 5000, replace = TRUE, prob = c(0.75, 0.10, 0.15)),
+ cipr = sample(ab_interpretations, 5000, replace = TRUE, prob = c(0.80, 0.00, 0.20)),
+ gent = sample(ab_interpretations, 5000, replace = TRUE, prob = c(0.92, 0.00, 0.08))
+ )
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:
head(data)
date | @@ -295,71 +296,71 @@ ab_interpretations <- -2014-02-20 | -D5 | -Hospital A | -Escherichia coli | -R | -S | -S | -S | -M | -|
---|---|---|---|---|---|---|---|---|---|---|
2010-06-17 | -N4 | -Hospital A | -Escherichia coli | -S | -S | -R | -S | -M | -||
2017-08-02 | -A6 | -Hospital B | -Staphylococcus aureus | -R | -I | -R | -S | -M | -||
2012-11-25 | -K7 | -Hospital A | -Escherichia coli | -I | -S | -S | -S | -M | -||
2012-06-24 | -G9 | -Hospital B | -Escherichia coli | -R | -S | -S | -R | -M | -||
2011-05-20 | -T7 | +2011-02-27 | +M6 | Hospital C | Escherichia coli | S | S | +R | +S | +M | +
2012-07-12 | +C2 | +Hospital B | +Streptococcus pneumoniae | +S | +R | +S | +S | +M | +||
2016-09-13 | +O7 | +Hospital A | +Escherichia coli | +R | +R | S | S | F | ||
2016-12-05 | +E4 | +Hospital A | +Escherichia coli | +I | +S | +S | +S | +M | +||
2017-10-05 | +M1 | +Hospital A | +Escherichia coli | +R | +I | +R | +S | +M | +||
2012-02-22 | +H9 | +Hospital C | +Streptococcus pneumoniae | +S | +S | +R | +S | +M | +
Now, let’s start the cleaning and the analysis!
@@ -369,7 +370,7 @@ ab_interpretations <- Cleaning the dataUse the frequency table function freq()
to look specifically for unique values in any variable. For example, for the gender
variable:
data %>% freq(gender) # this would be the same: freq(data$gender)
# Frequency table of `gender` # Class: factor (numeric) # Levels: F, M @@ -378,67 +379,67 @@ ab_interpretations <- mutate()
function of thedplyr
package makes this really easy: - -We also want to transform the antibiotics, because in real life data we don’t know if they are really clean. The
- +as.rsi()
function ensures reliability and reproducibility in these kind of variables. Themutate_at()
will run theas.rsi()
function on defined variables: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. Themutate()
function of thedplyr
package makes this really easy:We also want to transform the antibiotics, because in real life data we don’t know if they are really clean. The
+as.rsi()
function ensures reliability and reproducibility in these kind of variables. Themutate_at()
will run theas.rsi()
function on defined variables:Finally, we will apply EUCAST rules on our antimicrobial results. In Europe, most medical microbiological laboratories already apply these rules. Our package features their latest insights on intrinsic resistance and exceptional phenotypes. Moreover, the
eucast_rules()
function can also apply additional rules, like forcingampicillin = R whenamoxicillin/clavulanic acid = R.Because the amoxicillin (column
-amox
) and amoxicillin/clavulanic acid (columnamcl
) in our data were generated randomly, some rows will undoubtedly contain amox = S and amcl = R, which is technically impossible. Theeucast_rules()
fixes this:+data <- eucast_rules(data, col_mo = "bacteria") -# -# Rules by the European Committee on Antimicrobial Susceptibility Testing (EUCAST) -# -# EUCAST Clinical Breakpoints (v8.1, 2018) -# Enterobacteriales (Order) (no changes) -# Staphylococcus (no changes) -# Enterococcus (no changes) -# Streptococcus groups A, B, C, G (no changes) -# Streptococcus pneumoniae (no changes) -# Viridans group streptococci (no changes) -# Haemophilus influenzae (no changes) -# Moraxella catarrhalis (no changes) -# Anaerobic Gram positives (no changes) -# Anaerobic Gram negatives (no changes) -# Pasteurella multocida (no changes) -# Campylobacter jejuni and C. coli (no changes) -# Aerococcus sanguinicola and A. urinae (no changes) -# Kingella kingae (no changes) -# -# EUCAST Expert Rules, Intrinsic Resistance and Exceptional Phenotypes (v3.1, 2016) -# Table 1: Intrinsic resistance in Enterobacteriaceae (332 changes) -# Table 2: Intrinsic resistance in non-fermentative Gram-negative bacteria (no changes) -# Table 3: Intrinsic resistance in other Gram-negative bacteria (no changes) -# Table 4: Intrinsic resistance in Gram-positive bacteria (658 changes) -# Table 8: Interpretive rules for B-lactam agents and Gram-positive cocci (no changes) -# Table 9: Interpretive rules for B-lactam agents and Gram-negative rods (no changes) -# Table 10: Interpretive rules for B-lactam agents and other Gram-negative bacteria (no changes) -# Table 11: Interpretive rules for macrolides, lincosamides, and streptogramins (no changes) -# Table 12: Interpretive rules for aminoglycosides (no changes) -# Table 13: Interpretive rules for quinolones (no changes) -# -# Other rules -# Non-EUCAST: ampicillin = R where amoxicillin/clav acid = R (no changes) -# Non-EUCAST: piperacillin = R where piperacillin/tazobactam = R (no changes) -# Non-EUCAST: trimethoprim = R where trimethoprim/sulfa = R (no changes) -# Non-EUCAST: amoxicillin/clav acid = S where ampicillin = S (no changes) -# Non-EUCAST: piperacillin/tazobactam = S where piperacillin = S (no changes) -# Non-EUCAST: trimethoprim/sulfa = S where trimethoprim = S (no changes) -# -# => EUCAST rules affected 1,828 out of 5,000 rows -> changed 990 test results.
data <- eucast_rules(data, col_mo = "bacteria") +# +# Rules by the European Committee on Antimicrobial Susceptibility Testing (EUCAST) +# +# EUCAST Clinical Breakpoints (v8.1, 2018) +# Enterobacteriales (Order) (no changes) +# Staphylococcus (no changes) +# Enterococcus (no changes) +# Streptococcus groups A, B, C, G (no changes) +# Streptococcus pneumoniae (no changes) +# Viridans group streptococci (no changes) +# Haemophilus influenzae (no changes) +# Moraxella catarrhalis (no changes) +# Anaerobic Gram positives (no changes) +# Anaerobic Gram negatives (no changes) +# Pasteurella multocida (no changes) +# Campylobacter jejuni and C. coli (no changes) +# Aerococcus sanguinicola and A. urinae (no changes) +# Kingella kingae (no changes) +# +# EUCAST Expert Rules, Intrinsic Resistance and Exceptional Phenotypes (v3.1, 2016) +# Table 1: Intrinsic resistance in Enterobacteriaceae (349 changes) +# Table 2: Intrinsic resistance in non-fermentative Gram-negative bacteria (no changes) +# Table 3: Intrinsic resistance in other Gram-negative bacteria (no changes) +# Table 4: Intrinsic resistance in Gram-positive bacteria (694 changes) +# Table 8: Interpretive rules for B-lactam agents and Gram-positive cocci (no changes) +# Table 9: Interpretive rules for B-lactam agents and Gram-negative rods (no changes) +# Table 10: Interpretive rules for B-lactam agents and other Gram-negative bacteria (no changes) +# Table 11: Interpretive rules for macrolides, lincosamides, and streptogramins (no changes) +# Table 12: Interpretive rules for aminoglycosides (no changes) +# Table 13: Interpretive rules for quinolones (no changes) +# +# Other rules +# Non-EUCAST: ampicillin = R where amoxicillin/clav acid = R (no changes) +# Non-EUCAST: piperacillin = R where piperacillin/tazobactam = R (no changes) +# Non-EUCAST: trimethoprim = R where trimethoprim/sulfa = R (no changes) +# Non-EUCAST: amoxicillin/clav acid = S where ampicillin = S (no changes) +# Non-EUCAST: piperacillin/tazobactam = S where piperacillin = S (no changes) +# Non-EUCAST: trimethoprim/sulfa = S where trimethoprim = S (no changes) +# +# => EUCAST rules affected 1,854 out of 5,000 rows -> changed 1,043 test results.
Now that we have the microbial ID, we can add some taxonomic properties:
-data <- data %>%
- mutate(gramstain = mo_gramstain(bacteria),
- genus = mo_genus(bacteria),
- species = mo_species(bacteria))
data <- data %>%
+ mutate(gramstain = mo_gramstain(bacteria),
+ genus = mo_genus(bacteria),
+ species = mo_species(bacteria))
This AMR
package includes this methodology with the first_isolate()
function. It adopts the episode of a year (can be changed by user) and it starts counting days after every selected isolate. This new variable can easily be added to our data:
data <- data %>%
- mutate(first = first_isolate(.))
-# NOTE: Using column `bacteria` as input for `col_mo`.
-# NOTE: Using column `date` as input for `col_date`.
-# NOTE: Using column `patient_id` as input for `col_patient_id`.
-# => Found 2,950 first isolates (59.0% of total)
So only 59% is suitable for resistance analysis! We can now filter on is with the filter()
function, also from the dplyr
package:
data_1st <- data %>%
- filter(first == TRUE)
data <- data %>%
+ mutate(first = first_isolate(.))
+# NOTE: Using column `bacteria` as input for `col_mo`.
+# NOTE: Using column `date` as input for `col_date`.
+# NOTE: Using column `patient_id` as input for `col_patient_id`.
+# => Found 2,929 first isolates (58.6% of total)
So only 58.6% is suitable for resistance analysis! We can now filter on is with the filter()
function, also from the dplyr
package:
For future use, the above two syntaxes can be shortened with the filter_first_isolate()
function:
data_1st <- data %>%
- filter_first_isolate()
Only 3 isolates are marked as ‘first’ according to CLSI guideline. But when reviewing the antibiogram, it is obvious that some isolates are absolutely different strains and show be included too. This is why we weigh isolates, based on their antibiogram. The key_antibiotics()
function adds a vector with 18 key antibiotics: 6 broad spectrum ones, 6 small spectrum for Gram negatives and 6 small spectrum for Gram positives. These can be defined by the user.
If a column exists with a name like ‘key(…)ab’ the first_isolate()
function will automatically use it and determine the first weighted isolates. Mind the NOTEs in below output:
data <- data %>%
- mutate(keyab = key_antibiotics(.)) %>%
- mutate(first_weighted = first_isolate(.))
-# NOTE: Using column `bacteria` as input for `col_mo`.
-# amox amcl cipr gent
-# "amox" "amcl" "cipr" "gent"
-# [1] "amox" "amcl" "cipr"
-# amox amcl cipr gent
-# "amox" "amcl" "cipr" "gent"
-# NOTE: Using column `bacteria` as input for `col_mo`.
-# NOTE: Using column `date` as input for `col_date`.
-# NOTE: Using column `patient_id` as input for `col_patient_id`.
-# NOTE: Using column `keyab` as input for `col_keyantibiotics`. Use col_keyantibiotics = FALSE to prevent this.
-# [Criterion] Inclusion based on key antibiotics, ignoring I.
-# => Found 4,430 first weighted isolates (88.6% of total)
data <- data %>%
+ mutate(keyab = key_antibiotics(.)) %>%
+ mutate(first_weighted = first_isolate(.))
+# NOTE: Using column `bacteria` as input for `col_mo`.
+# amox amcl cipr gent
+# "amox" "amcl" "cipr" "gent"
+# [1] "amox" "amcl" "cipr"
+# amox amcl cipr gent
+# "amox" "amcl" "cipr" "gent"
+# NOTE: Using column `bacteria` as input for `col_mo`.
+# NOTE: Using column `date` as input for `col_date`.
+# NOTE: Using column `patient_id` as input for `col_patient_id`.
+# NOTE: Using column `keyab` as input for `col_keyantibiotics`. Use col_keyantibiotics = FALSE to prevent this.
+# [Criterion] Inclusion based on key antibiotics, ignoring I.
+# => Found 4,435 first weighted isolates (88.7% of total)
Instead of 3, now 8 isolates are flagged. In total, 88.6% of all isolates are marked ‘first weighted’ - 147.6% 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, 88.7% of all isolates are marked ‘first weighted’ - 147.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.
As with filter_first_isolate()
, there’s a shortcut for this new algorithm too:
data_1st <- data %>%
- filter_first_weighted_isolate()
So we end up with 4,430 isolates for analysis.
+ +So we end up with 4,435 isolates for analysis.
We can remove unneeded columns:
- +Now our data looks like:
-head(data_1st)
date | patient_id | hospital | @@ -772,87 +774,45 @@ ab_interpretations <- -2014-02-20 | -D5 | -Hospital A | -B_ESCHR_COL | -R | -S | -S | -S | -M | -Gram negative | -Escherichia | -coli | -TRUE | -|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
2010-06-17 | -N4 | -Hospital A | -B_ESCHR_COL | -S | -S | -R | -S | -M | -Gram negative | -Escherichia | -coli | -TRUE | -||||
2017-08-02 | -A6 | -Hospital B | -B_STPHY_AUR | -R | -I | -R | -S | -M | -Gram positive | -Staphylococcus | -aureus | -TRUE | -||||
2012-11-25 | -K7 | -Hospital A | -B_ESCHR_COL | -I | -S | -S | -S | -M | -Gram negative | -Escherichia | -coli | -TRUE | -||||
2012-06-24 | -G9 | -Hospital B | -B_ESCHR_COL | -R | -S | -S | -R | -M | -Gram negative | -Escherichia | -coli | -TRUE | -||||
2011-05-20 | -T7 | +1 | +2011-02-27 | +M6 | Hospital C | B_ESCHR_COL | S | S | +R | +S | +M | +Gram negative | +Escherichia | +coli | +TRUE | +|
2 | +2012-07-12 | +C2 | +Hospital B | +B_STRPTC_PNE | +S | +R | +S | +R | +M | +Gram positive | +Streptococcus | +pneumoniae | +TRUE | +|||
3 | +2016-09-13 | +O7 | +Hospital A | +B_ESCHR_COL | +R | +R | S | S | F | @@ -861,6 +821,54 @@ ab_interpretations <- coliTRUE | ||||||
5 | +2017-10-05 | +M1 | +Hospital A | +B_ESCHR_COL | +R | +I | +R | +S | +M | +Gram negative | +Escherichia | +coli | +TRUE | +|||
6 | +2012-02-22 | +H9 | +Hospital C | +B_STRPTC_PNE | +S | +S | +R | +R | +M | +Gram positive | +Streptococcus | +pneumoniae | +TRUE | +|||
7 | +2011-01-13 | +S6 | +Hospital D | +B_STPHY_AUR | +I | +S | +S | +S | +F | +Gram positive | +Staphylococcus | +aureus | +TRUE | +
Time for the analysis!
@@ -871,12 +879,12 @@ ab_interpretations <- Analysing the dataYou might want to start by getting an idea of how the data is distributed. It’s an important start, because it also decides how you will continue your analysis. ## Dispersion of species To just get an idea how the species are distributed, create a frequency table with our freq()
function. We created the genus
and species
column earlier based on the microbial ID. With paste()
, we can concatenate them together.
The freq()
function can be used like the base R language was intended:
Or can be used like the dplyr
way, which is easier readable:
data_1st %>% freq(genus, species)
Frequency table of genus
and species
Columns: 2
-Length: 4,430 (of which NA: 0 = 0.00%)
+Length: 4,435 (of which NA: 0 = 0.00%)
Unique: 4
Shortest: 16
Longest: 24
The functions portion_R
, portion_RI
, portion_I
, portion_IS
and portion_S
can be used to determine the portion of a specific antimicrobial outcome. They can be used on their own:
data_1st %>% portion_IR(amox)
-# [1] 0.46614
Or can be used in conjuction with group_by()
and summarise()
, both from the dplyr
package:
data_1st %>%
- group_by(hospital) %>%
- summarise(amoxicillin = portion_IR(amox))
Or can be used in conjuction with group_by()
and summarise()
, both from the dplyr
package:
hospital | @@ -942,27 +950,27 @@ Longest: 24||
---|---|---|
Hospital A | -0.4605873 | +0.4504164 |
Hospital B | -0.4624277 | +0.4782034 |
Hospital C | -0.4853801 | +0.4670571 |
Hospital D | -0.4659218 | +0.4471101 |
Of course it would be very convenient to know the number of isolates responsible for the percentages. For that purpose the n_rsi()
can be used, which works exactly like n_distinct()
from the dplyr
package. It counts all isolates available for every group (i.e. values S, I or R):
data_1st %>%
- group_by(hospital) %>%
- summarise(amoxicillin = portion_IR(amox),
- available = n_rsi(amox))
Of course it would be very convenient to know the number of isolates responsible for the percentages. For that purpose the n_rsi()
can be used, which works exactly like n_distinct()
from the dplyr
package. It counts all isolates available for every group (i.e. values S, I or R):
data_1st %>%
+ group_by(hospital) %>%
+ summarise(amoxicillin = portion_IR(amox),
+ available = n_rsi(amox))
hospital | @@ -972,32 +980,32 @@ Longest: 24||||
---|---|---|---|---|
Hospital A | -0.4605873 | -1294 | +0.4504164 | +1321 |
Hospital B | -0.4624277 | -1557 | +0.4782034 | +1514 |
Hospital C | -0.4853801 | -684 | +0.4670571 | +683 |
Hospital D | -0.4659218 | -895 | +0.4471101 | +917 |
These functions can also be used to get the portion of multiple antibiotics, to calculate co-resistance very easily:
-data_1st %>%
- group_by(genus) %>%
- summarise(amoxicillin = portion_S(amcl),
- gentamicin = portion_S(gent),
- "amox + gent" = portion_S(amcl, gent))
data_1st %>%
+ group_by(genus) %>%
+ summarise(amoxicillin = portion_S(amcl),
+ gentamicin = portion_S(gent),
+ "amox + gent" = portion_S(amcl, gent))
genus | @@ -1008,94 +1016,94 @@ Longest: 24||||||
---|---|---|---|---|---|---|
Escherichia | -0.7307344 | -0.9120580 | -0.9782412 | +0.7162960 | +0.9051294 | +0.9786655 |
Klebsiella | -0.7521552 | -0.9181034 | -0.9806034 | +0.7494692 | +0.9129512 | +0.9766454 |
Staphylococcus | -0.7419945 | -0.9268070 | -0.9798719 | +0.7341418 | +0.9244403 | +0.9776119 |
Streptococcus | -0.7256372 | +0.7576197 | 0.0000000 | -0.7256372 | +0.7576197 |
To make a transition to the next part, let’s see how this difference could be plotted:
-data_1st %>%
- group_by(genus) %>%
- summarise("1. Amoxicillin" = portion_S(amcl),
- "2. Gentamicin" = portion_S(gent),
- "3. Amox + gent" = portion_S(amcl, gent)) %>%
- tidyr::gather("Antibiotic", "S", -genus) %>%
- ggplot(aes(x = genus,
- y = S,
- fill = Antibiotic)) +
- geom_col(position = "dodge2")
data_1st %>%
+ group_by(genus) %>%
+ summarise("1. Amoxicillin" = portion_S(amcl),
+ "2. Gentamicin" = portion_S(gent),
+ "3. Amox + gent" = portion_S(amcl, gent)) %>%
+ tidyr::gather("Antibiotic", "S", -genus) %>%
+ ggplot(aes(x = genus,
+ y = S,
+ fill = Antibiotic)) +
+ geom_col(position = "dodge2")
To show results in plots, most R users would nowadays use the ggplot2
package. This package lets you create plots in layers. You can read more about it on their website. A quick example would look like these syntaxes:
ggplot(data = a_data_set,
- mapping = aes(x = year,
- y = value)) +
- geom_col() +
- labs(title = "A title",
- subtitle = "A subtitle",
- x = "My X axis",
- y = "My Y axis")
-
-ggplot(a_data_set,
- aes(year, value) +
- geom_bar()
ggplot(data = a_data_set,
+ mapping = aes(x = year,
+ y = value)) +
+ geom_col() +
+ labs(title = "A title",
+ subtitle = "A subtitle",
+ x = "My X axis",
+ y = "My Y axis")
+
+ggplot(a_data_set,
+ aes(year, value) +
+ geom_bar()
The AMR
package contains functions to extend this ggplot2
package, for example geom_rsi()
. It automatically transforms data with count_df()
or portion_df()
and show results in stacked bars. Its simplest and shortest example:
Omit the translate_ab = FALSE
to have the antibiotic codes (amox, amcl, cipr, gent) translated to official WHO names (amoxicillin, amoxicillin and betalactamase inhibitor, ciprofloxacin, gentamicin).
If we group on e.g. the genus
column and add some additional functions from our package, we can create this:
# group the data on `genus`
-ggplot(data_1st %>% group_by(genus)) +
- # create bars with genus on x axis
- # it looks for variables with class `rsi`,
- # of which we have 4 (earlier created with `as.rsi`)
- geom_rsi(x = "genus") +
- # split plots on antibiotic
- facet_rsi(facet = "Antibiotic") +
- # make R red, I yellow and S green
- scale_rsi_colours() +
- # show percentages on y axis
- scale_y_percent(breaks = 0:4 * 25) +
- # turn 90 degrees, make it bars instead of columns
- coord_flip() +
- # add labels
- labs(title = "Resistance per genus and antibiotic",
- subtitle = "(this is fake data)") +
- # and print genus in italic to follow our convention
- # (is now y axis because we turned the plot)
- theme(axis.text.y = element_text(face = "italic"))
# group the data on `genus`
+ggplot(data_1st %>% group_by(genus)) +
+ # create bars with genus on x axis
+ # it looks for variables with class `rsi`,
+ # of which we have 4 (earlier created with `as.rsi`)
+ geom_rsi(x = "genus") +
+ # split plots on antibiotic
+ facet_rsi(facet = "Antibiotic") +
+ # make R red, I yellow and S green
+ scale_rsi_colours() +
+ # show percentages on y axis
+ scale_y_percent(breaks = 0:4 * 25) +
+ # turn 90 degrees, make it bars instead of columns
+ coord_flip() +
+ # add labels
+ labs(title = "Resistance per genus and antibiotic",
+ subtitle = "(this is fake data)") +
+ # and print genus in italic to follow our convention
+ # (is now y axis because we turned the plot)
+ theme(axis.text.y = element_text(face = "italic"))
To simplify this, we also created the ggplot_rsi()
function, which combines almost all above functions:
data_1st %>%
- group_by(genus) %>%
- ggplot_rsi(x = "genus",
- facet = "Antibiotic",
- breaks = 0:4 * 25,
- datalabels = FALSE) +
- coord_flip()
We can transform the data and apply the test in only a couple of lines:
-septic_patients %>%
- filter(hospital_id %in% c("A", "D")) %>% # filter on only hospitals A and D
- select(hospital_id, fosf) %>% # select the hospitals and fosfomycin
- group_by(hospital_id) %>% # group on the hospitals
- count_df(combine_IR = TRUE) %>% # count all isolates per group (hospital_id)
- tidyr::spread(hospital_id, Value) %>% # transform output so A and D are columns
- select(A, D) %>% # and select these only
- as.matrix() %>% # transform to good old matrix for fisher.test()
- fisher.test() # do Fisher's Exact Test
-#
-# Fisher's Exact Test for Count Data
-#
-# data: .
-# p-value = 0.03104
-# alternative hypothesis: true odds ratio is not equal to 1
-# 95 percent confidence interval:
-# 1.054283 4.735995
-# sample estimates:
-# odds ratio
-# 2.228006
septic_patients %>%
+ filter(hospital_id %in% c("A", "D")) %>% # filter on only hospitals A and D
+ select(hospital_id, fosf) %>% # select the hospitals and fosfomycin
+ group_by(hospital_id) %>% # group on the hospitals
+ count_df(combine_IR = TRUE) %>% # count all isolates per group (hospital_id)
+ tidyr::spread(hospital_id, Value) %>% # transform output so A and D are columns
+ select(A, D) %>% # and select these only
+ as.matrix() %>% # transform to good old matrix for fisher.test()
+ fisher.test() # do Fisher's Exact Test
+#
+# Fisher's Exact Test for Count Data
+#
+# data: .
+# p-value = 0.03104
+# alternative hypothesis: true odds ratio is not equal to 1
+# 95 percent confidence interval:
+# 1.054283 4.735995
+# sample estimates:
+# odds ratio
+# 2.228006
As can be seen, the p value is 0.03, which means that the fosfomycin resistances found in hospital A and D are really different.
EUCAST.Rmd
-EUCAST expert rules are a tabulated collection of expert knowledge on intrinsic resistances, exceptional resistance phenotypes and interpretive rules that may be applied to antimicrobial susceptibility testing in order to reduce errors and make appropriate recommendations for reporting particular resistances.
In Europe, most medical microbiological laboratories already apply these rules. Our package features their latest insights on intrinsic resistance and exceptional phenotypes. Moreover, the eucast_rules()
function we use for this purpose can also apply additional rules, like forcing
In Europe, a lot of medical microbiological laboratories already apply these rules (Brown et al., 2015). Our package features their latest insights on intrinsic resistance and exceptional phenotypes (version 9.0, 2019). Moreover, the eucast_rules()
function we use for this purpose can also apply additional rules, like forcing
(more will be available soon)
G_test.Rmd
(will be available soon - in the meanwhile, please read about this G-test in the manual)
+(will be available soon - in the meanwhile, please read about this G-test in the manual)