1
0
mirror of https://github.com/msberends/AMR.git synced 2024-12-25 19:26:13 +01:00

benchmarks plots

This commit is contained in:
dr. M.S. (Matthijs) Berends 2019-02-14 10:23:51 +01:00
parent ae44b185e6
commit efb2af9e3a
63 changed files with 668 additions and 638 deletions

View File

@ -1,6 +1,6 @@
Package: AMR
Version: 0.5.0.9017
Date: 2019-02-13
Date: 2019-02-14
Title: Antimicrobial Resistance Analysis
Authors@R: c(
person(

View File

@ -667,16 +667,17 @@ format_header <- function(x, markdown = FALSE, decimal.mark = ".", big.mark = ",
header <- header[names(header) != "na_length"]
# format all numeric values
header <- lapply(header, function(x)
if (is.numeric(x))
header <- lapply(header, function(x) {
if (is.numeric(x)) {
if (any(x < 1000)) {
format(round2(x, digits = digits), decimal.mark = decimal.mark, big.mark = big.mark)
} else {
format(x, digits = digits, decimal.mark = decimal.mark, big.mark = big.mark)
}
else
} else {
x
)
}
})
# numeric values
if (has_length == TRUE & any(x_class %in% c("double", "integer", "numeric", "raw", "single"))) {

Binary file not shown.

View File

@ -185,7 +185,7 @@
<h1>How to conduct AMR analysis</h1>
<h4 class="author">Matthijs S. Berends</h4>
<h4 class="date">12 February 2019</h4>
<h4 class="date">14 February 2019</h4>
<div class="hidden name"><code>AMR.Rmd</code></div>
@ -194,7 +194,7 @@
<p><strong>Note:</strong> values on this page will change with every website update since they are based on randomly created values and the page was written in <a href="https://rmarkdown.rstudio.com/">RMarkdown</a>. However, the methodology remains unchanged. This page was generated on 12 February 2019.</p>
<p><strong>Note:</strong> values on this page will change with every website update since they are based on randomly created values and the page was written in <a href="https://rmarkdown.rstudio.com/">RMarkdown</a>. However, the methodology remains unchanged. This page was generated on 14 February 2019.</p>
<div id="introduction" class="section level1">
<h1 class="hasAnchor">
<a href="#introduction" class="anchor"></a>Introduction</h1>
@ -210,21 +210,21 @@
</tr></thead>
<tbody>
<tr class="odd">
<td align="center">2019-02-12</td>
<td align="center">2019-02-14</td>
<td align="center">abcd</td>
<td align="center">Escherichia coli</td>
<td align="center">S</td>
<td align="center">S</td>
</tr>
<tr class="even">
<td align="center">2019-02-12</td>
<td align="center">2019-02-14</td>
<td align="center">abcd</td>
<td align="center">Escherichia coli</td>
<td align="center">S</td>
<td align="center">R</td>
</tr>
<tr class="odd">
<td align="center">2019-02-12</td>
<td align="center">2019-02-14</td>
<td align="center">efgh</td>
<td align="center">Escherichia coli</td>
<td align="center">R</td>
@ -320,70 +320,70 @@
</tr></thead>
<tbody>
<tr class="odd">
<td align="center">2012-04-28</td>
<td align="center">X6</td>
<td align="center">Hospital B</td>
<td align="center">Escherichia coli</td>
<td align="center">R</td>
<td align="center">2016-08-15</td>
<td align="center">E9</td>
<td align="center">Hospital C</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">F</td>
<td align="center">S</td>
<td align="center">M</td>
</tr>
<tr class="even">
<td align="center">2012-12-23</td>
<td align="center">Z1</td>
<td align="center">Hospital A</td>
<td align="center">Escherichia coli</td>
<td align="center">I</td>
<td align="center">2013-02-21</td>
<td align="center">I8</td>
<td align="center">Hospital D</td>
<td align="center">Streptococcus pneumoniae</td>
<td align="center">S</td>
<td align="center">I</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">F</td>
<td align="center">M</td>
</tr>
<tr class="odd">
<td align="center">2011-05-27</td>
<td align="center">G10</td>
<td align="center">2015-05-12</td>
<td align="center">F4</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">M</td>
</tr>
<tr class="even">
<td align="center">2013-09-20</td>
<td align="center">M3</td>
<td align="center">Hospital A</td>
<td align="center">Escherichia coli</td>
<td align="center">S</td>
<td align="center">I</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">M</td>
</tr>
<tr class="odd">
<td align="center">2013-08-03</td>
<td align="center">V8</td>
<td align="center">Hospital C</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">S</td>
<td align="center">M</td>
</tr>
<tr class="even">
<td align="center">2012-08-19</td>
<td align="center">Q1</td>
<td align="center">Hospital D</td>
<td align="center">Escherichia coli</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">F</td>
</tr>
<tr class="odd">
<td align="center">2016-05-06</td>
<td align="center">Y2</td>
<td align="center">Hospital D</td>
<td align="center">Klebsiella pneumoniae</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>
<tr class="even">
<td align="center">2010-08-27</td>
<td align="center">I8</td>
<td align="center">Hospital A</td>
<td align="center">Escherichia coli</td>
<td align="center">R</td>
<td align="center">2017-10-01</td>
<td align="center">V9</td>
<td align="center">Hospital C</td>
<td align="center">Staphylococcus aureus</td>
<td align="center">S</td>
<td align="center">I</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">M</td>
<td align="center">F</td>
</tr>
</tbody>
</table>
@ -398,14 +398,14 @@
<pre><code>#&gt; Frequency table of `gender` from a data.frame (20,000 x 9)
#&gt;
#&gt; Class: factor (numeric)
#&gt; Levels: F, M
#&gt; Length: 20,000 (of which NA: 0 = 0.00%)
#&gt; Levels: 2: F, M
#&gt; Unique: 2
#&gt;
#&gt; Item Count Percent Cum. Count Cum. Percent
#&gt; --- ----- ------- -------- ----------- -------------
#&gt; 1 M 10,303 51.5% 10,303 51.5%
#&gt; 2 F 9,697 48.5% 20,000 100.0%</code></pre>
#&gt; 1 M 10,444 52.2% 10,444 52.2%
#&gt; 2 F 9,556 47.8% 20,000 100.0%</code></pre>
<p>So, we can draw at least two conclusions immediately. From a data scientist perspective, the data looks clean: only values <code>M</code> and <code>F</code>. From a researcher perspective: there are slightly more men. Nothing we didnt 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="cb12"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb12-1" title="1">data &lt;-<span class="st"> </span>data <span class="op">%&gt;%</span></a>
@ -436,10 +436,10 @@
<a class="sourceLine" id="cb14-19" title="19"><span class="co">#&gt; Kingella kingae (no changes)</span></a>
<a class="sourceLine" id="cb14-20" title="20"><span class="co">#&gt; </span></a>
<a class="sourceLine" id="cb14-21" title="21"><span class="co">#&gt; EUCAST Expert Rules, Intrinsic Resistance and Exceptional Phenotypes (v3.1, 2016)</span></a>
<a class="sourceLine" id="cb14-22" title="22"><span class="co">#&gt; Table 1: Intrinsic resistance in Enterobacteriaceae (1278 changes)</span></a>
<a class="sourceLine" id="cb14-22" title="22"><span class="co">#&gt; Table 1: Intrinsic resistance in Enterobacteriaceae (1293 changes)</span></a>
<a class="sourceLine" id="cb14-23" title="23"><span class="co">#&gt; Table 2: Intrinsic resistance in non-fermentative Gram-negative bacteria (no changes)</span></a>
<a class="sourceLine" id="cb14-24" title="24"><span class="co">#&gt; Table 3: Intrinsic resistance in other Gram-negative bacteria (no changes)</span></a>
<a class="sourceLine" id="cb14-25" title="25"><span class="co">#&gt; Table 4: Intrinsic resistance in Gram-positive bacteria (2750 changes)</span></a>
<a class="sourceLine" id="cb14-25" title="25"><span class="co">#&gt; Table 4: Intrinsic resistance in Gram-positive bacteria (2812 changes)</span></a>
<a class="sourceLine" id="cb14-26" title="26"><span class="co">#&gt; Table 8: Interpretive rules for B-lactam agents and Gram-positive cocci (no changes)</span></a>
<a class="sourceLine" id="cb14-27" title="27"><span class="co">#&gt; Table 9: Interpretive rules for B-lactam agents and Gram-negative rods (no changes)</span></a>
<a class="sourceLine" id="cb14-28" title="28"><span class="co">#&gt; Table 10: Interpretive rules for B-lactam agents and other Gram-negative bacteria (no changes)</span></a>
@ -455,9 +455,9 @@
<a class="sourceLine" id="cb14-38" title="38"><span class="co">#&gt; Non-EUCAST: piperacillin/tazobactam = S where piperacillin = S (no changes)</span></a>
<a class="sourceLine" id="cb14-39" title="39"><span class="co">#&gt; Non-EUCAST: trimethoprim/sulfa = S where trimethoprim = S (no changes)</span></a>
<a class="sourceLine" id="cb14-40" title="40"><span class="co">#&gt; </span></a>
<a class="sourceLine" id="cb14-41" title="41"><span class="co">#&gt; =&gt; EUCAST rules affected 7,442 out of 20,000 rows</span></a>
<a class="sourceLine" id="cb14-41" title="41"><span class="co">#&gt; =&gt; EUCAST rules affected 7,447 out of 20,000 rows</span></a>
<a class="sourceLine" id="cb14-42" title="42"><span class="co">#&gt; -&gt; added 0 test results</span></a>
<a class="sourceLine" id="cb14-43" title="43"><span class="co">#&gt; -&gt; changed 4,028 test results (0 to S; 0 to I; 4,028 to R)</span></a></code></pre></div>
<a class="sourceLine" id="cb14-43" title="43"><span class="co">#&gt; -&gt; changed 4,105 test results (0 to S; 0 to I; 4,105 to R)</span></a></code></pre></div>
</div>
<div id="adding-new-variables" class="section level1">
<h1 class="hasAnchor">
@ -482,8 +482,8 @@
<a class="sourceLine" id="cb16-3" title="3"><span class="co">#&gt; </span><span class="al">NOTE</span><span class="co">: Using column `bacteria` as input for `col_mo`.</span></a>
<a class="sourceLine" id="cb16-4" title="4"><span class="co">#&gt; </span><span class="al">NOTE</span><span class="co">: Using column `date` as input for `col_date`.</span></a>
<a class="sourceLine" id="cb16-5" title="5"><span class="co">#&gt; </span><span class="al">NOTE</span><span class="co">: Using column `patient_id` as input for `col_patient_id`.</span></a>
<a class="sourceLine" id="cb16-6" title="6"><span class="co">#&gt; =&gt; Found 5,652 first isolates (28.3% of total)</span></a></code></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>
<a class="sourceLine" id="cb16-6" title="6"><span class="co">#&gt; =&gt; Found 5,692 first isolates (28.5% of total)</span></a></code></pre></div>
<p>So only 28.5% 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="cb17"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb17-1" title="1">data_1st &lt;-<span class="st"> </span>data <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb17-2" title="2"><span class="st"> </span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/filter.html">filter</a></span>(first <span class="op">==</span><span class="st"> </span><span class="ot">TRUE</span>)</a></code></pre></div>
<p>For future use, the above two syntaxes can be shortened with the <code><a href="../reference/first_isolate.html">filter_first_isolate()</a></code> function:</p>
@ -509,32 +509,32 @@
<tbody>
<tr class="odd">
<td align="center">1</td>
<td align="center">2010-01-15</td>
<td align="center">V8</td>
<td align="center">2010-06-20</td>
<td align="center">Y4</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">TRUE</td>
</tr>
<tr class="even">
<td align="center">2</td>
<td align="center">2010-02-08</td>
<td align="center">V8</td>
<td align="center">2010-07-31</td>
<td align="center">Y4</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">FALSE</td>
</tr>
<tr class="odd">
<td align="center">3</td>
<td align="center">2010-02-24</td>
<td align="center">V8</td>
<td align="center">2010-08-26</td>
<td align="center">Y4</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
@ -542,8 +542,8 @@
</tr>
<tr class="even">
<td align="center">4</td>
<td align="center">2010-04-28</td>
<td align="center">V8</td>
<td align="center">2010-12-11</td>
<td align="center">Y4</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">R</td>
<td align="center">S</td>
@ -553,8 +553,8 @@
</tr>
<tr class="odd">
<td align="center">5</td>
<td align="center">2010-05-13</td>
<td align="center">V8</td>
<td align="center">2010-12-30</td>
<td align="center">Y4</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">R</td>
<td align="center">S</td>
@ -564,62 +564,62 @@
</tr>
<tr class="even">
<td align="center">6</td>
<td align="center">2010-05-14</td>
<td align="center">V8</td>
<td align="center">2011-04-02</td>
<td align="center">Y4</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">R</td>
<td align="center">I</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">FALSE</td>
</tr>
<tr class="odd">
<td align="center">7</td>
<td align="center">2010-08-04</td>
<td align="center">V8</td>
<td align="center">2011-04-06</td>
<td align="center">Y4</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">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">8</td>
<td align="center">2010-09-12</td>
<td align="center">V8</td>
<td align="center">2011-04-07</td>
<td align="center">Y4</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">FALSE</td>
</tr>
<tr class="odd">
<td align="center">9</td>
<td align="center">2010-10-03</td>
<td align="center">V8</td>
<td align="center">2011-05-28</td>
<td align="center">Y4</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">R</td>
<td align="center">I</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">FALSE</td>
</tr>
<tr class="even">
<td align="center">10</td>
<td align="center">2011-01-09</td>
<td align="center">V8</td>
<td align="center">2011-09-09</td>
<td align="center">Y4</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">FALSE</td>
<td align="center">TRUE</td>
</tr>
</tbody>
</table>
<p>Only 1 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>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="cb19"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb19-1" title="1">data &lt;-<span class="st"> </span>data <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb19-2" title="2"><span class="st"> </span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/mutate.html">mutate</a></span>(<span class="dt">keyab =</span> <span class="kw"><a href="../reference/key_antibiotics.html">key_antibiotics</a></span>(.)) <span class="op">%&gt;%</span><span class="st"> </span></a>
@ -630,7 +630,7 @@
<a class="sourceLine" id="cb19-7" title="7"><span class="co">#&gt; </span><span class="al">NOTE</span><span class="co">: Using column `patient_id` as input for `col_patient_id`.</span></a>
<a class="sourceLine" id="cb19-8" title="8"><span class="co">#&gt; </span><span class="al">NOTE</span><span class="co">: Using column `keyab` as input for `col_keyantibiotics`. Use col_keyantibiotics = FALSE to prevent this.</span></a>
<a class="sourceLine" id="cb19-9" title="9"><span class="co">#&gt; [Criterion] Inclusion based on key antibiotics, ignoring I.</span></a>
<a class="sourceLine" id="cb19-10" title="10"><span class="co">#&gt; =&gt; Found 15,783 first weighted isolates (78.9% of total)</span></a></code></pre></div>
<a class="sourceLine" id="cb19-10" title="10"><span class="co">#&gt; =&gt; Found 15,866 first weighted isolates (79.3% of total)</span></a></code></pre></div>
<table class="table">
<thead><tr class="header">
<th align="center">isolate</th>
@ -647,32 +647,44 @@
<tbody>
<tr class="odd">
<td align="center">1</td>
<td align="center">2010-01-15</td>
<td align="center">V8</td>
<td align="center">2010-06-20</td>
<td align="center">Y4</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">TRUE</td>
<td align="center">TRUE</td>
</tr>
<tr class="even">
<td align="center">2</td>
<td align="center">2010-02-08</td>
<td align="center">V8</td>
<td align="center">2010-07-31</td>
<td align="center">Y4</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">FALSE</td>
<td align="center">TRUE</td>
</tr>
<tr class="odd">
<td align="center">3</td>
<td align="center">2010-02-24</td>
<td align="center">V8</td>
<td align="center">2010-08-26</td>
<td align="center">Y4</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">FALSE</td>
<td align="center">FALSE</td>
</tr>
<tr class="even">
<td align="center">4</td>
<td align="center">2010-12-11</td>
<td align="center">Y4</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">R</td>
<td align="center">S</td>
@ -681,22 +693,10 @@
<td align="center">FALSE</td>
<td align="center">TRUE</td>
</tr>
<tr class="even">
<td align="center">4</td>
<td align="center">2010-04-28</td>
<td align="center">V8</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">FALSE</td>
<td align="center">FALSE</td>
</tr>
<tr class="odd">
<td align="center">5</td>
<td align="center">2010-05-13</td>
<td align="center">V8</td>
<td align="center">2010-12-30</td>
<td align="center">Y4</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">R</td>
<td align="center">S</td>
@ -707,47 +707,47 @@
</tr>
<tr class="even">
<td align="center">6</td>
<td align="center">2010-05-14</td>
<td align="center">V8</td>
<td align="center">2011-04-02</td>
<td align="center">Y4</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">R</td>
<td align="center">I</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">FALSE</td>
<td align="center">TRUE</td>
</tr>
<tr class="odd">
<td align="center">7</td>
<td align="center">2010-08-04</td>
<td align="center">V8</td>
<td align="center">2011-04-06</td>
<td align="center">Y4</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">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">8</td>
<td align="center">2010-09-12</td>
<td align="center">V8</td>
<td align="center">2011-04-07</td>
<td align="center">Y4</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">FALSE</td>
<td align="center">TRUE</td>
</tr>
<tr class="odd">
<td align="center">9</td>
<td align="center">2010-10-03</td>
<td align="center">V8</td>
<td align="center">2011-05-28</td>
<td align="center">Y4</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">R</td>
<td align="center">I</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">FALSE</td>
@ -755,23 +755,23 @@
</tr>
<tr class="even">
<td align="center">10</td>
<td align="center">2011-01-09</td>
<td align="center">V8</td>
<td align="center">2011-09-09</td>
<td align="center">Y4</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">FALSE</td>
<td align="center">TRUE</td>
<td align="center">TRUE</td>
</tr>
</tbody>
</table>
<p>Instead of 1, now 8 isolates are flagged. In total, 78.9% of all isolates are marked first weighted - 50.7% more than when using the CLSI guideline. In real life, this novel algorithm will yield 5-10% more isolates than the classic CLSI guideline.</p>
<p>Instead of 2, now 8 isolates are flagged. In total, 79.3% of all isolates are marked first weighted - 50.9% more than when using the CLSI guideline. In real life, this novel algorithm will yield 5-10% more isolates than the classic CLSI guideline.</p>
<p>As with <code><a href="../reference/first_isolate.html">filter_first_isolate()</a></code>, theres a shortcut for this new algorithm too:</p>
<div class="sourceCode" id="cb20"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb20-1" title="1">data_1st &lt;-<span class="st"> </span>data <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb20-2" title="2"><span class="st"> </span><span class="kw"><a href="../reference/first_isolate.html">filter_first_weighted_isolate</a></span>()</a></code></pre></div>
<p>So we end up with 15,783 isolates for analysis.</p>
<p>So we end up with 15,866 isolates for analysis.</p>
<p>We can remove unneeded columns:</p>
<div class="sourceCode" id="cb21"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb21-1" title="1">data_1st &lt;-<span class="st"> </span>data_1st <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb21-2" title="2"><span class="st"> </span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/select.html">select</a></span>(<span class="op">-</span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(first, keyab))</a></code></pre></div>
@ -779,6 +779,7 @@
<div class="sourceCode" id="cb22"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb22-1" title="1"><span class="kw"><a href="https://www.rdocumentation.org/packages/utils/topics/head">head</a></span>(data_1st)</a></code></pre></div>
<table class="table">
<thead><tr class="header">
<th></th>
<th align="center">date</th>
<th align="center">patient_id</th>
<th align="center">hospital</th>
@ -795,43 +796,30 @@
</tr></thead>
<tbody>
<tr class="odd">
<td align="center">2012-04-28</td>
<td align="center">X6</td>
<td align="center">Hospital B</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">R</td>
<td>1</td>
<td align="center">2016-08-15</td>
<td align="center">E9</td>
<td align="center">Hospital C</td>
<td align="center">B_STPHY_AUR</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">F</td>
<td align="center">Gram negative</td>
<td align="center">Escherichia</td>
<td align="center">coli</td>
<td align="center">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="even">
<td align="center">2012-12-23</td>
<td align="center">Z1</td>
<td align="center">Hospital A</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">I</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">F</td>
<td align="center">Gram negative</td>
<td align="center">Escherichia</td>
<td align="center">coli</td>
<td align="center">TRUE</td>
</tr>
<tr class="odd">
<td align="center">2011-05-27</td>
<td align="center">G10</td>
<td align="center">Hospital B</td>
<td>2</td>
<td align="center">2013-02-21</td>
<td align="center">I8</td>
<td align="center">Hospital D</td>
<td align="center">B_STRPTC_PNE</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">I</td>
<td align="center">R</td>
<td align="center">R</td>
<td align="center">M</td>
<td align="center">Gram positive</td>
@ -839,45 +827,64 @@
<td align="center">pneumoniae</td>
<td align="center">TRUE</td>
</tr>
<tr class="even">
<td align="center">2012-08-19</td>
<td align="center">Q1</td>
<td align="center">Hospital D</td>
<tr class="odd">
<td>3</td>
<td align="center">2015-05-12</td>
<td align="center">F4</td>
<td align="center">Hospital B</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">F</td>
<td align="center">S</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="center">2016-05-06</td>
<td align="center">Y2</td>
<td align="center">Hospital D</td>
<td align="center">B_KLBSL_PNE</td>
<tr class="even">
<td>5</td>
<td align="center">2013-08-03</td>
<td align="center">V8</td>
<td align="center">Hospital C</td>
<td align="center">B_STRPTC_PNE</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">R</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">F</td>
<td align="center">Gram negative</td>
<td align="center">Klebsiella</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="odd">
<td>6</td>
<td align="center">2017-10-01</td>
<td align="center">V9</td>
<td align="center">Hospital C</td>
<td align="center">B_STPHY_AUR</td>
<td align="center">S</td>
<td align="center">I</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">F</td>
<td align="center">Gram positive</td>
<td align="center">Staphylococcus</td>
<td align="center">aureus</td>
<td align="center">TRUE</td>
</tr>
<tr class="even">
<td align="center">2010-08-27</td>
<td align="center">I8</td>
<td align="center">Hospital A</td>
<td>7</td>
<td align="center">2014-06-20</td>
<td align="center">E9</td>
<td align="center">Hospital B</td>
<td align="center">B_ESCHR_COL</td>
<td align="center">S</td>
<td align="center">S</td>
<td align="center">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">Escherichia</td>
@ -901,9 +908,9 @@
<div class="sourceCode" id="cb23"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb23-1" title="1"><span class="kw"><a href="../reference/freq.html">freq</a></span>(<span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/paste">paste</a></span>(data_1st<span class="op">$</span>genus, data_1st<span class="op">$</span>species))</a></code></pre></div>
<p>Or can be used like the <code>dplyr</code> way, which is easier readable:</p>
<div class="sourceCode" id="cb24"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb24-1" title="1">data_1st <span class="op">%&gt;%</span><span class="st"> </span><span class="kw"><a href="../reference/freq.html">freq</a></span>(genus, species)</a></code></pre></div>
<p><strong>Frequency table of <code>genus</code> and <code>species</code> from a <code>data.frame</code> (15,783 x 13)</strong></p>
<p><strong>Frequency table of <code>genus</code> and <code>species</code> from a <code>data.frame</code> (15,866 x 13)</strong></p>
<p>Columns: 2<br>
Length: 15,783 (of which NA: 0 = 0.00%)<br>
Length: 15,866 (of which NA: 0 = 0.00%)<br>
Unique: 4</p>
<p>Shortest: 16<br>
Longest: 24</p>
@ -920,33 +927,33 @@ Longest: 24</p>
<tr class="odd">
<td align="left">1</td>
<td align="left">Escherichia coli</td>
<td align="right">7,825</td>
<td align="right">49.6%</td>
<td align="right">7,825</td>
<td align="right">49.6%</td>
<td align="right">7,860</td>
<td align="right">49.5%</td>
<td align="right">7,860</td>
<td align="right">49.5%</td>
</tr>
<tr class="even">
<td align="left">2</td>
<td align="left">Staphylococcus aureus</td>
<td align="right">3,979</td>
<td align="right">25.2%</td>
<td align="right">11,804</td>
<td align="right">74.8%</td>
<td align="right">3,892</td>
<td align="right">24.5%</td>
<td align="right">11,752</td>
<td align="right">74.1%</td>
</tr>
<tr class="odd">
<td align="left">3</td>
<td align="left">Streptococcus pneumoniae</td>
<td align="right">2,449</td>
<td align="right">15.5%</td>
<td align="right">14,253</td>
<td align="right">90.3%</td>
<td align="right">2,556</td>
<td align="right">16.1%</td>
<td align="right">14,308</td>
<td align="right">90.2%</td>
</tr>
<tr class="even">
<td align="left">4</td>
<td align="left">Klebsiella pneumoniae</td>
<td align="right">1,530</td>
<td align="right">9.7%</td>
<td align="right">15,783</td>
<td align="right">1,558</td>
<td align="right">9.8%</td>
<td align="right">15,866</td>
<td align="right">100.0%</td>
</tr>
</tbody>
@ -957,7 +964,7 @@ Longest: 24</p>
<a href="#resistance-percentages" class="anchor"></a>Resistance percentages</h2>
<p>The functions <code>portion_R</code>, <code>portion_RI</code>, <code>portion_I</code>, <code>portion_IS</code> and <code>portion_S</code> can be used to determine the portion of a specific antimicrobial outcome. They can be used on their own:</p>
<div class="sourceCode" id="cb25"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb25-1" title="1">data_1st <span class="op">%&gt;%</span><span class="st"> </span><span class="kw"><a href="../reference/portion.html">portion_IR</a></span>(amox)</a>
<a class="sourceLine" id="cb25-2" title="2"><span class="co">#&gt; [1] 0.4756383</span></a></code></pre></div>
<a class="sourceLine" id="cb25-2" title="2"><span class="co">#&gt; [1] 0.4766797</span></a></code></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="cb26"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb26-1" title="1">data_1st <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb26-2" title="2"><span class="st"> </span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/group_by.html">group_by</a></span>(hospital) <span class="op">%&gt;%</span><span class="st"> </span></a>
@ -970,19 +977,19 @@ Longest: 24</p>
<tbody>
<tr class="odd">
<td align="center">Hospital A</td>
<td align="center">0.4697326</td>
<td align="center">0.4749633</td>
</tr>
<tr class="even">
<td align="center">Hospital B</td>
<td align="center">0.4770958</td>
<td align="center">0.4879713</td>
</tr>
<tr class="odd">
<td align="center">Hospital C</td>
<td align="center">0.4799670</td>
<td align="center">0.4761905</td>
</tr>
<tr class="even">
<td align="center">Hospital D</td>
<td align="center">0.4785082</td>
<td align="center">0.4600062</td>
</tr>
</tbody>
</table>
@ -1000,23 +1007,23 @@ Longest: 24</p>
<tbody>
<tr class="odd">
<td align="center">Hospital A</td>
<td align="center">0.4697326</td>
<td align="center">4675</td>
<td align="center">0.4749633</td>
<td align="center">4773</td>
</tr>
<tr class="even">
<td align="center">Hospital B</td>
<td align="center">0.4770958</td>
<td align="center">5523</td>
<td align="center">0.4879713</td>
<td align="center">5570</td>
</tr>
<tr class="odd">
<td align="center">Hospital C</td>
<td align="center">0.4799670</td>
<td align="center">2421</td>
<td align="center">0.4761905</td>
<td align="center">2310</td>
</tr>
<tr class="even">
<td align="center">Hospital D</td>
<td align="center">0.4785082</td>
<td align="center">3164</td>
<td align="center">0.4600062</td>
<td align="center">3213</td>
</tr>
</tbody>
</table>
@ -1036,27 +1043,27 @@ Longest: 24</p>
<tbody>
<tr class="odd">
<td align="center">Escherichia</td>
<td align="center">0.7345687</td>
<td align="center">0.9051757</td>
<td align="center">0.9773802</td>
<td align="center">0.7249364</td>
<td align="center">0.8996183</td>
<td align="center">0.9725191</td>
</tr>
<tr class="even">
<td align="center">Klebsiella</td>
<td align="center">0.7307190</td>
<td align="center">0.9071895</td>
<td align="center">0.9771242</td>
<td align="center">0.7291399</td>
<td align="center">0.9037227</td>
<td align="center">0.9762516</td>
</tr>
<tr class="odd">
<td align="center">Staphylococcus</td>
<td align="center">0.7353606</td>
<td align="center">0.9210857</td>
<td align="center">0.9816537</td>
<td align="center">0.7410072</td>
<td align="center">0.9229188</td>
<td align="center">0.9786742</td>
</tr>
<tr class="even">
<td align="center">Streptococcus</td>
<td align="center">0.7268273</td>
<td align="center">0.7292645</td>
<td align="center">0.0000000</td>
<td align="center">0.7268273</td>
<td align="center">0.7292645</td>
</tr>
</tbody>
</table>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 68 KiB

After

Width:  |  Height:  |  Size: 68 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 50 KiB

After

Width:  |  Height:  |  Size: 50 KiB

View File

@ -185,7 +185,7 @@
<h1>How to apply EUCAST rules</h1>
<h4 class="author">Matthijs S. Berends</h4>
<h4 class="date">12 February 2019</h4>
<h4 class="date">14 February 2019</h4>
<div class="hidden name"><code>EUCAST.Rmd</code></div>

View File

@ -70,7 +70,7 @@
</a>
</li>
<li>
<a href="../articles/Predict.html">
<a href="../articles/resistance_predict.html">
<span class="fa fa-dice"></span>
Predict antimicrobial resistance
@ -91,14 +91,14 @@
</a>
</li>
<li>
<a href="../articles/mo_property.html">
<a href="../reference/mo_property.html">
<span class="fa fa-bug"></span>
Get properties of a microorganism
</a>
</li>
<li>
<a href="../articles/ab_property.html">
<a href="../reference/atc_property.html">
<span class="fa fa-capsules"></span>
Get properties of an antibiotic
@ -185,7 +185,7 @@
<h1>How to use the <em>G</em>-test</h1>
<h4 class="author">Matthijs S. Berends</h4>
<h4 class="date">09 February 2019</h4>
<h4 class="date">14 February 2019</h4>
<div class="hidden name"><code>G_test.Rmd</code></div>

View File

@ -70,7 +70,7 @@
</a>
</li>
<li>
<a href="../articles/Predict.html">
<a href="../articles/resistance_predict.html">
<span class="fa fa-dice"></span>
Predict antimicrobial resistance
@ -91,14 +91,14 @@
</a>
</li>
<li>
<a href="../articles/mo_property.html">
<a href="../reference/mo_property.html">
<span class="fa fa-bug"></span>
Get properties of a microorganism
</a>
</li>
<li>
<a href="../articles/ab_property.html">
<a href="../reference/atc_property.html">
<span class="fa fa-capsules"></span>
Get properties of an antibiotic
@ -185,7 +185,7 @@
<h1>How to work with WHONET data</h1>
<h4 class="author">Matthijs S. Berends</h4>
<h4 class="date">09 February 2019</h4>
<h4 class="date">14 February 2019</h4>
<div class="hidden name"><code>WHONET.Rmd</code></div>
@ -199,33 +199,33 @@
<a href="#import-of-data" class="anchor"></a>Import of data</h1>
<p>This tutorial assumes you already imported the WHONET data with e.g. the <a href="https://readxl.tidyverse.org/"><code>readxl</code> package</a>. In RStudio, this can be done using the menu button Import Dataset in the tab Environment. Choose the option From Excel and select your exported file. Make sure date fields are imported correctly.</p>
<p>An example syntax could look like this:</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb1-1" data-line-number="1"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/library">library</a></span>(readxl)</a>
<a class="sourceLine" id="cb1-2" data-line-number="2">data &lt;-<span class="st"> </span><span class="kw"><a href="https://readxl.tidyverse.org/reference/read_excel.html">read_excel</a></span>(<span class="dt">path =</span> <span class="st">"path/to/your/file.xlsx"</span>)</a></code></pre></div>
<div class="sourceCode" id="cb1"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb1-1" title="1"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/library">library</a></span>(readxl)</a>
<a class="sourceLine" id="cb1-2" title="2">data &lt;-<span class="st"> </span><span class="kw"><a href="https://readxl.tidyverse.org/reference/read_excel.html">read_excel</a></span>(<span class="dt">path =</span> <span class="st">"path/to/your/file.xlsx"</span>)</a></code></pre></div>
<p>This package comes with an <a href="./reference/WHONET.html">example data set <code>WHONET</code></a>. We will use it for this analysis.</p>
</div>
<div id="preparation" class="section level1">
<h1 class="hasAnchor">
<a href="#preparation" class="anchor"></a>Preparation</h1>
<p>First, load the relevant packages if you did not yet did this. I use the tidyverse for all of my analyses. All of them. If you dont know it yet, I suggest you read about it on their website: <a href="https://www.tidyverse.org/" class="uri">https://www.tidyverse.org/</a>.</p>
<div class="sourceCode" id="cb2"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb2-1" data-line-number="1"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/library">library</a></span>(dplyr) <span class="co"># part of tidyverse</span></a>
<a class="sourceLine" id="cb2-2" data-line-number="2"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/library">library</a></span>(ggplot2) <span class="co"># part of tidyverse</span></a>
<a class="sourceLine" id="cb2-3" data-line-number="3"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/library">library</a></span>(AMR) <span class="co"># this package</span></a></code></pre></div>
<div class="sourceCode" id="cb2"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb2-1" title="1"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/library">library</a></span>(dplyr) <span class="co"># part of tidyverse</span></a>
<a class="sourceLine" id="cb2-2" title="2"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/library">library</a></span>(ggplot2) <span class="co"># part of tidyverse</span></a>
<a class="sourceLine" id="cb2-3" title="3"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/library">library</a></span>(AMR) <span class="co"># this package</span></a></code></pre></div>
<p>We will have to transform some variables to simplify and automate the analysis:</p>
<ul>
<li>Microorganisms should be transformed to our own microorganism IDs (called an <code>mo</code>) using <a href="./reference/ITIS.html">the ITIS reference data set</a>, which contains all ~20,000 microorganisms from the taxonomic kingdoms Bacteria, Fungi and Protozoa. We do the tranformation with <code><a href="../reference/as.mo.html">as.mo()</a></code>. This function also recognises almost all WHONET abbreviations of microorganisms.</li>
<li>Antimicrobial results or interpretations have to be clean and valid. In other words, they should only contain values <code>"S"</code>, <code>"I"</code> or <code>"R"</code>. That is exactly where the <code><a href="../reference/as.rsi.html">as.rsi()</a></code> function is for.</li>
</ul>
<div class="sourceCode" id="cb3"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb3-1" data-line-number="1"><span class="co"># transform variables</span></a>
<a class="sourceLine" id="cb3-2" data-line-number="2">data &lt;-<span class="st"> </span>WHONET <span class="op">%&gt;%</span></a>
<a class="sourceLine" id="cb3-3" data-line-number="3"><span class="st"> </span><span class="co"># get microbial ID based on given organism</span></a>
<a class="sourceLine" id="cb3-4" data-line-number="4"><span class="st"> </span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/mutate.html">mutate</a></span>(<span class="dt">mo =</span> <span class="kw"><a href="../reference/as.mo.html">as.mo</a></span>(Organism)) <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb3-5" data-line-number="5"><span class="st"> </span><span class="co"># transform everything from "AMP_ND10" to "CIP_EE" to the new `rsi` class</span></a>
<a class="sourceLine" id="cb3-6" data-line-number="6"><span class="st"> </span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/summarise_all.html">mutate_at</a></span>(<span class="kw"><a href="https://dplyr.tidyverse.org/reference/vars.html">vars</a></span>(AMP_ND10<span class="op">:</span>CIP_EE), as.rsi)</a></code></pre></div>
<div class="sourceCode" id="cb3"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb3-1" title="1"><span class="co"># transform variables</span></a>
<a class="sourceLine" id="cb3-2" title="2">data &lt;-<span class="st"> </span>WHONET <span class="op">%&gt;%</span></a>
<a class="sourceLine" id="cb3-3" title="3"><span class="st"> </span><span class="co"># get microbial ID based on given organism</span></a>
<a class="sourceLine" id="cb3-4" title="4"><span class="st"> </span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/mutate.html">mutate</a></span>(<span class="dt">mo =</span> <span class="kw"><a href="../reference/as.mo.html">as.mo</a></span>(Organism)) <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb3-5" title="5"><span class="st"> </span><span class="co"># transform everything from "AMP_ND10" to "CIP_EE" to the new `rsi` class</span></a>
<a class="sourceLine" id="cb3-6" title="6"><span class="st"> </span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/summarise_all.html">mutate_at</a></span>(<span class="kw"><a href="https://dplyr.tidyverse.org/reference/vars.html">vars</a></span>(AMP_ND10<span class="op">:</span>CIP_EE), as.rsi)</a></code></pre></div>
<p>No errors or warnings, so all values are transformed succesfully. Lets check it though, with a couple of frequency tables:</p>
<div class="sourceCode" id="cb4"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb4-1" data-line-number="1"><span class="co"># our newly created `mo` variable</span></a>
<a class="sourceLine" id="cb4-2" data-line-number="2">data <span class="op">%&gt;%</span><span class="st"> </span><span class="kw"><a href="../reference/freq.html">freq</a></span>(mo, <span class="dt">nmax =</span> <span class="dv">10</span>)</a></code></pre></div>
<p><strong>Frequency table of <code>mo</code> from a <code>data.frame</code> (500 x 54)</strong><br>
Class: <code>mo</code> (<code>character</code>)<br>
<div class="sourceCode" id="cb4"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb4-1" title="1"><span class="co"># our newly created `mo` variable</span></a>
<a class="sourceLine" id="cb4-2" title="2">data <span class="op">%&gt;%</span><span class="st"> </span><span class="kw"><a href="../reference/freq.html">freq</a></span>(mo, <span class="dt">nmax =</span> <span class="dv">10</span>)</a></code></pre></div>
<p><strong>Frequency table of <code>mo</code> from a <code>data.frame</code> (500 x 54)</strong></p>
<p>Class: <code>mo</code> (<code>character</code>)<br>
Length: 500 (of which NA: 0 = 0.00%)<br>
Unique: 39</p>
<p>Families: 9<br>
@ -324,16 +324,16 @@ Species: 36</p>
</tbody>
</table>
<p>(omitted 29 entries, n = 57 [11.4%])</p>
<div class="sourceCode" id="cb5"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb5-1" data-line-number="1"></a>
<a class="sourceLine" id="cb5-2" data-line-number="2"><span class="co"># our transformed antibiotic columns</span></a>
<a class="sourceLine" id="cb5-3" data-line-number="3"><span class="co"># amoxicillin/clavulanic acid (J01CR02) as an example</span></a>
<a class="sourceLine" id="cb5-4" data-line-number="4">data <span class="op">%&gt;%</span><span class="st"> </span><span class="kw"><a href="../reference/freq.html">freq</a></span>(AMC_ND2)</a></code></pre></div>
<p><strong>Frequency table of <code>AMC_ND2</code> from a <code>data.frame</code> (500 x 54)</strong><br>
Class: <code>factor</code> &gt; <code>ordered</code> &gt; <code>rsi</code> (<code>numeric</code>)<br>
Levels: S &lt; I &lt; R<br>
<div class="sourceCode" id="cb5"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb5-1" title="1"></a>
<a class="sourceLine" id="cb5-2" title="2"><span class="co"># our transformed antibiotic columns</span></a>
<a class="sourceLine" id="cb5-3" title="3"><span class="co"># amoxicillin/clavulanic acid (J01CR02) as an example</span></a>
<a class="sourceLine" id="cb5-4" title="4">data <span class="op">%&gt;%</span><span class="st"> </span><span class="kw"><a href="../reference/freq.html">freq</a></span>(AMC_ND2)</a></code></pre></div>
<p><strong>Frequency table of <code>AMC_ND2</code> from a <code>data.frame</code> (500 x 54)</strong></p>
<p>Class: <code>factor</code> &gt; <code>ordered</code> &gt; <code>rsi</code> (<code>numeric</code>)<br>
Length: 500 (of which NA: 19 = 3.80%)<br>
Levels: 3: <code>S</code> &lt; <code>I</code> &lt; <code>R</code><br>
Unique: 3</p>
<p>%IR: 25.99% (ratio S : IR = 1.0 : 0.4)</p>
<p>%IR: 25.00% (ratio 2.8:1)</p>
<table class="table">
<thead><tr class="header">
<th align="left"></th>

View File

@ -185,7 +185,7 @@
<h1>How to get properties of an antibiotic</h1>
<h4 class="author">Matthijs S. Berends</h4>
<h4 class="date">12 February 2019</h4>
<h4 class="date">14 February 2019</h4>
<div class="hidden name"><code>atc_property.Rmd</code></div>

View File

@ -70,7 +70,7 @@
</a>
</li>
<li>
<a href="../articles/Predict.html">
<a href="../articles/resistance_predict.html">
<span class="fa fa-dice"></span>
Predict antimicrobial resistance
@ -91,14 +91,14 @@
</a>
</li>
<li>
<a href="../articles/mo_property.html">
<a href="../reference/mo_property.html">
<span class="fa fa-bug"></span>
Get properties of a microorganism
</a>
</li>
<li>
<a href="../articles/ab_property.html">
<a href="../reference/atc_property.html">
<span class="fa fa-capsules"></span>
Get properties of an antibiotic
@ -185,7 +185,7 @@
<h1>Benchmarks</h1>
<h4 class="author">Matthijs S. Berends</h4>
<h4 class="date">09 February 2019</h4>
<h4 class="date">14 February 2019</h4>
<div class="hidden name"><code>benchmarks.Rmd</code></div>
@ -195,150 +195,160 @@
<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><a href="../reference/as.mo.html">as.mo()</a></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" id="cb1"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb1-1" data-line-number="1"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/library">library</a></span>(microbenchmark)</a>
<a class="sourceLine" id="cb1-2" data-line-number="2"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/library">library</a></span>(AMR)</a></code></pre></div>
<p>Using the <code>microbenchmark</code> package, we can review the calculation performance of this function. Its function <code><a href="https://www.rdocumentation.org/packages/microbenchmark/topics/microbenchmark">microbenchmark()</a></code> calculates different input expressions independently of each others and runs every expression 100 times.</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb1-1" title="1"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/library">library</a></span>(microbenchmark)</a>
<a class="sourceLine" id="cb1-2" title="2"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/library">library</a></span>(AMR)</a></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" id="cb2"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb2-1" data-line-number="1"><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>),</a>
<a class="sourceLine" id="cb2-2" data-line-number="2"> <span class="dt">B =</span> <span class="kw"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="st">"staaur"</span>),</a>
<a class="sourceLine" id="cb2-3" data-line-number="3"> <span class="dt">C =</span> <span class="kw"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="st">"S. aureus"</span>),</a>
<a class="sourceLine" id="cb2-4" data-line-number="4"> <span class="dt">D =</span> <span class="kw"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="st">"S. aureus"</span>),</a>
<a class="sourceLine" id="cb2-5" data-line-number="5"> <span class="dt">E =</span> <span class="kw"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="st">"STAAUR"</span>),</a>
<a class="sourceLine" id="cb2-6" data-line-number="6"> <span class="dt">F =</span> <span class="kw"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="st">"Staphylococcus aureus"</span>),</a>
<a class="sourceLine" id="cb2-7" data-line-number="7"> <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>),</a>
<a class="sourceLine" id="cb2-8" data-line-number="8"> <span class="dt">times =</span> <span class="dv">10</span>,</a>
<a class="sourceLine" id="cb2-9" data-line-number="9"> <span class="dt">unit =</span> <span class="st">"ms"</span>)</a>
<a class="sourceLine" id="cb2-10" data-line-number="10"><span class="co"># Unit: milliseconds</span></a>
<a class="sourceLine" id="cb2-11" data-line-number="11"><span class="co"># expr min lq mean median uq max neval</span></a>
<a class="sourceLine" id="cb2-12" data-line-number="12"><span class="co"># A 34.745551 34.798630 35.2596102 34.8994810 35.258325 38.067062 10</span></a>
<a class="sourceLine" id="cb2-13" data-line-number="13"><span class="co"># B 7.095386 7.125348 7.2219948 7.1613865 7.240377 7.495857 10</span></a>
<a class="sourceLine" id="cb2-14" data-line-number="14"><span class="co"># C 11.677114 11.733826 11.8304789 11.7715050 11.843756 12.317559 10</span></a>
<a class="sourceLine" id="cb2-15" data-line-number="15"><span class="co"># D 11.694435 11.730054 11.9859313 11.8775585 12.206371 12.750016 10</span></a>
<a class="sourceLine" id="cb2-16" data-line-number="16"><span class="co"># E 7.044402 7.117387 7.2271630 7.1923610 7.246104 7.742396 10</span></a>
<a class="sourceLine" id="cb2-17" data-line-number="17"><span class="co"># F 6.642326 6.778446 6.8988042 6.8753165 6.923577 7.513945 10</span></a>
<a class="sourceLine" id="cb2-18" data-line-number="18"><span class="co"># G 0.106788 0.131023 0.1351229 0.1357725 0.144014 0.146458 10</span></a></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>
<div class="sourceCode" id="cb2"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb2-1" title="1">benchmark &lt;-<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/microbenchmark/topics/microbenchmark">microbenchmark</a></span>(<span class="kw"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="st">"sau"</span>),</a>
<a class="sourceLine" id="cb2-2" title="2"> <span class="kw"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="st">"stau"</span>),</a>
<a class="sourceLine" id="cb2-3" title="3"> <span class="kw"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="st">"staaur"</span>),</a>
<a class="sourceLine" id="cb2-4" title="4"> <span class="kw"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="st">"S. aureus"</span>),</a>
<a class="sourceLine" id="cb2-5" title="5"> <span class="kw"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="st">"S. aureus"</span>),</a>
<a class="sourceLine" id="cb2-6" title="6"> <span class="kw"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="st">"STAAUR"</span>),</a>
<a class="sourceLine" id="cb2-7" title="7"> <span class="kw"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="st">"Staphylococcus aureus"</span>),</a>
<a class="sourceLine" id="cb2-8" title="8"> <span class="kw"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="st">"B_STPHY_AUR"</span>))</a>
<a class="sourceLine" id="cb2-9" title="9"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/print">print</a></span>(benchmark, <span class="dt">unit =</span> <span class="st">"ms"</span>)</a>
<a class="sourceLine" id="cb2-10" title="10"><span class="co"># Unit: milliseconds</span></a>
<a class="sourceLine" id="cb2-11" title="11"><span class="co"># expr min lq mean median uq max neval</span></a>
<a class="sourceLine" id="cb2-12" title="12"><span class="co"># as.mo("sau") 18.983141 19.121148 19.9676944 19.1967505 19.2871260 38.635012 100</span></a>
<a class="sourceLine" id="cb2-13" title="13"><span class="co"># as.mo("stau") 37.503863 37.692049 38.9856547 37.8244335 37.9851040 57.576107 100</span></a>
<a class="sourceLine" id="cb2-14" title="14"><span class="co"># as.mo("staaur") 18.945427 19.122579 19.6392560 19.2241285 19.3536140 38.687672 100</span></a>
<a class="sourceLine" id="cb2-15" title="15"><span class="co"># as.mo("S. aureus") 15.305229 15.471103 16.3477096 15.5545630 15.6689280 36.363005 100</span></a>
<a class="sourceLine" id="cb2-16" title="16"><span class="co"># as.mo("S. aureus") 15.308232 15.469881 16.5269706 15.5506870 15.6277560 42.155292 100</span></a>
<a class="sourceLine" id="cb2-17" title="17"><span class="co"># as.mo("STAAUR") 18.984049 19.117166 19.6104597 19.2219285 19.3161095 38.638783 100</span></a>
<a class="sourceLine" id="cb2-18" title="18"><span class="co"># as.mo("Staphylococcus aureus") 8.103546 8.198285 8.6422018 8.2636915 8.3200535 27.002527 100</span></a>
<a class="sourceLine" id="cb2-19" title="19"><span class="co"># as.mo("B_STPHY_AUR") 0.156236 0.196779 0.2017926 0.2035535 0.2115505 0.241861 100</span></a>
<a class="sourceLine" id="cb2-20" title="20"></a>
<a class="sourceLine" id="cb2-21" title="21"><span class="kw"><a href="https://www.rdocumentation.org/packages/graphics/topics/par">par</a></span>(<span class="dt">mar =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="dv">5</span>, <span class="dv">15</span>, <span class="dv">4</span>, <span class="dv">2</span>)) <span class="co"># set more space for left margin text (15)</span></a>
<a class="sourceLine" id="cb2-22" title="22"><span class="kw"><a href="https://www.rdocumentation.org/packages/graphics/topics/boxplot">boxplot</a></span>(benchmark, <span class="dt">horizontal =</span> <span class="ot">TRUE</span>, <span class="dt">las =</span> <span class="dv">1</span>, <span class="dt">unit =</span> <span class="st">"ms"</span>, <span class="dt">log =</span> <span class="ot">FALSE</span>, <span class="dt">xlab =</span> <span class="st">""</span>, <span class="dt">ylim =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="dv">0</span>, <span class="dv">200</span>),</a>
<a class="sourceLine" id="cb2-23" title="23"> <span class="dt">main =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/expression">expression</a></span>(<span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/paste">paste</a></span>(<span class="st">"Benchmark of "</span>, <span class="kw"><a href="https://www.rdocumentation.org/packages/grDevices/topics/plotmath">italic</a></span>(<span class="st">"Staphylococcus aureus"</span>))))</a></code></pre></div>
<p><img src="../reference/figures/benchmark_1.png"></p>
<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 8 milliseconds means it can determine 125 input values per second. It case of 40 milliseconds, this is only 25 input values per second. The more an input value resembles a full name, the faster the result will be found. In case of <code><a href="../reference/as.mo.html">as.mo("B_STPHY_AUR")</a></code>, the input is already a valid MO code, so it only almost takes no time at all (0.0002 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" id="cb3"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb3-1" data-line-number="1"><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>),</a>
<a class="sourceLine" id="cb3-2" data-line-number="2"> <span class="dt">B =</span> <span class="kw"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="st">"burnod"</span>),</a>
<a class="sourceLine" id="cb3-3" data-line-number="3"> <span class="dt">C =</span> <span class="kw"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="st">"B. nodosa"</span>),</a>
<a class="sourceLine" id="cb3-4" data-line-number="4"> <span class="dt">D =</span> <span class="kw"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="st">"B. nodosa"</span>),</a>
<a class="sourceLine" id="cb3-5" data-line-number="5"> <span class="dt">E =</span> <span class="kw"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="st">"BURNOD"</span>),</a>
<a class="sourceLine" id="cb3-6" data-line-number="6"> <span class="dt">F =</span> <span class="kw"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="st">"Burkholderia nodosa"</span>),</a>
<a class="sourceLine" id="cb3-7" data-line-number="7"> <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>),</a>
<a class="sourceLine" id="cb3-8" data-line-number="8"> <span class="dt">times =</span> <span class="dv">10</span>,</a>
<a class="sourceLine" id="cb3-9" data-line-number="9"> <span class="dt">unit =</span> <span class="st">"ms"</span>)</a>
<a class="sourceLine" id="cb3-10" data-line-number="10"><span class="co"># Unit: milliseconds</span></a>
<a class="sourceLine" id="cb3-11" data-line-number="11"><span class="co"># expr min lq mean median uq max neval</span></a>
<a class="sourceLine" id="cb3-12" data-line-number="12"><span class="co"># A 124.175427 124.474837 125.8610536 125.3750560 126.160945 131.485994 10</span></a>
<a class="sourceLine" id="cb3-13" data-line-number="13"><span class="co"># B 154.249713 155.364729 160.9077032 156.8738940 157.136183 197.315105 10</span></a>
<a class="sourceLine" id="cb3-14" data-line-number="14"><span class="co"># C 66.066571 66.162393 66.5538611 66.4488130 66.698077 67.623404 10</span></a>
<a class="sourceLine" id="cb3-15" data-line-number="15"><span class="co"># D 86.747693 86.918665 90.7831016 87.8149725 89.440982 116.767991 10</span></a>
<a class="sourceLine" id="cb3-16" data-line-number="16"><span class="co"># E 154.863827 155.208563 162.6535954 158.4062465 168.593785 187.378088 10</span></a>
<a class="sourceLine" id="cb3-17" data-line-number="17"><span class="co"># F 32.427028 32.638648 32.9929454 32.7860475 32.992813 34.674241 10</span></a>
<a class="sourceLine" id="cb3-18" data-line-number="18"><span class="co"># G 0.213155 0.216578 0.2369226 0.2338985 0.253734 0.285581 10</span></a></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>
<div class="sourceCode" id="cb3"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb3-1" title="1">benchmark &lt;-<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/microbenchmark/topics/microbenchmark">microbenchmark</a></span>(<span class="kw"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="st">"buno"</span>),</a>
<a class="sourceLine" id="cb3-2" title="2"> <span class="kw"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="st">"burnod"</span>),</a>
<a class="sourceLine" id="cb3-3" title="3"> <span class="kw"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="st">"B. nodosa"</span>),</a>
<a class="sourceLine" id="cb3-4" title="4"> <span class="kw"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="st">"B. nodosa"</span>),</a>
<a class="sourceLine" id="cb3-5" title="5"> <span class="kw"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="st">"BURNOD"</span>),</a>
<a class="sourceLine" id="cb3-6" title="6"> <span class="kw"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="st">"Burkholderia nodosa"</span>),</a>
<a class="sourceLine" id="cb3-7" title="7"> <span class="kw"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="st">"B_BRKHL_NOD"</span>))</a>
<a class="sourceLine" id="cb3-8" title="8"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/print">print</a></span>(benchmark, <span class="dt">unit =</span> <span class="st">"ms"</span>)</a>
<a class="sourceLine" id="cb3-9" title="9"></a>
<a class="sourceLine" id="cb3-10" title="10"><span class="co"># Unit: milliseconds</span></a>
<a class="sourceLine" id="cb3-11" title="11"><span class="co"># expr min lq mean median uq max neval</span></a>
<a class="sourceLine" id="cb3-12" title="12"><span class="co"># as.mo("buno") 125.141333 125.8553210 129.5727691 126.3899910 127.0954925 194.51985 100</span></a>
<a class="sourceLine" id="cb3-13" title="13"><span class="co"># as.mo("burnod") 142.300359 144.1611750 147.0642288 144.6074960 145.5243025 176.91649 100</span></a>
<a class="sourceLine" id="cb3-14" title="14"><span class="co"># as.mo("B. nodosa") 81.530132 81.9360840 83.3915418 82.1852770 82.6848870 102.63184 100</span></a>
<a class="sourceLine" id="cb3-15" title="15"><span class="co"># as.mo("B. nodosa") 81.109547 81.9836805 84.7595894 82.3437825 82.8282705 110.67036 100</span></a>
<a class="sourceLine" id="cb3-16" title="16"><span class="co"># as.mo("BURNOD") 143.163527 143.9134485 148.7192688 144.5582580 145.7489115 314.92070 100</span></a>
<a class="sourceLine" id="cb3-17" title="17"><span class="co"># as.mo("Burkholderia nodosa") 36.226325 36.5499000 37.1309929 36.6581540 36.7551985 56.25597 100</span></a>
<a class="sourceLine" id="cb3-18" title="18"><span class="co"># as.mo("B_BRKHL_NOD") 0.172509 0.3038455 0.4806591 0.3078265 0.3121215 19.16173 100</span></a>
<a class="sourceLine" id="cb3-19" title="19"></a>
<a class="sourceLine" id="cb3-20" title="20"><span class="kw"><a href="https://www.rdocumentation.org/packages/graphics/topics/boxplot">boxplot</a></span>(benchmark, <span class="dt">horizontal =</span> <span class="ot">TRUE</span>, <span class="dt">las =</span> <span class="dv">1</span>, <span class="dt">unit =</span> <span class="st">"ms"</span>, <span class="dt">log =</span> <span class="ot">FALSE</span>, <span class="dt">xlab =</span> <span class="st">""</span>, <span class="dt">ylim =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="dv">0</span>, <span class="dv">200</span>),</a>
<a class="sourceLine" id="cb3-21" title="21"> <span class="dt">main =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/expression">expression</a></span>(<span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/paste">paste</a></span>(<span class="st">"Benchmark of "</span>, <span class="kw"><a href="https://www.rdocumentation.org/packages/grDevices/topics/plotmath">italic</a></span>(<span class="st">"Burkholderia nodosa"</span>))))</a></code></pre></div>
<p><img src="../reference/figures/benchmark_2.png"></p>
<p>That takes up to 8 times as much time! A value of 145 milliseconds means it can only determine ~7 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>repetitive results</strong> and <strong>already precalculated results</strong>.</p>
<div id="repetitive-results" class="section level3">
<h3 class="hasAnchor">
<a href="#repetitive-results" class="anchor"></a>Repetitive results</h3>
<p>Repetitive results mean that unique values are present more than once. Unique values will only be calculated once by <code><a href="../reference/as.mo.html">as.mo()</a></code>. We will use <code><a href="../reference/mo_property.html">mo_fullname()</a></code> for this test - a helper function that returns the full microbial name (genus, species and possibly subspecies) and uses <code><a href="../reference/as.mo.html">as.mo()</a></code> internally.</p>
<div class="sourceCode" id="cb4"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb4-1" data-line-number="1"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/library">library</a></span>(dplyr)</a>
<a class="sourceLine" id="cb4-2" data-line-number="2"><span class="co"># take 500,000 random MO codes from the septic_patients data set</span></a>
<a class="sourceLine" id="cb4-3" data-line-number="3">x =<span class="st"> </span>septic_patients <span class="op">%&gt;%</span></a>
<a class="sourceLine" id="cb4-4" data-line-number="4"><span class="st"> </span><span class="kw"><a href="https://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>) <span class="op">%&gt;%</span></a>
<a class="sourceLine" id="cb4-5" data-line-number="5"><span class="st"> </span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/pull.html">pull</a></span>(mo)</a>
<a class="sourceLine" id="cb4-6" data-line-number="6"> </a>
<a class="sourceLine" id="cb4-7" data-line-number="7"><span class="co"># got the right length?</span></a>
<a class="sourceLine" id="cb4-8" data-line-number="8"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/length">length</a></span>(x)</a>
<a class="sourceLine" id="cb4-9" data-line-number="9"><span class="co"># [1] 500000</span></a>
<a class="sourceLine" id="cb4-10" data-line-number="10"></a>
<a class="sourceLine" id="cb4-11" data-line-number="11"><span class="co"># and how many unique values do we have?</span></a>
<a class="sourceLine" id="cb4-12" data-line-number="12"><span class="kw"><a href="https://dplyr.tidyverse.org/reference/n_distinct.html">n_distinct</a></span>(x)</a>
<a class="sourceLine" id="cb4-13" data-line-number="13"><span class="co"># [1] 96</span></a>
<a class="sourceLine" id="cb4-14" data-line-number="14"></a>
<a class="sourceLine" id="cb4-15" data-line-number="15"><span class="co"># only 96, but distributed in 500,000 results. now let's see:</span></a>
<a class="sourceLine" id="cb4-16" data-line-number="16"><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),</a>
<a class="sourceLine" id="cb4-17" data-line-number="17"> <span class="dt">times =</span> <span class="dv">10</span>,</a>
<a class="sourceLine" id="cb4-18" data-line-number="18"> <span class="dt">unit =</span> <span class="st">"ms"</span>)</a>
<a class="sourceLine" id="cb4-19" data-line-number="19"><span class="co"># Unit: milliseconds</span></a>
<a class="sourceLine" id="cb4-20" data-line-number="20"><span class="co"># expr min lq mean median uq max neval</span></a>
<a class="sourceLine" id="cb4-21" data-line-number="21"><span class="co"># X 114.9342 117.1076 129.6448 120.2047 131.5005 168.6371 10</span></a></code></pre></div>
<div class="sourceCode" id="cb4"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb4-1" title="1"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/library">library</a></span>(dplyr)</a>
<a class="sourceLine" id="cb4-2" title="2"><span class="co"># take 500,000 random MO codes from the septic_patients data set</span></a>
<a class="sourceLine" id="cb4-3" title="3">x =<span class="st"> </span>septic_patients <span class="op">%&gt;%</span></a>
<a class="sourceLine" id="cb4-4" title="4"><span class="st"> </span><span class="kw"><a href="https://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>) <span class="op">%&gt;%</span></a>
<a class="sourceLine" id="cb4-5" title="5"><span class="st"> </span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/pull.html">pull</a></span>(mo)</a>
<a class="sourceLine" id="cb4-6" title="6"> </a>
<a class="sourceLine" id="cb4-7" title="7"><span class="co"># got the right length?</span></a>
<a class="sourceLine" id="cb4-8" title="8"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/length">length</a></span>(x)</a>
<a class="sourceLine" id="cb4-9" title="9"><span class="co"># [1] 500000</span></a>
<a class="sourceLine" id="cb4-10" title="10"></a>
<a class="sourceLine" id="cb4-11" title="11"><span class="co"># and how many unique values do we have?</span></a>
<a class="sourceLine" id="cb4-12" title="12"><span class="kw"><a href="https://dplyr.tidyverse.org/reference/n_distinct.html">n_distinct</a></span>(x)</a>
<a class="sourceLine" id="cb4-13" title="13"><span class="co"># [1] 96</span></a>
<a class="sourceLine" id="cb4-14" title="14"></a>
<a class="sourceLine" id="cb4-15" title="15"><span class="co"># only 96, but distributed in 500,000 results. now let's see:</span></a>
<a class="sourceLine" id="cb4-16" title="16"><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),</a>
<a class="sourceLine" id="cb4-17" title="17"> <span class="dt">times =</span> <span class="dv">10</span>,</a>
<a class="sourceLine" id="cb4-18" title="18"> <span class="dt">unit =</span> <span class="st">"ms"</span>)</a>
<a class="sourceLine" id="cb4-19" title="19"><span class="co"># Unit: milliseconds</span></a>
<a class="sourceLine" id="cb4-20" title="20"><span class="co"># expr min lq mean median uq max neval</span></a>
<a class="sourceLine" id="cb4-21" title="21"><span class="co"># X 114.9342 117.1076 129.6448 120.2047 131.5005 168.6371 10</span></a></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" id="cb5"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb5-1" data-line-number="1"><span class="co"># Unit: milliseconds</span></a>
<a class="sourceLine" id="cb5-2" data-line-number="2"><span class="co"># expr min lq mean median uq max neval</span></a>
<a class="sourceLine" id="cb5-3" data-line-number="3"><span class="co"># X 882.9045 901.3011 1001.677 940.3421 1168.088 1226.846 10</span></a></code></pre></div>
<p>Even the full names of 5 <em>Million</em> values are calculated within a second.</p>
<div class="sourceCode" id="cb5"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb5-1" title="1"><span class="co"># Unit: milliseconds</span></a>
<a class="sourceLine" id="cb5-2" title="2"><span class="co"># expr min lq mean median uq max neval</span></a>
<a class="sourceLine" id="cb5-3" title="3"><span class="co"># X 882.9045 901.3011 1001.677 940.3421 1168.088 1226.846 10</span></a></code></pre></div>
<p>Even determining the full names of 5 <em>Million</em> values is done within a second.</p>
</div>
<div id="precalculated-results" class="section level3">
<h3 class="hasAnchor">
<a href="#precalculated-results" class="anchor"></a>Precalculated results</h3>
<p>What about precalculated results? If the input is an already precalculated result of a helper function like <code><a href="../reference/mo_property.html">mo_fullname()</a></code>, it almost doesnt take any time at all (see C below):</p>
<div class="sourceCode" id="cb6"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb6-1" data-line-number="1"><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>),</a>
<a class="sourceLine" id="cb6-2" data-line-number="2"> <span class="dt">B =</span> <span class="kw"><a href="../reference/mo_property.html">mo_fullname</a></span>(<span class="st">"S. aureus"</span>),</a>
<a class="sourceLine" id="cb6-3" data-line-number="3"> <span class="dt">C =</span> <span class="kw"><a href="../reference/mo_property.html">mo_fullname</a></span>(<span class="st">"Staphylococcus aureus"</span>),</a>
<a class="sourceLine" id="cb6-4" data-line-number="4"> <span class="dt">times =</span> <span class="dv">10</span>,</a>
<a class="sourceLine" id="cb6-5" data-line-number="5"> <span class="dt">unit =</span> <span class="st">"ms"</span>)</a>
<a class="sourceLine" id="cb6-6" data-line-number="6"><span class="co"># Unit: milliseconds</span></a>
<a class="sourceLine" id="cb6-7" data-line-number="7"><span class="co"># expr min lq mean median uq max neval</span></a>
<a class="sourceLine" id="cb6-8" data-line-number="8"><span class="co"># A 11.364086 11.460537 11.5104799 11.4795330 11.524860 11.818263 10</span></a>
<a class="sourceLine" id="cb6-9" data-line-number="9"><span class="co"># B 11.976454 12.012352 12.1704592 12.0853020 12.210004 12.881737 10</span></a>
<a class="sourceLine" id="cb6-10" data-line-number="10"><span class="co"># C 0.095823 0.102528 0.1167754 0.1153785 0.132629 0.140661 10</span></a></code></pre></div>
<div class="sourceCode" id="cb6"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb6-1" title="1"><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>),</a>
<a class="sourceLine" id="cb6-2" title="2"> <span class="dt">B =</span> <span class="kw"><a href="../reference/mo_property.html">mo_fullname</a></span>(<span class="st">"S. aureus"</span>),</a>
<a class="sourceLine" id="cb6-3" title="3"> <span class="dt">C =</span> <span class="kw"><a href="../reference/mo_property.html">mo_fullname</a></span>(<span class="st">"Staphylococcus aureus"</span>),</a>
<a class="sourceLine" id="cb6-4" title="4"> <span class="dt">times =</span> <span class="dv">10</span>,</a>
<a class="sourceLine" id="cb6-5" title="5"> <span class="dt">unit =</span> <span class="st">"ms"</span>)</a>
<a class="sourceLine" id="cb6-6" title="6"><span class="co"># Unit: milliseconds</span></a>
<a class="sourceLine" id="cb6-7" title="7"><span class="co"># expr min lq mean median uq max neval</span></a>
<a class="sourceLine" id="cb6-8" title="8"><span class="co"># A 11.364086 11.460537 11.5104799 11.4795330 11.524860 11.818263 10</span></a>
<a class="sourceLine" id="cb6-9" title="9"><span class="co"># B 11.976454 12.012352 12.1704592 12.0853020 12.210004 12.881737 10</span></a>
<a class="sourceLine" id="cb6-10" title="10"><span class="co"># C 0.095823 0.102528 0.1167754 0.1153785 0.132629 0.140661 10</span></a></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" id="cb7"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb7-1" data-line-number="1"><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>),</a>
<a class="sourceLine" id="cb7-2" data-line-number="2"> <span class="dt">B =</span> <span class="kw"><a href="../reference/mo_property.html">mo_genus</a></span>(<span class="st">"Staphylococcus"</span>),</a>
<a class="sourceLine" id="cb7-3" data-line-number="3"> <span class="dt">C =</span> <span class="kw"><a href="../reference/mo_property.html">mo_fullname</a></span>(<span class="st">"Staphylococcus aureus"</span>),</a>
<a class="sourceLine" id="cb7-4" data-line-number="4"> <span class="dt">D =</span> <span class="kw"><a href="../reference/mo_property.html">mo_family</a></span>(<span class="st">"Staphylococcaceae"</span>),</a>
<a class="sourceLine" id="cb7-5" data-line-number="5"> <span class="dt">E =</span> <span class="kw"><a href="../reference/mo_property.html">mo_order</a></span>(<span class="st">"Bacillales"</span>),</a>
<a class="sourceLine" id="cb7-6" data-line-number="6"> <span class="dt">F =</span> <span class="kw"><a href="../reference/mo_property.html">mo_class</a></span>(<span class="st">"Bacilli"</span>),</a>
<a class="sourceLine" id="cb7-7" data-line-number="7"> <span class="dt">G =</span> <span class="kw"><a href="../reference/mo_property.html">mo_phylum</a></span>(<span class="st">"Firmicutes"</span>),</a>
<a class="sourceLine" id="cb7-8" data-line-number="8"> <span class="dt">H =</span> <span class="kw"><a href="../reference/mo_property.html">mo_subkingdom</a></span>(<span class="st">"Posibacteria"</span>),</a>
<a class="sourceLine" id="cb7-9" data-line-number="9"> <span class="dt">I =</span> <span class="kw"><a href="../reference/mo_property.html">mo_kingdom</a></span>(<span class="st">"Bacteria"</span>),</a>
<a class="sourceLine" id="cb7-10" data-line-number="10"> <span class="dt">times =</span> <span class="dv">10</span>,</a>
<a class="sourceLine" id="cb7-11" data-line-number="11"> <span class="dt">unit =</span> <span class="st">"ms"</span>)</a>
<a class="sourceLine" id="cb7-12" data-line-number="12"><span class="co"># Unit: milliseconds</span></a>
<a class="sourceLine" id="cb7-13" data-line-number="13"><span class="co"># expr min lq mean median uq max neval</span></a>
<a class="sourceLine" id="cb7-14" data-line-number="14"><span class="co"># A 0.105181 0.121314 0.1478538 0.1465265 0.166711 0.211409 10</span></a>
<a class="sourceLine" id="cb7-15" data-line-number="15"><span class="co"># B 0.132558 0.146388 0.1584278 0.1499835 0.164895 0.208477 10</span></a>
<a class="sourceLine" id="cb7-16" data-line-number="16"><span class="co"># C 0.135492 0.160355 0.2341847 0.1884665 0.348857 0.395931 10</span></a>
<a class="sourceLine" id="cb7-17" data-line-number="17"><span class="co"># D 0.109650 0.115727 0.1270481 0.1264130 0.128648 0.168317 10</span></a>
<a class="sourceLine" id="cb7-18" data-line-number="18"><span class="co"># E 0.081574 0.096940 0.0992582 0.0980915 0.101479 0.120477 10</span></a>
<a class="sourceLine" id="cb7-19" data-line-number="19"><span class="co"># F 0.081575 0.088489 0.0988463 0.0989650 0.103365 0.126482 10</span></a>
<a class="sourceLine" id="cb7-20" data-line-number="20"><span class="co"># G 0.091981 0.095333 0.1043568 0.1001530 0.111327 0.129625 10</span></a>
<a class="sourceLine" id="cb7-21" data-line-number="21"><span class="co"># H 0.092610 0.093169 0.1009135 0.0985455 0.101828 0.120406 10</span></a>
<a class="sourceLine" id="cb7-22" data-line-number="22"><span class="co"># I 0.087371 0.091213 0.1069758 0.0941815 0.109302 0.192831 10</span></a></code></pre></div>
<div class="sourceCode" id="cb7"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb7-1" title="1"><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>),</a>
<a class="sourceLine" id="cb7-2" title="2"> <span class="dt">B =</span> <span class="kw"><a href="../reference/mo_property.html">mo_genus</a></span>(<span class="st">"Staphylococcus"</span>),</a>
<a class="sourceLine" id="cb7-3" title="3"> <span class="dt">C =</span> <span class="kw"><a href="../reference/mo_property.html">mo_fullname</a></span>(<span class="st">"Staphylococcus aureus"</span>),</a>
<a class="sourceLine" id="cb7-4" title="4"> <span class="dt">D =</span> <span class="kw"><a href="../reference/mo_property.html">mo_family</a></span>(<span class="st">"Staphylococcaceae"</span>),</a>
<a class="sourceLine" id="cb7-5" title="5"> <span class="dt">E =</span> <span class="kw"><a href="../reference/mo_property.html">mo_order</a></span>(<span class="st">"Bacillales"</span>),</a>
<a class="sourceLine" id="cb7-6" title="6"> <span class="dt">F =</span> <span class="kw"><a href="../reference/mo_property.html">mo_class</a></span>(<span class="st">"Bacilli"</span>),</a>
<a class="sourceLine" id="cb7-7" title="7"> <span class="dt">G =</span> <span class="kw"><a href="../reference/mo_property.html">mo_phylum</a></span>(<span class="st">"Firmicutes"</span>),</a>
<a class="sourceLine" id="cb7-8" title="8"> <span class="dt">H =</span> <span class="kw"><a href="../reference/mo_property.html">mo_subkingdom</a></span>(<span class="st">"Posibacteria"</span>),</a>
<a class="sourceLine" id="cb7-9" title="9"> <span class="dt">I =</span> <span class="kw"><a href="../reference/mo_property.html">mo_kingdom</a></span>(<span class="st">"Bacteria"</span>),</a>
<a class="sourceLine" id="cb7-10" title="10"> <span class="dt">times =</span> <span class="dv">10</span>,</a>
<a class="sourceLine" id="cb7-11" title="11"> <span class="dt">unit =</span> <span class="st">"ms"</span>)</a>
<a class="sourceLine" id="cb7-12" title="12"><span class="co"># Unit: milliseconds</span></a>
<a class="sourceLine" id="cb7-13" title="13"><span class="co"># expr min lq mean median uq max neval</span></a>
<a class="sourceLine" id="cb7-14" title="14"><span class="co"># A 0.105181 0.121314 0.1478538 0.1465265 0.166711 0.211409 10</span></a>
<a class="sourceLine" id="cb7-15" title="15"><span class="co"># B 0.132558 0.146388 0.1584278 0.1499835 0.164895 0.208477 10</span></a>
<a class="sourceLine" id="cb7-16" title="16"><span class="co"># C 0.135492 0.160355 0.2341847 0.1884665 0.348857 0.395931 10</span></a>
<a class="sourceLine" id="cb7-17" title="17"><span class="co"># D 0.109650 0.115727 0.1270481 0.1264130 0.128648 0.168317 10</span></a>
<a class="sourceLine" id="cb7-18" title="18"><span class="co"># E 0.081574 0.096940 0.0992582 0.0980915 0.101479 0.120477 10</span></a>
<a class="sourceLine" id="cb7-19" title="19"><span class="co"># F 0.081575 0.088489 0.0988463 0.0989650 0.103365 0.126482 10</span></a>
<a class="sourceLine" id="cb7-20" title="20"><span class="co"># G 0.091981 0.095333 0.1043568 0.1001530 0.111327 0.129625 10</span></a>
<a class="sourceLine" id="cb7-21" title="21"><span class="co"># H 0.092610 0.093169 0.1009135 0.0985455 0.101828 0.120406 10</span></a>
<a class="sourceLine" id="cb7-22" title="22"><span class="co"># I 0.087371 0.091213 0.1069758 0.0941815 0.109302 0.192831 10</span></a></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>
</div>
<div id="results-in-other-languages" class="section level3">
<h3 class="hasAnchor">
<a href="#results-in-other-languages" class="anchor"></a>Results in other languages</h3>
<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" id="cb8"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb8-1" data-line-number="1"><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></a>
<a class="sourceLine" id="cb8-2" data-line-number="2"><span class="co"># "Coagulase Negative Staphylococcus (CoNS)"</span></a>
<a class="sourceLine" id="cb8-3" data-line-number="3"></a>
<a class="sourceLine" id="cb8-4" data-line-number="4"><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></a>
<a class="sourceLine" id="cb8-5" data-line-number="5"><span class="co"># "Staphylococcus à coagulase négative (CoNS)"</span></a>
<a class="sourceLine" id="cb8-6" data-line-number="6"></a>
<a class="sourceLine" id="cb8-7" data-line-number="7"><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>),</a>
<a class="sourceLine" id="cb8-8" data-line-number="8"> <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>),</a>
<a class="sourceLine" id="cb8-9" data-line-number="9"> <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>),</a>
<a class="sourceLine" id="cb8-10" data-line-number="10"> <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>),</a>
<a class="sourceLine" id="cb8-11" data-line-number="11"> <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>),</a>
<a class="sourceLine" id="cb8-12" data-line-number="12"> <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>),</a>
<a class="sourceLine" id="cb8-13" data-line-number="13"> <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>),</a>
<a class="sourceLine" id="cb8-14" data-line-number="14"> <span class="dt">times =</span> <span class="dv">10</span>,</a>
<a class="sourceLine" id="cb8-15" data-line-number="15"> <span class="dt">unit =</span> <span class="st">"ms"</span>)</a>
<a class="sourceLine" id="cb8-16" data-line-number="16"><span class="co"># Unit: milliseconds</span></a>
<a class="sourceLine" id="cb8-17" data-line-number="17"><span class="co"># expr min lq mean median uq max neval</span></a>
<a class="sourceLine" id="cb8-18" data-line-number="18"><span class="co"># en 6.093583 6.51724 6.555105 6.562986 6.630663 6.99698 100</span></a>
<a class="sourceLine" id="cb8-19" data-line-number="19"><span class="co"># de 13.934874 14.35137 16.891587 14.462210 14.764658 43.63956 100</span></a>
<a class="sourceLine" id="cb8-20" data-line-number="20"><span class="co"># nl 13.900092 14.34729 15.943268 14.424565 14.581535 43.76283 100</span></a>
<a class="sourceLine" id="cb8-21" data-line-number="21"><span class="co"># es 13.833813 14.34596 14.574783 14.439757 14.653994 17.49168 100</span></a>
<a class="sourceLine" id="cb8-22" data-line-number="22"><span class="co"># it 13.811883 14.36621 15.179060 14.453515 14.812359 43.64284 100</span></a>
<a class="sourceLine" id="cb8-23" data-line-number="23"><span class="co"># fr 13.798683 14.37019 16.344731 14.468775 14.697610 48.62923 100</span></a>
<a class="sourceLine" id="cb8-24" data-line-number="24"><span class="co"># pt 13.789674 14.36244 15.706321 14.443772 14.679905 44.76701 100</span></a></code></pre></div>
<div class="sourceCode" id="cb8"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb8-1" title="1"><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></a>
<a class="sourceLine" id="cb8-2" title="2"><span class="co"># "Coagulase Negative Staphylococcus (CoNS)"</span></a>
<a class="sourceLine" id="cb8-3" title="3"></a>
<a class="sourceLine" id="cb8-4" title="4"><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></a>
<a class="sourceLine" id="cb8-5" title="5"><span class="co"># "Staphylococcus à coagulase négative (CoNS)"</span></a>
<a class="sourceLine" id="cb8-6" title="6"></a>
<a class="sourceLine" id="cb8-7" title="7"><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>),</a>
<a class="sourceLine" id="cb8-8" title="8"> <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>),</a>
<a class="sourceLine" id="cb8-9" title="9"> <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>),</a>
<a class="sourceLine" id="cb8-10" title="10"> <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>),</a>
<a class="sourceLine" id="cb8-11" title="11"> <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>),</a>
<a class="sourceLine" id="cb8-12" title="12"> <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>),</a>
<a class="sourceLine" id="cb8-13" title="13"> <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>),</a>
<a class="sourceLine" id="cb8-14" title="14"> <span class="dt">times =</span> <span class="dv">10</span>,</a>
<a class="sourceLine" id="cb8-15" title="15"> <span class="dt">unit =</span> <span class="st">"ms"</span>)</a>
<a class="sourceLine" id="cb8-16" title="16"><span class="co"># Unit: milliseconds</span></a>
<a class="sourceLine" id="cb8-17" title="17"><span class="co"># expr min lq mean median uq max neval</span></a>
<a class="sourceLine" id="cb8-18" title="18"><span class="co"># en 6.093583 6.51724 6.555105 6.562986 6.630663 6.99698 100</span></a>
<a class="sourceLine" id="cb8-19" title="19"><span class="co"># de 13.934874 14.35137 16.891587 14.462210 14.764658 43.63956 100</span></a>
<a class="sourceLine" id="cb8-20" title="20"><span class="co"># nl 13.900092 14.34729 15.943268 14.424565 14.581535 43.76283 100</span></a>
<a class="sourceLine" id="cb8-21" title="21"><span class="co"># es 13.833813 14.34596 14.574783 14.439757 14.653994 17.49168 100</span></a>
<a class="sourceLine" id="cb8-22" title="22"><span class="co"># it 13.811883 14.36621 15.179060 14.453515 14.812359 43.64284 100</span></a>
<a class="sourceLine" id="cb8-23" title="23"><span class="co"># fr 13.798683 14.37019 16.344731 14.468775 14.697610 48.62923 100</span></a>
<a class="sourceLine" id="cb8-24" title="24"><span class="co"># pt 13.789674 14.36244 15.706321 14.443772 14.679905 44.76701 100</span></a></code></pre></div>
<p>Currently supported are German, Dutch, Spanish, Italian, French and Portuguese.</p>
</div>
</div>

