2022-08-21 16:59:35 +02:00
<!DOCTYPE html>
<!-- Generated by pkgdown: do not edit by hand --> < html lang = "en" >
< head >
< meta http-equiv = "Content-Type" content = "text/html; charset=UTF-8" >
< meta charset = "utf-8" >
< meta http-equiv = "X-UA-Compatible" content = "IE=edge" >
< meta name = "viewport" content = "width=device-width, initial-scale=1, shrink-to-fit=no" >
< meta name = "description" content = "AMR" >
< title > How to conduct AMR data analysis • AMR (for R)< / title >
<!-- favicons --> < link rel = "icon" type = "image/png" sizes = "16x16" href = "../favicon-16x16.png" >
< link rel = "icon" type = "image/png" sizes = "32x32" href = "../favicon-32x32.png" >
< link rel = "apple-touch-icon" type = "image/png" sizes = "180x180" href = "../apple-touch-icon.png" >
< link rel = "apple-touch-icon" type = "image/png" sizes = "120x120" href = "../apple-touch-icon-120x120.png" >
< link rel = "apple-touch-icon" type = "image/png" sizes = "76x76" href = "../apple-touch-icon-76x76.png" >
< link rel = "apple-touch-icon" type = "image/png" sizes = "60x60" href = "../apple-touch-icon-60x60.png" >
< script src = "../deps/jquery-3.6.0/jquery-3.6.0.min.js" > < / script > < meta name = "viewport" content = "width=device-width, initial-scale=1, shrink-to-fit=no" >
2022-12-20 16:22:22 +01:00
< link href = "../deps/bootstrap-5.2.2/bootstrap.min.css" rel = "stylesheet" >
< script src = "../deps/bootstrap-5.2.2/bootstrap.bundle.min.js" > < / script > < link href = "../deps/Fira_Code-0.4.4/font.css" rel = "stylesheet" >
2022-08-21 16:59:35 +02:00
<!-- Font Awesome icons --> < link rel = "stylesheet" href = "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css" integrity = "sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk=" crossorigin = "anonymous" >
< link rel = "stylesheet" href = "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/v4-shims.min.css" integrity = "sha256-wZjR52fzng1pJHwx4aV2AO3yyTOXrcDW7jBpJtTwVxw=" crossorigin = "anonymous" >
2022-12-16 16:17:49 +01:00
<!-- bootstrap - toc --> < script src = "https://cdn.jsdelivr.net/gh/afeld/bootstrap-toc@v1.0.1/dist/bootstrap-toc.min.js" integrity = "sha256-4veVQbu7//Lk5TSmc7YV48MxtMy98e26cf5MrgZYnwo=" crossorigin = "anonymous" > < / script > <!-- headroom.js --> < script src = "https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/headroom.min.js" integrity = "sha256-AsUX4SJE1+yuDu5+mAVzJbuYNPHj/WroHuZ8Ir/CkE0=" crossorigin = "anonymous" > < / script > < script src = "https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/jQuery.headroom.min.js" integrity = "sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4=" crossorigin = "anonymous" > < / script > <!-- clipboard.js --> < script src = "https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js" integrity = "sha256-inc5kl9MA1hkeYUt+EC3BhlIgyp/2jDIyBLS6k3UxPI=" crossorigin = "anonymous" > < / script > <!-- search --> < script src = "https://cdnjs.cloudflare.com/ajax/libs/fuse.js/6.4.6/fuse.js" integrity = "sha512-zv6Ywkjyktsohkbp9bb45V6tEMoWhzFzXis+LrMehmJZZSys19Yxf1dopHx7WzIKxr5tK2dVcYmaCk2uqdjF4A==" crossorigin = "anonymous" > < / script > < script src = "https://cdnjs.cloudflare.com/ajax/libs/autocomplete.js/0.38.0/autocomplete.jquery.min.js" integrity = "sha512-GU9ayf+66Xx2TmpxqJpliWbT5PiGYxpaG8rfnBEk1LL8l1KGkRShhngwdXK1UgqhAzWpZHSiYPc09/NwDQIGyg==" crossorigin = "anonymous" > < / script > < script src = "https://cdnjs.cloudflare.com/ajax/libs/mark.js/8.11.1/mark.min.js" integrity = "sha512-5CYOlHXGh6QpOFA/TeTylKLWfB3ftPsde7AnmhuitiTX4K5SqCLBeKro6sPS8ilsz1Q4NRx3v8Ko2IBiszzdww==" crossorigin = "anonymous" > < / script > <!-- pkgdown --> < script src = "../pkgdown.js" > < / script > < link href = "../extra.css" rel = "stylesheet" >
2022-08-21 16:59:35 +02:00
< script src = "../extra.js" > < / script > < meta property = "og:title" content = "How to conduct AMR data analysis" >
< meta property = "og:description" content = "AMR" >
< meta property = "og:image" content = "https://msberends.github.io/AMR/logo.svg" >
< meta name = "twitter:card" content = "summary_large_image" >
< meta name = "twitter:creator" content = "@msberends" >
2022-10-05 12:32:07 +02:00
< meta name = "twitter:site" content = "@msberends" >
2022-08-21 16:59:35 +02:00
<!-- mathjax --> < script src = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity = "sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin = "anonymous" > < / script > < script src = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity = "sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin = "anonymous" > < / script > <!-- [if lt IE 9]>
< script src = "https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js" > < / script >
< script src = "https://oss.maxcdn.com/respond/1.4.2/respond.min.js" > < / script >
<![endif]-->
< / head >
< body >
< a href = "#main" class = "visually-hidden-focusable" > Skip to contents< / a >
< nav class = "navbar fixed-top navbar-dark navbar-expand-lg bg-primary" > < div class = "container" >
< a class = "navbar-brand me-2" href = "../index.html" > AMR (for R)< / a >
2023-01-07 02:01:36 +01:00
< small class = "nav-text text-muted me-auto" data-bs-toggle = "tooltip" data-bs-placement = "bottom" title = "" > 1.8.2.9088< / small >
2022-08-21 16:59:35 +02:00
< button class = "navbar-toggler" type = "button" data-bs-toggle = "collapse" data-bs-target = "#navbar" aria-controls = "navbar" aria-expanded = "false" aria-label = "Toggle navigation" >
< span class = "navbar-toggler-icon" > < / span >
< / button >
< div id = "navbar" class = "collapse navbar-collapse ms-3" >
< ul class = "navbar-nav me-auto" >
< li class = "nav-item" >
< a class = "nav-link" href = "../index.html" >
< span class = "fa fa-home" > < / span >
Home
< / a >
< / li >
< li class = "active nav-item dropdown" >
< a href = "#" class = "nav-link dropdown-toggle" data-bs-toggle = "dropdown" role = "button" aria-expanded = "false" aria-haspopup = "true" id = "dropdown--how-to" >
< span class = "fa fa-question-circle" > < / span >
How to
< / a >
< div class = "dropdown-menu" aria-labelledby = "dropdown--how-to" >
< a class = "dropdown-item" href = "../articles/AMR.html" >
< span class = "fa fa-directions" > < / span >
Conduct AMR analysis
< / a >
< a class = "dropdown-item" href = "../articles/resistance_predict.html" >
< span class = "fa fa-dice" > < / span >
Predict antimicrobial resistance
< / a >
< a class = "dropdown-item" href = "../articles/datasets.html" >
< span class = "fa fa-database" > < / span >
Data sets for download / own use
< / a >
< a class = "dropdown-item" href = "../articles/PCA.html" >
< span class = "fa fa-compress" > < / span >
Conduct principal component analysis for AMR
< / a >
< a class = "dropdown-item" href = "../articles/MDR.html" >
< span class = "fa fa-skull-crossbones" > < / span >
Determine multi-drug resistance (MDR)
< / a >
< a class = "dropdown-item" href = "../articles/WHONET.html" >
< span class = "fa fa-globe-americas" > < / span >
Work with WHONET data
< / a >
< a class = "dropdown-item" href = "../articles/SPSS.html" >
< span class = "fa fa-file-upload" > < / span >
Import data from SPSS/SAS/Stata
< / a >
< a class = "dropdown-item" href = "../articles/EUCAST.html" >
< span class = "fa fa-exchange-alt" > < / span >
Apply EUCAST rules
< / a >
< a class = "dropdown-item" href = "../reference/mo_property.html" >
< span class = "fa fa-bug" > < / span >
2022-12-30 13:10:58 +01:00
Get taxonomy of a microorganism
2022-08-21 16:59:35 +02:00
< / a >
< a class = "dropdown-item" href = "../reference/ab_property.html" >
< span class = "fa fa-capsules" > < / span >
2022-12-30 13:10:58 +01:00
Get properties of an antibiotic drug
2022-08-21 16:59:35 +02:00
< / a >
2022-11-13 08:54:32 +01:00
< a class = "dropdown-item" href = "../reference/av_property.html" >
< span class = "fa fa-capsules" > < / span >
2022-12-30 13:10:58 +01:00
Get properties of an antiviral drug
2022-11-13 08:54:32 +01:00
< / a >
2022-08-21 16:59:35 +02:00
< / div >
< / li >
< li class = "nav-item" >
< a class = "nav-link" href = "../reference/index.html" >
< span class = "fa fa-book-open" > < / span >
Manual
< / a >
< / li >
< li class = "nav-item" >
< a class = "nav-link" href = "../authors.html" >
< span class = "fa fa-users" > < / span >
Authors
< / a >
< / li >
< li class = "nav-item" >
< a class = "nav-link" href = "../news/index.html" >
< span class = "far fa far fa-newspaper" > < / span >
Changelog
< / a >
< / li >
< / ul >
< form class = "form-inline my-2 my-lg-0" role = "search" >
< input type = "search" class = "form-control me-sm-2" aria-label = "Toggle navigation" name = "search-input" data-search-index = "../search.json" id = "search-input" placeholder = "Search for" autocomplete = "off" >
< / form >
< ul class = "navbar-nav" >
< li class = "nav-item" >
< a class = "external-link nav-link" href = "https://github.com/msberends/AMR" >
< span class = "fab fa fab fa-github" > < / span >
Source Code
< / a >
< / li >
< / ul >
< / div >
< / div >
< / nav > < div class = "container template-article" >
< div class = "row" >
< main id = "main" class = "col-md-9" > < div class = "page-header" >
< img src = "../logo.svg" class = "logo" alt = "" > < h1 > How to conduct AMR data analysis< / h1 >
2022-10-29 14:24:08 +02:00
< h4 data-toc-skip class = "author" > Dr. Matthijs
Berends< / h4 >
2022-08-21 16:59:35 +02:00
2023-01-07 02:01:36 +01:00
< h4 data-toc-skip class = "date" > 07 January 2023< / h4 >
2022-08-21 16:59:35 +02:00
< small class = "dont-index" > Source: < a href = "https://github.com/msberends/AMR/blob/HEAD/vignettes/AMR.Rmd" class = "external-link" > < code > vignettes/AMR.Rmd< / code > < / a > < / small >
< div class = "d-none name" > < code > AMR.Rmd< / code > < / div >
< / div >
2022-10-29 14:24:08 +02:00
< 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/" class = "external-link" > R
Markdown< / a > . However, the methodology remains unchanged. This page was
2023-01-07 02:01:36 +01:00
generated on 07 January 2023.< / p >
2022-08-21 16:59:35 +02:00
< div class = "section level2" >
< h2 id = "introduction" > Introduction< a class = "anchor" aria-label = "anchor" href = "#introduction" > < / a >
< / h2 >
2022-10-29 14:24:08 +02:00
< p > Conducting AMR data analysis unfortunately requires in-depth
knowledge from different scientific fields, which makes it hard to do
right. At least, it requires:< / p >
2022-08-21 16:59:35 +02:00
< ul >
< li > Good questions (always start with those!)< / li >
2022-10-29 14:24:08 +02:00
< li > A thorough understanding of (clinical) epidemiology, to understand
the clinical and epidemiological relevance and possible bias of
results< / li >
< li > A thorough understanding of (clinical) microbiology/infectious
diseases, to understand which microorganisms are causal to which
infections and the implications of pharmaceutical treatment, as well as
understanding intrinsic and acquired microbial resistance< / li >
< li > Experience with data analysis with microbiological tests and their
results, to understand the determination and limitations of MIC values
and their interpretations to RSI values< / li >
< li > Availability of the biological taxonomy of microorganisms and
probably normalisation factors for pharmaceuticals, such as defined
daily doses (DDD)< / li >
< li > Available (inter-)national guidelines, and profound methods to apply
them< / li >
2022-08-21 16:59:35 +02:00
< / ul >
2022-10-29 14:24:08 +02:00
< p > Of course, we cannot instantly provide you with knowledge and
experience. But with this < code > AMR< / code > package, we aimed at
providing (1) tools to simplify antimicrobial resistance data cleaning,
transformation and analysis, (2) methods to easily incorporate
international guidelines and (3) scientifically reliable reference data,
including the requirements mentioned above.< / p >
< p > The < code > AMR< / code > package enables standardised and reproducible
AMR data analysis, with the application of evidence-based rules,
determination of first isolates, translation of various codes for
microorganisms and antimicrobial agents, determination of (multi-drug)
resistant microorganisms, and calculation of antimicrobial resistance,
prevalence and future trends.< / p >
2022-08-21 16:59:35 +02:00
< / div >
< div class = "section level2" >
< h2 id = "preparation" > Preparation< a class = "anchor" aria-label = "anchor" href = "#preparation" > < / a >
< / h2 >
2022-10-29 14:24:08 +02:00
< p > For this tutorial, we will create fake demonstration data to work
with.< / p >
< p > You can skip to < a href = "#cleaning-the-data" > Cleaning the data< / a > if
you already have your own data ready. If you start your analysis, try to
make the structure of your data generally look like this:< / p >
2022-08-21 16:59:35 +02:00
< table class = "table" >
< thead > < tr class = "header" >
< th align = "center" > date< / th >
< th align = "center" > patient_id< / th >
< th align = "center" > mo< / th >
< th align = "center" > AMX< / th >
< th align = "center" > CIP< / th >
< / tr > < / thead >
< tbody >
< tr class = "odd" >
2023-01-07 02:01:36 +01:00
< td align = "center" > 2023-01-07< / td >
2022-08-21 16:59:35 +02:00
< 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" >
2023-01-07 02:01:36 +01:00
< td align = "center" > 2023-01-07< / td >
2022-08-21 16:59:35 +02:00
< 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" >
2023-01-07 02:01:36 +01:00
< td align = "center" > 2023-01-07< / td >
2022-08-21 16:59:35 +02:00
< td align = "center" > efgh< / td >
< td align = "center" > Escherichia coli< / td >
< td align = "center" > R< / td >
< td align = "center" > S< / td >
< / tr >
< / tbody >
< / table >
< div class = "section level3" >
< h3 id = "needed-r-packages" > Needed R packages< a class = "anchor" aria-label = "anchor" href = "#needed-r-packages" > < / a >
< / h3 >
2022-10-29 14:24:08 +02:00
< p > As with many uses in R, we need some additional packages for AMR data
analysis. Our package works closely together with the < a href = "https://www.tidyverse.org" class = "external-link" > tidyverse packages< / a > < a href = "https://dplyr.tidyverse.org/" class = "external-link" > < code > dplyr< / code > < / a > and < a href = "https://ggplot2.tidyverse.org" class = "external-link" > < code > ggplot2< / code > < / a > by
RStudio. The tidyverse tremendously improves the way we conduct data
science - it allows for a very natural way of writing syntaxes and
creating beautiful plots in R.< / p >
< p > We will also use the < code > cleaner< / code > package, that can be used
for cleaning data and creating frequency tables.< / p >
2022-08-21 16:59:35 +02:00
< div class = "sourceCode" id = "cb1" > < pre class = "downlit sourceCode r" >
< code class = "sourceCode R" > < span > < span class = "kw" > < a href = "https://rdrr.io/r/base/library.html" class = "external-link" > library< / a > < / span > < span class = "op" > (< / span > < span class = "va" > < a href = "https://dplyr.tidyverse.org" class = "external-link" > dplyr< / a > < / span > < span class = "op" > )< / span > < / span >
< span > < span class = "kw" > < a href = "https://rdrr.io/r/base/library.html" class = "external-link" > library< / a > < / span > < span class = "op" > (< / span > < span class = "va" > < a href = "https://ggplot2.tidyverse.org" class = "external-link" > ggplot2< / a > < / span > < span class = "op" > )< / span > < / span >
< span > < span class = "kw" > < a href = "https://rdrr.io/r/base/library.html" class = "external-link" > library< / a > < / span > < span class = "op" > (< / span > < span class = "va" > < a href = "https://msberends.github.io/AMR/" > AMR< / a > < / span > < span class = "op" > )< / span > < / span >
2022-10-29 14:24:08 +02:00
< span > < span class = "kw" > < a href = "https://rdrr.io/r/base/library.html" class = "external-link" > library< / a > < / span > < span class = "op" > (< / span > < span class = "va" > < a href = "https://msberends.github.io/cleaner/" class = "external-link" > cleaner< / a > < / span > < span class = "op" > )< / span > < / span >
2022-08-21 16:59:35 +02:00
< span > < / span >
< span > < span class = "co" > # (if not yet installed, install with:)< / span > < / span >
< span > < span class = "co" > # install.packages(c("dplyr", "ggplot2", "AMR", "cleaner"))< / span > < / span > < / code > < / pre > < / div >
< / div >
< / div >
< div class = "section level2" >
< h2 id = "creation-of-data" > Creation of data< a class = "anchor" aria-label = "anchor" href = "#creation-of-data" > < / a >
< / h2 >
2022-10-29 14:24:08 +02:00
< p > We will create some fake example data to use for analysis. For AMR
data analysis, we need at least: a patient ID, name or code of a
microorganism, a date and antimicrobial results (an antibiogram). It
could also include a specimen type (e.g. to filter on blood or urine),
the ward type (e.g. to filter on ICUs).< / p >
< p > With additional columns (like a hospital name, the patients gender of
even [well-defined] clinical properties) you can do a comparative
analysis, as this tutorial will demonstrate too.< / p >
2022-08-21 16:59:35 +02:00
< div class = "section level3" >
< h3 id = "patients" > Patients< a class = "anchor" aria-label = "anchor" href = "#patients" > < / a >
< / h3 >
< p > To start with patients, we need a unique list of patients.< / p >
< div class = "sourceCode" id = "cb2" > < pre class = "downlit sourceCode r" >
< code class = "sourceCode R" > < span > < span class = "va" > patients< / span > < span class = "op" > < -< / span > < span class = "fu" > < a href = "https://rdrr.io/r/base/unlist.html" class = "external-link" > unlist< / a > < / span > < span class = "op" > (< / span > < span class = "fu" > < a href = "https://rdrr.io/r/base/lapply.html" class = "external-link" > lapply< / a > < / span > < span class = "op" > (< / span > < span class = "va" > LETTERS< / span > , < span class = "va" > paste0< / span > , < span class = "fl" > 1< / span > < span class = "op" > :< / span > < span class = "fl" > 10< / span > < span class = "op" > )< / span > < span class = "op" > )< / span > < / span > < / code > < / pre > < / div >
2022-10-29 14:24:08 +02:00
< p > The < code > LETTERS< / code > object is available in R - it’ s a vector
with 26 characters: < code > A< / code > to < code > Z< / code > . The
< code > patients< / code > object we just created is now a vector of length
260, with values (patient IDs) varying from < code > A1< / code > to
< code > Z10< / code > . Now we we also set the gender of our patients, by
putting the ID and the gender in a table:< / p >
2022-08-21 16:59:35 +02:00
< div class = "sourceCode" id = "cb3" > < pre class = "downlit sourceCode r" >
2022-08-28 22:45:38 +02:00
< code class = "sourceCode R" > < span > < span class = "va" > patients_table< / span > < span class = "op" > < -< / span > < span class = "fu" > < a href = "https://rdrr.io/r/base/data.frame.html" class = "external-link" > data.frame< / a > < / span > < span class = "op" > (< / span > < / span >
< span > patient_id < span class = "op" > =< / span > < span class = "va" > patients< / span > ,< / span >
< span > gender < span class = "op" > =< / span > < span class = "fu" > < a href = "https://rdrr.io/r/base/c.html" class = "external-link" > c< / a > < / span > < span class = "op" > (< / span > < / span >
< span > < span class = "fu" > < a href = "https://rdrr.io/r/base/rep.html" class = "external-link" > rep< / a > < / span > < span class = "op" > (< / span > < span class = "st" > "M"< / span > , < span class = "fl" > 135< / span > < span class = "op" > )< / span > ,< / span >
< span > < span class = "fu" > < a href = "https://rdrr.io/r/base/rep.html" class = "external-link" > rep< / a > < / span > < span class = "op" > (< / span > < span class = "st" > "F"< / span > , < span class = "fl" > 125< / span > < span class = "op" > )< / span > < / span >
< span > < span class = "op" > )< / span > < / span >
< span > < span class = "op" > )< / span > < / span > < / code > < / pre > < / div >
2022-08-21 16:59:35 +02:00
< p > The first 135 patient IDs are now male, the other 125 are female.< / p >
< / div >
< div class = "section level3" >
< h3 id = "dates" > Dates< a class = "anchor" aria-label = "anchor" href = "#dates" > < / a >
< / h3 >
2022-10-29 14:24:08 +02:00
< p > Let’ s pretend that our data consists of blood cultures isolates from
between 1 January 2010 and 1 January 2018.< / p >
2022-08-21 16:59:35 +02:00
< div class = "sourceCode" id = "cb4" > < pre class = "downlit sourceCode r" >
< code class = "sourceCode R" > < span > < span class = "va" > dates< / span > < span class = "op" > < -< / span > < span class = "fu" > < a href = "https://rdrr.io/r/base/seq.html" class = "external-link" > seq< / a > < / span > < span class = "op" > (< / span > < span class = "fu" > < a href = "https://rdrr.io/r/base/as.Date.html" class = "external-link" > as.Date< / a > < / span > < span class = "op" > (< / span > < span class = "st" > "2010-01-01"< / span > < span class = "op" > )< / span > , < span class = "fu" > < a href = "https://rdrr.io/r/base/as.Date.html" class = "external-link" > as.Date< / a > < / span > < span class = "op" > (< / span > < span class = "st" > "2018-01-01"< / span > < span class = "op" > )< / span > , by < span class = "op" > =< / span > < span class = "st" > "day"< / span > < span class = "op" > )< / span > < / span > < / code > < / pre > < / div >
2022-10-29 14:24:08 +02:00
< p > This < code > dates< / code > object now contains all days in our date
range.< / p >
2022-08-21 16:59:35 +02:00
< div class = "section level5" >
< h5 id = "microorganisms" > Microorganisms< a class = "anchor" aria-label = "anchor" href = "#microorganisms" > < / a >
< / h5 >
2022-10-29 14:24:08 +02:00
< p > For this tutorial, we will uses four different microorganisms:
< em > Escherichia coli< / em > , < em > Staphylococcus aureus< / em > ,
< em > Streptococcus pneumoniae< / em > , and < em > Klebsiella
pneumoniae< / em > :< / p >
2022-08-21 16:59:35 +02:00
< div class = "sourceCode" id = "cb5" > < pre class = "downlit sourceCode r" >
2022-08-28 22:45:38 +02:00
< code class = "sourceCode R" > < span > < span class = "va" > bacteria< / span > < span class = "op" > < -< / span > < span class = "fu" > < a href = "https://rdrr.io/r/base/c.html" class = "external-link" > c< / a > < / span > < span class = "op" > (< / span > < / span >
< span > < span class = "st" > "Escherichia coli"< / span > , < span class = "st" > "Staphylococcus aureus"< / span > ,< / span >
< span > < span class = "st" > "Streptococcus pneumoniae"< / span > , < span class = "st" > "Klebsiella pneumoniae"< / span > < / span >
< span > < span class = "op" > )< / span > < / span > < / code > < / pre > < / div >
2022-08-21 16:59:35 +02:00
< / div >
< / div >
< div class = "section level3" >
< h3 id = "put-everything-together" > Put everything together< a class = "anchor" aria-label = "anchor" href = "#put-everything-together" > < / a >
< / h3 >
2022-10-29 14:24:08 +02:00
< p > Using the < code > < a href = "https://rdrr.io/r/base/sample.html" class = "external-link" > 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, using the < code > < a href = "../reference/random.html" > random_rsi()< / a > < / code >
function.< / p >
2022-08-21 16:59:35 +02:00
< div class = "sourceCode" id = "cb6" > < pre class = "downlit sourceCode r" >
< code class = "sourceCode R" > < span > < span class = "va" > sample_size< / span > < span class = "op" > < -< / span > < span class = "fl" > 20000< / span > < / span >
2022-08-28 22:45:38 +02:00
< span > < span class = "va" > data< / span > < span class = "op" > < -< / span > < span class = "fu" > < a href = "https://rdrr.io/r/base/data.frame.html" class = "external-link" > data.frame< / a > < / span > < span class = "op" > (< / span > < / span >
< span > date < span class = "op" > =< / span > < span class = "fu" > < a href = "https://rdrr.io/r/base/sample.html" class = "external-link" > sample< / a > < / span > < span class = "op" > (< / span > < span class = "va" > dates< / span > , size < span class = "op" > =< / span > < span class = "va" > sample_size< / span > , replace < span class = "op" > =< / span > < span class = "cn" > TRUE< / span > < span class = "op" > )< / span > ,< / span >
< span > patient_id < span class = "op" > =< / span > < span class = "fu" > < a href = "https://rdrr.io/r/base/sample.html" class = "external-link" > sample< / a > < / span > < span class = "op" > (< / span > < span class = "va" > patients< / span > , size < span class = "op" > =< / span > < span class = "va" > sample_size< / span > , replace < span class = "op" > =< / span > < span class = "cn" > TRUE< / span > < span class = "op" > )< / span > ,< / span >
< span > hospital < span class = "op" > =< / span > < span class = "fu" > < a href = "https://rdrr.io/r/base/sample.html" class = "external-link" > sample< / a > < / span > < span class = "op" > (< / span > < span class = "fu" > < a href = "https://rdrr.io/r/base/c.html" class = "external-link" > c< / a > < / span > < span class = "op" > (< / span > < / span >
< span > < span class = "st" > "Hospital A"< / span > ,< / span >
< span > < span class = "st" > "Hospital B"< / span > ,< / span >
< span > < span class = "st" > "Hospital C"< / span > ,< / span >
< span > < span class = "st" > "Hospital D"< / span > < / span >
< span > < span class = "op" > )< / span > ,< / span >
< span > size < span class = "op" > =< / span > < span class = "va" > sample_size< / span > , replace < span class = "op" > =< / span > < span class = "cn" > TRUE< / span > ,< / span >
< span > prob < span class = "op" > =< / span > < span class = "fu" > < a href = "https://rdrr.io/r/base/c.html" class = "external-link" > c< / a > < / span > < span class = "op" > (< / 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 > < span class = "op" > )< / span > < / span >
< span > < span class = "op" > )< / span > ,< / span >
< span > bacteria < span class = "op" > =< / span > < span class = "fu" > < a href = "https://rdrr.io/r/base/sample.html" class = "external-link" > sample< / a > < / span > < span class = "op" > (< / span > < span class = "va" > bacteria< / span > ,< / span >
< span > size < span class = "op" > =< / span > < span class = "va" > sample_size< / span > , replace < span class = "op" > =< / span > < span class = "cn" > TRUE< / span > ,< / span >
< span > prob < span class = "op" > =< / span > < span class = "fu" > < a href = "https://rdrr.io/r/base/c.html" class = "external-link" > c< / a > < / span > < span class = "op" > (< / 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 > < span class = "op" > )< / span > < / span >
< span > < span class = "op" > )< / span > ,< / span >
< span > AMX < span class = "op" > =< / span > < span class = "fu" > < a href = "../reference/random.html" > random_rsi< / a > < / span > < span class = "op" > (< / span > < span class = "va" > sample_size< / span > , prob_RSI < span class = "op" > =< / span > < span class = "fu" > < a href = "https://rdrr.io/r/base/c.html" class = "external-link" > c< / a > < / span > < span class = "op" > (< / span > < span class = "fl" > 0.35< / span > , < span class = "fl" > 0.60< / span > , < span class = "fl" > 0.05< / span > < span class = "op" > )< / span > < span class = "op" > )< / span > ,< / span >
< span > AMC < span class = "op" > =< / span > < span class = "fu" > < a href = "../reference/random.html" > random_rsi< / a > < / span > < span class = "op" > (< / span > < span class = "va" > sample_size< / span > , prob_RSI < span class = "op" > =< / span > < span class = "fu" > < a href = "https://rdrr.io/r/base/c.html" class = "external-link" > c< / a > < / span > < span class = "op" > (< / span > < span class = "fl" > 0.15< / span > , < span class = "fl" > 0.75< / span > , < span class = "fl" > 0.10< / span > < span class = "op" > )< / span > < span class = "op" > )< / span > ,< / span >
< span > CIP < span class = "op" > =< / span > < span class = "fu" > < a href = "../reference/random.html" > random_rsi< / a > < / span > < span class = "op" > (< / span > < span class = "va" > sample_size< / span > , prob_RSI < span class = "op" > =< / span > < span class = "fu" > < a href = "https://rdrr.io/r/base/c.html" class = "external-link" > c< / a > < / span > < span class = "op" > (< / span > < span class = "fl" > 0.20< / span > , < span class = "fl" > 0.80< / span > , < span class = "fl" > 0.00< / span > < span class = "op" > )< / span > < span class = "op" > )< / span > ,< / span >
< span > GEN < span class = "op" > =< / span > < span class = "fu" > < a href = "../reference/random.html" > random_rsi< / a > < / span > < span class = "op" > (< / span > < span class = "va" > sample_size< / span > , prob_RSI < span class = "op" > =< / span > < span class = "fu" > < a href = "https://rdrr.io/r/base/c.html" class = "external-link" > c< / a > < / span > < span class = "op" > (< / span > < span class = "fl" > 0.08< / span > , < span class = "fl" > 0.92< / span > , < span class = "fl" > 0.00< / span > < span class = "op" > )< / span > < span class = "op" > )< / span > < / span >
< span > < span class = "op" > )< / span > < / span > < / code > < / pre > < / div >
2022-10-29 14:24:08 +02:00
< p > Using the < code > < a href = "https://dplyr.tidyverse.org/reference/mutate-joins.html" class = "external-link" > 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 >
2022-08-21 16:59:35 +02:00
< div class = "sourceCode" id = "cb7" > < pre class = "downlit sourceCode r" >
< code class = "sourceCode R" > < span > < span class = "va" > data< / span > < span class = "op" > < -< / span > < span class = "va" > data< / span > < span class = "op" > < a href = "https://magrittr.tidyverse.org/reference/pipe.html" class = "external-link" > %> %< / a > < / span > < span class = "fu" > < a href = "https://dplyr.tidyverse.org/reference/mutate-joins.html" class = "external-link" > left_join< / a > < / span > < span class = "op" > (< / span > < span class = "va" > patients_table< / span > < span class = "op" > )< / span > < / span > < / code > < / pre > < / div >
2022-10-29 14:24:08 +02:00
< p > The resulting data set contains 20,000 blood culture isolates. With
the < code > < a href = "https://rdrr.io/r/utils/head.html" class = "external-link" > head()< / a > < / code > function we can preview the first 6 rows of this
data set:< / p >
2022-08-21 16:59:35 +02:00
< div class = "sourceCode" id = "cb8" > < pre class = "downlit sourceCode r" >
< code class = "sourceCode R" > < span > < span class = "fu" > < a href = "https://rdrr.io/r/utils/head.html" class = "external-link" > head< / a > < / span > < span class = "op" > (< / span > < span class = "va" > data< / span > < span class = "op" > )< / span > < / span > < / code > < / pre > < / div >
< table class = "table" >
2022-10-29 14:24:08 +02:00
< colgroup >
< col width = "13%" >
< col width = "13%" >
< col width = "13%" >
2023-01-07 02:01:36 +01:00
< col width = "26%" >
2022-10-29 14:24:08 +02:00
< col width = "5%" >
< col width = "5%" >
< col width = "5%" >
< col width = "5%" >
2023-01-07 02:01:36 +01:00
< col width = "9%" >
2022-10-29 14:24:08 +02:00
< / colgroup >
2022-08-21 16:59:35 +02:00
< thead > < tr class = "header" >
< th align = "center" > date< / th >
< th align = "center" > patient_id< / th >
< th align = "center" > hospital< / th >
< th align = "center" > bacteria< / th >
< th align = "center" > AMX< / th >
< th align = "center" > AMC< / th >
< th align = "center" > CIP< / th >
< th align = "center" > GEN< / th >
< th align = "center" > gender< / th >
< / tr > < / thead >
< tbody >
< tr class = "odd" >
2023-01-07 02:01:36 +01:00
< td align = "center" > 2015-01-23< / td >
< td align = "center" > N4< / td >
< td align = "center" > Hospital B< / td >
2023-01-06 19:28:42 +01:00
< td align = "center" > Escherichia coli< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > R< / td >
2022-12-09 11:27:21 +01:00
< td align = "center" > S< / td >
2023-01-06 13:51:55 +01:00
< td align = "center" > S< / td >
2023-01-06 19:28:42 +01:00
< td align = "center" > S< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > M< / td >
2022-08-21 16:59:35 +02:00
< / tr >
2022-08-25 19:30:35 +02:00
< tr class = "even" >
2023-01-07 02:01:36 +01:00
< td align = "center" > 2017-03-19< / td >
< td align = "center" > Z7< / td >
< td align = "center" > Hospital C< / td >
< td align = "center" > Klebsiella pneumoniae< / td >
2023-01-06 13:44:18 +01:00
< td align = "center" > R< / td >
2022-12-28 15:12:34 +01:00
< td align = "center" > S< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > R< / td >
2022-12-28 15:12:34 +01:00
< td align = "center" > S< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > F< / td >
2022-08-25 19:30:35 +02:00
< / tr >
< tr class = "odd" >
2023-01-07 02:01:36 +01:00
< td align = "center" > 2010-04-01< / td >
< td align = "center" > I9< / td >
2023-01-06 19:28:42 +01:00
< td align = "center" > Hospital A< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > Staphylococcus aureus< / td >
2023-01-06 10:16:17 +01:00
< td align = "center" > S< / td >
2023-01-06 19:28:42 +01:00
< td align = "center" > S< / td >
< td align = "center" > S< / td >
< td align = "center" > S< / td >
< td align = "center" > M< / td >
2022-08-21 16:59:35 +02:00
< / tr >
2022-12-12 00:23:03 +01:00
< tr class = "even" >
2023-01-07 02:01:36 +01:00
< td align = "center" > 2015-08-04< / td >
< td align = "center" > X4< / td >
< td align = "center" > Hospital B< / td >
< td align = "center" > Staphylococcus aureus< / td >
< td align = "center" > I< / td >
2023-01-06 13:51:55 +01:00
< td align = "center" > S< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > R< / td >
2023-01-06 19:28:42 +01:00
< td align = "center" > S< / td >
< td align = "center" > F< / td >
2022-08-21 16:59:35 +02:00
< / tr >
2022-12-12 00:23:03 +01:00
< tr class = "odd" >
2023-01-07 02:01:36 +01:00
< td align = "center" > 2016-09-21< / td >
< td align = "center" > W8< / td >
2023-01-06 19:28:42 +01:00
< td align = "center" > Hospital A< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > Staphylococcus aureus< / td >
< td align = "center" > R< / td >
2023-01-06 19:28:42 +01:00
< td align = "center" > S< / td >
< td align = "center" > S< / td >
2023-01-06 11:29:11 +01:00
< td align = "center" > S< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > F< / td >
2022-12-12 00:23:03 +01:00
< / tr >
< tr class = "even" >
2023-01-07 02:01:36 +01:00
< td align = "center" > 2010-01-28< / td >
< td align = "center" > H9< / td >
< td align = "center" > Hospital A< / td >
< td align = "center" > Escherichia coli< / td >
2023-01-06 13:44:18 +01:00
< td align = "center" > S< / td >
2023-01-05 15:48:37 +01:00
< td align = "center" > S< / td >
2023-01-05 18:29:06 +01:00
< td align = "center" > S< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > R< / td >
2023-01-06 11:29:11 +01:00
< td align = "center" > M< / td >
2022-08-21 16:59:35 +02:00
< / tr >
< / tbody >
< / table >
< p > Now, let’ s start the cleaning and the analysis!< / p >
< / div >
< / div >
< div class = "section level2" >
< h2 id = "cleaning-the-data" > Cleaning the data< a class = "anchor" aria-label = "anchor" href = "#cleaning-the-data" > < / a >
< / h2 >
2022-10-29 14:24:08 +02:00
< p > We also created a package dedicated to data cleaning and checking,
called the < code > cleaner< / code > package. It < code > < a href = "https://msberends.github.io/cleaner/reference/freq.html" class = "external-link" > freq()< / a > < / code > function
can be used to create frequency tables.< / p >
2022-08-21 16:59:35 +02:00
< p > For example, for the < code > gender< / code > variable:< / p >
< div class = "sourceCode" id = "cb9" > < pre class = "downlit sourceCode r" >
2022-10-29 14:24:08 +02:00
< code class = "sourceCode R" > < span > < span class = "va" > data< / span > < span class = "op" > < a href = "https://magrittr.tidyverse.org/reference/pipe.html" class = "external-link" > %> %< / a > < / span > < span class = "fu" > < a href = "https://msberends.github.io/cleaner/reference/freq.html" class = "external-link" > freq< / a > < / span > < span class = "op" > (< / span > < span class = "va" > gender< / span > < span class = "op" > )< / span > < / span > < / code > < / pre > < / div >
2022-08-21 16:59:35 +02:00
< p > < strong > Frequency table< / strong > < / p >
< p > Class: character< br >
Length: 20,000< br >
2022-10-29 14:24:08 +02:00
Available: 20,000 (100%, NA: 0 = 0%)< br >
2022-08-21 16:59:35 +02:00
Unique: 2< / p >
< p > Shortest: 1< br >
Longest: 1< / p >
< table class = "table" >
< thead > < tr class = "header" >
< th align = "left" > < / th >
< th align = "left" > Item< / th >
< th align = "right" > Count< / th >
< th align = "right" > Percent< / th >
< th align = "right" > Cum. Count< / th >
< th align = "right" > Cum. Percent< / th >
< / tr > < / thead >
< tbody >
< tr class = "odd" >
< td align = "left" > 1< / td >
< td align = "left" > M< / td >
2023-01-07 02:01:36 +01:00
< td align = "right" > 10,284< / td >
< td align = "right" > 51.42%< / td >
< td align = "right" > 10,284< / td >
< td align = "right" > 51.42%< / td >
2022-08-21 16:59:35 +02:00
< / tr >
< tr class = "even" >
< td align = "left" > 2< / td >
< td align = "left" > F< / td >
2023-01-07 02:01:36 +01:00
< td align = "right" > 9,716< / td >
< td align = "right" > 48.58%< / td >
2022-08-21 16:59:35 +02:00
< td align = "right" > 20,000< / td >
2022-12-28 15:12:34 +01:00
< td align = "right" > 100.00%< / td >
2022-08-21 16:59:35 +02:00
< / tr >
< / tbody >
< / table >
2022-10-29 14:24:08 +02:00
< p > So, we can draw at least two conclusions immediately. From a data
scientists perspective, the data looks clean: only values < code > M< / code >
and < code > F< / code > . From a researchers 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://dplyr.tidyverse.org/reference/mutate.html" class = "external-link" > mutate()< / a > < / code > function
of the < code > dplyr< / code > package makes this really easy:< / p >
2022-08-21 16:59:35 +02:00
< div class = "sourceCode" id = "cb10" > < pre class = "downlit sourceCode r" >
< code class = "sourceCode R" > < span > < span class = "va" > data< / span > < span class = "op" > < -< / span > < span class = "va" > data< / span > < span class = "op" > < a href = "https://magrittr.tidyverse.org/reference/pipe.html" class = "external-link" > %> %< / a > < / span > < / span >
< span > < span class = "fu" > < a href = "https://dplyr.tidyverse.org/reference/mutate.html" class = "external-link" > mutate< / a > < / span > < span class = "op" > (< / span > bacteria < span class = "op" > =< / span > < span class = "fu" > < a href = "../reference/as.mo.html" > as.mo< / a > < / span > < span class = "op" > (< / span > < span class = "va" > bacteria< / span > < span class = "op" > )< / span > < span class = "op" > )< / span > < / span > < / code > < / pre > < / div >
2022-10-29 14:24:08 +02:00
< 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 = "../reference/as.rsi.html" > is.rsi.eligible()< / a > < / code > can check which columns
are probably columns with R/SI test results. Using < code > < a href = "https://dplyr.tidyverse.org/reference/mutate.html" class = "external-link" > mutate()< / a > < / code >
and < code > < a href = "https://dplyr.tidyverse.org/reference/across.html" class = "external-link" > across()< / a > < / code > , we can apply the transformation to the formal
< code > < rsi> < / code > class:< / p >
2022-08-21 16:59:35 +02:00
< div class = "sourceCode" id = "cb11" > < pre class = "downlit sourceCode r" >
< code class = "sourceCode R" > < span > < span class = "fu" > < a href = "../reference/as.rsi.html" > is.rsi.eligible< / a > < / span > < span class = "op" > (< / span > < span class = "va" > data< / span > < span class = "op" > )< / span > < / span >
< span > < span class = "co" > # [1] FALSE FALSE FALSE FALSE TRUE TRUE TRUE TRUE FALSE< / span > < / span >
< span > < span class = "fu" > < a href = "https://rdrr.io/r/base/colnames.html" class = "external-link" > colnames< / a > < / span > < span class = "op" > (< / span > < span class = "va" > data< / span > < span class = "op" > )< / span > < span class = "op" > [< / span > < span class = "fu" > < a href = "../reference/as.rsi.html" > is.rsi.eligible< / a > < / span > < span class = "op" > (< / span > < span class = "va" > data< / span > < span class = "op" > )< / span > < span class = "op" > ]< / span > < / span >
< span > < span class = "co" > # [1] "AMX" "AMC" "CIP" "GEN"< / span > < / span >
< span > < / span >
< span > < span class = "va" > data< / span > < span class = "op" > < -< / span > < span class = "va" > data< / span > < span class = "op" > < a href = "https://magrittr.tidyverse.org/reference/pipe.html" class = "external-link" > %> %< / a > < / span > < / span >
< span > < span class = "fu" > < a href = "https://dplyr.tidyverse.org/reference/mutate.html" class = "external-link" > mutate< / a > < / span > < span class = "op" > (< / span > < span class = "fu" > < a href = "https://dplyr.tidyverse.org/reference/across.html" class = "external-link" > across< / a > < / span > < span class = "op" > (< / span > < span class = "fu" > where< / span > < span class = "op" > (< / span > < span class = "va" > is.rsi.eligible< / span > < span class = "op" > )< / span > , < span class = "va" > as.rsi< / span > < span class = "op" > )< / span > < span class = "op" > )< / span > < / span > < / code > < / pre > < / div >
2022-10-29 14:24:08 +02:00
< p > Finally, we will apply < a href = "https://www.eucast.org/expert_rules_and_intrinsic_resistance/" class = "external-link" > 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 > AMX< / code > ) and
amoxicillin/clavulanic acid (column < code > AMC< / code > ) in our data were
generated randomly, some rows will undoubtedly contain AMX = S and AMC =
R, which is technically impossible. The < code > < a href = "../reference/eucast_rules.html" > eucast_rules()< / a > < / code >
fixes this:< / p >
2022-08-21 16:59:35 +02:00
< div class = "sourceCode" id = "cb12" > < pre class = "downlit sourceCode r" >
< code class = "sourceCode R" > < span > < span class = "va" > data< / span > < span class = "op" > < -< / span > < span class = "fu" > < a href = "../reference/eucast_rules.html" > eucast_rules< / a > < / span > < span class = "op" > (< / span > < span class = "va" > data< / span > , col_mo < span class = "op" > =< / span > < span class = "st" > "bacteria"< / span > , rules < span class = "op" > =< / span > < span class = "st" > "all"< / span > < span class = "op" > )< / span > < / span > < / code > < / pre > < / div >
< / div >
< div class = "section level2" >
< h2 id = "adding-new-variables" > Adding new variables< a class = "anchor" aria-label = "anchor" href = "#adding-new-variables" > < / a >
< / h2 >
2022-10-29 14:24:08 +02:00
< p > Now that we have the microbial ID, we can add some taxonomic
properties:< / p >
2022-08-21 16:59:35 +02:00
< div class = "sourceCode" id = "cb13" > < pre class = "downlit sourceCode r" >
2022-08-28 22:45:38 +02:00
< code class = "sourceCode R" > < span > < span class = "va" > data< / span > < span class = "op" > < -< / span > < span class = "va" > data< / span > < span class = "op" > < a href = "https://magrittr.tidyverse.org/reference/pipe.html" class = "external-link" > %> %< / a > < / span > < / span >
< span > < span class = "fu" > < a href = "https://dplyr.tidyverse.org/reference/mutate.html" class = "external-link" > mutate< / a > < / span > < span class = "op" > (< / span > < / span >
< span > gramstain < span class = "op" > =< / span > < span class = "fu" > < a href = "../reference/mo_property.html" > mo_gramstain< / a > < / span > < span class = "op" > (< / span > < span class = "va" > bacteria< / span > < span class = "op" > )< / span > ,< / span >
< span > genus < span class = "op" > =< / span > < span class = "fu" > < a href = "../reference/mo_property.html" > mo_genus< / a > < / span > < span class = "op" > (< / span > < span class = "va" > bacteria< / span > < span class = "op" > )< / span > ,< / span >
< span > species < span class = "op" > =< / span > < span class = "fu" > < a href = "../reference/mo_property.html" > mo_species< / a > < / span > < span class = "op" > (< / span > < span class = "va" > bacteria< / span > < span class = "op" > )< / span > < / span >
< span > < span class = "op" > )< / span > < / span > < / code > < / pre > < / div >
2022-08-21 16:59:35 +02:00
< div class = "section level3" >
< h3 id = "first-isolates" > First isolates< a class = "anchor" aria-label = "anchor" href = "#first-isolates" > < / a >
< / h3 >
2022-10-29 14:24:08 +02:00
< p > We also need to know which isolates we can < em > actually< / em > use for
analysis.< / p >
< p > To conduct an analysis of antimicrobial resistance, you must < a href = "https:/pubmed.ncbi.nlm.nih.gov/17304462/" > only include the first
isolate of every patient per episode< / a > (Hindler < em > et al.< / em > , Clin
Infect Dis. 2007). If you would not do this, you could easily get an
overestimate or underestimate of the resistance of an antibiotic.
Imagine that a patient was admitted with an MRSA and that it was found
in 5 different blood cultures the following weeks (yes, some countries
like the Netherlands have these blood drawing policies). The resistance
percentage of oxacillin of all isolates would be overestimated, because
you included this MRSA more than once. It would clearly be < a href = "https://en.wikipedia.org/wiki/Selection_bias" class = "external-link" > selection
bias< / a > .< / p >
< p > The Clinical and Laboratory Standards Institute (CLSI) appoints this
as follows:< / p >
2022-08-21 16:59:35 +02:00
< blockquote >
2022-10-29 14:24:08 +02:00
< p > < em > (…) When preparing a cumulative antibiogram to guide clinical
decisions about empirical antimicrobial therapy of initial infections,
< strong > only the first isolate of a given species per patient, per
analysis period (eg, one year) should be included, irrespective of body
site, antimicrobial susceptibility profile, or other phenotypical
characteristics (eg, biotype)< / strong > . The first isolate is easily
identified, and cumulative antimicrobial susceptibility test data
prepared using the first isolate are generally comparable to cumulative
antimicrobial susceptibility test data calculated by other methods,
providing duplicate isolates are excluded.< / em > < br > < a href = "https://clsi.org/standards/products/microbiology/documents/m39/" class = "external-link" > M39-A4
Analysis and Presentation of Cumulative Antimicrobial Susceptibility
Test Data, 4th Edition. CLSI, 2014. Chapter 6.4< / a > < / p >
2022-08-21 16:59:35 +02:00
< / blockquote >
2022-10-29 14:24:08 +02:00
< p > This < code > AMR< / code > package includes this methodology with the
< code > < a href = "../reference/first_isolate.html" > first_isolate()< / a > < / code > function and is able to apply the four
different methods as defined by < a href = "https://academic.oup.com/cid/article/44/6/867/364325" class = "external-link" > Hindler
< em > et al.< / em > in 2007< / a > : phenotype-based, episode-based,
patient-based, isolate-based. The right method depends on your goals and
analysis, but the default phenotype-based method is in any case the
method to properly correct for most duplicate isolates. This method also
takes into account the antimicrobial susceptibility test results using
< code > all_microbials()< / code > . Read more about the methods on the
< code > < a href = "../reference/first_isolate.html" > first_isolate()< / a > < / code > page.< / p >
2022-08-21 16:59:35 +02:00
< p > The outcome of the function can easily be added to our data:< / p >
< div class = "sourceCode" id = "cb14" > < pre class = "downlit sourceCode r" >
2022-08-28 22:45:38 +02:00
< code class = "sourceCode R" > < span > < span class = "va" > data< / span > < span class = "op" > < -< / span > < span class = "va" > data< / span > < span class = "op" > < a href = "https://magrittr.tidyverse.org/reference/pipe.html" class = "external-link" > %> %< / a > < / span > < / span >
2022-08-21 16:59:35 +02:00
< span > < span class = "fu" > < a href = "https://dplyr.tidyverse.org/reference/mutate.html" class = "external-link" > mutate< / a > < / span > < span class = "op" > (< / span > first < span class = "op" > =< / span > < span class = "fu" > < a href = "../reference/first_isolate.html" > first_isolate< / a > < / span > < span class = "op" > (< / span > info < span class = "op" > =< / span > < span class = "cn" > TRUE< / span > < span class = "op" > )< / span > < span class = "op" > )< / span > < / span >
< span > < span class = "co" > # Determining first isolates using an episode length of 365 days< / span > < / span >
2022-11-24 20:37:19 +01:00
< span > < span class = "co" > # ℹ Using column 'bacteria' as input for col_mo.< / span > < / span >
< span > < span class = "co" > # ℹ Using column 'date' as input for col_date.< / span > < / span >
< span > < span class = "co" > # ℹ Using column 'patient_id' as input for col_patient_id.< / span > < / span >
2022-08-21 16:59:35 +02:00
< span > < span class = "co" > # Basing inclusion on all antimicrobial results, using a points threshold of< / span > < / span >
< span > < span class = "co" > # 2< / span > < / span >
2022-08-28 22:45:38 +02:00
< span > < span class = "co" > # Including isolates from ICU.< / span > < / span >
2023-01-07 02:01:36 +01:00
< span > < span class = "co" > # => Found 10,750 'phenotype-based' first isolates (53.8% of total where a< / span > < / span >
2022-08-21 16:59:35 +02:00
< span > < span class = "co" > # microbial ID was available)< / span > < / span > < / code > < / pre > < / div >
2023-01-07 02:01:36 +01:00
< p > So only 53.8% is suitable for resistance analysis! We can now filter
on it with the < code > < a href = "https://dplyr.tidyverse.org/reference/filter.html" class = "external-link" > filter()< / a > < / code > function, also from the
2022-10-29 14:24:08 +02:00
< code > dplyr< / code > package:< / p >
2022-08-21 16:59:35 +02:00
< div class = "sourceCode" id = "cb15" > < pre class = "downlit sourceCode r" >
2022-08-28 22:45:38 +02:00
< code class = "sourceCode R" > < span > < span class = "va" > data_1st< / span > < span class = "op" > < -< / span > < span class = "va" > data< / span > < span class = "op" > < a href = "https://magrittr.tidyverse.org/reference/pipe.html" class = "external-link" > %> %< / a > < / span > < / span >
2022-08-21 16:59:35 +02:00
< span > < span class = "fu" > < a href = "https://dplyr.tidyverse.org/reference/filter.html" class = "external-link" > filter< / a > < / span > < span class = "op" > (< / span > < span class = "va" > first< / span > < span class = "op" > ==< / span > < span class = "cn" > TRUE< / span > < span class = "op" > )< / span > < / span > < / code > < / pre > < / div >
< p > For future use, the above two syntaxes can be shortened:< / p >
< div class = "sourceCode" id = "cb16" > < pre class = "downlit sourceCode r" >
2022-08-28 22:45:38 +02:00
< code class = "sourceCode R" > < span > < span class = "va" > data_1st< / span > < span class = "op" > < -< / span > < span class = "va" > data< / span > < span class = "op" > < a href = "https://magrittr.tidyverse.org/reference/pipe.html" class = "external-link" > %> %< / a > < / span > < / span >
< span > < span class = "fu" > < a href = "../reference/first_isolate.html" > filter_first_isolate< / a > < / span > < span class = "op" > (< / span > < span class = "op" > )< / span > < / span >
< span > < span class = "co" > # Including isolates from ICU.< / span > < / span > < / code > < / pre > < / div >
2023-01-07 02:01:36 +01:00
< p > So we end up with 10,750 isolates for analysis. Now our data looks
2022-10-29 14:24:08 +02:00
like:< / p >
2022-08-21 16:59:35 +02:00
< div class = "sourceCode" id = "cb17" > < pre class = "downlit sourceCode r" >
< code class = "sourceCode R" > < span > < span class = "fu" > < a href = "https://rdrr.io/r/utils/head.html" class = "external-link" > head< / a > < / span > < span class = "op" > (< / span > < span class = "va" > data_1st< / span > < span class = "op" > )< / span > < / span > < / code > < / pre > < / div >
2023-01-07 02:01:36 +01:00
< table style = "width:100%;" class = "table" >
2022-08-21 16:59:35 +02:00
< colgroup >
2022-11-29 19:45:20 +01:00
< col width = "2%" >
2022-08-21 16:59:35 +02:00
< col width = "9%" >
< col width = "9%" >
< col width = "9%" >
2022-11-07 18:57:12 +01:00
< col width = "10%" >
< col width = "3%" >
< col width = "3%" >
< col width = "3%" >
< col width = "3%" >
2022-11-05 12:15:23 +01:00
< col width = "6%" >
2022-11-07 18:57:12 +01:00
< col width = "11%" >
2023-01-07 02:01:36 +01:00
< col width = "12%" >
2023-01-05 18:29:06 +01:00
< col width = "9%" >
2022-08-21 16:59:35 +02:00
< col width = "5%" >
< / colgroup >
< thead > < tr class = "header" >
2022-11-29 19:45:20 +01:00
< th align = "left" > < / th >
2022-08-21 16:59:35 +02:00
< th align = "center" > date< / th >
< th align = "center" > patient_id< / th >
< th align = "center" > hospital< / th >
< th align = "center" > bacteria< / th >
< th align = "center" > AMX< / th >
< th align = "center" > AMC< / th >
< th align = "center" > CIP< / th >
< th align = "center" > GEN< / th >
< th align = "center" > gender< / th >
< th align = "center" > gramstain< / th >
< th align = "center" > genus< / th >
< th align = "center" > species< / th >
< th align = "center" > first< / th >
< / tr > < / thead >
< tbody >
< tr class = "odd" >
2023-01-07 02:01:36 +01:00
< td align = "left" > 1< / td >
< td align = "center" > 2015-01-23< / td >
< td align = "center" > N4< / td >
< td align = "center" > Hospital B< / td >
< td align = "center" > B_ESCHR_COLI< / td >
< td align = "center" > R< / td >
2023-01-06 19:28:42 +01:00
< td align = "center" > S< / td >
2023-01-06 11:29:11 +01:00
< td align = "center" > S< / td >
2023-01-06 13:51:55 +01:00
< td align = "center" > S< / td >
2023-01-06 11:29:11 +01:00
< td align = "center" > M< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > Gram-negative< / td >
< td align = "center" > Escherichia< / td >
< td align = "center" > coli< / td >
2022-12-17 14:39:03 +01:00
< td align = "center" > TRUE< / td >
< / tr >
2023-01-06 13:51:55 +01:00
< tr class = "even" >
2023-01-07 02:01:36 +01:00
< td align = "left" > 2< / td >
< td align = "center" > 2017-03-19< / td >
< td align = "center" > Z7< / td >
< td align = "center" > Hospital C< / td >
2023-01-06 19:28:42 +01:00
< td align = "center" > B_KLBSL_PNMN< / td >
2023-01-06 13:44:18 +01:00
< td align = "center" > R< / td >
2023-01-06 11:29:11 +01:00
< td align = "center" > S< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > R< / td >
2023-01-06 13:51:55 +01:00
< td align = "center" > S< / td >
2023-01-06 19:28:42 +01:00
< td align = "center" > F< / td >
2023-01-06 11:29:11 +01:00
< td align = "center" > Gram-negative< / td >
2023-01-06 19:28:42 +01:00
< td align = "center" > Klebsiella< / td >
< td align = "center" > pneumoniae< / td >
2022-10-19 11:58:58 +02:00
< td align = "center" > TRUE< / td >
< / tr >
2023-01-06 13:51:55 +01:00
< tr class = "odd" >
2023-01-07 02:01:36 +01:00
< td align = "left" > 4< / td >
< td align = "center" > 2015-08-04< / td >
< td align = "center" > X4< / td >
< td align = "center" > Hospital B< / td >
< td align = "center" > B_STPHY_AURS< / td >
< td align = "center" > I< / td >
2022-12-27 16:14:41 +01:00
< td align = "center" > S< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > R< / td >
2023-01-06 19:28:42 +01:00
< td align = "center" > S< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > F< / td >
< td align = "center" > Gram-positive< / td >
< td align = "center" > Staphylococcus< / td >
< td align = "center" > aureus< / td >
2023-01-05 18:29:06 +01:00
< td align = "center" > TRUE< / td >
< / tr >
2023-01-06 13:51:55 +01:00
< tr class = "even" >
2023-01-07 02:01:36 +01:00
< td align = "left" > 5< / td >
< td align = "center" > 2016-09-21< / td >
2023-01-06 19:28:42 +01:00
< td align = "center" > W8< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > Hospital A< / td >
< td align = "center" > B_STPHY_AURS< / td >
2023-01-06 13:51:55 +01:00
< td align = "center" > R< / td >
2023-01-06 10:16:17 +01:00
< td align = "center" > S< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > S< / td >
2023-01-06 19:28:42 +01:00
< td align = "center" > S< / td >
< td align = "center" > F< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > Gram-positive< / td >
< td align = "center" > Staphylococcus< / td >
< td align = "center" > aureus< / td >
2022-12-27 16:14:41 +01:00
< td align = "center" > TRUE< / td >
< / tr >
2023-01-06 13:51:55 +01:00
< tr class = "odd" >
2023-01-07 02:01:36 +01:00
< td align = "left" > 6< / td >
< td align = "center" > 2010-01-28< / td >
< td align = "center" > H9< / td >
< td align = "center" > Hospital A< / td >
< td align = "center" > B_ESCHR_COLI< / td >
< td align = "center" > S< / td >
< td align = "center" > S< / td >
2023-01-06 13:51:55 +01:00
< td align = "center" > S< / td >
2023-01-06 11:29:11 +01:00
< td align = "center" > R< / td >
2023-01-06 13:51:55 +01:00
< td align = "center" > M< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > Gram-negative< / td >
< td align = "center" > Escherichia< / td >
< td align = "center" > coli< / td >
2023-01-06 13:51:55 +01:00
< td align = "center" > TRUE< / td >
< / tr >
< tr class = "even" >
2023-01-07 02:01:36 +01:00
< td align = "left" > 7< / td >
< td align = "center" > 2015-05-17< / td >
< td align = "center" > Z1< / td >
< td align = "center" > Hospital D< / td >
2023-01-06 13:51:55 +01:00
< td align = "center" > B_ESCHR_COLI< / td >
2023-01-06 19:28:42 +01:00
< td align = "center" > R< / td >
< td align = "center" > R< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > S< / td >
< td align = "center" > S< / td >
2023-01-06 13:44:18 +01:00
< td align = "center" > F< / td >
2023-01-05 15:09:34 +01:00
< td align = "center" > Gram-negative< / td >
2023-01-06 13:51:55 +01:00
< td align = "center" > Escherichia< / td >
< td align = "center" > coli< / td >
2022-11-05 08:26:59 +01:00
< td align = "center" > TRUE< / td >
< / tr >
2022-08-21 16:59:35 +02:00
< / tbody >
< / table >
< p > Time for the analysis!< / p >
< / div >
< / div >
< div class = "section level2" >
< h2 id = "analysing-the-data" > Analysing the data< a class = "anchor" aria-label = "anchor" href = "#analysing-the-data" > < / a >
< / h2 >
2022-10-29 14:24:08 +02:00
< p > You 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. Although this package contains a convenient
function to make frequency tables, exploratory data analysis (EDA) is
not the primary scope of this package. Use a package like < a href = "https://cran.r-project.org/package=DataExplorer" class = "external-link" > < code > DataExplorer< / code > < / a >
for that, or read the free online book < a href = "https://bookdown.org/rdpeng/exdata/" class = "external-link" > Exploratory Data Analysis
with R< / a > by Roger D. Peng.< / p >
2022-08-21 16:59:35 +02:00
< div class = "section level3" >
< h3 id = "dispersion-of-species" > Dispersion of species< a class = "anchor" aria-label = "anchor" href = "#dispersion-of-species" > < / a >
< / h3 >
2022-10-29 14:24:08 +02:00
< p > To just get an idea how the species are distributed, create a
frequency table with our < code > < a href = "https://msberends.github.io/cleaner/reference/freq.html" class = "external-link" > freq()< / a > < / code > function. We created the
< code > genus< / code > and < code > species< / code > column earlier based on the
microbial ID. With < code > < a href = "https://rdrr.io/r/base/paste.html" class = "external-link" > paste()< / a > < / code > , we can concatenate them
together.< / p >
< p > The < code > < a href = "https://msberends.github.io/cleaner/reference/freq.html" class = "external-link" > freq()< / a > < / code > function can be used like the base R language
was intended:< / p >
2022-08-21 16:59:35 +02:00
< div class = "sourceCode" id = "cb18" > < pre class = "downlit sourceCode r" >
2022-10-29 14:24:08 +02:00
< code class = "sourceCode R" > < span > < span class = "fu" > < a href = "https://msberends.github.io/cleaner/reference/freq.html" class = "external-link" > freq< / a > < / span > < span class = "op" > (< / span > < span class = "fu" > < a href = "https://rdrr.io/r/base/paste.html" class = "external-link" > paste< / a > < / span > < span class = "op" > (< / span > < span class = "va" > data_1st< / span > < span class = "op" > $< / span > < span class = "va" > genus< / span > , < span class = "va" > data_1st< / span > < span class = "op" > $< / span > < span class = "va" > species< / span > < span class = "op" > )< / span > < span class = "op" > )< / span > < / span > < / code > < / pre > < / div >
< p > Or can be used like the < code > dplyr< / code > way, which is easier
readable:< / p >
2022-08-21 16:59:35 +02:00
< div class = "sourceCode" id = "cb19" > < pre class = "downlit sourceCode r" >
2022-10-29 14:24:08 +02:00
< code class = "sourceCode R" > < span > < span class = "va" > data_1st< / span > < span class = "op" > < a href = "https://magrittr.tidyverse.org/reference/pipe.html" class = "external-link" > %> %< / a > < / span > < span class = "fu" > < a href = "https://msberends.github.io/cleaner/reference/freq.html" class = "external-link" > freq< / a > < / span > < span class = "op" > (< / span > < span class = "va" > genus< / span > , < span class = "va" > species< / span > < span class = "op" > )< / span > < / span > < / code > < / pre > < / div >
2022-08-21 16:59:35 +02:00
< p > < strong > Frequency table< / strong > < / p >
< p > Class: character< br >
2023-01-07 02:01:36 +01:00
Length: 10,750< br >
Available: 10,750 (100%, NA: 0 = 0%)< br >
2022-08-21 16:59:35 +02:00
Unique: 4< / p >
< p > Shortest: 16< br >
Longest: 24< / p >
< table class = "table" >
2022-10-29 14:24:08 +02:00
< colgroup >
< col width = "4%" >
< col width = "36%" >
< col width = "9%" >
< col width = "12%" >
< col width = "16%" >
< col width = "19%" >
< / colgroup >
2022-08-21 16:59:35 +02:00
< thead > < tr class = "header" >
< th align = "left" > < / th >
< th align = "left" > Item< / th >
< th align = "right" > Count< / th >
< th align = "right" > Percent< / th >
< th align = "right" > Cum. Count< / th >
< th align = "right" > Cum. Percent< / th >
< / tr > < / thead >
< tbody >
< tr class = "odd" >
< td align = "left" > 1< / td >
< td align = "left" > Escherichia coli< / td >
2023-01-07 02:01:36 +01:00
< td align = "right" > 4,767< / td >
< td align = "right" > 44.34%< / td >
< td align = "right" > 4,767< / td >
< td align = "right" > 44.34%< / td >
2022-08-21 16:59:35 +02:00
< / tr >
< tr class = "even" >
< td align = "left" > 2< / td >
< td align = "left" > Staphylococcus aureus< / td >
2023-01-07 02:01:36 +01:00
< td align = "right" > 2,719< / td >
< td align = "right" > 25.29%< / td >
< td align = "right" > 7,486< / td >
< td align = "right" > 69.64%< / td >
2022-08-21 16:59:35 +02:00
< / tr >
< tr class = "odd" >
< td align = "left" > 3< / td >
< td align = "left" > Streptococcus pneumoniae< / td >
2023-01-07 02:01:36 +01:00
< td align = "right" > 2,078< / td >
< td align = "right" > 19.33%< / td >
< td align = "right" > 9,564< / td >
< td align = "right" > 88.97%< / td >
2022-08-21 16:59:35 +02:00
< / tr >
< tr class = "even" >
< td align = "left" > 4< / td >
< td align = "left" > Klebsiella pneumoniae< / td >
2023-01-07 02:01:36 +01:00
< td align = "right" > 1,186< / td >
< td align = "right" > 11.03%< / td >
< td align = "right" > 10,750< / td >
2022-12-27 16:14:41 +01:00
< td align = "right" > 100.00%< / td >
2022-08-21 16:59:35 +02:00
< / tr >
< / tbody >
< / table >
< / div >
< div class = "section level3" >
< h3 id = "overview-of-different-bugdrug-combinations" > Overview of different bug/drug combinations< a class = "anchor" aria-label = "anchor" href = "#overview-of-different-bugdrug-combinations" > < / a >
< / h3 >
2022-10-29 14:24:08 +02:00
< p > Using < a href = "https://tidyselect.r-lib.org/reference/language.html" class = "external-link" > tidyverse
selections< / a > , you can also select or filter columns based on the
antibiotic class they are in:< / p >
2022-08-21 16:59:35 +02:00
< div class = "sourceCode" id = "cb20" > < pre class = "downlit sourceCode r" >
2022-08-28 22:45:38 +02:00
< code class = "sourceCode R" > < span > < span class = "va" > data_1st< / span > < span class = "op" > < a href = "https://magrittr.tidyverse.org/reference/pipe.html" class = "external-link" > %> %< / a > < / span > < / span >
2022-08-21 16:59:35 +02:00
< span > < span class = "fu" > < a href = "https://dplyr.tidyverse.org/reference/filter.html" class = "external-link" > filter< / a > < / span > < span class = "op" > (< / span > < span class = "fu" > < a href = "https://rdrr.io/r/base/any.html" class = "external-link" > any< / a > < / span > < span class = "op" > (< / span > < span class = "fu" > < a href = "../reference/antibiotic_class_selectors.html" > aminoglycosides< / a > < / span > < span class = "op" > (< / span > < span class = "op" > )< / span > < span class = "op" > ==< / span > < span class = "st" > "R"< / span > < span class = "op" > )< / span > < span class = "op" > )< / span > < / span > < / code > < / pre > < / div >
2022-11-24 20:37:19 +01:00
< pre > < code > < span > < span class = "co" > # ℹ For aminoglycosides() using column 'GEN' (gentamicin)< / span > < / span > < / code > < / pre >
2022-08-21 16:59:35 +02:00
< table class = "table" >
< colgroup >
< col width = "9%" >
< col width = "9%" >
< col width = "9%" >
2023-01-06 13:51:55 +01:00
< col width = "11%" >
2022-08-21 16:59:35 +02:00
< col width = "3%" >
< col width = "3%" >
< col width = "3%" >
< col width = "3%" >
< col width = "6%" >
< col width = "11%" >
2023-01-06 13:51:55 +01:00
< col width = "11%" >
2022-08-21 16:59:35 +02:00
< col width = "9%" >
< col width = "5%" >
< / colgroup >
< thead > < tr class = "header" >
< th align = "center" > date< / th >
< th align = "center" > patient_id< / th >
< th align = "center" > hospital< / th >
< th align = "center" > bacteria< / th >
< th align = "center" > AMX< / th >
< th align = "center" > AMC< / th >
< th align = "center" > CIP< / th >
< th align = "center" > GEN< / th >
< th align = "center" > gender< / th >
< th align = "center" > gramstain< / th >
< th align = "center" > genus< / th >
< th align = "center" > species< / th >
< th align = "center" > first< / th >
< / tr > < / thead >
< tbody >
< tr class = "odd" >
2023-01-07 02:01:36 +01:00
< td align = "center" > 2010-01-28< / td >
< td align = "center" > H9< / td >
2023-01-06 19:28:42 +01:00
< td align = "center" > Hospital A< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > B_ESCHR_COLI< / td >
2023-01-06 10:16:17 +01:00
< td align = "center" > S< / td >
< td align = "center" > S< / td >
2023-01-06 19:28:42 +01:00
< td align = "center" > S< / td >
2023-01-06 11:29:11 +01:00
< td align = "center" > R< / td >
2023-01-06 19:28:42 +01:00
< td align = "center" > M< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > Gram-negative< / td >
< td align = "center" > Escherichia< / td >
< td align = "center" > coli< / td >
2023-01-05 18:29:06 +01:00
< td align = "center" > TRUE< / td >
< / tr >
2023-01-06 13:51:55 +01:00
< tr class = "even" >
2023-01-07 02:01:36 +01:00
< td align = "center" > 2016-02-10< / td >
< td align = "center" > X1< / td >
< td align = "center" > Hospital A< / td >
2023-01-06 19:28:42 +01:00
< td align = "center" > B_STRPT_PNMN< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > S< / td >
< td align = "center" > S< / td >
2023-01-06 19:28:42 +01:00
< td align = "center" > S< / td >
2023-01-06 13:51:55 +01:00
< td align = "center" > R< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > F< / td >
2023-01-06 19:28:42 +01:00
< td align = "center" > Gram-positive< / td >
< td align = "center" > Streptococcus< / td >
< td align = "center" > pneumoniae< / td >
2022-11-10 22:16:02 +01:00
< td align = "center" > TRUE< / td >
< / tr >
2023-01-06 13:51:55 +01:00
< tr class = "odd" >
2023-01-07 02:01:36 +01:00
< td align = "center" > 2015-05-27< / td >
< td align = "center" > D10< / td >
< td align = "center" > Hospital A< / td >
< td align = "center" > B_STRPT_PNMN< / td >
< td align = "center" > S< / td >
< td align = "center" > S< / td >
2023-01-05 14:53:59 +01:00
< td align = "center" > S< / td >
2023-01-05 15:09:34 +01:00
< td align = "center" > R< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > M< / td >
< td align = "center" > Gram-positive< / td >
< td align = "center" > Streptococcus< / td >
< td align = "center" > pneumoniae< / td >
2023-01-06 13:44:18 +01:00
< td align = "center" > TRUE< / td >
< / tr >
2023-01-06 13:51:55 +01:00
< tr class = "even" >
2023-01-07 02:01:36 +01:00
< td align = "center" > 2017-09-20< / td >
< td align = "center" > F9< / td >
< td align = "center" > Hospital A< / td >
2023-01-06 13:44:18 +01:00
< td align = "center" > B_STRPT_PNMN< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > S< / td >
< td align = "center" > S< / td >
2023-01-06 13:44:18 +01:00
< td align = "center" > S< / td >
2023-01-06 13:51:55 +01:00
< td align = "center" > R< / td >
2023-01-06 19:28:42 +01:00
< td align = "center" > M< / td >
2023-01-06 13:51:55 +01:00
< td align = "center" > Gram-positive< / td >
< td align = "center" > Streptococcus< / td >
< td align = "center" > pneumoniae< / td >
< td align = "center" > TRUE< / td >
< / tr >
< tr class = "odd" >
2023-01-07 02:01:36 +01:00
< td align = "center" > 2016-04-12< / td >
< td align = "center" > Z5< / td >
< td align = "center" > Hospital D< / td >
2023-01-06 13:51:55 +01:00
< td align = "center" > B_STRPT_PNMN< / td >
2023-01-06 13:44:18 +01:00
< td align = "center" > R< / td >
2023-01-06 13:51:55 +01:00
< td align = "center" > R< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > R< / td >
2023-01-06 19:28:42 +01:00
< td align = "center" > R< / td >
2023-01-06 13:44:18 +01:00
< td align = "center" > F< / td >
< td align = "center" > Gram-positive< / td >
< td align = "center" > Streptococcus< / td >
< td align = "center" > pneumoniae< / td >
2022-08-21 16:59:35 +02:00
< td align = "center" > TRUE< / td >
< / tr >
2023-01-05 18:29:06 +01:00
< tr class = "even" >
2023-01-07 02:01:36 +01:00
< td align = "center" > 2011-12-20< / td >
< td align = "center" > D3< / td >
2023-01-06 11:29:11 +01:00
< td align = "center" > Hospital A< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > B_STRPT_PNMN< / td >
< td align = "center" > R< / td >
2023-01-06 13:51:55 +01:00
< td align = "center" > R< / td >
2023-01-05 15:48:37 +01:00
< td align = "center" > S< / td >
2023-01-05 15:09:34 +01:00
< td align = "center" > R< / td >
2023-01-06 19:28:42 +01:00
< td align = "center" > M< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > Gram-positive< / td >
< td align = "center" > Streptococcus< / td >
< td align = "center" > pneumoniae< / td >
2022-12-30 13:10:58 +01:00
< td align = "center" > TRUE< / td >
< / tr >
2022-08-21 16:59:35 +02:00
< / tbody >
< / table >
2022-10-29 14:24:08 +02:00
< p > If you want to get a quick glance of the number of isolates in
different bug/drug combinations, you can use the
< code > < a href = "../reference/bug_drug_combinations.html" > bug_drug_combinations()< / a > < / code > function:< / p >
2022-08-21 16:59:35 +02:00
< div class = "sourceCode" id = "cb22" > < pre class = "downlit sourceCode r" >
2022-08-28 22:45:38 +02:00
< code class = "sourceCode R" > < span > < span class = "va" > data_1st< / span > < span class = "op" > < a href = "https://magrittr.tidyverse.org/reference/pipe.html" class = "external-link" > %> %< / a > < / span > < / span >
< span > < span class = "fu" > < a href = "../reference/bug_drug_combinations.html" > bug_drug_combinations< / a > < / span > < span class = "op" > (< / span > < span class = "op" > )< / span > < span class = "op" > < a href = "https://magrittr.tidyverse.org/reference/pipe.html" class = "external-link" > %> %< / a > < / span > < / span >
2022-08-21 16:59:35 +02:00
< span > < span class = "fu" > < a href = "https://rdrr.io/r/utils/head.html" class = "external-link" > head< / a > < / span > < span class = "op" > (< / span > < span class = "op" > )< / span > < span class = "co" > # show first 6 rows< / span > < / span > < / code > < / pre > < / div >
< table class = "table" >
< thead > < tr class = "header" >
< th align = "center" > mo< / th >
< th align = "center" > ab< / th >
< th align = "center" > S< / th >
< th align = "center" > I< / th >
< th align = "center" > R< / th >
< th align = "center" > total< / th >
< / tr > < / thead >
< tbody >
< tr class = "odd" >
< td align = "center" > E. coli< / td >
< td align = "center" > AMX< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > 2241< / td >
< td align = "center" > 136< / td >
< td align = "center" > 2390< / td >
< td align = "center" > 4767< / td >
2022-08-21 16:59:35 +02:00
< / tr >
< tr class = "even" >
< td align = "center" > E. coli< / td >
< td align = "center" > AMC< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > 3489< / td >
2023-01-06 19:28:42 +01:00
< td align = "center" > 168< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > 1110< / td >
< td align = "center" > 4767< / td >
2022-08-21 16:59:35 +02:00
< / tr >
< tr class = "odd" >
< td align = "center" > E. coli< / td >
< td align = "center" > CIP< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > 3502< / td >
2022-08-21 16:59:35 +02:00
< td align = "center" > 0< / td >
2023-01-06 19:28:42 +01:00
< td align = "center" > 1265< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > 4767< / td >
2022-08-21 16:59:35 +02:00
< / tr >
< tr class = "even" >
< td align = "center" > E. coli< / td >
< td align = "center" > GEN< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > 4141< / td >
2022-08-21 16:59:35 +02:00
< td align = "center" > 0< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > 626< / td >
< td align = "center" > 4767< / td >
2022-08-21 16:59:35 +02:00
< / tr >
< tr class = "odd" >
< td align = "center" > K. pneumoniae< / td >
< td align = "center" > AMX< / td >
< td align = "center" > 0< / td >
< td align = "center" > 0< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > 1186< / td >
< td align = "center" > 1186< / td >
2022-08-21 16:59:35 +02:00
< / tr >
< tr class = "even" >
< td align = "center" > K. pneumoniae< / td >
< td align = "center" > AMC< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > 924< / td >
< td align = "center" > 53< / td >
< td align = "center" > 209< / td >
< td align = "center" > 1186< / td >
2022-08-21 16:59:35 +02:00
< / tr >
< / tbody >
< / table >
2022-11-24 20:37:19 +01:00
< div class = "sourceCode" id = "cb23" > < pre class = "downlit sourceCode r" >
2022-08-28 22:45:38 +02:00
< code class = "sourceCode R" > < span > < span class = "va" > data_1st< / span > < span class = "op" > < a href = "https://magrittr.tidyverse.org/reference/pipe.html" class = "external-link" > %> %< / a > < / span > < / span >
< span > < span class = "fu" > < a href = "https://dplyr.tidyverse.org/reference/select.html" class = "external-link" > select< / a > < / span > < span class = "op" > (< / span > < span class = "va" > bacteria< / span > , < span class = "fu" > < a href = "../reference/antibiotic_class_selectors.html" > aminoglycosides< / a > < / span > < span class = "op" > (< / span > < span class = "op" > )< / span > < span class = "op" > )< / span > < span class = "op" > < a href = "https://magrittr.tidyverse.org/reference/pipe.html" class = "external-link" > %> %< / a > < / span > < / span >
2022-08-21 16:59:35 +02:00
< span > < span class = "fu" > < a href = "../reference/bug_drug_combinations.html" > bug_drug_combinations< / a > < / span > < span class = "op" > (< / span > < span class = "op" > )< / span > < / span > < / code > < / pre > < / div >
2022-11-24 20:37:19 +01:00
< pre > < code > < span > < span class = "co" > # ℹ For aminoglycosides() using column 'GEN' (gentamicin)< / span > < / span > < / code > < / pre >
2022-08-21 16:59:35 +02:00
< table class = "table" >
< thead > < tr class = "header" >
< th align = "center" > mo< / th >
< th align = "center" > ab< / th >
< th align = "center" > S< / th >
< th align = "center" > I< / th >
< th align = "center" > R< / th >
< th align = "center" > total< / th >
< / tr > < / thead >
< tbody >
< tr class = "odd" >
< td align = "center" > E. coli< / td >
< td align = "center" > GEN< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > 4141< / td >
2022-08-21 16:59:35 +02:00
< td align = "center" > 0< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > 626< / td >
< td align = "center" > 4767< / td >
2022-08-21 16:59:35 +02:00
< / tr >
< tr class = "even" >
< td align = "center" > K. pneumoniae< / td >
< td align = "center" > GEN< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > 1072< / td >
2022-08-21 16:59:35 +02:00
< td align = "center" > 0< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > 114< / td >
< td align = "center" > 1186< / td >
2022-08-21 16:59:35 +02:00
< / tr >
< tr class = "odd" >
< td align = "center" > S. aureus< / td >
< td align = "center" > GEN< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > 2409< / td >
2022-08-21 16:59:35 +02:00
< td align = "center" > 0< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > 310< / td >
< td align = "center" > 2719< / td >
2022-08-21 16:59:35 +02:00
< / tr >
< tr class = "even" >
< td align = "center" > S. pneumoniae< / td >
< td align = "center" > GEN< / td >
< td align = "center" > 0< / td >
< td align = "center" > 0< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > 2078< / td >
< td align = "center" > 2078< / td >
2022-08-21 16:59:35 +02:00
< / tr >
< / tbody >
< / table >
2022-10-29 14:24:08 +02:00
< p > This will only give you the crude numbers in the data. To calculate
antimicrobial resistance in a more sensible way, also by correcting for
too few results, we use the < code > < a href = "../reference/proportion.html" > resistance()< / a > < / code > and
< code > < a href = "../reference/proportion.html" > susceptibility()< / a > < / code > functions.< / p >
2022-08-21 16:59:35 +02:00
< / div >
< div class = "section level3" >
< h3 id = "resistance-percentages" > Resistance percentages< a class = "anchor" aria-label = "anchor" href = "#resistance-percentages" > < / a >
< / h3 >
2022-10-29 14:24:08 +02:00
< p > The functions < code > < a href = "../reference/proportion.html" > resistance()< / a > < / code > and
< code > < a href = "../reference/proportion.html" > susceptibility()< / a > < / code > can be used to calculate antimicrobial
resistance or susceptibility. For more specific analyses, the functions
< code > < a href = "../reference/proportion.html" > proportion_S()< / a > < / code > , < code > < a href = "../reference/proportion.html" > proportion_SI()< / a > < / code > ,
< code > < a href = "../reference/proportion.html" > proportion_I()< / a > < / code > , < code > < a href = "../reference/proportion.html" > proportion_IR()< / a > < / code > and
< code > < a href = "../reference/proportion.html" > proportion_R()< / a > < / code > can be used to determine the proportion of a
specific antimicrobial outcome.< / p >
< p > All these functions contain a < code > minimum< / code > argument, denoting
the minimum required number of test results for returning a value. These
functions will otherwise return < code > NA< / code > . The default is
< code > minimum = 30< / code > , following the < a href = "https://clsi.org/standards/products/microbiology/documents/m39/" class = "external-link" > CLSI
M39-A4 guideline< / a > for applying microbial epidemiology.< / p >
< p > As per the EUCAST guideline of 2019, we calculate resistance as the
proportion of R (< code > < a href = "../reference/proportion.html" > proportion_R()< / a > < / code > , equal to
< code > < a href = "../reference/proportion.html" > resistance()< / a > < / code > ) and susceptibility as the proportion of S and
I (< code > < a href = "../reference/proportion.html" > proportion_SI()< / a > < / code > , equal to
< code > < a href = "../reference/proportion.html" > susceptibility()< / a > < / code > ). These functions can be used on their
own:< / p >
2022-11-24 20:37:19 +01:00
< div class = "sourceCode" id = "cb25" > < pre class = "downlit sourceCode r" >
2022-08-21 16:59:35 +02:00
< code class = "sourceCode R" > < span > < span class = "va" > data_1st< / span > < span class = "op" > < a href = "https://magrittr.tidyverse.org/reference/pipe.html" class = "external-link" > %> %< / a > < / span > < span class = "fu" > < a href = "../reference/proportion.html" > resistance< / a > < / span > < span class = "op" > (< / span > < span class = "va" > AMX< / span > < span class = "op" > )< / span > < / span >
2023-01-07 02:01:36 +01:00
< span > < span class = "co" > # [1] 0.543814< / span > < / span > < / code > < / pre > < / div >
2022-10-29 14:24:08 +02:00
< p > Or can be used in conjunction with < code > < a href = "https://dplyr.tidyverse.org/reference/group_by.html" class = "external-link" > group_by()< / a > < / code > and
< code > < a href = "https://dplyr.tidyverse.org/reference/summarise.html" class = "external-link" > summarise()< / a > < / code > , both from the < code > dplyr< / code > package:< / p >
2022-11-24 20:37:19 +01:00
< div class = "sourceCode" id = "cb26" > < pre class = "downlit sourceCode r" >
2022-08-28 22:45:38 +02:00
< code class = "sourceCode R" > < span > < span class = "va" > data_1st< / span > < span class = "op" > < a href = "https://magrittr.tidyverse.org/reference/pipe.html" class = "external-link" > %> %< / a > < / span > < / span >
< span > < span class = "fu" > < a href = "https://dplyr.tidyverse.org/reference/group_by.html" class = "external-link" > group_by< / a > < / span > < span class = "op" > (< / span > < span class = "va" > hospital< / span > < span class = "op" > )< / span > < span class = "op" > < a href = "https://magrittr.tidyverse.org/reference/pipe.html" class = "external-link" > %> %< / a > < / span > < / span >
2022-08-21 16:59:35 +02:00
< span > < span class = "fu" > < a href = "https://dplyr.tidyverse.org/reference/summarise.html" class = "external-link" > summarise< / a > < / span > < span class = "op" > (< / span > amoxicillin < span class = "op" > =< / span > < span class = "fu" > < a href = "../reference/proportion.html" > resistance< / a > < / span > < span class = "op" > (< / span > < span class = "va" > AMX< / span > < span class = "op" > )< / span > < span class = "op" > )< / span > < / span > < / code > < / pre > < / div >
< table class = "table" >
< thead > < tr class = "header" >
< th align = "center" > hospital< / th >
< th align = "center" > amoxicillin< / th >
< / tr > < / thead >
< tbody >
< tr class = "odd" >
< td align = "center" > Hospital A< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > 0.5540994< / td >
2022-08-21 16:59:35 +02:00
< / tr >
< tr class = "even" >
< td align = "center" > Hospital B< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > 0.5473965< / td >
2022-08-21 16:59:35 +02:00
< / tr >
< tr class = "odd" >
< td align = "center" > Hospital C< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > 0.5031606< / td >
2022-08-21 16:59:35 +02:00
< / tr >
< tr class = "even" >
< td align = "center" > Hospital D< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > 0.5518207< / td >
2022-08-21 16:59:35 +02:00
< / tr >
< / tbody >
< / table >
2022-10-29 14:24:08 +02:00
< p > Of course it would be very convenient to know the number of isolates
responsible for the percentages. For that purpose the
< code > < a href = "../reference/count.html" > n_rsi()< / a > < / code > can be used, which works exactly like
< code > < a href = "https://dplyr.tidyverse.org/reference/n_distinct.html" class = "external-link" > n_distinct()< / a > < / code > from the < code > dplyr< / code > package. It counts
all isolates available for every group (i.e. values S, I or R):< / p >
2022-11-24 20:37:19 +01:00
< div class = "sourceCode" id = "cb27" > < pre class = "downlit sourceCode r" >
2022-08-28 22:45:38 +02:00
< code class = "sourceCode R" > < span > < span class = "va" > data_1st< / span > < span class = "op" > < a href = "https://magrittr.tidyverse.org/reference/pipe.html" class = "external-link" > %> %< / a > < / span > < / span >
< span > < span class = "fu" > < a href = "https://dplyr.tidyverse.org/reference/group_by.html" class = "external-link" > group_by< / a > < / span > < span class = "op" > (< / span > < span class = "va" > hospital< / span > < span class = "op" > )< / span > < span class = "op" > < a href = "https://magrittr.tidyverse.org/reference/pipe.html" class = "external-link" > %> %< / a > < / span > < / span >
< span > < span class = "fu" > < a href = "https://dplyr.tidyverse.org/reference/summarise.html" class = "external-link" > summarise< / a > < / span > < span class = "op" > (< / span > < / span >
< span > amoxicillin < span class = "op" > =< / span > < span class = "fu" > < a href = "../reference/proportion.html" > resistance< / a > < / span > < span class = "op" > (< / span > < span class = "va" > AMX< / span > < span class = "op" > )< / span > ,< / span >
< span > available < span class = "op" > =< / span > < span class = "fu" > < a href = "../reference/count.html" > n_rsi< / a > < / span > < span class = "op" > (< / span > < span class = "va" > AMX< / span > < span class = "op" > )< / span > < / span >
< span > < span class = "op" > )< / span > < / span > < / code > < / pre > < / div >
2022-08-21 16:59:35 +02:00
< table class = "table" >
< thead > < tr class = "header" >
< th align = "center" > hospital< / th >
< th align = "center" > amoxicillin< / th >
< th align = "center" > available< / th >
< / tr > < / thead >
< tbody >
< tr class = "odd" >
< td align = "center" > Hospital A< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > 0.5540994< / td >
< td align = "center" > 3281< / td >
2022-08-21 16:59:35 +02:00
< / tr >
< tr class = "even" >
< td align = "center" > Hospital B< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > 0.5473965< / td >
< td align = "center" > 3745< / td >
2022-08-21 16:59:35 +02:00
< / tr >
< tr class = "odd" >
< td align = "center" > Hospital C< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > 0.5031606< / td >
< td align = "center" > 1582< / td >
2022-08-21 16:59:35 +02:00
< / tr >
< tr class = "even" >
< td align = "center" > Hospital D< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > 0.5518207< / td >
< td align = "center" > 2142< / td >
2022-08-21 16:59:35 +02:00
< / tr >
< / tbody >
< / table >
2022-10-29 14:24:08 +02:00
< p > These functions can also be used to get the proportion of multiple
antibiotics, to calculate empiric susceptibility of combination
therapies very easily:< / p >
2022-11-24 20:37:19 +01:00
< div class = "sourceCode" id = "cb28" > < pre class = "downlit sourceCode r" >
2022-08-28 22:45:38 +02:00
< code class = "sourceCode R" > < span > < span class = "va" > data_1st< / span > < span class = "op" > < a href = "https://magrittr.tidyverse.org/reference/pipe.html" class = "external-link" > %> %< / a > < / span > < / span >
< span > < span class = "fu" > < a href = "https://dplyr.tidyverse.org/reference/group_by.html" class = "external-link" > group_by< / a > < / span > < span class = "op" > (< / span > < span class = "va" > genus< / span > < span class = "op" > )< / span > < span class = "op" > < a href = "https://magrittr.tidyverse.org/reference/pipe.html" class = "external-link" > %> %< / a > < / span > < / span >
< span > < span class = "fu" > < a href = "https://dplyr.tidyverse.org/reference/summarise.html" class = "external-link" > summarise< / a > < / span > < span class = "op" > (< / span > < / span >
< span > amoxiclav < span class = "op" > =< / span > < span class = "fu" > < a href = "../reference/proportion.html" > susceptibility< / a > < / span > < span class = "op" > (< / span > < span class = "va" > AMC< / span > < span class = "op" > )< / span > ,< / span >
< span > gentamicin < span class = "op" > =< / span > < span class = "fu" > < a href = "../reference/proportion.html" > susceptibility< / a > < / span > < span class = "op" > (< / span > < span class = "va" > GEN< / span > < span class = "op" > )< / span > ,< / span >
< span > amoxiclav_genta < span class = "op" > =< / span > < span class = "fu" > < a href = "../reference/proportion.html" > susceptibility< / a > < / span > < span class = "op" > (< / span > < span class = "va" > AMC< / span > , < span class = "va" > GEN< / span > < span class = "op" > )< / span > < / span >
< span > < span class = "op" > )< / span > < / span > < / code > < / pre > < / div >
2022-08-21 16:59:35 +02:00
< table class = "table" >
< thead > < tr class = "header" >
< th align = "center" > genus< / th >
< th align = "center" > amoxiclav< / th >
< th align = "center" > gentamicin< / th >
< th align = "center" > amoxiclav_genta< / th >
< / tr > < / thead >
< tbody >
< tr class = "odd" >
< td align = "center" > Escherichia< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > 0.7671492< / td >
< td align = "center" > 0.8686805< / td >
< td align = "center" > 0.9758758< / td >
2022-08-21 16:59:35 +02:00
< / tr >
< tr class = "even" >
< td align = "center" > Klebsiella< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > 0.8237774< / td >
< td align = "center" > 0.9038786< / td >
< td align = "center" > 0.9806071< / td >
2022-08-21 16:59:35 +02:00
< / tr >
< tr class = "odd" >
< td align = "center" > Staphylococcus< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > 0.7899963< / td >
< td align = "center" > 0.8859875< / td >
< td align = "center" > 0.9834498< / td >
2022-08-21 16:59:35 +02:00
< / tr >
< tr class = "even" >
< td align = "center" > Streptococcus< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > 0.5303176< / td >
2022-08-21 16:59:35 +02:00
< td align = "center" > 0.0000000< / td >
2023-01-07 02:01:36 +01:00
< td align = "center" > 0.5303176< / td >
2022-08-21 16:59:35 +02:00
< / tr >
< / tbody >
< / table >
2022-10-29 14:24:08 +02:00
< p > Or if you are curious for the resistance within certain antibiotic
classes, use a antibiotic class selector such as
< code > < a href = "../reference/antibiotic_class_selectors.html" > penicillins()< / a > < / code > , which automatically will include the columns
< code > AMX< / code > and < code > AMC< / code > of our data:< / p >
2022-11-24 20:37:19 +01:00
< div class = "sourceCode" id = "cb29" > < pre class = "downlit sourceCode r" >
2022-08-28 22:45:38 +02:00
< code class = "sourceCode R" > < span > < span class = "va" > data_1st< / span > < span class = "op" > < a href = "https://magrittr.tidyverse.org/reference/pipe.html" class = "external-link" > %> %< / a > < / span > < / span >
2022-08-21 16:59:35 +02:00
< span > < span class = "co" > # group by hospital< / span > < / span >
2022-08-28 22:45:38 +02:00
< span > < span class = "fu" > < a href = "https://dplyr.tidyverse.org/reference/group_by.html" class = "external-link" > group_by< / a > < / span > < span class = "op" > (< / span > < span class = "va" > hospital< / span > < span class = "op" > )< / span > < span class = "op" > < a href = "https://magrittr.tidyverse.org/reference/pipe.html" class = "external-link" > %> %< / a > < / span > < / span >
2022-08-21 16:59:35 +02:00
< span > < span class = "co" > # / -> select all penicillins in the data for calculation< / span > < / span >
< span > < span class = "co" > # | / -> use resistance() for all peni's per hospital< / span > < / span >
< span > < span class = "co" > # | | / -> print as percentages< / span > < / span >
2022-08-28 22:45:38 +02:00
< span > < span class = "fu" > < a href = "https://dplyr.tidyverse.org/reference/summarise.html" class = "external-link" > summarise< / a > < / span > < span class = "op" > (< / span > < span class = "fu" > < a href = "https://dplyr.tidyverse.org/reference/across.html" class = "external-link" > across< / a > < / span > < span class = "op" > (< / span > < span class = "fu" > < a href = "../reference/antibiotic_class_selectors.html" > penicillins< / a > < / span > < span class = "op" > (< / span > < span class = "op" > )< / span > , < span class = "va" > resistance< / span > , as_percent < span class = "op" > =< / span > < span class = "cn" > TRUE< / span > < span class = "op" > )< / span > < span class = "op" > )< / span > < span class = "op" > < a href = "https://magrittr.tidyverse.org/reference/pipe.html" class = "external-link" > %> %< / a > < / span > < / span >
2022-08-21 16:59:35 +02:00
< span > < span class = "co" > # format the antibiotic column names, using so-called snake case,< / span > < / span >
< span > < span class = "co" > # so 'Amoxicillin/clavulanic acid' becomes 'amoxicillin_clavulanic_acid'< / span > < / span >
< span > < span class = "fu" > < a href = "https://dplyr.tidyverse.org/reference/rename.html" class = "external-link" > rename_with< / a > < / span > < span class = "op" > (< / span > < span class = "va" > set_ab_names< / span > , < span class = "fu" > < a href = "../reference/antibiotic_class_selectors.html" > penicillins< / a > < / span > < span class = "op" > (< / span > < span class = "op" > )< / span > < span class = "op" > )< / span > < / span > < / code > < / pre > < / div >
< table class = "table" >
< thead > < tr class = "header" >
< th align = "left" > hospital< / th >
< th align = "right" > amoxicillin< / th >
< th align = "right" > amoxicillin_clavulanic_acid< / th >
< / tr > < / thead >
< tbody >
< tr class = "odd" >
< td align = "left" > Hospital A< / td >
2023-01-07 02:01:36 +01:00
< td align = "right" > 55.4%< / td >
< td align = "right" > 26.9%< / td >
2022-08-21 16:59:35 +02:00
< / tr >
< tr class = "even" >
< td align = "left" > Hospital B< / td >
2023-01-07 02:01:36 +01:00
< td align = "right" > 54.7%< / td >
< td align = "right" > 27.3%< / td >
2022-08-21 16:59:35 +02:00
< / tr >
< tr class = "odd" >
< td align = "left" > Hospital C< / td >
2023-01-07 02:01:36 +01:00
< td align = "right" > 50.3%< / td >
< td align = "right" > 25.5%< / td >
2022-08-21 16:59:35 +02:00
< / tr >
< tr class = "even" >
< td align = "left" > Hospital D< / td >
2023-01-07 02:01:36 +01:00
< td align = "right" > 55.2%< / td >
< td align = "right" > 25.9%< / td >
2022-08-21 16:59:35 +02:00
< / tr >
< / tbody >
< / table >
2022-10-29 14:24:08 +02:00
< p > To make a transition to the next part, let’ s see how differences in
the previously calculated combination therapies could be plotted:< / p >
2022-11-24 20:37:19 +01:00
< div class = "sourceCode" id = "cb30" > < pre class = "downlit sourceCode r" >
2022-08-28 22:45:38 +02:00
< code class = "sourceCode R" > < span > < span class = "va" > data_1st< / span > < span class = "op" > < a href = "https://magrittr.tidyverse.org/reference/pipe.html" class = "external-link" > %> %< / a > < / span > < / span >
< span > < span class = "fu" > < a href = "https://dplyr.tidyverse.org/reference/group_by.html" class = "external-link" > group_by< / a > < / span > < span class = "op" > (< / span > < span class = "va" > genus< / span > < span class = "op" > )< / span > < span class = "op" > < a href = "https://magrittr.tidyverse.org/reference/pipe.html" class = "external-link" > %> %< / a > < / span > < / span >
< span > < span class = "fu" > < a href = "https://dplyr.tidyverse.org/reference/summarise.html" class = "external-link" > summarise< / a > < / span > < span class = "op" > (< / span > < / span >
< span > < span class = "st" > "1. Amoxi/clav"< / span > < span class = "op" > =< / span > < span class = "fu" > < a href = "../reference/proportion.html" > susceptibility< / a > < / span > < span class = "op" > (< / span > < span class = "va" > AMC< / span > < span class = "op" > )< / span > ,< / span >
< span > < span class = "st" > "2. Gentamicin"< / span > < span class = "op" > =< / span > < span class = "fu" > < a href = "../reference/proportion.html" > susceptibility< / a > < / span > < span class = "op" > (< / span > < span class = "va" > GEN< / span > < span class = "op" > )< / span > ,< / span >
< span > < span class = "st" > "3. Amoxi/clav + genta"< / span > < span class = "op" > =< / span > < span class = "fu" > < a href = "../reference/proportion.html" > susceptibility< / a > < / span > < span class = "op" > (< / span > < span class = "va" > AMC< / span > , < span class = "va" > GEN< / span > < span class = "op" > )< / span > < / span >
< span > < span class = "op" > )< / span > < span class = "op" > < a href = "https://magrittr.tidyverse.org/reference/pipe.html" class = "external-link" > %> %< / a > < / span > < / span >
2022-08-21 16:59:35 +02:00
< span > < span class = "co" > # pivot_longer() from the tidyr package "lengthens" data:< / span > < / span >
2022-08-28 22:45:38 +02:00
< span > < span class = "fu" > tidyr< / span > < span class = "fu" > ::< / span > < span class = "fu" > < a href = "https://tidyr.tidyverse.org/reference/pivot_longer.html" class = "external-link" > pivot_longer< / a > < / span > < span class = "op" > (< / span > < span class = "op" > -< / span > < span class = "va" > genus< / span > , names_to < span class = "op" > =< / span > < span class = "st" > "antibiotic"< / span > < span class = "op" > )< / span > < span class = "op" > < a href = "https://magrittr.tidyverse.org/reference/pipe.html" class = "external-link" > %> %< / a > < / span > < / span >
< span > < span class = "fu" > < a href = "https://ggplot2.tidyverse.org/reference/ggplot.html" class = "external-link" > ggplot< / a > < / span > < span class = "op" > (< / span > < span class = "fu" > < a href = "https://ggplot2.tidyverse.org/reference/aes.html" class = "external-link" > aes< / a > < / span > < span class = "op" > (< / span > < / span >
< span > x < span class = "op" > =< / span > < span class = "va" > genus< / span > ,< / span >
< span > y < span class = "op" > =< / span > < span class = "va" > value< / span > ,< / span >
< span > fill < span class = "op" > =< / span > < span class = "va" > antibiotic< / span > < / span >
< span > < span class = "op" > )< / span > < span class = "op" > )< / span > < span class = "op" > +< / span > < / span >
2022-08-21 16:59:35 +02:00
< span > < span class = "fu" > < a href = "https://ggplot2.tidyverse.org/reference/geom_bar.html" class = "external-link" > geom_col< / a > < / span > < span class = "op" > (< / span > position < span class = "op" > =< / span > < span class = "st" > "dodge2"< / span > < span class = "op" > )< / span > < / span > < / code > < / pre > < / div >
< p > < img src = "AMR_files/figure-html/plot%201-1.png" width = "720" > < / p >
< / div >
< div class = "section level3" >
< h3 id = "plots" > Plots< a class = "anchor" aria-label = "anchor" href = "#plots" > < / a >
< / h3 >
2022-10-29 14:24:08 +02:00
< p > To show results in plots, most R users would nowadays use the
< code > ggplot2< / code > package. This package lets you create plots in
layers. You can read more about it < a href = "https://ggplot2.tidyverse.org/" class = "external-link" > on their website< / a > . A quick
example would look like these syntaxes:< / p >
2022-11-24 20:37:19 +01:00
< div class = "sourceCode" id = "cb31" > < pre class = "downlit sourceCode r" >
2022-08-28 22:45:38 +02:00
< code class = "sourceCode R" > < span > < span class = "fu" > < a href = "https://ggplot2.tidyverse.org/reference/ggplot.html" class = "external-link" > ggplot< / a > < / span > < span class = "op" > (< / span > < / span >
< span > data < span class = "op" > =< / span > < span class = "va" > a_data_set< / span > ,< / span >
< span > mapping < span class = "op" > =< / span > < span class = "fu" > < a href = "https://ggplot2.tidyverse.org/reference/aes.html" class = "external-link" > aes< / a > < / span > < span class = "op" > (< / span > < / span >
< span > x < span class = "op" > =< / span > < span class = "va" > year< / span > ,< / span >
< span > y < span class = "op" > =< / span > < span class = "va" > value< / span > < / span >
< span > < span class = "op" > )< / span > < / span >
< span > < span class = "op" > )< / span > < span class = "op" > +< / span > < / span >
2022-08-21 16:59:35 +02:00
< span > < span class = "fu" > < a href = "https://ggplot2.tidyverse.org/reference/geom_bar.html" class = "external-link" > geom_col< / a > < / span > < span class = "op" > (< / span > < span class = "op" > )< / span > < span class = "op" > +< / span > < / span >
2022-08-28 22:45:38 +02:00
< span > < span class = "fu" > < a href = "https://ggplot2.tidyverse.org/reference/labs.html" class = "external-link" > labs< / a > < / span > < span class = "op" > (< / span > < / span >
< span > title < span class = "op" > =< / span > < span class = "st" > "A title"< / span > ,< / span >
< span > subtitle < span class = "op" > =< / span > < span class = "st" > "A subtitle"< / span > ,< / span >
< span > x < span class = "op" > =< / span > < span class = "st" > "My X axis"< / span > ,< / span >
< span > y < span class = "op" > =< / span > < span class = "st" > "My Y axis"< / span > < / span >
< span > < span class = "op" > )< / span > < / span >
2022-08-21 16:59:35 +02:00
< span > < / span >
< span > < span class = "co" > # or as short as:< / span > < / span >
< span > < span class = "fu" > < a href = "https://ggplot2.tidyverse.org/reference/ggplot.html" class = "external-link" > ggplot< / a > < / span > < span class = "op" > (< / span > < span class = "va" > a_data_set< / span > < span class = "op" > )< / span > < span class = "op" > +< / span > < / span >
< span > < span class = "fu" > < a href = "https://ggplot2.tidyverse.org/reference/geom_bar.html" class = "external-link" > geom_bar< / a > < / span > < span class = "op" > (< / span > < span class = "fu" > < a href = "https://ggplot2.tidyverse.org/reference/aes.html" class = "external-link" > aes< / a > < / span > < span class = "op" > (< / span > < span class = "va" > year< / span > < span class = "op" > )< / span > < span class = "op" > )< / span > < / span > < / code > < / pre > < / div >
2022-10-29 14:24:08 +02:00
< p > The < code > AMR< / code > package contains functions to extend this
< code > ggplot2< / code > package, for example < code > < a href = "../reference/ggplot_rsi.html" > geom_rsi()< / a > < / code > . It
automatically transforms data with < code > < a href = "../reference/count.html" > count_df()< / a > < / code > or
< code > < a href = "../reference/proportion.html" > proportion_df()< / a > < / code > and show results in stacked bars. Its
simplest and shortest example:< / p >
2022-11-24 20:37:19 +01:00
< div class = "sourceCode" id = "cb32" > < pre class = "downlit sourceCode r" >
2022-08-21 16:59:35 +02:00
< code class = "sourceCode R" > < span > < span class = "fu" > < a href = "https://ggplot2.tidyverse.org/reference/ggplot.html" class = "external-link" > ggplot< / a > < / span > < span class = "op" > (< / span > < span class = "va" > data_1st< / span > < span class = "op" > )< / span > < span class = "op" > +< / span > < / span >
< span > < span class = "fu" > < a href = "../reference/ggplot_rsi.html" > geom_rsi< / a > < / span > < span class = "op" > (< / span > translate_ab < span class = "op" > =< / span > < span class = "cn" > FALSE< / span > < span class = "op" > )< / span > < / span > < / code > < / pre > < / div >
< p > < img src = "AMR_files/figure-html/plot%203-1.png" width = "720" > < / p >
2022-10-29 14:24:08 +02:00
< p > Omit the < code > translate_ab = FALSE< / code > to have the antibiotic
codes (AMX, AMC, CIP, GEN) translated to official WHO names
(amoxicillin, amoxicillin/clavulanic acid, ciprofloxacin,
gentamicin).< / p >
< p > If we group on e.g. the < code > genus< / code > column and add some
additional functions from our package, we can create this:< / p >
2022-11-24 20:37:19 +01:00
< div class = "sourceCode" id = "cb33" > < pre class = "downlit sourceCode r" >
2022-08-21 16:59:35 +02:00
< code class = "sourceCode R" > < span > < span class = "co" > # group the data on `genus`< / span > < / span >
2022-08-28 22:45:38 +02:00
< span > < span class = "fu" > < a href = "https://ggplot2.tidyverse.org/reference/ggplot.html" class = "external-link" > ggplot< / a > < / span > < span class = "op" > (< / span > < span class = "va" > data_1st< / span > < span class = "op" > < a href = "https://magrittr.tidyverse.org/reference/pipe.html" class = "external-link" > %> %< / a > < / span > < span class = "fu" > < a href = "https://dplyr.tidyverse.org/reference/group_by.html" class = "external-link" > group_by< / a > < / span > < span class = "op" > (< / span > < span class = "va" > genus< / span > < span class = "op" > )< / span > < span class = "op" > )< / span > < span class = "op" > +< / span > < / span >
2022-08-21 16:59:35 +02:00
< span > < span class = "co" > # create bars with genus on x axis< / span > < / span >
< span > < span class = "co" > # it looks for variables with class `rsi`,< / span > < / span >
< span > < span class = "co" > # of which we have 4 (earlier created with `as.rsi`)< / span > < / span >
2022-08-28 22:45:38 +02:00
< span > < span class = "fu" > < a href = "../reference/ggplot_rsi.html" > geom_rsi< / a > < / span > < span class = "op" > (< / span > x < span class = "op" > =< / span > < span class = "st" > "genus"< / span > < span class = "op" > )< / span > < span class = "op" > +< / span > < / span >
2022-08-21 16:59:35 +02:00
< span > < span class = "co" > # split plots on antibiotic< / span > < / span >
< span > < span class = "fu" > < a href = "../reference/ggplot_rsi.html" > facet_rsi< / a > < / span > < span class = "op" > (< / span > facet < span class = "op" > =< / span > < span class = "st" > "antibiotic"< / span > < span class = "op" > )< / span > < span class = "op" > +< / span > < / span >
< span > < span class = "co" > # set colours to the R/SI interpretations (colour-blind friendly)< / span > < / span >
< span > < span class = "fu" > < a href = "../reference/ggplot_rsi.html" > scale_rsi_colours< / a > < / span > < span class = "op" > (< / span > < span class = "op" > )< / span > < span class = "op" > +< / span > < / span >
< span > < span class = "co" > # show percentages on y axis< / span > < / span >
< span > < span class = "fu" > < a href = "../reference/ggplot_rsi.html" > scale_y_percent< / a > < / span > < span class = "op" > (< / span > breaks < span class = "op" > =< / span > < span class = "fl" > 0< / span > < span class = "op" > :< / span > < span class = "fl" > 4< / span > < span class = "op" > *< / span > < span class = "fl" > 25< / span > < span class = "op" > )< / span > < span class = "op" > +< / span > < / span >
< span > < span class = "co" > # turn 90 degrees, to make it bars instead of columns< / span > < / span >
< span > < span class = "fu" > < a href = "https://ggplot2.tidyverse.org/reference/coord_flip.html" class = "external-link" > coord_flip< / a > < / span > < span class = "op" > (< / span > < span class = "op" > )< / span > < span class = "op" > +< / span > < / span >
< span > < span class = "co" > # add labels< / span > < / span >
2022-08-28 22:45:38 +02:00
< span > < span class = "fu" > < a href = "https://ggplot2.tidyverse.org/reference/labs.html" class = "external-link" > labs< / a > < / span > < span class = "op" > (< / span > < / span >
< span > title < span class = "op" > =< / span > < span class = "st" > "Resistance per genus and antibiotic"< / span > ,< / span >
< span > subtitle < span class = "op" > =< / span > < span class = "st" > "(this is fake data)"< / span > < / span >
< span > < span class = "op" > )< / span > < span class = "op" > +< / span > < / span >
2022-08-21 16:59:35 +02:00
< span > < span class = "co" > # and print genus in italic to follow our convention< / span > < / span >
< span > < span class = "co" > # (is now y axis because we turned the plot)< / span > < / span >
< span > < span class = "fu" > < a href = "https://ggplot2.tidyverse.org/reference/theme.html" class = "external-link" > theme< / a > < / span > < span class = "op" > (< / span > axis.text.y < span class = "op" > =< / span > < span class = "fu" > < a href = "https://ggplot2.tidyverse.org/reference/element.html" class = "external-link" > element_text< / a > < / span > < span class = "op" > (< / span > face < span class = "op" > =< / span > < span class = "st" > "italic"< / span > < span class = "op" > )< / span > < span class = "op" > )< / span > < / span > < / code > < / pre > < / div >
< p > < img src = "AMR_files/figure-html/plot%204-1.png" width = "720" > < / p >
2022-10-29 14:24:08 +02:00
< p > To simplify this, we also created the < code > < a href = "../reference/ggplot_rsi.html" > ggplot_rsi()< / a > < / code >
function, which combines almost all above functions:< / p >
2022-11-24 20:37:19 +01:00
< div class = "sourceCode" id = "cb34" > < pre class = "downlit sourceCode r" >
2022-08-28 22:45:38 +02:00
< code class = "sourceCode R" > < span > < span class = "va" > data_1st< / span > < span class = "op" > < a href = "https://magrittr.tidyverse.org/reference/pipe.html" class = "external-link" > %> %< / a > < / span > < / span >
2022-08-21 16:59:35 +02:00
< span > < span class = "fu" > < a href = "https://dplyr.tidyverse.org/reference/group_by.html" class = "external-link" > group_by< / a > < / span > < span class = "op" > (< / span > < span class = "va" > genus< / span > < span class = "op" > )< / span > < span class = "op" > < a href = "https://magrittr.tidyverse.org/reference/pipe.html" class = "external-link" > %> %< / a > < / span > < / span >
2022-08-28 22:45:38 +02:00
< span > < span class = "fu" > < a href = "../reference/ggplot_rsi.html" > ggplot_rsi< / a > < / span > < span class = "op" > (< / span > < / span >
< span > x < span class = "op" > =< / span > < span class = "st" > "genus"< / span > ,< / span >
< span > facet < span class = "op" > =< / span > < span class = "st" > "antibiotic"< / span > ,< / span >
< span > breaks < span class = "op" > =< / span > < span class = "fl" > 0< / span > < span class = "op" > :< / span > < span class = "fl" > 4< / span > < span class = "op" > *< / span > < span class = "fl" > 25< / span > ,< / span >
< span > datalabels < span class = "op" > =< / span > < span class = "cn" > FALSE< / span > < / span >
< span > < span class = "op" > )< / span > < span class = "op" > +< / span > < / span >
2022-08-21 16:59:35 +02:00
< span > < span class = "fu" > < a href = "https://ggplot2.tidyverse.org/reference/coord_flip.html" class = "external-link" > coord_flip< / a > < / span > < span class = "op" > (< / span > < span class = "op" > )< / span > < / span > < / code > < / pre > < / div >
< p > < img src = "AMR_files/figure-html/plot%205-1.png" width = "720" > < / p >
< div class = "section level4" >
< h4 id = "plotting-mic-and-disk-diffusion-values" > Plotting MIC and disk diffusion values< a class = "anchor" aria-label = "anchor" href = "#plotting-mic-and-disk-diffusion-values" > < / a >
< / h4 >
2022-10-29 14:24:08 +02:00
< p > The AMR package also extends the < code > < a href = "../reference/plot.html" > plot()< / a > < / code > and
< code > < a href = "https://ggplot2.tidyverse.org/reference/autoplot.html" class = "external-link" > ggplot2::autoplot()< / a > < / code > functions for plotting minimum
inhibitory concentrations (MIC, created with < code > < a href = "../reference/as.mic.html" > as.mic()< / a > < / code > ) and
disk diffusion diameters (created with < code > < a href = "../reference/as.disk.html" > as.disk()< / a > < / code > ).< / p >
< p > With the < code > < a href = "../reference/random.html" > random_mic()< / a > < / code > and < code > < a href = "../reference/random.html" > random_disk()< / a > < / code >
functions, we can generate sampled values for the new data types (S3
classes) < code > < mic> < / code > and < code > < disk> < / code > :< / p >
2022-11-24 20:37:19 +01:00
< div class = "sourceCode" id = "cb35" > < pre class = "downlit sourceCode r" >
2022-08-21 16:59:35 +02:00
< code class = "sourceCode R" > < span > < span class = "va" > mic_values< / span > < span class = "op" > < -< / span > < span class = "fu" > < a href = "../reference/random.html" > random_mic< / a > < / span > < span class = "op" > (< / span > size < span class = "op" > =< / span > < span class = "fl" > 100< / span > < span class = "op" > )< / span > < / span >
< span > < span class = "va" > mic_values< / span > < / span >
2022-10-19 11:58:58 +02:00
< span > < span class = "co" > # Class 'mic'< / span > < / span >
2023-01-07 02:01:36 +01:00
< span > < span class = "co" > # [1] 8 0.01 0.01 0.025 128 64 2 0.025 0.0625 0.005 < / span > < / span >
< span > < span class = "co" > # [11] 0.001 0.0625 1 0.002 0.5 0.25 64 0.025 256 128 < / span > < / span >
< span > < span class = "co" > # [21] 0.001 0.005 1 0.125 256 8 0.001 0.25 0.0625 1 < / span > < / span >
< span > < span class = "co" > # [31] 4 0.005 0.5 0.0625 0.002 2 0.0625 0.005 0.005 0.25 < / span > < / span >
< span > < span class = "co" > # [41] 32 0.01 0.01 2 128 16 0.25 8 4 0.025 < / span > < / span >
< span > < span class = "co" > # [51] 32 256 0.0625 128 128 0.001 0.5 0.5 0.125 64 < / span > < / span >
< span > < span class = "co" > # [61] 0.25 8 0.0625 0.001 1 2 256 0.005 4 16 < / span > < / span >
< span > < span class = "co" > # [71] 0.125 0.002 256 64 0.01 8 0.5 0.5 64 1 < / span > < / span >
< span > < span class = "co" > # [81] 0.5 32 4 1 2 0.025 0.0625 0.25 0.005 16 < / span > < / span >
< span > < span class = "co" > # [91] 0.0625 0.002 8 0.001 0.125 0.125 128 64 0.125 64< / span > < / span > < / code > < / pre > < / div >
2022-11-24 20:37:19 +01:00
< div class = "sourceCode" id = "cb36" > < pre class = "downlit sourceCode r" >
2022-08-21 16:59:35 +02:00
< code class = "sourceCode R" > < span > < span class = "co" > # base R:< / span > < / span >
< span > < span class = "fu" > < a href = "../reference/plot.html" > plot< / a > < / span > < span class = "op" > (< / span > < span class = "va" > mic_values< / span > < span class = "op" > )< / span > < / span > < / code > < / pre > < / div >
< p > < img src = "AMR_files/figure-html/mic_plots-1.png" width = "720" > < / p >
2022-11-24 20:37:19 +01:00
< div class = "sourceCode" id = "cb37" > < pre class = "downlit sourceCode r" >
2022-08-21 16:59:35 +02:00
< code class = "sourceCode R" > < span > < span class = "co" > # ggplot2:< / span > < / span >
< span > < span class = "fu" > < a href = "https://ggplot2.tidyverse.org/reference/autoplot.html" class = "external-link" > autoplot< / a > < / span > < span class = "op" > (< / span > < span class = "va" > mic_values< / span > < span class = "op" > )< / span > < / span > < / code > < / pre > < / div >
< p > < img src = "AMR_files/figure-html/mic_plots-2.png" width = "720" > < / p >
2022-10-29 14:24:08 +02:00
< p > But we could also be more specific, by generating MICs that are
likely to be found in < em > E. coli< / em > for ciprofloxacin:< / p >
2022-11-24 20:37:19 +01:00
< div class = "sourceCode" id = "cb38" > < pre class = "downlit sourceCode r" >
2022-08-21 16:59:35 +02:00
< code class = "sourceCode R" > < span > < span class = "va" > mic_values< / span > < span class = "op" > < -< / span > < span class = "fu" > < a href = "../reference/random.html" > random_mic< / a > < / span > < span class = "op" > (< / span > size < span class = "op" > =< / span > < span class = "fl" > 100< / span > , mo < span class = "op" > =< / span > < span class = "st" > "E. coli"< / span > , ab < span class = "op" > =< / span > < span class = "st" > "cipro"< / span > < span class = "op" > )< / span > < / span > < / code > < / pre > < / div >
2022-10-29 14:24:08 +02:00
< p > For the < code > < a href = "../reference/plot.html" > plot()< / a > < / code > and < code > < a href = "https://ggplot2.tidyverse.org/reference/autoplot.html" class = "external-link" > autoplot()< / a > < / code > function, we
can define the microorganism and an antimicrobial agent the same way.
This will add the interpretation of those values according to a chosen
guidelines (defaults to the latest EUCAST guideline).< / p >
< p > Default colours are colour-blind friendly, while maintaining the
convention that e.g. ‘ susceptible’ should be green and ‘ resistant’
should be red:< / p >
2022-11-24 20:37:19 +01:00
< div class = "sourceCode" id = "cb39" > < pre class = "downlit sourceCode r" >
2022-08-21 16:59:35 +02:00
< code class = "sourceCode R" > < span > < span class = "co" > # base R:< / span > < / span >
< span > < span class = "fu" > < a href = "../reference/plot.html" > plot< / a > < / span > < span class = "op" > (< / span > < span class = "va" > mic_values< / span > , mo < span class = "op" > =< / span > < span class = "st" > "E. coli"< / span > , ab < span class = "op" > =< / span > < span class = "st" > "cipro"< / span > < span class = "op" > )< / span > < / span > < / code > < / pre > < / div >
< p > < img src = "AMR_files/figure-html/mic_plots_mo_ab-1.png" width = "720" > < / p >
2022-11-24 20:37:19 +01:00
< div class = "sourceCode" id = "cb40" > < pre class = "downlit sourceCode r" >
2022-08-21 16:59:35 +02:00
< code class = "sourceCode R" > < span > < span class = "co" > # ggplot2:< / span > < / span >
< span > < span class = "fu" > < a href = "https://ggplot2.tidyverse.org/reference/autoplot.html" class = "external-link" > autoplot< / a > < / span > < span class = "op" > (< / span > < span class = "va" > mic_values< / span > , mo < span class = "op" > =< / span > < span class = "st" > "E. coli"< / span > , ab < span class = "op" > =< / span > < span class = "st" > "cipro"< / span > < span class = "op" > )< / span > < / span > < / code > < / pre > < / div >
< p > < img src = "AMR_files/figure-html/mic_plots_mo_ab-2.png" width = "720" > < / p >
2022-10-29 14:24:08 +02:00
< p > For disk diffusion values, there is not much of a difference in
plotting:< / p >
2022-11-24 20:37:19 +01:00
< div class = "sourceCode" id = "cb41" > < pre class = "downlit sourceCode r" >
2022-08-21 16:59:35 +02:00
< code class = "sourceCode R" > < span > < span class = "va" > disk_values< / span > < span class = "op" > < -< / span > < span class = "fu" > < a href = "../reference/random.html" > random_disk< / a > < / span > < span class = "op" > (< / span > size < span class = "op" > =< / span > < span class = "fl" > 100< / span > , mo < span class = "op" > =< / span > < span class = "st" > "E. coli"< / span > , ab < span class = "op" > =< / span > < span class = "st" > "cipro"< / span > < span class = "op" > )< / span > < / span >
< span > < span class = "va" > disk_values< / span > < / span >
2022-10-19 11:58:58 +02:00
< span > < span class = "co" > # Class 'disk'< / span > < / span >
2023-01-07 02:01:36 +01:00
< span > < span class = "co" > # [1] 26 30 22 29 29 24 23 31 22 19 29 24 22 30 20 18 26 25 18 23 23 25 31 24 25< / span > < / span >
< span > < span class = "co" > # [26] 18 30 22 31 24 22 22 25 22 17 22 24 25 28 19 21 21 21 22 18 31 25 22 25 30< / span > < / span >
< span > < span class = "co" > # [51] 25 31 23 21 17 19 31 23 19 20 28 22 26 25 25 24 20 24 25 19 27 28 21 26 23< / span > < / span >
< span > < span class = "co" > # [76] 17 22 23 30 20 20 18 18 22 19 29 31 18 26 20 28 27 24 27 21 17 25 30 22 22< / span > < / span > < / code > < / pre > < / div >
2022-11-24 20:37:19 +01:00
< div class = "sourceCode" id = "cb42" > < pre class = "downlit sourceCode r" >
2022-08-21 16:59:35 +02:00
< code class = "sourceCode R" > < span > < span class = "co" > # base R:< / span > < / span >
< span > < span class = "fu" > < a href = "../reference/plot.html" > plot< / a > < / span > < span class = "op" > (< / span > < span class = "va" > disk_values< / span > , mo < span class = "op" > =< / span > < span class = "st" > "E. coli"< / span > , ab < span class = "op" > =< / span > < span class = "st" > "cipro"< / span > < span class = "op" > )< / span > < / span > < / code > < / pre > < / div >
< p > < img src = "AMR_files/figure-html/disk_plots-1.png" width = "720" > < / p >
2022-10-29 14:24:08 +02:00
< p > And when using the < code > ggplot2< / code > package, but now choosing the
latest implemented CLSI guideline (notice that the EUCAST-specific term
“Susceptible, incr. exp.” has changed to “Intermediate”):< / p >
2022-11-24 20:37:19 +01:00
< div class = "sourceCode" id = "cb43" > < pre class = "downlit sourceCode r" >
2022-08-28 22:45:38 +02:00
< code class = "sourceCode R" > < span > < span class = "fu" > < a href = "https://ggplot2.tidyverse.org/reference/autoplot.html" class = "external-link" > autoplot< / a > < / span > < span class = "op" > (< / span > < / span >
< span > < span class = "va" > disk_values< / span > ,< / span >
< span > mo < span class = "op" > =< / span > < span class = "st" > "E. coli"< / span > ,< / span >
< span > ab < span class = "op" > =< / span > < span class = "st" > "cipro"< / span > ,< / span >
< span > guideline < span class = "op" > =< / span > < span class = "st" > "CLSI"< / span > < / span >
< span > < span class = "op" > )< / span > < / span > < / code > < / pre > < / div >
2022-08-21 16:59:35 +02:00
< p > < img src = "AMR_files/figure-html/disk_plots_mo_ab-1.png" width = "720" > < / p >
< / div >
< / div >
< div class = "section level3" >
< h3 id = "independence-test" > Independence test< a class = "anchor" aria-label = "anchor" href = "#independence-test" > < / a >
< / h3 >
2022-10-29 14:24:08 +02:00
< p > The next example uses the < code > example_isolates< / code > data set.
This is a data set included with this package and contains 2,000
microbial isolates with their full antibiograms. It reflects reality and
can be used to practise AMR data analysis.< / p >
< p > We will compare the resistance to amoxicillin/clavulanic acid (column
< code > FOS< / code > ) between an ICU and other clinical wards. The input for
the < code > < a href = "https://rdrr.io/r/stats/fisher.test.html" class = "external-link" > fisher.test()< / a > < / code > can be retrieved with a transformation
like this:< / p >
2022-11-24 20:37:19 +01:00
< div class = "sourceCode" id = "cb44" > < pre class = "downlit sourceCode r" >
2022-08-21 16:59:35 +02:00
< code class = "sourceCode R" > < span > < span class = "co" > # use package 'tidyr' to pivot data:< / span > < / span >
< span > < span class = "kw" > < a href = "https://rdrr.io/r/base/library.html" class = "external-link" > library< / a > < / span > < span class = "op" > (< / span > < span class = "va" > < a href = "https://tidyr.tidyverse.org" class = "external-link" > tidyr< / a > < / span > < span class = "op" > )< / span > < / span >
< span > < / span >
< span > < span class = "va" > check_FOS< / span > < span class = "op" > < -< / span > < span class = "va" > example_isolates< / span > < span class = "op" > < a href = "https://magrittr.tidyverse.org/reference/pipe.html" class = "external-link" > %> %< / a > < / span > < / span >
2022-08-28 22:45:38 +02:00
< span > < span class = "fu" > < a href = "https://dplyr.tidyverse.org/reference/filter.html" class = "external-link" > filter< / a > < / span > < span class = "op" > (< / span > < span class = "va" > ward< / span > < span class = "op" > < a href = "https://rdrr.io/r/base/match.html" class = "external-link" > %in%< / a > < / span > < span class = "fu" > < a href = "https://rdrr.io/r/base/c.html" class = "external-link" > c< / a > < / span > < span class = "op" > (< / span > < span class = "st" > "ICU"< / span > , < span class = "st" > "Clinical"< / span > < span class = "op" > )< / span > < span class = "op" > )< / span > < span class = "op" > < a href = "https://magrittr.tidyverse.org/reference/pipe.html" class = "external-link" > %> %< / a > < / span > < span class = "co" > # filter on only these wards< / span > < / span >
< span > < span class = "fu" > < a href = "https://dplyr.tidyverse.org/reference/select.html" class = "external-link" > select< / a > < / span > < span class = "op" > (< / span > < span class = "va" > ward< / span > , < span class = "va" > AMC< / span > < span class = "op" > )< / span > < span class = "op" > < a href = "https://magrittr.tidyverse.org/reference/pipe.html" class = "external-link" > %> %< / a > < / span > < span class = "co" > # select the wards and amoxi/clav< / span > < / span >
< span > < span class = "fu" > < a href = "https://dplyr.tidyverse.org/reference/group_by.html" class = "external-link" > group_by< / a > < / span > < span class = "op" > (< / span > < span class = "va" > ward< / span > < span class = "op" > )< / span > < span class = "op" > < a href = "https://magrittr.tidyverse.org/reference/pipe.html" class = "external-link" > %> %< / a > < / span > < span class = "co" > # group on the wards< / span > < / span >
< span > < span class = "fu" > < a href = "../reference/count.html" > count_df< / a > < / span > < span class = "op" > (< / span > combine_SI < span class = "op" > =< / span > < span class = "cn" > TRUE< / span > < span class = "op" > )< / span > < span class = "op" > < a href = "https://magrittr.tidyverse.org/reference/pipe.html" class = "external-link" > %> %< / a > < / span > < span class = "co" > # count all isolates per group (ward)< / span > < / span >
< span > < span class = "fu" > < a href = "https://tidyr.tidyverse.org/reference/pivot_wider.html" class = "external-link" > pivot_wider< / a > < / span > < span class = "op" > (< / span > < / span >
< span > names_from < span class = "op" > =< / span > < span class = "va" > ward< / span > , < span class = "co" > # transform output so "ICU" and "Clinical" are columns< / span > < / span >
< span > values_from < span class = "op" > =< / span > < span class = "va" > value< / span > < / span >
< span > < span class = "op" > )< / span > < span class = "op" > < a href = "https://magrittr.tidyverse.org/reference/pipe.html" class = "external-link" > %> %< / a > < / span > < / span >
< span > < span class = "fu" > < a href = "https://dplyr.tidyverse.org/reference/select.html" class = "external-link" > select< / a > < / span > < span class = "op" > (< / span > < span class = "va" > ICU< / span > , < span class = "va" > Clinical< / span > < span class = "op" > )< / span > < span class = "op" > < a href = "https://magrittr.tidyverse.org/reference/pipe.html" class = "external-link" > %> %< / a > < / span > < span class = "co" > # and only select these columns< / span > < / span >
< span > < span class = "fu" > < a href = "https://rdrr.io/r/base/matrix.html" class = "external-link" > as.matrix< / a > < / span > < span class = "op" > (< / span > < span class = "op" > )< / span > < span class = "co" > # transform to a good old matrix for fisher.test()< / span > < / span >
2022-08-21 16:59:35 +02:00
< span > < / span >
< span > < span class = "va" > check_FOS< / span > < / span >
2022-08-28 22:45:38 +02:00
< span > < span class = "co" > # ICU Clinical< / span > < / span >
< span > < span class = "co" > # [1,] 396 942< / span > < / span >
< span > < span class = "co" > # [2,] 184 240< / span > < / span > < / code > < / pre > < / div >
2022-08-21 16:59:35 +02:00
< p > We can apply the test now with:< / p >
2022-11-24 20:37:19 +01:00
< div class = "sourceCode" id = "cb45" > < pre class = "downlit sourceCode r" >
2022-08-21 16:59:35 +02:00
< code class = "sourceCode R" > < span > < span class = "co" > # do Fisher's Exact Test< / span > < / span >
2022-08-28 22:45:38 +02:00
< span > < span class = "fu" > < a href = "https://rdrr.io/r/stats/fisher.test.html" class = "external-link" > fisher.test< / a > < / span > < span class = "op" > (< / span > < span class = "va" > check_FOS< / span > < span class = "op" > )< / span > < / span >
2022-08-21 16:59:35 +02:00
< span > < span class = "co" > # < / span > < / span >
< span > < span class = "co" > # Fisher's Exact Test for Count Data< / span > < / span >
< span > < span class = "co" > # < / span > < / span >
< span > < span class = "co" > # data: check_FOS< / span > < / span >
2022-08-28 22:45:38 +02:00
< span > < span class = "co" > # p-value = 2.263e-07< / span > < / span >
2022-08-21 16:59:35 +02:00
< span > < span class = "co" > # alternative hypothesis: true odds ratio is not equal to 1< / span > < / span >
< span > < span class = "co" > # 95 percent confidence interval:< / span > < / span >
2022-08-28 22:45:38 +02:00
< span > < span class = "co" > # 0.435261 0.691614< / span > < / span >
2022-08-21 16:59:35 +02:00
< span > < span class = "co" > # sample estimates:< / span > < / span >
< span > < span class = "co" > # odds ratio < / span > < / span >
2022-08-28 22:45:38 +02:00
< span > < span class = "co" > # 0.5485079< / span > < / span > < / code > < / pre > < / div >
2022-10-29 14:24:08 +02:00
< p > As can be seen, the p value is practically zero (0.0000002263247),
which means that the amoxicillin/clavulanic acid resistance found in
isolates between patients in ICUs and other clinical wards are really
different.< / p >
2022-08-21 16:59:35 +02:00
< / div >
< / div >
< / main > < aside class = "col-md-3" > < nav id = "toc" > < h2 > On this page< / h2 >
< / nav > < / aside >
< / div >
< footer > < div class = "pkgdown-footer-left" >
< p > < / p >
2022-12-11 11:50:34 +01:00
< p > < code > AMR< / code > (for R). Free and open-source, licenced under the < a target = "_blank" href = "https://github.com/msberends/AMR/blob/main/LICENSE" class = "external-link" > GNU General Public License version 2.0 (GPL-2)< / a > .< br > Developed at the < a target = "_blank" href = "https://www.rug.nl" class = "external-link" > University of Groningen< / a > and < a target = "_blank" href = "https://www.umcg.nl" class = "external-link" > University Medical Center Groningen< / a > in The Netherlands.< / p >
2022-08-21 16:59:35 +02:00
< / div >
< div class = "pkgdown-footer-right" >
< p > < / p >
2022-12-11 11:50:34 +01:00
< p > < a target = "_blank" href = "https://www.rug.nl" class = "external-link" > < img src = "https://github.com/msberends/AMR/raw/main/pkgdown/logos/logo_rug.svg" style = "max-width: 150px;" > < / a > < a target = "_blank" href = "https://www.umcg.nl" class = "external-link" > < img src = "https://github.com/msberends/AMR/raw/main/pkgdown/logos/logo_umcg.svg" style = "max-width: 150px;" > < / a > < / p >
2022-08-21 16:59:35 +02:00
< / div >
< / footer >
< / div >
< / body >
< / html >