<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>
<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> and is part of the <code><ahref="../reference/eucast_rules.html">eucast_rules()</a></code> function as well:</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 analysis. If we test the MDR/XDR/PDR guideline on this data set, we get:</p>
<divclass="sourceCode"id="cb1"><html><body><preclass="r"><spanclass="fu"><ahref="https://rdrr.io/r/base/library.html">library</a></span>(<spanclass="no">dplyr</span>) <spanclass="co"># to support pipes: %>%</span>
<spanclass="fu"><ahref="https://rdrr.io/r/base/library.html">library</a></span>(<spanclass="no">cleaner</span>) <spanclass="co"># to create frequency tables</span></pre></body></html></div>
<spanclass="fu"><ahref="https://rdrr.io/r/base/library.html">library</a></span>(<spanclass="kw"><ahref="https://dplyr.tidyverse.org">dplyr</a></span>) <spanclass="co"># to support pipes: %>%</span>
<spanclass="fu"><ahref="https://rdrr.io/r/base/library.html">library</a></span>(<spanclass="kw"><ahref="https://github.com/msberends/cleaner">cleaner</a></span>) <spanclass="co"># to create frequency tables</span>
<spanclass="co"># NOTE: No column found as input for `col_mo`, assuming all records contain Mycobacterium tuberculosis.</span>
<spanclass="co"># NOTE: Auto-guessing columns suitable for analysis...OK.</span>
<spanclass="co"># NOTE: Reliability would be improved if these antimicrobial results would be available too: capreomycin (CAP), rifabutin (RIB), rifapentine (RFP)</span></pre></body></html></div>
<spanclass="co"># NOTE: Reliability would be improved if these antimicrobial results would be available too: capreomycin (CAP), rifabutin (RIB), rifapentine (RFP)</span>
<spanclass="fu"><ahref="https://dplyr.tidyverse.org/reference/group_by.html">group_by</a></span>(<spanclass="kw">order</span><spanclass="kw">=</span><spanclass="fu"><ahref="../reference/mo_property.html">mo_order</a></span>(<spanclass="no">mo</span>), <spanclass="co"># group on anything, like order</span>
<spanclass="kw">genus</span><spanclass="kw">=</span><spanclass="fu"><ahref="../reference/mo_property.html">mo_genus</a></span>(<spanclass="no">mo</span>)) <spanclass="kw">%>%</span><spanclass="co"># and genus as we do here</span>
<spanclass="fu"><ahref="https://dplyr.tidyverse.org/reference/summarise_all.html">summarise_if</a></span>(<spanclass="no">is.rsi</span>, <spanclass="no">resistance</span>) <spanclass="kw">%>%</span><spanclass="co"># then get resistance of all drugs</span>
<spanclass="fu"><ahref="https://dplyr.tidyverse.org/reference/group_by.html">group_by</a></span>(order = <spanclass="fu"><ahref="../reference/mo_property.html">mo_order</a></span>(<spanclass="kw">mo</span>), <spanclass="co"># group on anything, like order</span>
genus = <spanclass="fu"><ahref="../reference/mo_property.html">mo_genus</a></span>(<spanclass="kw">mo</span>)) <spanclass="op">%>%</span><spanclass="co"># and genus as we do here</span>
<spanclass="fu"><ahref="https://dplyr.tidyverse.org/reference/summarise_all.html">summarise_if</a></span>(<spanclass="kw">is.rsi</span>, <spanclass="kw">resistance</span>) <spanclass="op">%>%</span><spanclass="co"># then get resistance of all drugs</span>
<ahref="#perform-principal-component-analysis"class="anchor"></a>Perform principal component analysis</h1>
<p>The new <code><ahref="../reference/pca.html">pca()</a></code> function will automatically filter on rows that contain numeric values in all selected variables, so we now only need to do:</p>
<p>Good news. The first two components explain a total of 93.3% of the variance (see the PC1 and PC2 values of the <em>Proportion of Variance</em>. We can create a so-called biplot with the base R <code><ahref="https://rdrr.io/r/stats/biplot.html">biplot()</a></code> function, to see which antimicrobial resistance per drug explain the difference per microorganism.</p>
<p>But we can’t see the explanation of the points. Perhaps this works better with our new <code><ahref="../reference/ggplot_pca.html">ggplot_pca()</a></code> function, that automatically adds the right labels and even groups:</p>
<spanclass="kw">klebsiella_test</span><spanclass="co"># (our original data)</span>
<spanclass="co"># mo amox</span>
<spanclass="co"># 1 klebsiella S</span>
<spanclass="fu"><ahref="../reference/eucast_rules.html">eucast_rules</a></span>(<spanclass="no">klebsiella_test</span>, <spanclass="kw">info</span><spanclass="kw">=</span><spanclass="fl">FALSE</span>) <spanclass="co"># (the edited data by EUCAST rules)</span>
<spanclass="fu"><ahref="../reference/eucast_rules.html">eucast_rules</a></span>(<spanclass="kw">klebsiella_test</span>, info = <spanclass="fl">FALSE</span>) <spanclass="co"># (the edited data by EUCAST rules)</span>
<p>If you want named variables to be imported as factors so it resembles SPSS more, use <code><ahref="https://haven.tidyverse.org/reference/as_factor.html">as_factor()</a></code>.</p>
<ahref="#import-of-data"class="anchor"></a>Import of data</h3>
<p>This tutorial assumes you already imported the WHONET data with e.g.the <ahref="https://readxl.tidyverse.org/"><code>readxl</code> package</a>. In RStudio, this can be done using the menu button ‘Import Dataset’ in the tab ‘Environment’. Choose the option ‘From Excel’ and select your exported file. Make sure date fields are imported correctly.</p>
<p>This package comes with an <ahref="https://msberends.github.io/AMR/reference/WHONET.html">example data set <code>WHONET</code></a>. We will use it for this analysis.</p>
<p>First, load the relevant packages if you did not yet did this. I use the tidyverse for all of my analyses. All of them. If you don’t know it yet, I suggest you read about it on their website: <ahref="https://www.tidyverse.org/"class="uri">https://www.tidyverse.org/</a>.</p>
<divclass="sourceCode"id="cb2"><html><body><preclass="r"><spanclass="fu"><ahref="https://rdrr.io/r/base/library.html">library</a></span>(<spanclass="no">dplyr</span>) <spanclass="co"># part of tidyverse</span>
<spanclass="fu"><ahref="https://rdrr.io/r/base/library.html">library</a></span>(<spanclass="no">ggplot2</span>) <spanclass="co"># part of tidyverse</span>
<spanclass="fu"><ahref="https://rdrr.io/r/base/library.html">library</a></span>(<spanclass="no">AMR</span>) <spanclass="co"># this package</span>
<spanclass="fu"><ahref="https://rdrr.io/r/base/library.html">library</a></span>(<spanclass="no">cleaner</span>) <spanclass="co"># to create frequency tables</span></pre></body></html></div>
<spanclass="fu"><ahref="https://rdrr.io/r/base/library.html">library</a></span>(<spanclass="kw"><ahref="https://dplyr.tidyverse.org">dplyr</a></span>) <spanclass="co"># part of tidyverse</span>
<spanclass="fu"><ahref="https://rdrr.io/r/base/library.html">library</a></span>(<spanclass="kw"><ahref="http://ggplot2.tidyverse.org">ggplot2</a></span>) <spanclass="co"># part of tidyverse</span>
<spanclass="fu"><ahref="https://rdrr.io/r/base/library.html">library</a></span>(<spanclass="kw"><ahref="https://msberends.github.io/AMR">AMR</a></span>) <spanclass="co"># this package</span>
<spanclass="fu"><ahref="https://rdrr.io/r/base/library.html">library</a></span>(<spanclass="kw"><ahref="https://github.com/msberends/cleaner">cleaner</a></span>) <spanclass="co"># to create frequency tables</span>
</pre></div>
<p>We will have to transform some variables to simplify and automate the analysis:</p>
<ul>
<li>Microorganisms should be transformed to our own microorganism IDs (called an <code>mo</code>) using <ahref="https://msberends.github.io/AMR/reference/catalogue_of_life">our Catalogue of Life reference data set</a>, which contains all ~70,000 microorganisms from the taxonomic kingdoms Bacteria, Fungi and Protozoa. We do the tranformation with <code><ahref="../reference/as.mo.html">as.mo()</a></code>. This function also recognises almost all WHONET abbreviations of microorganisms.</li>
<li>Antimicrobial results or interpretations have to be clean and valid. In other words, they should only contain values <code>"S"</code>, <code>"I"</code> or <code>"R"</code>. That is exactly where the <code><ahref="../reference/as.rsi.html">as.rsi()</a></code> function is for.</li>
<p>No errors or warnings, so all values are transformed succesfully.</p>
<p>We also created a package dedicated to data cleaning and checking, called the <code>cleaner</code> package. Its <code><ahref="https://rdrr.io/pkg/cleaner/man/freq.html">freq()</a></code> function can be used to create frequency tables.</p>
<p>So let’s check our data, with a couple of frequency tables:</p>
<divclass="sourceCode"id="cb4"><html><body><preclass="r"><spanclass="co"># our newly created `mo` variable, put in the mo_name() function</span>
<ahref="#a-first-glimpse-at-results"class="anchor"></a>A first glimpse at results</h3>
<p>An easy <code>ggplot</code> will already give a lot of information, using the included <code><ahref="../reference/ggplot_rsi.html">ggplot_rsi()</a></code> function:</p>