View File

@ -70,7 +70,7 @@
</a>
</li>
<li>
<a href="../articles/Predict.html">
<a href="../articles/resistance_predict.html">
<span class="fa fa-dice"></span>
Predict antimicrobial resistance
@ -91,14 +91,14 @@
</a>
</li>
<li>
<a href="../articles/mo_property.html">
<a href="../reference/mo_property.html">
<span class="fa fa-bug"></span>
Get properties of a microorganism
</a>
</li>
<li>
<a href="../articles/ab_property.html">
<a href="../reference/atc_property.html">
<span class="fa fa-capsules"></span>
Get properties of an antibiotic
@ -185,7 +185,7 @@
<h1>How to create frequency tables</h1>
<h4 class="author">Matthijs S. Berends</h4>
<h4 class="date">09 February 2019</h4>
<h4 class="date">14 February 2019</h4>
<div class="hidden name"><code>freq.Rmd</code></div>
@ -203,9 +203,9 @@
<h2 class="hasAnchor">
<a href="#frequencies-of-one-variable" class="anchor"></a>Frequencies of one variable</h2>
<p>To only show and quickly review the content of one variable, you can just select this variable in various ways. Lets say we want to get the frequencies of the <code>gender</code> variable of the <code>septic_patients</code> dataset:</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb1-1" data-line-number="1">septic_patients <span class="op">%&gt;%</span><span class="st"> </span><span class="kw"><a href="../reference/freq.html">freq</a></span>(gender)</a></code></pre></div>
<p><strong>Frequency table of <code>gender</code> from a <code>data.frame</code> (2,000 x 49)</strong><br>
Class: <code>character</code> (<code>character</code>)<br>
<div class="sourceCode" id="cb1"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb1-1" title="1">septic_patients <span class="op">%&gt;%</span><span class="st"> </span><span class="kw"><a href="../reference/freq.html">freq</a></span>(gender)</a></code></pre></div>
<p><strong>Frequency table of <code>gender</code> from a <code>data.frame</code> (2,000 x 49)</strong></p>
<p>Class: <code>character</code> (<code>character</code>)<br>
Length: 2,000 (of which NA: 0 = 0.00%)<br>
Unique: 2</p>
<p>Shortest: 1<br>
@ -245,23 +245,23 @@ Longest: 1</p>
<a href="#frequencies-of-more-than-one-variable" class="anchor"></a>Frequencies of more than one variable</h2>
<p>Multiple variables will be pasted into one variable to review individual cases, keeping a univariate frequency table.</p>
<p>For illustration, we could add some more variables to the <code>septic_patients</code> dataset to learn about bacterial properties:</p>
<div class="sourceCode" id="cb2"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb2-1" data-line-number="1">my_patients &lt;-<span class="st"> </span>septic_patients <span class="op">%&gt;%</span><span class="st"> </span><span class="kw"><a href="../reference/join.html">left_join_microorganisms</a></span>()</a>
<a class="sourceLine" id="cb2-2" data-line-number="2"><span class="co"># Joining, by = "mo"</span></a></code></pre></div>
<div class="sourceCode" id="cb2"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb2-1" title="1">my_patients &lt;-<span class="st"> </span>septic_patients <span class="op">%&gt;%</span><span class="st"> </span><span class="kw"><a href="../reference/join.html">left_join_microorganisms</a></span>()</a>
<a class="sourceLine" id="cb2-2" title="2"><span class="co"># Joining, by = "mo"</span></a></code></pre></div>
<p>Now all variables of the <code>microorganisms</code> dataset have been joined to the <code>septic_patients</code> dataset. The <code>microorganisms</code> dataset consists of the following variables:</p>
<div class="sourceCode" id="cb3"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb3-1" data-line-number="1"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/colnames">colnames</a></span>(microorganisms)</a>
<a class="sourceLine" id="cb3-2" data-line-number="2"><span class="co"># [1] "mo" "tsn" "genus" "species" "subspecies"</span></a>
<a class="sourceLine" id="cb3-3" data-line-number="3"><span class="co"># [6] "fullname" "family" "order" "class" "phylum" </span></a>
<a class="sourceLine" id="cb3-4" data-line-number="4"><span class="co"># [11] "subkingdom" "kingdom" "gramstain" "prevalence" "ref"</span></a></code></pre></div>
<div class="sourceCode" id="cb3"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb3-1" title="1"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/colnames">colnames</a></span>(microorganisms)</a>
<a class="sourceLine" id="cb3-2" title="2"><span class="co"># [1] "mo" "tsn" "genus" "species" "subspecies"</span></a>
<a class="sourceLine" id="cb3-3" title="3"><span class="co"># [6] "fullname" "family" "order" "class" "phylum" </span></a>
<a class="sourceLine" id="cb3-4" title="4"><span class="co"># [11] "subkingdom" "kingdom" "gramstain" "prevalence" "ref"</span></a></code></pre></div>
<p>If we compare the dimensions between the old and new dataset, we can see that these 14 variables were added:</p>
<div class="sourceCode" id="cb4"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb4-1" data-line-number="1"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/dim">dim</a></span>(septic_patients)</a>
<a class="sourceLine" id="cb4-2" data-line-number="2"><span class="co"># [1] 2000 49</span></a>
<a class="sourceLine" id="cb4-3" data-line-number="3"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/dim">dim</a></span>(my_patients)</a>
<a class="sourceLine" id="cb4-4" data-line-number="4"><span class="co"># [1] 2000 63</span></a></code></pre></div>
<div class="sourceCode" id="cb4"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb4-1" title="1"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/dim">dim</a></span>(septic_patients)</a>
<a class="sourceLine" id="cb4-2" title="2"><span class="co"># [1] 2000 49</span></a>
<a class="sourceLine" id="cb4-3" title="3"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/dim">dim</a></span>(my_patients)</a>
<a class="sourceLine" id="cb4-4" title="4"><span class="co"># [1] 2000 63</span></a></code></pre></div>
<p>So now the <code>genus</code> and <code>species</code> variables are available. A frequency table of these combined variables can be created like this:</p>
<div class="sourceCode" id="cb5"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb5-1" data-line-number="1">my_patients <span class="op">%&gt;%</span></a>
<a class="sourceLine" id="cb5-2" data-line-number="2"><span class="st"> </span><span class="kw"><a href="../reference/freq.html">freq</a></span>(genus, species, <span class="dt">nmax =</span> <span class="dv">15</span>)</a></code></pre></div>
<p><strong>Frequency table of <code>genus</code> and <code>species</code> from a <code>data.frame</code> (2,000 x 63)</strong><br>
Columns: 2<br>
<div class="sourceCode" id="cb5"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb5-1" title="1">my_patients <span class="op">%&gt;%</span></a>
<a class="sourceLine" id="cb5-2" title="2"><span class="st"> </span><span class="kw"><a href="../reference/freq.html">freq</a></span>(genus, species, <span class="dt">nmax =</span> <span class="dv">15</span>)</a></code></pre></div>
<p><strong>Frequency table of <code>genus</code> and <code>species</code> from a <code>data.frame</code> (2,000 x 63)</strong></p>
<p>Columns: 2<br>
Length: 2,000 (of which NA: 0 = 0.00%)<br>
Unique: 96</p>
<p>Shortest: 12<br>
@ -405,12 +405,12 @@ Longest: 34</p>
<a href="#frequencies-of-numeric-values" class="anchor"></a>Frequencies of numeric values</h2>
<p>Frequency tables can be created of any input.</p>
<p>In case of numeric values (like integers, doubles, etc.) additional descriptive statistics will be calculated and shown into the header:</p>
<div class="sourceCode" id="cb6"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb6-1" data-line-number="1"><span class="co"># # get age distribution of unique patients</span></a>
<a class="sourceLine" id="cb6-2" data-line-number="2">septic_patients <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb6-3" data-line-number="3"><span class="st"> </span><span class="kw">distinct</span>(patient_id, <span class="dt">.keep_all =</span> <span class="ot">TRUE</span>) <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb6-4" data-line-number="4"><span class="st"> </span><span class="kw"><a href="../reference/freq.html">freq</a></span>(age, <span class="dt">nmax =</span> <span class="dv">5</span>, <span class="dt">header =</span> <span class="ot">TRUE</span>)</a></code></pre></div>
<p><strong>Frequency table of <code>age</code> from a <code>data.frame</code> (981 x 49)</strong><br>
Class: <code>numeric</code> (<code>numeric</code>)<br>
<div class="sourceCode" id="cb6"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb6-1" title="1"><span class="co"># # get age distribution of unique patients</span></a>
<a class="sourceLine" id="cb6-2" title="2">septic_patients <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb6-3" title="3"><span class="st"> </span><span class="kw">distinct</span>(patient_id, <span class="dt">.keep_all =</span> <span class="ot">TRUE</span>) <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb6-4" title="4"><span class="st"> </span><span class="kw"><a href="../reference/freq.html">freq</a></span>(age, <span class="dt">nmax =</span> <span class="dv">5</span>, <span class="dt">header =</span> <span class="ot">TRUE</span>)</a></code></pre></div>
<p><strong>Frequency table of <code>age</code> from a <code>data.frame</code> (981 x 49)</strong></p>
<p>Class: <code>numeric</code> (<code>numeric</code>)<br>
Length: 981 (of which NA: 0 = 0.00%)<br>
Unique: 73</p>
<p>Mean: 71.08<br>
@ -486,12 +486,12 @@ Outliers: 15 (unique count: 12)</p>
<a href="#frequencies-of-factors" class="anchor"></a>Frequencies of factors</h2>
<p>To sort frequencies of factors on factor level instead of item count, use the <code>sort.count</code> parameter.</p>
<p><code>sort.count</code> is <code>TRUE</code> by default. Compare this default behaviour…</p>
<div class="sourceCode" id="cb7"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb7-1" data-line-number="1">septic_patients <span class="op">%&gt;%</span></a>
<a class="sourceLine" id="cb7-2" data-line-number="2"><span class="st"> </span><span class="kw"><a href="../reference/freq.html">freq</a></span>(hospital_id)</a></code></pre></div>
<p><strong>Frequency table of <code>hospital_id</code> from a <code>data.frame</code> (2,000 x 49)</strong><br>
Class: <code>factor</code> (<code>numeric</code>)<br>
Levels: A, B, C, D<br>
<div class="sourceCode" id="cb7"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb7-1" title="1">septic_patients <span class="op">%&gt;%</span></a>
<a class="sourceLine" id="cb7-2" title="2"><span class="st"> </span><span class="kw"><a href="../reference/freq.html">freq</a></span>(hospital_id)</a></code></pre></div>
<p><strong>Frequency table of <code>hospital_id</code> from a <code>data.frame</code> (2,000 x 49)</strong></p>
<p>Class: <code>factor</code> (<code>numeric</code>)<br>
Length: 2,000 (of which NA: 0 = 0.00%)<br>
Levels: 4: <code>A</code>, <code>B</code>, <code>C</code>, <code>D</code><br>
Unique: 4</p>
<table class="table">
<thead><tr class="header">
@ -538,12 +538,12 @@ Unique: 4</p>
</tbody>
</table>
<p>… with this, where items are now sorted on count:</p>
<div class="sourceCode" id="cb8"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb8-1" data-line-number="1">septic_patients <span class="op">%&gt;%</span></a>
<a class="sourceLine" id="cb8-2" data-line-number="2"><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>)</a></code></pre></div>
<p><strong>Frequency table of <code>hospital_id</code> from a <code>data.frame</code> (2,000 x 49)</strong><br>
Class: <code>factor</code> (<code>numeric</code>)<br>
Levels: A, B, C, D<br>
<div class="sourceCode" id="cb8"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb8-1" title="1">septic_patients <span class="op">%&gt;%</span></a>
<a class="sourceLine" id="cb8-2" title="2"><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>)</a></code></pre></div>
<p><strong>Frequency table of <code>hospital_id</code> from a <code>data.frame</code> (2,000 x 49)</strong></p>
<p>Class: <code>factor</code> (<code>numeric</code>)<br>
Length: 2,000 (of which NA: 0 = 0.00%)<br>
Levels: 4: <code>A</code>, <code>B</code>, <code>C</code>, <code>D</code><br>
Unique: 4</p>
<table class="table">
<thead><tr class="header">
@ -590,14 +590,14 @@ Unique: 4</p>
</tbody>
</table>
<p>All classes will be printed into the header (default is <code>FALSE</code> when using markdown like this document). Variables with the new <code>rsi</code> class of this AMR package are actually ordered factors and have three classes (look at <code>Class</code> in the header):</p>
<div class="sourceCode" id="cb9"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb9-1" data-line-number="1">septic_patients <span class="op">%&gt;%</span></a>
<a class="sourceLine" id="cb9-2" data-line-number="2"><span class="st"> </span><span class="kw"><a href="../reference/freq.html">freq</a></span>(amox, <span class="dt">header =</span> <span class="ot">TRUE</span>)</a></code></pre></div>
<p><strong>Frequency table of <code>amox</code> from a <code>data.frame</code> (2,000 x 49)</strong><br>
Class: <code>factor</code> &gt; <code>ordered</code> &gt; <code>rsi</code> (<code>numeric</code>)<br>
Levels: S &lt; I &lt; R<br>
<div class="sourceCode" id="cb9"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb9-1" title="1">septic_patients <span class="op">%&gt;%</span></a>
<a class="sourceLine" id="cb9-2" title="2"><span class="st"> </span><span class="kw"><a href="../reference/freq.html">freq</a></span>(amox, <span class="dt">header =</span> <span class="ot">TRUE</span>)</a></code></pre></div>
<p><strong>Frequency table of <code>amox</code> from a <code>data.frame</code> (2,000 x 49)</strong></p>
<p>Class: <code>factor</code> &gt; <code>ordered</code> &gt; <code>rsi</code> (<code>numeric</code>)<br>
Length: 2,000 (of which NA: 771 = 38.55%)<br>
Levels: 3: <code>S</code> &lt; <code>I</code> &lt; <code>R</code><br>
Unique: 3</p>
<p>%IR: 55.82% (ratio S : IR = 1.0 : 1.3)</p>
<p>%IR: 34.30% (ratio 1:1.3)</p>
<table class="table">
<thead><tr class="header">
<th align="left"></th>
@ -639,10 +639,10 @@ Unique: 3</p>
<h2 class="hasAnchor">
<a href="#frequencies-of-dates" class="anchor"></a>Frequencies of dates</h2>
<p>Frequencies of dates will show the oldest and newest date in the data, and the amount of days between them:</p>
<div class="sourceCode" id="cb10"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb10-1" data-line-number="1">septic_patients <span class="op">%&gt;%</span></a>
<a class="sourceLine" id="cb10-2" data-line-number="2"><span class="st"> </span><span class="kw"><a href="../reference/freq.html">freq</a></span>(date, <span class="dt">nmax =</span> <span class="dv">5</span>, <span class="dt">header =</span> <span class="ot">TRUE</span>)</a></code></pre></div>
<p><strong>Frequency table of <code>date</code> from a <code>data.frame</code> (2,000 x 49)</strong><br>
Class: <code>Date</code> (<code>numeric</code>)<br>
<div class="sourceCode" id="cb10"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb10-1" title="1">septic_patients <span class="op">%&gt;%</span></a>
<a class="sourceLine" id="cb10-2" title="2"><span class="st"> </span><span class="kw"><a href="../reference/freq.html">freq</a></span>(date, <span class="dt">nmax =</span> <span class="dv">5</span>, <span class="dt">header =</span> <span class="ot">TRUE</span>)</a></code></pre></div>
<p><strong>Frequency table of <code>date</code> from a <code>data.frame</code> (2,000 x 49)</strong></p>
<p>Class: <code>Date</code> (<code>numeric</code>)<br>
Length: 2,000 (of which NA: 0 = 0.00%)<br>
Unique: 1,140</p>
<p>Oldest: 2 January 2002<br>
@ -706,11 +706,11 @@ Median: 31 July 2009 (47.39%)</p>
<h2 class="hasAnchor">
<a href="#assigning-a-frequency-table-to-an-object" class="anchor"></a>Assigning a frequency table to an object</h2>
<p>A frequency table is actaually a regular <code>data.frame</code>, with the exception that it contains an additional class.</p>
<div class="sourceCode" id="cb11"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb11-1" data-line-number="1">my_df &lt;-<span class="st"> </span>septic_patients <span class="op">%&gt;%</span><span class="st"> </span><span class="kw"><a href="../reference/freq.html">freq</a></span>(age)</a>
<a class="sourceLine" id="cb11-2" data-line-number="2"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/class">class</a></span>(my_df)</a></code></pre></div>
<div class="sourceCode" id="cb11"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb11-1" title="1">my_df &lt;-<span class="st"> </span>septic_patients <span class="op">%&gt;%</span><span class="st"> </span><span class="kw"><a href="../reference/freq.html">freq</a></span>(age)</a>
<a class="sourceLine" id="cb11-2" title="2"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/class">class</a></span>(my_df)</a></code></pre></div>
<p>[1] “frequency_tbl” “data.frame”</p>
<p>Because of this additional class, a frequency table prints like the examples above. But the object itself contains the complete table without a row limitation:</p>
<div class="sourceCode" id="cb12"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb12-1" data-line-number="1"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/dim">dim</a></span>(my_df)</a></code></pre></div>
<div class="sourceCode" id="cb12"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb12-1" title="1"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/dim">dim</a></span>(my_df)</a></code></pre></div>
<p>[1] 74 5</p>
</div>
<div id="additional-parameters" class="section level2">
@ -721,14 +721,14 @@ Median: 31 July 2009 (47.39%)</p>
<a href="#parameter-na-rm" class="anchor"></a>Parameter <code>na.rm</code>
</h3>
<p>With the <code>na.rm</code> parameter (defaults to <code>TRUE</code>, but they will always be shown into the header), you can include <code>NA</code> values in the frequency table:</p>
<div class="sourceCode" id="cb13"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb13-1" data-line-number="1">septic_patients <span class="op">%&gt;%</span></a>
<a class="sourceLine" id="cb13-2" data-line-number="2"><span class="st"> </span><span class="kw"><a href="../reference/freq.html">freq</a></span>(amox, <span class="dt">na.rm =</span> <span class="ot">FALSE</span>)</a></code></pre></div>
<p><strong>Frequency table of <code>amox</code> from a <code>data.frame</code> (2,000 x 49)</strong><br>
Class: <code>factor</code> &gt; <code>ordered</code> &gt; <code>rsi</code> (<code>numeric</code>)<br>
Levels: S &lt; I &lt; R<br>
Length: 2,771 (of which NA: 771 = 27.82%)<br>
<div class="sourceCode" id="cb13"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb13-1" title="1">septic_patients <span class="op">%&gt;%</span></a>
<a class="sourceLine" id="cb13-2" title="2"><span class="st"> </span><span class="kw"><a href="../reference/freq.html">freq</a></span>(amox, <span class="dt">na.rm =</span> <span class="ot">FALSE</span>)</a></code></pre></div>
<p><strong>Frequency table of <code>amox</code> from a <code>data.frame</code> (2,000 x 49)</strong></p>
<p>Class: <code>factor</code> &gt; <code>ordered</code> &gt; <code>rsi</code> (<code>numeric</code>)<br>
Length: 2,000 (of which NA: 771 = 38.55%)<br>
Levels: 3: <code>S</code> &lt; <code>I</code> &lt; <code>R</code><br>
Unique: 4</p>
<p>%IR: 34.30% (ratio S : IR = 1.0 : 1.3)</p>
<p>%IR: 34.30% (ratio 1:1.3)</p>
<table class="table">
<thead><tr class="header">
<th align="left"></th>
@ -779,12 +779,12 @@ Unique: 4</p>
<a href="#parameter-row-names" class="anchor"></a>Parameter <code>row.names</code>
</h3>
<p>The default frequency tables shows row indices. To remove them, use <code>row.names = FALSE</code>:</p>
<div class="sourceCode" id="cb14"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb14-1" data-line-number="1">septic_patients <span class="op">%&gt;%</span></a>
<a class="sourceLine" id="cb14-2" data-line-number="2"><span class="st"> </span><span class="kw"><a href="../reference/freq.html">freq</a></span>(hospital_id, <span class="dt">row.names =</span> <span class="ot">FALSE</span>)</a></code></pre></div>
<p><strong>Frequency table of <code>hospital_id</code> from a <code>data.frame</code> (2,000 x 49)</strong><br>
Class: <code>factor</code> (<code>numeric</code>)<br>
Levels: A, B, C, D<br>
<div class="sourceCode" id="cb14"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb14-1" title="1">septic_patients <span class="op">%&gt;%</span></a>
<a class="sourceLine" id="cb14-2" title="2"><span class="st"> </span><span class="kw"><a href="../reference/freq.html">freq</a></span>(hospital_id, <span class="dt">row.names =</span> <span class="ot">FALSE</span>)</a></code></pre></div>
<p><strong>Frequency table of <code>hospital_id</code> from a <code>data.frame</code> (2,000 x 49)</strong></p>
<p>Class: <code>factor</code> (<code>numeric</code>)<br>
Length: 2,000 (of which NA: 0 = 0.00%)<br>
Levels: 4: <code>A</code>, <code>B</code>, <code>C</code>, <code>D</code><br>
Unique: 4</p>
<table class="table">
<thead><tr class="header">
@ -831,12 +831,12 @@ Unique: 4</p>
<a href="#parameter-markdown" class="anchor"></a>Parameter <code>markdown</code>
</h3>
<p>The <code>markdown</code> parameter is <code>TRUE</code> at default in non-interactive sessions, like in reports created with R Markdown. This will always print all rows, unless <code>nmax</code> is set.</p>
<div class="sourceCode" id="cb15"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb15-1" data-line-number="1">septic_patients <span class="op">%&gt;%</span></a>
<a class="sourceLine" id="cb15-2" data-line-number="2"><span class="st"> </span><span class="kw"><a href="../reference/freq.html">freq</a></span>(hospital_id, <span class="dt">markdown =</span> <span class="ot">TRUE</span>)</a></code></pre></div>
<p><strong>Frequency table of <code>hospital_id</code> from a <code>data.frame</code> (2,000 x 49)</strong><br>
Class: <code>factor</code> (<code>numeric</code>)<br>
Levels: A, B, C, D<br>
<div class="sourceCode" id="cb15"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb15-1" title="1">septic_patients <span class="op">%&gt;%</span></a>
<a class="sourceLine" id="cb15-2" title="2"><span class="st"> </span><span class="kw"><a href="../reference/freq.html">freq</a></span>(hospital_id, <span class="dt">markdown =</span> <span class="ot">TRUE</span>)</a></code></pre></div>
<p><strong>Frequency table of <code>hospital_id</code> from a <code>data.frame</code> (2,000 x 49)</strong></p>
<p>Class: <code>factor</code> (<code>numeric</code>)<br>
Length: 2,000 (of which NA: 0 = 0.00%)<br>
Levels: 4: <code>A</code>, <code>B</code>, <code>C</code>, <code>D</code><br>
Unique: 4</p>
<table class="table">
<thead><tr class="header">

