mirror of https://github.com/msberends/AMR.git
1421 lines
75 KiB
HTML
1421 lines
75 KiB
HTML
<!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.0">
|
||
<title>How to conduct AMR 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">
|
||
<!-- jquery --><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script><!-- Bootstrap --><link href="https://cdnjs.cloudflare.com/ajax/libs/bootswatch/3.4.0/flatly/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous">
|
||
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha256-nuL8/2cJ5NDSSwnKD8VqreErSWHtnEP9E7AySL+1ev4=" crossorigin="anonymous"></script><!-- bootstrap-toc --><link rel="stylesheet" href="../bootstrap-toc.css">
|
||
<script src="../bootstrap-toc.js"></script><!-- 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">
|
||
<!-- 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><!-- 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><!-- pkgdown --><link href="../pkgdown.css" rel="stylesheet">
|
||
<script src="../pkgdown.js"></script><link href="../extra.css" rel="stylesheet">
|
||
<script src="../extra.js"></script><meta property="og:title" content="How to conduct AMR analysis">
|
||
<meta property="og:description" content="AMR">
|
||
<meta property="og:image" content="https://msberends.github.io/AMR/logo.svg">
|
||
<!-- 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 data-spy="scroll" data-target="#toc">
|
||
<div class="container template-article">
|
||
<header><div class="navbar navbar-default navbar-fixed-top" role="navigation">
|
||
<div class="container">
|
||
<div class="navbar-header">
|
||
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false">
|
||
<span class="sr-only">Toggle navigation</span>
|
||
<span class="icon-bar"></span>
|
||
<span class="icon-bar"></span>
|
||
<span class="icon-bar"></span>
|
||
</button>
|
||
<span class="navbar-brand">
|
||
<a class="navbar-link" href="../index.html">AMR (for R)</a>
|
||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.3.0.9006</span>
|
||
</span>
|
||
</div>
|
||
|
||
<div id="navbar" class="navbar-collapse collapse">
|
||
<ul class="nav navbar-nav">
|
||
<li>
|
||
<a href="../index.html">
|
||
<span class="fa fa-home"></span>
|
||
|
||
Home
|
||
</a>
|
||
</li>
|
||
<li class="dropdown">
|
||
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
|
||
<span class="fa fa-question-circle"></span>
|
||
|
||
How to
|
||
|
||
<span class="caret"></span>
|
||
</a>
|
||
<ul class="dropdown-menu" role="menu">
|
||
<li>
|
||
<a href="../articles/AMR.html">
|
||
<span class="fa fa-directions"></span>
|
||
|
||
Conduct AMR analysis
|
||
</a>
|
||
</li>
|
||
<li>
|
||
<a href="../articles/resistance_predict.html">
|
||
<span class="fa fa-dice"></span>
|
||
|
||
Predict antimicrobial resistance
|
||
</a>
|
||
</li>
|
||
<li>
|
||
<a href="../articles/datasets.html">
|
||
<span class="fa fa-database"></span>
|
||
|
||
Download our reference data sets for own use
|
||
</a>
|
||
</li>
|
||
<li>
|
||
<a href="../articles/PCA.html">
|
||
<span class="fa fa-compress"></span>
|
||
|
||
Conduct principal component analysis for AMR
|
||
</a>
|
||
</li>
|
||
<li>
|
||
<a href="../articles/MDR.html">
|
||
<span class="fa fa-skull-crossbones"></span>
|
||
|
||
Determine multi-drug resistance (MDR)
|
||
</a>
|
||
</li>
|
||
<li>
|
||
<a href="../articles/WHONET.html">
|
||
<span class="fa fa-globe-americas"></span>
|
||
|
||
Work with WHONET data
|
||
</a>
|
||
</li>
|
||
<li>
|
||
<a href="../articles/SPSS.html">
|
||
<span class="fa fa-file-upload"></span>
|
||
|
||
Import data from SPSS/SAS/Stata
|
||
</a>
|
||
</li>
|
||
<li>
|
||
<a href="../articles/EUCAST.html">
|
||
<span class="fa fa-exchange-alt"></span>
|
||
|
||
Apply EUCAST rules
|
||
</a>
|
||
</li>
|
||
<li>
|
||
<a href="../reference/mo_property.html">
|
||
<span class="fa fa-bug"></span>
|
||
|
||
Get properties of a microorganism
|
||
</a>
|
||
</li>
|
||
<li>
|
||
<a href="../reference/ab_property.html">
|
||
<span class="fa fa-capsules"></span>
|
||
|
||
Get properties of an antibiotic
|
||
</a>
|
||
</li>
|
||
<li>
|
||
<a href="../articles/benchmarks.html">
|
||
<span class="fa fa-shipping-fast"></span>
|
||
|
||
Other: benchmarks
|
||
</a>
|
||
</li>
|
||
</ul>
|
||
</li>
|
||
<li>
|
||
<a href="../reference/index.html">
|
||
<span class="fa fa-book-open"></span>
|
||
|
||
Manual
|
||
</a>
|
||
</li>
|
||
<li>
|
||
<a href="../authors.html">
|
||
<span class="fa fa-users"></span>
|
||
|
||
Authors
|
||
</a>
|
||
</li>
|
||
<li>
|
||
<a href="../news/index.html">
|
||
<span class="far fa far fa-newspaper"></span>
|
||
|
||
Changelog
|
||
</a>
|
||
</li>
|
||
</ul>
|
||
<ul class="nav navbar-nav navbar-right">
|
||
<li>
|
||
<a href="https://github.com/msberends/AMR">
|
||
<span class="fab fa fab fa-github"></span>
|
||
|
||
Source Code
|
||
</a>
|
||
</li>
|
||
<li>
|
||
<a href="../survey.html">
|
||
<span class="fa fa-clipboard-list"></span>
|
||
|
||
Survey
|
||
</a>
|
||
</li>
|
||
</ul>
|
||
</div>
|
||
<!--/.nav-collapse -->
|
||
</div>
|
||
<!--/.container -->
|
||
</div>
|
||
<!--/.navbar -->
|
||
|
||
|
||
|
||
</header><script src="AMR_files/accessible-code-block-0.0.1/empty-anchor.js"></script><div class="row">
|
||
<div class="col-md-9 contents">
|
||
<div class="page-header toc-ignore">
|
||
<h1 data-toc-skip>How to conduct AMR analysis</h1>
|
||
<h4 class="author">Matthijs S. Berends</h4>
|
||
|
||
<h4 class="date">21 August 2020</h4>
|
||
|
||
<small class="dont-index">Source: <a href="https://github.com/msberends/AMR/blob/master/vignettes/AMR.Rmd"><code>vignettes/AMR.Rmd</code></a></small>
|
||
<div class="hidden name"><code>AMR.Rmd</code></div>
|
||
|
||
</div>
|
||
|
||
|
||
|
||
<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/">R Markdown</a>. However, the methodology remains unchanged. This page was generated on 21 August 2020.</p>
|
||
<div id="introduction" class="section level1">
|
||
<h1 class="hasAnchor">
|
||
<a href="#introduction" class="anchor"></a>Introduction</h1>
|
||
<p>Conducting antimicrobial resistance analysis unfortunately requires in-depth knowledge from different scientific fields, which makes it hard to do right. At least, it requires:</p>
|
||
<ul>
|
||
<li>Good questions (always start with those!)</li>
|
||
<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>
|
||
</ul>
|
||
<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 antimicrobial resistance 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>
|
||
</div>
|
||
<div id="preparation" class="section level1">
|
||
<h1 class="hasAnchor">
|
||
<a href="#preparation" class="anchor"></a>Preparation</h1>
|
||
<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>
|
||
<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">
|
||
<td align="center">2020-08-21</td>
|
||
<td align="center">abcd</td>
|
||
<td align="center">Escherichia coli</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
</tr>
|
||
<tr class="even">
|
||
<td align="center">2020-08-21</td>
|
||
<td align="center">abcd</td>
|
||
<td align="center">Escherichia coli</td>
|
||
<td align="center">S</td>
|
||
<td align="center">R</td>
|
||
</tr>
|
||
<tr class="odd">
|
||
<td align="center">2020-08-21</td>
|
||
<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 id="needed-r-packages" class="section level2">
|
||
<h2 class="hasAnchor">
|
||
<a href="#needed-r-packages" class="anchor"></a>Needed R packages</h2>
|
||
<p>As with many uses in R, we need some additional packages for AMR analysis. Our package works closely together with the <a href="https://www.tidyverse.org">tidyverse packages</a> <a href="https://dplyr.tidyverse.org/"><code>dplyr</code></a> and <a href="https://ggplot2.tidyverse.org"><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>
|
||
<div class="sourceCode" id="cb1"><pre class="downlit">
|
||
<span class="fu"><a href="https://rdrr.io/r/base/library.html">library</a></span>(<span class="kw"><a href="https://dplyr.tidyverse.org">dplyr</a></span>)
|
||
<span class="fu"><a href="https://rdrr.io/r/base/library.html">library</a></span>(<span class="kw"><a href="http://ggplot2.tidyverse.org">ggplot2</a></span>)
|
||
<span class="fu"><a href="https://rdrr.io/r/base/library.html">library</a></span>(<span class="kw"><a href="https://msberends.github.io/AMR">AMR</a></span>)
|
||
<span class="fu"><a href="https://rdrr.io/r/base/library.html">library</a></span>(<span class="kw"><a href="https://github.com/msberends/cleaner">cleaner</a></span>)
|
||
|
||
<span class="co"># (if not yet installed, install with:)</span>
|
||
<span class="co"># install.packages(c("dplyr", "ggplot2", "AMR", "cleaner"))</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<div id="creation-of-data" class="section level1">
|
||
<h1 class="hasAnchor">
|
||
<a href="#creation-of-data" class="anchor"></a>Creation of data</h1>
|
||
<p>We will create some fake example data to use for analysis. For antimicrobial resistance 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>
|
||
<div id="patients" class="section level2">
|
||
<h2 class="hasAnchor">
|
||
<a href="#patients" class="anchor"></a>Patients</h2>
|
||
<p>To start with patients, we need a unique list of patients.</p>
|
||
<div class="sourceCode" id="cb2"><pre class="downlit">
|
||
<span class="kw">patients</span> <span class="op"><-</span> <span class="fu"><a href="https://rdrr.io/r/base/unlist.html">unlist</a></span>(<span class="fu"><a href="https://rdrr.io/r/base/lapply.html">lapply</a></span>(<span class="kw">LETTERS</span>, <span class="kw">paste0</span>, <span class="fl">1</span><span class="op">:</span><span class="fl">10</span>))
|
||
</pre></div>
|
||
<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>
|
||
<div class="sourceCode" id="cb3"><pre class="downlit">
|
||
<span class="kw">patients_table</span> <span class="op"><-</span> <span class="fu"><a href="https://rdrr.io/r/base/data.frame.html">data.frame</a></span>(patient_id = <span class="kw">patients</span>,
|
||
gender = <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span>(<span class="fu"><a href="https://rdrr.io/r/base/rep.html">rep</a></span>(<span class="st">"M"</span>, <span class="fl">135</span>),
|
||
<span class="fu"><a href="https://rdrr.io/r/base/rep.html">rep</a></span>(<span class="st">"F"</span>, <span class="fl">125</span>)))
|
||
</pre></div>
|
||
<p>The first 135 patient IDs are now male, the other 125 are female.</p>
|
||
</div>
|
||
<div id="dates" class="section level2">
|
||
<h2 class="hasAnchor">
|
||
<a href="#dates" class="anchor"></a>Dates</h2>
|
||
<p>Let’s pretend that our data consists of blood cultures isolates from between 1 January 2010 and 1 January 2018.</p>
|
||
<div class="sourceCode" id="cb4"><pre class="downlit">
|
||
<span class="kw">dates</span> <span class="op"><-</span> <span class="fu"><a href="https://rdrr.io/r/base/seq.html">seq</a></span>(<span class="fu"><a href="https://rdrr.io/r/base/as.Date.html">as.Date</a></span>(<span class="st">"2010-01-01"</span>), <span class="fu"><a href="https://rdrr.io/r/base/as.Date.html">as.Date</a></span>(<span class="st">"2018-01-01"</span>), by = <span class="st">"day"</span>)
|
||
</pre></div>
|
||
<p>This <code>dates</code> object now contains all days in our date range.</p>
|
||
<div id="microorganisms" class="section level4">
|
||
<h4 class="hasAnchor">
|
||
<a href="#microorganisms" class="anchor"></a>Microorganisms</h4>
|
||
<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>
|
||
<div class="sourceCode" id="cb5"><pre class="downlit">
|
||
<span class="kw">bacteria</span> <span class="op"><-</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span>(<span class="st">"Escherichia coli"</span>, <span class="st">"Staphylococcus aureus"</span>,
|
||
<span class="st">"Streptococcus pneumoniae"</span>, <span class="st">"Klebsiella pneumoniae"</span>)
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<div id="other-variables" class="section level2">
|
||
<h2 class="hasAnchor">
|
||
<a href="#other-variables" class="anchor"></a>Other variables</h2>
|
||
<p>For completeness, we can also add the hospital where the patients was admitted and we need to define valid antibmicrobial results for our randomisation:</p>
|
||
<div class="sourceCode" id="cb6"><pre class="downlit">
|
||
<span class="kw">hospitals</span> <span class="op"><-</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span>(<span class="st">"Hospital A"</span>, <span class="st">"Hospital B"</span>, <span class="st">"Hospital C"</span>, <span class="st">"Hospital D"</span>)
|
||
<span class="kw">ab_interpretations</span> <span class="op"><-</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span>(<span class="st">"S"</span>, <span class="st">"I"</span>, <span class="st">"R"</span>)
|
||
</pre></div>
|
||
</div>
|
||
<div id="put-everything-together" class="section level2">
|
||
<h2 class="hasAnchor">
|
||
<a href="#put-everything-together" class="anchor"></a>Put everything together</h2>
|
||
<p>Using the <code><a href="https://rdrr.io/r/base/sample.html">sample()</a></code> function, we can randomly select items from all objects we defined earlier. To let our fake data reflect reality a bit, we will also approximately define the probabilities of bacteria and the antibiotic results with the <code>prob</code> parameter.</p>
|
||
<div class="sourceCode" id="cb7"><pre class="downlit">
|
||
<span class="kw">sample_size</span> <span class="op"><-</span> <span class="fl">20000</span>
|
||
<span class="kw">data</span> <span class="op"><-</span> <span class="fu"><a href="https://rdrr.io/r/base/data.frame.html">data.frame</a></span>(date = <span class="fu"><a href="https://rdrr.io/r/base/sample.html">sample</a></span>(<span class="kw">dates</span>, size = <span class="kw">sample_size</span>, replace = <span class="fl">TRUE</span>),
|
||
patient_id = <span class="fu"><a href="https://rdrr.io/r/base/sample.html">sample</a></span>(<span class="kw">patients</span>, size = <span class="kw">sample_size</span>, replace = <span class="fl">TRUE</span>),
|
||
hospital = <span class="fu"><a href="https://rdrr.io/r/base/sample.html">sample</a></span>(<span class="kw">hospitals</span>, size = <span class="kw">sample_size</span>, replace = <span class="fl">TRUE</span>,
|
||
prob = <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span>(<span class="fl">0.30</span>, <span class="fl">0.35</span>, <span class="fl">0.15</span>, <span class="fl">0.20</span>)),
|
||
bacteria = <span class="fu"><a href="https://rdrr.io/r/base/sample.html">sample</a></span>(<span class="kw">bacteria</span>, size = <span class="kw">sample_size</span>, replace = <span class="fl">TRUE</span>,
|
||
prob = <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span>(<span class="fl">0.50</span>, <span class="fl">0.25</span>, <span class="fl">0.15</span>, <span class="fl">0.10</span>)),
|
||
AMX = <span class="fu"><a href="https://rdrr.io/r/base/sample.html">sample</a></span>(<span class="kw">ab_interpretations</span>, size = <span class="kw">sample_size</span>, replace = <span class="fl">TRUE</span>,
|
||
prob = <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span>(<span class="fl">0.60</span>, <span class="fl">0.05</span>, <span class="fl">0.35</span>)),
|
||
AMC = <span class="fu"><a href="https://rdrr.io/r/base/sample.html">sample</a></span>(<span class="kw">ab_interpretations</span>, size = <span class="kw">sample_size</span>, replace = <span class="fl">TRUE</span>,
|
||
prob = <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span>(<span class="fl">0.75</span>, <span class="fl">0.10</span>, <span class="fl">0.15</span>)),
|
||
CIP = <span class="fu"><a href="https://rdrr.io/r/base/sample.html">sample</a></span>(<span class="kw">ab_interpretations</span>, size = <span class="kw">sample_size</span>, replace = <span class="fl">TRUE</span>,
|
||
prob = <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span>(<span class="fl">0.80</span>, <span class="fl">0.00</span>, <span class="fl">0.20</span>)),
|
||
GEN = <span class="fu"><a href="https://rdrr.io/r/base/sample.html">sample</a></span>(<span class="kw">ab_interpretations</span>, size = <span class="kw">sample_size</span>, replace = <span class="fl">TRUE</span>,
|
||
prob = <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span>(<span class="fl">0.92</span>, <span class="fl">0.00</span>, <span class="fl">0.08</span>)))
|
||
</pre></div>
|
||
<p>Using the <code><a href="https://dplyr.tidyverse.org/reference/mutate-joins.html">left_join()</a></code> function from the <code>dplyr</code> package, we can ‘map’ the gender to the patient ID using the <code>patients_table</code> object we created earlier:</p>
|
||
<div class="sourceCode" id="cb8"><pre class="downlit">
|
||
<span class="kw">data</span> <span class="op"><-</span> <span class="kw">data</span> <span class="op">%>%</span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/mutate-joins.html">left_join</a></span>(<span class="kw">patients_table</span>)
|
||
</pre></div>
|
||
<p>The resulting data set contains 20,000 blood culture isolates. With the <code><a href="https://rdrr.io/r/utils/head.html">head()</a></code> function we can preview the first 6 rows of this data set:</p>
|
||
<div class="sourceCode" id="cb9"><pre class="downlit">
|
||
<span class="fu"><a href="https://rdrr.io/r/utils/head.html">head</a></span>(<span class="kw">data</span>)
|
||
</pre></div>
|
||
<table class="table">
|
||
<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">
|
||
<td align="center">2011-03-20</td>
|
||
<td align="center">W2</td>
|
||
<td align="center">Hospital A</td>
|
||
<td align="center">Streptococcus pneumoniae</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">R</td>
|
||
<td align="center">F</td>
|
||
</tr>
|
||
<tr class="even">
|
||
<td align="center">2011-12-03</td>
|
||
<td align="center">X9</td>
|
||
<td align="center">Hospital B</td>
|
||
<td align="center">Klebsiella pneumoniae</td>
|
||
<td align="center">R</td>
|
||
<td align="center">I</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">F</td>
|
||
</tr>
|
||
<tr class="odd">
|
||
<td align="center">2012-11-11</td>
|
||
<td align="center">A5</td>
|
||
<td align="center">Hospital D</td>
|
||
<td align="center">Staphylococcus aureus</td>
|
||
<td align="center">S</td>
|
||
<td align="center">R</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">M</td>
|
||
</tr>
|
||
<tr class="even">
|
||
<td align="center">2012-09-03</td>
|
||
<td align="center">Y3</td>
|
||
<td align="center">Hospital C</td>
|
||
<td align="center">Escherichia coli</td>
|
||
<td align="center">R</td>
|
||
<td align="center">S</td>
|
||
<td align="center">R</td>
|
||
<td align="center">R</td>
|
||
<td align="center">F</td>
|
||
</tr>
|
||
<tr class="odd">
|
||
<td align="center">2012-11-19</td>
|
||
<td align="center">I3</td>
|
||
<td align="center">Hospital C</td>
|
||
<td align="center">Escherichia coli</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">R</td>
|
||
<td align="center">M</td>
|
||
</tr>
|
||
<tr class="even">
|
||
<td align="center">2015-06-05</td>
|
||
<td align="center">Q7</td>
|
||
<td align="center">Hospital B</td>
|
||
<td align="center">Escherichia coli</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">F</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
<p>Now, let’s start the cleaning and the analysis!</p>
|
||
</div>
|
||
</div>
|
||
<div id="cleaning-the-data" class="section level1">
|
||
<h1 class="hasAnchor">
|
||
<a href="#cleaning-the-data" class="anchor"></a>Cleaning the data</h1>
|
||
<p>We also created a package dedicated to data cleaning and checking, called the <code>cleaner</code> package. It <code><a href="https://rdrr.io/pkg/cleaner/man/freq.html">freq()</a></code> function can be used to create frequency tables.</p>
|
||
<p>For example, for the <code>gender</code> variable:</p>
|
||
<div class="sourceCode" id="cb10"><pre class="downlit">
|
||
<span class="kw">data</span> <span class="op">%>%</span> <span class="fu"><a href="https://rdrr.io/pkg/cleaner/man/freq.html">freq</a></span>(<span class="kw">gender</span>)
|
||
</pre></div>
|
||
<p><strong>Frequency table</strong></p>
|
||
<p>Class: character<br>
|
||
Length: 20,000<br>
|
||
Available: 20,000 (100%, NA: 0 = 0%)<br>
|
||
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>
|
||
<td align="right">10,358</td>
|
||
<td align="right">51.79%</td>
|
||
<td align="right">10,358</td>
|
||
<td align="right">51.79%</td>
|
||
</tr>
|
||
<tr class="even">
|
||
<td align="left">2</td>
|
||
<td align="left">F</td>
|
||
<td align="right">9,642</td>
|
||
<td align="right">48.21%</td>
|
||
<td align="right">20,000</td>
|
||
<td align="right">100.00%</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
<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">mutate()</a></code> function of the <code>dplyr</code> package makes this really easy:</p>
|
||
<div class="sourceCode" id="cb11"><pre class="downlit">
|
||
<span class="kw">data</span> <span class="op"><-</span> <span class="kw">data</span> <span class="op">%>%</span>
|
||
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/mutate.html">mutate</a></span>(bacteria = <span class="fu"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="kw">bacteria</span>))
|
||
</pre></div>
|
||
<p>We also want to transform the antibiotics, because in real life data we don’t know if they are really clean. The <code><a href="../reference/as.rsi.html">as.rsi()</a></code> function ensures reliability and reproducibility in these kind of variables. The <code><a href="https://dplyr.tidyverse.org/reference/mutate_all.html">mutate_at()</a></code> will run the <code><a href="../reference/as.rsi.html">as.rsi()</a></code> function on defined variables:</p>
|
||
<div class="sourceCode" id="cb12"><pre class="downlit">
|
||
<span class="kw">data</span> <span class="op"><-</span> <span class="kw">data</span> <span class="op">%>%</span>
|
||
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/mutate_all.html">mutate_at</a></span>(<span class="fu"><a href="https://dplyr.tidyverse.org/reference/vars.html">vars</a></span>(<span class="kw">AMX</span><span class="op">:</span><span class="kw">GEN</span>), <span class="kw">as.rsi</span>)
|
||
</pre></div>
|
||
<p>Finally, we will apply <a href="http://www.eucast.org/expert_rules_and_intrinsic_resistance/">EUCAST rules</a> on our antimicrobial results. In Europe, most medical microbiological laboratories already apply these rules. Our package features their latest insights on intrinsic resistance and exceptional phenotypes. Moreover, the <code><a href="../reference/eucast_rules.html">eucast_rules()</a></code> function can also apply additional rules, like forcing <help title="ATC: J01CA01">ampicillin</help> = R when <help title="ATC: J01CR02">amoxicillin/clavulanic acid</help> = R.</p>
|
||
<p>Because the amoxicillin (column <code>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>
|
||
<div class="sourceCode" id="cb13"><pre class="downlit">
|
||
<span class="kw">data</span> <span class="op"><-</span> <span class="fu"><a href="../reference/eucast_rules.html">eucast_rules</a></span>(<span class="kw">data</span>, col_mo = <span class="st">"bacteria"</span>, rules = <span class="st">"all"</span>)
|
||
</pre></div>
|
||
</div>
|
||
<div id="adding-new-variables" class="section level1">
|
||
<h1 class="hasAnchor">
|
||
<a href="#adding-new-variables" class="anchor"></a>Adding new variables</h1>
|
||
<p>Now that we have the microbial ID, we can add some taxonomic properties:</p>
|
||
<div class="sourceCode" id="cb14"><pre class="downlit">
|
||
<span class="kw">data</span> <span class="op"><-</span> <span class="kw">data</span> <span class="op">%>%</span>
|
||
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/mutate.html">mutate</a></span>(gramstain = <span class="fu"><a href="../reference/mo_property.html">mo_gramstain</a></span>(<span class="kw">bacteria</span>),
|
||
genus = <span class="fu"><a href="../reference/mo_property.html">mo_genus</a></span>(<span class="kw">bacteria</span>),
|
||
species = <span class="fu"><a href="../reference/mo_property.html">mo_species</a></span>(<span class="kw">bacteria</span>))
|
||
</pre></div>
|
||
<div id="first-isolates" class="section level2">
|
||
<h2 class="hasAnchor">
|
||
<a href="#first-isolates" class="anchor"></a>First isolates</h2>
|
||
<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://www.ncbi.nlm.nih.gov/pubmed/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">selection bias</a>.</p>
|
||
<p>The Clinical and Laboratory Standards Institute (CLSI) appoints this as follows:</p>
|
||
<blockquote>
|
||
<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/">M39-A4 Analysis and Presentation of Cumulative Antimicrobial Susceptibility Test Data, 4th Edition. CLSI, 2014. Chapter 6.4</a></p>
|
||
</blockquote>
|
||
<p>This <code>AMR</code> package includes this methodology with the <code><a href="../reference/first_isolate.html">first_isolate()</a></code> function. It adopts the episode of a year (can be changed by user) and it starts counting days after every selected isolate. This new variable can easily be added to our data:</p>
|
||
<div class="sourceCode" id="cb15"><pre class="downlit">
|
||
<span class="kw">data</span> <span class="op"><-</span> <span class="kw">data</span> <span class="op">%>%</span>
|
||
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/mutate.html">mutate</a></span>(first = <span class="fu"><a href="../reference/first_isolate.html">first_isolate</a></span>(<span class="kw">.</span>))
|
||
<span class="co"># NOTE: Using column `bacteria` as input for `col_mo`.</span>
|
||
<span class="co"># NOTE: Using column `date` as input for `col_date`.</span>
|
||
<span class="co"># NOTE: Using column `patient_id` as input for `col_patient_id`.</span>
|
||
</pre></div>
|
||
<p>So only 28.3% is suitable for resistance analysis! We can now filter on it with the <code><a href="https://dplyr.tidyverse.org/reference/filter.html">filter()</a></code> function, also from the <code>dplyr</code> package:</p>
|
||
<div class="sourceCode" id="cb16"><pre class="downlit">
|
||
<span class="kw">data_1st</span> <span class="op"><-</span> <span class="kw">data</span> <span class="op">%>%</span>
|
||
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/filter.html">filter</a></span>(<span class="kw">first</span> <span class="op">==</span> <span class="fl">TRUE</span>)
|
||
</pre></div>
|
||
<p>For future use, the above two syntaxes can be shortened with the <code><a href="../reference/first_isolate.html">filter_first_isolate()</a></code> function:</p>
|
||
<div class="sourceCode" id="cb17"><pre class="downlit">
|
||
<span class="kw">data_1st</span> <span class="op"><-</span> <span class="kw">data</span> <span class="op">%>%</span>
|
||
<span class="fu"><a href="../reference/first_isolate.html">filter_first_isolate</a></span>()
|
||
</pre></div>
|
||
</div>
|
||
<div id="first-weighted-isolates" class="section level2">
|
||
<h2 class="hasAnchor">
|
||
<a href="#first-weighted-isolates" class="anchor"></a>First <em>weighted</em> isolates</h2>
|
||
<p>We made a slight twist to the CLSI algorithm, to take into account the antimicrobial susceptibility profile. Have a look at all isolates of patient C8, sorted on date:</p>
|
||
<table class="table">
|
||
<thead><tr class="header">
|
||
<th align="center">isolate</th>
|
||
<th align="center">date</th>
|
||
<th align="center">patient_id</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">first</th>
|
||
</tr></thead>
|
||
<tbody>
|
||
<tr class="odd">
|
||
<td align="center">1</td>
|
||
<td align="center">2010-01-13</td>
|
||
<td align="center">C8</td>
|
||
<td align="center">B_ESCHR_COLI</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">TRUE</td>
|
||
</tr>
|
||
<tr class="even">
|
||
<td align="center">2</td>
|
||
<td align="center">2010-02-19</td>
|
||
<td align="center">C8</td>
|
||
<td align="center">B_ESCHR_COLI</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">FALSE</td>
|
||
</tr>
|
||
<tr class="odd">
|
||
<td align="center">3</td>
|
||
<td align="center">2010-03-12</td>
|
||
<td align="center">C8</td>
|
||
<td align="center">B_ESCHR_COLI</td>
|
||
<td align="center">R</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">FALSE</td>
|
||
</tr>
|
||
<tr class="even">
|
||
<td align="center">4</td>
|
||
<td align="center">2010-03-25</td>
|
||
<td align="center">C8</td>
|
||
<td align="center">B_ESCHR_COLI</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">R</td>
|
||
<td align="center">R</td>
|
||
<td align="center">FALSE</td>
|
||
</tr>
|
||
<tr class="odd">
|
||
<td align="center">5</td>
|
||
<td align="center">2010-04-28</td>
|
||
<td align="center">C8</td>
|
||
<td align="center">B_ESCHR_COLI</td>
|
||
<td align="center">R</td>
|
||
<td align="center">S</td>
|
||
<td align="center">R</td>
|
||
<td align="center">S</td>
|
||
<td align="center">FALSE</td>
|
||
</tr>
|
||
<tr class="even">
|
||
<td align="center">6</td>
|
||
<td align="center">2010-07-22</td>
|
||
<td align="center">C8</td>
|
||
<td align="center">B_ESCHR_COLI</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">FALSE</td>
|
||
</tr>
|
||
<tr class="odd">
|
||
<td align="center">7</td>
|
||
<td align="center">2010-12-05</td>
|
||
<td align="center">C8</td>
|
||
<td align="center">B_ESCHR_COLI</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">FALSE</td>
|
||
</tr>
|
||
<tr class="even">
|
||
<td align="center">8</td>
|
||
<td align="center">2011-01-18</td>
|
||
<td align="center">C8</td>
|
||
<td align="center">B_ESCHR_COLI</td>
|
||
<td align="center">R</td>
|
||
<td align="center">R</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">TRUE</td>
|
||
</tr>
|
||
<tr class="odd">
|
||
<td align="center">9</td>
|
||
<td align="center">2011-05-24</td>
|
||
<td align="center">C8</td>
|
||
<td align="center">B_ESCHR_COLI</td>
|
||
<td align="center">R</td>
|
||
<td align="center">I</td>
|
||
<td align="center">R</td>
|
||
<td align="center">S</td>
|
||
<td align="center">FALSE</td>
|
||
</tr>
|
||
<tr class="even">
|
||
<td align="center">10</td>
|
||
<td align="center">2011-06-24</td>
|
||
<td align="center">C8</td>
|
||
<td align="center">B_ESCHR_COLI</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">FALSE</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
<p>Only 2 isolates are marked as ‘first’ according to CLSI guideline. But when reviewing the antibiogram, it is obvious that some isolates are absolutely different strains and should be included too. This is why we weigh isolates, based on their antibiogram. The <code><a href="../reference/key_antibiotics.html">key_antibiotics()</a></code> function adds a vector with 18 key antibiotics: 6 broad spectrum ones, 6 small spectrum for Gram negatives and 6 small spectrum for Gram positives. These can be defined by the user.</p>
|
||
<p>If a column exists with a name like ‘key(…)ab’ the <code><a href="../reference/first_isolate.html">first_isolate()</a></code> function will automatically use it and determine the first weighted isolates. Mind the NOTEs in below output:</p>
|
||
<div class="sourceCode" id="cb18"><pre class="downlit">
|
||
<span class="kw">data</span> <span class="op"><-</span> <span class="kw">data</span> <span class="op">%>%</span>
|
||
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/mutate.html">mutate</a></span>(keyab = <span class="fu"><a href="../reference/key_antibiotics.html">key_antibiotics</a></span>(<span class="kw">.</span>)) <span class="op">%>%</span>
|
||
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/mutate.html">mutate</a></span>(first_weighted = <span class="fu"><a href="../reference/first_isolate.html">first_isolate</a></span>(<span class="kw">.</span>))
|
||
<span class="co"># NOTE: Using column `bacteria` as input for `col_mo`.</span>
|
||
<span class="co"># NOTE: Using column `bacteria` as input for `col_mo`.</span>
|
||
<span class="co"># NOTE: Using column `date` as input for `col_date`.</span>
|
||
<span class="co"># NOTE: Using column `patient_id` as input for `col_patient_id`.</span>
|
||
<span class="co"># NOTE: Using column `keyab` as input for `col_keyantibiotics`. Use col_keyantibiotics = FALSE to prevent this.</span>
|
||
</pre></div>
|
||
<table class="table">
|
||
<thead><tr class="header">
|
||
<th align="center">isolate</th>
|
||
<th align="center">date</th>
|
||
<th align="center">patient_id</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">first</th>
|
||
<th align="center">first_weighted</th>
|
||
</tr></thead>
|
||
<tbody>
|
||
<tr class="odd">
|
||
<td align="center">1</td>
|
||
<td align="center">2010-01-13</td>
|
||
<td align="center">C8</td>
|
||
<td align="center">B_ESCHR_COLI</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">TRUE</td>
|
||
<td align="center">TRUE</td>
|
||
</tr>
|
||
<tr class="even">
|
||
<td align="center">2</td>
|
||
<td align="center">2010-02-19</td>
|
||
<td align="center">C8</td>
|
||
<td align="center">B_ESCHR_COLI</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">FALSE</td>
|
||
<td align="center">FALSE</td>
|
||
</tr>
|
||
<tr class="odd">
|
||
<td align="center">3</td>
|
||
<td align="center">2010-03-12</td>
|
||
<td align="center">C8</td>
|
||
<td align="center">B_ESCHR_COLI</td>
|
||
<td align="center">R</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">FALSE</td>
|
||
<td align="center">TRUE</td>
|
||
</tr>
|
||
<tr class="even">
|
||
<td align="center">4</td>
|
||
<td align="center">2010-03-25</td>
|
||
<td align="center">C8</td>
|
||
<td align="center">B_ESCHR_COLI</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">R</td>
|
||
<td align="center">R</td>
|
||
<td align="center">FALSE</td>
|
||
<td align="center">TRUE</td>
|
||
</tr>
|
||
<tr class="odd">
|
||
<td align="center">5</td>
|
||
<td align="center">2010-04-28</td>
|
||
<td align="center">C8</td>
|
||
<td align="center">B_ESCHR_COLI</td>
|
||
<td align="center">R</td>
|
||
<td align="center">S</td>
|
||
<td align="center">R</td>
|
||
<td align="center">S</td>
|
||
<td align="center">FALSE</td>
|
||
<td align="center">TRUE</td>
|
||
</tr>
|
||
<tr class="even">
|
||
<td align="center">6</td>
|
||
<td align="center">2010-07-22</td>
|
||
<td align="center">C8</td>
|
||
<td align="center">B_ESCHR_COLI</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">FALSE</td>
|
||
<td align="center">TRUE</td>
|
||
</tr>
|
||
<tr class="odd">
|
||
<td align="center">7</td>
|
||
<td align="center">2010-12-05</td>
|
||
<td align="center">C8</td>
|
||
<td align="center">B_ESCHR_COLI</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">FALSE</td>
|
||
<td align="center">FALSE</td>
|
||
</tr>
|
||
<tr class="even">
|
||
<td align="center">8</td>
|
||
<td align="center">2011-01-18</td>
|
||
<td align="center">C8</td>
|
||
<td align="center">B_ESCHR_COLI</td>
|
||
<td align="center">R</td>
|
||
<td align="center">R</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">TRUE</td>
|
||
<td align="center">TRUE</td>
|
||
</tr>
|
||
<tr class="odd">
|
||
<td align="center">9</td>
|
||
<td align="center">2011-05-24</td>
|
||
<td align="center">C8</td>
|
||
<td align="center">B_ESCHR_COLI</td>
|
||
<td align="center">R</td>
|
||
<td align="center">I</td>
|
||
<td align="center">R</td>
|
||
<td align="center">S</td>
|
||
<td align="center">FALSE</td>
|
||
<td align="center">TRUE</td>
|
||
</tr>
|
||
<tr class="even">
|
||
<td align="center">10</td>
|
||
<td align="center">2011-06-24</td>
|
||
<td align="center">C8</td>
|
||
<td align="center">B_ESCHR_COLI</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">FALSE</td>
|
||
<td align="center">TRUE</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
<p>Instead of 2, now 8 isolates are flagged. In total, 78.4% of all isolates are marked ‘first weighted’ - 50.1% more than when using the CLSI guideline. In real life, this novel algorithm will yield 5-10% more isolates than the classic CLSI guideline.</p>
|
||
<p>As with <code><a href="../reference/first_isolate.html">filter_first_isolate()</a></code>, there’s a shortcut for this new algorithm too:</p>
|
||
<div class="sourceCode" id="cb19"><pre class="downlit">
|
||
<span class="kw">data_1st</span> <span class="op"><-</span> <span class="kw">data</span> <span class="op">%>%</span>
|
||
<span class="fu"><a href="../reference/first_isolate.html">filter_first_weighted_isolate</a></span>()
|
||
</pre></div>
|
||
<p>So we end up with 15,686 isolates for analysis.</p>
|
||
<p>We can remove unneeded columns:</p>
|
||
<div class="sourceCode" id="cb20"><pre class="downlit">
|
||
<span class="kw">data_1st</span> <span class="op"><-</span> <span class="kw">data_1st</span> <span class="op">%>%</span>
|
||
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/select.html">select</a></span>(<span class="op">-</span><span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span>(<span class="kw">first</span>, <span class="kw">keyab</span>))
|
||
</pre></div>
|
||
<p>Now our data looks like:</p>
|
||
<div class="sourceCode" id="cb21"><pre class="downlit">
|
||
<span class="fu"><a href="https://rdrr.io/r/utils/head.html">head</a></span>(<span class="kw">data_1st</span>)
|
||
</pre></div>
|
||
<table class="table">
|
||
<colgroup>
|
||
<col width="2%">
|
||
<col width="8%">
|
||
<col width="8%">
|
||
<col width="8%">
|
||
<col width="10%">
|
||
<col width="3%">
|
||
<col width="3%">
|
||
<col width="3%">
|
||
<col width="3%">
|
||
<col width="5%">
|
||
<col width="10%">
|
||
<col width="11%">
|
||
<col width="8%">
|
||
<col width="11%">
|
||
</colgroup>
|
||
<thead><tr class="header">
|
||
<th align="left"></th>
|
||
<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_weighted</th>
|
||
</tr></thead>
|
||
<tbody>
|
||
<tr class="odd">
|
||
<td align="left">1</td>
|
||
<td align="center">2011-03-20</td>
|
||
<td align="center">W2</td>
|
||
<td align="center">Hospital A</td>
|
||
<td align="center">B_STRPT_PNMN</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">R</td>
|
||
<td align="center">F</td>
|
||
<td align="center">Gram-positive</td>
|
||
<td align="center">Streptococcus</td>
|
||
<td align="center">pneumoniae</td>
|
||
<td align="center">TRUE</td>
|
||
</tr>
|
||
<tr class="even">
|
||
<td align="left">3</td>
|
||
<td align="center">2012-11-11</td>
|
||
<td align="center">A5</td>
|
||
<td align="center">Hospital D</td>
|
||
<td align="center">B_STPHY_AURS</td>
|
||
<td align="center">R</td>
|
||
<td align="center">R</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">M</td>
|
||
<td align="center">Gram-positive</td>
|
||
<td align="center">Staphylococcus</td>
|
||
<td align="center">aureus</td>
|
||
<td align="center">TRUE</td>
|
||
</tr>
|
||
<tr class="odd">
|
||
<td align="left">4</td>
|
||
<td align="center">2012-09-03</td>
|
||
<td align="center">Y3</td>
|
||
<td align="center">Hospital C</td>
|
||
<td align="center">B_ESCHR_COLI</td>
|
||
<td align="center">R</td>
|
||
<td align="center">S</td>
|
||
<td align="center">R</td>
|
||
<td align="center">R</td>
|
||
<td align="center">F</td>
|
||
<td align="center">Gram-negative</td>
|
||
<td align="center">Escherichia</td>
|
||
<td align="center">coli</td>
|
||
<td align="center">TRUE</td>
|
||
</tr>
|
||
<tr class="even">
|
||
<td align="left">5</td>
|
||
<td align="center">2012-11-19</td>
|
||
<td align="center">I3</td>
|
||
<td align="center">Hospital C</td>
|
||
<td align="center">B_ESCHR_COLI</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">R</td>
|
||
<td align="center">M</td>
|
||
<td align="center">Gram-negative</td>
|
||
<td align="center">Escherichia</td>
|
||
<td align="center">coli</td>
|
||
<td align="center">TRUE</td>
|
||
</tr>
|
||
<tr class="odd">
|
||
<td align="left">8</td>
|
||
<td align="center">2013-11-06</td>
|
||
<td align="center">B1</td>
|
||
<td align="center">Hospital B</td>
|
||
<td align="center">B_KLBSL_PNMN</td>
|
||
<td align="center">R</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">M</td>
|
||
<td align="center">Gram-negative</td>
|
||
<td align="center">Klebsiella</td>
|
||
<td align="center">pneumoniae</td>
|
||
<td align="center">TRUE</td>
|
||
</tr>
|
||
<tr class="even">
|
||
<td align="left">9</td>
|
||
<td align="center">2017-01-21</td>
|
||
<td align="center">U3</td>
|
||
<td align="center">Hospital D</td>
|
||
<td align="center">B_KLBSL_PNMN</td>
|
||
<td align="center">R</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">S</td>
|
||
<td align="center">F</td>
|
||
<td align="center">Gram-negative</td>
|
||
<td align="center">Klebsiella</td>
|
||
<td align="center">pneumoniae</td>
|
||
<td align="center">TRUE</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
<p>Time for the analysis!</p>
|
||
</div>
|
||
</div>
|
||
<div id="analysing-the-data" class="section level1">
|
||
<h1 class="hasAnchor">
|
||
<a href="#analysing-the-data" class="anchor"></a>Analysing the data</h1>
|
||
<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"><code>DataExplorer</code></a> for that, or read the free online book <a href="https://bookdown.org/rdpeng/exdata/">Exploratory Data Analysis with R</a> by Roger D. Peng.</p>
|
||
<div id="dispersion-of-species" class="section level2">
|
||
<h2 class="hasAnchor">
|
||
<a href="#dispersion-of-species" class="anchor"></a>Dispersion of species</h2>
|
||
<p>To just get an idea how the species are distributed, create a frequency table with our <code><a href="https://rdrr.io/pkg/cleaner/man/freq.html">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">paste()</a></code>, we can concatenate them together.</p>
|
||
<p>The <code><a href="https://rdrr.io/pkg/cleaner/man/freq.html">freq()</a></code> function can be used like the base R language was intended:</p>
|
||
<div class="sourceCode" id="cb22"><pre class="downlit">
|
||
<span class="fu"><a href="https://rdrr.io/pkg/cleaner/man/freq.html">freq</a></span>(<span class="fu"><a href="https://rdrr.io/r/base/paste.html">paste</a></span>(<span class="kw">data_1st</span><span class="op">$</span><span class="kw">genus</span>, <span class="kw">data_1st</span><span class="op">$</span><span class="kw">species</span>))
|
||
</pre></div>
|
||
<p>Or can be used like the <code>dplyr</code> way, which is easier readable:</p>
|
||
<div class="sourceCode" id="cb23"><pre class="downlit">
|
||
<span class="kw">data_1st</span> <span class="op">%>%</span> <span class="fu"><a href="https://rdrr.io/pkg/cleaner/man/freq.html">freq</a></span>(<span class="kw">genus</span>, <span class="kw">species</span>)
|
||
</pre></div>
|
||
<p><strong>Frequency table</strong></p>
|
||
<p>Class: character<br>
|
||
Length: 15,686<br>
|
||
Available: 15,686 (100%, NA: 0 = 0%)<br>
|
||
Unique: 4</p>
|
||
<p>Shortest: 16<br>
|
||
Longest: 24</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">Escherichia coli</td>
|
||
<td align="right">7,774</td>
|
||
<td align="right">49.56%</td>
|
||
<td align="right">7,774</td>
|
||
<td align="right">49.56%</td>
|
||
</tr>
|
||
<tr class="even">
|
||
<td align="left">2</td>
|
||
<td align="left">Staphylococcus aureus</td>
|
||
<td align="right">3,952</td>
|
||
<td align="right">25.19%</td>
|
||
<td align="right">11,726</td>
|
||
<td align="right">74.75%</td>
|
||
</tr>
|
||
<tr class="odd">
|
||
<td align="left">3</td>
|
||
<td align="left">Streptococcus pneumoniae</td>
|
||
<td align="right">2,367</td>
|
||
<td align="right">15.09%</td>
|
||
<td align="right">14,093</td>
|
||
<td align="right">89.84%</td>
|
||
</tr>
|
||
<tr class="even">
|
||
<td align="left">4</td>
|
||
<td align="left">Klebsiella pneumoniae</td>
|
||
<td align="right">1,593</td>
|
||
<td align="right">10.16%</td>
|
||
<td align="right">15,686</td>
|
||
<td align="right">100.00%</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<div id="overview-of-different-bugdrug-combinations" class="section level2">
|
||
<h2 class="hasAnchor">
|
||
<a href="#overview-of-different-bugdrug-combinations" class="anchor"></a>Overview of different bug/drug combinations</h2>
|
||
<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>
|
||
<div class="sourceCode" id="cb24"><pre class="downlit">
|
||
<span class="kw">data_1st</span> <span class="op">%>%</span>
|
||
<span class="fu"><a href="../reference/bug_drug_combinations.html">bug_drug_combinations</a></span>() <span class="op">%>%</span>
|
||
<span class="fu"><a href="https://rdrr.io/r/utils/head.html">head</a></span>() <span class="co"># show first 6 rows</span>
|
||
</pre></div>
|
||
<pre><code># NOTE: Using column `bacteria` as input for `col_mo`.</code></pre>
|
||
<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>
|
||
<td align="center">3685</td>
|
||
<td align="center">257</td>
|
||
<td align="center">3832</td>
|
||
<td align="center">7774</td>
|
||
</tr>
|
||
<tr class="even">
|
||
<td align="center">E. coli</td>
|
||
<td align="center">AMC</td>
|
||
<td align="center">6104</td>
|
||
<td align="center">275</td>
|
||
<td align="center">1395</td>
|
||
<td align="center">7774</td>
|
||
</tr>
|
||
<tr class="odd">
|
||
<td align="center">E. coli</td>
|
||
<td align="center">CIP</td>
|
||
<td align="center">5979</td>
|
||
<td align="center">0</td>
|
||
<td align="center">1795</td>
|
||
<td align="center">7774</td>
|
||
</tr>
|
||
<tr class="even">
|
||
<td align="center">E. coli</td>
|
||
<td align="center">GEN</td>
|
||
<td align="center">6986</td>
|
||
<td align="center">0</td>
|
||
<td align="center">788</td>
|
||
<td align="center">7774</td>
|
||
</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>
|
||
<td align="center">1593</td>
|
||
<td align="center">1593</td>
|
||
</tr>
|
||
<tr class="even">
|
||
<td align="center">K. pneumoniae</td>
|
||
<td align="center">AMC</td>
|
||
<td align="center">1269</td>
|
||
<td align="center">57</td>
|
||
<td align="center">267</td>
|
||
<td align="center">1593</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
<p>Using <a href="https://tidyselect.r-lib.org/reference/language.html">Tidyverse selections</a>, you can also select columns based on the antibiotic class they are in:</p>
|
||
<div class="sourceCode" id="cb26"><pre class="downlit">
|
||
<span class="kw">data_1st</span> <span class="op">%>%</span>
|
||
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/select.html">select</a></span>(<span class="kw">bacteria</span>, <span class="fu"><a href="../reference/antibiotic_class_selectors.html">fluoroquinolones</a></span>()) <span class="op">%>%</span>
|
||
<span class="fu"><a href="../reference/bug_drug_combinations.html">bug_drug_combinations</a></span>()
|
||
</pre></div>
|
||
<pre><code># Selecting fluoroquinolones: `CIP` (ciprofloxacin)
|
||
# NOTE: Using column `bacteria` as input for `col_mo`.</code></pre>
|
||
<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">CIP</td>
|
||
<td align="center">5979</td>
|
||
<td align="center">0</td>
|
||
<td align="center">1795</td>
|
||
<td align="center">7774</td>
|
||
</tr>
|
||
<tr class="even">
|
||
<td align="center">K. pneumoniae</td>
|
||
<td align="center">CIP</td>
|
||
<td align="center">1213</td>
|
||
<td align="center">0</td>
|
||
<td align="center">380</td>
|
||
<td align="center">1593</td>
|
||
</tr>
|
||
<tr class="odd">
|
||
<td align="center">S. aureus</td>
|
||
<td align="center">CIP</td>
|
||
<td align="center">3003</td>
|
||
<td align="center">0</td>
|
||
<td align="center">949</td>
|
||
<td align="center">3952</td>
|
||
</tr>
|
||
<tr class="even">
|
||
<td align="center">S. pneumoniae</td>
|
||
<td align="center">CIP</td>
|
||
<td align="center">1820</td>
|
||
<td align="center">0</td>
|
||
<td align="center">547</td>
|
||
<td align="center">2367</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
<p>This will only give you the crude numbers in the data. To calculate antimicrobial resistance, we use the <code><a href="../reference/proportion.html">resistance()</a></code> and <code><a href="../reference/proportion.html">susceptibility()</a></code> functions.</p>
|
||
</div>
|
||
<div id="resistance-percentages" class="section level2">
|
||
<h2 class="hasAnchor">
|
||
<a href="#resistance-percentages" class="anchor"></a>Resistance percentages</h2>
|
||
<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>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>
|
||
<div class="sourceCode" id="cb28"><pre class="downlit">
|
||
<span class="kw">data_1st</span> <span class="op">%>%</span> <span class="fu"><a href="../reference/proportion.html">resistance</a></span>(<span class="kw">AMX</span>)
|
||
<span class="co"># [1] 0.5350631</span>
|
||
</pre></div>
|
||
<p>Or can be used in conjuction with <code><a href="https://dplyr.tidyverse.org/reference/group_by.html">group_by()</a></code> and <code><a href="https://dplyr.tidyverse.org/reference/summarise.html">summarise()</a></code>, both from the <code>dplyr</code> package:</p>
|
||
<div class="sourceCode" id="cb29"><pre class="downlit">
|
||
<span class="kw">data_1st</span> <span class="op">%>%</span>
|
||
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/group_by.html">group_by</a></span>(<span class="kw">hospital</span>) <span class="op">%>%</span>
|
||
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/summarise.html">summarise</a></span>(amoxicillin = <span class="fu"><a href="../reference/proportion.html">resistance</a></span>(<span class="kw">AMX</span>))
|
||
</pre></div>
|
||
<pre><code># `summarise()` ungrouping output (override with `.groups` argument)</code></pre>
|
||
<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>
|
||
<td align="center">0.5338783</td>
|
||
</tr>
|
||
<tr class="even">
|
||
<td align="center">Hospital B</td>
|
||
<td align="center">0.5368875</td>
|
||
</tr>
|
||
<tr class="odd">
|
||
<td align="center">Hospital C</td>
|
||
<td align="center">0.5367068</td>
|
||
</tr>
|
||
<tr class="even">
|
||
<td align="center">Hospital D</td>
|
||
<td align="center">0.5322422</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
<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">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>
|
||
<div class="sourceCode" id="cb31"><pre class="downlit">
|
||
<span class="kw">data_1st</span> <span class="op">%>%</span>
|
||
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/group_by.html">group_by</a></span>(<span class="kw">hospital</span>) <span class="op">%>%</span>
|
||
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/summarise.html">summarise</a></span>(amoxicillin = <span class="fu"><a href="../reference/proportion.html">resistance</a></span>(<span class="kw">AMX</span>),
|
||
available = <span class="fu"><a href="../reference/count.html">n_rsi</a></span>(<span class="kw">AMX</span>))
|
||
</pre></div>
|
||
<pre><code># `summarise()` ungrouping output (override with `.groups` argument)</code></pre>
|
||
<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>
|
||
<td align="center">0.5338783</td>
|
||
<td align="center">4649</td>
|
||
</tr>
|
||
<tr class="even">
|
||
<td align="center">Hospital B</td>
|
||
<td align="center">0.5368875</td>
|
||
<td align="center">5571</td>
|
||
</tr>
|
||
<tr class="odd">
|
||
<td align="center">Hospital C</td>
|
||
<td align="center">0.5367068</td>
|
||
<td align="center">2411</td>
|
||
</tr>
|
||
<tr class="even">
|
||
<td align="center">Hospital D</td>
|
||
<td align="center">0.5322422</td>
|
||
<td align="center">3055</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
<p>These functions can also be used to get the proportion of multiple antibiotics, to calculate empiric susceptibility of combination therapies very easily:</p>
|
||
<div class="sourceCode" id="cb33"><pre class="downlit">
|
||
<span class="kw">data_1st</span> <span class="op">%>%</span>
|
||
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/group_by.html">group_by</a></span>(<span class="kw">genus</span>) <span class="op">%>%</span>
|
||
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/summarise.html">summarise</a></span>(amoxiclav = <span class="fu"><a href="../reference/proportion.html">susceptibility</a></span>(<span class="kw">AMC</span>),
|
||
gentamicin = <span class="fu"><a href="../reference/proportion.html">susceptibility</a></span>(<span class="kw">GEN</span>),
|
||
amoxiclav_genta = <span class="fu"><a href="../reference/proportion.html">susceptibility</a></span>(<span class="kw">AMC</span>, <span class="kw">GEN</span>))
|
||
</pre></div>
|
||
<pre><code># `summarise()` ungrouping output (override with `.groups` argument)</code></pre>
|
||
<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>
|
||
<td align="center">0.8205557</td>
|
||
<td align="center">0.8986365</td>
|
||
<td align="center">0.9855930</td>
|
||
</tr>
|
||
<tr class="even">
|
||
<td align="center">Klebsiella</td>
|
||
<td align="center">0.8323917</td>
|
||
<td align="center">0.8901444</td>
|
||
<td align="center">0.9855618</td>
|
||
</tr>
|
||
<tr class="odd">
|
||
<td align="center">Staphylococcus</td>
|
||
<td align="center">0.8276822</td>
|
||
<td align="center">0.9210526</td>
|
||
<td align="center">0.9868421</td>
|
||
</tr>
|
||
<tr class="even">
|
||
<td align="center">Streptococcus</td>
|
||
<td align="center">0.5504858</td>
|
||
<td align="center">0.0000000</td>
|
||
<td align="center">0.5504858</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
<p>To make a transition to the next part, let’s see how this difference could be plotted:</p>
|
||
<div class="sourceCode" id="cb35"><pre class="downlit">
|
||
<span class="kw">data_1st</span> <span class="op">%>%</span>
|
||
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/group_by.html">group_by</a></span>(<span class="kw">genus</span>) <span class="op">%>%</span>
|
||
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/summarise.html">summarise</a></span>(<span class="st">"1. Amoxi/clav"</span> = <span class="fu"><a href="../reference/proportion.html">susceptibility</a></span>(<span class="kw">AMC</span>),
|
||
<span class="st">"2. Gentamicin"</span> = <span class="fu"><a href="../reference/proportion.html">susceptibility</a></span>(<span class="kw">GEN</span>),
|
||
<span class="st">"3. Amoxi/clav + genta"</span> = <span class="fu"><a href="../reference/proportion.html">susceptibility</a></span>(<span class="kw">AMC</span>, <span class="kw">GEN</span>)) <span class="op">%>%</span>
|
||
<span class="co"># pivot_longer() from the tidyr package "lengthens" data:</span>
|
||
<span class="kw">tidyr</span>::<span class="fu"><a href="https://tidyr.tidyverse.org/reference/pivot_longer.html">pivot_longer</a></span>(<span class="op">-</span><span class="kw">genus</span>, names_to = <span class="st">"antibiotic"</span>) <span class="op">%>%</span>
|
||
<span class="fu"><a href="https://ggplot2.tidyverse.org/reference/ggplot.html">ggplot</a></span>(<span class="fu"><a href="https://ggplot2.tidyverse.org/reference/aes.html">aes</a></span>(x = <span class="kw">genus</span>,
|
||
y = <span class="kw">value</span>,
|
||
fill = <span class="kw">antibiotic</span>)) <span class="op">+</span>
|
||
<span class="fu"><a href="https://ggplot2.tidyverse.org/reference/geom_bar.html">geom_col</a></span>(position = <span class="st">"dodge2"</span>)
|
||
<span class="co"># `summarise()` ungrouping output (override with `.groups` argument)</span>
|
||
</pre></div>
|
||
<p><img src="AMR_files/figure-html/plot%201-1.png" width="720"></p>
|
||
</div>
|
||
<div id="plots" class="section level2">
|
||
<h2 class="hasAnchor">
|
||
<a href="#plots" class="anchor"></a>Plots</h2>
|
||
<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/">on their website</a>. A quick example would look like these syntaxes:</p>
|
||
<div class="sourceCode" id="cb36"><pre class="downlit">
|
||
<span class="fu"><a href="https://ggplot2.tidyverse.org/reference/ggplot.html">ggplot</a></span>(data = <span class="kw">a_data_set</span>,
|
||
mapping = <span class="fu"><a href="https://ggplot2.tidyverse.org/reference/aes.html">aes</a></span>(x = <span class="kw">year</span>,
|
||
y = <span class="kw">value</span>)) <span class="op">+</span>
|
||
<span class="fu"><a href="https://ggplot2.tidyverse.org/reference/geom_bar.html">geom_col</a></span>() <span class="op">+</span>
|
||
<span class="fu"><a href="https://ggplot2.tidyverse.org/reference/labs.html">labs</a></span>(title = <span class="st">"A title"</span>,
|
||
subtitle = <span class="st">"A subtitle"</span>,
|
||
x = <span class="st">"My X axis"</span>,
|
||
y = <span class="st">"My Y axis"</span>)
|
||
|
||
<span class="co"># or as short as:</span>
|
||
<span class="fu"><a href="https://ggplot2.tidyverse.org/reference/ggplot.html">ggplot</a></span>(<span class="kw">a_data_set</span>) <span class="op">+</span>
|
||
<span class="fu"><a href="https://ggplot2.tidyverse.org/reference/geom_bar.html">geom_bar</a></span>(<span class="fu"><a href="https://ggplot2.tidyverse.org/reference/aes.html">aes</a></span>(<span class="kw">year</span>))
|
||
</pre></div>
|
||
<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>
|
||
<div class="sourceCode" id="cb37"><pre class="downlit">
|
||
<span class="fu"><a href="https://ggplot2.tidyverse.org/reference/ggplot.html">ggplot</a></span>(<span class="kw">data_1st</span>) <span class="op">+</span>
|
||
<span class="fu"><a href="../reference/ggplot_rsi.html">geom_rsi</a></span>(translate_ab = <span class="fl">FALSE</span>)
|
||
</pre></div>
|
||
<p><img src="AMR_files/figure-html/plot%203-1.png" width="720"></p>
|
||
<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>
|
||
<div class="sourceCode" id="cb38"><pre class="downlit">
|
||
<span class="co"># group the data on `genus`</span>
|
||
<span class="fu"><a href="https://ggplot2.tidyverse.org/reference/ggplot.html">ggplot</a></span>(<span class="kw">data_1st</span> <span class="op">%>%</span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/group_by.html">group_by</a></span>(<span class="kw">genus</span>)) <span class="op">+</span>
|
||
<span class="co"># create bars with genus on x axis</span>
|
||
<span class="co"># it looks for variables with class `rsi`,</span>
|
||
<span class="co"># of which we have 4 (earlier created with `as.rsi`)</span>
|
||
<span class="fu"><a href="../reference/ggplot_rsi.html">geom_rsi</a></span>(x = <span class="st">"genus"</span>) <span class="op">+</span>
|
||
<span class="co"># split plots on antibiotic</span>
|
||
<span class="fu"><a href="../reference/ggplot_rsi.html">facet_rsi</a></span>(facet = <span class="st">"antibiotic"</span>) <span class="op">+</span>
|
||
<span class="co"># set colours to the R/SI interpretations</span>
|
||
<span class="fu"><a href="../reference/ggplot_rsi.html">scale_rsi_colours</a></span>() <span class="op">+</span>
|
||
<span class="co"># show percentages on y axis</span>
|
||
<span class="fu"><a href="../reference/ggplot_rsi.html">scale_y_percent</a></span>(breaks = <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="co"># turn 90 degrees, to make it bars instead of columns</span>
|
||
<span class="fu"><a href="https://ggplot2.tidyverse.org/reference/coord_flip.html">coord_flip</a></span>() <span class="op">+</span>
|
||
<span class="co"># add labels</span>
|
||
<span class="fu"><a href="https://ggplot2.tidyverse.org/reference/labs.html">labs</a></span>(title = <span class="st">"Resistance per genus and antibiotic"</span>,
|
||
subtitle = <span class="st">"(this is fake data)"</span>) <span class="op">+</span>
|
||
<span class="co"># and print genus in italic to follow our convention</span>
|
||
<span class="co"># (is now y axis because we turned the plot)</span>
|
||
<span class="fu"><a href="https://ggplot2.tidyverse.org/reference/theme.html">theme</a></span>(axis.text.y = <span class="fu"><a href="https://ggplot2.tidyverse.org/reference/element.html">element_text</a></span>(face = <span class="st">"italic"</span>))
|
||
</pre></div>
|
||
<p><img src="AMR_files/figure-html/plot%204-1.png" width="720"></p>
|
||
<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>
|
||
<div class="sourceCode" id="cb39"><pre class="downlit">
|
||
<span class="kw">data_1st</span> <span class="op">%>%</span>
|
||
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/group_by.html">group_by</a></span>(<span class="kw">genus</span>) <span class="op">%>%</span>
|
||
<span class="fu"><a href="../reference/ggplot_rsi.html">ggplot_rsi</a></span>(x = <span class="st">"genus"</span>,
|
||
facet = <span class="st">"antibiotic"</span>,
|
||
breaks = <span class="fl">0</span><span class="op">:</span><span class="fl">4</span> <span class="op">*</span> <span class="fl">25</span>,
|
||
datalabels = <span class="fl">FALSE</span>) <span class="op">+</span>
|
||
<span class="fu"><a href="https://ggplot2.tidyverse.org/reference/coord_flip.html">coord_flip</a></span>()
|
||
</pre></div>
|
||
<p><img src="AMR_files/figure-html/plot%205-1.png" width="720"></p>
|
||
</div>
|
||
<div id="independence-test" class="section level2">
|
||
<h2 class="hasAnchor">
|
||
<a href="#independence-test" class="anchor"></a>Independence test</h2>
|
||
<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 practice AMR analysis.</p>
|
||
<p>We will compare the resistance to fosfomycin (column <code>FOS</code>) in hospital A and D. The input for the <code><a href="https://rdrr.io/r/stats/fisher.test.html">fisher.test()</a></code> can be retrieved with a transformation like this:</p>
|
||
<div class="sourceCode" id="cb40"><pre class="downlit">
|
||
<span class="co"># use package 'tidyr' to pivot data:</span>
|
||
<span class="fu"><a href="https://rdrr.io/r/base/library.html">library</a></span>(<span class="kw"><a href="https://tidyr.tidyverse.org">tidyr</a></span>)
|
||
|
||
<span class="kw">check_FOS</span> <span class="op"><-</span> <span class="kw">example_isolates</span> <span class="op">%>%</span>
|
||
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/filter.html">filter</a></span>(<span class="kw">hospital_id</span> <span class="op">%in%</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span>(<span class="st">"A"</span>, <span class="st">"D"</span>)) <span class="op">%>%</span> <span class="co"># filter on only hospitals A and D</span>
|
||
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/select.html">select</a></span>(<span class="kw">hospital_id</span>, <span class="kw">FOS</span>) <span class="op">%>%</span> <span class="co"># select the hospitals and fosfomycin</span>
|
||
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/group_by.html">group_by</a></span>(<span class="kw">hospital_id</span>) <span class="op">%>%</span> <span class="co"># group on the hospitals</span>
|
||
<span class="fu"><a href="../reference/count.html">count_df</a></span>(combine_SI = <span class="fl">TRUE</span>) <span class="op">%>%</span> <span class="co"># count all isolates per group (hospital_id)</span>
|
||
<span class="fu"><a href="https://tidyr.tidyverse.org/reference/pivot_wider.html">pivot_wider</a></span>(names_from = <span class="kw">hospital_id</span>, <span class="co"># transform output so A and D are columns</span>
|
||
values_from = <span class="kw">value</span>) <span class="op">%>%</span>
|
||
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/select.html">select</a></span>(<span class="kw">A</span>, <span class="kw">D</span>) <span class="op">%>%</span> <span class="co"># and only select these columns</span>
|
||
<span class="fu"><a href="https://rdrr.io/r/base/matrix.html">as.matrix</a></span>() <span class="co"># transform to a good old matrix for fisher.test()</span>
|
||
|
||
<span class="kw">check_FOS</span>
|
||
<span class="co"># A D</span>
|
||
<span class="co"># [1,] 25 77</span>
|
||
<span class="co"># [2,] 24 33</span>
|
||
</pre></div>
|
||
<p>We can apply the test now with:</p>
|
||
<div class="sourceCode" id="cb41"><pre class="downlit">
|
||
<span class="co"># do Fisher's Exact Test</span>
|
||
<span class="fu"><a href="https://rdrr.io/r/stats/fisher.test.html">fisher.test</a></span>(<span class="kw">check_FOS</span>)
|
||
<span class="co"># </span>
|
||
<span class="co"># Fisher's Exact Test for Count Data</span>
|
||
<span class="co"># </span>
|
||
<span class="co"># data: check_FOS</span>
|
||
<span class="co"># p-value = 0.03104</span>
|
||
<span class="co"># alternative hypothesis: true odds ratio is not equal to 1</span>
|
||
<span class="co"># 95 percent confidence interval:</span>
|
||
<span class="co"># 0.2111489 0.9485124</span>
|
||
<span class="co"># sample estimates:</span>
|
||
<span class="co"># odds ratio </span>
|
||
<span class="co"># 0.4488318</span>
|
||
</pre></div>
|
||
<p>As can be seen, the p value is 0.031, which means that the fosfomycin resistance found in isolates from patients in hospital A and D are really different.</p>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="col-md-3 hidden-xs hidden-sm" id="pkgdown-sidebar">
|
||
|
||
<nav id="toc" data-toggle="toc"><h2 data-toc-skip>Contents</h2>
|
||
</nav>
|
||
</div>
|
||
|
||
</div>
|
||
|
||
|
||
|
||
<footer><div class="copyright">
|
||
<p>Developed by <a href="https://www.rug.nl/staff/m.s.berends/">Matthijs S. Berends</a>, <a href="https://www.rug.nl/staff/c.f.luz/">Christian F. Luz</a>, <a href="https://www.rug.nl/staff/a.w.friedrich/">Alexander W. Friedrich</a>, <a href="https://www.rug.nl/staff/b.sinha/">Bhanu N. M. Sinha</a>, <a href="https://www.rug.nl/staff/c.j.albers/">Casper J. Albers</a>, <a href="https://www.rug.nl/staff/c.glasner/">Corinna Glasner</a>.</p>
|
||
</div>
|
||
|
||
<div class="pkgdown">
|
||
<p>Site built with <a href="https://pkgdown.r-lib.org/">pkgdown</a> 1.5.1.9000.</p>
|
||
</div>
|
||
|
||
</footer>
|
||
</div>
|
||
|
||
|
||
|
||
|
||
</body>
|
||
</html>
|