Browse Source

freq update

main
parent
commit
3efb54d016
  1. 2
      DESCRIPTION
  2. 2
      NAMESPACE
  3. 38
      R/data.R
  4. 7
      R/first_isolate.R
  5. 32
      R/freq.R
  6. 5
      R/misc.R
  7. 27
      R/zzz.R
  8. 1
      _pkgdown.yml
  9. BIN
      data/WHONET.rda
  10. BIN
      data/antibiotics.rda
  11. 2
      docs/LICENSE-text.html
  12. 470
      docs/articles/AMR.html
  13. BIN
      docs/articles/AMR_files/figure-html/plot 1-1.png
  14. BIN
      docs/articles/AMR_files/figure-html/plot 3-1.png
  15. BIN
      docs/articles/AMR_files/figure-html/plot 4-1.png
  16. BIN
      docs/articles/AMR_files/figure-html/plot 5-1.png
  17. 2
      docs/articles/EUCAST.html
  18. 2
      docs/articles/G_test.html
  19. 2
      docs/articles/Predict.html
  20. 184
      docs/articles/WHONET.html
  21. 2
      docs/articles/ab_property.html
  22. 8
      docs/articles/benchmarks.html
  23. 2
      docs/articles/freq.html
  24. 2
      docs/articles/index.html
  25. 2
      docs/articles/mo_property.html
  26. 2
      docs/authors.html
  27. 18
      docs/index.html
  28. 4
      docs/news/index.html
  29. 2
      docs/reference/AMR-deprecated.html
  30. 35
      docs/reference/AMR.html
  31. 2
      docs/reference/ITIS.html
  32. 2
      docs/reference/WHOCC.html
  33. 322
      docs/reference/WHONET.html
  34. 2
      docs/reference/abname.html
  35. 2
      docs/reference/age.html
  36. 10
      docs/reference/age_groups.html
  37. 4
      docs/reference/antibiotics.html
  38. 2
      docs/reference/as.atc.html
  39. 2
      docs/reference/as.mic.html
  40. 8
      docs/reference/as.mo.html
  41. 6
      docs/reference/as.rsi.html
  42. 2
      docs/reference/atc_property.html
  43. 16
      docs/reference/count.html
  44. 2
      docs/reference/eucast_rules.html
  45. 14
      docs/reference/first_isolate.html
  46. 16
      docs/reference/freq.html
  47. 2
      docs/reference/g.test.html
  48. 2
      docs/reference/get_locale.html
  49. 50
      docs/reference/ggplot_rsi.html
  50. 2
      docs/reference/guess_ab_col.html
  51. 8
      docs/reference/index.html
  52. 2
      docs/reference/join.html
  53. 6
      docs/reference/key_antibiotics.html
  54. 2
      docs/reference/kurtosis.html
  55. 4
      docs/reference/like.html
  56. 4
      docs/reference/mdro.html
  57. 2
      docs/reference/microorganisms.codes.html
  58. 2
      docs/reference/microorganisms.html
  59. 2
      docs/reference/microorganisms.old.html
  60. 2
      docs/reference/mo_property.html
  61. 2
      docs/reference/mo_source.html
  62. 2
      docs/reference/p.symbol.html
  63. 26
      docs/reference/portion.html
  64. 2
      docs/reference/read.4D.html
  65. 20
      docs/reference/resistance_predict.html
  66. 2
      docs/reference/septic_patients.html
  67. 2
      docs/reference/skewness.html
  68. 2
      docs/reference/supplementary_data.html
  69. 3
      docs/sitemap.xml
  70. 16
      index.md
  71. 2
      man/AMR-deprecated.Rd
  72. 31
      man/AMR.Rd
  73. 2
      man/ITIS.Rd
  74. 2
      man/WHOCC.Rd
  75. 48
      man/WHONET.Rd
  76. 2
      man/abname.Rd
  77. 2
      man/age.Rd
  78. 2
      man/age_groups.Rd
  79. 14
      man/antibiotics.Rd
  80. 2
      man/as.atc.Rd
  81. 2
      man/as.mic.Rd
  82. 2
      man/as.mo.Rd
  83. 2
      man/as.rsi.Rd
  84. 2
      man/atc_property.Rd
  85. 2
      man/count.Rd
  86. 2
      man/eucast_rules.Rd
  87. 2
      man/first_isolate.Rd
  88. 2
      man/freq.Rd
  89. 2
      man/g.test.Rd
  90. 2
      man/get_locale.Rd
  91. 2
      man/ggplot_rsi.Rd
  92. 2
      man/guess_ab_col.Rd
  93. 2
      man/join.Rd
  94. 2
      man/key_antibiotics.Rd
  95. 2
      man/kurtosis.Rd
  96. 2
      man/like.Rd
  97. 2
      man/mdro.Rd
  98. 2
      man/microorganisms.Rd
  99. 2
      man/microorganisms.codes.Rd
  100. 2
      man/microorganisms.old.Rd
  101. Some files were not shown because too many files have changed in this diff Show More