View File

@ -185,7 +185,7 @@
<h1>How to get properties of a microorganism</h1>
<h4 class="author">Matthijs S. Berends</h4>
<h4 class="date">12 February 2019</h4>
<h4 class="date">14 February 2019</h4>
<div class="hidden name"><code>mo_property.Rmd</code></div>

View File

@ -185,7 +185,7 @@
<h1>How to predict antimicrobial resistance</h1>
<h4 class="author">Matthijs S. Berends</h4>
<h4 class="date">12 February 2019</h4>
<h4 class="date">14 February 2019</h4>
<div class="hidden name"><code>resistance_predict.Rmd</code></div>

View File

@ -110,7 +110,7 @@
</a>
</li>
<li>
<a href="../articles/Predict.html">
<a href="../articles/resistance_predict.html">
<span class="fa fa-dice"></span>
Predict antimicrobial resistance
@ -131,14 +131,14 @@
</a>
</li>
<li>
<a href="../articles/mo_property.html">
<a href="../reference/mo_property.html">
<span class="fa fa-bug"></span>
Get properties of a microorganism
</a>
</li>
<li>
<a href="../articles/ab_property.html">
<a href="../reference/atc_property.html">
<span class="fa fa-capsules"></span>
Get properties of an antibiotic

View File

@ -110,7 +110,7 @@
</a>
</li>
<li>
<a href="../articles/Predict.html">
<a href="../articles/resistance_predict.html">
<span class="fa fa-dice"></span>
Predict antimicrobial resistance
@ -131,14 +131,14 @@
</a>
</li>
<li>
<a href="../articles/mo_property.html">
<a href="../reference/mo_property.html">
<span class="fa fa-bug"></span>
Get properties of a microorganism
</a>
</li>
<li>
<a href="../articles/ab_property.html">
<a href="../reference/atc_property.html">
<span class="fa fa-capsules"></span>
Get properties of an antibiotic

