1
0
mirror of https://github.com/msberends/AMR.git synced 2025-12-25 05:10:23 +01:00

Built site for AMR@3.0.1.9007: a5c6aa9

This commit is contained in:
github-actions
2025-12-22 08:48:41 +00:00
parent 7c8d0f82f9
commit 1227e2c60c
128 changed files with 1616 additions and 440 deletions

View File

@@ -31,7 +31,7 @@
<a class="navbar-brand me-2" href="https://amr-for-r.org/index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">

View File

@@ -7,7 +7,7 @@
<a class="navbar-brand me-2" href="index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">

View File

@@ -30,7 +30,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
@@ -91,7 +91,7 @@
website update since they are based on randomly created values and the
page was written in <a href="https://rmarkdown.rstudio.com/" class="external-link">R
Markdown</a>. However, the methodology remains unchanged. This page was
generated on 15 December 2025.</p>
generated on 22 December 2025.</p>
<div class="section level2">
<h2 id="introduction">Introduction<a class="anchor" aria-label="anchor" href="#introduction"></a>
</h2>
@@ -147,21 +147,21 @@ make the structure of your data generally look like this:</p>
</tr></thead>
<tbody>
<tr class="odd">
<td align="center">2025-12-15</td>
<td align="center">2025-12-22</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">2025-12-15</td>
<td align="center">2025-12-22</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">2025-12-15</td>
<td align="center">2025-12-22</td>
<td align="center">efgh</td>
<td align="center">Escherichia coli</td>
<td align="center">R</td>
@@ -1254,7 +1254,7 @@ function on a grouped <code>tibble</code>, i.e., using
provides an extension to that function:</p>
<div class="sourceCode" id="cb22"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="https://ggplot2.tidyverse.org/reference/autoplot.html" class="external-link">autoplot</a></span><span class="op">(</span><span class="va">combined_ab</span><span class="op">)</span></span></code></pre></div>
<p><img src="AMR_files/figure-html/unnamed-chunk-10-1.png" class="r-plt" width="720"></p>
<p><img src="AMR_files/figure-html/unnamed-chunk-10-1.png" class="r-plt" alt="" width="720"></p>
<p>To calculate antimicrobial resistance in a more sensible way, also by
correcting for too few results, we use the <code><a href="../reference/proportion.html">resistance()</a></code> and
<code><a href="../reference/proportion.html">susceptibility()</a></code> functions.</p>
@@ -1348,7 +1348,7 @@ categories.</p>
<span> <span class="fu"><a href="https://ggplot2.tidyverse.org/reference/labs.html" class="external-link">labs</a></span><span class="op">(</span>title <span class="op">=</span> <span class="st">"MIC Distribution and SIR Interpretation"</span>,</span>
<span> x <span class="op">=</span> <span class="st">"Sample Groups"</span>,</span>
<span> y <span class="op">=</span> <span class="st">"MIC (mg/L)"</span><span class="op">)</span></span></code></pre></div>
<p><img src="AMR_files/figure-html/mic_plot-1.png" class="r-plt" width="720"></p>
<p><img src="AMR_files/figure-html/mic_plot-1.png" class="r-plt" alt="" width="720"></p>
<p>This plot provides an intuitive way to assess susceptibility patterns
across different groups while incorporating clinical breakpoints.</p>
<p>For a more straightforward and less manual approach,
@@ -1357,12 +1357,12 @@ extended by this package to directly plot MIC and disk diffusion
values:</p>
<div class="sourceCode" id="cb27"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="https://ggplot2.tidyverse.org/reference/autoplot.html" class="external-link">autoplot</a></span><span class="op">(</span><span class="va">mic_values</span><span class="op">)</span></span></code></pre></div>
<p><img src="AMR_files/figure-html/autoplot-1.png" class="r-plt" width="720"></p>
<p><img src="AMR_files/figure-html/autoplot-1.png" class="r-plt" alt="" width="720"></p>
<div class="sourceCode" id="cb28"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span></span>
<span><span class="co"># by providing `mo` and `ab`, colours will indicate the SIR interpretation:</span></span>
<span><span class="fu"><a href="https://ggplot2.tidyverse.org/reference/autoplot.html" class="external-link">autoplot</a></span><span class="op">(</span><span class="va">mic_values</span>, mo <span class="op">=</span> <span class="st">"K. pneumoniae"</span>, ab <span class="op">=</span> <span class="st">"cipro"</span>, guideline <span class="op">=</span> <span class="st">"EUCAST 2024"</span><span class="op">)</span></span></code></pre></div>
<p><img src="AMR_files/figure-html/autoplot-2.png" class="r-plt" width="720"></p>
<p><img src="AMR_files/figure-html/autoplot-2.png" class="r-plt" alt="" width="720"></p>
<hr>
<p><em>Author: Dr. Matthijs Berends, 23rd Feb 2025</em></p>
</div>

View File

