AMR/public/index.html

717 lines
65 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!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>Antimicrobial Resistance Analysis • AMR</title>
<!-- jquery --><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script><!-- Bootstrap --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha256-916EbMg70RQy9LHiGkXzG8hSg9EdNy97GazNG/aiY1w=" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha256-U5ZEeKfGNOja007MMD3YBI0A3OSZOQbeG6z2f2Y0hu8=" crossorigin="anonymous"></script><!-- Font Awesome icons --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" integrity="sha256-eZrrJcwDc/3uDhsdt61sL2oOBY362qM3lon1gyExkL0=" crossorigin="anonymous">
<!-- clipboard.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.4/clipboard.min.js" integrity="sha256-FiZwavyI2V6+EXO1U+xzLG3IKldpiTFf3153ea9zikQ=" crossorigin="anonymous"></script><!-- sticky kit --><script src="https://cdnjs.cloudflare.com/ajax/libs/sticky-kit/1.1.3/sticky-kit.min.js" integrity="sha256-c4Rlo1ZozqTPE2RLuvbusY3+SU1pQaJC0TjuhygMipw=" crossorigin="anonymous"></script><!-- pkgdown --><link href="pkgdown.css" rel="stylesheet">
<script src="pkgdown.js"></script><meta property="og:title" content="Antimicrobial Resistance Analysis">
<meta property="og:description" content="Functions to simplify the analysis and prediction of Antimicrobial
Resistance (AMR) and to work with microbial and antimicrobial properties by
using evidence-based methods.">
<meta name="twitter:card" content="summary">
<!-- 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>
<div class="container template-home">
<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</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.5.0.9007</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 fa-lg"></span>
</a>
</li>
<li>
<a href="articles/AMR.html">Get started</a>
</li>
<li>
<a href="reference/index.html">Reference</a>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
Articles
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="articles/freq.html">Creating Frequency Tables</a>
</li>
</ul>
</li>
<li>
<a href="news/index.html">Changelog</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right"></ul>
</div>
<!--/.nav-collapse -->
</div>
<!--/.container -->
</div>
<!--/.navbar -->
</header><div class="row">
<div class="contents col-md-9">
<div id="amr" class="section level1">
<div class="page-header"><h1 class="hasAnchor">
<a href="#amr" class="anchor"></a><code>AMR</code> <img src="reference/figures/logo_amr.png" align="right" height="120px">
</h1></div>
<div id="an-r-package-to-simplify-the-analysis-and-prediction-of-antimicrobial-resistance-amr-and-to-work-with-antibiotic-properties-by-using-evidence-based-methods-" class="section level3">
<h3 class="hasAnchor">
<a href="#an-r-package-to-simplify-the-analysis-and-prediction-of-antimicrobial-resistance-amr-and-to-work-with-antibiotic-properties-by-using-evidence-based-methods-" class="anchor"></a>An <a href="https://www.r-project.org">R package</a> to simplify the analysis and prediction of Antimicrobial Resistance (AMR) and to work with antibiotic properties by using evidence-based methods.</h3>
<p>This R package was created for academic research by PhD students of the Faculty of Medical Sciences of the <a href="https://www.rug.nl">University of Groningen</a> and the Medical Microbiology &amp; Infection Prevention (MMBI) department of the <a href="https://www.umcg.nl">University Medical Center Groningen (UMCG)</a>.</p>
<p>▶️ Get it with <code><a href="https://www.rdocumentation.org/packages/utils/topics/install.packages">install.packages("AMR")</a></code> or see below for other possibilities.</p>
<p>▶️ Read the <a href="https://gitlab.com/msberends/AMR/blob/master/NEWS.md">changelog here</a>.</p>
</div>
<div id="authors" class="section level2">
<h2 class="hasAnchor">
<a href="#authors" class="anchor"></a>Authors</h2>
<p>Matthijs S. Berends <a href="https://orcid.org/0000-0001-7620-1800"><img src="https://cran.r-project.org/web/orcid.svg" height="16px"></a> <sup>1,2,a</sup>, Christian F. Luz <a href="https://orcid.org/0000-0001-5809-5995"><img src="https://cran.r-project.org/web/orcid.svg" height="16px"></a> <sup>1,a</sup>, Erwin E.A. Hassing<sup>2</sup>, Corinna Glasner <a href="https://orcid.org/0000-0003-1241-1328"><img src="https://cran.r-project.org/web/orcid.svg" height="16px"></a> <sup>1,b</sup>, Alex W. Friedrich <a href="https://orcid.org/0000-0003-4881-038X"><img src="https://cran.r-project.org/web/orcid.svg" height="16px"></a> <sup>1,b</sup>, Bhanu N.M. Sinha <a href="https://orcid.org/0000-0003-1634-0010"><img src="https://cran.r-project.org/web/orcid.svg" height="16px"></a> <sup>1,b</sup></p>
<p><sup>1</sup> Department of Medical Microbiology, University of Groningen, University Medical Center Groningen, Groningen, the Netherlands - <a href="http://www.rug.nl">rug.nl</a> <a href="http://www.umcg.nl">umcg.nl</a><br><sup>2</sup> Certe Medical Diagnostics &amp; Advice, Groningen, the Netherlands - <a href="http://www.certe.nl">certe.nl</a><br><sup>a</sup> R package author and thesis dissertant<br><sup>b</sup> Thesis advisor</p>
<p><a href="https://www.rug.nl"><img src="reference/figures/logo_rug.png" height="60px"></a> <a href="https://www.umcg.nl"><img src="reference/figures/logo_umcg.png" height="60px"></a> <a href="https://www.certe.nl"><img src="reference/figures/logo_certe.png" height="60px"></a> <a href="http://www.eurhealth-1health.eu"><img src="reference/figures/logo_eh1h.png" height="60px"></a> <a href="http://www.eurhealth-1health.eu"><img src="reference/figures/logo_interreg.png" height="60px"></a></p>
</div>
<div id="contents" class="section level2">
<h2 class="hasAnchor">
<a href="#contents" class="anchor"></a>Contents</h2>
<ul>
<li><a href="#why-this-package">Why this package?</a></li>
<li><a href="#itis">ITIS</a></li>
<li><a href="#how-to-get-it">How to get it?</a></li>
<li><a href="#install-from-cran">Install from CRAN</a></li>
<li><a href="#install-from-zenodo">Install from Zenodo</a></li>
<li><a href="#install-from-gitlab">Install from GitLab</a></li>
<li><a href="#how-to-use-it">How to use it?</a></li>
<li><a href="#new-classes">New classes</a></li>
<li><a href="#overwriteforce-resistance-based-on-eucast-rules">Overwrite/force resistance based on EUCAST rules</a></li>
<li><a href="#other-microbial-epidemiological-functions">Other (microbial) epidemiological functions</a></li>
<li><a href="#frequency-tables">Frequency tables</a></li>
<li><a href="#data-sets-included-in-package">Data sets included in package</a></li>
<li><a href="#benchmarks">Benchmarks</a></li>
<li><a href="#copyright">Copyright</a></li>
</ul>
</div>
<div id="why-this-package" class="section level2">
<h2 class="hasAnchor">
<a href="#why-this-package" class="anchor"></a>Why this package?</h2>
<p>This R package was intended <strong>to make microbial epidemiology easier</strong>. Most functions contain extensive help pages to get started.</p>
<p>The <code>AMR</code> package basically does four important things:</p>
<ol>
<li>It <strong>cleanses existing data</strong>, by transforming it to reproducible and profound <em>classes</em>, making the most efficient use of R. These functions all use artificial intelligence to guess results that you would expect:</li>
</ol>
<ul>
<li>Use <code>as.mo</code> to get an ID of a microorganism. The IDs are human readable for the trained eye - the ID of <em>Klebsiella pneumoniae</em> is “B_KLBSL_PNE” (B stands for Bacteria) and the ID of <em>S. aureus</em> is “B_STPHY_AUR”. The function takes almost any text as input that looks like the name or code of a microorganism like “E. coli”, “esco” and “esccol”. Even <code><a href="reference/as.mo.html">as.mo("MRSA")</a></code> will return the ID of <em>S. aureus</em>. Moreover, it can group all coagulase negative and positive <em>Staphylococci</em>, and can transform <em>Streptococci</em> into Lancefield groups. To find bacteria based on your input, it uses Artificial Intelligence to look up values in the included ITIS data, consisting of more than 18,000 microorganisms. It is <em>very</em> fast, see <a href="#benchmarks">Benchmarks</a>.</li>
<li>Use <code>as.rsi</code> to transform values to valid antimicrobial results. It produces just S, I or R based on your input and warns about invalid values. Even values like “&lt;=0.002; S” (combined MIC/RSI) will result in “S”.</li>
<li>Use <code>as.mic</code> to cleanse your MIC values. It produces a so-called factor (called <em>ordinal</em> in SPSS) with valid MIC values as levels. A value like “&lt;=0.002; S” (combined MIC/RSI) will result in “&lt;=0.002”.</li>
<li>Use <code>as.atc</code> to get the ATC code of an antibiotic as defined by the WHO. This package contains a database with most LIS codes, official names, DDDs and even trade names of antibiotics. For example, the values “Furabid”, “Furadantin”, “nitro” all return the ATC code of Nitrofurantoine.</li>
</ul>
<ol>
<li>It <strong>enhances existing data</strong> and <strong>adds new data</strong> from data sets included in this package.</li>
</ol>
<ul>
<li>Use <code>EUCAST_rules</code> to apply <a href="http://www.eucast.org/expert_rules_and_intrinsic_resistance/">EUCAST expert rules to isolates</a>.</li>
<li>Use <code>first_isolate</code> to identify the first isolates of every patient <a href="https://clsi.org/standards/products/microbiology/documents/m39/">using guidelines from the CLSI</a> (Clinical and Laboratory Standards Institute).
<ul>
<li>You can also identify first <em>weighted</em> isolates of every patient, an adjusted version of the CLSI guideline. This takes into account key antibiotics of every strain and compares them.</li>
</ul>
</li>
<li>Use <code>MDRO</code> (abbreviation of Multi Drug Resistant Organisms) to check your isolates for exceptional resistance with country-specific guidelines or EUCAST rules. Currently, national guidelines for Germany and the Netherlands are supported.</li>
<li>The data set <code>microorganisms</code> contains the complete taxonomic tree of more than 18,000 microorganisms (bacteria, fungi/yeasts and protozoa). Furthermore, the colloquial name and Gram stain are available, which enables resistance analysis of e.g. different antibiotics per Gram stain. The package also contains functions to look up values in this data set like <code>mo_genus</code>, <code>mo_family</code>, <code>mo_gramstain</code> or even <code>mo_phylum</code>. As they use <code>as.mo</code> internally, they also use artificial intelligence. For example, <code><a href="reference/mo_property.html">mo_genus("MRSA")</a></code> and <code><a href="reference/mo_property.html">mo_genus("S. aureus")</a></code> will both return <code>"Staphylococcus"</code>. They also come with support for German, Dutch, Spanish, Italian, French and Portuguese. These functions can be used to add new variables to your data.</li>
<li>The data set <code>antibiotics</code> contains the ATC code, LIS codes, official name, trivial name and DDD of both oral and parenteral administration. It also contains a total of 298 trade names. Use functions like <code>ab_name</code> and <code>ab_tradenames</code> to look up values. The <code>ab_*</code> functions use <code>as.atc</code> internally so they support AI to guess your expected result. For example, <code><a href="reference/ab_property.html">ab_name("Fluclox")</a></code>, <code><a href="reference/ab_property.html">ab_name("Floxapen")</a></code> and <code><a href="reference/ab_property.html">ab_name("J01CF05")</a></code> will all return <code>"Flucloxacillin"</code>. These functions can again be used to add new variables to your data.</li>
</ul>
<ol>
<li>It <strong>analyses the data</strong> with convenient functions that use well-known methods.</li>
</ol>
<ul>
<li>Calculate the resistance (and even co-resistance) of microbial isolates with the <code>portion_R</code>, <code>portion_IR</code>, <code>portion_I</code>, <code>portion_SI</code> and <code>portion_S</code> functions. Similarly, the <em>number</em> of isolates can be determined with the <code>count_R</code>, <code>count_IR</code>, <code>count_I</code>, <code>count_SI</code> and <code>count_S</code> functions. All these functions can be used <a href="https://dplyr.tidyverse.org/#usage">with the <code>dplyr</code> package</a> (e.g. in conjunction with <a href="https://dplyr.tidyverse.org/reference/summarise.html"><code>summarise</code></a>)</li>
<li>Plot AMR results with <code>geom_rsi</code>, a function made for the <code>ggplot2</code> package</li>
<li>Predict antimicrobial resistance for the nextcoming years using logistic regression models with the <code>resistance_predict</code> function</li>
<li>Conduct descriptive statistics to enhance base R: calculate kurtosis, skewness and create frequency tables</li>
</ul>
<ol>
<li>It <strong>teaches the user</strong> how to use all the above actions.</li>
</ol>
<ul>
<li>The package contains extensive help pages with many examples.</li>
<li>It also contains an example data set called <code>septic_patients</code>. This data set contains:
<ul>
<li>2,000 blood culture isolates from anonymised septic patients between 2001 and 2017 in the Northern Netherlands</li>
<li>Results of 40 antibiotics (each antibiotic in its own column) with a total of 38,414 antimicrobial results</li>
<li>Real and genuine data</li>
</ul>
</li>
</ul>
<div id="itis" class="section level3">
<h3 class="hasAnchor">
<a href="#itis" class="anchor"></a>ITIS</h3>
<p><img src="reference/figures/itis_logo.jpg" height="100px"></p>
<p>This package contains the <strong>complete microbial taxonomic data</strong> (with all nine taxonomic ranks - from kingdom to subspecies) from the publicly available Integrated Taxonomic Information System (ITIS, <a href="https://www.itis.gov" class="uri">https://www.itis.gov</a>).</p>
<p>All (sub)species from <strong>the taxonomic kingdoms Bacteria, Fungi and Protozoa are included in this package</strong>, as well as all previously accepted names known to ITIS. Furthermore, the responsible authors and year of publication are available. This allows users to use authoritative taxonomic information for their data analysis on any microorganism, not only human pathogens. It also helps to quickly determine the Gram stain of bacteria, since all bacteria are classified into subkingdom Negibacteria or Posibacteria.</p>
<p>ITIS is a partnership of U.S., Canadian, and Mexican agencies and taxonomic specialists.</p>
<p><strong>Get a note when a species was renamed</strong></p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw"><a href="reference/mo_property.html">mo_shortname</a></span>(<span class="st">"Chlamydia psittaci"</span>)
<span class="co"># Note: 'Chlamydia psittaci' (Page, 1968) was renamed 'Chlamydophila psittaci' (Everett et al., 1999)</span>
<span class="co"># [1] "C. psittaci"</span></code></pre></div>
<p><strong>Get any property from the entire taxonomic tree for all included species</strong></p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw"><a href="reference/mo_property.html">mo_class</a></span>(<span class="st">"E. coli"</span>)
<span class="co"># [1] "Gammaproteobacteria"</span>
<span class="kw"><a href="reference/mo_property.html">mo_family</a></span>(<span class="st">"E. coli"</span>)
<span class="co"># [1] "Enterobacteriaceae"</span>
<span class="kw"><a href="reference/mo_property.html">mo_subkingdom</a></span>(<span class="st">"E. coli"</span>)
<span class="co"># [1] "Negibacteria"</span>
<span class="kw"><a href="reference/mo_property.html">mo_gramstain</a></span>(<span class="st">"E. coli"</span>) <span class="co"># based on subkingdom</span>
<span class="co"># [1] "Gram negative"</span>
<span class="kw"><a href="reference/mo_property.html">mo_ref</a></span>(<span class="st">"E. coli"</span>)
<span class="co"># [1] "Castellani and Chalmers, 1919"</span></code></pre></div>
<p><strong>Do not get mistaken - the package only includes microorganisms</strong></p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw"><a href="reference/mo_property.html">mo_phylum</a></span>(<span class="st">"C. elegans"</span>)
<span class="co"># [1] "Cyanobacteria" # Bacteria?!</span>
<span class="kw"><a href="reference/mo_property.html">mo_fullname</a></span>(<span class="st">"C. elegans"</span>)
<span class="co"># [1] "Chroococcus limneticus elegans" # Because a microorganism was found </span></code></pre></div>
</div>
</div>
<div id="how-to-get-it" class="section level2">
<h2 class="hasAnchor">
<a href="#how-to-get-it" class="anchor"></a>How to get it?</h2>
<p>All stable versions of this package <a href="http://cran.r-project.org/package=AMR">are published on CRAN</a>, the official R network with a peer-reviewed submission process.</p>
<div id="install-from-cran" class="section level3">
<h3 class="hasAnchor">
<a href="#install-from-cran" class="anchor"></a>Install from CRAN</h3>
<p><a href="http://cran.r-project.org/package=AMR"><img src="https://www.r-pkg.org/badges/version/AMR" alt="CRAN_Badge"></a> <a href="http://cran.r-project.org/package=AMR"><img src="https://cranlogs.r-pkg.org/badges/grand-total/AMR" alt="CRAN_Downloads"></a></p>
<p>(Note: Downloads measured only by <a href="https://cran.rstudio.com/package=AMR">cran.rstudio.com</a>, this excludes e.g. the official <a href="https://cran.r-project.org/package=AMR">cran.r-project.org</a>)</p>
<ul>
<li>
<img src="http://www.rstudio.com/favicon.ico" alt="RStudio favicon" height="20px"> Install using <a href="http://www.rstudio.com">RStudio</a> (recommended):</li>
<li>Click on <code>Tools</code> and then <code>Install Packages...</code>
</li>
<li><p>Type in <code>AMR</code> and press <kbd>Install</kbd></p></li>
<li>
<img src="https://cran.r-project.org/favicon.ico" alt="R favicon" height="20px"> Install in R directly:</li>
<li><p><code><a href="https://www.rdocumentation.org/packages/utils/topics/install.packages">install.packages("AMR")</a></code></p></li>
</ul>
</div>
<div id="install-from-zenodo" class="section level3">
<h3 class="hasAnchor">
<a href="#install-from-zenodo" class="anchor"></a>Install from Zenodo</h3>
<p><a href="https://doi.org/10.5281/zenodo.1305355"><img src="https://zenodo.org/badge/DOI/10.5281/zenodo.1305355.svg" alt="DOI"></a></p>
<p>This package was also published on Zenodo (stable releases only): <a href="https://doi.org/10.5281/zenodo.1305355" class="uri">https://doi.org/10.5281/zenodo.1305355</a></p>
</div>
<div id="install-from-gitlab" class="section level3">
<h3 class="hasAnchor">
<a href="#install-from-gitlab" class="anchor"></a>Install from GitLab</h3>
<p>This is the latest <strong>development version</strong>. Although it may contain bugfixes and even new functions compared to the latest released version on CRAN, it is also subject to change and may be unstable or behave unexpectedly. Always consider this a beta version. All below badges should be green:</p>
<table class="table">
<colgroup>
<col width="5%">
<col width="8%">
<col width="5%">
</colgroup>
<thead><tr class="header">
<th>Development Test</th>
<th align="center">Result</th>
<th>Reference</th>
</tr></thead>
<tbody>
<tr class="odd">
<td>All functions checked on Linux</td>
<td align="center"><a href="https://gitlab.com/msberends/AMR/commits/master"><img src="https://gitlab.com/msberends/AMR/badges/master/pipeline.svg" alt="pipeline status"></a></td>
<td>GitLab CI <a href="https://gitlab.com/msberends/AMR/pipelines">[ref 1]</a>
</td>
</tr>
<tr class="even">
<td>All functions checked on Windows</td>
<td align="center"><a href="https://ci.appveyor.com/project/msberends/amr-svxon"><img src="https://ci.appveyor.com/api/projects/status/gitlab/msberends/AMR?branch=master&amp;svg=true" alt="AppVeyor_Build"></a></td>
<td>Appveyor Systems Inc. <a href="https://ci.appveyor.com/project/msberends/amr-svxon">[ref 2]</a>
</td>
</tr>
<tr class="odd">
<td>Percentage of syntax lines checked</td>
<td align="center"><a href="https://codecov.io/gl/msberends/AMR"><img src="https://codecov.io/gl/msberends/AMR/branch/master/graph/badge.svg" alt="Code_Coverage"></a></td>
<td>Codecov LLC <a href="https://codecov.io/gl/msberends/AMR">[ref 3]</a>
</td>
</tr>
</tbody>
</table>
<p>If so, try it with:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw"><a href="https://www.rdocumentation.org/packages/utils/topics/install.packages">install.packages</a></span>(<span class="st">"devtools"</span>)
devtools::<span class="kw">install_gitlab</span>(<span class="st">"msberends/AMR"</span>)</code></pre></div>
</div>
</div>
<div id="how-to-use-it" class="section level2">
<h2 class="hasAnchor">
<a href="#how-to-use-it" class="anchor"></a>How to use it?</h2>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co"># Call it with:</span>
<span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/library">library</a></span>(AMR)
<span class="co"># For a list of functions:</span>
<span class="kw"><a href="https://www.rdocumentation.org/packages/utils/topics/help">help</a></span>(<span class="dt">package =</span> <span class="st">"AMR"</span>)</code></pre></div>
<div id="new-classes" class="section level3">
<h3 class="hasAnchor">
<a href="#new-classes" class="anchor"></a>New classes</h3>
<p>This package contains two new S3 classes: <code>mic</code> for MIC values (e.g. from Vitek or Phoenix) and <code>rsi</code> for antimicrobial drug interpretations (i.e. S, I and R). Both are actually ordered factors under the hood (an MIC of <code>2</code> being higher than <code>&lt;=1</code> but lower than <code>&gt;=32</code>, and for class <code>rsi</code> factors are ordered as <code>S &lt; I &lt; R</code>). Both classes have extensions for existing generic functions like <code>print</code>, <code>summary</code> and <code>plot</code>.</p>
<p>These functions also try to coerce valid values.</p>
<div id="rsi" class="section level4">
<h4 class="hasAnchor">
<a href="#rsi" class="anchor"></a>RSI</h4>
<p>The <code>septic_patients</code> data set comes with antimicrobial results of more than 40 different drugs. For example, columns <code>amox</code> and <code>cipr</code> contain results of amoxicillin and ciprofloxacin, respectively.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/summary">summary</a></span>(septic_patients[, <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="st">"amox"</span>, <span class="st">"cipr"</span>)])
<span class="co"># amox cipr </span>
<span class="co"># Mode :rsi Mode :rsi </span>
<span class="co"># &lt;NA&gt; :1002 &lt;NA&gt; :596 </span>
<span class="co"># Sum S :336 Sum S :1108 </span>
<span class="co"># Sum IR:662 Sum IR:296 </span>
<span class="co"># -Sum R:659 -Sum R:227 </span>
<span class="co"># -Sum I:3 -Sum I:69 </span></code></pre></div>
<p>You can use the <code>plot</code> function from base R:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw"><a href="https://www.rdocumentation.org/packages/graphics/topics/plot">plot</a></span>(septic_patients$cipr)</code></pre></div>
<p><img src="reference/figures/rsi_example1.png" alt="example_1_rsi"></p>
<p>Or use the <code>ggplot2</code> and <code>dplyr</code> packages to create more appealing plots:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/library">library</a></span>(dplyr)
<span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/library">library</a></span>(ggplot2)
septic_patients %&gt;%
<span class="st"> </span><span class="kw"><a href="http://dplyr.tidyverse.org/reference/select.html">select</a></span>(amox, nitr, fosf, trim, cipr) %&gt;%
<span class="st"> </span><span class="kw"><a href="reference/ggplot_rsi.html">ggplot_rsi</a></span>()</code></pre></div>
<p><img src="reference/figures/rsi_example2.png" alt="example_2_rsi"></p>
<p>Adjust it with any parameter you know from the <code>ggplot2</code> package:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">septic_patients %&gt;%
<span class="st"> </span><span class="kw"><a href="http://dplyr.tidyverse.org/reference/select.html">select</a></span>(amox, nitr, fosf, trim, cipr) %&gt;%
<span class="st"> </span><span class="kw"><a href="reference/ggplot_rsi.html">ggplot_rsi</a></span>(<span class="dt">datalabels =</span> <span class="ot">FALSE</span>,
<span class="dt">width =</span> <span class="fl">0.5</span>, <span class="dt">colour =</span> <span class="st">"purple"</span>, <span class="dt">size =</span> <span class="dv">1</span>, <span class="dt">linetype =</span> <span class="dv">2</span>, <span class="dt">alpha =</span> <span class="fl">0.5</span>)</code></pre></div>
<p><img src="reference/figures/rsi_example3.png" alt="example_3_rsi"></p>
<p>It also supports grouping variables. Lets say we want to compare resistance of drugs against Urine Tract Infections (UTI) between hospitals A to D (variable <code>hospital_id</code>):</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">septic_patients %&gt;%
<span class="st"> </span><span class="kw"><a href="http://dplyr.tidyverse.org/reference/select.html">select</a></span>(hospital_id, amox, nitr, fosf, trim, cipr) %&gt;%
<span class="st"> </span><span class="kw"><a href="http://dplyr.tidyverse.org/reference/group_by.html">group_by</a></span>(hospital_id) %&gt;%
<span class="st"> </span><span class="kw"><a href="reference/ggplot_rsi.html">ggplot_rsi</a></span>(<span class="dt">x =</span> <span class="st">"hospital_id"</span>,
<span class="dt">facet =</span> <span class="st">"Antibiotic"</span>,
<span class="dt">nrow =</span> <span class="dv">1</span>,
<span class="dt">datalabels =</span> <span class="ot">FALSE</span>) +
<span class="st"> </span><span class="kw"><a href="https://ggplot2.tidyverse.org/reference/labs.html">labs</a></span>(<span class="dt">title =</span> <span class="st">"AMR of Anti-UTI Drugs Per Hospital"</span>,
<span class="dt">x =</span> <span class="st">"Hospital"</span>)</code></pre></div>
<p><img src="reference/figures/rsi_example4.png" alt="example_4_rsi"></p>
<p>You could use this to group on anything in your plots: Gram stain, age (group), genus, geographic location, et cetera.</p>
<p>Is there a significant difference between hospital A and D when it comes to Fosfomycin?</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">check_A_and_D &lt;-<span class="st"> </span>septic_patients %&gt;%
<span class="st"> </span><span class="kw"><a href="http://dplyr.tidyverse.org/reference/filter.html">filter</a></span>(hospital_id %in%<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="st">"A"</span>, <span class="st">"D"</span>)) %&gt;%<span class="st"> </span><span class="co"># filter on only hospitals A and D</span>
<span class="st"> </span><span class="kw"><a href="http://dplyr.tidyverse.org/reference/select.html">select</a></span>(hospital_id, fosf) %&gt;%<span class="st"> </span><span class="co"># select the hospitals and fosfomycin</span>
<span class="st"> </span><span class="kw"><a href="http://dplyr.tidyverse.org/reference/group_by.html">group_by</a></span>(hospital_id) %&gt;%
<span class="st"> </span><span class="kw"><a href="reference/count.html">count_df</a></span>(<span class="dt">combine_IR =</span> <span class="ot">TRUE</span>) %&gt;%<span class="st"> </span><span class="co"># count all isolates per group (hospital_id)</span>
<span class="st"> </span>tidyr::<span class="kw">spread</span>(hospital_id, Value) %&gt;%<span class="st"> </span><span class="co"># transform output so A and D are columns</span>
<span class="st"> </span><span class="kw"><a href="http://dplyr.tidyverse.org/reference/select.html">select</a></span>(A, D) %&gt;%<span class="st"> </span><span class="co"># and select these only</span>
<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/matrix">as.matrix</a></span>() <span class="co"># transform to good old matrix for fisher.test</span>
check_A_and_D
<span class="co"># A D</span>
<span class="co"># [1,] 24 33</span>
<span class="co"># [2,] 25 77</span></code></pre></div>
<p>Total sum is lower than 1,000 so wed prefer a <a href="https://en.wikipedia.org/wiki/Fisher%27s_exact_test">Fishers exact test</a>, not a <a href="https://en.wikipedia.org/wiki/G-test"><em>G</em>-test</a> (or its formerly used equivalent, the famous <a href="https://en.wikipedia.org/wiki/Chi-squared_test">Chi<sup>2</sup> test</a>):</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw"><a href="https://www.rdocumentation.org/packages/stats/topics/fisher.test">fisher.test</a></span>(check_A_and_D)
<span class="co"># </span>
<span class="co"># Fisher's Exact Test for Count Data</span>
<span class="co"># </span>
<span class="co"># data: check_A_and_D</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"># 1.054283 4.735995</span>
<span class="co"># sample estimates:</span>
<span class="co"># odds ratio </span>
<span class="co"># 2.228006 </span></code></pre></div>
<p>Well, there you go!</p>
</div>
<div id="mic" class="section level4">
<h4 class="hasAnchor">
<a href="#mic" class="anchor"></a>MIC</h4>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co"># Transform values to new class</span>
mic_data &lt;-<span class="st"> </span><span class="kw"><a href="reference/as.mic.html">as.mic</a></span>(<span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="st">"&gt;=32"</span>, <span class="st">"1.0"</span>, <span class="st">"8"</span>, <span class="st">"&lt;=0.128"</span>, <span class="st">"8"</span>, <span class="st">"16"</span>, <span class="st">"16"</span>))
<span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/summary">summary</a></span>(mic_data)
<span class="co"># Mode:mic </span>
<span class="co"># &lt;NA&gt;:0 </span>
<span class="co"># Min.:&lt;=0.128 </span>
<span class="co"># Max.:&gt;=32 </span>
<span class="kw"><a href="https://www.rdocumentation.org/packages/graphics/topics/plot">plot</a></span>(mic_data)</code></pre></div>
<p><img src="reference/figures/mic_example.png" alt="example_mic"></p>
</div>
</div>
<div id="overwriteforce-resistance-based-on-eucast-rules" class="section level3">
<h3 class="hasAnchor">
<a href="#overwriteforce-resistance-based-on-eucast-rules" class="anchor"></a>Overwrite/force resistance based on EUCAST rules</h3>
<p>This is also called <em>interpretive reading</em>.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">a &lt;-<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/data.frame">data.frame</a></span>(<span class="dt">mo =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="st">"Staphylococcus aureus"</span>,
<span class="st">"Enterococcus faecalis"</span>,
<span class="st">"Escherichia coli"</span>,
<span class="st">"Klebsiella pneumoniae"</span>,
<span class="st">"Pseudomonas aeruginosa"</span>),
<span class="dt">vanc =</span> <span class="st">"-"</span>, <span class="co"># Vancomycin</span>
<span class="dt">amox =</span> <span class="st">"-"</span>, <span class="co"># Amoxicillin</span>
<span class="dt">coli =</span> <span class="st">"-"</span>, <span class="co"># Colistin</span>
<span class="dt">cfta =</span> <span class="st">"-"</span>, <span class="co"># Ceftazidime</span>
<span class="dt">cfur =</span> <span class="st">"-"</span>, <span class="co"># Cefuroxime</span>
<span class="dt">peni =</span> <span class="st">"S"</span>, <span class="co"># Benzylpenicillin</span>
<span class="dt">cfox =</span> <span class="st">"S"</span>, <span class="co"># Cefoxitin</span>
<span class="dt">stringsAsFactors =</span> <span class="ot">FALSE</span>)
a
<span class="co"># mo vanc amox coli cfta cfur peni cfox</span>
<span class="co"># 1 Staphylococcus aureus - - - - - S S</span>
<span class="co"># 2 Enterococcus faecalis - - - - - S S</span>
<span class="co"># 3 Escherichia coli - - - - - S S</span>
<span class="co"># 4 Klebsiella pneumoniae - - - - - S S</span>
<span class="co"># 5 Pseudomonas aeruginosa - - - - - S S</span>
b &lt;-<span class="st"> </span><span class="kw"><a href="reference/eucast_rules.html">EUCAST_rules</a></span>(a) <span class="co"># 18 results are forced as R or S</span>
b
<span class="co"># mo vanc amox coli cfta cfur peni cfox</span>
<span class="co"># 1 Staphylococcus aureus - S R R S S S</span>
<span class="co"># 2 Enterococcus faecalis - - R R R S R</span>
<span class="co"># 3 Escherichia coli R - - - - R S</span>
<span class="co"># 4 Klebsiella pneumoniae R R - - - R S</span>
<span class="co"># 5 Pseudomonas aeruginosa R R - - R R R</span></code></pre></div>
<p>Bacteria IDs can be retrieved with the <code>guess_mo</code> function. It uses any type of info about a microorganism as input. For example, all these will return value <code>B_STPHY_AUR</code>, the ID of <em>S. aureus</em>:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw"><a href="reference/as.mo.html">guess_mo</a></span>(<span class="st">"stau"</span>)
<span class="kw"><a href="reference/as.mo.html">guess_mo</a></span>(<span class="st">"STAU"</span>)
<span class="kw"><a href="reference/as.mo.html">guess_mo</a></span>(<span class="st">"staaur"</span>)
<span class="kw"><a href="reference/as.mo.html">guess_mo</a></span>(<span class="st">"S. aureus"</span>)
<span class="kw"><a href="reference/as.mo.html">guess_mo</a></span>(<span class="st">"S aureus"</span>)
<span class="kw"><a href="reference/as.mo.html">guess_mo</a></span>(<span class="st">"Staphylococcus aureus"</span>)
<span class="kw"><a href="reference/as.mo.html">guess_mo</a></span>(<span class="st">"MRSA"</span>) <span class="co"># Methicillin Resistant S. aureus</span>
<span class="kw"><a href="reference/as.mo.html">guess_mo</a></span>(<span class="st">"MSSA"</span>) <span class="co"># Methicillin Susceptible S. aureus</span>
<span class="kw"><a href="reference/as.mo.html">guess_mo</a></span>(<span class="st">"VISA"</span>) <span class="co"># Vancomycin Intermediate S. aureus</span>
<span class="kw"><a href="reference/as.mo.html">guess_mo</a></span>(<span class="st">"VRSA"</span>) <span class="co"># Vancomycin Resistant S. aureus</span></code></pre></div>
</div>
<div id="other-microbial-epidemiological-functions" class="section level3">
<h3 class="hasAnchor">
<a href="#other-microbial-epidemiological-functions" class="anchor"></a>Other (microbial) epidemiological functions</h3>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co"># G-test to replace Chi squared test</span>
<span class="kw"><a href="reference/g.test.html">g.test</a></span>(...)
<span class="co"># Determine key antibiotic based on bacteria ID</span>
<span class="kw"><a href="reference/key_antibiotics.html">key_antibiotics</a></span>(...)
<span class="co"># Selection of first isolates of any patient</span>
<span class="kw"><a href="reference/first_isolate.html">first_isolate</a></span>(...)
<span class="co"># Predict resistance levels of antibiotics</span>
<span class="kw"><a href="reference/resistance_predict.html">resistance_predict</a></span>(...)
<span class="co"># Get name of antibiotic by ATC code</span>
<span class="kw"><a href="reference/abname.html">abname</a></span>(...)
<span class="kw"><a href="reference/abname.html">abname</a></span>(<span class="st">"J01CR02"</span>, <span class="dt">from =</span> <span class="st">"atc"</span>, <span class="dt">to =</span> <span class="st">"umcg"</span>) <span class="co"># "AMCL"</span></code></pre></div>
</div>
<div id="frequency-tables" class="section level3">
<h3 class="hasAnchor">
<a href="#frequency-tables" class="anchor"></a>Frequency tables</h3>
<p>Base R lacks a simple function to create frequency tables. We created such a function that works with almost all data types: <code>freq</code> (or <code>frequency_tbl</code>). It can be used in two ways:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co"># Like base R:</span>
<span class="kw"><a href="reference/freq.html">freq</a></span>(mydata$myvariable)
<span class="co"># And like tidyverse:</span>
mydata %&gt;%<span class="st"> </span><span class="kw"><a href="reference/freq.html">freq</a></span>(myvariable)</code></pre></div>
<p>Frequency are of course sorted by count at default:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">septic_patients %&gt;%<span class="st"> </span><span class="kw"><a href="reference/freq.html">freq</a></span>(hospital_id)
<span class="co"># Class: factor (numeric)</span>
<span class="co"># Length: 2000 (of which NA: 0 = 0.00%)</span>
<span class="co"># Unique: 4</span>
<span class="co"># </span>
<span class="co"># Item Count Percent Cum. Count Cum. Percent</span>
<span class="co"># --- ----- ------ -------- ----------- -------------</span>
<span class="co"># 1 D 762 38.1% 762 38.1%</span>
<span class="co"># 2 B 663 33.1% 1425 71.2%</span>
<span class="co"># 3 A 321 16.1% 1746 87.3%</span>
<span class="co"># 4 C 254 12.7% 2000 100.0%</span></code></pre></div>
<p>This can be changed with the <code>sort.count</code> parameter:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">septic_patients %&gt;%<span class="st"> </span><span class="kw"><a href="reference/freq.html">freq</a></span>(hospital_id, <span class="dt">sort.count =</span> <span class="ot">FALSE</span>)
<span class="co"># Class: factor (numeric)</span>
<span class="co"># Length: 2000 (of which NA: 0 = 0.00%)</span>
<span class="co"># Unique: 4</span>
<span class="co"># </span>
<span class="co"># Item Count Percent Cum. Count Cum. Percent</span>
<span class="co"># --- ----- ------ -------- ----------- -------------</span>
<span class="co"># 1 A 321 16.1% 321 16.1%</span>
<span class="co"># 2 B 663 33.1% 984 49.2%</span>
<span class="co"># 3 C 254 12.7% 1238 61.9%</span>
<span class="co"># 4 D 762 38.1% 2000 100.0%</span></code></pre></div>
<p>For numeric values, some extra descriptive statistics will be calculated:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw"><a href="reference/freq.html">freq</a></span>(<span class="kw"><a href="https://www.rdocumentation.org/packages/stats/topics/Uniform">runif</a></span>(<span class="dt">n =</span> <span class="dv">10</span>, <span class="dt">min =</span> <span class="dv">1</span>, <span class="dt">max =</span> <span class="dv">5</span>))
<span class="co"># Frequency table </span>
<span class="co"># Class: numeric</span>
<span class="co"># Length: 10 (of which NA: 0 = 0.00%)</span>
<span class="co"># Unique: 10</span>
<span class="co"># </span>
<span class="co"># Mean: 3.1</span>
<span class="co"># Std. dev.: 1.3 (CV: 0.43, MAD: 1.8)</span>
<span class="co"># Five-Num: 1.3 | 1.7 | 3.2 | 4.3 | 5.0 (IQR: 2.6, CQV: 0.43)</span>
<span class="co"># Outliers: 0</span>
<span class="co"># </span>
<span class="co"># Item Count Percent Cum. Count Cum. Percent</span>
<span class="co"># --- --------- ------ -------- ----------- -------------</span>
<span class="co"># 1 1.271079 1 10.0% 1 10.0%</span>
<span class="co"># 2 1.333975 1 10.0% 2 20.0%</span>
<span class="co"># 3 1.714946 1 10.0% 3 30.0%</span>
<span class="co"># 4 2.751871 1 10.0% 4 40.0%</span>
<span class="co"># 5 3.090140 1 10.0% 5 50.0%</span>
<span class="co"># 6 3.260850 1 10.0% 6 60.0%</span>
<span class="co"># 7 3.824105 1 10.0% 7 70.0%</span>
<span class="co"># 8 4.278028 1 10.0% 8 80.0%</span>
<span class="co"># 9 4.436265 1 10.0% 9 90.0%</span>
<span class="co"># 10 4.996694 1 10.0% 10 100.0%</span>
<span class="co"># </span>
<span class="co"># Warning message:</span>
<span class="co"># All observations are unique. </span></code></pre></div>
<p>Learn more about this function with:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><a href="reference/freq.html">?freq</a></code></pre></div>
</div>
<div id="data-sets-included-in-package" class="section level3">
<h3 class="hasAnchor">
<a href="#data-sets-included-in-package" class="anchor"></a>Data sets included in package</h3>
<p>Data sets to work with antibiotics and bacteria properties.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co"># Data set with complete taxonomic trees from ITIS, containing of </span>
<span class="co"># the three kingdoms Bacteria, Fungi and Protozoa</span>
microorganisms <span class="co"># data.frame: 18,833 x 15</span>
microorganisms.old <span class="co"># data.frame: 2,383 x 4</span>
<span class="co"># Data set with ATC antibiotics codes, official names, trade names </span>
<span class="co"># and DDDs (oral and parenteral)</span>
antibiotics <span class="co"># data.frame: 423 x 18</span>
<span class="co"># Data set with 2000 random blood culture isolates from anonymised</span>
<span class="co"># septic patients between 2001 and 2017 in 5 Dutch hospitals</span>
septic_patients <span class="co"># data.frame: 2,000 x 49</span></code></pre></div>
</div>
</div>
<div id="benchmarks" class="section level2">
<h2 class="hasAnchor">
<a href="#benchmarks" class="anchor"></a>Benchmarks</h2>
<p>One of the most important features of this package is the complete microbial taxonomic database, supplied by ITIS (<a href="https://www.itis.gov" class="uri">https://www.itis.gov</a>). We created a function <code>as.mo</code> that transforms any user input value to a valid microbial ID by using AI (Artificial Intelligence) and based on the taxonomic tree of ITIS.</p>
<p>Using the <code>microbenchmark</code> package, we can review the calculation performance of this function.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/library">library</a></span>(microbenchmark)</code></pre></div>
<p>In the next test, we try to coerce different input values for <em>Staphylococcus aureus</em>. The actual result is the same every time: it returns its MO code <code>B_STPHY_AUR</code> (<em>B</em> stands for <em>Bacteria</em>, the taxonomic kingdom).</p>
<p>But the calculation time differs a lot. Here, the AI effect can be reviewed best:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw"><a href="https://www.rdocumentation.org/packages/microbenchmark/topics/microbenchmark">microbenchmark</a></span>(<span class="dt">A =</span> <span class="kw"><a href="reference/as.mo.html">as.mo</a></span>(<span class="st">"stau"</span>),
<span class="dt">B =</span> <span class="kw"><a href="reference/as.mo.html">as.mo</a></span>(<span class="st">"staaur"</span>),
<span class="dt">C =</span> <span class="kw"><a href="reference/as.mo.html">as.mo</a></span>(<span class="st">"S. aureus"</span>),
<span class="dt">D =</span> <span class="kw"><a href="reference/as.mo.html">as.mo</a></span>(<span class="st">"S. aureus"</span>),
<span class="dt">E =</span> <span class="kw"><a href="reference/as.mo.html">as.mo</a></span>(<span class="st">"STAAUR"</span>),
<span class="dt">F =</span> <span class="kw"><a href="reference/as.mo.html">as.mo</a></span>(<span class="st">"Staphylococcus aureus"</span>),
<span class="dt">G =</span> <span class="kw"><a href="reference/as.mo.html">as.mo</a></span>(<span class="st">"B_STPHY_AUR"</span>),
<span class="dt">times =</span> <span class="dv">10</span>,
<span class="dt">unit =</span> <span class="st">"ms"</span>)
<span class="co"># Unit: milliseconds</span>
<span class="co"># expr min lq mean median uq max neval</span>
<span class="co"># A 34.745551 34.798630 35.2596102 34.8994810 35.258325 38.067062 10</span>
<span class="co"># B 7.095386 7.125348 7.2219948 7.1613865 7.240377 7.495857 10</span>
<span class="co"># C 11.677114 11.733826 11.8304789 11.7715050 11.843756 12.317559 10</span>
<span class="co"># D 11.694435 11.730054 11.9859313 11.8775585 12.206371 12.750016 10</span>
<span class="co"># E 7.044402 7.117387 7.2271630 7.1923610 7.246104 7.742396 10</span>
<span class="co"># F 6.642326 6.778446 6.8988042 6.8753165 6.923577 7.513945 10</span>
<span class="co"># G 0.106788 0.131023 0.1351229 0.1357725 0.144014 0.146458 10</span></code></pre></div>
<p>In the table above, all measurements are shown in milliseconds (thousands of seconds), tested on a quite regular Linux server from 2007 (Core 2 Duo 2.7 GHz, 2 GB DDR2 RAM). A value of 6.9 milliseconds means it will roughly determine 144 input values per second. It case of 39.2 milliseconds, this is only 26 input values per second. The more an input value resembles a full name (like C, D and F), the faster the result will be found. In case of G, the input is already a valid MO code, so it only almost takes no time at all (0.0001 seconds on our server).</p>
<p>To achieve this speed, the <code>as.mo</code> function also takes into account the prevalence of human pathogenic microorganisms. The downside is of course that less prevalent microorganisms will be determined far less faster. See this example for the ID of <em>Burkholderia nodosa</em> (<code>B_BRKHL_NOD</code>):</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw"><a href="https://www.rdocumentation.org/packages/microbenchmark/topics/microbenchmark">microbenchmark</a></span>(<span class="dt">A =</span> <span class="kw"><a href="reference/as.mo.html">as.mo</a></span>(<span class="st">"buno"</span>),
<span class="dt">B =</span> <span class="kw"><a href="reference/as.mo.html">as.mo</a></span>(<span class="st">"burnod"</span>),
<span class="dt">C =</span> <span class="kw"><a href="reference/as.mo.html">as.mo</a></span>(<span class="st">"B. nodosa"</span>),
<span class="dt">D =</span> <span class="kw"><a href="reference/as.mo.html">as.mo</a></span>(<span class="st">"B. nodosa"</span>),
<span class="dt">E =</span> <span class="kw"><a href="reference/as.mo.html">as.mo</a></span>(<span class="st">"BURNOD"</span>),
<span class="dt">F =</span> <span class="kw"><a href="reference/as.mo.html">as.mo</a></span>(<span class="st">"Burkholderia nodosa"</span>),
<span class="dt">G =</span> <span class="kw"><a href="reference/as.mo.html">as.mo</a></span>(<span class="st">"B_BRKHL_NOD"</span>),
<span class="dt">times =</span> <span class="dv">10</span>,
<span class="dt">unit =</span> <span class="st">"ms"</span>)
<span class="co"># Unit: milliseconds</span>
<span class="co"># expr min lq mean median uq max neval</span>
<span class="co"># A 124.175427 124.474837 125.8610536 125.3750560 126.160945 131.485994 10</span>
<span class="co"># B 154.249713 155.364729 160.9077032 156.8738940 157.136183 197.315105 10</span>
<span class="co"># C 66.066571 66.162393 66.5538611 66.4488130 66.698077 67.623404 10</span>
<span class="co"># D 86.747693 86.918665 90.7831016 87.8149725 89.440982 116.767991 10</span>
<span class="co"># E 154.863827 155.208563 162.6535954 158.4062465 168.593785 187.378088 10</span>
<span class="co"># F 32.427028 32.638648 32.9929454 32.7860475 32.992813 34.674241 10</span>
<span class="co"># G 0.213155 0.216578 0.2369226 0.2338985 0.253734 0.285581 10</span></code></pre></div>
<p>That takes up to 11 times as much time! A value of 158.4 milliseconds means it can only determine ~6 different input values per second. We can conclude that looking up arbitrary codes of less prevalent microorganisms is the worst way to go, in terms of calculation performance.</p>
<p>To relieve this pitfall and further improve performance, two important calculations take almost no time at all: <strong>repetive results</strong> and <strong>already precalculated results</strong>.</p>
<p>Repetive results mean that unique values are present more than once. Unique values will only be calculated once by <code>as.mo</code>. We will use <code>mo_fullname</code> for this test - a helper function that returns the full microbial name (genus, species and possibly subspecies) and uses <code>as.mo</code> internally.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/library">library</a></span>(dplyr)
<span class="co"># take 500,000 random MO codes from the septic_patients data set</span>
x =<span class="st"> </span>septic_patients %&gt;%
<span class="st"> </span><span class="kw"><a href="http://dplyr.tidyverse.org/reference/sample.html">sample_n</a></span>(<span class="dv">500000</span>, <span class="dt">replace =</span> <span class="ot">TRUE</span>) %&gt;%
<span class="st"> </span><span class="kw"><a href="http://dplyr.tidyverse.org/reference/pull.html">pull</a></span>(mo)
<span class="co"># got the right length?</span>
<span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/length">length</a></span>(x)
<span class="co"># [1] 500000</span>
<span class="co"># and how many unique values do we have?</span>
<span class="kw"><a href="http://dplyr.tidyverse.org/reference/n_distinct.html">n_distinct</a></span>(x)
<span class="co"># [1] 96</span>
<span class="co"># only 96, but distributed in 500,000 results. now let's see:</span>
<span class="kw"><a href="https://www.rdocumentation.org/packages/microbenchmark/topics/microbenchmark">microbenchmark</a></span>(<span class="dt">X =</span> <span class="kw"><a href="reference/mo_property.html">mo_fullname</a></span>(x),
<span class="dt">times =</span> <span class="dv">10</span>,
<span class="dt">unit =</span> <span class="st">"ms"</span>)
<span class="co"># Unit: milliseconds</span>
<span class="co"># expr min lq mean median uq max neval</span>
<span class="co"># X 114.9342 117.1076 129.6448 120.2047 131.5005 168.6371 10</span></code></pre></div>
<p>So transforming 500,000 values (!) of 96 unique values only takes 0.12 seconds (120 ms). You only lose time on your unique input values.</p>
<p>Results of a tenfold - 5,000,000 values:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co"># Unit: milliseconds</span>
<span class="co"># expr min lq mean median uq max neval</span>
<span class="co"># X 882.9045 901.3011 1001.677 940.3421 1168.088 1226.846 10</span></code></pre></div>
<p>Even the full names of 5 <em>Million</em> values are calculated within a second.</p>
<p>What about precalculated results? If the input is an already precalculated result of a helper function like <code>mo_fullname</code>, it almost doesnt take any time at all (see C below):</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw"><a href="https://www.rdocumentation.org/packages/microbenchmark/topics/microbenchmark">microbenchmark</a></span>(<span class="dt">A =</span> <span class="kw"><a href="reference/mo_property.html">mo_fullname</a></span>(<span class="st">"B_STPHY_AUR"</span>),
<span class="dt">B =</span> <span class="kw"><a href="reference/mo_property.html">mo_fullname</a></span>(<span class="st">"S. aureus"</span>),
<span class="dt">C =</span> <span class="kw"><a href="reference/mo_property.html">mo_fullname</a></span>(<span class="st">"Staphylococcus aureus"</span>),
<span class="dt">times =</span> <span class="dv">10</span>,
<span class="dt">unit =</span> <span class="st">"ms"</span>)
<span class="co"># Unit: milliseconds</span>
<span class="co"># expr min lq mean median uq max neval</span>
<span class="co"># A 11.364086 11.460537 11.5104799 11.4795330 11.524860 11.818263 10</span>
<span class="co"># B 11.976454 12.012352 12.1704592 12.0853020 12.210004 12.881737 10</span>
<span class="co"># C 0.095823 0.102528 0.1167754 0.1153785 0.132629 0.140661 10</span></code></pre></div>
<p>So going from <code><a href="reference/mo_property.html">mo_fullname("Staphylococcus aureus")</a></code> to <code>"Staphylococcus aureus"</code> takes 0.0001 seconds - it doesnt even start calculating <em>if the result would be the same as the expected resulting value</em>. That goes for all helper functions:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw"><a href="https://www.rdocumentation.org/packages/microbenchmark/topics/microbenchmark">microbenchmark</a></span>(<span class="dt">A =</span> <span class="kw"><a href="reference/mo_property.html">mo_species</a></span>(<span class="st">"aureus"</span>),
<span class="dt">B =</span> <span class="kw"><a href="reference/mo_property.html">mo_genus</a></span>(<span class="st">"Staphylococcus"</span>),
<span class="dt">C =</span> <span class="kw"><a href="reference/mo_property.html">mo_fullname</a></span>(<span class="st">"Staphylococcus aureus"</span>),
<span class="dt">D =</span> <span class="kw"><a href="reference/mo_property.html">mo_family</a></span>(<span class="st">"Staphylococcaceae"</span>),
<span class="dt">E =</span> <span class="kw"><a href="reference/mo_property.html">mo_order</a></span>(<span class="st">"Bacillales"</span>),
<span class="dt">F =</span> <span class="kw"><a href="reference/mo_property.html">mo_class</a></span>(<span class="st">"Bacilli"</span>),
<span class="dt">G =</span> <span class="kw"><a href="reference/mo_property.html">mo_phylum</a></span>(<span class="st">"Firmicutes"</span>),
<span class="dt">H =</span> <span class="kw"><a href="reference/mo_property.html">mo_subkingdom</a></span>(<span class="st">"Posibacteria"</span>),
<span class="dt">I =</span> <span class="kw"><a href="reference/mo_property.html">mo_kingdom</a></span>(<span class="st">"Bacteria"</span>),
<span class="dt">times =</span> <span class="dv">10</span>,
<span class="dt">unit =</span> <span class="st">"ms"</span>)
<span class="co"># Unit: milliseconds</span>
<span class="co"># expr min lq mean median uq max neval</span>
<span class="co"># A 0.105181 0.121314 0.1478538 0.1465265 0.166711 0.211409 10</span>
<span class="co"># B 0.132558 0.146388 0.1584278 0.1499835 0.164895 0.208477 10</span>
<span class="co"># C 0.135492 0.160355 0.2341847 0.1884665 0.348857 0.395931 10</span>
<span class="co"># D 0.109650 0.115727 0.1270481 0.1264130 0.128648 0.168317 10</span>
<span class="co"># E 0.081574 0.096940 0.0992582 0.0980915 0.101479 0.120477 10</span>
<span class="co"># F 0.081575 0.088489 0.0988463 0.0989650 0.103365 0.126482 10</span>
<span class="co"># G 0.091981 0.095333 0.1043568 0.1001530 0.111327 0.129625 10</span>
<span class="co"># H 0.092610 0.093169 0.1009135 0.0985455 0.101828 0.120406 10</span>
<span class="co"># I 0.087371 0.091213 0.1069758 0.0941815 0.109302 0.192831 10</span></code></pre></div>
<p>Of course, when running <code><a href="reference/mo_property.html">mo_phylum("Firmicutes")</a></code> the function has zero knowledge about the actual microorganism, namely <em>S. aureus</em>. But since the result would be <code>"Firmicutes"</code> too, there is no point in calculating the result. And because this package knows all phyla of all known microorganisms (according to ITIS), it can just return the initial value immediately.</p>
<p>When the system language is non-English and supported by this <code>AMR</code> package, some functions take a little while longer:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw"><a href="reference/mo_property.html">mo_fullname</a></span>(<span class="st">"CoNS"</span>, <span class="dt">language =</span> <span class="st">"en"</span>) <span class="co"># or just mo_fullname("CoNS") on an English system</span>
<span class="co"># "Coagulase Negative Staphylococcus (CoNS)"</span>
<span class="kw"><a href="reference/mo_property.html">mo_fullname</a></span>(<span class="st">"CoNS"</span>, <span class="dt">language =</span> <span class="st">"fr"</span>) <span class="co"># or just mo_fullname("CoNS") on a French system</span>
<span class="co"># "Staphylococcus à coagulase négative (CoNS)"</span>
<span class="kw"><a href="https://www.rdocumentation.org/packages/microbenchmark/topics/microbenchmark">microbenchmark</a></span>(<span class="dt">en =</span> <span class="kw"><a href="reference/mo_property.html">mo_fullname</a></span>(<span class="st">"CoNS"</span>, <span class="dt">language =</span> <span class="st">"en"</span>),
<span class="dt">de =</span> <span class="kw"><a href="reference/mo_property.html">mo_fullname</a></span>(<span class="st">"CoNS"</span>, <span class="dt">language =</span> <span class="st">"de"</span>),
<span class="dt">nl =</span> <span class="kw"><a href="reference/mo_property.html">mo_fullname</a></span>(<span class="st">"CoNS"</span>, <span class="dt">language =</span> <span class="st">"nl"</span>),
<span class="dt">es =</span> <span class="kw"><a href="reference/mo_property.html">mo_fullname</a></span>(<span class="st">"CoNS"</span>, <span class="dt">language =</span> <span class="st">"es"</span>),
<span class="dt">it =</span> <span class="kw"><a href="reference/mo_property.html">mo_fullname</a></span>(<span class="st">"CoNS"</span>, <span class="dt">language =</span> <span class="st">"it"</span>),
<span class="dt">fr =</span> <span class="kw"><a href="reference/mo_property.html">mo_fullname</a></span>(<span class="st">"CoNS"</span>, <span class="dt">language =</span> <span class="st">"fr"</span>),
<span class="dt">pt =</span> <span class="kw"><a href="reference/mo_property.html">mo_fullname</a></span>(<span class="st">"CoNS"</span>, <span class="dt">language =</span> <span class="st">"pt"</span>),
<span class="dt">times =</span> <span class="dv">10</span>,
<span class="dt">unit =</span> <span class="st">"ms"</span>)
<span class="co"># Unit: milliseconds</span>
<span class="co"># expr min lq mean median uq max neval</span>
<span class="co"># en 6.093583 6.51724 6.555105 6.562986 6.630663 6.99698 100</span>
<span class="co"># de 13.934874 14.35137 16.891587 14.462210 14.764658 43.63956 100</span>
<span class="co"># nl 13.900092 14.34729 15.943268 14.424565 14.581535 43.76283 100</span>
<span class="co"># es 13.833813 14.34596 14.574783 14.439757 14.653994 17.49168 100</span>
<span class="co"># it 13.811883 14.36621 15.179060 14.453515 14.812359 43.64284 100</span>
<span class="co"># fr 13.798683 14.37019 16.344731 14.468775 14.697610 48.62923 100</span>
<span class="co"># pt 13.789674 14.36244 15.706321 14.443772 14.679905 44.76701 100</span></code></pre></div>
<p>Currently supported are German, Dutch, Spanish, Italian, French and Portuguese.</p>
</div>
<div id="copyright" class="section level2">
<h2 class="hasAnchor">
<a href="#copyright" class="anchor"></a>Copyright</h2>
<p>This R package is licensed under the <a href="https://gitlab.com/msberends/AMR/blob/master/LICENSE">GNU General Public License (GPL) v2.0</a>. In a nutshell, this means that this package:</p>
<ul>
<li><p>May be used for commercial purposes</p></li>
<li><p>May be used for private purposes</p></li>
<li><p>May <strong>not</strong> be used for patent purposes</p></li>
<li><p>May be modified, although:</p></li>
<li>Modifications <strong>must</strong> be released under the same license when distributing the package</li>
<li><p>Changes made to the code <strong>must</strong> be documented</p></li>
<li><p>May be distributed, although:</p></li>
<li>Source code <strong>must</strong> be made available when the package is distributed</li>
<li><p>A copy of the license and copyright notice <strong>must</strong> be included with the package.</p></li>
<li><p>Comes with a LIMITATION of liability</p></li>
<li><p>Comes with NO warranty</p></li>
</ul>
</div>
</div>
</div>
<div class="col-md-3 hidden-xs hidden-sm" id="sidebar">
<div class="links">
<h2>Links</h2>
<ul class="list-unstyled">
<li>Download from CRAN at <br><a href="https://cloud.r-project.org/package=AMR">https://cloud.r-project.org/package=AMR</a>
</li>
<li>Report a bug at <br><a href="https://gitlab.com/msberends/AMR/issues">https://gitlab.com/msberends/AMR/issues</a>
</li>
</ul>
</div>
<div class="license">
<h2>License</h2>
<ul class="list-unstyled">
<li>
<a href="https://www.r-project.org/Licenses/GPL-2">GPL-2</a> | file <a href="LICENSE-text.html">LICENSE</a>
</li>
</ul>
</div>
<div class="developers">
<h2>Developers</h2>
<ul class="list-unstyled">
<li>Matthijs S. Berends <br><small class="roles"> Author, maintainer </small> <a href="https://orcid.org/0000-0001-7620-1800" target="orcid.widget"><img src="https://members.orcid.org/sites/default/files/vector_iD_icon.svg" class="orcid" alt="ORCID" height="16"></a> </li>
<li>Christian F. Luz <br><small class="roles"> Author, reviewer </small> <a href="https://orcid.org/0000-0001-5809-5995" target="orcid.widget"><img src="https://members.orcid.org/sites/default/files/vector_iD_icon.svg" class="orcid" alt="ORCID" height="16"></a> </li>
<li><a href="authors.html">All authors...</a></li>
</ul>
</div>
</div>
</div>
<footer><div class="copyright">
<p>Developed by Matthijs S. Berends, Christian F. Luz.</p>
</div>
<div class="pkgdown">
<p>Site built with <a href="https://pkgdown.r-lib.org/">pkgdown</a> 1.3.0.</p>
</div>
</footer>
</div>
</body>
</html>