View File

@ -110,7 +110,7 @@
</a>
</li>
<li>
<a href="../articles/Predict.html">
<a href="../articles/resistance_predict.html">
<span class="fa fa-dice"></span>
Predict antimicrobial resistance
@ -131,14 +131,14 @@
</a>
</li>
<li>
<a href="../articles/mo_property.html">
<a href="../reference/mo_property.html">
<span class="fa fa-bug"></span>
Get properties of a microorganism
</a>
</li>
<li>
<a href="../articles/ab_property.html">
<a href="../reference/atc_property.html">
<span class="fa fa-capsules"></span>
Get properties of an antibiotic

View File

@ -110,7 +110,7 @@
</a>
</li>
<li>
<a href="../articles/Predict.html">
<a href="../articles/resistance_predict.html">
<span class="fa fa-dice"></span>
Predict antimicrobial resistance
@ -131,14 +131,14 @@
</a>
</li>
<li>
<a href="../articles/mo_property.html">
<a href="../reference/mo_property.html">
<span class="fa fa-bug"></span>
Get properties of a microorganism
</a>
</li>
<li>
<a href="../articles/ab_property.html">
<a href="../reference/atc_property.html">
<span class="fa fa-capsules"></span>
Get properties of an antibiotic

View File

@ -110,7 +110,7 @@
</a>
</li>
<li>
<a href="../articles/Predict.html">
<a href="../articles/resistance_predict.html">
<span class="fa fa-dice"></span>
Predict antimicrobial resistance
@ -131,14 +131,14 @@
</a>
</li>
<li>
<a href="../articles/mo_property.html">
<a href="../reference/mo_property.html">
<span class="fa fa-bug"></span>
Get properties of a microorganism
</a>
</li>
<li>
<a href="../articles/ab_property.html">
<a href="../reference/atc_property.html">
<span class="fa fa-capsules"></span>
Get properties of an antibiotic

