#' @param gram_negative names of antibiotic agents for **Gram-positives**, case-insensitive. Set to `NULL` to ignore. See *Details* for the default agents.
#' @param gram_positive names of antibiotic agents for **Gram-negatives**, case-insensitive. Set to `NULL` to ignore. See *Details* for the default agents.
#' @param antifungal names of antifungal agents for **fungi**, case-insensitive. Set to `NULL` to ignore. See *Details* for the default agents.
#' @param only_rsi_columns a logical to indicate whether only columns must be included that were transformed to class `<rsi>` (see [as.rsi()]) on beforehand (defaults to `FALSE`)
#' @param ... ignored, allows for future extensions
#' @details
#' The [key_antimicrobials()] and [all_antimicrobials()] functions are context-aware. This means that then the `x` argument can be left blank, see *Examples*.
<p>These rules can be used to discard impossible bug-drug combinations in your data. For example, <em>Klebsiella</em> produces beta-lactamase that prevents ampicillin (or amoxicillin) from working against it. In other words, practically every strain of <em>Klebsiella</em> is resistant to ampicillin.</p>
<p>Sometimes, laboratory data can still contain such strains with ampicillin being susceptible to ampicillin. This could be because an antibiogram is available before an identification is available, and the antibiogram is then not re-interpreted based on the identification (namely, <em>Klebsiella</em>). EUCAST expert rules solve this, that can be applied using <code><ahref="../reference/eucast_rules.html">eucast_rules()</a></code>:</p>
<spanclass="fu"><ahref="../reference/eucast_rules.html">eucast_rules</a></span><spanclass="op">(</span><spanclass="va">oops</span>, info <spanclass="op">=</span><spanclass="cn">FALSE</span><spanclass="op">)</span>
<p>A more convenient function is <code><ahref="../reference/mo_property.html">mo_is_intrinsic_resistant()</a></code> that uses the same guideline, but allows to check for one or more specific microorganisms or antibiotics:</p>
<p>EUCAST rules can not only be used for correction, they can also be used for filling in known resistance and susceptibility based on results of other antimicrobials drugs. This process is called <em>interpretive reading</em>, is basically a form of imputation, and is part of the <code><ahref="../reference/eucast_rules.html">eucast_rules()</a></code> function as well:</p>
<p>You can also use your own custom guideline. Custom guidelines can be set with the <code><ahref="../reference/mdro.html">custom_mdro_guideline()</a></code> function. This is of great importance if you have custom rules to determine MDROs in your hospital, e.g., rules that are dependent on ward, state of contact isolation or other variables in your data.</p>
<p>If you are familiar with <code><ahref="https://dplyr.tidyverse.org/reference/case_when.html">case_when()</a></code> of the <code>dplyr</code> package, you will recognise the input method to set your own rules. Rules must be set using what considers to be the ‘formula notation’:</p>
<codeclass="sourceCode R"><spanclass="va">custom</span><spanclass="op"><-</span><spanclass="fu"><ahref="../reference/mdro.html">custom_mdro_guideline</a></span><spanclass="op">(</span><spanclass="va">CIP</span><spanclass="op">==</span><spanclass="st">"R"</span><spanclass="op">&</span><spanclass="va">age</span><spanclass="op">></span><spanclass="fl">60</span><spanclass="op">~</span><spanclass="st">"Elderly Type A"</span>,
<spanclass="va">ERY</span><spanclass="op">==</span><spanclass="st">"R"</span><spanclass="op">&</span><spanclass="va">age</span><spanclass="op">></span><spanclass="fl">60</span><spanclass="op">~</span><spanclass="st">"Elderly Type B"</span><spanclass="op">)</span></code></pre></div>
<spanclass="va">custom</span><spanclass="op"><-</span><spanclass="fu"><ahref="../reference/mdro.html">custom_mdro_guideline</a></span><spanclass="op">(</span><spanclass="va">CIP</span><spanclass="op">==</span><spanclass="st">"R"</span><spanclass="op">&</span><spanclass="va">age</span><spanclass="op">></span><spanclass="fl">60</span><spanclass="op">~</span><spanclass="st">"Elderly Type A"</span>,
<spanclass="va">ERY</span><spanclass="op">==</span><spanclass="st">"R"</span><spanclass="op">&</span><spanclass="va">age</span><spanclass="op">></span><spanclass="fl">60</span><spanclass="op">~</span><spanclass="st">"Elderly Type B"</span><spanclass="op">)</span></pre></div>
<p>If a row/an isolate matches the first rule, the value after the first <code><ahref="https://rdrr.io/r/base/tilde.html">~</a></code> (in this case <em>‘Elderly Type A’</em>) will be set as MDRO value. Otherwise, the second rule will be tried and so on. The number of rules is unlimited.</p>
<p>You can print the rules set in the console for an overview. Colours will help reading it if your console supports colours.</p>
<spanclass="co"># 1. If CIP is "R" and age is higher than 60 then: Elderly Type A</span>
<spanclass="co"># 2. If ERY is "R" and age is higher than 60 then: Elderly Type B</span>
<spanclass="co"># 3. Otherwise: Negative</span>
<spanclass="co"># </span>
<spanclass="co"># Unmatched rows will return NA.</span>
<spanclass="co"># Results will be of class <factor>, with ordered levels: Negative < Elderly Type A < Elderly Type B</span></code></pre></div>
<spanclass="co"># Results will be of class <factor>, with ordered levels: Negative < Elderly Type A < Elderly Type B</span></pre></div>
<p>The outcome of the function can be used for the <code>guideline</code> argument in the [mdro()] function:</p>
<p>The rules set (the <code>custom</code> object in this case) could be exported to a shared file location using <code><ahref="https://rdrr.io/r/base/readRDS.html">saveRDS()</a></code> if you collaborate with multiple users. The custom rules set could then be imported using <code><ahref="https://rdrr.io/r/base/readRDS.html">readRDS()</a></code>.</p>
<p>The <code><ahref="../reference/mdro.html">mdro()</a></code> function always returns an ordered <code>factor</code>. For example, the output of the default guideline by Magiorakos <em>et al.</em> returns a <code>factor</code> with levels ‘Negative’, ‘MDR’, ‘XDR’ or ‘PDR’ in that order.</p>
<p>The next example uses the <code>example_isolates</code> data set. This is a data set included with this package and contains 2,000 microbial isolates with their full antibiograms. It reflects reality and can be used to practice AMR data analysis. If we test the MDR/XDR/PDR guideline on this data set, we get:</p>
<codeclass="sourceCode R"><spanclass="kw"><ahref="https://rdrr.io/r/base/library.html">library</a></span><spanclass="op">(</span><spanclass="va"><ahref="https://dplyr.tidyverse.org">dplyr</a></span><spanclass="op">)</span><spanclass="co"># to support pipes: %>%</span>
<spanclass="kw"><ahref="https://rdrr.io/r/base/library.html">library</a></span><spanclass="op">(</span><spanclass="va"><ahref="https://github.com/msberends/cleaner">cleaner</a></span><spanclass="op">)</span><spanclass="co"># to create frequency tables</span></code></pre></div>
<spanclass="kw"><ahref="https://rdrr.io/r/base/library.html">library</a></span><spanclass="op">(</span><spanclass="va"><ahref="https://dplyr.tidyverse.org">dplyr</a></span><spanclass="op">)</span><spanclass="co"># to support pipes: %>%</span>
<spanclass="kw"><ahref="https://rdrr.io/r/base/library.html">library</a></span><spanclass="op">(</span><spanclass="va"><ahref="https://github.com/msberends/cleaner">cleaner</a></span><spanclass="op">)</span><spanclass="co"># to create frequency tables</span></pre></div>
<spanclass="fu"><ahref="https://rdrr.io/pkg/cleaner/man/freq.html">freq</a></span><spanclass="op">(</span><spanclass="op">)</span><spanclass="co"># show frequency table of the result</span>
<spanclass="co"># Warning: NA introduced for isolates where the available percentage of antimicrobial</span>
<spanclass="co"># classes was below 50% (set with `pct_required_classes`)</span></code></pre></div>
<spanclass="co"># classes was below 50% (set with `pct_required_classes`)</span></pre></div>
<p><strong>Frequency table</strong></p>
<p>Class: factor > ordered (numeric)<br>
Length: 2,000<br>
@ -316,8 +317,8 @@ Unique: 2</p>
</tbody>
</table>
<p>For another example, I will create a data set to determine multi-drug resistant TB:</p>
GAT <spanclass="op">=</span><spanclass="fu"><ahref="../reference/random.html">random_rsi</a></span><spanclass="op">(</span><spanclass="fl">5000</span><spanclass="op">)</span>,
ETH <spanclass="op">=</span><spanclass="fu"><ahref="../reference/random.html">random_rsi</a></span><spanclass="op">(</span><spanclass="fl">5000</span><spanclass="op">)</span>,
KAN <spanclass="op">=</span><spanclass="fu"><ahref="../reference/random.html">random_rsi</a></span><spanclass="op">(</span><spanclass="fl">5000</span><spanclass="op">)</span><spanclass="op">)</span></code></pre></div>
KAN <spanclass="op">=</span><spanclass="fu"><ahref="../reference/random.html">random_rsi</a></span><spanclass="op">(</span><spanclass="fl">5000</span><spanclass="op">)</span><spanclass="op">)</span></pre></div>