2
DESCRIPTION

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
Package: AMR
Version: 0.5.0.9015
Version: 0.5.0.9016
Date: 2019-01-29
Title: Antimicrobial Resistance Analysis
Authors@R: c(

2
NAMESPACE

@ -253,7 +253,7 @@ importFrom(graphics,plot) @@ -253,7 +253,7 @@ importFrom(graphics,plot)
importFrom(graphics,text)
importFrom(hms,is.hms)
importFrom(knitr,kable)
importFrom(rlang,as_name)
importFrom(rlang,as_label)
importFrom(rlang,enquos)
importFrom(rlang,eval_tidy)
importFrom(stats,complete.cases)

38
R/data.R

@ -42,13 +42,14 @@ @@ -42,13 +42,14 @@
#' \item{\code{useful_gramnegative}}{\code{FALSE} if not useful according to EUCAST, \code{NA} otherwise (see Source)}
#' \item{\code{useful_grampositive}}{\code{FALSE} if not useful according to EUCAST, \code{NA} otherwise (see Source)}
#' }
#' @source - World Health Organization (WHO) Collaborating Centre for Drug Statistics Methodology: \url{https://www.whocc.no/atc_ddd_index/}
#' @source World Health Organization (WHO) Collaborating Centre for Drug Statistics Methodology: \url{https://www.whocc.no/atc_ddd_index/}
#'
#' Table antibiotic coding EARSS (from WHONET 5.3): \url{http://www.madsonline.dk/Tutorials/landskoder_antibiotika_WM.pdf}
#'
#' EUCAST Expert Rules, Intrinsic Resistance and Exceptional Phenotypes Tables. Version 3.1, 2016: \url{http://www.eucast.org/fileadmin/src/media/PDFs/EUCAST_files/Expert_Rules/Expert_rules_intrinsic_exceptional_V3.1.pdf}
#'
#' European Commission Public Health PHARMACEUTICALS - COMMUNITY REGISTER: \url{http://ec.europa.eu/health/documents/community-register/html/atc.htm}
#' @inheritSection WHOCC WHOCC
#' @inheritSection AMR Read more on our website!
#' @seealso \code{\link{microorganisms}}
# use this later to further fill AMR::antibiotics
@ -203,6 +204,41 @@ @@ -203,6 +204,41 @@
#' @inheritSection AMR Read more on our website!
"septic_patients"
#' Data set with 500 isolates - WHONET example
#'
#' This example data set has the exact same structure as an export file from WHONET. Such files can be used with this package, as this example data set shows. The data itself was based on our \code{\link{septic_patients}} data set.
#' @format A \code{\link{data.frame}} with 500 observations and 53 variables:
#' \describe{
#' \item{\code{Identification number}}{ID of the sample}
#' \item{\code{Specimen number}}{ID of the specimen}
#' \item{\code{Organism}}{Microorganisms, can be coerced with \code{\link{as.mo}}}
#' \item{\code{Country}}{Country of origin}
#' \item{\code{Laboratory}}{Name of laboratory}
#' \item{\code{Last name}}{Last name of patient}
#' \item{\code{First name}}{Initial of patient}
#' \item{\code{Sex}}{Gender of patient}
#' \item{\code{Age}}{Age of patient}
#' \item{\code{Age category}}{Age group, can also be looked up using \code{\link{age_groups}}}
#' \item{\code{Date of admission}}{Date of hospital admission}
#' \item{\code{Specimen date}}{Date when specimen was received at laboratory}
#' \item{\code{Specimen type}}{Specimen type or group}
#' \item{\code{Specimen type (Numeric)}}{Translation of \code{"Specimen type"}}
#' \item{\code{Reason}}{Reason of request with Differential Diagnosis}
#' \item{\code{Isolate number}}{ID of isolate}
#' \item{\code{Organism type}}{Type of microorganism, can also be looked up using \code{\link{mo_type}}}
#' \item{\code{Serotype}}{Serotype of microorganism}
#' \item{\code{Beta-lactamase}}{Microorganism produces beta-lactamase?}
#' \item{\code{ESBL}}{Microorganism produces extended spectrum beta-lactamase?}
#' \item{\code{Carbapenemase}}{Microorganism produces carbapenemase?}
#' \item{\code{MRSA screening test}}{Microorganism is possible MRSA?}
#' \item{\code{Inducible clindamycin resistance}}{Clindamycin can be induced?}
#' \item{\code{Comment}}{Other comments}
#' \item{\code{Date of data entry}}{Date this data was entered in WHONET}
#' \item{\code{AMP_ND10:CIP_EE}}{27 different antibiotics. You can lookup the abbreviatons in the \code{\link{antibiotics}} data set, or use e.g. \code{\link{atc_name}("AMP")} to get the official name immediately.}
#' }
#' @inheritSection AMR Read more on our website!
"WHONET"
#' Supplementary Data
#'
#' These \code{\link{data.table}s} are transformed from the \code{\link{microorganisms}} and \code{\link{microorganisms}} data sets to improve speed of \code{\link{as.mo}}. They are meant for internal use only, and are only mentioned here for reference.

7
R/first_isolate.R

@ -206,7 +206,14 @@ first_isolate <- function(tbl, @@ -206,7 +206,14 @@ first_isolate <- function(tbl,
# -- patient id
if (is.null(col_patient_id)) {
if (all(c("First name", "Last name", "Sex", "Identification number") %in% colnames(tbl))) {
# WHONET support
tbl <- tbl %>% mutate(patient_id = paste(`First name`, `Last name`, Sex))
col_patient_id <- "patient_id"
message(blue(paste0("NOTE: Using combined columns ", bold("`First name`, `Last name` and `Sex`"), " as input for `col_patient_id`.")))
} else {
col_patient_id <- search_type_in_df(tbl = tbl, type = "patient_id")
}
}
if (is.null(col_patient_id)) {
stop("`col_patient_id` must be set.", call. = FALSE)

32
R/freq.R

@ -71,7 +71,7 @@ @@ -71,7 +71,7 @@
#' @importFrom utils browseVignettes
#' @importFrom hms is.hms
#' @importFrom crayon red green silver
#' @importFrom rlang enquos eval_tidy as_name
#' @importFrom rlang enquos eval_tidy as_label
#' @keywords summary summarise frequency freq
#' @rdname freq
#' @name freq
@ -206,6 +206,7 @@ frequency_tbl <- function(x, @@ -206,6 +206,7 @@ frequency_tbl <- function(x,
# x_haslevels <- !is.null(levels(x))
x.name <- NULL
cols <- NULL
cols.names <- NULL
if (any(class(x) == "list")) {
cols <- names(x)
x <- as.data.frame(x, stringsAsFactors = FALSE)
@ -224,9 +225,19 @@ frequency_tbl <- function(x, @@ -224,9 +225,19 @@ frequency_tbl <- function(x,
if (is.null(x.name)) {
x.name <- deparse(substitute(x))
}
if (x.name %like% "(%>%)") {
x.name <- x.name %>% strsplit("%>%", fixed = TRUE) %>% unlist() %>% .[1] %>% trimws()
}
if (x.name == ".") {
x.name <- NULL
x.name <- "a data.frame"
}
x.name <- paste0("`", x.name, "`")
x.name.dims <- x %>%
dim() %>%
format(decimal.mark = decimal.mark, big.mark = big.mark) %>%
trimws() %>%
paste(collapse = " x ")
x.name <- paste0(x.name, " (", x.name.dims, ")")
x.group <- group_vars(x)
if (length(x.group) > 1) {
@ -238,24 +249,19 @@ frequency_tbl <- function(x, @@ -238,24 +249,19 @@ frequency_tbl <- function(x,
if (length(user_exprs) > 0) {
new_list <- list(0)
for (i in 1:length(user_exprs)) {
new_list[[i]] <- eval_tidy(user_exprs[[i]], data = x)
this_name <- try( as_name(user_exprs[[i]]) , silent = TRUE)
if (class(this_name) == "try-error") {
this_name <- paste0("V", i)
}
cols <- c(cols, this_name)
cols <- c(cols, as_label(user_exprs[[i]]))
}
if (length(new_list) == 1 & length(x.group) == 0) {
# is now character
x <- new_list[[1]]
df <- NULL
cols <- NULL
} else {
# create data frame
df <- as.data.frame(new_list, col.names = paste0("V", 1:length(new_list)), stringsAsFactors = FALSE)
df <- as.data.frame(new_list, col.names = cols, stringsAsFactors = FALSE)
cols.names <- colnames(df)
}
} else {
# complete data frame
@ -264,7 +270,7 @@ frequency_tbl <- function(x, @@ -264,7 +270,7 @@ frequency_tbl <- function(x,
# support grouping variables
if (length(x.group) > 0) {
x.group_cols <- c(x.group, cols)
x.group_cols <- c(x.group, cols.names)
x <- bind_cols(x, df)
# if (droplevels == TRUE) {
# x <- x %>% mutate_at(vars(x.group_cols), droplevels)
@ -302,11 +308,10 @@ frequency_tbl <- function(x, @@ -302,11 +308,10 @@ frequency_tbl <- function(x,
# no groups, multiple values like: septic_patients %>% freq(mo, mo_genus(mo))
x <- df
df <- NULL
cols <- NULL
}
}
if (length(cols) > 0 & is.data.frame(x)) {
x <- x[, cols]
x <- x[, cols.names]
}
} else if (any(class(x) == "table")) {
@ -328,6 +333,7 @@ frequency_tbl <- function(x, @@ -328,6 +333,7 @@ frequency_tbl <- function(x,
x <- x %>% pull(1)
} else if (ncol(x) < 10) {
mult.columns <- ncol(x)
# paste old columns together
x <- do.call(paste, c(x[colnames(x)], sep = sep))
} else {
stop("A maximum of 9 columns can be analysed at the same time.", call. = FALSE)

5
R/misc.R

@ -152,7 +152,10 @@ search_type_in_df <- function(tbl, type) { @@ -152,7 +152,10 @@ search_type_in_df <- function(tbl, type) {
# -- date
if (type == "date") {
for (i in 1:ncol(tbl)) {
if ("Date" %in% class(tbl %>% pull(i)) | "POSIXct" %in% class(tbl %>% pull(i))) {
if (any(colnames(tbl) %like% "^(Specimen date)")) {
# WHONET support
found <- colnames(tbl)[colnames(tbl) %like% "^(Specimen date)"][1]
} else if ("Date" %in% class(tbl %>% pull(i)) | "POSIXct" %in% class(tbl %>% pull(i))) {
found <- colnames(tbl)[i]
break
}

27
R/zzz.R

@ -21,19 +21,34 @@ @@ -21,19 +21,34 @@
#' The \code{AMR} Package
#'
#' Welcome to the \code{AMR} package. This page gives some additional contact information about the authors.
#' Welcome to the \code{AMR} package.
#' @details
#' This package was intended to simplify the analysis and prediction of Antimicrobial Resistance (AMR) and to work with microbial and antimicrobial properties by using evidence-based methods.
#' \code{AMR} is a free and open-source R package to simplify the analysis and prediction of Antimicrobial Resistance (AMR) and to work with microbial and antimicrobial properties by using evidence-based methods. It supports any table format, including WHONET/EARS-Net data.
#'
#' This package was created for both academic research and routine analysis by PhD students of the Faculty of Medical Sciences of the University of Groningen and the Medical Microbiology & Infection Prevention (MMBI) department of the University Medical Center Groningen (UMCG).
#' @section Read more on our website!:
#' \if{html}{\figure{logo.png}{options: height=40px style=margin-bottom:5px} \cr}
#' On our website \url{https://msberends.gitlab.io/AMR} you can find \href{https://msberends.gitlab.io/AMR/articles/AMR.html}{a omprehensive tutorial} about how to conduct AMR analysis and find \href{https://msberends.gitlab.io/AMR/reference}{the complete documentation of all functions}, which reads a lot easier than in R.
#' We created this package for both academic research and routine analysis at the Faculty of Medical Sciences of the University of Groningen and the Medical Microbiology & Infection Prevention (MMBI) department of the University Medical Center Groningen (UMCG). This R package is actively maintained and free software; you can freely use and distribute it for both personal and commercial (but not patent) purposes under the terms of the GNU General Public License version 2.0 (GPL-2), as published by the Free Software Foundation.
#'
#' This package can be used for:
#' \itemize{
#' \item{Calculating antimicrobial resistance}
#' \item{Predicting antimicrobial resistance using regression models}
#' \item{Getting properties for any microorganism (like Gram stain, species, genus or family)}
#' \item{Getting properties for any antibiotic (like name, ATC code, defined daily dose or trade name)}
#' \item{Plotting antimicrobial resistance}
#' \item{Determining first isolates to be used for AMR analysis}
#' \item{Applying EUCAST rules}
#' \item{Determining multi-drug resistance organisms (MDRO)}
#' \item{Descriptive statistics: frequency tables, kurtosis and skewness}
#' }
#' @section Authors:
#' Matthijs S. Berends[1,2] Christian F. Luz[1], Erwin E.A. Hassing[2], Corinna Glasner[1], Alex W. Friedrich[1], Bhanu N.M. Sinha[1] \cr
#'
#' [1] Department of Medical Microbiology, University of Groningen, University Medical Center Groningen, Groningen, the Netherlands - \url{rug.nl} \url{umcg.nl} \cr
#' [2] Certe Medical Diagnostics & Advice, Groningen, the Netherlands - \url{certe.nl}
#' @section Read more on our website!:
#' \if{html}{\figure{logo.png}{options: height=40px style=margin-bottom:5px} \cr}
#' On our website \url{https://msberends.gitlab.io/AMR} you can find \href{https://msberends.gitlab.io/AMR/articles/AMR.html}{a comprehensive tutorial} about how to conduct AMR analysis, the \href{https://msberends.gitlab.io/AMR/reference}{complete documentation of all functions} (which reads a lot easier than here in R) and \href{https://msberends.gitlab.io/AMR/articles/WHONET.html}{an example analysis using WHONET data}.
#' @section Contact us:
#' For suggestions, comments or questions, please contact us at:
#'

1
_pkgdown.yml

@ -136,6 +136,7 @@ reference: @@ -136,6 +136,7 @@ reference:
- '`antibiotics`'
- '`microorganisms`'
- '`septic_patients`'
- '`WHONET`'
- '`microorganisms.codes`'
- '`microorganisms.old`'
- '`supplementary_data`'

BIN
data/WHONET.rda

Binary file not shown.

BIN
data/antibiotics.rda

Binary file not shown.

2
docs/LICENSE-text.html

@ -78,7 +78,7 @@ @@ -78,7 +78,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.5.0.9015</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.5.0.9016</span>
</span>
</div>

470
docs/articles/AMR.html

@ -185,7 +185,7 @@ @@ -185,7 +185,7 @@
<h1>How to conduct AMR analysis</h1>
<h4 class="author">Matthijs S. Berends</h4>
<h4 class="date">28 January 2019</h4>
<h4 class="date">29 January 2019</h4>
<div class="hidden name"><code>AMR.Rmd</code></div>
@ -194,7 +194,7 @@ @@ -194,7 +194,7 @@
<p><strong>Note:</strong> values on this page will change with every website update since they are based on randomly created values and the page was written in <a href="https://rmarkdown.rstudio.com/">RMarkdown</a>. However, the methodology remains unchanged. This page was generated on 28 January 2019.</p>
<p><strong>Note:</strong> values on this page will change with every website update since they are based on randomly created values and the page was written in <a href="https://rmarkdown.rstudio.com/">RMarkdown</a>. However, the methodology remains unchanged. This page was generated on 29 January 2019.</p>
<div id="introduction" class="section level2">
<h2 class="hasAnchor">
<a href="#introduction" class="anchor"></a>Introduction</h2>
@ -210,21 +210,21 @@ @@ -210,21 +210,21 @@
</tr></thead>
<tbody>
<tr class="odd">
<td align="center">2019-01-28</td>
<td align="center">2019-01-29</td>
<td align="center">abcd</td>
<td align="center">Escherichia coli</td>
<td align="center">S</td>
<td align="center">S</td>
</tr>
<tr class="even">
<td align="center">2019-01-28</td>
<td align="center">2019-01-29</td>
<td align="center">abcd</td>
<td align="center">Escherichia coli</td>
<td align="center">S</td>
<td align="center">R</td>
</tr>
<tr class="odd">
<td align="center">2019-01-28</td>
<td align="center">2019-01-29</td>
<td align="center">efgh</td>
<td align="center">Escherichia coli</td>
<td align="center">R</td>
@ -285,18 +285,18 @@ @@ -285,18 +285,18 @@
<div id="put-everything-together" class="section level4">
<h4 class="hasAnchor">
<a href="#put-everything-together" class="anchor"></a>Put everything together</h4>
<p>Using the <code><a href="https://www.rdocumentation.org/packages/dplyr/topics/sample">sample()</a></code> 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 <code>prob</code> parameter.</p>
<div class="sourceCode" id="cb7"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb7-1" data-line-number="1">data &lt;-<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/data.frame">data.frame</a></span>(<span class="dt">date =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/dplyr/topics/sample">sample</a></span>(dates, <span class="dv">5000</span>, <span class="dt">replace =</span> <span class="ot">TRUE</span>),</a>
<a class="sourceLine" id="cb7-2" data-line-number="2"> <span class="dt">patient_id =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/dplyr/topics/sample">sample</a></span>(patients, <span class="dv">5000</span>, <span class="dt">replace =</span> <span class="ot">TRUE</span>),</a>
<a class="sourceLine" id="cb7-3" data-line-number="3"> <span class="dt">hospital =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/dplyr/topics/sample">sample</a></span>(hospitals, <span class="dv">5000</span>, <span class="dt">replace =</span> <span class="ot">TRUE</span>, <span class="dt">prob =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="fl">0.30</span>, <span class="fl">0.35</span>, <span class="fl">0.15</span>, <span class="fl">0.20</span>)),</a>
<a class="sourceLine" id="cb7-4" data-line-number="4"> <span class="dt">bacteria =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/dplyr/topics/sample">sample</a></span>(bacteria, <span class="dv">5000</span>, <span class="dt">replace =</span> <span class="ot">TRUE</span>, <span class="dt">prob =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="fl">0.50</span>, <span class="fl">0.25</span>, <span class="fl">0.15</span>, <span class="fl">0.10</span>)),</a>
<a class="sourceLine" id="cb7-5" data-line-number="5"> <span class="dt">amox =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/dplyr/topics/sample">sample</a></span>(ab_interpretations, <span class="dv">5000</span>, <span class="dt">replace =</span> <span class="ot">TRUE</span>, <span class="dt">prob =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="fl">0.60</span>, <span class="fl">0.05</span>, <span class="fl">0.35</span>)),</a>
<a class="sourceLine" id="cb7-6" data-line-number="6"> <span class="dt">amcl =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/dplyr/topics/sample">sample</a></span>(ab_interpretations, <span class="dv">5000</span>, <span class="dt">replace =</span> <span class="ot">TRUE</span>, <span class="dt">prob =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="fl">0.75</span>, <span class="fl">0.10</span>, <span class="fl">0.15</span>)),</a>
<a class="sourceLine" id="cb7-7" data-line-number="7"> <span class="dt">cipr =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/dplyr/topics/sample">sample</a></span>(ab_interpretations, <span class="dv">5000</span>, <span class="dt">replace =</span> <span class="ot">TRUE</span>, <span class="dt">prob =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="fl">0.80</span>, <span class="fl">0.00</span>, <span class="fl">0.20</span>)),</a>
<a class="sourceLine" id="cb7-8" data-line-number="8"> <span class="dt">gent =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/dplyr/topics/sample">sample</a></span>(ab_interpretations, <span class="dv">5000</span>, <span class="dt">replace =</span> <span class="ot">TRUE</span>, <span class="dt">prob =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="fl">0.92</span>, <span class="fl">0.00</span>, <span class="fl">0.08</span>))</a>
<p>Using the <code><a href="https://dplyr.tidyverse.org/reference/sample.html">sample()</a></code> 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 <code>prob</code> parameter.</p>
<div class="sourceCode" id="cb7"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb7-1" data-line-number="1">data &lt;-<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/data.frame">data.frame</a></span>(<span class="dt">date =</span> <span class="kw"><a href="https://dplyr.tidyverse.org/reference/sample.html">sample</a></span>(dates, <span class="dv">5000</span>, <span class="dt">replace =</span> <span class="ot">TRUE</span>),</a>
<a class="sourceLine" id="cb7-2" data-line-number="2"> <span class="dt">patient_id =</span> <span class="kw"><a href="https://dplyr.tidyverse.org/reference/sample.html">sample</a></span>(patients, <span class="dv">5000</span>, <span class="dt">replace =</span> <span class="ot">TRUE</span>),</a>
<a class="sourceLine" id="cb7-3" data-line-number="3"> <span class="dt">hospital =</span> <span class="kw"><a href="https://dplyr.tidyverse.org/reference/sample.html">sample</a></span>(hospitals, <span class="dv">5000</span>, <span class="dt">replace =</span> <span class="ot">TRUE</span>, <span class="dt">prob =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="fl">0.30</span>, <span class="fl">0.35</span>, <span class="fl">0.15</span>, <span class="fl">0.20</span>)),</a>
<a class="sourceLine" id="cb7-4" data-line-number="4"> <span class="dt">bacteria =</span> <span class="kw"><a href="https://dplyr.tidyverse.org/reference/sample.html">sample</a></span>(bacteria, <span class="dv">5000</span>, <span class="dt">replace =</span> <span class="ot">TRUE</span>, <span class="dt">prob =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="fl">0.50</span>, <span class="fl">0.25</span>, <span class="fl">0.15</span>, <span class="fl">0.10</span>)),</a>
<a class="sourceLine" id="cb7-5" data-line-number="5"> <span class="dt">amox =</span> <span class="kw"><a href="https://dplyr.tidyverse.org/reference/sample.html">sample</a></span>(ab_interpretations, <span class="dv">5000</span>, <span class="dt">replace =</span> <span class="ot">TRUE</span>, <span class="dt">prob =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="fl">0.60</span>, <span class="fl">0.05</span>, <span class="fl">0.35</span>)),</a>
<a class="sourceLine" id="cb7-6" data-line-number="6"> <span class="dt">amcl =</span> <span class="kw"><a href="https://dplyr.tidyverse.org/reference/sample.html">sample</a></span>(ab_interpretations, <span class="dv">5000</span>, <span class="dt">replace =</span> <span class="ot">TRUE</span>, <span class="dt">prob =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="fl">0.75</span>, <span class="fl">0.10</span>, <span class="fl">0.15</span>)),</a>
<a class="sourceLine" id="cb7-7" data-line-number="7"> <span class="dt">cipr =</span> <span class="kw"><a href="https://dplyr.tidyverse.org/reference/sample.html">sample</a></span>(ab_interpretations, <span class="dv">5000</span>, <span class="dt">replace =</span> <span class="ot">TRUE</span>, <span class="dt">prob =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="fl">0.80</span>, <span class="fl">0.00</span>, <span class="fl">0.20</span>)),</a>
<a class="sourceLine" id="cb7-8" data-line-number="8"> <span class="dt">gent =</span> <span class="kw"><a href="https://dplyr.tidyverse.org/reference/sample.html">sample</a></span>(ab_interpretations, <span class="dv">5000</span>, <span class="dt">replace =</span> <span class="ot">TRUE</span>, <span class="dt">prob =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="fl">0.92</span>, <span class="fl">0.00</span>, <span class="fl">0.08</span>))</a>
<a class="sourceLine" id="cb7-9" data-line-number="9"> )</a></code></pre></div>
<p>Using the <code><a href="https://www.rdocumentation.org/packages/dplyr/topics/join">left_join()</a></code> function from the <code>dplyr</code> package, we can ‘map’ the gender to the patient ID using the <code>patients_table</code> object we created earlier:</p>
<div class="sourceCode" id="cb8"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb8-1" data-line-number="1">data &lt;-<span class="st"> </span>data <span class="op">%&gt;%</span><span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/dplyr/topics/join">left_join</a></span>(patients_table)</a></code></pre></div>
<p>Using the <code><a href="https://dplyr.tidyverse.org/reference/join.html">left_join()</a></code> function from the <code>dplyr</code> package, we can ‘map’ the gender to the patient ID using the <code>patients_table</code> object we created earlier:</p>
<div class="sourceCode" id="cb8"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb8-1" data-line-number="1">data &lt;-<span class="st"> </span>data <span class="op">%&gt;%</span><span class="st"> </span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/join.html">left_join</a></span>(patients_table)</a></code></pre></div>
<p>The resulting data set contains 5,000 blood culture isolates. With the <code><a href="https://www.rdocumentation.org/packages/utils/topics/head">head()</a></code> function we can preview the first 6 values of this data set:</p>
<div class="sourceCode" id="cb9"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb9-1" data-line-number="1"><span class="kw"><a href="https://www.rdocumentation.org/packages/utils/topics/head">head</a></span>(data)</a></code></pre></div>
<table class="table">
@ -313,66 +313,66 @@ @@ -313,66 +313,66 @@
</tr></thead>
<tbody>
<tr class="odd">
<td align="center">2011-12-05</td>
<td align="center">N6</td>
<td align="center">2015-02-23</td>
<td align="center">C5</td>
<td align="center">Hospital B</td>
<td align="center">Escherichia coli</td>
<td align="center">Staphylococcus aureus</td>
<td align="center">R</td>
<td align="center">R</td>
<td align="center">I</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">F</td>
<td align="center">M</td>
</tr>
<tr class="even">
<td align="center">2012-08-21</td>
<td align="center">O9</td>
<td align="center">Hospital B</td>
<td align="center">2011-10-29</td>
<td align="center">X2</td>
<td align="center">Hospital C</td>
<td align="center">Streptococcus pneumoniae</td>
<td align="center">I</td>
<td align="center">R</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">F</td>
</tr>
<tr class="odd">
<td align="center">2015-10-17</td>
<td align="center">P4</td>
<td align="center">Hospital D</td>
<td align="center">2010-06-10</td>
<td align="center">J5</td>
<td align="center">Hospital B</td>
<td align="center">Escherichia coli</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">F</td>
<td align="center">M</td>
</tr>
<tr class="even">
<td align="center">2014-03-12</td>
<td align="center">V8</td>
<td align="center">2013-11-09</td>
<td align="center">U4</td>
<td align="center">Hospital A</td>
<td align="center">Escherichia coli</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">F</td>
</tr>
<tr class="odd">
<td align="center">2015-04-17</td>
<td align="center">L3</td>
<td align="center">Hospital D</td>
<td align="center">Escherichia coli</td>
<td align="center">2010-10-12</td>
<td align="center">C3</td>
<td align="center">Hospital A</td>
<td align="center">Staphylococcus aureus</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">I</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">M</td>
</tr>
<tr class="even">
<td align="center">2012-09-29</td>
<td align="center">Q10</td>
<td align="center">Hospital B</td>
<td align="center">2017-12-04</td>
<td align="center">T3</td>
<td align="center">Hospital C</td>
<td align="center">Escherichia coli</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
@ -396,15 +396,15 @@ @@ -396,15 +396,15 @@
#
# Item Count Percent Cum. Count Cum. Percent
# --- ----- ------ -------- ----------- -------------
# 1 M 2,640 52.8% 2,640 52.8%
# 2 F 2,360 47.2% 5,000 100.0%</code></pre>
# 1 M 2,586 51.7% 2,586 51.7%
# 2 F 2,414 48.3% 5,000 100.0%</code></pre>
<p>So, we can draw at least two conclusions immediately. From a data scientist perspective, the data looks clean: only values <code>M</code> and <code>F</code>. From a researcher perspective: there are slightly more men. Nothing we didn’t already know.</p>
<p>The data is already quite clean, but we still need to transform some variables. The <code>bacteria</code> 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 <code><a href="https://www.rdocumentation.org/packages/dplyr/topics/mutate">mutate()</a></code> function of the <code>dplyr</code> package makes this really easy:</p>
<p>The data is already quite clean, but we still need to transform some variables. The <code>bacteria</code> 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 <code><a href="https://dplyr.tidyverse.org/reference/mutate.html">mutate()</a></code> function of the <code>dplyr</code> package makes this really easy:</p>
<div class="sourceCode" id="cb12"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb12-1" data-line-number="1">data &lt;-<span class="st"> </span>data <span class="op">%&gt;%</span></a>
<a class="sourceLine" id="cb12-2" data-line-number="2"><span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/dplyr/topics/mutate">mutate</a></span>(<span class="dt">bacteria =</span> <span class="kw"><a href="../reference/as.mo.html">as.mo</a></span>(bacteria))</a></code></pre></div>
<p>We also want to transform the antibiotics, because in real life data we don’t know if they are really clean. The <code><a href="../reference/as.rsi.html">as.rsi()</a></code> function ensures reliability and reproducibility in these kind of variables. The <code><a href="https://www.rdocumentation.org/packages/dplyr/topics/summarise_all">mutate_at()</a></code> will run the <code><a href="../reference/as.rsi.html">as.rsi()</a></code> function on defined variables:</p>
<a class="sourceLine" id="cb12-2" data-line-number="2"><span class="st"> </span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/mutate.html">mutate</a></span>(<span class="dt">bacteria =</span> <span class="kw"><a href="../reference/as.mo.html">as.mo</a></span>(bacteria))</a></code></pre></div>
<p>We also want to transform the antibiotics, because in real life data we don’t know if they are really clean. The <code><a href="../reference/as.rsi.html">as.rsi()</a></code> function ensures reliability and reproducibility in these kind of variables. The <code><a href="https://dplyr.tidyverse.org/reference/summarise_all.html">mutate_at()</a></code> will run the <code><a href="../reference/as.rsi.html">as.rsi()</a></code> function on defined variables:</p>
<div class="sourceCode" id="cb13"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb13-1" data-line-number="1">data &lt;-<span class="st"> </span>data <span class="op">%&gt;%</span></a>
<a class="sourceLine" id="cb13-2" data-line-number="2"><span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/dplyr/topics/summarise_all">mutate_at</a></span>(<span class="kw"><a href="https://www.rdocumentation.org/packages/dplyr/topics/vars">vars</a></span>(amox<span class="op">:</span>gent), as.rsi)</a></code></pre></div>
<a class="sourceLine" id="cb13-2" data-line-number="2"><span class="st"> </span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/summarise_all.html">mutate_at</a></span>(<span class="kw"><a href="https://dplyr.tidyverse.org/reference/vars.html">vars</a></span>(amox<span class="op">:</span>gent), as.rsi)</a></code></pre></div>
<p>Finally, we will apply <a href="http://www.eucast.org/expert_rules_and_intrinsic_resistance/">EUCAST rules</a> 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 <code><a href="../reference/eucast_rules.html">eucast_rules()</a></code> function can also apply additional rules, like forcing <help title="ATC: J01CA01">ampicillin</help> = R when <help title="ATC: J01CR02">amoxicillin/clavulanic acid</help> = R.</p>
<p>Because the amoxicillin (column <code>amox</code>) and amoxicillin/clavulanic acid (column <code>amcl</code>) in our data were generated randomly, some rows will undoubtedly contain amox = S and amcl = R, which is technically impossible. The <code><a href="../reference/eucast_rules.html">eucast_rules()</a></code> fixes this:</p>
<div class="sourceCode" id="cb14"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb14-1" data-line-number="1">data &lt;-<span class="st"> </span><span class="kw"><a href="../reference/eucast_rules.html">eucast_rules</a></span>(data, <span class="dt">col_mo =</span> <span class="st">"bacteria"</span>)</a>
@ -428,10 +428,10 @@ @@ -428,10 +428,10 @@
<a class="sourceLine" id="cb14-19" data-line-number="19"><span class="co"># Kingella kingae (no changes)</span></a>
<a class="sourceLine" id="cb14-20" data-line-number="20"><span class="co"># </span></a>
<a class="sourceLine" id="cb14-21" data-line-number="21"><span class="co"># EUCAST Expert Rules, Intrinsic Resistance and Exceptional Phenotypes (v3.1, 2016)</span></a>
<a class="sourceLine" id="cb14-22" data-line-number="22"><span class="co"># Table 1: Intrinsic resistance in Enterobacteriaceae (313 changes)</span></a>
<a class="sourceLine" id="cb14-22" data-line-number="22"><span class="co"># Table 1: Intrinsic resistance in Enterobacteriaceae (324 changes)</span></a>
<a class="sourceLine" id="cb14-23" data-line-number="23"><span class="co"># Table 2: Intrinsic resistance in non-fermentative Gram-negative bacteria (no changes)</span></a>
<a class="sourceLine" id="cb14-24" data-line-number="24"><span class="co"># Table 3: Intrinsic resistance in other Gram-negative bacteria (no changes)</span></a>
<a class="sourceLine" id="cb14-25" data-line-number="25"><span class="co"># Table 4: Intrinsic resistance in Gram-positive bacteria (649 changes)</span></a>
<a class="sourceLine" id="cb14-25" data-line-number="25"><span class="co"># Table 4: Intrinsic resistance in Gram-positive bacteria (722 changes)</span></a>
<a class="sourceLine" id="cb14-26" data-line-number="26"><span class="co"># Table 8: Interpretive rules for B-lactam agents and Gram-positive cocci (no changes)</span></a>
<a class="sourceLine" id="cb14-27" data-line-number="27"><span class="co"># Table 9: Interpretive rules for B-lactam agents and Gram-negative rods (no changes)</span></a>
<a class="sourceLine" id="cb14-28" data-line-number="28"><span class="co"># Table 10: Interpretive rules for B-lactam agents and other Gram-negative bacteria (no changes)</span></a>
@ -447,14 +447,14 @@ @@ -447,14 +447,14 @@
<a class="sourceLine" id="cb14-38" data-line-number="38"><span class="co"># Non-EUCAST: piperacillin/tazobactam = S where piperacillin = S (no changes)</span></a>
<a class="sourceLine" id="cb14-39" data-line-number="39"><span class="co"># Non-EUCAST: trimethoprim/sulfa = S where trimethoprim = S (no changes)</span></a>
<a class="sourceLine" id="cb14-40" data-line-number="40"><span class="co"># </span></a>
<a class="sourceLine" id="cb14-41" data-line-number="41"><span class="co"># =&gt; EUCAST rules affected 1,804 out of 5,000 rows -&gt; changed 962 test results.</span></a></code></pre></div>
<a class="sourceLine" id="cb14-41" data-line-number="41"><span class="co"># =&gt; EUCAST rules affected 1,853 out of 5,000 rows -&gt; changed 1,046 test results.</span></a></code></pre></div>
</div>
<div id="adding-new-variables" class="section level2">
<h2 class="hasAnchor">
<a href="#adding-new-variables" class="anchor"></a>Adding new variables</h2>
<p>Now that we have the microbial ID, we can add some taxonomic properties:</p>
<div class="sourceCode" id="cb15"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb15-1" data-line-number="1">data &lt;-<span class="st"> </span>data <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb15-2" data-line-number="2"><span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/dplyr/topics/mutate">mutate</a></span>(<span class="dt">gramstain =</span> <span class="kw"><a href="../reference/mo_property.html">mo_gramstain</a></span>(bacteria),</a>
<a class="sourceLine" id="cb15-2" data-line-number="2"><span class="st"> </span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/mutate.html">mutate</a></span>(<span class="dt">gramstain =</span> <span class="kw"><a href="../reference/mo_property.html">mo_gramstain</a></span>(bacteria),</a>
<a class="sourceLine" id="cb15-3" data-line-number="3"> <span class="dt">genus =</span> <span class="kw"><a href="../reference/mo_property.html">mo_genus</a></span>(bacteria),</a>
<a class="sourceLine" id="cb15-4" data-line-number="4"> <span class="dt">species =</span> <span class="kw"><a href="../reference/mo_property.html">mo_species</a></span>(bacteria))</a></code></pre></div>
<div id="first-isolates" class="section level3">
@ -468,14 +468,14 @@ @@ -468,14 +468,14 @@
</blockquote>
<p>This <code>AMR</code> package includes this methodology with the <code><a href="../reference/first_isolate.html">first_isolate()</a></code> 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:</p>
<div class="sourceCode" id="cb16"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb16-1" data-line-number="1">data &lt;-<span class="st"> </span>data <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb16-2" data-line-number="2"><span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/dplyr/topics/mutate">mutate</a></span>(<span class="dt">first =</span> <span class="kw"><a href="../reference/first_isolate.html">first_isolate</a></span>(.))</a>
<a class="sourceLine" id="cb16-2" data-line-number="2"><span class="st"> </span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/mutate.html">mutate</a></span>(<span class="dt">first =</span> <span class="kw"><a href="../reference/first_isolate.html">first_isolate</a></span>(.))</a>
<a class="sourceLine" id="cb16-3" data-line-number="3"><span class="co"># </span><span class="al">NOTE</span><span class="co">: Using column `bacteria` as input for `col_mo`.</span></a>
<a class="sourceLine" id="cb16-4" data-line-number="4"><span class="co"># </span><span class="al">NOTE</span><span class="co">: Using column `date` as input for `col_date`.</span></a>
<a class="sourceLine" id="cb16-5" data-line-number="5"><span class="co"># </span><span class="al">NOTE</span><span class="co">: Using column `patient_id` as input for `col_patient_id`.</span></a>
<a class="sourceLine" id="cb16-6" data-line-number="6"><span class="co"># =&gt; Found 2,941 first isolates (58.8% of total)</span></a></code></pre></div>
<p>So only 58.8% is suitable for resistance analysis! We can now filter on is with the <code><a href="https://www.rdocumentation.org/packages/dplyr/topics/filter">filter()</a></code> function, also from the <code>dplyr</code> package:</p>
<a class="sourceLine" id="cb16-6" data-line-number="6"><span class="co"># =&gt; Found 2,926 first isolates (58.5% of total)</span></a></code></pre></div>
<p>So only 58.5% is suitable for resistance analysis! We can now filter on is with the <code><a href="https://dplyr.tidyverse.org/reference/filter.html">filter()</a></code> function, also from the <code>dplyr</code> package:</p>
<div class="sourceCode" id="cb17"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb17-1" data-line-number="1">data_1st &lt;-<span class="st"> </span>data <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb17-2" data-line-number="2"><span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/dplyr/topics/filter">filter</a></span>(first <span class="op">==</span><span class="st"> </span><span class="ot">TRUE</span>)</a></code></pre></div>
<a class="sourceLine" id="cb17-2" data-line-number="2"><span class="st"> </span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/filter.html">filter</a></span>(first <span class="op">==</span><span class="st"> </span><span class="ot">TRUE</span>)</a></code></pre></div>
<p>For future use, the above two syntaxes can be shortened with the <code><a href="../reference/first_isolate.html">filter_first_isolate()</a></code> function:</p>
<div class="sourceCode" id="cb18"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb18-1" data-line-number="1">data_1st &lt;-<span class="st"> </span>data <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb18-2" data-line-number="2"><span class="st"> </span><span class="kw"><a href="../reference/first_isolate.html">filter_first_isolate</a></span>()</a></code></pre></div>
@ -499,74 +499,74 @@ @@ -499,74 +499,74 @@
<tbody>
<tr class="odd">
<td align="center">1</td>
<td align="center">2010-02-22</td>
<td align="center">Y8</td>
<td align="center">2010-08-27</td>
<td align="center">X6</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">TRUE</td>
</tr>
<tr class="even">
<td align="center">2</td>
<td align="center">2011-11-07</td>
<td align="center">Y8</td>
<td align="center">2010-12-12</td>
<td align="center">X6</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">I</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">TRUE</td>
<td align="center">FALSE</td>
</tr>
<tr class="odd">
<td align="center">3</td>
<td align="center">2012-05-14</td>
<td align="center">Y8</td>
<td align="center">2011-05-24</td>
<td align="center">X6</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">I</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">FALSE</td>
</tr>
<tr class="even">
<td align="center">4</td>
<td align="center">2012-10-27</td>
<td align="center">Y8</td>
<td align="center">2011-09-03</td>
<td align="center">X6</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">FALSE</td>
<td align="center">TRUE</td>
</tr>
<tr class="odd">
<td align="center">5</td>
<td align="center">2013-03-26</td>
<td align="center">Y8</td>
<td align="center">2011-09-21</td>
<td align="center">X6</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">S</td>
<td align="center">I</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">TRUE</td>
<td align="center">S</td>
<td align="center">FALSE</td>
</tr>
<tr class="even">
<td align="center">6</td>
<td align="center">2013-05-26</td>
<td align="center">Y8</td>
<td align="center">2011-10-31</td>
<td align="center">X6</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">FALSE</td>
</tr>
<tr class="odd">
<td align="center">7</td>
<td align="center">2013-10-20</td>
<td align="center">Y8</td>
<td align="center">2012-07-02</td>
<td align="center">X6</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">S</td>
<td align="center">S</td>
@ -576,51 +576,51 @@ @@ -576,51 +576,51 @@
</tr>
<tr class="even">
<td align="center">8</td>
<td align="center">2015-03-07</td>
<td align="center">Y8</td>
<td align="center">2012-12-30</td>
<td align="center">X6</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">TRUE</td>
</tr>
<tr class="odd">
<td align="center">9</td>
<td align="center">2015-03-20</td>
<td align="center">Y8</td>
<td align="center">2013-03-15</td>
<td align="center">X6</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">S</td>
<td align="center">I</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">FALSE</td>
</tr>
<tr class="even">
<td align="center">10</td>
<td align="center">2015-10-18</td>
<td align="center">Y8</td>
<td align="center">2014-01-14</td>
<td align="center">X6</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">FALSE</td>
<td align="center">TRUE</td>
</tr>
</tbody>
</table>
<p>Only 4 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 <code><a href="../reference/key_antibiotics.html">key_antibiotics()</a></code> 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.</p>
<p>If a column exists with a name like ‘key(…)ab’ the <code><a href="../reference/first_isolate.html">first_isolate()</a></code> function will automatically use it and determine the first weighted isolates. Mind the NOTEs in below output:</p>
<div class="sourceCode" id="cb19"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb19-1" data-line-number="1">data &lt;-<span class="st"> </span>data <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb19-2" data-line-number="2"><span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/dplyr/topics/mutate">mutate</a></span>(<span class="dt">keyab =</span> <span class="kw"><a href="../reference/key_antibiotics.html">key_antibiotics</a></span>(.)) <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb19-3" data-line-number="3"><span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/dplyr/topics/mutate">mutate</a></span>(<span class="dt">first_weighted =</span> <span class="kw"><a href="../reference/first_isolate.html">first_isolate</a></span>(.))</a>
<a class="sourceLine" id="cb19-2" data-line-number="2"><span class="st"> </span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/mutate.html">mutate</a></span>(<span class="dt">keyab =</span> <span class="kw"><a href="../reference/key_antibiotics.html">key_antibiotics</a></span>(.)) <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb19-3" data-line-number="3"><span class="st"> </span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/mutate.html">mutate</a></span>(<span class="dt">first_weighted =</span> <span class="kw"><a href="../reference/first_isolate.html">first_isolate</a></span>(.))</a>
<a class="sourceLine" id="cb19-4" data-line-number="4"><span class="co"># </span><span class="al">NOTE</span><span class="co">: Using column `bacteria` as input for `col_mo`.</span></a>
<a class="sourceLine" id="cb19-5" data-line-number="5"><span class="co"># </span><span class="al">NOTE</span><span class="co">: Using column `bacteria` as input for `col_mo`.</span></a>
<a class="sourceLine" id="cb19-6" data-line-number="6"><span class="co"># </span><span class="al">NOTE</span><span class="co">: Using column `date` as input for `col_date`.</span></a>
<a class="sourceLine" id="cb19-7" data-line-number="7"><span class="co"># </span><span class="al">NOTE</span><span class="co">: Using column `patient_id` as input for `col_patient_id`.</span></a>
<a class="sourceLine" id="cb19-8" data-line-number="8"><span class="co"># </span><span class="al">NOTE</span><span class="co">: Using column `keyab` as input for `col_keyantibiotics`. Use col_keyantibiotics = FALSE to prevent this.</span></a>
<a class="sourceLine" id="cb19-9" data-line-number="9"><span class="co"># [Criterion] Inclusion based on key antibiotics, ignoring I.</span></a>
<a class="sourceLine" id="cb19-10" data-line-number="10"><span class="co"># =&gt; Found 4,452 first weighted isolates (89.0% of total)</span></a></code></pre></div>
<a class="sourceLine" id="cb19-10" data-line-number="10"><span class="co"># =&gt; Found 4,404 first weighted isolates (88.1% of total)</span></a></code></pre></div>
<table class="table">
<thead><tr class="header">
<th align="center">isolate</th>
@ -637,80 +637,80 @@ @@ -637,80 +637,80 @@
<tbody>
<tr class="odd">
<td align="center">1</td>
<td align="center">2010-02-22</td>
<td align="center">Y8</td>
<td align="center">2010-08-27</td>
<td align="center">X6</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">TRUE</td>
<td align="center">TRUE</td>
</tr>
<tr class="even">
<td align="center">2</td>
<td align="center">2011-11-07</td>
<td align="center">Y8</td>
<td align="center">2010-12-12</td>
<td align="center">X6</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">I</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">TRUE</td>
<td align="center">FALSE</td>
<td align="center">TRUE</td>
</tr>
<tr class="odd">
<td align="center">3</td>
<td align="center">2012-05-14</td>
<td align="center">Y8</td>
<td align="center">2011-05-24</td>
<td align="center">X6</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">I</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">FALSE</td>
<td align="center">FALSE</td>
<td align="center">TRUE</td>
</tr>
<tr class="even">
<td align="center">4</td>
<td align="center">2012-10-27</td>
<td align="center">Y8</td>
<td align="center">2011-09-03</td>
<td align="center">X6</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">FALSE</td>
<td align="center">TRUE</td>
<td align="center">TRUE</td>
</tr>
<tr class="odd">
<td align="center">5</td>
<td align="center">2013-03-26</td>
<td align="center">Y8</td>
<td align="center">2011-09-21</td>
<td align="center">X6</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">S</td>
<td align="center">I</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">TRUE</td>
<td align="center">S</td>
<td align="center">FALSE</td>
<td align="center">TRUE</td>
</tr>
<tr class="even">
<td align="center">6</td>
<td align="center">2013-05-26</td>
<td align="center">Y8</td>
<td align="center">2011-10-31</td>
<td align="center">X6</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">FALSE</td>
<td align="center">TRUE</td>
</tr>
<tr class="odd">
<td align="center">7</td>
<td align="center">2013-10-20</td>
<td align="center">Y8</td>
<td align="center">2012-07-02</td>
<td align="center">X6</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">S</td>
<td align="center">S</td>
@ -721,11 +721,11 @@ @@ -721,11 +721,11 @@
</tr>
<tr class="even">
<td align="center">8</td>
<td align="center">2015-03-07</td>
<td align="center">Y8</td>
<td align="center">2012-12-30</td>
<td align="center">X6</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">TRUE</td>
@ -733,11 +733,11 @@ @@ -733,11 +733,11 @@
</tr>
<tr class="odd">
<td align="center">9</td>
<td align="center">2015-03-20</td>
<td align="center">Y8</td>
<td align="center">2013-03-15</td>
<td align="center">X6</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">S</td>
<td align="center">I</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">FALSE</td>
@ -745,26 +745,26 @@ @@ -745,26 +745,26 @@
</tr>
<tr class="even">
<td align="center">10</td>
<td align="center">2015-10-18</td>
<td align="center">Y8</td>
<td align="center">2014-01-14</td>
<td align="center">X6</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">FALSE</td>
<td align="center">TRUE</td>
<td align="center">TRUE</td>
</tr>
</tbody>
</table>
<p>Instead of 4, now 8 isolates are flagged. In total, 89% of all isolates are marked ‘first weighted’ - 147.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.</p>
<p>Instead of 4, now 9 isolates are flagged. In total, 88.1% of all isolates are marked ‘first weighted’ - 146.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.</p>
<p>As with <code><a href="../reference/first_isolate.html">filter_first_isolate()</a></code>, there’s a shortcut for this new algorithm too:</p>
<div class="sourceCode" id="cb20"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb20-1" data-line-number="1">data_1st &lt;-<span class="st"> </span>data <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb20-2" data-line-number="2"><span class="st"> </span><span class="kw"><a href="../reference/first_isolate.html">filter_first_weighted_isolate</a></span>()</a></code></pre></div>
<p>So we end up with 4,452 isolates for analysis.</p>
<p>So we end up with 4,404 isolates for analysis.</p>
<p>We can remove unneeded columns:</p>
<div class="sourceCode" id="cb21"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb21-1" data-line-number="1">data_1st &lt;-<span class="st"> </span>data_1st <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb21-2" data-line-number="2"><span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/dplyr/topics/select">select</a></span>(<span class="op">-</span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(first, keyab))</a></code></pre></div>
<a class="sourceLine" id="cb21-2" data-line-number="2"><span class="st"> </span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/select.html">select</a></span>(<span class="op">-</span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(first, keyab))</a></code></pre></div>
<p>Now our data looks like:</p>
<div class="sourceCode" id="cb22"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb22-1" data-line-number="1"><span class="kw"><a href="https://www.rdocumentation.org/packages/utils/topics/head">head</a></span>(data_1st)</a></code></pre></div>
<table class="table">
@ -785,28 +785,28 @@ @@ -785,28 +785,28 @@
</tr></thead>
<tbody>
<tr class="odd">
<td align="center">2011-12-05</td>
<td align="center">N6</td>
<td align="center">2015-02-23</td>
<td align="center">C5</td>
<td align="center">Hospital B</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">B_STPHY_AUR</td>
<td align="center">R</td>
<td align="center">R</td>
<td align="center">I</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">F</td>
<td align="center">Gram negative</td>
<td align="center">Escherichia</td>
<td align="center">coli</td>
<td align="center">M</td>
<td align="center">Gram positive</td>
<td align="center">Staphylococcus</td>
<td align="center">aureus</td>
<td align="center">TRUE</td>
</tr>
<tr class="even">
<td align="center">2012-08-21</td>
<td align="center">O9</td>
<td align="center">Hospital B</td>
<td align="center">2011-10-29</td>
<td align="center">X2</td>
<td align="center">Hospital C</td>
<td align="center">B_STRPTC_PNE</td>
<td align="center">I</td>
<td align="center">R</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">F</td>
<td align="center">Gram positive</td>
@ -815,28 +815,28 @@ @@ -815,28 +815,28 @@
<td align="center">TRUE</td>
</tr>
<tr class="odd">
<td align="center">2015-10-17</td>
<td align="center">P4</td>
<td align="center">Hospital D</td>
<td align="center">2010-06-10</td>
<td align="center">J5</td>
<td align="center">Hospital B</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">F</td>
<td align="center">M</td>
<td align="center">Gram negative</td>
<td align="center">Escherichia</td>
<td align="c