View File

@ -110,7 +110,7 @@
</a>
</li>
<li>
<a href="../articles/Predict.html">
<a href="../articles/resistance_predict.html">
<span class="fa fa-dice"></span>
Predict antimicrobial resistance
@ -131,14 +131,14 @@
</a>
</li>
<li>
<a href="../articles/mo_property.html">
<a href="../reference/mo_property.html">
<span class="fa fa-bug"></span>
Get properties of a microorganism
</a>
</li>
<li>
<a href="../articles/ab_property.html">
<a href="../reference/atc_property.html">
<span class="fa fa-capsules"></span>
Get properties of an antibiotic

View File

@ -110,7 +110,7 @@
</a>
</li>
<li>
<a href="../articles/Predict.html">
<a href="../articles/resistance_predict.html">
<span class="fa fa-dice"></span>
Predict antimicrobial resistance
@ -131,14 +131,14 @@
</a>
</li>
<li>
<a href="../articles/mo_property.html">
<a href="../reference/mo_property.html">
<span class="fa fa-bug"></span>
Get properties of a microorganism
</a>
</li>
<li>
<a href="../articles/ab_property.html">
<a href="../reference/atc_property.html">
<span class="fa fa-capsules"></span>
Get properties of an antibiotic

View File

@ -110,7 +110,7 @@
</a>
</li>
<li>
<a href="../articles/Predict.html">
<a href="../articles/resistance_predict.html">
<span class="fa fa-dice"></span>
Predict antimicrobial resistance
@ -131,14 +131,14 @@
</a>
</li>
<li>
<a href="../articles/mo_property.html">
<a href="../reference/mo_property.html">
<span class="fa fa-bug"></span>
Get properties of a microorganism
</a>
</li>
<li>
<a href="../articles/ab_property.html">
<a href="../reference/atc_property.html">
<span class="fa fa-capsules"></span>
Get properties of an antibiotic

