<!-- Generated by pkgdown: do not edit by hand --><htmllang="en"><head><metahttp-equiv="Content-Type"content="text/html; charset=UTF-8"><metacharset="utf-8"><metahttp-equiv="X-UA-Compatible"content="IE=edge"><metaname="viewport"content="width=device-width, initial-scale=1, shrink-to-fit=no"><metaname="description"content="Thesefunctionscanbeusedtocalculatethe(co-)resistanceorsusceptibilityofmicrobialisolates(i.e.percentageofS,SI,I,IRorR).Allfunctionssupportquasiquotationwithpipes,canbeusedinsummarise()fromthedplyrpackageandalsosupportgroupedvariables,seeExamples.
resistance() should be used to calculate resistance, susceptibility() should be used to calculate susceptibility."><title>Calculate Antimicrobial Resistance — proportion • AMR (for R)</title><!-- favicons --><linkrel="icon"type="image/png"sizes="16x16"href="../favicon-16x16.png"><linkrel="icon"type="image/png"sizes="32x32"href="../favicon-32x32.png"><linkrel="apple-touch-icon"type="image/png"sizes="180x180"href="../apple-touch-icon.png"><linkrel="apple-touch-icon"type="image/png"sizes="120x120"href="../apple-touch-icon-120x120.png"><linkrel="apple-touch-icon"type="image/png"sizes="76x76"href="../apple-touch-icon-76x76.png"><linkrel="apple-touch-icon"type="image/png"sizes="60x60"href="../apple-touch-icon-60x60.png"><scriptsrc="../deps/jquery-3.6.0/jquery-3.6.0.min.js"></script><metaname="viewport"content="width=device-width, initial-scale=1, shrink-to-fit=no"><linkhref="../deps/bootstrap-5.2.2/bootstrap.min.css"rel="stylesheet"><scriptsrc="../deps/bootstrap-5.2.2/bootstrap.bundle.min.js"></script><linkhref="../deps/Fira_Code-0.4.6/font.css"rel="stylesheet"><!-- Font Awesome icons --><linkrel="stylesheet"href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css"integrity="sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk="crossorigin="anonymous"><linkrel="stylesheet"href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/v4-shims.min.css"integrity="sha256-wZjR52fzng1pJHwx4aV2AO3yyTOXrcDW7jBpJtTwVxw="crossorigin="anonymous"><!-- bootstrap-toc --><scriptsrc="https://cdn.jsdelivr.net/gh/afeld/bootstrap-toc@v1.0.1/dist/bootstrap-toc.min.js"integrity="sha256-4veVQbu7//Lk5TSmc7YV48MxtMy98e26cf5MrgZYnwo="crossorigin="anonymous"></script><!-- headroom.js --><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/headroom.min.js"integrity="sha256-AsUX4SJE1+yuDu5+mAVzJbuYNPHj/WroHuZ8Ir/CkE0="crossorigin="anonymous"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/jQuery.headroom.min.js"integrity="sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4="crossorigin="anonymous"></script><!-- clipboard.js --><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js"integrity="sha256-inc5kl9MA1hkeYUt+EC3BhlIgyp/2jDIyBLS6k3UxPI="crossorigin="anonymous"></script><!-- search --><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/fuse.js/6.4.6/fuse.js"integrity="sha512-zv6Ywkjyktsohkbp9bb45V6tEMoWhzFzXis+LrMehmJZZSys19Yxf1dopHx7WzIKxr5tK2dVcYmaCk2uqdjF4A=="crossorigin="anonymous"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/autocomplete.js/0.38.0/autocomplete.jquery.min.js"integrity="sha512-GU9ayf+66Xx2TmpxqJpliWbT5PiGYxpaG8rfnBEk1LL8l1KGkRShhngwdXK1UgqhAzWpZHSiYPc09/NwDQIGyg=="crossorigin="anonymous"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/mark.js/8.11.1/mark.min.js"integrity="sha512-5CYOlHXGh6QpOFA/TeTylKLWfB3ftPsde7AnmhuitiTX4K5SqCLBeKro6sPS8ilsz1Q4NRx3v8Ko2IBiszzdww=="crossorigin="anonymous"></script><!-- pkgdown --><scriptsrc="../pkgdown.js"></script><linkhref="../extra.css"rel="stylesheet"><scriptsrc="../extra.js"></script><metaproperty="og:title"content="Calculate Antimicrobial Resistance — proportion"><metaproperty="og:description"content="Thesefunctionscanbeusedtocalculatethe(co-)resistanceorsusceptibilityofmicrobialisolates(i.e.percentageofS,SI,I,IRorR).Allfunctionssupportquasiquotationwithpipes,canbeusedinsummarise()fromthedplyrpackageandalsosupportgroupedvariables,seeExamples.
resistance() should be used to calculate resistance, susceptibility() should be used to calculate susceptibility."><metaproperty="og:image"content="https://msberends.github.io/AMR/logo.svg"><metaname="twitter:card"content="summary_large_image"><metaname="twitter:creator"content="@msberends"><metaname="twitter:site"content="@msberends"><!-- mathjax --><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js"integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k="crossorigin="anonymous"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js"integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA="crossorigin="anonymous"></script><!--[if lt IE 9]>
<p>These functions can be used to calculate the (co-)resistance or susceptibility of microbial isolates (i.e. percentage of S, SI, I, IR or R). All functions support quasiquotation with pipes, can be used in <code><ahref="https://dplyr.tidyverse.org/reference/summarise.html"class="external-link">summarise()</a></code> from the <code>dplyr</code> package and also support grouped variables, see <em>Examples</em>.</p>
<p><code>resistance()</code> should be used to calculate resistance, <code>susceptibility()</code> should be used to calculate susceptibility.<br></p>
<span> language <spanclass="op">=</span><spanclass="fu"><ahref="translate.html">get_AMR_locale</a></span><spanclass="op">(</span><spanclass="op">)</span>,</span>
<span> language <spanclass="op">=</span><spanclass="fu"><ahref="translate.html">get_AMR_locale</a></span><spanclass="op">(</span><spanclass="op">)</span>,</span>
<p><strong>M39 Analysis and Presentation of Cumulative Antimicrobial Susceptibility Test Data, 5th Edition</strong>, 2022, <em>Clinical and Laboratory Standards Institute (CLSI)</em>. <ahref="https://clsi.org/standards/products/microbiology/documents/m39/"class="external-link">https://clsi.org/standards/products/microbiology/documents/m39/</a>.</p>
<dd><p>one or more vectors (or columns) with antibiotic interpretations. They will be transformed internally with <code><ahref="as.sir.html">as.sir()</a></code> if needed. Use multiple columns to calculate (the lack of) co-resistance: the probability where one of two drugs have a resistant or susceptible result. See <em>Examples</em>.</p></dd>
<dd><p>the minimum allowed number of available (tested) isolates. Any isolate count lower than <code>minimum</code> will return <code>NA</code> with a warning. The default number of <code>30</code> isolates is advised by the Clinical and Laboratory Standards Institute (CLSI) as best practice, see <em>Source</em>.</p></dd>
<dt>as_percent</dt>
<dd><p>a <ahref="https://rdrr.io/r/base/logical.html"class="external-link">logical</a> to indicate whether the output must be returned as a hundred fold with % sign (a character). A value of <code>0.123456</code> will then be returned as <code>"12.3%"</code>.</p></dd>
<dt>only_all_tested</dt>
<dd><p>(for combination therapies, i.e. using more than one variable for <code>...</code>): a <ahref="https://rdrr.io/r/base/logical.html"class="external-link">logical</a> to indicate that isolates must be tested for all antibiotics, see section <em>Combination Therapy</em> below</p></dd>
<dd><p>the confidence level for the returned confidence interval. For the calculation, the number of S or SI isolates, and R isolates are compared with the total number of available isolates with R, S, or I by using <code><ahref="https://rdrr.io/r/stats/binom.test.html"class="external-link">binom.test()</a></code>, i.e., the Clopper-Pearson method.</p></dd>
<dd><p>the side of the confidence interval to return. The default is <code>"both"</code> for a length 2 vector, but can also be (abbreviated as) <code>"min"</code>/<code>"left"</code>/<code>"lower"</code>/<code>"less"</code> or <code>"max"</code>/<code>"right"</code>/<code>"higher"</code>/<code>"greater"</code>.</p></dd>
<dd><p>a <ahref="https://rdrr.io/r/base/logical.html"class="external-link">logical</a> to indicate whether the output values should be 'collapsed', i.e. be merged together into one value, or a character value to use for collapsing</p></dd>
<dd><p>a <ahref="https://rdrr.io/r/base/data.frame.html"class="external-link">data.frame</a> containing columns with class <code><ahref="as.sir.html">sir</a></code> (see <code><ahref="as.sir.html">as.sir()</a></code>)</p></dd>
<dd><p>a column name of the <ahref="antibiotics.html">antibiotics</a> data set to translate the antibiotic abbreviations to, using <code><ahref="ab_property.html">ab_property()</a></code></p></dd>
<dd><p>language of the returned text - the default is the current system language (see <code><ahref="translate.html">get_AMR_locale()</a></code>) and can also be set with the <ahref="AMR-options.html">package option</a><code><ahref="AMR-options.html">AMR_locale</a></code>. Use <code>language = NULL</code> or <code>language = ""</code> to prevent translation.</p></dd>
<dd><p>a <ahref="https://rdrr.io/r/base/logical.html"class="external-link">logical</a> to indicate whether all values of S and I must be merged into one, so the output only consists of S+I vs. R (susceptible vs. resistant) - the default is <code>TRUE</code></p></dd>
<p>A <ahref="https://rdrr.io/r/base/double.html"class="external-link">double</a> or, when <code>as_percent = TRUE</code>, a <ahref="https://rdrr.io/r/base/character.html"class="external-link">character</a>.</p>
<p>The function <code>resistance()</code> is equal to the function <code>proportion_R()</code>. The function <code>susceptibility()</code> is equal to the function <code>proportion_SI()</code>.</p>
<p>Use <code>sir_confidence_interval()</code> to calculate the confidence interval, which relies on <code><ahref="https://rdrr.io/r/stats/binom.test.html"class="external-link">binom.test()</a></code>, i.e., the Clopper-Pearson method. This function returns a vector of length 2 at default for antimicrobial <em>resistance</em>. Change the <code>side</code> argument to "left"/"min" or "right"/"max" to return a single value, and change the <code>ab_result</code> argument to e.g. <code>c("S", "I")</code> to test for antimicrobial <em>susceptibility</em>, see Examples.</p>
<p><strong>Remember that you should filter your data to let it contain only first isolates!</strong> This is needed to exclude duplicates and to reduce selection bias. Use <code><ahref="first_isolate.html">first_isolate()</a></code> to determine them in your data set with one of the four available algorithms.</p>
<p>These functions are not meant to count isolates, but to calculate the proportion of resistance/susceptibility. Use the <code><ahref="count.html">count()</a></code> functions to count isolates. The function <code>susceptibility()</code> is essentially equal to <code>count_susceptible() / count_all()</code>. <em>Low counts can influence the outcome - the <code>proportion</code> functions may camouflage this, since they only return the proportion (albeit being dependent on the <code>minimum</code> argument).</em></p>
<p>The function <code>proportion_df()</code> takes any variable from <code>data</code> that has an <code><ahref="as.sir.html">sir</a></code> class (created with <code><ahref="as.sir.html">as.sir()</a></code>) and calculates the proportions S, I, and R. It also supports grouped variables. The function <code>sir_df()</code> works exactly like <code>proportion_df()</code>, but adds the number of isolates.</p>
<p>When using more than one variable for <code>...</code> (= combination therapy), use <code>only_all_tested</code> to only count isolates that are tested for all antibiotics/variables that you test them for. See this example for two antibiotics, Drug A and Drug B, about how <code>susceptibility()</code> works to calculate the %SI:</p>
<spanid="cb1-7"><ahref="#cb1-7"aria-hidden="true"tabindex="-1"></a> S or I S or I X X X X</span>
<spanid="cb1-8"><ahref="#cb1-8"aria-hidden="true"tabindex="-1"></a> R S or I X X X X</span>
<spanid="cb1-9"><ahref="#cb1-9"aria-hidden="true"tabindex="-1"></a><spanclass="sc"><</span><spanclass="cn">NA</span><spanclass="sc">></span> S or I X X <spanclass="sc">-</span><spanclass="sc">-</span></span>
<spanid="cb1-10"><ahref="#cb1-10"aria-hidden="true"tabindex="-1"></a> S or I R X X X X</span>
<spanid="cb1-11"><ahref="#cb1-11"aria-hidden="true"tabindex="-1"></a> R R <spanclass="sc">-</span> X <spanclass="sc">-</span> X</span>
<spanid="cb1-12"><ahref="#cb1-12"aria-hidden="true"tabindex="-1"></a><spanclass="sc"><</span><spanclass="cn">NA</span><spanclass="sc">></span> R <spanclass="sc">-</span><spanclass="sc">-</span><spanclass="sc">-</span><spanclass="sc">-</span></span>
<spanid="cb1-13"><ahref="#cb1-13"aria-hidden="true"tabindex="-1"></a> S or I <spanclass="sc"><</span><spanclass="cn">NA</span><spanclass="sc">></span> X X <spanclass="sc">-</span><spanclass="sc">-</span></span>
<spanid="cb1-14"><ahref="#cb1-14"aria-hidden="true"tabindex="-1"></a> R <spanclass="sc"><</span><spanclass="cn">NA</span><spanclass="sc">></span><spanclass="sc">-</span><spanclass="sc">-</span><spanclass="sc">-</span><spanclass="sc">-</span></span>
<p>In 2019, the European Committee on Antimicrobial Susceptibility Testing (EUCAST) has decided to change the definitions of susceptibility testing categories S, I, and R as shown below (<ahref="https://www.eucast.org/newsiandr/"class="external-link">https://www.eucast.org/newsiandr/</a>):</p><ul><li><p><strong>S - Susceptible, standard dosing regimen</strong><br>
A microorganism is categorised as "Susceptible, standard dosing regimen", when there is a high likelihood of therapeutic success using a standard dosing regimen of the agent.</p></li>
A microorganism is categorised as "Susceptible, Increased exposure</em>" when there is a high likelihood of therapeutic success because exposure to the agent is increased by adjusting the dosing regimen or by its concentration at the site of infection.</p></li>
<li><p><strong>R = Resistant</strong><br>
A microorganism is categorised as "Resistant" when there is a high likelihood of therapeutic failure even when there is increased exposure.</p><ul><li><p><em>Exposure</em> is a function of how the mode of administration, dose, dosing interval, infusion time, as well as distribution and excretion of the antimicrobial agent will influence the infecting organism at the site of infection.</p></li>
</ul><p>This AMR package honours this insight. Use <code>susceptibility()</code> (equal to <code>proportion_SI()</code>) to determine antimicrobial susceptibility and <code><ahref="count.html">count_susceptible()</a></code> (equal to <code><ahref="count.html">count_SI()</a></code>) to count susceptible isolates.</p>
<divclass="sourceCode"><preclass="sourceCode r"><code><spanclass="r-in"><span><spanclass="co"># example_isolates is a data set available in the AMR package.</span></span></span>
<spanclass="r-in"><span><spanclass="co"># run ?example_isolates for more info.</span></span></span>
<spanclass="r-out co"><spanclass="r-pr">#></span><spanstyle="color: #BCBCBC;"> 1</span> 2002-01-02 A77334 65 F Clinical B_ESCHR_COLI R NA NA NA </span>
<spanclass="r-out co"><spanclass="r-pr">#></span><spanstyle="color: #BCBCBC;"> 2</span> 2002-01-03 A77334 65 F Clinical B_ESCHR_COLI R NA NA NA </span>
<spanclass="r-out co"><spanclass="r-pr">#></span><spanstyle="color: #BCBCBC;"> 3</span> 2002-01-07 067927 45 F ICU B_STPHY_EPDR R NA R NA </span>
<spanclass="r-out co"><spanclass="r-pr">#></span><spanstyle="color: #BCBCBC;"> 4</span> 2002-01-07 067927 45 F ICU B_STPHY_EPDR R NA R NA </span>
<spanclass="r-out co"><spanclass="r-pr">#></span><spanstyle="color: #BCBCBC;"> 5</span> 2002-01-13 067927 45 F ICU B_STPHY_EPDR R NA R NA </span>
<spanclass="r-out co"><spanclass="r-pr">#></span><spanstyle="color: #BCBCBC;"> 6</span> 2002-01-13 067927 45 F ICU B_STPHY_EPDR R NA R NA </span>
<spanclass="r-out co"><spanclass="r-pr">#></span><spanstyle="color: #BCBCBC;"> 7</span> 2002-01-14 462729 78 M Clinical B_STPHY_AURS R NA S R </span>
<spanclass="r-out co"><spanclass="r-pr">#></span><spanstyle="color: #BCBCBC;"> 8</span> 2002-01-14 462729 78 M Clinical B_STPHY_AURS R NA S R </span>
<spanclass="r-out co"><spanclass="r-pr">#></span><spanstyle="color: #BCBCBC;"> 9</span> 2002-01-16 067927 45 F ICU B_STPHY_EPDR R NA R NA </span>
<spanclass="r-out co"><spanclass="r-pr">#></span><spanstyle="color: #BCBCBC;">10</span> 2002-01-17 858515 79 F ICU B_STPHY_EPDR R NA S NA </span>
<spanclass="r-in"><span> r <spanclass="op">=</span><spanclass="fu">resistance</span><spanclass="op">(</span><spanclass="va">CIP</span><spanclass="op">)</span>,</span></span>
<spanclass="r-in"><span> n <spanclass="op">=</span><spanclass="fu"><ahref="count.html">n_sir</a></span><spanclass="op">(</span><spanclass="va">CIP</span><spanclass="op">)</span></span></span>
<spanclass="r-in"><span><spanclass="op">)</span><spanclass="co"># n_sir works like n_distinct in dplyr, see ?n_sir</span></span></span>
<spanclass="r-in"><span> ci_min <spanclass="op">=</span><spanclass="fu">sir_confidence_interval</span><spanclass="op">(</span><spanclass="va">CIP</span>, side <spanclass="op">=</span><spanclass="st">"min"</span><spanclass="op">)</span>,</span></span>
<spanclass="r-in"><span> ci_max <spanclass="op">=</span><spanclass="fu">sir_confidence_interval</span><spanclass="op">(</span><spanclass="va">CIP</span>, side <spanclass="op">=</span><spanclass="st">"max"</span><spanclass="op">)</span>,</span></span>
<spanclass="r-wrn co"><spanclass="r-pr">#></span><spanstyle="color: #00BBBB;">ℹ</span> In group 3: `ward = "Outpatient"`.</span>
<spanclass="r-wrn co"><spanclass="r-pr">#></span> Caused by warning:</span>
<spanclass="r-wrn co"><spanclass="r-pr">#></span><spanstyle="color: #BBBB00;">!</span> Introducing NA: only 23 results available for KAN in group: ward =</span>
<spanclass="r-in"><span> R <spanclass="op">=</span><spanclass="fu">resistance</span><spanclass="op">(</span><spanclass="va">CIP</span>, as_percent <spanclass="op">=</span><spanclass="cn">TRUE</span><spanclass="op">)</span>,</span></span>
<spanclass="r-in"><span> SI <spanclass="op">=</span><spanclass="fu">susceptibility</span><spanclass="op">(</span><spanclass="va">CIP</span>, as_percent <spanclass="op">=</span><spanclass="cn">TRUE</span><spanclass="op">)</span>,</span></span>
<spanclass="r-in"><span> n1 <spanclass="op">=</span><spanclass="fu"><ahref="count.html">count_all</a></span><spanclass="op">(</span><spanclass="va">CIP</span><spanclass="op">)</span>, <spanclass="co"># the actual total; sum of all three</span></span></span>
<spanclass="r-in"><span> n2 <spanclass="op">=</span><spanclass="fu"><ahref="count.html">n_sir</a></span><spanclass="op">(</span><spanclass="va">CIP</span><spanclass="op">)</span>, <spanclass="co"># same - analogous to n_distinct</span></span></span>
<spanclass="r-in"><span> total <spanclass="op">=</span><spanclass="fu"><ahref="https://dplyr.tidyverse.org/reference/context.html"class="external-link">n</a></span><spanclass="op">(</span><spanclass="op">)</span></span></span>
<spanclass="r-in"><span><spanclass="op">)</span><spanclass="co"># NOT the number of tested isolates!</span></span></span>
<spanclass="r-in"><span><spanclass="va">example_isolates</span><spanclass="op"><ahref="https://magrittr.tidyverse.org/reference/pipe.html"class="external-link">%>%</a></span><spanclass="fu"><ahref="count.html">count_all</a></span><spanclass="op">(</span><spanclass="va">AMC</span><spanclass="op">)</span><spanclass="co"># n = 1879</span></span></span>
<spanclass="r-in"><span><spanclass="va">example_isolates</span><spanclass="op"><ahref="https://magrittr.tidyverse.org/reference/pipe.html"class="external-link">%>%</a></span><spanclass="fu"><ahref="count.html">count_all</a></span><spanclass="op">(</span><spanclass="va">GEN</span><spanclass="op">)</span><spanclass="co"># n = 1855</span></span></span>
<spanclass="r-in"><span><spanclass="va">example_isolates</span><spanclass="op"><ahref="https://magrittr.tidyverse.org/reference/pipe.html"class="external-link">%>%</a></span><spanclass="fu"><ahref="count.html">count_all</a></span><spanclass="op">(</span><spanclass="va">AMC</span>, <spanclass="va">GEN</span><spanclass="op">)</span><spanclass="co"># n = 1939</span></span></span>
<p></p><p><code>AMR</code> (for R). Free and open-source, licenced under the <atarget="_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 <atarget="_blank"href="https://www.rug.nl"class="external-link">University of Groningen</a> and <atarget="_blank"href="https://www.umcg.nl"class="external-link">University Medical Center Groningen</a> in The Netherlands.</p>