<scriptsrc="../bootstrap-toc.js"></script><!-- Font Awesome icons --><linkrel="stylesheet"href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css"integrity="sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk="crossorigin="anonymous">
<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 <ahref="https://rmarkdown.rstudio.com/"class="external-link">R Markdown</a>. However, the methodology remains unchanged. This page was generated on 04 October 2021.</p>
<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>
<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>
<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>
<p>For this tutorial, we will create fake demonstration data to work with.</p>
<p>You can skip to <ahref="#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>
<ahref="#needed-r-packages"class="anchor"aria-hidden="true"></a>Needed R packages</h2>
<p>As with many uses in R, we need some additional packages for AMR data analysis. Our package works closely together with the <ahref="https://www.tidyverse.org"class="external-link">tidyverse packages</a><ahref="https://dplyr.tidyverse.org/"class="external-link"><code>dplyr</code></a> and <ahref="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 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>
<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>
<codeclass="sourceCode R"><spanclass="va">dates</span><spanclass="op"><-</span><spanclass="fu"><ahref="https://rdrr.io/r/base/seq.html"class="external-link">seq</a></span><spanclass="op">(</span><spanclass="fu"><ahref="https://rdrr.io/r/base/as.Date.html"class="external-link">as.Date</a></span><spanclass="op">(</span><spanclass="st">"2010-01-01"</span><spanclass="op">)</span>, <spanclass="fu"><ahref="https://rdrr.io/r/base/as.Date.html"class="external-link">as.Date</a></span><spanclass="op">(</span><spanclass="st">"2018-01-01"</span><spanclass="op">)</span>, by <spanclass="op">=</span><spanclass="st">"day"</span><spanclass="op">)</span></code></pre></div>
<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>
<p>Using the <code><ahref="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><ahref="../reference/random.html">random_rsi()</a></code> function.</p>
GEN <spanclass="op">=</span><spanclass="fu"><ahref="../reference/random.html">random_rsi</a></span><spanclass="op">(</span><spanclass="va">sample_size</span>, prob_RSI <spanclass="op">=</span><spanclass="fu"><ahref="https://rdrr.io/r/base/c.html"class="external-link">c</a></span><spanclass="op">(</span><spanclass="fl">0.08</span>, <spanclass="fl">0.92</span>, <spanclass="fl">0.00</span><spanclass="op">)</span><spanclass="op">)</span><spanclass="op">)</span></code></pre></div>
<p>Using the <code><ahref="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>
<p>The resulting data set contains 20,000 blood culture isolates. With the <code><ahref="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>
<ahref="#cleaning-the-data"class="anchor"aria-hidden="true"></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><ahref="https://rdrr.io/pkg/cleaner/man/freq.html"class="external-link">freq()</a></code> function can be used to create frequency tables.</p>
<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><ahref="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>
<p>We also want to transform the antibiotics, because in real life data we don’t know if they are really clean. The <code><ahref="../reference/as.rsi.html">as.rsi()</a></code> function ensures reliability and reproducibility in these kind of variables. The <code><ahref="../reference/as.rsi.html">is.rsi.eligible()</a></code> can check which columns are probably columns with R/SI test results. Using <code><ahref="https://dplyr.tidyverse.org/reference/mutate.html"class="external-link">mutate()</a></code> and <code><ahref="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>
<p>Finally, we will apply <ahref="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><ahref="../reference/eucast_rules.html">eucast_rules()</a></code> function can also apply additional rules, like forcing <helptitle="ATC: J01CA01">ampicillin</help> = R when <helptitle="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><ahref="../reference/eucast_rules.html">eucast_rules()</a></code> fixes this:</p>
genus <spanclass="op">=</span><spanclass="fu"><ahref="../reference/mo_property.html">mo_genus</a></span><spanclass="op">(</span><spanclass="va">bacteria</span><spanclass="op">)</span>,
species <spanclass="op">=</span><spanclass="fu"><ahref="../reference/mo_property.html">mo_species</a></span><spanclass="op">(</span><spanclass="va">bacteria</span><spanclass="op">)</span><spanclass="op">)</span></code></pre></div>
<p>To conduct an analysis of antimicrobial resistance, you must <ahref="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 <ahref="https://en.wikipedia.org/wiki/Selection_bias"class="external-link">selection bias</a>.</p>
<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><ahref="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>
<p>This <code>AMR</code> package includes this methodology with the <code><ahref="../reference/first_isolate.html">first_isolate()</a></code> function and is able to apply the four different methods as defined by <ahref="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><ahref="../reference/first_isolate.html">first_isolate()</a></code> page.</p>