View File

@ -110,7 +110,7 @@
</a>
</li>
<li>
<a href="../articles/Predict.html">
<a href="../articles/resistance_predict.html">
<span class="fa fa-dice"></span>
Predict antimicrobial resistance
@ -131,14 +131,14 @@
</a>
</li>
<li>
<a href="../articles/mo_property.html">
<a href="../reference/mo_property.html">
<span class="fa fa-bug"></span>
Get properties of a microorganism
</a>
</li>
<li>
<a href="../articles/ab_property.html">
<a href="../reference/atc_property.html">
<span class="fa fa-capsules"></span>
Get properties of an antibiotic

View File

@ -110,7 +110,7 @@
</a>
</li>
<li>
<a href="../articles/Predict.html">
<a href="../articles/resistance_predict.html">
<span class="fa fa-dice"></span>
Predict antimicrobial resistance
@ -131,14 +131,14 @@
</a>
</li>
<li>
<a href="../articles/mo_property.html">
<a href="../reference/mo_property.html">
<span class="fa fa-bug"></span>
Get properties of a microorganism
</a>
</li>
<li>
<a href="../articles/ab_property.html">
<a href="../reference/atc_property.html">
<span class="fa fa-capsules"></span>
Get properties of an antibiotic

View File

@ -110,7 +110,7 @@
</a>
</li>
<li>
<a href="../articles/Predict.html">
<a href="../articles/resistance_predict.html">
<span class="fa fa-dice"></span>
Predict antimicrobial resistance
@ -131,14 +131,14 @@
</a>
</li>
<li>
<a href="../articles/mo_property.html">
<a href="../reference/mo_property.html">
<span class="fa fa-bug"></span>
Get properties of a microorganism
</a>
</li>
<li>
<a href="../articles/ab_property.html">
<a href="../reference/atc_property.html">
<span class="fa fa-capsules"></span>
Get properties of an antibiotic