@@ -3,7 +3,7 @@
**Note:** values on this page will change with every website update
since they are based on randomly created values and the page was written
in [R Markdown](https://rmarkdown.rstudio.com/). However, the
methodology remains unchanged. This page was generated on 15 December
methodology remains unchanged. This page was generated on 22 December
2025.
## Introduction
@@ -52,9 +52,9 @@ structure of your data generally look like this:
| date | patient_id | mo | AMX | CIP |
|:----------:|:----------:|:----------------:|:---:|:---:|
| 2025-12-15 | abcd | Escherichia coli | S | S |
| 2025-12-15 | abcd | Escherichia coli | S | R |
| 2025-12-15 | efgh | Escherichia coli | R | S |
| 2025-12-22 | abcd | Escherichia coli | S | S |
| 2025-12-22 | abcd | Escherichia coli | S | R |
| 2025-12-22 | efgh | Escherichia coli | R | S |
### Needed R packages

View File

@@ -30,7 +30,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">

View File

@@ -30,7 +30,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
@@ -88,7 +88,7 @@
<blockquote>
<p>This page was entirely written by our <a href="https://chat.amr-for-r.org" class="external-link">AMR for R Assistant</a>, a ChatGPT
<p>This page was almost entirely written by our <a href="https://chat.amr-for-r.org" class="external-link">AMR for R Assistant</a>, a ChatGPT
manually-trained model able to answer any question about the
<code>AMR</code> package.</p>
</blockquote>
@@ -413,7 +413,7 @@ ROC curve looks like this:</p>
<code class="sourceCode R"><span><span class="va">predictions</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span></span>
<span> <span class="fu">roc_curve</span><span class="op">(</span><span class="va">mo</span>, <span class="va">`.pred_Gram-negative`</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span></span>
<span> <span class="fu"><a href="https://ggplot2.tidyverse.org/reference/autoplot.html" class="external-link">autoplot</a></span><span class="op">(</span><span class="op">)</span></span></code></pre></div>
<p><img src="AMR_with_tidymodels_files/figure-html/unnamed-chunk-8-1.png" class="r-plt" width="720"></p>
<p><img src="AMR_with_tidymodels_files/figure-html/unnamed-chunk-8-1.png" class="r-plt" alt="" width="720"></p>
</div>
<div class="section level3">
<h3 id="conclusion">
@@ -438,21 +438,258 @@ and reproducibly.</p>
<code>&lt;mic&gt;</code> columns directly in <code>tidymodels</code>
workflows using AMR-specific recipe steps. This includes a
transformation to <code>log2</code> scale using
<code>step_mic_log2()</code>, which prepares MIC values for use in
<code><a href="../reference/amr-tidymodels.html">step_mic_log2()</a></code>, which prepares MIC values for use in
classification models.</p>
<p>This approach and idea formed the basis for the publication <a href="https://doi.org/10.3389/fmicb.2025.1582703" class="external-link">DOI:
10.3389/fmicb.2025.1582703</a> to model the presence of
extended-spectrum beta-lactamases (ESBL).</p>
<blockquote>
<p>NOTE: THIS EXAMPLE WILL BE AVAILABLE IN A NEXT VERSION (#TODO)</p>
<p>The new AMR package version will contain new tidymodels selectors
such as <code>step_mic_log2()</code>.</p>
</blockquote>
<!-- TODO for AMR v3.1.0: add info from here: https://github.com/msberends/AMR/blob/2461631bcefa78ebdb37bdfad359be74cdd9165a/vignettes/AMR_with_tidymodels.Rmd#L212-L291 -->
extended-spectrum beta-lactamases (ESBL) based on MIC values.</p>
<div class="section level3">
<h3 id="objective-1">
<strong>Objective</strong><a class="anchor" aria-label="anchor" href="#objective-1"></a>
</h3>
<p>Our goal is to:</p>
<ol style="list-style-type: decimal">
<li>Use raw MIC values to predict whether a bacterial isolate produces
ESBL.</li>
<li>Apply AMR-aware preprocessing in a <code>tidymodels</code>
recipe.</li>
<li>Train a classification model and evaluate its predictive
performance.</li>
</ol>
</div>
<div class="section level3">
<h3 id="data-preparation-1">
<strong>Data Preparation</strong><a class="anchor" aria-label="anchor" href="#data-preparation-1"></a>
</h3>
<p>We use the <code>esbl_isolates</code> dataset that comes with the AMR
package.</p>
<div class="sourceCode" id="cb10"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># Load required libraries</span></span>
<span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://amr-for-r.org">AMR</a></span><span class="op">)</span></span>
<span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://tidymodels.tidymodels.org" class="external-link">tidymodels</a></span><span class="op">)</span></span>
<span></span>
<span><span class="co"># View the esbl_isolates data set</span></span>
<span><span class="va">esbl_isolates</span></span>
<span><span class="co">#&gt; <span style="color: #949494;"># A tibble: 500 × 19</span></span></span>
<span><span class="co">#&gt; esbl genus AMC AMP TZP CXM FOX CTX CAZ GEN TOB TMP SXT</span></span>
<span><span class="co">#&gt; <span style="color: #949494; font-style: italic;">&lt;lgl&gt;</span> <span style="color: #949494; font-style: italic;">&lt;chr&gt;</span> <span style="color: #949494; font-style: italic;">&lt;mic&gt;</span> <span style="color: #949494; font-style: italic;">&lt;mic&gt;</span> <span style="color: #949494; font-style: italic;">&lt;mic&gt;</span> <span style="color: #949494; font-style: italic;">&lt;mic&gt;</span> <span style="color: #949494; font-style: italic;">&lt;mic&gt;</span> <span style="color: #949494; font-style: italic;">&lt;mic&gt;</span> <span style="color: #949494; font-style: italic;">&lt;mic&gt;</span> <span style="color: #949494; font-style: italic;">&lt;mic&gt;</span> <span style="color: #949494; font-style: italic;">&lt;mic&gt;</span> <span style="color: #949494; font-style: italic;">&lt;mic&gt;</span> <span style="color: #949494; font-style: italic;">&lt;mic&gt;</span></span></span>
<span><span class="co">#&gt; <span style="color: #BCBCBC;"> 1</span> FALSE Esch… 32 32 4 64 64 8<span style="color: #555555;">.00</span> 8<span style="color: #555555;">.00</span> 1 1 16<span style="color: #555555;">.0</span> 20</span></span>
<span><span class="co">#&gt; <span style="color: #BCBCBC;"> 2</span> FALSE Esch… 32 32 4 64 64 4<span style="color: #555555;">.00</span> 8<span style="color: #555555;">.00</span> 1 1 16<span style="color: #555555;">.0</span> 320</span></span>
<span><span class="co">#&gt; <span style="color: #BCBCBC;"> 3</span> FALSE Esch… 4 2 64 8 4 8<span style="color: #555555;">.00</span> 0.12 16 16 0.5 20</span></span>
<span><span class="co">#&gt; <span style="color: #BCBCBC;"> 4</span> FALSE Kleb… 32 32 16 64 64 8<span style="color: #555555;">.00</span> 8<span style="color: #555555;">.00</span> 1 1 0.5 20</span></span>
<span><span class="co">#&gt; <span style="color: #BCBCBC;"> 5</span> FALSE Esch… 32 32 4 4 4 0.25 2<span style="color: #555555;">.00</span> 1 1 16<span style="color: #555555;">.0</span> 320</span></span>
<span><span class="co">#&gt; <span style="color: #BCBCBC;"> 6</span> FALSE Citr… 32 32 16 64 64 64<span style="color: #555555;">.00</span> 32<span style="color: #555555;">.00</span> 1 1 0.5 20</span></span>
<span><span class="co">#&gt; <span style="color: #BCBCBC;"> 7</span> FALSE Morg… 32 32 4 64 64 16<span style="color: #555555;">.00</span> 2<span style="color: #555555;">.00</span> 1 1 0.5 20</span></span>
<span><span class="co">#&gt; <span style="color: #BCBCBC;"> 8</span> FALSE Prot… 16 32 4 1 4 8<span style="color: #555555;">.00</span> 0.12 1 1 16<span style="color: #555555;">.0</span> 320</span></span>
<span><span class="co">#&gt; <span style="color: #BCBCBC;"> 9</span> FALSE Ente… 32 32 8 64 64 32<span style="color: #555555;">.00</span> 4<span style="color: #555555;">.00</span> 1 1 0.5 20</span></span>
<span><span class="co">#&gt; <span style="color: #BCBCBC;">10</span> FALSE Citr… 32 32 32 64 64 8<span style="color: #555555;">.00</span> 64<span style="color: #555555;">.00</span> 1 1 16<span style="color: #555555;">.0</span> 320</span></span>
<span><span class="co">#&gt; <span style="color: #949494;"># 490 more rows</span></span></span>
<span><span class="co">#&gt; <span style="color: #949494;"># 6 more variables: NIT &lt;mic&gt;, FOS &lt;mic&gt;, CIP &lt;mic&gt;, IPM &lt;mic&gt;, MEM &lt;mic&gt;,</span></span></span>
<span><span class="co">#&gt; <span style="color: #949494;"># COL &lt;mic&gt;</span></span></span>
<span></span>
<span><span class="co"># Prepare a binary outcome and convert to ordered factor</span></span>
<span><span class="va">data</span> <span class="op">&lt;-</span> <span class="va">esbl_isolates</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span></span>
<span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/mutate.html" class="external-link">mutate</a></span><span class="op">(</span>esbl <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/factor.html" class="external-link">factor</a></span><span class="op">(</span><span class="va">esbl</span>, levels <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="cn">FALSE</span>, <span class="cn">TRUE</span><span class="op">)</span>, ordered <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span><span class="op">)</span></span></code></pre></div>
<p><strong>Explanation:</strong></p>
<ul>
<li>
<code>esbl_isolates</code>: Contains MIC test results and ESBL
status for each isolate.</li>
<li>
<code>mutate(esbl = ...)</code>: Converts the target column to an
ordered factor for classification.</li>
</ul>
</div>
<div class="section level3">
<h3 id="defining-the-workflow-1">
<strong>Defining the Workflow</strong><a class="anchor" aria-label="anchor" href="#defining-the-workflow-1"></a>
</h3>
<div class="section level4">
<h4 id="preprocessing-with-a-recipe-1">1. Preprocessing with a Recipe<a class="anchor" aria-label="anchor" href="#preprocessing-with-a-recipe-1"></a>
</h4>
<p>We use our <code><a href="../reference/amr-tidymodels.html">step_mic_log2()</a></code> function to log2-transform
MIC values, ensuring that MICs are numeric and properly scaled. All MIC
predictors can easily and agnostically selected using the new
<code><a href="../reference/amr-tidymodels.html">all_mic_predictors()</a></code>:</p>
<div class="sourceCode" id="cb11"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># Split into training and testing sets</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/base/Random.html" class="external-link">set.seed</a></span><span class="op">(</span><span class="fl">123</span><span class="op">)</span></span>
<span><span class="va">split</span> <span class="op">&lt;-</span> <span class="fu">initial_split</span><span class="op">(</span><span class="va">data</span><span class="op">)</span></span>
<span><span class="va">training_data</span> <span class="op">&lt;-</span> <span class="fu">training</span><span class="op">(</span><span class="va">split</span><span class="op">)</span></span>
<span><span class="va">testing_data</span> <span class="op">&lt;-</span> <span class="fu">testing</span><span class="op">(</span><span class="va">split</span><span class="op">)</span></span>
<span></span>
<span><span class="co"># Define the recipe</span></span>
<span><span class="va">mic_recipe</span> <span class="op">&lt;-</span> <span class="fu">recipe</span><span class="op">(</span><span class="va">esbl</span> <span class="op">~</span> <span class="va">.</span>, data <span class="op">=</span> <span class="va">training_data</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span></span>
<span> <span class="fu">remove_role</span><span class="op">(</span><span class="va">genus</span>, old_role <span class="op">=</span> <span class="st">"predictor"</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span> <span class="co"># Remove non-informative variable</span></span>
<span> <span class="fu"><a href="../reference/amr-tidymodels.html">step_mic_log2</a></span><span class="op">(</span><span class="fu"><a href="../reference/amr-tidymodels.html">all_mic_predictors</a></span><span class="op">(</span><span class="op">)</span><span class="op">)</span> <span class="co">#%&gt;% # Log2 transform all MIC predictors</span></span>
<span> <span class="co"># prep()</span></span>
<span></span>
<span><span class="va">mic_recipe</span></span>
<span><span class="co">#&gt; </span></span>
<span><span class="co">#&gt; <span style="color: #00BBBB;">──</span> <span style="font-weight: bold;">Recipe</span> <span style="color: #00BBBB;">──────────────────────────────────────────────────────────────────────</span></span></span>
<span><span class="co">#&gt; </span></span>
<span><span class="co">#&gt; ── Inputs</span></span>
<span><span class="co">#&gt; Number of variables by role</span></span>
<span><span class="co">#&gt; outcome: 1</span></span>
<span><span class="co">#&gt; predictor: 17</span></span>
<span><span class="co">#&gt; undeclared role: 1</span></span>
<span><span class="co">#&gt; </span></span>
<span><span class="co">#&gt; ── Operations</span></span>
<span><span class="co">#&gt; <span style="color: #00BBBB;"></span> Log2 transformation of MIC columns: <span style="color: #0000BB;">all_mic_predictors()</span></span></span></code></pre></div>
<p><strong>Explanation:</strong></p>
<ul>
<li>
<code>remove_role()</code>: Removes irrelevant variables like
genus.</li>
<li>
<code><a href="../reference/amr-tidymodels.html">step_mic_log2()</a></code>: Applies
<code>log2(as.numeric(...))</code> to all MIC predictors in one go.</li>
<li>
<code>prep()</code>: Finalises the recipe based on training
data.</li>
</ul>
</div>
<div class="section level4">
<h4 id="specifying-the-model-1">2. Specifying the Model<a class="anchor" aria-label="anchor" href="#specifying-the-model-1"></a>
</h4>
<p>We use a simple logistic regression to model ESBL presence, though
recent models such as xgboost (<a href="https://parsnip.tidymodels.org/reference/details_boost_tree_xgboost.html" class="external-link">link
to <code>parsnip</code> manual</a>) could be much more precise.</p>
<div class="sourceCode" id="cb12"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># Define the model</span></span>
<span><span class="va">model</span> <span class="op">&lt;-</span> <span class="fu">logistic_reg</span><span class="op">(</span>mode <span class="op">=</span> <span class="st">"classification"</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span></span>
<span> <span class="fu">set_engine</span><span class="op">(</span><span class="st">"glm"</span><span class="op">)</span></span>
<span></span>
<span><span class="va">model</span></span>
<span><span class="co">#&gt; Logistic Regression Model Specification (classification)</span></span>
<span><span class="co">#&gt; </span></span>
<span><span class="co">#&gt; Computational engine: glm</span></span></code></pre></div>
<p><strong>Explanation:</strong></p>
<ul>
<li>
<code>logistic_reg()</code>: Specifies a binary classification
model.</li>
<li>
<code>set_engine("glm")</code>: Uses the base R GLM engine.</li>
</ul>
</div>
<div class="section level4">
<h4 id="building-the-workflow-1">3. Building the Workflow<a class="anchor" aria-label="anchor" href="#building-the-workflow-1"></a>
</h4>
<div class="sourceCode" id="cb13"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># Create workflow</span></span>
<span><span class="va">workflow_model</span> <span class="op">&lt;-</span> <span class="fu">workflow</span><span class="op">(</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span></span>
<span> <span class="fu">add_recipe</span><span class="op">(</span><span class="va">mic_recipe</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span></span>
<span> <span class="fu">add_model</span><span class="op">(</span><span class="va">model</span><span class="op">)</span></span>
<span></span>
<span><span class="va">workflow_model</span></span>
<span><span class="co">#&gt; ══ Workflow ════════════════════════════════════════════════════════════════════</span></span>
<span><span class="co">#&gt; <span style="font-style: italic;">Preprocessor:</span> Recipe</span></span>
<span><span class="co">#&gt; <span style="font-style: italic;">Model:</span> logistic_reg()</span></span>
<span><span class="co">#&gt; </span></span>
<span><span class="co">#&gt; ── Preprocessor ────────────────────────────────────────────────────────────────</span></span>
<span><span class="co">#&gt; 1 Recipe Step</span></span>
<span><span class="co">#&gt; </span></span>
<span><span class="co">#&gt; • step_mic_log2()</span></span>
<span><span class="co">#&gt; </span></span>
<span><span class="co">#&gt; ── Model ───────────────────────────────────────────────────────────────────────</span></span>
<span><span class="co">#&gt; Logistic Regression Model Specification (classification)</span></span>
<span><span class="co">#&gt; </span></span>
<span><span class="co">#&gt; Computational engine: glm</span></span></code></pre></div>
</div>
</div>
<div class="section level3">
<h3 id="training-and-evaluating-the-model-1">
<strong>Training and Evaluating the Model</strong><a class="anchor" aria-label="anchor" href="#training-and-evaluating-the-model-1"></a>
</h3>
<div class="sourceCode" id="cb14"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># Fit the model</span></span>
<span><span class="va">fitted</span> <span class="op">&lt;-</span> <span class="fu">fit</span><span class="op">(</span><span class="va">workflow_model</span>, <span class="va">training_data</span><span class="op">)</span></span>
<span></span>
<span><span class="co"># Generate predictions</span></span>
<span><span class="va">predictions</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/stats/predict.html" class="external-link">predict</a></span><span class="op">(</span><span class="va">fitted</span>, <span class="va">testing_data</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span></span>
<span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/bind_cols.html" class="external-link">bind_cols</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/stats/predict.html" class="external-link">predict</a></span><span class="op">(</span><span class="va">fitted</span>, <span class="va">testing_data</span>, type <span class="op">=</span> <span class="st">"prob"</span><span class="op">)</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span> <span class="co"># add probabilities</span></span>
<span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/bind_cols.html" class="external-link">bind_cols</a></span><span class="op">(</span><span class="va">testing_data</span><span class="op">)</span></span>
<span></span>
<span><span class="co"># Evaluate model performance</span></span>
<span><span class="va">our_metrics</span> <span class="op">&lt;-</span> <span class="fu">metric_set</span><span class="op">(</span><span class="va">accuracy</span>, <span class="va">recall</span>, <span class="va">precision</span>, <span class="va">sensitivity</span>, <span class="va">specificity</span>, <span class="va">ppv</span>, <span class="va">npv</span><span class="op">)</span></span>
<span><span class="va">metrics</span> <span class="op">&lt;-</span> <span class="fu">our_metrics</span><span class="op">(</span><span class="va">predictions</span>, truth <span class="op">=</span> <span class="va">esbl</span>, estimate <span class="op">=</span> <span class="va">.pred_class</span><span class="op">)</span></span>
<span></span>
<span><span class="va">metrics</span></span>
<span><span class="co">#&gt; <span style="color: #949494;"># A tibble: 7 × 3</span></span></span>
<span><span class="co">#&gt; .metric .estimator .estimate</span></span>
<span><span class="co">#&gt; <span style="color: #949494; font-style: italic;">&lt;chr&gt;</span> <span style="color: #949494; font-style: italic;">&lt;chr&gt;</span> <span style="color: #949494; font-style: italic;">&lt;dbl&gt;</span></span></span>
<span><span class="co">#&gt; <span style="color: #BCBCBC;">1</span> accuracy binary 0.92 </span></span>
<span><span class="co">#&gt; <span style="color: #BCBCBC;">2</span> recall binary 0.921</span></span>
<span><span class="co">#&gt; <span style="color: #BCBCBC;">3</span> precision binary 0.921</span></span>
<span><span class="co">#&gt; <span style="color: #BCBCBC;">4</span> sensitivity binary 0.921</span></span>
<span><span class="co">#&gt; <span style="color: #BCBCBC;">5</span> specificity binary 0.919</span></span>
<span><span class="co">#&gt; <span style="color: #BCBCBC;">6</span> ppv binary 0.921</span></span>
<span><span class="co">#&gt; <span style="color: #BCBCBC;">7</span> npv binary 0.919</span></span></code></pre></div>
<p><strong>Explanation:</strong></p>
<ul>
<li>
<code>fit()</code>: Trains the model on the processed training
data.</li>
<li>
<code><a href="https://rdrr.io/r/stats/predict.html" class="external-link">predict()</a></code>: Produces predictions for unseen test
data.</li>
<li>
<code>metric_set()</code>: Allows evaluating multiple classification
metrics. This will make <code>our_metrics</code> to become a function
that we can use to check the predictions with.</li>
</ul>
<p>It appears we can predict ESBL gene presence with a positive
predictive value (PPV) of 92.1% and a negative predictive value (NPV) of
91.9 using a simplistic logistic regression model.</p>
</div>
<div class="section level3">
<h3 id="visualising-predictions">
<strong>Visualising Predictions</strong><a class="anchor" aria-label="anchor" href="#visualising-predictions"></a>
</h3>
<p>We can visualise predictions by comparing predicted and actual ESBL
status.</p>
<div class="sourceCode" id="cb15"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://ggplot2.tidyverse.org" class="external-link">ggplot2</a></span><span class="op">)</span></span>
<span></span>
<span><span class="fu"><a href="https://ggplot2.tidyverse.org/reference/ggplot.html" class="external-link">ggplot</a></span><span class="op">(</span><span class="va">predictions</span>, <span class="fu"><a href="https://ggplot2.tidyverse.org/reference/aes.html" class="external-link">aes</a></span><span class="op">(</span>x <span class="op">=</span> <span class="va">esbl</span>, fill <span class="op">=</span> <span class="va">.pred_class</span><span class="op">)</span><span class="op">)</span> <span class="op">+</span></span>
<span> <span class="fu"><a href="https://ggplot2.tidyverse.org/reference/geom_bar.html" class="external-link">geom_bar</a></span><span class="op">(</span>position <span class="op">=</span> <span class="st">"stack"</span><span class="op">)</span> <span class="op">+</span></span>
<span> <span class="fu"><a href="https://ggplot2.tidyverse.org/reference/labs.html" class="external-link">labs</a></span><span class="op">(</span>title <span class="op">=</span> <span class="st">"Predicted vs Actual ESBL Status"</span>,</span>
<span> x <span class="op">=</span> <span class="st">"Actual ESBL"</span>,</span>
<span> y <span class="op">=</span> <span class="st">"Count"</span><span class="op">)</span> <span class="op">+</span></span>
<span> <span class="fu"><a href="https://ggplot2.tidyverse.org/reference/ggtheme.html" class="external-link">theme_minimal</a></span><span class="op">(</span><span class="op">)</span></span></code></pre></div>
<p><img src="AMR_with_tidymodels_files/figure-html/unnamed-chunk-14-1.png" class="r-plt" alt="" width="720"></p>
<p>And plot the certainties too - how certain were the actual
predictions?</p>
<div class="sourceCode" id="cb16"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">predictions</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span></span>
<span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/mutate.html" class="external-link">mutate</a></span><span class="op">(</span>certainty <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/ifelse.html" class="external-link">ifelse</a></span><span class="op">(</span><span class="va">.pred_class</span> <span class="op">==</span> <span class="st">"FALSE"</span>,</span>
<span> <span class="va">.pred_FALSE</span>,</span>
<span> <span class="va">.pred_TRUE</span><span class="op">)</span>,</span>
<span> correct <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/ifelse.html" class="external-link">ifelse</a></span><span class="op">(</span><span class="va">esbl</span> <span class="op">==</span> <span class="va">.pred_class</span>, <span class="st">"Right"</span>, <span class="st">"Wrong"</span><span class="op">)</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span></span>
<span> <span class="fu"><a href="https://ggplot2.tidyverse.org/reference/ggplot.html" class="external-link">ggplot</a></span><span class="op">(</span><span class="fu"><a href="https://ggplot2.tidyverse.org/reference/aes.html" class="external-link">aes</a></span><span class="op">(</span>x <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/seq.html" class="external-link">seq_len</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/nrow.html" class="external-link">nrow</a></span><span class="op">(</span><span class="va">predictions</span><span class="op">)</span><span class="op">)</span>,</span>
<span> y <span class="op">=</span> <span class="va">certainty</span>,</span>
<span> colour <span class="op">=</span> <span class="va">correct</span><span class="op">)</span><span class="op">)</span> <span class="op">+</span></span>
<span> <span class="fu"><a href="https://ggplot2.tidyverse.org/reference/scale_manual.html" class="external-link">scale_colour_manual</a></span><span class="op">(</span>values <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span>Right <span class="op">=</span> <span class="st">"green3"</span>, Wrong <span class="op">=</span> <span class="st">"red2"</span><span class="op">)</span>,</span>
<span> name <span class="op">=</span> <span class="st">"Correct?"</span><span class="op">)</span> <span class="op">+</span></span>
<span> <span class="fu"><a href="https://ggplot2.tidyverse.org/reference/geom_point.html" class="external-link">geom_point</a></span><span class="op">(</span><span class="op">)</span> <span class="op">+</span> </span>
<span> <span class="fu"><a href="https://ggplot2.tidyverse.org/reference/scale_continuous.html" class="external-link">scale_y_continuous</a></span><span class="op">(</span>labels <span class="op">=</span> <span class="kw">function</span><span class="op">(</span><span class="va">x</span><span class="op">)</span> <span class="fu"><a href="https://rdrr.io/r/base/paste.html" class="external-link">paste0</a></span><span class="op">(</span><span class="va">x</span> <span class="op">*</span> <span class="fl">100</span>, <span class="st">"%"</span><span class="op">)</span>,</span>
<span> limits <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="fl">0.5</span>, <span class="fl">1</span><span class="op">)</span><span class="op">)</span> <span class="op">+</span></span>
<span> <span class="fu"><a href="https://ggplot2.tidyverse.org/reference/ggtheme.html" class="external-link">theme_minimal</a></span><span class="op">(</span><span class="op">)</span></span></code></pre></div>
<p><img src="AMR_with_tidymodels_files/figure-html/unnamed-chunk-15-1.png" class="r-plt" alt="" width="720">
### <strong>Conclusion</strong></p>
<p>In this example, we showcased how the new <code>AMR</code>-specific
recipe steps simplify working with <code>&lt;mic&gt;</code> columns in
<code>tidymodels</code>. The <code><a href="../reference/amr-tidymodels.html">step_mic_log2()</a></code> transformation
converts ordered MICs to log2-transformed numerics, improving
compatibility with classification models.</p>
<p>This pipeline enables realistic, reproducible, and interpretable
modelling of antimicrobial resistance data.</p>
<hr>
</div>
</div>
<div class="section level2">
<h2 id="example-2-predicting-amr-over-time">Example 2: Predicting AMR Over Time<a class="anchor" aria-label="anchor" href="#example-2-predicting-amr-over-time"></a>
<h2 id="example-3-predicting-amr-over-time">Example 3: Predicting AMR Over Time<a class="anchor" aria-label="anchor" href="#example-3-predicting-amr-over-time"></a>
</h2>
<p>In this third example, we aim to predict antimicrobial resistance
(AMR) trends over time using <code>tidymodels</code>. We will model
@@ -461,8 +698,8 @@ amoxicillin-clavulanic acid <code>AMC</code>, and ciprofloxacin
<code>CIP</code>), based on historical data grouped by year and hospital
ward.</p>
<div class="section level3">
<h3 id="objective-1">
<strong>Objective</strong><a class="anchor" aria-label="anchor" href="#objective-1"></a>
<h3 id="objective-2">
<strong>Objective</strong><a class="anchor" aria-label="anchor" href="#objective-2"></a>
</h3>
<p>Our goal is to:</p>
<ol style="list-style-type: decimal">
@@ -473,12 +710,12 @@ model.</li>
</ol>
</div>
<div class="section level3">
<h3 id="data-preparation-1">
<strong>Data Preparation</strong><a class="anchor" aria-label="anchor" href="#data-preparation-1"></a>
<h3 id="data-preparation-2">
<strong>Data Preparation</strong><a class="anchor" aria-label="anchor" href="#data-preparation-2"></a>
</h3>
<p>We start by transforming the <code>example_isolates</code> dataset
into a structured time-series format.</p>
<div class="sourceCode" id="cb10"><pre class="downlit sourceCode r">
<div class="sourceCode" id="cb17"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># Load required libraries</span></span>
<span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://amr-for-r.org">AMR</a></span><span class="op">)</span></span>
<span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://tidymodels.tidymodels.org" class="external-link">tidymodels</a></span><span class="op">)</span></span>
@@ -525,15 +762,15 @@ rates by year and ward.</li>
</ul>
</div>
<div class="section level3">
<h3 id="defining-the-workflow-1">
<strong>Defining the Workflow</strong><a class="anchor" aria-label="anchor" href="#defining-the-workflow-1"></a>
<h3 id="defining-the-workflow-2">
<strong>Defining the Workflow</strong><a class="anchor" aria-label="anchor" href="#defining-the-workflow-2"></a>
</h3>
<p>We now define the modelling workflow, which consists of a
preprocessing step, a model specification, and the fitting process.</p>
<div class="section level4">
<h4 id="preprocessing-with-a-recipe-1">1. Preprocessing with a Recipe<a class="anchor" aria-label="anchor" href="#preprocessing-with-a-recipe-1"></a>
<h4 id="preprocessing-with-a-recipe-2">1. Preprocessing with a Recipe<a class="anchor" aria-label="anchor" href="#preprocessing-with-a-recipe-2"></a>
</h4>
<div class="sourceCode" id="cb11"><pre class="downlit sourceCode r">
<div class="sourceCode" id="cb18"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># Define the recipe</span></span>
<span><span class="va">resistance_recipe_time</span> <span class="op">&lt;-</span> <span class="fu">recipe</span><span class="op">(</span><span class="va">res_AMX</span> <span class="op">~</span> <span class="va">year</span> <span class="op">+</span> <span class="va">gramstain</span>, data <span class="op">=</span> <span class="va">data_time</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span></span>
<span> <span class="fu">step_dummy</span><span class="op">(</span><span class="va">gramstain</span>, one_hot <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span> <span class="co"># Convert categorical to numerical</span></span>
@@ -566,10 +803,10 @@ variable.</li>
</ul>
</div>
<div class="section level4">
<h4 id="specifying-the-model-1">2. Specifying the Model<a class="anchor" aria-label="anchor" href="#specifying-the-model-1"></a>
<h4 id="specifying-the-model-2">2. Specifying the Model<a class="anchor" aria-label="anchor" href="#specifying-the-model-2"></a>
</h4>
<p>We use a linear regression model to predict resistance trends.</p>
<div class="sourceCode" id="cb12"><pre class="downlit sourceCode r">
<div class="sourceCode" id="cb19"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># Define the linear regression model</span></span>
<span><span class="va">lm_model</span> <span class="op">&lt;-</span> <span class="fu">linear_reg</span><span class="op">(</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span></span>
<span> <span class="fu">set_engine</span><span class="op">(</span><span class="st">"lm"</span><span class="op">)</span> <span class="co"># Use linear regression</span></span>
@@ -588,10 +825,10 @@ engine.</li>
</ul>
</div>
<div class="section level4">
<h4 id="building-the-workflow-1">3. Building the Workflow<a class="anchor" aria-label="anchor" href="#building-the-workflow-1"></a>
<h4 id="building-the-workflow-2">3. Building the Workflow<a class="anchor" aria-label="anchor" href="#building-the-workflow-2"></a>
</h4>
<p>We combine the preprocessing recipe and model into a workflow.</p>
<div class="sourceCode" id="cb13"><pre class="downlit sourceCode r">
<div class="sourceCode" id="cb20"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># Create workflow</span></span>
<span><span class="va">resistance_workflow_time</span> <span class="op">&lt;-</span> <span class="fu">workflow</span><span class="op">(</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span></span>
<span> <span class="fu">add_recipe</span><span class="op">(</span><span class="va">resistance_recipe_time</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span></span>
@@ -616,12 +853,12 @@ engine.</li>
</div>
</div>
<div class="section level3">
<h3 id="training-and-evaluating-the-model-1">
<strong>Training and Evaluating the Model</strong><a class="anchor" aria-label="anchor" href="#training-and-evaluating-the-model-1"></a>
<h3 id="training-and-evaluating-the-model-2">
<strong>Training and Evaluating the Model</strong><a class="anchor" aria-label="anchor" href="#training-and-evaluating-the-model-2"></a>
</h3>
<p>We split the data into training and testing sets, fit the model, and
evaluate performance.</p>
<div class="sourceCode" id="cb14"><pre class="downlit sourceCode r">
<div class="sourceCode" id="cb21"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># Split the data</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/base/Random.html" class="external-link">set.seed</a></span><span class="op">(</span><span class="fl">123</span><span class="op">)</span></span>
<span><span class="va">data_split_time</span> <span class="op">&lt;-</span> <span class="fu">initial_split</span><span class="op">(</span><span class="va">data_time</span>, prop <span class="op">=</span> <span class="fl">0.8</span><span class="op">)</span></span>
@@ -662,11 +899,11 @@ sets.</li>
</ul>
</div>
<div class="section level3">
<h3 id="visualising-predictions">
<strong>Visualising Predictions</strong><a class="anchor" aria-label="anchor" href="#visualising-predictions"></a>
<h3 id="visualising-predictions-1">
<strong>Visualising Predictions</strong><a class="anchor" aria-label="anchor" href="#visualising-predictions-1"></a>
</h3>
<p>We plot resistance trends over time for amoxicillin.</p>
<div class="sourceCode" id="cb15"><pre class="downlit sourceCode r">
<div class="sourceCode" id="cb22"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://ggplot2.tidyverse.org" class="external-link">ggplot2</a></span><span class="op">)</span></span>
<span></span>
<span><span class="co"># Plot actual vs predicted resistance over time</span></span>
@@ -677,10 +914,10 @@ sets.</li>
<span> x <span class="op">=</span> <span class="st">"Year"</span>,</span>
<span> y <span class="op">=</span> <span class="st">"Resistance Proportion"</span><span class="op">)</span> <span class="op">+</span></span>
<span> <span class="fu"><a href="https://ggplot2.tidyverse.org/reference/ggtheme.html" class="external-link">theme_minimal</a></span><span class="op">(</span><span class="op">)</span></span></code></pre></div>
<p><img src="AMR_with_tidymodels_files/figure-html/unnamed-chunk-14-1.png" class="r-plt" width="720"></p>
<p><img src="AMR_with_tidymodels_files/figure-html/unnamed-chunk-21-1.png" class="r-plt" alt="" width="720"></p>
<p>Additionally, we can visualise resistance trends in
<code>ggplot2</code> and directly add linear models there:</p>
<div class="sourceCode" id="cb16"><pre class="downlit sourceCode r">
<div class="sourceCode" id="cb23"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="https://ggplot2.tidyverse.org/reference/ggplot.html" class="external-link">ggplot</a></span><span class="op">(</span><span class="va">data_time</span>, <span class="fu"><a href="https://ggplot2.tidyverse.org/reference/aes.html" class="external-link">aes</a></span><span class="op">(</span>x <span class="op">=</span> <span class="va">year</span>, y <span class="op">=</span> <span class="va">res_AMX</span>, color <span class="op">=</span> <span class="va">gramstain</span><span class="op">)</span><span class="op">)</span> <span class="op">+</span></span>
<span> <span class="fu"><a href="https://ggplot2.tidyverse.org/reference/geom_path.html" class="external-link">geom_line</a></span><span class="op">(</span><span class="op">)</span> <span class="op">+</span></span>
<span> <span class="fu"><a href="https://ggplot2.tidyverse.org/reference/labs.html" class="external-link">labs</a></span><span class="op">(</span>title <span class="op">=</span> <span class="st">"AMX Resistance Trends"</span>,</span>
@@ -691,7 +928,7 @@ sets.</li>
<span> formula <span class="op">=</span> <span class="va">y</span> <span class="op">~</span> <span class="va">x</span>,</span>
<span> alpha <span class="op">=</span> <span class="fl">0.25</span><span class="op">)</span> <span class="op">+</span></span>
<span> <span class="fu"><a href="https://ggplot2.tidyverse.org/reference/ggtheme.html" class="external-link">theme_minimal</a></span><span class="op">(</span><span class="op">)</span></span></code></pre></div>
<p><img src="AMR_with_tidymodels_files/figure-html/unnamed-chunk-15-1.png" class="r-plt" width="720"></p>
<p><img src="AMR_with_tidymodels_files/figure-html/unnamed-chunk-22-1.png" class="r-plt" alt="" width="720"></p>
</div>
<div class="section level3">
<h3 id="conclusion-1">

View File

@@ -1,6 +1,6 @@
# AMR with tidymodels
> This page was entirely written by our [AMR for R
> This page was almost entirely written by our [AMR for R
> Assistant](https://chat.amr-for-r.org), a ChatGPT manually-trained
> model able to answer any question about the `AMR` package.
@@ -351,21 +351,250 @@ and reproducibly.
In this second example, we demonstrate how to use `<mic>` columns
directly in `tidymodels` workflows using AMR-specific recipe steps. This
includes a transformation to `log2` scale using `step_mic_log2()`, which
prepares MIC values for use in classification models.
includes a transformation to `log2` scale using
[`step_mic_log2()`](https://amr-for-r.org/reference/amr-tidymodels.md),
which prepares MIC values for use in classification models.
This approach and idea formed the basis for the publication [DOI:
10.3389/fmicb.2025.1582703](https://doi.org/10.3389/fmicb.2025.1582703)
to model the presence of extended-spectrum beta-lactamases (ESBL).
to model the presence of extended-spectrum beta-lactamases (ESBL) based
on MIC values.
> NOTE: THIS EXAMPLE WILL BE AVAILABLE IN A NEXT VERSION (#TODO)
>
> The new AMR package version will contain new tidymodels selectors such
> as `step_mic_log2()`.
### **Objective**
Our goal is to:
1. Use raw MIC values to predict whether a bacterial isolate produces
ESBL.
2. Apply AMR-aware preprocessing in a `tidymodels` recipe.
3. Train a classification model and evaluate its predictive
performance.
### **Data Preparation**
We use the `esbl_isolates` dataset that comes with the AMR package.
``` r
# Load required libraries
library(AMR)
library(tidymodels)
# View the esbl_isolates data set
esbl_isolates
#> # A tibble: 500 × 19
#> esbl genus AMC AMP TZP CXM FOX CTX CAZ GEN TOB TMP SXT
#> <lgl> <chr> <mic> <mic> <mic> <mic> <mic> <mic> <mic> <mic> <mic> <mic> <mic>
#> 1 FALSE Esch… 32 32 4 64 64 8.00 8.00 1 1 16.0 20
#> 2 FALSE Esch… 32 32 4 64 64 4.00 8.00 1 1 16.0 320
#> 3 FALSE Esch… 4 2 64 8 4 8.00 0.12 16 16 0.5 20
#> 4 FALSE Kleb… 32 32 16 64 64 8.00 8.00 1 1 0.5 20
#> 5 FALSE Esch… 32 32 4 4 4 0.25 2.00 1 1 16.0 320
#> 6 FALSE Citr… 32 32 16 64 64 64.00 32.00 1 1 0.5 20
#> 7 FALSE Morg… 32 32 4 64 64 16.00 2.00 1 1 0.5 20
#> 8 FALSE Prot… 16 32 4 1 4 8.00 0.12 1 1 16.0 320
#> 9 FALSE Ente… 32 32 8 64 64 32.00 4.00 1 1 0.5 20
#> 10 FALSE Citr… 32 32 32 64 64 8.00 64.00 1 1 16.0 320
#> # 490 more rows
#> # 6 more variables: NIT <mic>, FOS <mic>, CIP <mic>, IPM <mic>, MEM <mic>,
#> # COL <mic>
# Prepare a binary outcome and convert to ordered factor
data <- esbl_isolates %>%
mutate(esbl = factor(esbl, levels = c(FALSE, TRUE), ordered = TRUE))
```
**Explanation:**
- `esbl_isolates`: Contains MIC test results and ESBL status for each
isolate.
- `mutate(esbl = ...)`: Converts the target column to an ordered factor
for classification.
### **Defining the Workflow**
#### 1. Preprocessing with a Recipe
We use our
[`step_mic_log2()`](https://amr-for-r.org/reference/amr-tidymodels.md)
function to log2-transform MIC values, ensuring that MICs are numeric
and properly scaled. All MIC predictors can easily and agnostically
selected using the new
[`all_mic_predictors()`](https://amr-for-r.org/reference/amr-tidymodels.md):
``` r
# Split into training and testing sets
set.seed(123)
split <- initial_split(data)
training_data <- training(split)
testing_data <- testing(split)
# Define the recipe
mic_recipe <- recipe(esbl ~ ., data = training_data) %>%
remove_role(genus, old_role = "predictor") %>% # Remove non-informative variable
step_mic_log2(all_mic_predictors()) #%>% # Log2 transform all MIC predictors
# prep()
mic_recipe
#>
#> ── Recipe ──────────────────────────────────────────────────────────────────────
#>
#> ── Inputs
#> Number of variables by role
#> outcome: 1
#> predictor: 17
#> undeclared role: 1
#>
#> ── Operations
#> • Log2 transformation of MIC columns: all_mic_predictors()
```
**Explanation:**
- `remove_role()`: Removes irrelevant variables like genus.
- [`step_mic_log2()`](https://amr-for-r.org/reference/amr-tidymodels.md):
Applies `log2(as.numeric(...))` to all MIC predictors in one go.
- `prep()`: Finalises the recipe based on training data.
#### 2. Specifying the Model
We use a simple logistic regression to model ESBL presence, though
recent models such as xgboost ([link to `parsnip`
manual](https://parsnip.tidymodels.org/reference/details_boost_tree_xgboost.html))
could be much more precise.
``` r
# Define the model
model <- logistic_reg(mode = "classification") %>%
set_engine("glm")
model
#> Logistic Regression Model Specification (classification)
#>
#> Computational engine: glm
```
**Explanation:**
- `logistic_reg()`: Specifies a binary classification model.
- `set_engine("glm")`: Uses the base R GLM engine.
#### 3. Building the Workflow
``` r
# Create workflow
workflow_model <- workflow() %>%
add_recipe(mic_recipe) %>%
add_model(model)
workflow_model
#> ══ Workflow ════════════════════════════════════════════════════════════════════
#> Preprocessor: Recipe
#> Model: logistic_reg()
#>
#> ── Preprocessor ────────────────────────────────────────────────────────────────
#> 1 Recipe Step
#>
#> • step_mic_log2()
#>
#> ── Model ───────────────────────────────────────────────────────────────────────
#> Logistic Regression Model Specification (classification)
#>
#> Computational engine: glm
```
### **Training and Evaluating the Model**
``` r
# Fit the model
fitted <- fit(workflow_model, training_data)
# Generate predictions
predictions <- predict(fitted, testing_data) %>%
bind_cols(predict(fitted, testing_data, type = "prob")) %>% # add probabilities
bind_cols(testing_data)
# Evaluate model performance
our_metrics <- metric_set(accuracy, recall, precision, sensitivity, specificity, ppv, npv)
metrics <- our_metrics(predictions, truth = esbl, estimate = .pred_class)
metrics
#> # A tibble: 7 × 3
#> .metric .estimator .estimate
#> <chr> <chr> <dbl>
#> 1 accuracy binary 0.92
#> 2 recall binary 0.921
#> 3 precision binary 0.921
#> 4 sensitivity binary 0.921
#> 5 specificity binary 0.919
#> 6 ppv binary 0.921
#> 7 npv binary 0.919
```
**Explanation:**
- `fit()`: Trains the model on the processed training data.
- [`predict()`](https://rdrr.io/r/stats/predict.html): Produces
predictions for unseen test data.
- `metric_set()`: Allows evaluating multiple classification metrics.
This will make `our_metrics` to become a function that we can use to
check the predictions with.
It appears we can predict ESBL gene presence with a positive predictive
value (PPV) of 92.1% and a negative predictive value (NPV) of 91.9 using
a simplistic logistic regression model.
### **Visualising Predictions**
We can visualise predictions by comparing predicted and actual ESBL
status.
``` r
library(ggplot2)
ggplot(predictions, aes(x = esbl, fill = .pred_class)) +
geom_bar(position = "stack") +
labs(title = "Predicted vs Actual ESBL Status",
x = "Actual ESBL",
y = "Count") +
theme_minimal()
```
![](AMR_with_tidymodels_files/figure-html/unnamed-chunk-14-1.png)
And plot the certainties too - how certain were the actual predictions?
``` r
predictions %>%
mutate(certainty = ifelse(.pred_class == "FALSE",
.pred_FALSE,
.pred_TRUE),
correct = ifelse(esbl == .pred_class, "Right", "Wrong")) %>%
ggplot(aes(x = seq_len(nrow(predictions)),
y = certainty,
colour = correct)) +
scale_colour_manual(values = c(Right = "green3", Wrong = "red2"),
name = "Correct?") +
geom_point() +
scale_y_continuous(labels = function(x) paste0(x * 100, "%"),
limits = c(0.5, 1)) +
theme_minimal()
```
![](AMR_with_tidymodels_files/figure-html/unnamed-chunk-15-1.png) \###
**Conclusion**
In this example, we showcased how the new `AMR`-specific recipe steps
simplify working with `<mic>` columns in `tidymodels`. The
[`step_mic_log2()`](https://amr-for-r.org/reference/amr-tidymodels.md)
transformation converts ordered MICs to log2-transformed numerics,
improving compatibility with classification models.
This pipeline enables realistic, reproducible, and interpretable
modelling of antimicrobial resistance data.
------------------------------------------------------------------------
## Example 2: Predicting AMR Over Time
## Example 3: Predicting AMR Over Time
In this third example, we aim to predict antimicrobial resistance (AMR)
trends over time using `tidymodels`. We will model resistance to three
@@ -573,7 +802,7 @@ ggplot(predictions_time, aes(x = year)) +
theme_minimal()
```
![](AMR_with_tidymodels_files/figure-html/unnamed-chunk-14-1.png)
![](AMR_with_tidymodels_files/figure-html/unnamed-chunk-21-1.png)
Additionally, we can visualise resistance trends in `ggplot2` and
directly add linear models there:
@@ -591,7 +820,7 @@ ggplot(data_time, aes(x = year, y = res_AMX, color = gramstain)) +
theme_minimal()
```
![](AMR_with_tidymodels_files/figure-html/unnamed-chunk-15-1.png)
![](AMR_with_tidymodels_files/figure-html/unnamed-chunk-22-1.png)
### **Conclusion**

Binary file not shown.

Before

Width:  |  Height:  |  Size: 64 KiB

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 137 KiB

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 137 KiB

View File

@@ -30,7 +30,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">

View File

@@ -30,7 +30,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
@@ -210,18 +210,18 @@ per drug explain the difference per microorganism.</p>
</h2>
<div class="sourceCode" id="cb6"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="https://rdrr.io/r/stats/biplot.html" class="external-link">biplot</a></span><span class="op">(</span><span class="va">pca_result</span><span class="op">)</span></span></code></pre></div>
<p><img src="PCA_files/figure-html/unnamed-chunk-5-1.png" class="r-plt" width="750"></p>
<p><img src="PCA_files/figure-html/unnamed-chunk-5-1.png" class="r-plt" alt="" width="750"></p>
<p>But we cant see the explanation of the points. Perhaps this works
better with our new <code><a href="../reference/ggplot_pca.html">ggplot_pca()</a></code> function, that
automatically adds the right labels and even groups:</p>
<div class="sourceCode" id="cb7"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="../reference/ggplot_pca.html">ggplot_pca</a></span><span class="op">(</span><span class="va">pca_result</span><span class="op">)</span></span></code></pre></div>
<p><img src="PCA_files/figure-html/unnamed-chunk-6-1.png" class="r-plt" width="750"></p>
<p><img src="PCA_files/figure-html/unnamed-chunk-6-1.png" class="r-plt" alt="" width="750"></p>
<p>You can also print an ellipse per group, and edit the appearance:</p>
<div class="sourceCode" id="cb8"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="../reference/ggplot_pca.html">ggplot_pca</a></span><span class="op">(</span><span class="va">pca_result</span>, ellipse <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span> <span class="op">+</span></span>
<span> <span class="fu">ggplot2</span><span class="fu">::</span><span class="fu"><a href="https://ggplot2.tidyverse.org/reference/labs.html" class="external-link">labs</a></span><span class="op">(</span>title <span class="op">=</span> <span class="st">"An AMR/PCA biplot!"</span><span class="op">)</span></span></code></pre></div>
<p><img src="PCA_files/figure-html/unnamed-chunk-7-1.png" class="r-plt" width="750"></p>
<p><img src="PCA_files/figure-html/unnamed-chunk-7-1.png" class="r-plt" alt="" width="750"></p>
</div>
</main><aside class="col-md-3"><nav id="toc" aria-label="Table of contents"><h2>On this page</h2>
</nav></aside>

View File

@@ -30,7 +30,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
@@ -311,7 +311,7 @@ using the included <code><a href="../reference/ggplot_sir.html">ggplot_sir()</a>
<span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/group_by.html" class="external-link">group_by</a></span><span class="op">(</span><span class="va">Country</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span></span>
<span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/select.html" class="external-link">select</a></span><span class="op">(</span><span class="va">Country</span>, <span class="va">AMP_ND2</span>, <span class="va">AMC_ED20</span>, <span class="va">CAZ_ED10</span>, <span class="va">CIP_ED5</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span></span>
<span> <span class="fu"><a href="../reference/ggplot_sir.html">ggplot_sir</a></span><span class="op">(</span>translate_ab <span class="op">=</span> <span class="st">"ab"</span>, facet <span class="op">=</span> <span class="st">"Country"</span>, datalabels <span class="op">=</span> <span class="cn">FALSE</span><span class="op">)</span></span></code></pre></div>
<p><img src="WHONET_files/figure-html/unnamed-chunk-7-1.png" class="r-plt" width="720"></p>
<p><img src="WHONET_files/figure-html/unnamed-chunk-7-1.png" class="r-plt" alt="" width="720"></p>
</div>
</main><aside class="col-md-3"><nav id="toc" aria-label="Table of contents"><h2>On this page</h2>
</nav></aside>

View File

@@ -30,7 +30,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">

View File

@@ -30,7 +30,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
@@ -80,7 +80,7 @@
<main id="main" class="col-md-9"><div class="page-header">
<img src="../logo.svg" class="logo" alt=""><h1>Download data sets for download / own use</h1>
<h4 data-toc-skip class="date">15 December 2025</h4>
<h4 data-toc-skip class="date">22 December 2025</h4>
<small class="dont-index">Source: <a href="https://github.com/msberends/AMR/blob/main/vignettes/datasets.Rmd" class="external-link"><code>vignettes/datasets.Rmd</code></a></small>
<div class="d-none name"><code>datasets.Rmd</code></div>

View File

@@ -7,7 +7,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">

View File

@@ -7,7 +7,7 @@
<a class="navbar-brand me-2" href="index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">

View File

@@ -33,7 +33,7 @@
<a class="navbar-brand me-2" href="index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">

View File

@@ -859,6 +859,8 @@ information about how to work with functions in this package.
: Data Set with Clinical Breakpoints for SIR Interpretation
- [`example_isolates`](https://amr-for-r.org/reference/example_isolates.md)
: Data Set with 2 000 Example Isolates
- [`esbl_isolates`](https://amr-for-r.org/reference/esbl_isolates.md) :
Data Set with 500 ESBL Isolates
- [`microorganisms.codes`](https://amr-for-r.org/reference/microorganisms.codes.md)
: Data Set with 6 036 Common Microorganism Codes
- [`microorganisms.groups`](https://amr-for-r.org/reference/microorganisms.groups.md)

View File

@@ -7,7 +7,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
@@ -49,9 +49,19 @@
</div>
<div class="section level2">
<h2 class="pkg-version" data-toc-text="3.0.1.9004" id="amr-3019004">AMR 3.0.1.9004<a class="anchor" aria-label="anchor" href="#amr-3019004"></a></h2>
<h2 class="pkg-version" data-toc-text="3.0.1.9007" id="amr-3019007">AMR 3.0.1.9007<a class="anchor" aria-label="anchor" href="#amr-3019007"></a></h2>
<div class="section level4">
<h4 id="changed-3-0-1-9004">Changed<a class="anchor" aria-label="anchor" href="#changed-3-0-1-9004"></a></h4>
<h4 id="new-3-0-1-9007">New<a class="anchor" aria-label="anchor" href="#new-3-0-1-9007"></a></h4>
<ul><li>Integration with the <strong>tidymodels</strong> framework to allow seamless use of SIR, MIC and disk data in modelling pipelines via <code>recipes</code>
<ul><li>
<code><a href="../reference/amr-tidymodels.html">step_mic_log2()</a></code> to transform <code>&lt;mic&gt;</code> columns with log2, and <code><a href="../reference/amr-tidymodels.html">step_sir_numeric()</a></code> to convert <code>&lt;sir&gt;</code> columns to numeric</li>
<li>New <code>tidyselect</code> helpers: <code><a href="../reference/amr-tidymodels.html">all_sir()</a></code>, <code><a href="../reference/amr-tidymodels.html">all_sir_predictors()</a></code>, <code><a href="../reference/amr-tidymodels.html">all_mic()</a></code>, <code><a href="../reference/amr-tidymodels.html">all_mic_predictors()</a></code>, <code><a href="../reference/amr-tidymodels.html">all_disk()</a></code>, <code><a href="../reference/amr-tidymodels.html">all_disk_predictors()</a></code>
</li>
</ul></li>
<li>Data set <code>esbl_isolates</code> to practise with AMR modelling</li>
</ul></div>
<div class="section level4">
<h4 id="changed-3-0-1-9007">Changed<a class="anchor" aria-label="anchor" href="#changed-3-0-1-9007"></a></h4>
<ul><li>Fixed a bug in <code><a href="../reference/antibiogram.html">antibiogram()</a></code> for when no antimicrobials are set</li>
<li>Added taniborbactam (<code>TAN</code>) and cefepime/taniborbactam (<code>FTA</code>) to the <code>antimicrobials</code> data set</li>
<li>Fixed a bug in <code><a href="../reference/as.sir.html">as.sir()</a></code> where for numeric input the arguments <code>S</code>, <code>i</code>, and <code>R</code> would not be considered (<a href="https://github.com/msberends/AMR/issues/244" class="external-link">#244</a>)</li>
@@ -104,7 +114,7 @@
<p>This package now supports not only tools for AMR data analysis in clinical settings, but also for veterinary and environmental microbiology. This was made possible through a collaboration with the <a href="https://www.upei.ca/avc" class="external-link">University of Prince Edward Islands Atlantic Veterinary College</a>, Canada. To celebrate this great improvement of the package, we also updated the package logo to reflect this change.</p>
<div class="section level4">
<h4 id="breaking-3-0-0">Breaking<a class="anchor" aria-label="anchor" href="#breaking-3-0-0"></a></h4>
<ul><li>Dataset <code>antibiotics</code> has been renamed to <code>antimicrobials</code> as the data set contains more than just antibiotics. Using <code>antibiotics</code> will still work, but now returns a warning.</li>
<ul><li>Data set <code>antibiotics</code> has been renamed to <code>antimicrobials</code> as the data set contains more than just antibiotics. Using <code>antibiotics</code> will still work, but now returns a warning.</li>
<li>Removed all functions and references that used the deprecated <code>rsi</code> class, which were all replaced with their <code>sir</code> equivalents over two years ago.</li>
<li>Functions <code><a href="../reference/resistance_predict.html">resistance_predict()</a></code> and <code><a href="../reference/resistance_predict.html">sir_predict()</a></code> are now deprecated and will be removed in a future version. Use the <code>tidymodels</code> framework instead, for which we <a href="https://amr-for-r.org/articles/AMR_with_tidymodels.html">wrote a basic introduction</a>.</li>
</ul></div>
@@ -122,7 +132,7 @@
</ul></li>
<li>
<strong>Support for WISCA antibiograms</strong>
<ul><li>The <code><a href="../reference/antibiogram.html">antibiogram()</a></code> function now supports creating true Weighted-Incidence Syndromic Combination Antibiograms (WISCA), a powerful Bayesian method for estimating regimen coverage probabilities using pathogen incidence and antimicrobial susceptibility data. WISCA offers improved precision for syndrome-specific treatment, even in datasets with sparse data. A dedicated <code><a href="../reference/antibiogram.html">wisca()</a></code> function is also available for easy usage.</li>
<ul><li>The <code><a href="../reference/antibiogram.html">antibiogram()</a></code> function now supports creating true Weighted-Incidence Syndromic Combination Antibiograms (WISCA), a powerful Bayesian method for estimating regimen coverage probabilities using pathogen incidence and antimicrobial susceptibility data. WISCA offers improved precision for syndrome-specific treatment, even in data sets with sparse data. A dedicated <code><a href="../reference/antibiogram.html">wisca()</a></code> function is also available for easy usage.</li>
</ul></li>
<li>
<strong>More global coverage of languages</strong>

View File

@@ -1,6 +1,23 @@
# Changelog
## AMR 3.0.1.9004
## AMR 3.0.1.9007
#### New
- Integration with the **tidymodels** framework to allow seamless use of
SIR, MIC and disk data in modelling pipelines via `recipes`
- [`step_mic_log2()`](https://amr-for-r.org/reference/amr-tidymodels.md)
to transform `<mic>` columns with log2, and
[`step_sir_numeric()`](https://amr-for-r.org/reference/amr-tidymodels.md)
to convert `<sir>` columns to numeric
- New `tidyselect` helpers:
[`all_sir()`](https://amr-for-r.org/reference/amr-tidymodels.md),
[`all_sir_predictors()`](https://amr-for-r.org/reference/amr-tidymodels.md),
[`all_mic()`](https://amr-for-r.org/reference/amr-tidymodels.md),
[`all_mic_predictors()`](https://amr-for-r.org/reference/amr-tidymodels.md),
[`all_disk()`](https://amr-for-r.org/reference/amr-tidymodels.md),
[`all_disk_predictors()`](https://amr-for-r.org/reference/amr-tidymodels.md)
- Data set `esbl_isolates` to practise with AMR modelling
#### Changed
@@ -119,8 +136,8 @@ this change.
#### Breaking
- Dataset `antibiotics` has been renamed to `antimicrobials` as the data
set contains more than just antibiotics. Using `antibiotics` will
- Data set `antibiotics` has been renamed to `antimicrobials` as the
data set contains more than just antibiotics. Using `antibiotics` will
still work, but now returns a warning.
- Removed all functions and references that used the deprecated `rsi`
class, which were all replaced with their `sir` equivalents over two
@@ -158,7 +175,7 @@ this change.
Combination Antibiograms (WISCA), a powerful Bayesian method for
estimating regimen coverage probabilities using pathogen incidence
and antimicrobial susceptibility data. WISCA offers improved
precision for syndrome-specific treatment, even in datasets with
precision for syndrome-specific treatment, even in data sets with
sparse data. A dedicated
[`wisca()`](https://amr-for-r.org/reference/antibiogram.md) function
is also available for easy usage.

View File

@@ -10,7 +10,7 @@ articles:
PCA: PCA.html
WHONET: WHONET.html
WISCA: WISCA.html
last_built: 2025-12-15T12:28Z
last_built: 2025-12-22T08:44Z
urls:
reference: https://amr-for-r.org/reference
article: https://amr-for-r.org/articles

View File

@@ -7,7 +7,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">

View File

@@ -7,7 +7,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">

View File

@@ -21,7 +21,7 @@ The AMR package is available in English, Arabic, Bengali, Chinese, Czech, Danish
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">

View File

@@ -7,7 +7,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">

View File

@@ -7,7 +7,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">

View File

@@ -7,7 +7,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">

View File

@@ -7,7 +7,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">

View File

@@ -7,7 +7,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">

View File

@@ -7,7 +7,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">

View File

@@ -7,7 +7,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
@@ -112,16 +112,16 @@
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="va">df</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> birth_date age age_exact age_at_y2k</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1 1980-02-27 45 45.79726 19</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2 1953-07-26 72 72.38904 46</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3 1949-09-02 76 76.28493 50</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4 1986-08-03 39 39.36712 13</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 5 1932-11-19 93 93.07123 67</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 6 1949-03-30 76 76.71233 50</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 7 1996-06-23 29 29.47945 3</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 8 1963-09-16 62 62.24658 36</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 9 1952-05-16 73 73.58356 47</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 10 1952-11-14 73 73.08493 47</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1 1980-02-27 45 45.81644 19</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2 1953-07-26 72 72.40822 46</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3 1949-09-02 76 76.30411 50</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4 1986-08-03 39 39.38630 13</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 5 1932-11-19 93 93.09041 67</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 6 1949-03-30 76 76.73151 50</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 7 1996-06-23 29 29.49863 3</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 8 1963-09-16 62 62.26575 36</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 9 1952-05-16 73 73.60274 47</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 10 1952-11-14 73 73.10411 47</span>
</code></pre></div>
</div>
</main><aside class="col-md-3"><nav id="toc" aria-label="Table of contents"><h2>On this page</h2>

View File

@@ -81,14 +81,14 @@ df$age_at_y2k <- age(df$birth_date, "2000-01-01")
df
#> birth_date age age_exact age_at_y2k
#> 1 1980-02-27 45 45.79726 19
#> 2 1953-07-26 72 72.38904 46
#> 3 1949-09-02 76 76.28493 50
#> 4 1986-08-03 39 39.36712 13
#> 5 1932-11-19 93 93.07123 67
#> 6 1949-03-30 76 76.71233 50
#> 7 1996-06-23 29 29.47945 3
#> 8 1963-09-16 62 62.24658 36
#> 9 1952-05-16 73 73.58356 47
#> 10 1952-11-14 73 73.08493 47
#> 1 1980-02-27 45 45.81644 19
#> 2 1953-07-26 72 72.40822 46
#> 3 1949-09-02 76 76.30411 50
#> 4 1986-08-03 39 39.38630 13
#> 5 1932-11-19 93 93.09041 67
#> 6 1949-03-30 76 76.73151 50
#> 7 1996-06-23 29 29.49863 3
#> 8 1963-09-16 62 62.26575 36
#> 9 1952-05-16 73 73.60274 47
#> 10 1952-11-14 73 73.10411 47
```

View File

@@ -7,7 +7,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">

8
reference/all_disk.html Normal file
View File

@@ -0,0 +1,8 @@
<html>
<head>
<meta http-equiv="refresh" content="0;URL=https://amr-for-r.org/reference/amr-tidymodels.html" />
<meta name="robots" content="noindex">
<link rel="canonical" href="https://amr-for-r.org/reference/amr-tidymodels.html">
</head>
</html>

View File

@@ -0,0 +1,8 @@
<html>
<head>
<meta http-equiv="refresh" content="0;URL=https://amr-for-r.org/reference/amr-tidymodels.html" />
<meta name="robots" content="noindex">
<link rel="canonical" href="https://amr-for-r.org/reference/amr-tidymodels.html">
</head>
</html>

8
reference/all_mic.html Normal file
View File

@@ -0,0 +1,8 @@
<html>
<head>
<meta http-equiv="refresh" content="0;URL=https://amr-for-r.org/reference/amr-tidymodels.html" />
<meta name="robots" content="noindex">
<link rel="canonical" href="https://amr-for-r.org/reference/amr-tidymodels.html">
</head>
</html>

View File

@@ -0,0 +1,8 @@
<html>
<head>
<meta http-equiv="refresh" content="0;URL=https://amr-for-r.org/reference/amr-tidymodels.html" />
<meta name="robots" content="noindex">
<link rel="canonical" href="https://amr-for-r.org/reference/amr-tidymodels.html">
</head>
</html>

8
reference/all_sir.html Normal file
View File

@@ -0,0 +1,8 @@
<html>
<head>
<meta http-equiv="refresh" content="0;URL=https://amr-for-r.org/reference/amr-tidymodels.html" />
<meta name="robots" content="noindex">
<link rel="canonical" href="https://amr-for-r.org/reference/amr-tidymodels.html">
</head>
</html>

View File

@@ -0,0 +1,8 @@
<html>
<head>
<meta http-equiv="refresh" content="0;URL=https://amr-for-r.org/reference/amr-tidymodels.html" />
<meta name="robots" content="noindex">
<link rel="canonical" href="https://amr-for-r.org/reference/amr-tidymodels.html">
</head>
</html>

View File

@@ -0,0 +1,234 @@
<!DOCTYPE html>
<!-- Generated by pkgdown: do not edit by hand --><html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"><title>AMR Extensions for Tidymodels — amr-tidymodels • AMR (for R)</title><!-- favicons --><link rel="icon" type="image/png" sizes="96x96" href="../favicon-96x96.png"><link rel="icon" type="”image/svg+xml”" href="../favicon.svg"><link rel="apple-touch-icon" sizes="180x180" href="../apple-touch-icon.png"><link rel="icon" sizes="any" href="../favicon.ico"><link rel="manifest" href="../site.webmanifest"><script src="../deps/jquery-3.6.0/jquery-3.6.0.min.js"></script><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"><link href="../deps/bootstrap-5.3.1/bootstrap.min.css" rel="stylesheet"><script src="../deps/bootstrap-5.3.1/bootstrap.bundle.min.js"></script><link href="../deps/Lato-0.4.10/font.css" rel="stylesheet"><link href="../deps/Fira_Code-0.4.10/font.css" rel="stylesheet"><link href="../deps/font-awesome-6.5.2/css/all.min.css" rel="stylesheet"><link href="../deps/font-awesome-6.5.2/css/v4-shims.min.css" rel="stylesheet"><script src="../deps/headroom-0.11.0/headroom.min.js"></script><script src="../deps/headroom-0.11.0/jQuery.headroom.min.js"></script><script src="../deps/bootstrap-toc-1.0.1/bootstrap-toc.min.js"></script><script src="../deps/clipboard.js-2.0.11/clipboard.min.js"></script><script src="../deps/search-1.0.0/autocomplete.jquery.min.js"></script><script src="../deps/search-1.0.0/fuse.min.js"></script><script src="../deps/search-1.0.0/mark.min.js"></script><!-- pkgdown --><script src="../pkgdown.js"></script><link href="../extra.css" rel="stylesheet"><script src="../extra.js"></script><meta property="og:title" content="AMR Extensions for Tidymodels — amr-tidymodels"><meta name="description" content="This family of functions allows using AMR-specific data types such as &amp;lt;sir&amp;gt; and &amp;lt;mic&amp;gt; inside tidymodels pipelines."><meta property="og:description" content="This family of functions allows using AMR-specific data types such as &amp;lt;sir&amp;gt; and &amp;lt;mic&amp;gt; inside tidymodels pipelines."><meta property="og:image" content="https://amr-for-r.org/logo.svg"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/katex.min.css" integrity="sha384-nB0miv6/jRmo5UMMR1wu3Gz6NLsoTkbqJghGIsx//Rlm+ZU03BU6SQNC66uf4l5+" crossorigin="anonymous"><script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/katex.min.js" integrity="sha384-7zkQWkzuo3B5mTepMUcHkMB5jZaolc2xDwL6VFqjFALcbeS9Ggm/Yr2r3Dy4lfFg" crossorigin="anonymous"></script><script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/contrib/auto-render.min.js" integrity="sha384-43gviWU0YVjaDtb/GhzOouOXtZMP/7XUzwPTstBeZFe/+rCMvRwr4yROQP43s0Xk" crossorigin="anonymous" onload="renderMathInElement(document.body);"></script></head><body>
<a href="#main" class="visually-hidden-focusable">Skip to contents</a>
<nav class="navbar navbar-expand-lg fixed-top bg-primary" data-bs-theme="dark" aria-label="Site navigation"><div class="container">
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div id="navbar" class="collapse navbar-collapse ms-3">
<ul class="navbar-nav me-auto"><li class="nav-item dropdown">
<button class="nav-link dropdown-toggle" type="button" id="dropdown-how-to" data-bs-toggle="dropdown" aria-expanded="false" aria-haspopup="true"><span class="fa fa-question-circle"></span> How to</button>
<ul class="dropdown-menu" aria-labelledby="dropdown-how-to"><li><a class="dropdown-item" href="../articles/AMR.html"><span class="fa fa-directions"></span> Conduct AMR Analysis</a></li>
<li><a class="dropdown-item" href="../reference/antibiogram.html"><span class="fa fa-file-prescription"></span> Generate Antibiogram (Trad./Syndromic/WISCA)</a></li>
<li><a class="dropdown-item" href="../articles/AMR_with_tidymodels.html"><span class="fa fa-square-root-variable"></span> Use AMR for Predictive Modelling (tidymodels)</a></li>
<li><a class="dropdown-item" href="../articles/datasets.html"><span class="fa fa-database"></span> Download Data Sets for Own Use</a></li>
<li><a class="dropdown-item" href="../reference/AMR-options.html"><span class="fa fa-gear"></span> Set User- Or Team-specific Package Settings</a></li>
<li><a class="dropdown-item" href="../articles/PCA.html"><span class="fa fa-compress"></span> Conduct Principal Component Analysis for AMR</a></li>
<li><a class="dropdown-item" href="../reference/mdro.html"><span class="fa fa-skull-crossbones"></span> Determine Multi-Drug Resistance (MDR)</a></li>
<li><a class="dropdown-item" href="../articles/WHONET.html"><span class="fa fa-globe-americas"></span> Work with WHONET Data</a></li>
<li><a class="dropdown-item" href="../articles/EUCAST.html"><span class="fa fa-exchange-alt"></span> Apply EUCAST Rules</a></li>
<li><a class="dropdown-item" href="../reference/mo_property.html"><span class="fa fa-bug"></span> Get Taxonomy of a Microorganism</a></li>
<li><a class="dropdown-item" href="../reference/ab_property.html"><span class="fa fa-capsules"></span> Get Properties of an Antibiotic Drug</a></li>
<li><a class="dropdown-item" href="../reference/av_property.html"><span class="fa fa-capsules"></span> Get Properties of an Antiviral Drug</a></li>
</ul></li>
<li class="nav-item"><a class="nav-link" href="../articles/AMR_for_Python.html"><span class="fa fab fa-python"></span> AMR for Python</a></li>
<li class="active nav-item"><a class="nav-link" href="../reference/index.html"><span class="fa fa-book-open"></span> Manual</a></li>
<li class="nav-item"><a class="nav-link" href="../authors.html"><span class="fa fa-users"></span> Authors</a></li>
</ul><ul class="navbar-nav"><li class="nav-item"><form class="form-inline" role="search">
<input class="form-control" type="search" name="search-input" id="search-input" autocomplete="off" aria-label="Search site" placeholder="Search for" data-search-index="../search.json"></form></li>
<li class="nav-item"><a class="nav-link" href="../news/index.html"><span class="fa fa-newspaper"></span> Changelog</a></li>
<li class="nav-item"><a class="external-link nav-link" href="https://github.com/msberends/AMR"><span class="fa fa-github"></span> Source Code</a></li>
</ul></div>
</div>
</nav><div class="container template-reference-topic">
<div class="row">
<main id="main" class="col-md-9"><div class="page-header">
<img src="../logo.svg" class="logo" alt=""><h1>AMR Extensions for Tidymodels</h1>
<small class="dont-index">Source: <a href="https://github.com/msberends/AMR/blob/main/R/tidymodels.R" class="external-link"><code>R/tidymodels.R</code></a></small>
<div class="d-none name"><code>amr-tidymodels.Rd</code></div>
</div>
<div class="ref-description section level2">
<p>This family of functions allows using AMR-specific data types such as <code>&lt;sir&gt;</code> and <code>&lt;mic&gt;</code> inside <code>tidymodels</code> pipelines.</p>
</div>
<div class="section level2">
<h2 id="ref-usage">Usage<a class="anchor" aria-label="anchor" href="#ref-usage"></a></h2>
<div class="sourceCode"><pre class="sourceCode r"><code><span><span class="fu">all_sir</span><span class="op">(</span><span class="op">)</span></span>
<span></span>
<span><span class="fu">all_sir_predictors</span><span class="op">(</span><span class="op">)</span></span>
<span></span>
<span><span class="fu">all_mic</span><span class="op">(</span><span class="op">)</span></span>
<span></span>
<span><span class="fu">all_mic_predictors</span><span class="op">(</span><span class="op">)</span></span>
<span></span>
<span><span class="fu">all_disk</span><span class="op">(</span><span class="op">)</span></span>
<span></span>
<span><span class="fu">all_disk_predictors</span><span class="op">(</span><span class="op">)</span></span>
<span></span>
<span><span class="fu">step_mic_log2</span><span class="op">(</span><span class="va">recipe</span>, <span class="va">...</span>, role <span class="op">=</span> <span class="cn">NA</span>, trained <span class="op">=</span> <span class="cn">FALSE</span>, columns <span class="op">=</span> <span class="cn">NULL</span>,</span>
<span> skip <span class="op">=</span> <span class="cn">FALSE</span>, id <span class="op">=</span> <span class="fu">recipes</span><span class="fu">::</span><span class="fu"><a href="https://recipes.tidymodels.org/reference/rand_id.html" class="external-link">rand_id</a></span><span class="op">(</span><span class="st">"mic_log2"</span><span class="op">)</span><span class="op">)</span></span>
<span></span>
<span><span class="fu">step_sir_numeric</span><span class="op">(</span><span class="va">recipe</span>, <span class="va">...</span>, role <span class="op">=</span> <span class="cn">NA</span>, trained <span class="op">=</span> <span class="cn">FALSE</span>, columns <span class="op">=</span> <span class="cn">NULL</span>,</span>
<span> skip <span class="op">=</span> <span class="cn">FALSE</span>, id <span class="op">=</span> <span class="fu">recipes</span><span class="fu">::</span><span class="fu"><a href="https://recipes.tidymodels.org/reference/rand_id.html" class="external-link">rand_id</a></span><span class="op">(</span><span class="st">"sir_numeric"</span><span class="op">)</span><span class="op">)</span></span></code></pre></div>
</div>
<div class="section level2">
<h2 id="arguments">Arguments<a class="anchor" aria-label="anchor" href="#arguments"></a></h2>
<dl><dt id="arg-recipe">recipe<a class="anchor" aria-label="anchor" href="#arg-recipe"></a></dt>
<dd><p>A recipe object. The step will be added to the sequence of
operations for this recipe.</p></dd>
<dt id="arg--">...<a class="anchor" aria-label="anchor" href="#arg--"></a></dt>
<dd><p>One or more selector functions to choose variables for this step.
See <code><a href="https://recipes.tidymodels.org/reference/selections.html" class="external-link">selections()</a></code> for more details.</p></dd>
<dt id="arg-role">role<a class="anchor" aria-label="anchor" href="#arg-role"></a></dt>
<dd><p>Not used by this step since no new variables are created.</p></dd>
<dt id="arg-trained">trained<a class="anchor" aria-label="anchor" href="#arg-trained"></a></dt>
<dd><p>A logical to indicate if the quantities for preprocessing have
been estimated.</p></dd>
<dt id="arg-skip">skip<a class="anchor" aria-label="anchor" href="#arg-skip"></a></dt>
<dd><p>A logical. Should the step be skipped when the recipe is baked by
<code><a href="https://recipes.tidymodels.org/reference/bake.html" class="external-link">bake()</a></code>? While all operations are baked when <code><a href="https://recipes.tidymodels.org/reference/prep.html" class="external-link">prep()</a></code> is run, some
operations may not be able to be conducted on new data (e.g. processing the
outcome variable(s)). Care should be taken when using <code>skip = TRUE</code> as it
may affect the computations for subsequent operations.</p></dd>
<dt id="arg-id">id<a class="anchor" aria-label="anchor" href="#arg-id"></a></dt>
<dd><p>A character string that is unique to this step to identify it.</p></dd>
</dl></div>
<div class="section level2">
<h2 id="details">Details<a class="anchor" aria-label="anchor" href="#details"></a></h2>
<p>You can read more in our online <a href="https://amr-for-r.org/articles/AMR_with_tidymodels.html">AMR with tidymodels introduction</a>.</p>
<p>Tidyselect helpers include:</p><ul><li><p><code>all_sir()</code> and <code>all_sir_predictors()</code> to select <code><a href="as.sir.html">&lt;sir&gt;</a></code> columns</p></li>
<li><p><code>all_mic()</code> and <code>all_mic_predictors()</code> to select <code><a href="as.mic.html">&lt;mic&gt;</a></code> columns</p></li>
<li><p><code>all_disk()</code> and <code>all_disk_predictors()</code> to select <code><a href="as.disk.html">&lt;disk&gt;</a></code> columns</p></li>
</ul><p>Pre-processing pipeline steps include:</p><ul><li><p><code>step_sir_numeric()</code> to convert SIR columns to numeric (via <code><a href="https://rdrr.io/r/base/numeric.html" class="external-link">as.numeric()</a></code>), to be used with <code>all_sir_predictors()</code>: <code>"S"</code> = 1, <code>"I"</code>/<code>"SDD"</code> = 2, <code>"R"</code> = 3. All other values are rendered <code>NA</code>. Keep this in mind for further processing, especially if the model does not allow for <code>NA</code> values.</p></li>
<li><p><code>step_mic_log2()</code> to convert MIC columns to numeric (via <code><a href="https://rdrr.io/r/base/numeric.html" class="external-link">as.numeric()</a></code>) and apply a log2 transform, to be used with <code>all_mic_predictors()</code></p></li>
</ul><p>These steps integrate with <code><a href="https://recipes.tidymodels.org/reference/recipe.html" class="external-link">recipes::recipe()</a></code> and work like standard preprocessing steps. They are useful for preparing data for modelling, especially with classification models.</p>
</div>
<div class="section level2">
<h2 id="see-also">See also<a class="anchor" aria-label="anchor" href="#see-also"></a></h2>
<div class="dont-index"><p><code><a href="https://recipes.tidymodels.org/reference/recipe.html" class="external-link">recipes::recipe()</a></code>, <code><a href="as.sir.html">as.sir()</a></code>, <code><a href="as.mic.html">as.mic()</a></code>, <code><a href="as.disk.html">as.disk()</a></code></p></div>
</div>
<div class="section level2">
<h2 id="ref-examples">Examples<a class="anchor" aria-label="anchor" href="#ref-examples"></a></h2>
<div class="sourceCode"><pre class="sourceCode r"><code><span class="r-in"><span><span class="kw">if</span> <span class="op">(</span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">require</a></span><span class="op">(</span><span class="st"><a href="https://tidymodels.tidymodels.org" class="external-link">"tidymodels"</a></span><span class="op">)</span><span class="op">)</span> <span class="op">{</span></span></span>
<span class="r-in"><span></span></span>
<span class="r-in"><span> <span class="co"># The below approach formed the basis for this paper: DOI 10.3389/fmicb.2025.1582703</span></span></span>
<span class="r-in"><span> <span class="co"># Presence of ESBL genes was predicted based on raw MIC values.</span></span></span>
<span class="r-in"><span></span></span>
<span class="r-in"><span></span></span>
<span class="r-in"><span> <span class="co"># example data set in the AMR package</span></span></span>
<span class="r-in"><span> <span class="va">esbl_isolates</span></span></span>
<span class="r-in"><span></span></span>
<span class="r-in"><span> <span class="co"># Prepare a binary outcome and convert to ordered factor</span></span></span>
<span class="r-in"><span> <span class="va">data</span> <span class="op">&lt;-</span> <span class="va">esbl_isolates</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span></span></span>
<span class="r-in"><span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/mutate.html" class="external-link">mutate</a></span><span class="op">(</span>esbl <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/factor.html" class="external-link">factor</a></span><span class="op">(</span><span class="va">esbl</span>, levels <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="cn">FALSE</span>, <span class="cn">TRUE</span><span class="op">)</span>, ordered <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span><span class="op">)</span></span></span>
<span class="r-in"><span></span></span>
<span class="r-in"><span> <span class="co"># Split into training and testing sets</span></span></span>
<span class="r-in"><span> <span class="va">split</span> <span class="op">&lt;-</span> <span class="fu">initial_split</span><span class="op">(</span><span class="va">data</span><span class="op">)</span></span></span>
<span class="r-in"><span> <span class="va">training_data</span> <span class="op">&lt;-</span> <span class="fu">training</span><span class="op">(</span><span class="va">split</span><span class="op">)</span></span></span>
<span class="r-in"><span> <span class="va">testing_data</span> <span class="op">&lt;-</span> <span class="fu">testing</span><span class="op">(</span><span class="va">split</span><span class="op">)</span></span></span>
<span class="r-in"><span></span></span>
<span class="r-in"><span> <span class="co"># Create and prep a recipe with MIC log2 transformation</span></span></span>
<span class="r-in"><span> <span class="va">mic_recipe</span> <span class="op">&lt;-</span> <span class="fu">recipe</span><span class="op">(</span><span class="va">esbl</span> <span class="op">~</span> <span class="va">.</span>, data <span class="op">=</span> <span class="va">training_data</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span></span></span>
<span class="r-in"><span></span></span>
<span class="r-in"><span> <span class="co"># Optionally remove non-predictive variables</span></span></span>
<span class="r-in"><span> <span class="fu">remove_role</span><span class="op">(</span><span class="va">genus</span>, old_role <span class="op">=</span> <span class="st">"predictor"</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span></span></span>
<span class="r-in"><span></span></span>
<span class="r-in"><span> <span class="co"># Apply the log2 transformation to all MIC predictors</span></span></span>
<span class="r-in"><span> <span class="fu">step_mic_log2</span><span class="op">(</span><span class="fu">all_mic_predictors</span><span class="op">(</span><span class="op">)</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span></span></span>
<span class="r-in"><span></span></span>
<span class="r-in"><span> <span class="co"># And apply the preparation steps</span></span></span>
<span class="r-in"><span> <span class="fu">prep</span><span class="op">(</span><span class="op">)</span></span></span>
<span class="r-in"><span></span></span>
<span class="r-in"><span> <span class="co"># View prepped recipe</span></span></span>
<span class="r-in"><span> <span class="va">mic_recipe</span></span></span>
<span class="r-in"><span></span></span>
<span class="r-in"><span> <span class="co"># Apply the recipe to training and testing data</span></span></span>
<span class="r-in"><span> <span class="va">out_training</span> <span class="op">&lt;-</span> <span class="fu">bake</span><span class="op">(</span><span class="va">mic_recipe</span>, new_data <span class="op">=</span> <span class="cn">NULL</span><span class="op">)</span></span></span>
<span class="r-in"><span> <span class="va">out_testing</span> <span class="op">&lt;-</span> <span class="fu">bake</span><span class="op">(</span><span class="va">mic_recipe</span>, new_data <span class="op">=</span> <span class="va">testing_data</span><span class="op">)</span></span></span>
<span class="r-in"><span></span></span>
<span class="r-in"><span> <span class="co"># Fit a logistic regression model</span></span></span>
<span class="r-in"><span> <span class="va">fitted</span> <span class="op">&lt;-</span> <span class="fu">logistic_reg</span><span class="op">(</span>mode <span class="op">=</span> <span class="st">"classification"</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span></span></span>
<span class="r-in"><span> <span class="fu">set_engine</span><span class="op">(</span><span class="st">"glm"</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span></span></span>
<span class="r-in"><span> <span class="fu">fit</span><span class="op">(</span><span class="va">esbl</span> <span class="op">~</span> <span class="va">.</span>, data <span class="op">=</span> <span class="va">out_training</span><span class="op">)</span></span></span>
<span class="r-in"><span></span></span>
<span class="r-in"><span> <span class="co"># Generate predictions on the test set</span></span></span>
<span class="r-in"><span> <span class="va">predictions</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/stats/predict.html" class="external-link">predict</a></span><span class="op">(</span><span class="va">fitted</span>, <span class="va">out_testing</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span></span></span>
<span class="r-in"><span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/bind_cols.html" class="external-link">bind_cols</a></span><span class="op">(</span><span class="va">out_testing</span><span class="op">)</span></span></span>
<span class="r-in"><span></span></span>
<span class="r-in"><span> <span class="co"># Evaluate predictions using standard classification metrics</span></span></span>
<span class="r-in"><span> <span class="va">our_metrics</span> <span class="op">&lt;-</span> <span class="fu">metric_set</span><span class="op">(</span><span class="va">accuracy</span>,</span></span>
<span class="r-in"><span> <span class="va">recall</span>,</span></span>
<span class="r-in"><span> <span class="va">precision</span>,</span></span>
<span class="r-in"><span> <span class="va">sensitivity</span>,</span></span>
<span class="r-in"><span> <span class="va">specificity</span>,</span></span>
<span class="r-in"><span> <span class="va">ppv</span>,</span></span>
<span class="r-in"><span> <span class="va">npv</span><span class="op">)</span></span></span>
<span class="r-in"><span> <span class="va">metrics</span> <span class="op">&lt;-</span> <span class="fu">our_metrics</span><span class="op">(</span><span class="va">predictions</span>, truth <span class="op">=</span> <span class="va">esbl</span>, estimate <span class="op">=</span> <span class="va">.pred_class</span><span class="op">)</span></span></span>
<span class="r-in"><span></span></span>
<span class="r-in"><span> <span class="co"># Show performance</span></span></span>
<span class="r-in"><span> <span class="va">metrics</span></span></span>
<span class="r-in"><span><span class="op">}</span></span></span>
<span class="r-msg co"><span class="r-pr">#&gt;</span> Loading required package: tidymodels</span>
<span class="r-msg co"><span class="r-pr">#&gt;</span> ── <span style="font-weight: bold;">Attaching packages</span> ────────────────────────────────────── tidymodels 1.4.1 ──</span>
<span class="r-msg co"><span class="r-pr">#&gt;</span> <span style="color: #00BB00;"></span> <span style="color: #0000BB;">broom </span> 1.0.11 <span style="color: #00BB00;"></span> <span style="color: #0000BB;">rsample </span> 1.3.1 </span>
<span class="r-msg co"><span class="r-pr">#&gt;</span> <span style="color: #00BB00;"></span> <span style="color: #0000BB;">dials </span> 1.4.2 <span style="color: #00BB00;"></span> <span style="color: #0000BB;">tailor </span> 0.1.0 </span>
<span class="r-msg co"><span class="r-pr">#&gt;</span> <span style="color: #00BB00;"></span> <span style="color: #0000BB;">infer </span> 1.1.0 <span style="color: #00BB00;"></span> <span style="color: #0000BB;">tidyr </span> 1.3.2 </span>
<span class="r-msg co"><span class="r-pr">#&gt;</span> <span style="color: #00BB00;"></span> <span style="color: #0000BB;">modeldata </span> 1.5.1 <span style="color: #00BB00;"></span> <span style="color: #0000BB;">tune </span> 2.0.1 </span>
<span class="r-msg co"><span class="r-pr">#&gt;</span> <span style="color: #00BB00;"></span> <span style="color: #0000BB;">parsnip </span> 1.4.0 <span style="color: #00BB00;"></span> <span style="color: #0000BB;">workflows </span> 1.3.0 </span>
<span class="r-msg co"><span class="r-pr">#&gt;</span> <span style="color: #00BB00;"></span> <span style="color: #0000BB;">purrr </span> 1.2.0 <span style="color: #00BB00;"></span> <span style="color: #0000BB;">workflowsets</span> 1.1.1 </span>
<span class="r-msg co"><span class="r-pr">#&gt;</span> <span style="color: #00BB00;"></span> <span style="color: #0000BB;">recipes </span> 1.3.1 <span style="color: #00BB00;"></span> <span style="color: #0000BB;">yardstick </span> 1.3.2 </span>
<span class="r-msg co"><span class="r-pr">#&gt;</span> ── <span style="font-weight: bold;">Conflicts</span> ───────────────────────────────────────── tidymodels_conflicts() ──</span>
<span class="r-msg co"><span class="r-pr">#&gt;</span> <span style="color: #BB0000;"></span> <span style="color: #0000BB;">purrr</span>::<span style="color: #00BB00;">discard()</span> masks <span style="color: #0000BB;">scales</span>::discard()</span>
<span class="r-msg co"><span class="r-pr">#&gt;</span> <span style="color: #BB0000;"></span> <span style="color: #0000BB;">dplyr</span>::<span style="color: #00BB00;">filter()</span> masks <span style="color: #0000BB;">stats</span>::filter()</span>
<span class="r-msg co"><span class="r-pr">#&gt;</span> <span style="color: #BB0000;"></span> <span style="color: #0000BB;">dplyr</span>::<span style="color: #00BB00;">lag()</span> masks <span style="color: #0000BB;">stats</span>::lag()</span>
<span class="r-msg co"><span class="r-pr">#&gt;</span> <span style="color: #BB0000;"></span> <span style="color: #0000BB;">recipes</span>::<span style="color: #00BB00;">step()</span> masks <span style="color: #0000BB;">stats</span>::step()</span>
<span class="r-wrn co"><span class="r-pr">#&gt;</span> <span class="warning">Warning: </span>glm.fit: fitted probabilities numerically 0 or 1 occurred</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #949494;"># A tibble: 7 × 3</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> .metric .estimator .estimate</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #949494; font-style: italic;">&lt;chr&gt;</span> <span style="color: #949494; font-style: italic;">&lt;chr&gt;</span> <span style="color: #949494; font-style: italic;">&lt;dbl&gt;</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">1</span> accuracy binary 0.936</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">2</span> recall binary 0.954</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">3</span> precision binary 0.925</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">4</span> sensitivity binary 0.954</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">5</span> specificity binary 0.917</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">6</span> ppv binary 0.925</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">7</span> npv binary 0.948</span>
</code></pre></div>
</div>
</main><aside class="col-md-3"><nav id="toc" aria-label="Table of contents"><h2>On this page</h2>
</nav></aside></div>
<footer><div class="pkgdown-footer-left">
<p><code>AMR</code> (for R). Free and open-source, licenced under the <a target="_blank" href="https://github.com/msberends/AMR/blob/main/LICENSE" class="external-link">GNU General Public License version 2.0 (GPL-2)</a>.<br>Developed at the <a target="_blank" href="https://www.rug.nl" class="external-link">University of Groningen</a> and <a target="_blank" href="https://www.umcg.nl" class="external-link">University Medical Center Groningen</a> in The Netherlands.</p>
</div>
<div class="pkgdown-footer-right">
<p><a target="_blank" href="https://www.rug.nl" class="external-link"><img src="https://amr-for-r.org/logo_rug.svg" style="max-width: 150px;"></a><a target="_blank" href="https://www.umcg.nl" class="external-link"><img src="https://amr-for-r.org/logo_umcg.svg" style="max-width: 150px;"></a></p>
</div>
</footer></div>
</body></html>

192
reference/amr-tidymodels.md Normal file
View File

@@ -0,0 +1,192 @@
# AMR Extensions for Tidymodels
This family of functions allows using AMR-specific data types such as
`<sir>` and `<mic>` inside `tidymodels` pipelines.
## Usage
``` r
all_sir()
all_sir_predictors()
all_mic()
all_mic_predictors()
all_disk()
all_disk_predictors()
step_mic_log2(recipe, ..., role = NA, trained = FALSE, columns = NULL,
skip = FALSE, id = recipes::rand_id("mic_log2"))
step_sir_numeric(recipe, ..., role = NA, trained = FALSE, columns = NULL,
skip = FALSE, id = recipes::rand_id("sir_numeric"))
```
## Arguments
- recipe:
A recipe object. The step will be added to the sequence of operations
for this recipe.
- ...:
One or more selector functions to choose variables for this step. See
[`selections()`](https://recipes.tidymodels.org/reference/selections.html)
for more details.
- role:
Not used by this step since no new variables are created.
- trained:
A logical to indicate if the quantities for preprocessing have been
estimated.
- skip:
A logical. Should the step be skipped when the recipe is baked by
[`bake()`](https://recipes.tidymodels.org/reference/bake.html)? While
all operations are baked when
[`prep()`](https://recipes.tidymodels.org/reference/prep.html) is run,
some operations may not be able to be conducted on new data (e.g.
processing the outcome variable(s)). Care should be taken when using
`skip = TRUE` as it may affect the computations for subsequent
operations.
- id:
A character string that is unique to this step to identify it.
## Details
You can read more in our online [AMR with tidymodels
introduction](https://amr-for-r.org/articles/AMR_with_tidymodels.html).
Tidyselect helpers include:
- `all_sir()` and `all_sir_predictors()` to select
[`<sir>`](https://amr-for-r.org/reference/as.sir.md) columns
- `all_mic()` and `all_mic_predictors()` to select
[`<mic>`](https://amr-for-r.org/reference/as.mic.md) columns
- `all_disk()` and `all_disk_predictors()` to select
[`<disk>`](https://amr-for-r.org/reference/as.disk.md) columns
Pre-processing pipeline steps include:
- `step_sir_numeric()` to convert SIR columns to numeric (via
[`as.numeric()`](https://rdrr.io/r/base/numeric.html)), to be used
with `all_sir_predictors()`: `"S"` = 1, `"I"`/`"SDD"` = 2, `"R"` = 3.
All other values are rendered `NA`. Keep this in mind for further
processing, especially if the model does not allow for `NA` values.
- `step_mic_log2()` to convert MIC columns to numeric (via
[`as.numeric()`](https://rdrr.io/r/base/numeric.html)) and apply a
log2 transform, to be used with `all_mic_predictors()`
These steps integrate with
[`recipes::recipe()`](https://recipes.tidymodels.org/reference/recipe.html)
and work like standard preprocessing steps. They are useful for
preparing data for modelling, especially with classification models.
## See also
[`recipes::recipe()`](https://recipes.tidymodels.org/reference/recipe.html),
[`as.sir()`](https://amr-for-r.org/reference/as.sir.md),
[`as.mic()`](https://amr-for-r.org/reference/as.mic.md),
[`as.disk()`](https://amr-for-r.org/reference/as.disk.md)
## Examples
``` r
if (require("tidymodels")) {
# The below approach formed the basis for this paper: DOI 10.3389/fmicb.2025.1582703
# Presence of ESBL genes was predicted based on raw MIC values.
# example data set in the AMR package
esbl_isolates
# Prepare a binary outcome and convert to ordered factor
data <- esbl_isolates %>%
mutate(esbl = factor(esbl, levels = c(FALSE, TRUE), ordered = TRUE))
# Split into training and testing sets
split <- initial_split(data)
training_data <- training(split)
testing_data <- testing(split)
# Create and prep a recipe with MIC log2 transformation
mic_recipe <- recipe(esbl ~ ., data = training_data) %>%
# Optionally remove non-predictive variables
remove_role(genus, old_role = "predictor") %>%
# Apply the log2 transformation to all MIC predictors
step_mic_log2(all_mic_predictors()) %>%
# And apply the preparation steps
prep()
# View prepped recipe
mic_recipe
# Apply the recipe to training and testing data
out_training <- bake(mic_recipe, new_data = NULL)
out_testing <- bake(mic_recipe, new_data = testing_data)
# Fit a logistic regression model
fitted <- logistic_reg(mode = "classification") %>%
set_engine("glm") %>%
fit(esbl ~ ., data = out_training)
# Generate predictions on the test set
predictions <- predict(fitted, out_testing) %>%
bind_cols(out_testing)
# Evaluate predictions using standard classification metrics
our_metrics <- metric_set(accuracy,
recall,
precision,
sensitivity,
specificity,
ppv,
npv)
metrics <- our_metrics(predictions, truth = esbl, estimate = .pred_class)
# Show performance
metrics
}
#> Loading required package: tidymodels
#> ── Attaching packages ────────────────────────────────────── tidymodels 1.4.1 ──
#> ✔ broom 1.0.11 ✔ rsample 1.3.1
#> ✔ dials 1.4.2 ✔ tailor 0.1.0
#> ✔ infer 1.1.0 ✔ tidyr 1.3.2
#> ✔ modeldata 1.5.1 ✔ tune 2.0.1
#> ✔ parsnip 1.4.0 ✔ workflows 1.3.0
#> ✔ purrr 1.2.0 ✔ workflowsets 1.1.1
#> ✔ recipes 1.3.1 ✔ yardstick 1.3.2
#> ── Conflicts ───────────────────────────────────────── tidymodels_conflicts() ──
#> ✖ purrr::discard() masks scales::discard()
#> ✖ dplyr::filter() masks stats::filter()
#> ✖ dplyr::lag() masks stats::lag()
#> ✖ recipes::step() masks stats::step()
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> # A tibble: 7 × 3
#> .metric .estimator .estimate
#> <chr> <chr> <dbl>
#> 1 accuracy binary 0.936
#> 2 recall binary 0.954
#> 3 precision binary 0.925
#> 4 sensitivity binary 0.954
#> 5 specificity binary 0.917
#> 6 ppv binary 0.925
#> 7 npv binary 0.948
```

View File

@@ -9,7 +9,7 @@ Adhering to previously described approaches (see Source) and especially the Baye
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
@@ -282,7 +282,7 @@ Adhering to previously described approaches (see Source) and especially the Baye
<span><span class="co"># this is equal to:</span></span>
<span><span class="fu"><a href="../reference/antibiogram.html">wisca</a></span><span class="op">(</span><span class="va">your_data</span>,</span>
<span> antimicrobials <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"TZP"</span>, <span class="st">"TZP+TOB"</span>, <span class="st">"TZP+GEN"</span><span class="op">)</span><span class="op">)</span></span></code></pre><p></p></div>
<p>WISCA uses a sophisticated Bayesian decision model to combine both local and pooled antimicrobial resistance data. This approach not only evaluates local patterns but can also draw on multi-centre datasets to improve regimen accuracy, even in low-incidence infections like paediatric bloodstream infections (BSIs).</p></li>
<p>WISCA uses a sophisticated Bayesian decision model to combine both local and pooled antimicrobial resistance data. This approach not only evaluates local patterns but can also draw on multi-centre data sets to improve regimen accuracy, even in low-incidence infections like paediatric bloodstream infections (BSIs).</p></li>
</ol></div>
<div class="section">
@@ -587,9 +587,9 @@ Adhering to previously described approaches (see Source) and especially the Baye
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #949494;"># Type: WISCA with 95% CI</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> `Syndromic Group` `Piperacillin/tazobactam` Piperacillin/tazobactam + Gentam…¹</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #949494; font-style: italic;">&lt;chr&gt;</span> <span style="color: #949494; font-style: italic;">&lt;chr&gt;</span> <span style="color: #949494; font-style: italic;">&lt;chr&gt;</span> </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">1</span> Clinical 73.4% (67.6-78.6%) 92.4% (90.6-93.7%) </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">2</span> ICU 57.4% (49.7-65.6%) 85% (82.1-87.6%) </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">3</span> Outpatient 56.9% (46.9-66.7%) 74.4% (69-79.7%) </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">1</span> Clinical 73.5% (68.1-78.6%) 92.3% (90.8-93.8%) </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">2</span> ICU 57.3% (49.8-64.9%) 84.8% (82-87.7%) </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">3</span> Outpatient 56.8% (47-67%) 74.4% (68.6-79.7%) </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #949494;"># abbreviated name: ¹​`Piperacillin/tazobactam + Gentamicin`</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #949494;"># 1 more variable: `Piperacillin/tazobactam + Tobramycin` &lt;chr&gt;</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #949494;"># Use `ggplot2::autoplot()` or base R `plot()` to create a plot of this antibiogram,</span></span>
@@ -614,9 +614,9 @@ Adhering to previously described approaches (see Source) and especially the Baye
<span class="r-out co"><span class="r-pr">#&gt;</span> </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> |Syndromic Group |Piperacillin/tazobactam |</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> |:---------------|:-----------------------|</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> |Clinical |73.6% (68.4-79%) |</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> |ICU |57.4% (49.7-65.4%) |</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> |Outpatient |57% (47.2-66.7%) |</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> |Clinical |73.6% (68.5-78.7%) |</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> |ICU |57.4% (49.3-65.8%) |</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> |Outpatient |57% (47.1-67.3%) |</span>
<span class="r-in"><span></span></span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="co"># Generate plots with ggplot2 or base R --------------------------------</span></span></span>

View File

@@ -427,9 +427,9 @@ pathogen, but rather by syndrome.
WISCA uses a sophisticated Bayesian decision model to combine both
local and pooled antimicrobial resistance data. This approach not
only evaluates local patterns but can also draw on multi-centre
datasets to improve regimen accuracy, even in low-incidence
infections like paediatric bloodstream infections (BSIs).
only evaluates local patterns but can also draw on multi-centre data
sets to improve regimen accuracy, even in low-incidence infections
like paediatric bloodstream infections (BSIs).
### Grouped tibbles
@@ -777,9 +777,9 @@ antibiogram(example_isolates,
#> # Type: WISCA with 95% CI
#> `Syndromic Group` `Piperacillin/tazobactam` Piperacillin/tazobactam + Gentam…¹
#> <chr> <chr> <chr>
#> 1 Clinical 73.4% (67.6-78.6%) 92.4% (90.6-93.7%)
#> 2 ICU 57.4% (49.7-65.6%) 85% (82.1-87.6%)
#> 3 Outpatient 56.9% (46.9-66.7%) 74.4% (69-79.7%)
#> 1 Clinical 73.5% (68.1-78.6%) 92.3% (90.8-93.8%)
#> 2 ICU 57.3% (49.8-64.9%) 84.8% (82-87.7%)
#> 3 Outpatient 56.8% (47-67%) 74.4% (68.6-79.7%)
#> # abbreviated name: ¹​`Piperacillin/tazobactam + Gentamicin`
#> # 1 more variable: `Piperacillin/tazobactam + Tobramycin` <chr>
#> # Use `ggplot2::autoplot()` or base R `plot()` to create a plot of this antibiogram,
@@ -804,9 +804,9 @@ if (requireNamespace("knitr")) {
#>
#> |Syndromic Group |Piperacillin/tazobactam |
#> |:---------------|:-----------------------|
#> |Clinical |73.6% (68.4-79%) |
#> |ICU |57.4% (49.7-65.4%) |
#> |Outpatient |57% (47.2-66.7%) |
#> |Clinical |73.6% (68.5-78.7%) |
#> |ICU |57.4% (49.3-65.8%) |
#> |Outpatient |57% (47.1-67.3%) |
# Generate plots with ggplot2 or base R --------------------------------

View File

@@ -17,7 +17,7 @@ my_data_with_all_these_columns %&amp;gt;%
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
@@ -670,6 +670,9 @@ my_data_with_all_these_columns %&amp;gt;%
<span class="r-msg co"><span class="r-pr">#&gt;</span> Loading required package: data.table</span>
<span class="r-msg co"><span class="r-pr">#&gt;</span> </span>
<span class="r-msg co"><span class="r-pr">#&gt;</span> Attaching package: data.table</span>
<span class="r-msg co"><span class="r-pr">#&gt;</span> The following object is masked from package:purrr:</span>
<span class="r-msg co"><span class="r-pr">#&gt;</span> </span>
<span class="r-msg co"><span class="r-pr">#&gt;</span> transpose</span>
<span class="r-msg co"><span class="r-pr">#&gt;</span> The following objects are masked from package:dplyr:</span>
<span class="r-msg co"><span class="r-pr">#&gt;</span> </span>
<span class="r-msg co"><span class="r-pr">#&gt;</span> between, first, last</span>

View File

@@ -1013,6 +1013,9 @@ if (require("data.table")) {
#> Loading required package: data.table
#>
#> Attaching package: data.table
#> The following object is masked from package:purrr:
#>
#> transpose
#> The following objects are masked from package:dplyr:
#>
#> between, first, last

View File

@@ -9,7 +9,7 @@ The antibiotics data set has been renamed to antimicrobials. The old name will b
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">

View File

@@ -7,7 +7,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">

View File

@@ -7,7 +7,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">

View File

@@ -7,7 +7,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">

View File

@@ -7,7 +7,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">

View File

@@ -7,7 +7,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">

View File

@@ -9,7 +9,7 @@ Breakpoints are currently implemented from EUCAST 2011-2025 and CLSI 2011-2025,
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
@@ -416,10 +416,10 @@ Breakpoints are currently implemented from EUCAST 2011-2025 and CLSI 2011-2025,
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #949494;"># A tibble: 4 × 18</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> datetime index method ab_given mo_given host_given input_given</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #949494; font-style: italic;">&lt;dttm&gt;</span> <span style="color: #949494; font-style: italic;">&lt;int&gt;</span> <span style="color: #949494; font-style: italic;">&lt;chr&gt;</span> <span style="color: #949494; font-style: italic;">&lt;chr&gt;</span> <span style="color: #949494; font-style: italic;">&lt;chr&gt;</span> <span style="color: #949494; font-style: italic;">&lt;chr&gt;</span> <span style="color: #949494; font-style: italic;">&lt;chr&gt;</span> </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">1</span> 2025-12-15 <span style="color: #949494;">12:29:02</span> 1 MIC amoxicillin Escherich… human 8 </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">2</span> 2025-12-15 <span style="color: #949494;">12:29:02</span> 1 MIC cipro Escherich… human 0.256 </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">3</span> 2025-12-15 <span style="color: #949494;">12:29:02</span> 1 DISK tobra Escherich… human 16 </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">4</span> 2025-12-15 <span style="color: #949494;">12:29:03</span> 1 DISK genta Escherich… human 18 </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">1</span> 2025-12-22 <span style="color: #949494;">08:45:24</span> 1 MIC amoxicillin Escherich… human 8 </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">2</span> 2025-12-22 <span style="color: #949494;">08:45:24</span> 1 MIC cipro Escherich… human 0.256 </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">3</span> 2025-12-22 <span style="color: #949494;">08:45:24</span> 1 DISK tobra Escherich… human 16 </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">4</span> 2025-12-22 <span style="color: #949494;">08:45:24</span> 1 DISK genta Escherich… human 18 </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #949494;"># 11 more variables: ab &lt;ab&gt;, mo &lt;mo&gt;, host &lt;chr&gt;, input &lt;chr&gt;,</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #949494;"># outcome &lt;sir&gt;, notes &lt;chr&gt;, guideline &lt;chr&gt;, ref_table &lt;chr&gt;, uti &lt;lgl&gt;,</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #949494;"># breakpoint_S_R &lt;chr&gt;, site &lt;chr&gt;</span></span>
@@ -620,12 +620,12 @@ Breakpoints are currently implemented from EUCAST 2011-2025 and CLSI 2011-2025,
<span class="r-in"><span><span class="co"># For CLEANING existing SIR values -------------------------------------</span></span></span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="fu">as.sir</span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"S"</span>, <span class="st">"SDD"</span>, <span class="st">"I"</span>, <span class="st">"R"</span>, <span class="st">"NI"</span>, <span class="st">"A"</span>, <span class="st">"B"</span>, <span class="st">"C"</span><span class="op">)</span><span class="op">)</span></span></span>
<span class="r-wrn co"><span class="r-pr">#&gt;</span> <span class="warning">Warning: </span>in <span style="background-color: #444444;">`as.sir()`</span>: 3 results in index '20' truncated (38%) that were invalid</span>
<span class="r-wrn co"><span class="r-pr">#&gt;</span> <span class="warning">Warning: </span>in <span style="background-color: #444444;">`as.sir()`</span>: 3 results in index '21' truncated (38%) that were invalid</span>
<span class="r-wrn co"><span class="r-pr">#&gt;</span> antimicrobial interpretations: "A", "B", and "C"</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> Class 'sir'</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [1] S SDD I R NI &lt;NA&gt; &lt;NA&gt; &lt;NA&gt;</span>
<span class="r-in"><span><span class="fu">as.sir</span><span class="op">(</span><span class="st">"&lt;= 0.002; S"</span><span class="op">)</span> <span class="co"># will return "S"</span></span></span>
<span class="r-wrn co"><span class="r-pr">#&gt;</span> <span class="warning">Warning: </span>in <span style="background-color: #444444;">`as.sir()`</span>: 1 result in index '20' truncated (100%) that were invalid</span>
<span class="r-wrn co"><span class="r-pr">#&gt;</span> <span class="warning">Warning: </span>in <span style="background-color: #444444;">`as.sir()`</span>: 1 result in index '21' truncated (100%) that were invalid</span>
<span class="r-wrn co"><span class="r-pr">#&gt;</span> antimicrobial interpretations: "&lt;= 0.002; S"</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> Class 'sir'</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [1] &lt;NA&gt;</span>

View File

@@ -648,10 +648,10 @@ sir_interpretation_history()
#> # A tibble: 4 × 18
#> datetime index method ab_given mo_given host_given input_given
#> <dttm> <int> <chr> <chr> <chr> <chr> <chr>
#> 1 2025-12-15 12:29:02 1 MIC amoxicillin Escherich… human 8
#> 2 2025-12-15 12:29:02 1 MIC cipro Escherich… human 0.256
#> 3 2025-12-15 12:29:02 1 DISK tobra Escherich… human 16
#> 4 2025-12-15 12:29:03 1 DISK genta Escherich… human 18
#> 1 2025-12-22 08:45:24 1 MIC amoxicillin Escherich… human 8
#> 2 2025-12-22 08:45:24 1 MIC cipro Escherich… human 0.256
#> 3 2025-12-22 08:45:24 1 DISK tobra Escherich… human 16
#> 4 2025-12-22 08:45:24 1 DISK genta Escherich… human 18
#> # 11 more variables: ab <ab>, mo <mo>, host <chr>, input <chr>,
#> # outcome <sir>, notes <chr>, guideline <chr>, ref_table <chr>, uti <lgl>,
#> # breakpoint_S_R <chr>, site <chr>
@@ -852,12 +852,12 @@ as.sir(
# For CLEANING existing SIR values -------------------------------------
as.sir(c("S", "SDD", "I", "R", "NI", "A", "B", "C"))
#> Warning: in `as.sir()`: 3 results in index '20' truncated (38%) that were invalid
#> Warning: in `as.sir()`: 3 results in index '21' truncated (38%) that were invalid
#> antimicrobial interpretations: "A", "B", and "C"
#> Class 'sir'
#> [1] S SDD I R NI <NA> <NA> <NA>
as.sir("<= 0.002; S") # will return "S"
#> Warning: in `as.sir()`: 1 result in index '20' truncated (100%) that were invalid
#> Warning: in `as.sir()`: 1 result in index '21' truncated (100%) that were invalid
#> antimicrobial interpretations: "<= 0.002; S"
#> Class 'sir'
#> [1] <NA>

View File

@@ -7,7 +7,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">

View File

@@ -7,7 +7,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">

View File

@@ -7,7 +7,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">

View File

@@ -7,7 +7,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">

View File

@@ -7,7 +7,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">

View File

@@ -1,12 +1,12 @@
<!DOCTYPE html>
<!-- Generated by pkgdown: do not edit by hand --><html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"><title>Data Set with Clinical Breakpoints for SIR Interpretation — clinical_breakpoints • AMR (for R)</title><!-- favicons --><link rel="icon" type="image/png" sizes="96x96" href="../favicon-96x96.png"><link rel="icon" type="”image/svg+xml”" href="../favicon.svg"><link rel="apple-touch-icon" sizes="180x180" href="../apple-touch-icon.png"><link rel="icon" sizes="any" href="../favicon.ico"><link rel="manifest" href="../site.webmanifest"><script src="../deps/jquery-3.6.0/jquery-3.6.0.min.js"></script><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"><link href="../deps/bootstrap-5.3.1/bootstrap.min.css" rel="stylesheet"><script src="../deps/bootstrap-5.3.1/bootstrap.bundle.min.js"></script><link href="../deps/Lato-0.4.10/font.css" rel="stylesheet"><link href="../deps/Fira_Code-0.4.10/font.css" rel="stylesheet"><link href="../deps/font-awesome-6.5.2/css/all.min.css" rel="stylesheet"><link href="../deps/font-awesome-6.5.2/css/v4-shims.min.css" rel="stylesheet"><script src="../deps/headroom-0.11.0/headroom.min.js"></script><script src="../deps/headroom-0.11.0/jQuery.headroom.min.js"></script><script src="../deps/bootstrap-toc-1.0.1/bootstrap-toc.min.js"></script><script src="../deps/clipboard.js-2.0.11/clipboard.min.js"></script><script src="../deps/search-1.0.0/autocomplete.jquery.min.js"></script><script src="../deps/search-1.0.0/fuse.min.js"></script><script src="../deps/search-1.0.0/mark.min.js"></script><!-- pkgdown --><script src="../pkgdown.js"></script><link href="../extra.css" rel="stylesheet"><script src="../extra.js"></script><meta property="og:title" content="Data Set with Clinical Breakpoints for SIR Interpretation — clinical_breakpoints"><meta name="description" content="Data set containing clinical breakpoints to interpret MIC and disk diffusion to SIR values, according to international guidelines. This dataset contain breakpoints for humans, 7 different animal groups, and ECOFFs.
<!-- Generated by pkgdown: do not edit by hand --><html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"><title>Data Set with Clinical Breakpoints for SIR Interpretation — clinical_breakpoints • AMR (for R)</title><!-- favicons --><link rel="icon" type="image/png" sizes="96x96" href="../favicon-96x96.png"><link rel="icon" type="”image/svg+xml”" href="../favicon.svg"><link rel="apple-touch-icon" sizes="180x180" href="../apple-touch-icon.png"><link rel="icon" sizes="any" href="../favicon.ico"><link rel="manifest" href="../site.webmanifest"><script src="../deps/jquery-3.6.0/jquery-3.6.0.min.js"></script><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"><link href="../deps/bootstrap-5.3.1/bootstrap.min.css" rel="stylesheet"><script src="../deps/bootstrap-5.3.1/bootstrap.bundle.min.js"></script><link href="../deps/Lato-0.4.10/font.css" rel="stylesheet"><link href="../deps/Fira_Code-0.4.10/font.css" rel="stylesheet"><link href="../deps/font-awesome-6.5.2/css/all.min.css" rel="stylesheet"><link href="../deps/font-awesome-6.5.2/css/v4-shims.min.css" rel="stylesheet"><script src="../deps/headroom-0.11.0/headroom.min.js"></script><script src="../deps/headroom-0.11.0/jQuery.headroom.min.js"></script><script src="../deps/bootstrap-toc-1.0.1/bootstrap-toc.min.js"></script><script src="../deps/clipboard.js-2.0.11/clipboard.min.js"></script><script src="../deps/search-1.0.0/autocomplete.jquery.min.js"></script><script src="../deps/search-1.0.0/fuse.min.js"></script><script src="../deps/search-1.0.0/mark.min.js"></script><!-- pkgdown --><script src="../pkgdown.js"></script><link href="../extra.css" rel="stylesheet"><script src="../extra.js"></script><meta property="og:title" content="Data Set with Clinical Breakpoints for SIR Interpretation — clinical_breakpoints"><meta name="description" content="Data set containing clinical breakpoints to interpret MIC and disk diffusion to SIR values, according to international guidelines. This data set contains breakpoints for humans, 7 different animal groups, and ECOFFs.
These breakpoints are currently implemented:
For clinical microbiology: EUCAST 2011-2025 and CLSI 2011-2025;
For veterinary microbiology: EUCAST 2021-2025 and CLSI 2019-2025;
For ECOFFs (Epidemiological Cut-off Values): EUCAST 2020-2025 and CLSI 2022-2025.
Use as.sir() to transform MICs or disks measurements to SIR values."><meta property="og:description" content="Data set containing clinical breakpoints to interpret MIC and disk diffusion to SIR values, according to international guidelines. This dataset contain breakpoints for humans, 7 different animal groups, and ECOFFs.
Use as.sir() to transform MICs or disks measurements to SIR values."><meta property="og:description" content="Data set containing clinical breakpoints to interpret MIC and disk diffusion to SIR values, according to international guidelines. This data set contains breakpoints for humans, 7 different animal groups, and ECOFFs.
These breakpoints are currently implemented:
For clinical microbiology: EUCAST 2011-2025 and CLSI 2011-2025;
For veterinary microbiology: EUCAST 2021-2025 and CLSI 2019-2025;
@@ -21,7 +21,7 @@ Use as.sir() to transform MICs or disks measurements to SIR values."><meta prope
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
@@ -64,7 +64,7 @@ Use as.sir() to transform MICs or disks measurements to SIR values."><meta prope
</div>
<div class="ref-description section level2">
<p>Data set containing clinical breakpoints to interpret MIC and disk diffusion to SIR values, according to international guidelines. This dataset contain breakpoints for humans, 7 different animal groups, and ECOFFs.</p>
<p>Data set containing clinical breakpoints to interpret MIC and disk diffusion to SIR values, according to international guidelines. This data set contains breakpoints for humans, 7 different animal groups, and ECOFFs.</p>
<p>These breakpoints are currently implemented:</p><ul><li><p>For <strong>clinical microbiology</strong>: EUCAST 2011-2025 and CLSI 2011-2025;</p></li>
<li><p>For <strong>veterinary microbiology</strong>: EUCAST 2021-2025 and CLSI 2019-2025;</p></li>
<li><p>For <strong>ECOFFs</strong> (Epidemiological Cut-off Values): EUCAST 2020-2025 and CLSI 2022-2025.</p></li>

View File

@@ -2,7 +2,7 @@
Data set containing clinical breakpoints to interpret MIC and disk
diffusion to SIR values, according to international guidelines. This
dataset contain breakpoints for humans, 7 different animal groups, and
data set contains breakpoints for humans, 7 different animal groups, and
ECOFFs.
These breakpoints are currently implemented:

View File

@@ -9,7 +9,7 @@ count_resistant() should be used to count resistant isolates, count_susceptible(
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">

View File

@@ -7,7 +7,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">

View File

@@ -7,7 +7,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">

View File

@@ -7,7 +7,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">

View File

@@ -0,0 +1,112 @@
<!DOCTYPE html>
<!-- Generated by pkgdown: do not edit by hand --><html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"><title>Data Set with 500 ESBL Isolates — esbl_isolates • AMR (for R)</title><!-- favicons --><link rel="icon" type="image/png" sizes="96x96" href="../favicon-96x96.png"><link rel="icon" type="”image/svg+xml”" href="../favicon.svg"><link rel="apple-touch-icon" sizes="180x180" href="../apple-touch-icon.png"><link rel="icon" sizes="any" href="../favicon.ico"><link rel="manifest" href="../site.webmanifest"><script src="../deps/jquery-3.6.0/jquery-3.6.0.min.js"></script><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"><link href="../deps/bootstrap-5.3.1/bootstrap.min.css" rel="stylesheet"><script src="../deps/bootstrap-5.3.1/bootstrap.bundle.min.js"></script><link href="../deps/Lato-0.4.10/font.css" rel="stylesheet"><link href="../deps/Fira_Code-0.4.10/font.css" rel="stylesheet"><link href="../deps/font-awesome-6.5.2/css/all.min.css" rel="stylesheet"><link href="../deps/font-awesome-6.5.2/css/v4-shims.min.css" rel="stylesheet"><script src="../deps/headroom-0.11.0/headroom.min.js"></script><script src="../deps/headroom-0.11.0/jQuery.headroom.min.js"></script><script src="../deps/bootstrap-toc-1.0.1/bootstrap-toc.min.js"></script><script src="../deps/clipboard.js-2.0.11/clipboard.min.js"></script><script src="../deps/search-1.0.0/autocomplete.jquery.min.js"></script><script src="../deps/search-1.0.0/fuse.min.js"></script><script src="../deps/search-1.0.0/mark.min.js"></script><!-- pkgdown --><script src="../pkgdown.js"></script><link href="../extra.css" rel="stylesheet"><script src="../extra.js"></script><meta property="og:title" content="Data Set with 500 ESBL Isolates — esbl_isolates"><meta name="description" content="A data set containing 500 microbial isolates with MIC values of common antibiotics and a binary esbl column for extended-spectrum beta-lactamase (ESBL) production. This data set contains randomised fictitious data but reflects reality and can be used to practise AMR-related machine learning, e.g., classification modelling with tidymodels."><meta property="og:description" content="A data set containing 500 microbial isolates with MIC values of common antibiotics and a binary esbl column for extended-spectrum beta-lactamase (ESBL) production. This data set contains randomised fictitious data but reflects reality and can be used to practise AMR-related machine learning, e.g., classification modelling with tidymodels."><meta property="og:image" content="https://amr-for-r.org/logo.svg"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/katex.min.css" integrity="sha384-nB0miv6/jRmo5UMMR1wu3Gz6NLsoTkbqJghGIsx//Rlm+ZU03BU6SQNC66uf4l5+" crossorigin="anonymous"><script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/katex.min.js" integrity="sha384-7zkQWkzuo3B5mTepMUcHkMB5jZaolc2xDwL6VFqjFALcbeS9Ggm/Yr2r3Dy4lfFg" crossorigin="anonymous"></script><script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/contrib/auto-render.min.js" integrity="sha384-43gviWU0YVjaDtb/GhzOouOXtZMP/7XUzwPTstBeZFe/+rCMvRwr4yROQP43s0Xk" crossorigin="anonymous" onload="renderMathInElement(document.body);"></script></head><body>
<a href="#main" class="visually-hidden-focusable">Skip to contents</a>
<nav class="navbar navbar-expand-lg fixed-top bg-primary" data-bs-theme="dark" aria-label="Site navigation"><div class="container">
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div id="navbar" class="collapse navbar-collapse ms-3">
<ul class="navbar-nav me-auto"><li class="nav-item dropdown">
<button class="nav-link dropdown-toggle" type="button" id="dropdown-how-to" data-bs-toggle="dropdown" aria-expanded="false" aria-haspopup="true"><span class="fa fa-question-circle"></span> How to</button>
<ul class="dropdown-menu" aria-labelledby="dropdown-how-to"><li><a class="dropdown-item" href="../articles/AMR.html"><span class="fa fa-directions"></span> Conduct AMR Analysis</a></li>
<li><a class="dropdown-item" href="../reference/antibiogram.html"><span class="fa fa-file-prescription"></span> Generate Antibiogram (Trad./Syndromic/WISCA)</a></li>
<li><a class="dropdown-item" href="../articles/AMR_with_tidymodels.html"><span class="fa fa-square-root-variable"></span> Use AMR for Predictive Modelling (tidymodels)</a></li>
<li><a class="dropdown-item" href="../articles/datasets.html"><span class="fa fa-database"></span> Download Data Sets for Own Use</a></li>
<li><a class="dropdown-item" href="../reference/AMR-options.html"><span class="fa fa-gear"></span> Set User- Or Team-specific Package Settings</a></li>
<li><a class="dropdown-item" href="../articles/PCA.html"><span class="fa fa-compress"></span> Conduct Principal Component Analysis for AMR</a></li>
<li><a class="dropdown-item" href="../reference/mdro.html"><span class="fa fa-skull-crossbones"></span> Determine Multi-Drug Resistance (MDR)</a></li>
<li><a class="dropdown-item" href="../articles/WHONET.html"><span class="fa fa-globe-americas"></span> Work with WHONET Data</a></li>
<li><a class="dropdown-item" href="../articles/EUCAST.html"><span class="fa fa-exchange-alt"></span> Apply EUCAST Rules</a></li>
<li><a class="dropdown-item" href="../reference/mo_property.html"><span class="fa fa-bug"></span> Get Taxonomy of a Microorganism</a></li>
<li><a class="dropdown-item" href="../reference/ab_property.html"><span class="fa fa-capsules"></span> Get Properties of an Antibiotic Drug</a></li>
<li><a class="dropdown-item" href="../reference/av_property.html"><span class="fa fa-capsules"></span> Get Properties of an Antiviral Drug</a></li>
</ul></li>
<li class="nav-item"><a class="nav-link" href="../articles/AMR_for_Python.html"><span class="fa fab fa-python"></span> AMR for Python</a></li>
<li class="active nav-item"><a class="nav-link" href="../reference/index.html"><span class="fa fa-book-open"></span> Manual</a></li>
<li class="nav-item"><a class="nav-link" href="../authors.html"><span class="fa fa-users"></span> Authors</a></li>
</ul><ul class="navbar-nav"><li class="nav-item"><form class="form-inline" role="search">
<input class="form-control" type="search" name="search-input" id="search-input" autocomplete="off" aria-label="Search site" placeholder="Search for" data-search-index="../search.json"></form></li>
<li class="nav-item"><a class="nav-link" href="../news/index.html"><span class="fa fa-newspaper"></span> Changelog</a></li>
<li class="nav-item"><a class="external-link nav-link" href="https://github.com/msberends/AMR"><span class="fa fa-github"></span> Source Code</a></li>
</ul></div>
</div>
</nav><div class="container template-reference-topic">
<div class="row">
<main id="main" class="col-md-9"><div class="page-header">
<img src="../logo.svg" class="logo" alt=""><h1>Data Set with 500 ESBL Isolates</h1>
<small class="dont-index">Source: <a href="https://github.com/msberends/AMR/blob/main/R/data.R" class="external-link"><code>R/data.R</code></a></small>
<div class="d-none name"><code>esbl_isolates.Rd</code></div>
</div>
<div class="ref-description section level2">
<p>A data set containing 500 microbial isolates with MIC values of common antibiotics and a binary <code>esbl</code> column for extended-spectrum beta-lactamase (ESBL) production. This data set contains randomised fictitious data but reflects reality and can be used to practise AMR-related machine learning, e.g., classification modelling with <a href="https://amr-for-r.org/articles/AMR_with_tidymodels.html">tidymodels</a>.</p>
</div>
<div class="section level2">
<h2 id="ref-usage">Usage<a class="anchor" aria-label="anchor" href="#ref-usage"></a></h2>
<div class="sourceCode"><pre class="sourceCode r"><code><span><span class="va">esbl_isolates</span></span></code></pre></div>
</div>
<div class="section level2">
<h2 id="format">Format<a class="anchor" aria-label="anchor" href="#format"></a></h2>
<p>A <a href="https://tibble.tidyverse.org/reference/tibble.html" class="external-link">tibble</a> with 500 observations and 19 variables:</p><ul><li><p><code>esbl</code><br> Logical indicator if the isolate is ESBL-producing</p></li>
<li><p><code>genus</code><br> Genus of the microorganism</p></li>
<li><p><code>AMC:COL</code><br> MIC values for 17 antimicrobial agents, transformed to class <code><a href="as.mic.html">mic</a></code> (see <code><a href="as.mic.html">as.mic()</a></code>)</p></li>
</ul></div>
<div class="section level2">
<h2 id="details">Details<a class="anchor" aria-label="anchor" href="#details"></a></h2>
<p>See our <a href="amr-tidymodels.html">tidymodels integration</a> for an example using this data set.</p>
</div>
<div class="section level2">
<h2 id="ref-examples">Examples<a class="anchor" aria-label="anchor" href="#ref-examples"></a></h2>
<div class="sourceCode"><pre class="sourceCode r"><code><span class="r-in"><span><span class="va">esbl_isolates</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #949494;"># A tibble: 500 × 19</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> esbl genus AMC AMP TZP CXM FOX CTX CAZ GEN TOB TMP SXT</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #949494; font-style: italic;">&lt;lgl&gt;</span> <span style="color: #949494; font-style: italic;">&lt;chr&gt;</span> <span style="color: #949494; font-style: italic;">&lt;mic&gt;</span> <span style="color: #949494; font-style: italic;">&lt;mic&gt;</span> <span style="color: #949494; font-style: italic;">&lt;mic&gt;</span> <span style="color: #949494; font-style: italic;">&lt;mic&gt;</span> <span style="color: #949494; font-style: italic;">&lt;mic&gt;</span> <span style="color: #949494; font-style: italic;">&lt;mic&gt;</span> <span style="color: #949494; font-style: italic;">&lt;mic&gt;</span> <span style="color: #949494; font-style: italic;">&lt;mic&gt;</span> <span style="color: #949494; font-style: italic;">&lt;mic&gt;</span> <span style="color: #949494; font-style: italic;">&lt;mic&gt;</span> <span style="color: #949494; font-style: italic;">&lt;mic&gt;</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 1</span> FALSE Esch… 32 32 4 64 64 8<span style="color: #555555;">.00</span> 8<span style="color: #555555;">.00</span> 1 1 16<span style="color: #555555;">.0</span> 20</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 2</span> FALSE Esch… 32 32 4 64 64 4<span style="color: #555555;">.00</span> 8<span style="color: #555555;">.00</span> 1 1 16<span style="color: #555555;">.0</span> 320</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 3</span> FALSE Esch… 4 2 64 8 4 8<span style="color: #555555;">.00</span> 0.12 16 16 0.5 20</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 4</span> FALSE Kleb… 32 32 16 64 64 8<span style="color: #555555;">.00</span> 8<span style="color: #555555;">.00</span> 1 1 0.5 20</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 5</span> FALSE Esch… 32 32 4 4 4 0.25 2<span style="color: #555555;">.00</span> 1 1 16<span style="color: #555555;">.0</span> 320</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 6</span> FALSE Citr… 32 32 16 64 64 64<span style="color: #555555;">.00</span> 32<span style="color: #555555;">.00</span> 1 1 0.5 20</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 7</span> FALSE Morg… 32 32 4 64 64 16<span style="color: #555555;">.00</span> 2<span style="color: #555555;">.00</span> 1 1 0.5 20</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 8</span> FALSE Prot… 16 32 4 1 4 8<span style="color: #555555;">.00</span> 0.12 1 1 16<span style="color: #555555;">.0</span> 320</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 9</span> FALSE Ente… 32 32 8 64 64 32<span style="color: #555555;">.00</span> 4<span style="color: #555555;">.00</span> 1 1 0.5 20</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">10</span> FALSE Citr… 32 32 32 64 64 8<span style="color: #555555;">.00</span> 64<span style="color: #555555;">.00</span> 1 1 16<span style="color: #555555;">.0</span> 320</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #949494;"># 490 more rows</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #949494;"># 6 more variables: NIT &lt;mic&gt;, FOS &lt;mic&gt;, CIP &lt;mic&gt;, IPM &lt;mic&gt;, MEM &lt;mic&gt;,</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #949494;"># COL &lt;mic&gt;</span></span>
</code></pre></div>
</div>
</main><aside class="col-md-3"><nav id="toc" aria-label="Table of contents"><h2>On this page</h2>
</nav></aside></div>
<footer><div class="pkgdown-footer-left">
<p><code>AMR</code> (for R). Free and open-source, licenced under the <a target="_blank" href="https://github.com/msberends/AMR/blob/main/LICENSE" class="external-link">GNU General Public License version 2.0 (GPL-2)</a>.<br>Developed at the <a target="_blank" href="https://www.rug.nl" class="external-link">University of Groningen</a> and <a target="_blank" href="https://www.umcg.nl" class="external-link">University Medical Center Groningen</a> in The Netherlands.</p>
</div>
<div class="pkgdown-footer-right">
<p><a target="_blank" href="https://www.rug.nl" class="external-link"><img src="https://amr-for-r.org/logo_rug.svg" style="max-width: 150px;"></a><a target="_blank" href="https://www.umcg.nl" class="external-link"><img src="https://amr-for-r.org/logo_umcg.svg" style="max-width: 150px;"></a></p>
</div>
</footer></div>
</body></html>

View File

@@ -0,0 +1,58 @@
# Data Set with 500 ESBL Isolates
A data set containing 500 microbial isolates with MIC values of common
antibiotics and a binary `esbl` column for extended-spectrum
beta-lactamase (ESBL) production. This data set contains randomised
fictitious data but reflects reality and can be used to practise
AMR-related machine learning, e.g., classification modelling with
[tidymodels](https://amr-for-r.org/articles/AMR_with_tidymodels.html).
## Usage
``` r
esbl_isolates
```
## Format
A [tibble](https://tibble.tidyverse.org/reference/tibble.html) with 500
observations and 19 variables:
- `esbl`
Logical indicator if the isolate is ESBL-producing
- `genus`
Genus of the microorganism
- `AMC:COL`
MIC values for 17 antimicrobial agents, transformed to class
[`mic`](https://amr-for-r.org/reference/as.mic.md) (see
[`as.mic()`](https://amr-for-r.org/reference/as.mic.md))
## Details
See our [tidymodels
integration](https://amr-for-r.org/reference/amr-tidymodels.md) for an
example using this data set.
## Examples
``` r
esbl_isolates
#> # A tibble: 500 × 19
#> esbl genus AMC AMP TZP CXM FOX CTX CAZ GEN TOB TMP SXT
#> <lgl> <chr> <mic> <mic> <mic> <mic> <mic> <mic> <mic> <mic> <mic> <mic> <mic>
#> 1 FALSE Esch… 32 32 4 64 64 8.00 8.00 1 1 16.0 20
#> 2 FALSE Esch… 32 32 4 64 64 4.00 8.00 1 1 16.0 320
#> 3 FALSE Esch… 4 2 64 8 4 8.00 0.12 16 16 0.5 20
#> 4 FALSE Kleb… 32 32 16 64 64 8.00 8.00 1 1 0.5 20
#> 5 FALSE Esch… 32 32 4 4 4 0.25 2.00 1 1 16.0 320
#> 6 FALSE Citr… 32 32 16 64 64 64.00 32.00 1 1 0.5 20
#> 7 FALSE Morg… 32 32 4 64 64 16.00 2.00 1 1 0.5 20
#> 8 FALSE Prot… 16 32 4 1 4 8.00 0.12 1 1 16.0 320
#> 9 FALSE Ente… 32 32 8 64 64 32.00 4.00 1 1 0.5 20
#> 10 FALSE Citr… 32 32 32 64 64 8.00 64.00 1 1 16.0 320
#> # 490 more rows
#> # 6 more variables: NIT <mic>, FOS <mic>, CIP <mic>, IPM <mic>, MEM <mic>,
#> # COL <mic>
```

View File

@@ -9,7 +9,7 @@ To improve the interpretation of the antibiogram before EUCAST rules are applied
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">

View File

@@ -7,7 +7,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">

View File

@@ -7,7 +7,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">

View File

@@ -7,7 +7,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">

View File

@@ -9,7 +9,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">

View File

@@ -7,7 +7,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">

View File

@@ -7,7 +7,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
@@ -154,28 +154,28 @@
<span class="r-in"><span><span class="va">df</span> <span class="op">&lt;-</span> <span class="va">example_isolates</span><span class="op">[</span><span class="fu"><a href="https://rdrr.io/r/base/sample.html" class="external-link">sample</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/seq.html" class="external-link">seq_len</a></span><span class="op">(</span><span class="fl">2000</span><span class="op">)</span>, size <span class="op">=</span> <span class="fl">100</span><span class="op">)</span>, <span class="op">]</span></span></span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="fu">get_episode</span><span class="op">(</span><span class="va">df</span><span class="op">$</span><span class="va">date</span>, episode_days <span class="op">=</span> <span class="fl">60</span><span class="op">)</span> <span class="co"># indices</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [1] 17 19 32 7 48 16 36 11 41 30 43 42 3 37 6 42 16 46 12 6 38 15 31 23 44</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [26] 35 42 21 10 21 18 22 9 29 40 8 22 14 31 47 18 26 28 18 25 20 11 49 8 27</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [51] 50 23 46 3 27 6 31 1 33 10 23 31 11 20 46 13 4 24 4 27 8 48 16 2 20</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [76] 35 31 19 33 34 16 14 33 17 46 24 15 17 7 9 39 14 50 5 12 2 45 35 8 28</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [1] 43 9 7 14 28 40 49 29 19 27 10 44 18 22 42 12 8 36 13 3 46 5 4 35 38</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [26] 16 22 23 16 10 42 13 2 45 18 19 39 32 22 36 40 45 39 40 11 23 25 39 26 23</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [51] 25 12 17 23 30 30 34 16 21 37 40 26 11 7 4 16 43 22 47 37 39 31 25 41 1</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [76] 45 39 23 32 45 20 22 15 14 13 43 9 38 29 6 48 24 21 23 44 19 31 1 3 33</span>
<span class="r-in"><span><span class="fu">is_new_episode</span><span class="op">(</span><span class="va">df</span><span class="op">$</span><span class="va">date</span>, episode_days <span class="op">=</span> <span class="fl">60</span><span class="op">)</span> <span class="co"># TRUE/FALSE</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [13] TRUE TRUE TRUE FALSE FALSE TRUE TRUE FALSE TRUE TRUE TRUE TRUE</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [25] TRUE TRUE FALSE TRUE TRUE FALSE TRUE TRUE TRUE TRUE TRUE TRUE</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [37] FALSE TRUE FALSE TRUE FALSE TRUE TRUE FALSE TRUE TRUE FALSE TRUE</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [49] FALSE TRUE TRUE FALSE FALSE FALSE FALSE FALSE FALSE TRUE TRUE FALSE</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [61] FALSE FALSE FALSE FALSE FALSE TRUE TRUE TRUE FALSE FALSE FALSE FALSE</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [73] FALSE TRUE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [85] FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE TRUE FALSE FALSE</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [97] TRUE FALSE FALSE FALSE</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [13] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [25] TRUE TRUE FALSE TRUE FALSE FALSE FALSE FALSE TRUE TRUE FALSE FALSE</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [37] TRUE TRUE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE TRUE FALSE</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [49] TRUE FALSE FALSE FALSE TRUE FALSE TRUE FALSE TRUE FALSE TRUE TRUE</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [61] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE TRUE</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [73] FALSE TRUE TRUE FALSE FALSE FALSE FALSE FALSE TRUE FALSE TRUE FALSE</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [85] FALSE FALSE FALSE FALSE FALSE TRUE TRUE TRUE FALSE FALSE FALSE FALSE</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [97] FALSE FALSE FALSE TRUE</span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="co"># filter on results from the third 60-day episode only, using base R</span></span></span>
<span class="r-in"><span><span class="va">df</span><span class="op">[</span><span class="fu"><a href="https://rdrr.io/r/base/which.html" class="external-link">which</a></span><span class="op">(</span><span class="fu">get_episode</span><span class="op">(</span><span class="va">df</span><span class="op">$</span><span class="va">date</span>, <span class="fl">60</span><span class="op">)</span> <span class="op">==</span> <span class="fl">3</span><span class="op">)</span>, <span class="op">]</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #949494;"># A tibble: 2 × 46</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> date patient age gender ward mo PEN OXA FLC AMX </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #949494; font-style: italic;">&lt;date&gt;</span> <span style="color: #949494; font-style: italic;">&lt;chr&gt;</span> <span style="color: #949494; font-style: italic;">&lt;dbl&gt;</span> <span style="color: #949494; font-style: italic;">&lt;chr&gt;</span> <span style="color: #949494; font-style: italic;">&lt;chr&gt;</span> <span style="color: #949494; font-style: italic;">&lt;mo&gt;</span> <span style="color: #949494; font-style: italic;">&lt;sir&gt;</span> <span style="color: #949494; font-style: italic;">&lt;sir&gt;</span> <span style="color: #949494; font-style: italic;">&lt;sir&gt;</span> <span style="color: #949494; font-style: italic;">&lt;sir&gt;</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">1</span> 2002-07-23 F35553 51 M ICU <span style="color: #949494;">B_</span>STPHY<span style="color: #949494;">_</span>AURS <span style="color: #080808; background-color: #FF5F5F;"> R </span> <span style="color: #B2B2B2;"> NA</span> <span style="color: #080808; background-color: #5FD7AF;"> S </span> <span style="color: #080808; background-color: #FF5F5F;"> R </span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">2</span> 2002-07-23 F35553 51 M ICU <span style="color: #949494;">B_</span>STPHY<span style="color: #949494;">_</span>AURS <span style="color: #080808; background-color: #FF5F5F;"> R </span> <span style="color: #B2B2B2;"> NA</span> <span style="color: #080808; background-color: #5FD7AF;"> S </span> <span style="color: #080808; background-color: #FF5F5F;"> R </span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> date patient age gender ward mo PEN OXA FLC AMX </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #949494; font-style: italic;">&lt;date&gt;</span> <span style="color: #949494; font-style: italic;">&lt;chr&gt;</span> <span style="color: #949494; font-style: italic;">&lt;dbl&gt;</span> <span style="color: #949494; font-style: italic;">&lt;chr&gt;</span> <span style="color: #949494; font-style: italic;">&lt;chr&gt;</span> <span style="color: #949494; font-style: italic;">&lt;mo&gt;</span> <span style="color: #949494; font-style: italic;">&lt;sir&gt;</span> <span style="color: #949494; font-style: italic;">&lt;sir&gt;</span> <span style="color: #949494; font-style: italic;">&lt;sir&gt;</span> <span style="color: #949494; font-style: italic;">&lt;sir&gt;</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">1</span> 2002-11-04 304347 62 M Clinical <span style="color: #949494;">B_</span>STRPT<span style="color: #949494;">_</span>PNMN <span style="color: #080808; background-color: #5FD7AF;"> S </span> <span style="color: #B2B2B2;"> NA</span> <span style="color: #B2B2B2;"> NA</span> <span style="color: #080808; background-color: #5FD7AF;"> S </span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">2</span> 2002-10-18 E55128 57 F ICU <span style="color: #949494;">B_</span>STPHY<span style="color: #949494;">_</span>AURS <span style="color: #080808; background-color: #FF5F5F;"> R </span> <span style="color: #B2B2B2;"> NA</span> <span style="color: #080808; background-color: #5FD7AF;"> S </span> <span style="color: #080808; background-color: #FF5F5F;"> R </span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #949494;"># 36 more variables: AMC &lt;sir&gt;, AMP &lt;sir&gt;, TZP &lt;sir&gt;, CZO &lt;sir&gt;, FEP &lt;sir&gt;,</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #949494;"># CXM &lt;sir&gt;, FOX &lt;sir&gt;, CTX &lt;sir&gt;, CAZ &lt;sir&gt;, CRO &lt;sir&gt;, GEN &lt;sir&gt;,</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #949494;"># TOB &lt;sir&gt;, AMK &lt;sir&gt;, KAN &lt;sir&gt;, TMP &lt;sir&gt;, SXT &lt;sir&gt;, NIT &lt;sir&gt;,</span></span>
@@ -209,19 +209,19 @@
<span class="r-in"><span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/arrange.html" class="external-link">arrange</a></span><span class="op">(</span><span class="va">patient</span>, <span class="va">condition</span>, <span class="va">date</span><span class="op">)</span></span></span>
<span class="r-in"><span><span class="op">}</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #949494;"># A tibble: 100 × 4</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #949494;"># Groups: patient, condition [95]</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #949494;"># Groups: patient, condition [96]</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> patient date condition new_episode</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #949494; font-style: italic;">&lt;chr&gt;</span> <span style="color: #949494; font-style: italic;">&lt;date&gt;</span> <span style="color: #949494; font-style: italic;">&lt;chr&gt;</span> <span style="color: #949494; font-style: italic;">&lt;lgl&gt;</span> </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 1</span> 011307 2011-09-20 B TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 2</span> 011307 2011-09-20 C TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 3</span> 021368 2016-03-25 A TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 4</span> 060287 2007-03-11 B TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 5</span> 078381 2014-07-17 A TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 6</span> 097186 2015-10-28 B TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 7</span> 0DBB93 2003-10-02 A TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 8</span> 0DBF93 2015-12-03 C TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 9</span> 114570 2003-04-22 A TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">10</span> 141061 2014-10-22 C TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 1</span> 022060 2004-05-04 A TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 2</span> 060287 2007-03-11 A TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 3</span> 0E2483 2007-04-06 C TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 4</span> 101305 2006-12-13 A TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 5</span> 141061 2014-10-22 A TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 6</span> 146F70 2009-08-14 A TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 7</span> 15D386 2004-08-01 B TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 8</span> 187841 2008-04-22 C TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 9</span> 195736 2008-08-29 C TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">10</span> 195736 2008-08-29 C FALSE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #949494;"># 90 more rows</span></span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="kw">if</span> <span class="op">(</span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">require</a></span><span class="op">(</span><span class="st"><a href="https://dplyr.tidyverse.org" class="external-link">"dplyr"</a></span><span class="op">)</span><span class="op">)</span> <span class="op">{</span></span></span>
@@ -235,19 +235,19 @@
<span class="r-in"><span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/arrange.html" class="external-link">arrange</a></span><span class="op">(</span><span class="va">patient</span>, <span class="va">ward</span>, <span class="va">date</span><span class="op">)</span></span></span>
<span class="r-in"><span><span class="op">}</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #949494;"># A tibble: 100 × 5</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #949494;"># Groups: ward, patient [93]</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> ward date patient new_index new_logical</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #949494; font-style: italic;">&lt;chr&gt;</span> <span style="color: #949494; font-style: italic;">&lt;date&gt;</span> <span style="color: #949494; font-style: italic;">&lt;chr&gt;</span> <span style="color: #949494; font-style: italic;">&lt;int&gt;</span> <span style="color: #949494; font-style: italic;">&lt;lgl&gt;</span> </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 1</span> Clinical 2011-09-20 011307 1 TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 2</span> Clinical 2011-09-20 011307 1 FALSE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 3</span> Outpatient 2016-03-25 021368 1 TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 4</span> Clinical 2007-03-11 060287 1 TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 5</span> ICU 2014-07-17 078381 1 TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 6</span> Clinical 2015-10-28 097186 1 TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 7</span> ICU 2003-10-02 0DBB93 1 TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 8</span> ICU 2015-12-03 0DBF93 1 TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 9</span> ICU 2003-04-22 114570 1 TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">10</span> Clinical 2014-10-22 141061 1 TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #949494;"># Groups: ward, patient [91]</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> ward date patient new_index new_logical</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #949494; font-style: italic;">&lt;chr&gt;</span> <span style="color: #949494; font-style: italic;">&lt;date&gt;</span> <span style="color: #949494; font-style: italic;">&lt;chr&gt;</span> <span style="color: #949494; font-style: italic;">&lt;int&gt;</span> <span style="color: #949494; font-style: italic;">&lt;lgl&gt;</span> </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 1</span> ICU 2004-05-04 022060 1 TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 2</span> Clinical 2007-03-11 060287 1 TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 3</span> Clinical 2007-04-06 0E2483 1 TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 4</span> Clinical 2006-12-13 101305 1 TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 5</span> Clinical 2014-10-22 141061 1 TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 6</span> Clinical 2009-08-14 146F70 1 TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 7</span> ICU 2004-08-01 15D386 1 TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 8</span> Clinical 2008-04-22 187841 1 TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 9</span> Clinical 2008-08-29 195736 1 TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">10</span> Clinical 2008-08-29 195736 1 FALSE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #949494;"># 90 more rows</span></span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="kw">if</span> <span class="op">(</span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">require</a></span><span class="op">(</span><span class="st"><a href="https://dplyr.tidyverse.org" class="external-link">"dplyr"</a></span><span class="op">)</span><span class="op">)</span> <span class="op">{</span></span></span>
@@ -263,9 +263,9 @@
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #949494;"># A tibble: 3 × 5</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> ward n_patients n_episodes_365 n_episodes_60 n_episodes_30</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #949494; font-style: italic;">&lt;chr&gt;</span> <span style="color: #949494; font-style: italic;">&lt;int&gt;</span> <span style="color: #949494; font-style: italic;">&lt;int&gt;</span> <span style="color: #949494; font-style: italic;">&lt;int&gt;</span> <span style="color: #949494; font-style: italic;">&lt;int&gt;</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">1</span> Clinical 51 12 33 43</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">2</span> ICU 31 11 26 30</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">3</span> Outpatient 11 8 11 11</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">1</span> Clinical 58 14 38 44</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">2</span> ICU 26 7 20 23</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">3</span> Outpatient 7 4 6 7</span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="co"># grouping on patients and microorganisms leads to the same</span></span></span>
<span class="r-in"><span><span class="co"># results as first_isolate() when using 'episode-based':</span></span></span>
@@ -283,7 +283,7 @@
<span class="r-in"><span></span></span>
<span class="r-in"><span> <span class="fu"><a href="https://rdrr.io/r/base/identical.html" class="external-link">identical</a></span><span class="op">(</span><span class="va">x</span>, <span class="va">y</span><span class="op">)</span></span></span>
<span class="r-in"><span><span class="op">}</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [1] TRUE</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [1] FALSE</span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="co"># but is_new_episode() has a lot more flexibility than first_isolate(),</span></span></span>
<span class="r-in"><span><span class="co"># since you can now group on anything that seems relevant:</span></span></span>
@@ -294,19 +294,19 @@
<span class="r-in"><span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/select.html" class="external-link">select</a></span><span class="op">(</span><span class="fu"><a href="https://dplyr.tidyverse.org/reference/group_data.html" class="external-link">group_vars</a></span><span class="op">(</span><span class="va">.</span><span class="op">)</span>, <span class="va">flag_episode</span><span class="op">)</span></span></span>
<span class="r-in"><span><span class="op">}</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #949494;"># A tibble: 100 × 4</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #949494;"># Groups: patient, mo, ward [95]</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> patient mo ward flag_episode</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #949494; font-style: italic;">&lt;chr&gt;</span> <span style="color: #949494; font-style: italic;">&lt;mo&gt;</span> <span style="color: #949494; font-style: italic;">&lt;chr&gt;</span> <span style="color: #949494; font-style: italic;">&lt;lgl&gt;</span> </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 1</span> 690B42 <span style="color: #949494;">B_</span>ESCHR<span style="color: #949494;">_</span>COLI ICU TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 2</span> 550406 <span style="color: #949494;">B_</span>ESCHR<span style="color: #949494;">_</span>COLI Outpatient TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 3</span> F86227 <span style="color: #949494;">B_</span>STPHY<span style="color: #949494;">_</span>CONS Clinical TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 4</span> 859863 <span style="color: #949494;">B_</span>STPHY<span style="color: #949494;">_</span>EPDR ICU TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 5</span> 987C84 <span style="color: #949494;">B_</span>ESCHR<span style="color: #949494;">_</span>COLI Clinical TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 6</span> E19440 <span style="color: #949494;">B_</span>ESCHR<span style="color: #949494;">_</span>COLI ICU TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 7</span> F42C5F <span style="color: #949494;">B_</span>MRGNL<span style="color: #949494;">_</span>MRGN Clinical TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 8</span> F54261 <span style="color: #949494;">B_</span>STPHY<span style="color: #949494;">_</span>AURS Clinical TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 9</span> 5D1690 <span style="color: #949494;">B_</span>ESCHR<span style="color: #949494;">_</span>COLI Outpatient TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">10</span> 874171 <span style="color: #949494;">B_</span>STPHY<span style="color: #949494;">_</span>CONS Clinical TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #949494;"># Groups: patient, mo, ward [96]</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> patient mo ward flag_episode</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #949494; font-style: italic;">&lt;chr&gt;</span> <span style="color: #949494; font-style: italic;">&lt;mo&gt;</span> <span style="color: #949494; font-style: italic;">&lt;chr&gt;</span> <span style="color: #949494; font-style: italic;">&lt;lgl&gt;</span> </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 1</span> 917895 <span style="color: #949494;">B_</span>STPHY<span style="color: #949494;">_</span>CPTS ICU TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 2</span> 022060 <span style="color: #949494;">B_</span>ENTRBC<span style="color: #949494;">_</span>CLOC ICU TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 3</span> C36883 <span style="color: #949494;">B_</span>ESCHR<span style="color: #949494;">_</span>COLI Clinical TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 4</span> 5DF436 <span style="color: #949494;">B_</span>STPHY<span style="color: #949494;">_</span>AURS ICU TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 5</span> 971739 <span style="color: #949494;">B_</span>STPHY<span style="color: #949494;">_</span>CONS Clinical TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 6</span> 488175 <span style="color: #949494;">B_</span>ESCHR<span style="color: #949494;">_</span>COLI Clinical TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 7</span> 5DB1C8 <span style="color: #949494;">B_</span>STPHY<span style="color: #949494;">_</span>CPTS Clinical TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 8</span> BC9909 <span style="color: #949494;">B_</span>ENTRBC<span style="color: #949494;">_</span>CLOC Clinical TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 9</span> 5B78D5 <span style="color: #949494;">B_</span>STPHY<span style="color: #949494;">_</span>AURS Clinical TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">10</span> 284FFF <span style="color: #949494;">B_</span>STPHY<span style="color: #949494;">_</span>EPDR Clinical TRUE </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #949494;"># 90 more rows</span></span>
<span class="r-in"><span><span class="co"># }</span></span></span>
</code></pre></div>

View File

@@ -178,28 +178,28 @@ x
df <- example_isolates[sample(seq_len(2000), size = 100), ]
get_episode(df$date, episode_days = 60) # indices
#> [1] 17 19 32 7 48 16 36 11 41 30 43 42 3 37 6 42 16 46 12 6 38 15 31 23 44
#> [26] 35 42 21 10 21 18 22 9 29 40 8 22 14 31 47 18 26 28 18 25 20 11 49 8 27
#> [51] 50 23 46 3 27 6 31 1 33 10 23 31 11 20 46 13 4 24 4 27 8 48 16 2 20
#> [76] 35 31 19 33 34 16 14 33 17 46 24 15 17 7 9 39 14 50 5 12 2 45 35 8 28
#> [1] 43 9 7 14 28 40 49 29 19 27 10 44 18 22 42 12 8 36 13 3 46 5 4 35 38
#> [26] 16 22 23 16 10 42 13 2 45 18 19 39 32 22 36 40 45 39 40 11 23 25 39 26 23
#> [51] 25 12 17 23 30 30 34 16 21 37 40 26 11 7 4 16 43 22 47 37 39 31 25 41 1
#> [76] 45 39 23 32 45 20 22 15 14 13 43 9 38 29 6 48 24 21 23 44 19 31 1 3 33
is_new_episode(df$date, episode_days = 60) # TRUE/FALSE
#> [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
#> [13] TRUE TRUE TRUE FALSE FALSE TRUE TRUE FALSE TRUE TRUE TRUE TRUE
#> [25] TRUE TRUE FALSE TRUE TRUE FALSE TRUE TRUE TRUE TRUE TRUE TRUE
#> [37] FALSE TRUE FALSE TRUE FALSE TRUE TRUE FALSE TRUE TRUE FALSE TRUE
#> [49] FALSE TRUE TRUE FALSE FALSE FALSE FALSE FALSE FALSE TRUE TRUE FALSE
#> [61] FALSE FALSE FALSE FALSE FALSE TRUE TRUE TRUE FALSE FALSE FALSE FALSE
#> [73] FALSE TRUE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE
#> [85] FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE TRUE FALSE FALSE
#> [97] TRUE FALSE FALSE FALSE
#> [13] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
#> [25] TRUE TRUE FALSE TRUE FALSE FALSE FALSE FALSE TRUE TRUE FALSE FALSE
#> [37] TRUE TRUE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE TRUE FALSE
#> [49] TRUE FALSE FALSE FALSE TRUE FALSE TRUE FALSE TRUE FALSE TRUE TRUE
#> [61] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE TRUE
#> [73] FALSE TRUE TRUE FALSE FALSE FALSE FALSE FALSE TRUE FALSE TRUE FALSE
#> [85] FALSE FALSE FALSE FALSE FALSE TRUE TRUE TRUE FALSE FALSE FALSE FALSE
#> [97] FALSE FALSE FALSE TRUE
# filter on results from the third 60-day episode only, using base R
df[which(get_episode(df$date, 60) == 3), ]
#> # A tibble: 2 × 46
#> date patient age gender ward mo PEN OXA FLC AMX
#> <date> <chr> <dbl> <chr> <chr> <mo> <sir> <sir> <sir> <sir>
#> 1 2002-07-23 F35553 51 M ICU B_STPHY_AURS R NA S R
#> 2 2002-07-23 F35553 51 M ICU B_STPHY_AURS R NA S R
#> date patient age gender ward mo PEN OXA FLC AMX
#> <date> <chr> <dbl> <chr> <chr> <mo> <sir> <sir> <sir> <sir>
#> 1 2002-11-04 304347 62 M Clinical B_STRPT_PNMN S NA NA S
#> 2 2002-10-18 E55128 57 F ICU B_STPHY_AURS R NA S R
#> # 36 more variables: AMC <sir>, AMP <sir>, TZP <sir>, CZO <sir>, FEP <sir>,
#> # CXM <sir>, FOX <sir>, CTX <sir>, CAZ <sir>, CRO <sir>, GEN <sir>,
#> # TOB <sir>, AMK <sir>, KAN <sir>, TMP <sir>, SXT <sir>, NIT <sir>,
@@ -233,19 +233,19 @@ if (require("dplyr")) {
arrange(patient, condition, date)
}
#> # A tibble: 100 × 4
#> # Groups: patient, condition [95]
#> # Groups: patient, condition [96]
#> patient date condition new_episode
#> <chr> <date> <chr> <lgl>
#> 1 011307 2011-09-20 B TRUE
#> 2 011307 2011-09-20 C TRUE
#> 3 021368 2016-03-25 A TRUE
#> 4 060287 2007-03-11 B TRUE
#> 5 078381 2014-07-17 A TRUE
#> 6 097186 2015-10-28 B TRUE
#> 7 0DBB93 2003-10-02 A TRUE
#> 8 0DBF93 2015-12-03 C TRUE
#> 9 114570 2003-04-22 A TRUE
#> 10 141061 2014-10-22 C TRUE
#> 1 022060 2004-05-04 A TRUE
#> 2 060287 2007-03-11 A TRUE
#> 3 0E2483 2007-04-06 C TRUE
#> 4 101305 2006-12-13 A TRUE
#> 5 141061 2014-10-22 A TRUE
#> 6 146F70 2009-08-14 A TRUE
#> 7 15D386 2004-08-01 B TRUE
#> 8 187841 2008-04-22 C TRUE
#> 9 195736 2008-08-29 C TRUE
#> 10 195736 2008-08-29 C FALSE
#> # 90 more rows
if (require("dplyr")) {
@@ -259,19 +259,19 @@ if (require("dplyr")) {
arrange(patient, ward, date)
}
#> # A tibble: 100 × 5
#> # Groups: ward, patient [93]
#> ward date patient new_index new_logical
#> <chr> <date> <chr> <int> <lgl>
#> 1 Clinical 2011-09-20 011307 1 TRUE
#> 2 Clinical 2011-09-20 011307 1 FALSE
#> 3 Outpatient 2016-03-25 021368 1 TRUE
#> 4 Clinical 2007-03-11 060287 1 TRUE
#> 5 ICU 2014-07-17 078381 1 TRUE
#> 6 Clinical 2015-10-28 097186 1 TRUE
#> 7 ICU 2003-10-02 0DBB93 1 TRUE
#> 8 ICU 2015-12-03 0DBF93 1 TRUE
#> 9 ICU 2003-04-22 114570 1 TRUE
#> 10 Clinical 2014-10-22 141061 1 TRUE
#> # Groups: ward, patient [91]
#> ward date patient new_index new_logical
#> <chr> <date> <chr> <int> <lgl>
#> 1 ICU 2004-05-04 022060 1 TRUE
#> 2 Clinical 2007-03-11 060287 1 TRUE
#> 3 Clinical 2007-04-06 0E2483 1 TRUE
#> 4 Clinical 2006-12-13 101305 1 TRUE
#> 5 Clinical 2014-10-22 141061 1 TRUE
#> 6 Clinical 2009-08-14 146F70 1 TRUE
#> 7 ICU 2004-08-01 15D386 1 TRUE
#> 8 Clinical 2008-04-22 187841 1 TRUE
#> 9 Clinical 2008-08-29 195736 1 TRUE
#> 10 Clinical 2008-08-29 195736 1 FALSE
#> # 90 more rows
if (require("dplyr")) {
@@ -287,9 +287,9 @@ if (require("dplyr")) {
#> # A tibble: 3 × 5
#> ward n_patients n_episodes_365 n_episodes_60 n_episodes_30
#> <chr> <int> <int> <int> <int>
#> 1 Clinical 51 12 33 43
#> 2 ICU 31 11 26 30
#> 3 Outpatient 11 8 11 11
#> 1 Clinical 58 14 38 44
#> 2 ICU 26 7 20 23
#> 3 Outpatient 7 4 6 7
# grouping on patients and microorganisms leads to the same
# results as first_isolate() when using 'episode-based':
@@ -307,7 +307,7 @@ if (require("dplyr")) {
identical(x, y)
}
#> [1] TRUE
#> [1] FALSE
# but is_new_episode() has a lot more flexibility than first_isolate(),
# since you can now group on anything that seems relevant:
@@ -318,19 +318,19 @@ if (require("dplyr")) {
select(group_vars(.), flag_episode)
}
#> # A tibble: 100 × 4
#> # Groups: patient, mo, ward [95]
#> patient mo ward flag_episode
#> <chr> <mo> <chr> <lgl>
#> 1 690B42 B_ESCHR_COLI ICU TRUE
#> 2 550406 B_ESCHR_COLI Outpatient TRUE
#> 3 F86227 B_STPHY_CONS Clinical TRUE
#> 4 859863 B_STPHY_EPDR ICU TRUE
#> 5 987C84 B_ESCHR_COLI Clinical TRUE
#> 6 E19440 B_ESCHR_COLI ICU TRUE
#> 7 F42C5F B_MRGNL_MRGN Clinical TRUE
#> 8 F54261 B_STPHY_AURS Clinical TRUE
#> 9 5D1690 B_ESCHR_COLI Outpatient TRUE
#> 10 874171 B_STPHY_CONS Clinical TRUE
#> # Groups: patient, mo, ward [96]
#> patient mo ward flag_episode
#> <chr> <mo> <chr> <lgl>
#> 1 917895 B_STPHY_CPTS ICU TRUE
#> 2 022060 B_ENTRBC_CLOC ICU TRUE
#> 3 C36883 B_ESCHR_COLI Clinical TRUE
#> 4 5DF436 B_STPHY_AURS ICU TRUE
#> 5 971739 B_STPHY_CONS Clinical TRUE
#> 6 488175 B_ESCHR_COLI Clinical TRUE
#> 7 5DB1C8 B_STPHY_CPTS Clinical TRUE
#> 8 BC9909 B_ENTRBC_CLOC Clinical TRUE
#> 9 5B78D5 B_STPHY_AURS Clinical TRUE
#> 10 284FFF B_STPHY_EPDR Clinical TRUE
#> # 90 more rows
# }
```

View File

@@ -7,7 +7,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">

View File

@@ -7,7 +7,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">

View File

@@ -7,7 +7,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">

View File

@@ -7,7 +7,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
@@ -409,6 +409,13 @@
</dt>
<dd>Data Set with 2 000 Example Isolates</dd>
<dt>
<code><a href="esbl_isolates.html">esbl_isolates</a></code>
</dt>
<dd>Data Set with 500 ESBL Isolates</dd>
<dt>
<code><a href="microorganisms.codes.html">microorganisms.codes</a></code>

View File

@@ -391,6 +391,8 @@ information about how to work with functions in this package.
: Data Set with Clinical Breakpoints for SIR Interpretation
- [`example_isolates`](https://amr-for-r.org/reference/example_isolates.md)
: Data Set with 2 000 Example Isolates
- [`esbl_isolates`](https://amr-for-r.org/reference/esbl_isolates.md) :
Data Set with 500 ESBL Isolates
- [`microorganisms.codes`](https://amr-for-r.org/reference/microorganisms.codes.md)
: Data Set with 6 036 Common Microorganism Codes
- [`microorganisms.groups`](https://amr-for-r.org/reference/microorganisms.groups.md)

View File

@@ -7,7 +7,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">

View File

@@ -7,7 +7,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">

View File

@@ -7,7 +7,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">

View File

@@ -7,7 +7,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">

View File

@@ -7,7 +7,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
@@ -91,9 +91,9 @@
<div class="section level2">
<h2 id="ref-examples">Examples<a class="anchor" aria-label="anchor" href="#ref-examples"></a></h2>
<div class="sourceCode"><pre class="sourceCode r"><code><span class="r-in"><span><span class="fu">kurtosis</span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/stats/Normal.html" class="external-link">rnorm</a></span><span class="op">(</span><span class="fl">10000</span><span class="op">)</span><span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [1] 3.071712</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [1] 3.069947</span>
<span class="r-in"><span><span class="fu">kurtosis</span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/stats/Normal.html" class="external-link">rnorm</a></span><span class="op">(</span><span class="fl">10000</span><span class="op">)</span>, excess <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [1] -0.02774835</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [1] -0.02599697</span>
</code></pre></div>
</div>
</main><aside class="col-md-3"><nav id="toc" aria-label="Table of contents"><h2>On this page</h2>

View File

@@ -45,7 +45,7 @@ kurtosis(x, na.rm = FALSE, excess = FALSE)
``` r
kurtosis(rnorm(10000))
#> [1] 3.071712
#> [1] 3.069947
kurtosis(rnorm(10000), excess = TRUE)
#> [1] -0.02774835
#> [1] -0.02599697
```

View File

@@ -7,7 +7,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
@@ -107,6 +107,8 @@
<h2 id="ref-examples">Examples<a class="anchor" aria-label="anchor" href="#ref-examples"></a></h2>
<div class="sourceCode"><pre class="sourceCode r"><code><span class="r-in"><span><span class="co"># data.table has a more limited version of %like%, so unload it:</span></span></span>
<span class="r-in"><span><span class="kw"><a href="https://rdrr.io/r/base/try.html" class="external-link">try</a></span><span class="op">(</span><span class="kw"><a href="https://rdrr.io/r/base/detach.html" class="external-link">detach</a></span><span class="op">(</span><span class="st">"package:data.table"</span>, unload <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span>, silent <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span></span></span>
<span class="r-wrn co"><span class="r-pr">#&gt;</span> <span class="warning">Warning: </span>data.table namespace cannot be unloaded:</span>
<span class="r-wrn co"><span class="r-pr">#&gt;</span> namespace data.table is imported by prodlim so cannot be unloaded</span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="va">a</span> <span class="op">&lt;-</span> <span class="st">"This is a test"</span></span></span>
<span class="r-in"><span><span class="va">b</span> <span class="op">&lt;-</span> <span class="st">"TEST"</span></span></span>

View File

@@ -88,6 +88,8 @@ inserted text will be iterated over `%like%` -\> `%unlike%` -\>
``` r
# data.table has a more limited version of %like%, so unload it:
try(detach("package:data.table", unload = TRUE), silent = TRUE)
#> Warning: data.table namespace cannot be unloaded:
#> namespace data.table is imported by prodlim so cannot be unloaded
a <- "This is a test"
b <- "TEST"

View File

@@ -7,7 +7,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">

View File

@@ -7,7 +7,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
@@ -110,30 +110,30 @@
<div class="sourceCode"><pre class="sourceCode r"><code><span class="r-in"><span><span class="va">sir</span> <span class="op">&lt;-</span> <span class="fu"><a href="random.html">random_sir</a></span><span class="op">(</span><span class="fl">10</span><span class="op">)</span></span></span>
<span class="r-in"><span><span class="va">sir</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> Class 'sir'</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [1] I I R I R S S S I S</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [1] R R I R I I S R S I</span>
<span class="r-in"><span><span class="fu">mean_amr_distance</span><span class="op">(</span><span class="va">sir</span><span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [1] -0.4743416 -0.4743416 1.8973666 -0.4743416 1.8973666 -0.4743416</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [7] -0.4743416 -0.4743416 -0.4743416 -0.4743416</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [1] 1.1618950 1.1618950 -0.7745967 1.1618950 -0.7745967 -0.7745967</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [7] -0.7745967 1.1618950 -0.7745967 -0.7745967</span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="va">mic</span> <span class="op">&lt;-</span> <span class="fu"><a href="random.html">random_mic</a></span><span class="op">(</span><span class="fl">10</span><span class="op">)</span></span></span>
<span class="r-in"><span><span class="va">mic</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> Class 'mic'</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [1] 0.004 2 0.002 0.0001 0.004 0.002 &gt;=4 0.0002 0.032 0.004 </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [1] 0.032 0.5 1 &gt;=8 4 0.016 &gt;=8 1 0.004 0.008</span>
<span class="r-in"><span><span class="fu">mean_amr_distance</span><span class="op">(</span><span class="va">mic</span><span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [1] -0.2047915 1.5799751 -0.4038557 -1.2641969 -0.2047915 -0.4038557</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [7] 1.7790393 -1.0651327 0.3924011 -0.2047915</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [1] -0.7311752 0.2104422 0.4478776 1.1601837 0.9227483 -0.9686106</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [7] 1.1601837 0.4478776 -1.4434813 -1.2060459</span>
<span class="r-in"><span><span class="co"># equal to the Z-score of their log2:</span></span></span>
<span class="r-in"><span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/Log.html" class="external-link">log2</a></span><span class="op">(</span><span class="va">mic</span><span class="op">)</span> <span class="op">-</span> <span class="fu"><a href="https://rdrr.io/r/base/mean.html" class="external-link">mean</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/Log.html" class="external-link">log2</a></span><span class="op">(</span><span class="va">mic</span><span class="op">)</span><span class="op">)</span><span class="op">)</span> <span class="op">/</span> <span class="fu"><a href="https://rdrr.io/r/stats/sd.html" class="external-link">sd</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/Log.html" class="external-link">log2</a></span><span class="op">(</span><span class="va">mic</span><span class="op">)</span><span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [1] -0.2047915 1.5799751 -0.4038557 -1.2641969 -0.2047915 -0.4038557</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [7] 1.7790393 -1.0651327 0.3924011 -0.2047915</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [1] -0.7311752 0.2104422 0.4478776 1.1601837 0.9227483 -0.9686106</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [7] 1.1601837 0.4478776 -1.4434813 -1.2060459</span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="va">disk</span> <span class="op">&lt;-</span> <span class="fu"><a href="random.html">random_disk</a></span><span class="op">(</span><span class="fl">10</span><span class="op">)</span></span></span>
<span class="r-in"><span><span class="va">disk</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> Class 'disk'</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [1] 43 12 28 32 22 31 35 25 43 35</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [1] 50 49 38 33 31 17 42 43 46 37</span>
<span class="r-in"><span><span class="fu">mean_amr_distance</span><span class="op">(</span><span class="va">disk</span><span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [1] 1.30998909 -1.96498364 -0.27467513 0.14790199 -0.90854082 0.04225771</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [7] 0.46483484 -0.59160798 1.30998909 0.46483484</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [1] 1.15131286 1.05032051 -0.06059541 -0.56555720 -0.76754191 -2.18143490</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [7] 0.34337401 0.44436637 0.74734344 -0.16158777</span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="va">y</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/data.frame.html" class="external-link">data.frame</a></span><span class="op">(</span></span></span>
<span class="r-in"><span> id <span class="op">=</span> <span class="va">LETTERS</span><span class="op">[</span><span class="fl">1</span><span class="op">:</span><span class="fl">10</span><span class="op">]</span>,</span></span>
@@ -144,35 +144,35 @@
<span class="r-in"><span><span class="op">)</span></span></span>
<span class="r-in"><span><span class="va">y</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> id amox cipr gent tobr</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1 A S 31 2 &gt;=16</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2 B S 27 &lt;=1 8</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3 C R 25 2 4</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4 D R 25 &lt;=1 2</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 5 E I 31 &lt;=1 2</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 6 F S 32 &lt;=1 8</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 7 G I 29 2 2</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 8 H S 18 &lt;=1 4</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 9 I S 28 &lt;=1 4</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 10 J R 17 &lt;=1 2</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1 A I 27 &gt;=2 8</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2 B S 28 1 8</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3 C R 33 1 8</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4 D R 32 1 16</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 5 E I 25 0.5 16</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 6 F I 19 0.5 8</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 7 G S 23 0.5 16</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 8 H R 27 0.5 8</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 9 I S 29 1 8</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 10 J R 32 0.5 16</span>
<span class="r-in"><span><span class="fu">mean_amr_distance</span><span class="op">(</span><span class="va">y</span><span class="op">)</span></span></span>
<span class="r-msg co"><span class="r-pr">#&gt;</span> <span style="color: #0000BB;"> Calculating mean AMR distance based on columns "amox", "cipr", "gent",</span></span>
<span class="r-msg co"><span class="r-pr">#&gt;</span> <span style="color: #0000BB;"> and "tobr"</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [1] 0.90606144 -0.03989270 0.66241774 -0.09230226 -0.32300020 0.19914999</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [7] 0.09893189 -0.70734036 -0.22925499 -0.47477055</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [1] 0.08471751 -0.21572693 0.55391610 0.98093500 -0.26046456 -1.08721162</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [7] -0.37467261 -0.14625651 -0.15862291 0.62338653</span>
<span class="r-in"><span><span class="va">y</span><span class="op">$</span><span class="va">amr_distance</span> <span class="op">&lt;-</span> <span class="fu">mean_amr_distance</span><span class="op">(</span><span class="va">y</span>, <span class="fu"><a href="as.mic.html">is.mic</a></span><span class="op">(</span><span class="va">y</span><span class="op">)</span><span class="op">)</span></span></span>
<span class="r-msg co"><span class="r-pr">#&gt;</span> <span style="color: #0000BB;"> Calculating mean AMR distance based on columns "gent" and "tobr"</span></span>
<span class="r-in"><span><span class="va">y</span><span class="op">[</span><span class="fu"><a href="https://rdrr.io/r/base/order.html" class="external-link">order</a></span><span class="op">(</span><span class="va">y</span><span class="op">$</span><span class="va">amr_distance</span><span class="op">)</span>, <span class="op">]</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> id amox cipr gent tobr amr_distance</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4 D R 25 &lt;=1 2 -0.7848712</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 5 E I 31 &lt;=1 2 -0.7848712</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 10 J R 17 &lt;=1 2 -0.7848712</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 8 H S 18 &lt;=1 4 -0.3105295</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 9 I S 28 &lt;=1 4 -0.3105295</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2 B S 27 &lt;=1 8 0.1638121</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 6 F S 32 &lt;=1 8 0.1638121</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 7 G I 29 2 2 0.2502272</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3 C R 25 2 4 0.7245688</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1 A S 31 2 &gt;=16 1.6732521</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 6 F I 19 0.5 8 -0.8163565</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 8 H R 27 0.5 8 -0.8163565</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2 B S 28 1 8 -0.1012596</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3 C R 33 1 8 -0.1012596</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 9 I S 29 1 8 -0.1012596</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 5 E I 25 0.5 16 0.1518893</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 7 G S 23 0.5 16 0.1518893</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 10 J R 32 0.5 16 0.1518893</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1 A I 27 &gt;=2 8 0.6138374</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4 D R 32 1 16 0.8669863</span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="kw">if</span> <span class="op">(</span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">require</a></span><span class="op">(</span><span class="st"><a href="https://dplyr.tidyverse.org" class="external-link">"dplyr"</a></span><span class="op">)</span><span class="op">)</span> <span class="op">{</span></span></span>
<span class="r-in"><span> <span class="va">y</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span></span></span>
@@ -185,16 +185,16 @@
<span class="r-msg co"><span class="r-pr">#&gt;</span> <span style="color: #0000BB;"> Calculating mean AMR distance based on columns "amox", "cipr", "gent",</span></span>
<span class="r-msg co"><span class="r-pr">#&gt;</span> <span style="color: #0000BB;"> and "tobr"</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> id amox cipr gent tobr amr_distance check_id_C</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1 C R 25 2 4 0.66241774 0.0000000</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2 A S 31 2 &gt;=16 0.90606144 0.2436437</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3 F S 32 &lt;=1 8 0.19914999 0.4632678</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4 G I 29 2 2 0.09893189 0.5634858</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 5 B S 27 &lt;=1 8 -0.03989270 0.7023104</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 6 D R 25 &lt;=1 2 -0.09230226 0.7547200</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 7 I S 28 &lt;=1 4 -0.22925499 0.8916727</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 8 E I 31 &lt;=1 2 -0.32300020 0.9854179</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 9 J R 17 &lt;=1 2 -0.47477055 1.1371883</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 10 H S 18 &lt;=1 4 -0.70734036 1.3697581</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1 C R 33 1 8 0.55391610 0.00000000</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2 J R 32 0.5 16 0.62338653 0.06947042</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3 D R 32 1 16 0.98093500 0.42701889</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4 A I 27 &gt;=2 8 0.08471751 0.46919859</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 5 H R 27 0.5 8 -0.14625651 0.70017262</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 6 I S 29 1 8 -0.15862291 0.71253901</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 7 B S 28 1 8 -0.21572693 0.76964304</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 8 E I 25 0.5 16 -0.26046456 0.81438066</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 9 G S 23 0.5 16 -0.37467261 0.92858871</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 10 F I 19 0.5 8 -1.08721162 1.64112773</span>
<span class="r-in"><span><span class="kw">if</span> <span class="op">(</span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">require</a></span><span class="op">(</span><span class="st"><a href="https://dplyr.tidyverse.org" class="external-link">"dplyr"</a></span><span class="op">)</span><span class="op">)</span> <span class="op">{</span></span></span>
<span class="r-in"><span> <span class="co"># support for groups</span></span></span>
<span class="r-in"><span> <span class="va">example_isolates</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span></span></span>

View File

@@ -85,30 +85,30 @@ suspicious.
sir <- random_sir(10)
sir
#> Class 'sir'
#> [1] I I R I R S S S I S
#> [1] R R I R I I S R S I
mean_amr_distance(sir)
#> [1] -0.4743416 -0.4743416 1.8973666 -0.4743416 1.8973666 -0.4743416
#> [7] -0.4743416 -0.4743416 -0.4743416 -0.4743416
#> [1] 1.1618950 1.1618950 -0.7745967 1.1618950 -0.7745967 -0.7745967
#> [7] -0.7745967 1.1618950 -0.7745967 -0.7745967
mic <- random_mic(10)
mic
#> Class 'mic'
#> [1] 0.004 2 0.002 0.0001 0.004 0.002 >=4 0.0002 0.032 0.004
#> [1] 0.032 0.5 1 >=8 4 0.016 >=8 1 0.004 0.008
mean_amr_distance(mic)
#> [1] -0.2047915 1.5799751 -0.4038557 -1.2641969 -0.2047915 -0.4038557
#> [7] 1.7790393 -1.0651327 0.3924011 -0.2047915
#> [1] -0.7311752 0.2104422 0.4478776 1.1601837 0.9227483 -0.9686106
#> [7] 1.1601837 0.4478776 -1.4434813 -1.2060459
# equal to the Z-score of their log2:
(log2(mic) - mean(log2(mic))) / sd(log2(mic))
#> [1] -0.2047915 1.5799751 -0.4038557 -1.2641969 -0.2047915 -0.4038557
#> [7] 1.7790393 -1.0651327 0.3924011 -0.2047915
#> [1] -0.7311752 0.2104422 0.4478776 1.1601837 0.9227483 -0.9686106
#> [7] 1.1601837 0.4478776 -1.4434813 -1.2060459
disk <- random_disk(10)
disk
#> Class 'disk'
#> [1] 43 12 28 32 22 31 35 25 43 35
#> [1] 50 49 38 33 31 17 42 43 46 37
mean_amr_distance(disk)
#> [1] 1.30998909 -1.96498364 -0.27467513 0.14790199 -0.90854082 0.04225771
#> [7] 0.46483484 -0.59160798 1.30998909 0.46483484
#> [1] 1.15131286 1.05032051 -0.06059541 -0.56555720 -0.76754191 -2.18143490
#> [7] 0.34337401 0.44436637 0.74734344 -0.16158777
y <- data.frame(
id = LETTERS[1:10],
@@ -119,35 +119,35 @@ y <- data.frame(
)
y
#> id amox cipr gent tobr
#> 1 A S 31 2 >=16
#> 2 B S 27 <=1 8
#> 3 C R 25 2 4
#> 4 D R 25 <=1 2
#> 5 E I 31 <=1 2
#> 6 F S 32 <=1 8
#> 7 G I 29 2 2
#> 8 H S 18 <=1 4
#> 9 I S 28 <=1 4
#> 10 J R 17 <=1 2
#> 1 A I 27 >=2 8
#> 2 B S 28 1 8
#> 3 C R 33 1 8
#> 4 D R 32 1 16
#> 5 E I 25 0.5 16
#> 6 F I 19 0.5 8
#> 7 G S 23 0.5 16
#> 8 H R 27 0.5 8
#> 9 I S 29 1 8
#> 10 J R 32 0.5 16
mean_amr_distance(y)
#> Calculating mean AMR distance based on columns "amox", "cipr", "gent",
#> and "tobr"
#> [1] 0.90606144 -0.03989270 0.66241774 -0.09230226 -0.32300020 0.19914999
#> [7] 0.09893189 -0.70734036 -0.22925499 -0.47477055
#> [1] 0.08471751 -0.21572693 0.55391610 0.98093500 -0.26046456 -1.08721162
#> [7] -0.37467261 -0.14625651 -0.15862291 0.62338653
y$amr_distance <- mean_amr_distance(y, is.mic(y))
#> Calculating mean AMR distance based on columns "gent" and "tobr"
y[order(y$amr_distance), ]
#> id amox cipr gent tobr amr_distance
#> 4 D R 25 <=1 2 -0.7848712
#> 5 E I 31 <=1 2 -0.7848712
#> 10 J R 17 <=1 2 -0.7848712
#> 8 H S 18 <=1 4 -0.3105295
#> 9 I S 28 <=1 4 -0.3105295
#> 2 B S 27 <=1 8 0.1638121
#> 6 F S 32 <=1 8 0.1638121
#> 7 G I 29 2 2 0.2502272
#> 3 C R 25 2 4 0.7245688
#> 1 A S 31 2 >=16 1.6732521
#> 6 F I 19 0.5 8 -0.8163565
#> 8 H R 27 0.5 8 -0.8163565
#> 2 B S 28 1 8 -0.1012596
#> 3 C R 33 1 8 -0.1012596
#> 9 I S 29 1 8 -0.1012596
#> 5 E I 25 0.5 16 0.1518893
#> 7 G S 23 0.5 16 0.1518893
#> 10 J R 32 0.5 16 0.1518893
#> 1 A I 27 >=2 8 0.6138374
#> 4 D R 32 1 16 0.8669863
if (require("dplyr")) {
y %>%
@@ -160,16 +160,16 @@ if (require("dplyr")) {
#> Calculating mean AMR distance based on columns "amox", "cipr", "gent",
#> and "tobr"
#> id amox cipr gent tobr amr_distance check_id_C
#> 1 C R 25 2 4 0.66241774 0.0000000
#> 2 A S 31 2 >=16 0.90606144 0.2436437
#> 3 F S 32 <=1 8 0.19914999 0.4632678
#> 4 G I 29 2 2 0.09893189 0.5634858
#> 5 B S 27 <=1 8 -0.03989270 0.7023104
#> 6 D R 25 <=1 2 -0.09230226 0.7547200
#> 7 I S 28 <=1 4 -0.22925499 0.8916727
#> 8 E I 31 <=1 2 -0.32300020 0.9854179
#> 9 J R 17 <=1 2 -0.47477055 1.1371883
#> 10 H S 18 <=1 4 -0.70734036 1.3697581
#> 1 C R 33 1 8 0.55391610 0.00000000
#> 2 J R 32 0.5 16 0.62338653 0.06947042
#> 3 D R 32 1 16 0.98093500 0.42701889
#> 4 A I 27 >=2 8 0.08471751 0.46919859
#> 5 H R 27 0.5 8 -0.14625651 0.70017262
#> 6 I S 29 1 8 -0.15862291 0.71253901
#> 7 B S 28 1 8 -0.21572693 0.76964304
#> 8 E I 25 0.5 16 -0.26046456 0.81438066
#> 9 G S 23 0.5 16 -0.37467261 0.92858871
#> 10 F I 19 0.5 8 -1.08721162 1.64112773
if (require("dplyr")) {
# support for groups
example_isolates %>%

View File

@@ -7,7 +7,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">

View File

@@ -7,7 +7,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">

View File

@@ -9,7 +9,7 @@ This data set is carefully crafted, yet made 100% reproducible from public and a
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">

View File

@@ -7,7 +7,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">

View File

@@ -7,7 +7,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">

View File

@@ -9,7 +9,7 @@ This is the fastest way to have your organisation (or analysis) specific codes p
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">

View File

@@ -7,7 +7,7 @@
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9004</small>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.0.1.9007</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 36 KiB

Some files were not shown because too many files have changed in this diff Show More