View File

@ -110,7 +110,7 @@
</a>
</li>
<li>
<a href="../articles/Predict.html">
<a href="../articles/resistance_predict.html">
<span class="fa fa-dice"></span>
Predict antimicrobial resistance
@ -131,14 +131,14 @@
</a>
</li>
<li>
<a href="../articles/mo_property.html">
<a href="../reference/mo_property.html">
<span class="fa fa-bug"></span>
Get properties of a microorganism
</a>
</li>
<li>
<a href="../articles/ab_property.html">
<a href="../reference/atc_property.html">
<span class="fa fa-capsules"></span>
Get properties of an antibiotic

View File

@ -110,7 +110,7 @@
</a>
</li>
<li>
<a href="../articles/Predict.html">
<a href="../articles/resistance_predict.html">
<span class="fa fa-dice"></span>
Predict antimicrobial resistance
@ -131,14 +131,14 @@
</a>
</li>
<li>
<a href="../articles/mo_property.html">
<a href="../reference/mo_property.html">
<span class="fa fa-bug"></span>
Get properties of a microorganism
</a>
</li>
<li>
<a href="../articles/ab_property.html">
<a href="../reference/atc_property.html">
<span class="fa fa-capsules"></span>
Get properties of an antibiotic

View File

@ -110,7 +110,7 @@
</a>
</li>
<li>
<a href="../articles/Predict.html">
<a href="../articles/resistance_predict.html">
<span class="fa fa-dice"></span>
Predict antimicrobial resistance
@ -131,14 +131,14 @@
</a>
</li>
<li>
<a href="../articles/mo_property.html">
<a href="../reference/mo_property.html">
<span class="fa fa-bug"></span>
Get properties of a microorganism
</a>
</li>
<li>
<a href="../articles/ab_property.html">
<a href="../reference/atc_property.html">
<span class="fa fa-capsules"></span>
Get properties of an antibiotic

View File

@ -110,7 +110,7 @@
</a>
</li>
<li>
<a href="../articles/Predict.html">
<a href="../articles/resistance_predict.html">
<span class="fa fa-dice"></span>
Predict antimicrobial resistance
@ -131,14 +131,14 @@
</a>
</li>
<li>
<a href="../articles/mo_property.html">
<a href="../reference/mo_property.html">
<span class="fa fa-bug"></span>
Get properties of a microorganism
</a>
</li>
<li>
<a href="../articles/ab_property.html">
<a href="../reference/atc_property.html">
<span class="fa fa-capsules"></span>
Get properties of an antibiotic

View File

@ -110,7 +110,7 @@
</a>
</li>
<li>
<a href="../articles/Predict.html">
<a href="../articles/resistance_predict.html">
<span class="fa fa-dice"></span>
Predict antimicrobial resistance
@ -131,14 +131,14 @@
</a>
</li>
<li>
<a href="../articles/mo_property.html">
<a href="../reference/mo_property.html">
<span class="fa fa-bug"></span>
Get properties of a microorganism
</a>
</li>
<li>
<a href="../articles/ab_property.html">
<a href="../reference/atc_property.html">
<span class="fa fa-capsules"></span>
Get properties of an antibiotic

View File

@ -111,7 +111,7 @@ count_R and count_IR can be used to count resistant isolates, count_S and count_
</a>
</li>
<li>
<a href="../articles/Predict.html">
<a href="../articles/resistance_predict.html">
<span class="fa fa-dice"></span>
Predict antimicrobial resistance
@ -132,14 +132,14 @@ count_R and count_IR can be used to count resistant isolates, count_S and count_
</a>
</li>
<li>
<a href="../articles/mo_property.html">
<a href="../reference/mo_property.html">
<span class="fa fa-bug"></span>
Get properties of a microorganism
</a>
</li>
<li>
<a href="../articles/ab_property.html">
<a href="../reference/atc_property.html">
<span class="fa fa-capsules"></span>
Get properties of an antibiotic

View File

@ -110,7 +110,7 @@
</a>
</li>
<li>
<a href="../articles/Predict.html">
<a href="../articles/resistance_predict.html">
<span class="fa fa-dice"></span>
Predict antimicrobial resistance
@ -131,14 +131,14 @@
</a>
</li>
<li>
<a href="../articles/mo_property.html">
<a href="../reference/mo_property.html">
<span class="fa fa-bug"></span>
Get properties of a microorganism
</a>
</li>
<li>
<a href="../articles/ab_property.html">
<a href="../reference/atc_property.html">
<span class="fa fa-capsules"></span>
Get properties of an antibiotic

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@ -110,7 +110,7 @@
</a>
</li>
<li>
<a href="../articles/Predict.html">
<a href="../articles/resistance_predict.html">
<span class="fa fa-dice"></span>
Predict antimicrobial resistance
@ -131,14 +131,14 @@
</a>
</li>
<li>
<a href="../articles/mo_property.html">
<a href="../reference/mo_property.html">
<span class="fa fa-bug"></span>
Get properties of a microorganism
</a>
</li>
<li>
<a href="../articles/ab_property.html">
<a href="../reference/atc_property.html">
<span class="fa fa-capsules"></span>
Get properties of an antibiotic

View File

@ -111,7 +111,7 @@ top_freq can be used to get the top/bottom n items of a frequency table, with co
</a>
</li>
<li>
<a href="../articles/Predict.html">
<a href="../articles/resistance_predict.html">
<span class="fa fa-dice"></span>
Predict antimicrobial resistance
@ -132,14 +132,14 @@ top_freq can be used to get the top/bottom n items of a frequency table, with co
</a>
</li>
<li>
<a href="../articles/mo_property.html">
<a href="../reference/mo_property.html">
<span class="fa fa-bug"></span>
Get properties of a microorganism
</a>
</li>
<li>
<a href="../articles/ab_property.html">
<a href="../reference/atc_property.html">
<span class="fa fa-capsules"></span>
Get properties of an antibiotic

View File

@ -110,7 +110,7 @@
</a>
</li>
<li>
<a href="../articles/Predict.html">
<a href="../articles/resistance_predict.html">
<span class="fa fa-dice"></span>
Predict antimicrobial resistance
@ -131,14 +131,14 @@
</a>
</li>
<li>
<a href="../articles/mo_property.html">
<a href="../reference/mo_property.html">
<span class="fa fa-bug"></span>
Get properties of a microorganism
</a>
</li>
<li>
<a href="../articles/ab_property.html">
<a href="../reference/atc_property.html">
<span class="fa fa-capsules"></span>
Get properties of an antibiotic

View File

@ -110,7 +110,7 @@
</a>
</li>
<li>
<a href="../articles/Predict.html">
<a href="../articles/resistance_predict.html">
<span class="fa fa-dice"></span>
Predict antimicrobial resistance
@ -131,14 +131,14 @@
</a>
</li>
<li>
<a href="../articles/mo_property.html">
<a href="../reference/mo_property.html">
<span class="fa fa-bug"></span>
Get properties of a microorganism
</a>
</li>
<li>
<a href="../articles/ab_property.html">
<a href="../reference/atc_property.html">
<span class="fa fa-capsules"></span>
Get properties of an antibiotic

View File

@ -110,7 +110,7 @@
</a>
</li>
<li>
<a href="../articles/Predict.html">
<a href="../articles/resistance_predict.html">
<span class="fa fa-dice"></span>
Predict antimicrobial resistance
@ -131,14 +131,14 @@
</a>
</li>
<li>
<a href="../articles/mo_property.html">
<a href="../reference/mo_property.html">
<span class="fa fa-bug"></span>
Get properties of a microorganism
</a>
</li>
<li>
<a href="../articles/ab_property.html">
<a href="../reference/atc_property.html">
<span class="fa fa-capsules"></span>
Get properties of an antibiotic

View File

@ -110,7 +110,7 @@
</a>
</li>
<li>
<a href="../articles/Predict.html">
<a href="../articles/resistance_predict.html">
<span class="fa fa-dice"></span>
Predict antimicrobial resistance
@ -131,14 +131,14 @@
</a>
</li>
<li>
<a href="../articles/mo_property.html">
<a href="../reference/mo_property.html">
<span class="fa fa-bug"></span>
Get properties of a microorganism
</a>
</li>
<li>
<a href="../articles/ab_property.html">
<a href="../reference/atc_property.html">
<span class="fa fa-capsules"></span>
Get properties of an antibiotic

View File

@ -110,7 +110,7 @@
</a>
</li>
<li>
<a href="../articles/Predict.html">
<a href="../articles/resistance_predict.html">
<span class="fa fa-dice"></span>
Predict antimicrobial resistance
@ -131,14 +131,14 @@
</a>
</li>
<li>
<a href="../articles/mo_property.html">
<a href="../reference/mo_property.html">
<span class="fa fa-bug"></span>
Get properties of a microorganism
</a>
</li>
<li>
<a href="../articles/ab_property.html">
<a href="../reference/atc_property.html">
<span class="fa fa-capsules"></span>
Get properties of an antibiotic

View File

@ -110,7 +110,7 @@
</a>
</li>
<li>
<a href="../articles/Predict.html">
<a href="../articles/resistance_predict.html">
<span class="fa fa-dice"></span>
Predict antimicrobial resistance
@ -131,14 +131,14 @@
</a>
</li>
<li>
<a href="../articles/mo_property.html">
<a href="../reference/mo_property.html">
<span class="fa fa-bug"></span>
Get properties of a microorganism
</a>
</li>
<li>
<a href="../articles/ab_property.html">
<a href="../reference/atc_property.html">
<span class="fa fa-capsules"></span>
Get properties of an antibiotic

View File

@ -110,7 +110,7 @@
</a>
</li>
<li>
<a href="../articles/Predict.html">
<a href="../articles/resistance_predict.html">
<span class="fa fa-dice"></span>
Predict antimicrobial resistance
@ -131,14 +131,14 @@
</a>
</li>
<li>
<a href="../articles/mo_property.html">
<a href="../reference/mo_property.html">
<span class="fa fa-bug"></span>
Get properties of a microorganism
</a>
</li>
<li>
<a href="../articles/ab_property.html">
<a href="../reference/atc_property.html">
<span class="fa fa-capsules"></span>
Get properties of an antibiotic

View File

@ -110,7 +110,7 @@
</a>
</li>
<li>
<a href="../articles/Predict.html">
<a href="../articles/resistance_predict.html">
<span class="fa fa-dice"></span>
Predict antimicrobial resistance
@ -131,14 +131,14 @@
</a>
</li>
<li>
<a href="../articles/mo_property.html">
<a href="../reference/mo_property.html">
<span class="fa fa-bug"></span>
Get properties of a microorganism
</a>
</li>
<li>
<a href="../articles/ab_property.html">
<a href="../reference/atc_property.html">
<span class="fa fa-capsules"></span>
Get properties of an antibiotic

View File

@ -110,7 +110,7 @@
</a>
</li>
<li>
<a href="../articles/Predict.html">
<a href="../articles/resistance_predict.html">
<span class="fa fa-dice"></span>
Predict antimicrobial resistance
@ -131,14 +131,14 @@
</a>
</li>
<li>
<a href="../articles/mo_property.html">
<a href="../reference/mo_property.html">
<span class="fa fa-bug"></span>
Get properties of a microorganism
</a>
</li>
<li>
<a href="../articles/ab_property.html">
<a href="../reference/atc_property.html">
<span class="fa fa-capsules"></span>
Get properties of an antibiotic

View File

@ -110,7 +110,7 @@
</a>
</li>
<li>
<a href="../articles/Predict.html">
<a href="../articles/resistance_predict.html">
<span class="fa fa-dice"></span>
Predict antimicrobial resistance
@ -131,14 +131,14 @@
</a>
</li>
<li>
<a href="../articles/mo_property.html">
<a href="../reference/mo_property.html">
<span class="fa fa-bug"></span>
Get properties of a microorganism
</a>
</li>
<li>
<a href="../articles/ab_property.html">
<a href="../reference/atc_property.html">
<span class="fa fa-capsules"></span>
Get properties of an antibiotic

View File

@ -110,7 +110,7 @@
</a>
</li>
<li>
<a href="../articles/Predict.html">
<a href="../articles/resistance_predict.html">
<span class="fa fa-dice"></span>
Predict antimicrobial resistance
@ -131,14 +131,14 @@
</a>
</li>
<li>
<a href="../articles/mo_property.html">
<a href="../reference/mo_property.html">
<span class="fa fa-bug"></span>
Get properties of a microorganism
</a>
</li>
<li>
<a href="../articles/ab_property.html">
<a href="../reference/atc_property.html">
<span class="fa fa-capsules"></span>
Get properties of an antibiotic

View File

@ -110,7 +110,7 @@
</a>
</li>
<li>
<a href="../articles/Predict.html">
<a href="../articles/resistance_predict.html">
<span class="fa fa-dice"></span>
Predict antimicrobial resistance
@ -131,14 +131,14 @@
</a>
</li>
<li>
<a href="../articles/mo_property.html">
<a href="../reference/mo_property.html">
<span class="fa fa-bug"></span>
Get properties of a microorganism
</a>
</li>
<li>
<a href="../articles/ab_property.html">
<a href="../reference/atc_property.html">
<span class="fa fa-capsules"></span>
Get properties of an antibiotic

View File

@ -110,7 +110,7 @@
</a>
</li>
<li>
<a href="../articles/Predict.html">
<a href="../articles/resistance_predict.html">
<span class="fa fa-dice"></span>
Predict antimicrobial resistance
@ -131,14 +131,14 @@
</a>
</li>
<li>
<a href="../articles/mo_property.html">
<a href="../reference/mo_property.html">
<span class="fa fa-bug"></span>
Get properties of a microorganism
</a>
</li>
<li>
<a href="../articles/ab_property.html">
<a href="../reference/atc_property.html">
<span class="fa fa-capsules"></span>
Get properties of an antibiotic

View File

@ -110,7 +110,7 @@
</a>
</li>
<li>
<a href="../articles/Predict.html">
<a href="../articles/resistance_predict.html">
<span class="fa fa-dice"></span>
Predict antimicrobial resistance
@ -131,14 +131,14 @@
</a>
</li>
<li>
<a href="../articles/mo_property.html">
<a href="../reference/mo_property.html">
<span class="fa fa-bug"></span>
Get properties of a microorganism
</a>
</li>
<li>
<a href="../articles/ab_property.html">
<a href="../reference/atc_property.html">
<span class="fa fa-capsules"></span>
Get properties of an antibiotic

View File

@ -110,7 +110,7 @@
</a>
</li>
<li>
<a href="../articles/Predict.html">
<a href="../articles/resistance_predict.html">
<span class="fa fa-dice"></span>
Predict antimicrobial resistance
@ -131,14 +131,14 @@
</a>
</li>
<li>
<a href="../articles/mo_property.html">
<a href="../reference/mo_property.html">
<span class="fa fa-bug"></span>
Get properties of a microorganism
</a>
</li>
<li>
<a href="../articles/ab_property.html">
<a href="../reference/atc_property.html">
<span class="fa fa-capsules"></span>
Get properties of an antibiotic

View File

@ -111,7 +111,7 @@ portion_R and portion_IR can be used to calculate resistance, portion_S and port
</a>
</li>
<li>
<a href="../articles/Predict.html">
<a href="../articles/resistance_predict.html">
<span class="fa fa-dice"></span>
Predict antimicrobial resistance
@ -132,14 +132,14 @@ portion_R and portion_IR can be used to calculate resistance, portion_S and port
</a>
</li>
<li>
<a href="../articles/mo_property.html">
<a href="../reference/mo_property.html">
<span class="fa fa-bug"></span>
Get properties of a microorganism
</a>
</li>
<li>
<a href="../articles/ab_property.html">
<a href="../reference/atc_property.html">
<span class="fa fa-capsules"></span>
Get properties of an antibiotic

View File

@ -110,7 +110,7 @@
</a>
</li>
<li>
<a href="../articles/Predict.html">
<a href="../articles/resistance_predict.html">
<span class="fa fa-dice"></span>
Predict antimicrobial resistance
@ -131,14 +131,14 @@
</a>
</li>
<li>
<a href="../articles/mo_property.html">
<a href="../reference/mo_property.html">
<span class="fa fa-bug"></span>
Get properties of a microorganism
</a>
</li>
<li>
<a href="../articles/ab_property.html">
<a href="../reference/atc_property.html">
<span class="fa fa-capsules"></span>
Get properties of an antibiotic

View File

@ -359,7 +359,7 @@ On our website <a href='https://msberends.gitlab.io/AMR'>https://msberends.gitla
<span class='fu'><a href='https://www.rdocumentation.org/packages/base/topics/library'>library</a></span>(<span class='no'>dplyr</span>)
<span class='no'>x</span> <span class='kw'>&lt;-</span> <span class='no'>septic_patients</span> <span class='kw'>%&gt;%</span>
<span class='fu'><a href='first_isolate.html'>filter_first_isolate</a></span>() <span class='kw'>%&gt;%</span>
<span class='fu'><a href='https://www.rdocumentation.org/packages/dplyr/topics/filter'>filter</a></span>(<span class='fu'><a href='mo_property.html'>mo_genus</a></span>(<span class='no'>mo</span>) <span class='kw'>==</span> <span class='st'>"Staphylococcus"</span>) <span class='kw'>%&gt;%</span>
<span class='fu'><a href='https://dplyr.tidyverse.org/reference/filter.html'>filter</a></span>(<span class='fu'><a href='mo_property.html'>mo_genus</a></span>(<span class='no'>mo</span>) <span class='kw'>==</span> <span class='st'>"Staphylococcus"</span>) <span class='kw'>%&gt;%</span>
<span class='fu'>resistance_predict</span>(<span class='st'>"peni"</span>)
<span class='fu'><a href='https://www.rdocumentation.org/packages/graphics/topics/plot'>plot</a></span>(<span class='no'>x</span>)
@ -373,27 +373,27 @@ On our website <a href='https://msberends.gitlab.io/AMR'>https://msberends.gitla
<span class='kw'>if</span> (!<span class='fu'><a href='https://www.rdocumentation.org/packages/base/topics/library'>require</a></span>(<span class='no'>ggplot2</span>)) {
<span class='no'>data</span> <span class='kw'>&lt;-</span> <span class='no'>septic_patients</span> <span class='kw'>%&gt;%</span>
<span class='fu'><a href='https://www.rdocumentation.org/packages/dplyr/topics/filter'>filter</a></span>(<span class='no'>mo</span> <span class='kw'>==</span> <span class='fu'><a href='as.mo.html'>as.mo</a></span>(<span class='st'>"E. coli"</span>)) <span class='kw'>%&gt;%</span>
<span class='fu'><a href='https://dplyr.tidyverse.org/reference/filter.html'>filter</a></span>(<span class='no'>mo</span> <span class='kw'>==</span> <span class='fu'><a href='as.mo.html'>as.mo</a></span>(<span class='st'>"E. coli"</span>)) <span class='kw'>%&gt;%</span>
<span class='fu'>resistance_predict</span>(<span class='kw'>col_ab</span> <span class='kw'>=</span> <span class='st'>"amox"</span>,
<span class='kw'>col_date</span> <span class='kw'>=</span> <span class='st'>"date"</span>,
<span class='kw'>info</span> <span class='kw'>=</span> <span class='fl'>FALSE</span>,
<span class='kw'>minimum</span> <span class='kw'>=</span> <span class='fl'>15</span>)
<span class='fu'><a href='https://www.rdocumentation.org/packages/ggplot2/topics/ggplot'>ggplot</a></span>(<span class='no'>data</span>,
<span class='fu'><a href='https://www.rdocumentation.org/packages/ggplot2/topics/aes'>aes</a></span>(<span class='kw'>x</span> <span class='kw'>=</span> <span class='no'>year</span>)) +
<span class='fu'><a href='https://www.rdocumentation.org/packages/ggplot2/topics/geom_bar'>geom_col</a></span>(<span class='fu'><a href='https://www.rdocumentation.org/packages/ggplot2/topics/aes'>aes</a></span>(<span class='kw'>y</span> <span class='kw'>=</span> <span class='no'>value</span>),
<span class='fu'><a href='https://ggplot2.tidyverse.org/reference/ggplot.html'>ggplot</a></span>(<span class='no'>data</span>,
<span class='fu'><a href='https://ggplot2.tidyverse.org/reference/aes.html'>aes</a></span>(<span class='kw'>x</span> <span class='kw'>=</span> <span class='no'>year</span>)) +
<span class='fu'><a href='https://ggplot2.tidyverse.org/reference/geom_bar.html'>geom_col</a></span>(<span class='fu'><a href='https://ggplot2.tidyverse.org/reference/aes.html'>aes</a></span>(<span class='kw'>y</span> <span class='kw'>=</span> <span class='no'>value</span>),
<span class='kw'>fill</span> <span class='kw'>=</span> <span class='st'>"grey75"</span>) +
<span class='fu'><a href='https://www.rdocumentation.org/packages/ggplot2/topics/geom_linerange'>geom_errorbar</a></span>(<span class='fu'><a href='https://www.rdocumentation.org/packages/ggplot2/topics/aes'>aes</a></span>(<span class='kw'>ymin</span> <span class='kw'>=</span> <span class='no'>se_min</span>,
<span class='fu'><a href='https://ggplot2.tidyverse.org/reference/geom_linerange.html'>geom_errorbar</a></span>(<span class='fu'><a href='https://ggplot2.tidyverse.org/reference/aes.html'>aes</a></span>(<span class='kw'>ymin</span> <span class='kw'>=</span> <span class='no'>se_min</span>,
<span class='kw'>ymax</span> <span class='kw'>=</span> <span class='no'>se_max</span>),
<span class='kw'>colour</span> <span class='kw'>=</span> <span class='st'>"grey50"</span>) +
<span class='fu'><a href='https://www.rdocumentation.org/packages/ggplot2/topics/scale_continuous'>scale_y_continuous</a></span>(<span class='kw'>limits</span> <span class='kw'>=</span> <span class='fu'><a href='https://www.rdocumentation.org/packages/base/topics/c'>c</a></span>(<span class='fl'>0</span>, <span class='fl'>1</span>),
<span class='fu'><a href='https://ggplot2.tidyverse.org/reference/scale_continuous.html'>scale_y_continuous</a></span>(<span class='kw'>limits</span> <span class='kw'>=</span> <span class='fu'><a href='https://www.rdocumentation.org/packages/base/topics/c'>c</a></span>(<span class='fl'>0</span>, <span class='fl'>1</span>),
<span class='kw'>breaks</span> <span class='kw'>=</span> <span class='fu'><a href='https://www.rdocumentation.org/packages/base/topics/seq'>seq</a></span>(<span class='fl'>0</span>, <span class='fl'>1</span>, <span class='fl'>0.1</span>),
<span class='kw'>labels</span> <span class='kw'>=</span> <span class='fu'><a href='https://www.rdocumentation.org/packages/base/topics/paste'>paste0</a></span>(<span class='fu'><a href='https://www.rdocumentation.org/packages/base/topics/seq'>seq</a></span>(<span class='fl'>0</span>, <span class='fl'>100</span>, <span class='fl'>10</span>), <span class='st'>"%"</span>)) +
<span class='fu'><a href='https://www.rdocumentation.org/packages/ggplot2/topics/labs'>labs</a></span>(<span class='kw'>title</span> <span class='kw'>=</span> <span class='fu'><a href='https://www.rdocumentation.org/packages/base/topics/expression'>expression</a></span>(<span class='fu'><a href='https://www.rdocumentation.org/packages/base/topics/paste'>paste</a></span>(<span class='st'>"Forecast of amoxicillin resistance in "</span>,
<span class='fu'><a href='https://ggplot2.tidyverse.org/reference/labs.html'>labs</a></span>(<span class='kw'>title</span> <span class='kw'>=</span> <span class='fu'><a href='https://www.rdocumentation.org/packages/base/topics/expression'>expression</a></span>(<span class='fu'><a href='https://www.rdocumentation.org/packages/base/topics/paste'>paste</a></span>(<span class='st'>"Forecast of amoxicillin resistance in "</span>,
<span class='fu'><a href='https://www.rdocumentation.org/packages/grDevices/topics/plotmath'>italic</a></span>(<span class='st'>"E. coli"</span>))),
<span class='kw'>y</span> <span class='kw'>=</span> <span class='st'>"%IR"</span>,
<span class='kw'>x</span> <span class='kw'>=</span> <span class='st'>"Year"</span>) +
<span class='fu'><a href='https://www.rdocumentation.org/packages/ggplot2/topics/ggtheme'>theme_minimal</a></span>(<span class='kw'>base_size</span> <span class='kw'>=</span> <span class='fl'>13</span>)
<span class='fu'><a href='https://ggplot2.tidyverse.org/reference/ggtheme.html'>theme_minimal</a></span>(<span class='kw'>base_size</span> <span class='kw'>=</span> <span class='fl'>13</span>)
}
<span class='co'># }</span></pre>
</div>

View File

@ -110,7 +110,7 @@
</a>
</li>
<li>
<a href="../articles/Predict.html">
<a href="../articles/resistance_predict.html">
<span class="fa fa-dice"></span>
Predict antimicrobial resistance
@ -131,14 +131,14 @@
</a>
</li>
<li>
<a href="../articles/mo_property.html">
<a href="../reference/mo_property.html">
<span class="fa fa-bug"></span>
Get properties of a microorganism
</a>
</li>
<li>
<a href="../articles/ab_property.html">
<a href="../reference/atc_property.html">
<span class="fa fa-capsules"></span>
Get properties of an antibiotic

View File

@ -110,7 +110,7 @@
</a>
</li>
<li>
<a href="../articles/Predict.html">
<a href="../articles/resistance_predict.html">
<span class="fa fa-dice"></span>
Predict antimicrobial resistance
@ -131,14 +131,14 @@
</a>
</li>
<li>
<a href="../articles/mo_property.html">
<a href="../reference/mo_property.html">
<span class="fa fa-bug"></span>
Get properties of a microorganism
</a>
</li>
<li>
<a href="../articles/ab_property.html">
<a href="../reference/atc_property.html">
<span class="fa fa-capsules"></span>
Get properties of an antibiotic

View File

@ -111,7 +111,7 @@ When negative: the left tail is longer; the mass of the distribution is concentr
</a>
</li>
<li>
<a href="../articles/Predict.html">
<a href="../articles/resistance_predict.html">
<span class="fa fa-dice"></span>
Predict antimicrobial resistance
@ -132,14 +132,14 @@ When negative: the left tail is longer; the mass of the distribution is concentr
</a>
</li>
<li>
<a href="../articles/mo_property.html">
<a href="../reference/mo_property.html">
<span class="fa fa-bug"></span>
Get properties of a microorganism
</a>
</li>
<li>
<a href="../articles/ab_property.html">
<a href="../reference/atc_property.html">
<span class="fa fa-capsules"></span>
Get properties of an antibiotic

View File

@ -110,7 +110,7 @@
</a>
</li>
<li>
<a href="../articles/Predict.html">
<a href="../articles/resistance_predict.html">
<span class="fa fa-dice"></span>
Predict antimicrobial resistance
@ -131,14 +131,14 @@
</a>
</li>
<li>
<a href="../articles/mo_property.html">
<a href="../reference/mo_property.html">
<span class="fa fa-bug"></span>
Get properties of a microorganism
</a>
</li>
<li>
<a href="../articles/ab_property.html">
<a href="../reference/atc_property.html">
<span class="fa fa-capsules"></span>
Get properties of an antibiotic

BIN
man/figures/benchmark_1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
man/figures/benchmark_2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@ -25,9 +25,9 @@ knitr::opts_chunk$set(
One of the most important features of this package is the complete microbial taxonomic database, supplied by ITIS (https://www.itis.gov). We created a function `as.mo()` that transforms any user input value to a valid microbial ID by using AI (Artificial Intelligence) and based on the taxonomic tree of ITIS.
Using the `microbenchmark` package, we can review the calculation performance of this function.
Using the `microbenchmark` package, we can review the calculation performance of this function. Its function `microbenchmark()` calculates different input expressions independently of each others and runs every expression 100 times.
```r
```{r, eval = FALSE}
library(microbenchmark)
library(AMR)
```
@ -36,53 +36,65 @@ In the next test, we try to 'coerce' different input values for *Staphylococcus
But the calculation time differs a lot. Here, the AI effect can be reviewed best:
```r
microbenchmark(A = as.mo("stau"),
B = as.mo("staaur"),
C = as.mo("S. aureus"),
D = as.mo("S. aureus"),
E = as.mo("STAAUR"),
F = as.mo("Staphylococcus aureus"),
G = as.mo("B_STPHY_AUR"),
times = 10,
unit = "ms")
```{r, eval = FALSE}
benchmark <- microbenchmark(as.mo("sau"),
as.mo("stau"),
as.mo("staaur"),
as.mo("S. aureus"),
as.mo("S. aureus"),
as.mo("STAAUR"),
as.mo("Staphylococcus aureus"),
as.mo("B_STPHY_AUR"))
print(benchmark, unit = "ms")
# Unit: milliseconds
# expr min lq mean median uq max neval
# A 34.745551 34.798630 35.2596102 34.8994810 35.258325 38.067062 10
# B 7.095386 7.125348 7.2219948 7.1613865 7.240377 7.495857 10
# C 11.677114 11.733826 11.8304789 11.7715050 11.843756 12.317559 10
# D 11.694435 11.730054 11.9859313 11.8775585 12.206371 12.750016 10
# E 7.044402 7.117387 7.2271630 7.1923610 7.246104 7.742396 10
# F 6.642326 6.778446 6.8988042 6.8753165 6.923577 7.513945 10
# G 0.106788 0.131023 0.1351229 0.1357725 0.144014 0.146458 10
# as.mo("sau") 18.983141 19.121148 19.9676944 19.1967505 19.2871260 38.635012 100
# as.mo("stau") 37.503863 37.692049 38.9856547 37.8244335 37.9851040 57.576107 100
# as.mo("staaur") 18.945427 19.122579 19.6392560 19.2241285 19.3536140 38.687672 100
# as.mo("S. aureus") 15.305229 15.471103 16.3477096 15.5545630 15.6689280 36.363005 100
# as.mo("S. aureus") 15.308232 15.469881 16.5269706 15.5506870 15.6277560 42.155292 100
# as.mo("STAAUR") 18.984049 19.117166 19.6104597 19.2219285 19.3161095 38.638783 100
# as.mo("Staphylococcus aureus") 8.103546 8.198285 8.6422018 8.2636915 8.3200535 27.002527 100
# as.mo("B_STPHY_AUR") 0.156236 0.196779 0.2017926 0.2035535 0.2115505 0.241861 100
par(mar = c(5, 15, 4, 2)) # set more space for left margin text (15)
boxplot(benchmark, horizontal = TRUE, las = 1, unit = "ms", log = FALSE, xlab = "", ylim = c(0, 200),
main = expression(paste("Benchmark of ", italic("Staphylococcus aureus"))))
```
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).
![](../reference/figures/benchmark_1.png)
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 8 milliseconds means it can determine 125 input values per second. It case of 40 milliseconds, this is only 25 input values per second. The more an input value resembles a full name, the faster the result will be found. In case of `as.mo("B_STPHY_AUR")`, the input is already a valid MO code, so it only almost takes no time at all (0.0002 seconds on our server).
To achieve this speed, the `as.mo` 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 *Burkholderia nodosa* (`B_BRKHL_NOD`):
```r
microbenchmark(A = as.mo("buno"),
B = as.mo("burnod"),
C = as.mo("B. nodosa"),
D = as.mo("B. nodosa"),
E = as.mo("BURNOD"),
F = as.mo("Burkholderia nodosa"),
G = as.mo("B_BRKHL_NOD"),
times = 10,
unit = "ms")
```{r, eval = FALSE}
benchmark <- microbenchmark(as.mo("buno"),
as.mo("burnod"),
as.mo("B. nodosa"),
as.mo("B. nodosa"),
as.mo("BURNOD"),
as.mo("Burkholderia nodosa"),
as.mo("B_BRKHL_NOD"))
print(benchmark, unit = "ms")
# Unit: milliseconds
# expr min lq mean median uq max neval
# A 124.175427 124.474837 125.8610536 125.3750560 126.160945 131.485994 10
# B 154.249713 155.364729 160.9077032 156.8738940 157.136183 197.315105 10
# C 66.066571 66.162393 66.5538611 66.4488130 66.698077 67.623404 10
# D 86.747693 86.918665 90.7831016 87.8149725 89.440982 116.767991 10
# E 154.863827 155.208563 162.6535954 158.4062465 168.593785 187.378088 10
# F 32.427028 32.638648 32.9929454 32.7860475 32.992813 34.674241 10
# G 0.213155 0.216578 0.2369226 0.2338985 0.253734 0.285581 10
# as.mo("buno") 125.141333 125.8553210 129.5727691 126.3899910 127.0954925 194.51985 100
# as.mo("burnod") 142.300359 144.1611750 147.0642288 144.6074960 145.5243025 176.91649 100
# as.mo("B. nodosa") 81.530132 81.9360840 83.3915418 82.1852770 82.6848870 102.63184 100
# as.mo("B. nodosa") 81.109547 81.9836805 84.7595894 82.3437825 82.8282705 110.67036 100
# as.mo("BURNOD") 143.163527 143.9134485 148.7192688 144.5582580 145.7489115 314.92070 100
# as.mo("Burkholderia nodosa") 36.226325 36.5499000 37.1309929 36.6581540 36.7551985 56.25597 100
# as.mo("B_BRKHL_NOD") 0.172509 0.3038455 0.4806591 0.3078265 0.3121215 19.16173 100
boxplot(benchmark, horizontal = TRUE, las = 1, unit = "ms", log = FALSE, xlab = "", ylim = c(0, 200),
main = expression(paste("Benchmark of ", italic("Burkholderia nodosa"))))
```
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.
![](../reference/figures/benchmark_2.png)
That takes up to 8 times as much time! A value of 145 milliseconds means it can only determine ~7 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.
To relieve this pitfall and further improve performance, two important calculations take almost no time at all: **repetitive results** and **already precalculated results**.
@ -90,7 +102,7 @@ To relieve this pitfall and further improve performance, two important calculati
Repetitive results mean that unique values are present more than once. Unique values will only be calculated once by `as.mo()`. We will use `mo_fullname()` for this test - a helper function that returns the full microbial name (genus, species and possibly subspecies) and uses `as.mo()` internally.
```r
```{r, eval = FALSE}
library(dplyr)
# take 500,000 random MO codes from the septic_patients data set
x = septic_patients %>%
@ -118,19 +130,19 @@ So transforming 500,000 values (!) of 96 unique values only takes 0.12 seconds (
Results of a tenfold - 5,000,000 values:
```r
```{r, eval = FALSE}
# Unit: milliseconds
# expr min lq mean median uq max neval
# X 882.9045 901.3011 1001.677 940.3421 1168.088 1226.846 10
```
Even the full names of 5 *Million* values are calculated within a second.
Even determining the full names of 5 *Million* values is done within a second.
### Precalculated results
What about precalculated results? If the input is an already precalculated result of a helper function like `mo_fullname()`, it almost doesn't take any time at all (see 'C' below):
```r
```{r, eval = FALSE}
microbenchmark(A = mo_fullname("B_STPHY_AUR"),
B = mo_fullname("S. aureus"),
C = mo_fullname("Staphylococcus aureus"),
@ -145,7 +157,7 @@ microbenchmark(A = mo_fullname("B_STPHY_AUR"),
So going from `mo_fullname("Staphylococcus aureus")` to `"Staphylococcus aureus"` takes 0.0001 seconds - it doesn't even start calculating *if the result would be the same as the expected resulting value*. That goes for all helper functions:
```r
```{r, eval = FALSE}
microbenchmark(A = mo_species("aureus"),
B = mo_genus("Staphylococcus"),
C = mo_fullname("Staphylococcus aureus"),
@ -176,7 +188,7 @@ Of course, when running `mo_phylum("Firmicutes")` the function has zero knowledg
When the system language is non-English and supported by this `AMR` package, some functions take a little while longer:
```r
```{r, eval = FALSE}
mo_fullname("CoNS", language = "en") # or just mo_fullname("CoNS") on an English system
# "Coagulase Negative Staphylococcus (CoNS)"