AMR/reference/proportion.html

552 lines
66 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!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"><meta name="description" content="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 summarise() from the dplyr package and also support grouped variables, see Examples.
resistance() should be used to calculate resistance, susceptibility() should be used to calculate susceptibility."><title>Calculate Antimicrobial Resistance — proportion • AMR (for R)</title><!-- favicons --><link rel="icon" type="image/png" sizes="16x16" href="../favicon-16x16.png"><link rel="icon" type="image/png" sizes="32x32" href="../favicon-32x32.png"><link rel="apple-touch-icon" type="image/png" sizes="180x180" href="../apple-touch-icon.png"><link rel="apple-touch-icon" type="image/png" sizes="120x120" href="../apple-touch-icon-120x120.png"><link rel="apple-touch-icon" type="image/png" sizes="76x76" href="../apple-touch-icon-76x76.png"><link rel="apple-touch-icon" type="image/png" sizes="60x60" href="../apple-touch-icon-60x60.png"><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.2.2/bootstrap.min.css" rel="stylesheet"><script src="../deps/bootstrap-5.2.2/bootstrap.bundle.min.js"></script><link href="../deps/Fira_Code-0.4.6/font.css" rel="stylesheet"><!-- Font Awesome icons --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css" integrity="sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk=" crossorigin="anonymous"><link rel="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 --><script src="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 --><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/headroom.min.js" integrity="sha256-AsUX4SJE1+yuDu5+mAVzJbuYNPHj/WroHuZ8Ir/CkE0=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/jQuery.headroom.min.js" integrity="sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4=" crossorigin="anonymous"></script><!-- clipboard.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js" integrity="sha256-inc5kl9MA1hkeYUt+EC3BhlIgyp/2jDIyBLS6k3UxPI=" crossorigin="anonymous"></script><!-- search --><script src="https://cdnjs.cloudflare.com/ajax/libs/fuse.js/6.4.6/fuse.js" integrity="sha512-zv6Ywkjyktsohkbp9bb45V6tEMoWhzFzXis+LrMehmJZZSys19Yxf1dopHx7WzIKxr5tK2dVcYmaCk2uqdjF4A==" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/autocomplete.js/0.38.0/autocomplete.jquery.min.js" integrity="sha512-GU9ayf+66Xx2TmpxqJpliWbT5PiGYxpaG8rfnBEk1LL8l1KGkRShhngwdXK1UgqhAzWpZHSiYPc09/NwDQIGyg==" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mark.js/8.11.1/mark.min.js" integrity="sha512-5CYOlHXGh6QpOFA/TeTylKLWfB3ftPsde7AnmhuitiTX4K5SqCLBeKro6sPS8ilsz1Q4NRx3v8Ko2IBiszzdww==" crossorigin="anonymous"></script><!-- pkgdown --><script src="../pkgdown.js"></script><link href="../extra.css" rel="stylesheet"><script src="../extra.js"></script><meta property="og:title" content="Calculate Antimicrobial Resistance — proportion"><meta property="og:description" content="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 summarise() from the dplyr package and also support grouped variables, see Examples.
resistance() should be used to calculate resistance, susceptibility() should be used to calculate susceptibility."><meta property="og:image" content="https://msberends.github.io/AMR/logo.svg"><meta name="twitter:card" content="summary_large_image"><meta name="twitter:creator" content="@msberends"><meta name="twitter:site" content="@msberends"><!-- mathjax --><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script><script src="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]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]--></head><body>
<a href="#main" class="visually-hidden-focusable">Skip to contents</a>
<nav class="navbar fixed-top navbar-dark navbar-expand-lg bg-primary"><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="">2.0.0.9024</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">
<a href="#" class="nav-link dropdown-toggle" data-bs-toggle="dropdown" role="button" aria-expanded="false" aria-haspopup="true" id="dropdown--how-to">
<span class="fa fa-question-circle"></span>
How to
</a>
<div class="dropdown-menu" aria-labelledby="dropdown--how-to">
<a class="dropdown-item" href="../articles/AMR.html">
<span class="fa fa-directions"></span>
Conduct AMR Analysis
</a>
<a class="dropdown-item" href="../reference/antibiogram.html">
<span class="fa fa-file-prescription"></span>
Generate Antibiogram (Trad./Syndromic/WISCA)
</a>
<a class="dropdown-item" href="../articles/resistance_predict.html">
<span class="fa fa-dice"></span>
Predict Antimicrobial Resistance
</a>
<a class="dropdown-item" href="../articles/datasets.html">
<span class="fa fa-database"></span>
Download Data Sets for Own Use
</a>
<a class="dropdown-item" href="../reference/AMR-options.html">
<span class="fa fa-gear"></span>
Set User- Or Team-specific Package Settings
</a>
<a class="dropdown-item" href="../articles/PCA.html">
<span class="fa fa-compress"></span>
Conduct Principal Component Analysis for AMR
</a>
<a class="dropdown-item" href="../articles/MDR.html">
<span class="fa fa-skull-crossbones"></span>
Determine Multi-Drug Resistance (MDR)
</a>
<a class="dropdown-item" href="../articles/WHONET.html">
<span class="fa fa-globe-americas"></span>
Work with WHONET Data
</a>
<a class="dropdown-item" href="../articles/EUCAST.html">
<span class="fa fa-exchange-alt"></span>
Apply Eucast Rules
</a>
<a class="dropdown-item" href="../reference/mo_property.html">
<span class="fa fa-bug"></span>
Get Taxonomy of a Microorganism
</a>
<a class="dropdown-item" href="../reference/ab_property.html">
<span class="fa fa-capsules"></span>
Get Properties of an Antibiotic Drug
</a>
<a class="dropdown-item" href="../reference/av_property.html">
<span class="fa fa-capsules"></span>
Get Properties of an Antiviral Drug
</a>
</div>
</li>
<li class="nav-item dropdown">
<a href="#" class="nav-link dropdown-toggle" data-bs-toggle="dropdown" role="button" aria-expanded="false" aria-haspopup="true" id="dropdown--with-other-pkgs">
<span class="fa fa-layer-group"></span>
With other pkgs
</a>
<div class="dropdown-menu" aria-labelledby="dropdown--with-other-pkgs">
<a class="dropdown-item" href="../articles/other_pkg.html">
<span class="fa fa-layer-group"></span>
AMR &amp; dplyr/tidyverse
</a>
<a class="dropdown-item" href="../articles/other_pkg.html">
<span class="fa fa-layer-group"></span>
AMR &amp; data.table
</a>
<a class="dropdown-item" href="../articles/other_pkg.html">
<span class="fa fa-layer-group"></span>
AMR &amp; tidymodels
</a>
<a class="dropdown-item" href="../articles/other_pkg.html">
<span class="fa fa-layer-group"></span>
AMR &amp; base R
</a>
</div>
</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><form class="form-inline my-2 my-lg-0" role="search">
<input type="search" class="form-control me-sm-2" aria-label="Toggle navigation" name="search-input" data-search-index="../search.json" id="search-input" placeholder="Search for" autocomplete="off"></form>
<ul class="navbar-nav"><li class="nav-item">
<a class="nav-link" href="../news/index.html">
<span class="far fa far fa-newspaper"></span>
Changelog
</a>
</li>
<li class="nav-item">
<a class="external-link nav-link" href="https://github.com/msberends/AMR">
<span class="fab fa fab 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>Calculate Antimicrobial Resistance</h1>
<small class="dont-index">Source: <a href="https://github.com/msberends/AMR/blob/HEAD/R/proportion.R" class="external-link"><code>R/proportion.R</code></a>, <a href="https://github.com/msberends/AMR/blob/HEAD/R/sir_df.R" class="external-link"><code>R/sir_df.R</code></a></small>
<div class="d-none name"><code>proportion.Rd</code></div>
</div>
<div class="ref-description section level2">
<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><a href="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>
</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">resistance</span><span class="op">(</span><span class="va">...</span>, minimum <span class="op">=</span> <span class="fl">30</span>, as_percent <span class="op">=</span> <span class="cn">FALSE</span>, only_all_tested <span class="op">=</span> <span class="cn">FALSE</span><span class="op">)</span></span>
<span></span>
<span><span class="fu">susceptibility</span><span class="op">(</span><span class="va">...</span>, minimum <span class="op">=</span> <span class="fl">30</span>, as_percent <span class="op">=</span> <span class="cn">FALSE</span>, only_all_tested <span class="op">=</span> <span class="cn">FALSE</span><span class="op">)</span></span>
<span></span>
<span><span class="fu">sir_confidence_interval</span><span class="op">(</span></span>
<span> <span class="va">...</span>,</span>
<span> ab_result <span class="op">=</span> <span class="st">"R"</span>,</span>
<span> minimum <span class="op">=</span> <span class="fl">30</span>,</span>
<span> as_percent <span class="op">=</span> <span class="cn">FALSE</span>,</span>
<span> only_all_tested <span class="op">=</span> <span class="cn">FALSE</span>,</span>
<span> confidence_level <span class="op">=</span> <span class="fl">0.95</span>,</span>
<span> side <span class="op">=</span> <span class="st">"both"</span>,</span>
<span> collapse <span class="op">=</span> <span class="cn">FALSE</span></span>
<span><span class="op">)</span></span>
<span></span>
<span><span class="fu">proportion_R</span><span class="op">(</span><span class="va">...</span>, minimum <span class="op">=</span> <span class="fl">30</span>, as_percent <span class="op">=</span> <span class="cn">FALSE</span>, only_all_tested <span class="op">=</span> <span class="cn">FALSE</span><span class="op">)</span></span>
<span></span>
<span><span class="fu">proportion_IR</span><span class="op">(</span><span class="va">...</span>, minimum <span class="op">=</span> <span class="fl">30</span>, as_percent <span class="op">=</span> <span class="cn">FALSE</span>, only_all_tested <span class="op">=</span> <span class="cn">FALSE</span><span class="op">)</span></span>
<span></span>
<span><span class="fu">proportion_I</span><span class="op">(</span><span class="va">...</span>, minimum <span class="op">=</span> <span class="fl">30</span>, as_percent <span class="op">=</span> <span class="cn">FALSE</span>, only_all_tested <span class="op">=</span> <span class="cn">FALSE</span><span class="op">)</span></span>
<span></span>
<span><span class="fu">proportion_SI</span><span class="op">(</span><span class="va">...</span>, minimum <span class="op">=</span> <span class="fl">30</span>, as_percent <span class="op">=</span> <span class="cn">FALSE</span>, only_all_tested <span class="op">=</span> <span class="cn">FALSE</span><span class="op">)</span></span>
<span></span>
<span><span class="fu">proportion_S</span><span class="op">(</span><span class="va">...</span>, minimum <span class="op">=</span> <span class="fl">30</span>, as_percent <span class="op">=</span> <span class="cn">FALSE</span>, only_all_tested <span class="op">=</span> <span class="cn">FALSE</span><span class="op">)</span></span>
<span></span>
<span><span class="fu">proportion_df</span><span class="op">(</span></span>
<span> <span class="va">data</span>,</span>
<span> translate_ab <span class="op">=</span> <span class="st">"name"</span>,</span>
<span> language <span class="op">=</span> <span class="fu"><a href="translate.html">get_AMR_locale</a></span><span class="op">(</span><span class="op">)</span>,</span>
<span> minimum <span class="op">=</span> <span class="fl">30</span>,</span>
<span> as_percent <span class="op">=</span> <span class="cn">FALSE</span>,</span>
<span> combine_SI <span class="op">=</span> <span class="cn">TRUE</span>,</span>
<span> confidence_level <span class="op">=</span> <span class="fl">0.95</span></span>
<span><span class="op">)</span></span>
<span></span>
<span><span class="fu">sir_df</span><span class="op">(</span></span>
<span> <span class="va">data</span>,</span>
<span> translate_ab <span class="op">=</span> <span class="st">"name"</span>,</span>
<span> language <span class="op">=</span> <span class="fu"><a href="translate.html">get_AMR_locale</a></span><span class="op">(</span><span class="op">)</span>,</span>
<span> minimum <span class="op">=</span> <span class="fl">30</span>,</span>
<span> as_percent <span class="op">=</span> <span class="cn">FALSE</span>,</span>
<span> combine_SI <span class="op">=</span> <span class="cn">TRUE</span>,</span>
<span> confidence_level <span class="op">=</span> <span class="fl">0.95</span></span>
<span><span class="op">)</span></span></code></pre></div>
</div>
<div class="section level2">
<h2 id="source">Source<a class="anchor" aria-label="anchor" href="#source"></a></h2>
<p><strong>M39 Analysis and Presentation of Cumulative Antimicrobial Susceptibility Test Data, 5th Edition</strong>, 2022, <em>Clinical and Laboratory Standards Institute (CLSI)</em>. <a href="https://clsi.org/standards/products/microbiology/documents/m39/" class="external-link">https://clsi.org/standards/products/microbiology/documents/m39/</a>.</p>
</div>
<div class="section level2">
<h2 id="arguments">Arguments<a class="anchor" aria-label="anchor" href="#arguments"></a></h2>
<dl><dt>...</dt>
<dd><p>one or more vectors (or columns) with antibiotic interpretations. They will be transformed internally with <code><a href="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>
<dt>minimum</dt>
<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 <a href="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 <a href="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>
<dt>ab_result</dt>
<dd><p>antibiotic results to test against, must be one or more values of "S", "I", or "R"</p></dd>
<dt>confidence_level</dt>
<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><a href="https://rdrr.io/r/stats/binom.test.html" class="external-link">binom.test()</a></code>, i.e., the Clopper-Pearson method.</p></dd>
<dt>side</dt>
<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>
<dt>collapse</dt>
<dd><p>a <a href="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>
<dt>data</dt>
<dd><p>a <a href="https://rdrr.io/r/base/data.frame.html" class="external-link">data.frame</a> containing columns with class <code><a href="as.sir.html">sir</a></code> (see <code><a href="as.sir.html">as.sir()</a></code>)</p></dd>
<dt>translate_ab</dt>
<dd><p>a column name of the <a href="antibiotics.html">antibiotics</a> data set to translate the antibiotic abbreviations to, using <code><a href="ab_property.html">ab_property()</a></code></p></dd>
<dt>language</dt>
<dd><p>language of the returned text - the default is the current system language (see <code><a href="translate.html">get_AMR_locale()</a></code>) and can also be set with the <a href="AMR-options.html">package option</a> <code><a href="AMR-options.html">AMR_locale</a></code>. Use <code>language = NULL</code> or <code>language = ""</code> to prevent translation.</p></dd>
<dt>combine_SI</dt>
<dd><p>a <a href="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>
</dl></div>
<div class="section level2">
<h2 id="value">Value<a class="anchor" aria-label="anchor" href="#value"></a></h2>
<p>A <a href="https://rdrr.io/r/base/double.html" class="external-link">double</a> or, when <code>as_percent = TRUE</code>, a <a href="https://rdrr.io/r/base/character.html" class="external-link">character</a>.</p>
</div>
<div class="section level2">
<h2 id="details">Details<a class="anchor" aria-label="anchor" href="#details"></a></h2>
<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><a href="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><a href="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><a href="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><a href="as.sir.html">sir</a></code> class (created with <code><a href="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>
</div>
<div class="section level2">
<h2 id="combination-therapy">Combination Therapy<a class="anchor" aria-label="anchor" href="#combination-therapy"></a></h2>
<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>
<p></p><div class="sourceCode"><pre><code><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="sc">--------------------------------------------------------------------</span></span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a> only_all_tested <span class="ot">=</span> <span class="cn">FALSE</span> only_all_tested <span class="ot">=</span> <span class="cn">TRUE</span></span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a> <span class="sc">-----------------------</span> <span class="sc">-----------------------</span></span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a> Drug A Drug B include as include as include as include as</span>
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a> numerator denominator numerator denominator</span>
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true" tabindex="-1"></a><span class="sc">--------</span> <span class="sc">--------</span> <span class="sc">----------</span> <span class="sc">-----------</span> <span class="sc">----------</span> <span class="sc">-----------</span></span>
<span id="cb1-7"><a href="#cb1-7" aria-hidden="true" tabindex="-1"></a> S or I S or I X X X X</span>
<span id="cb1-8"><a href="#cb1-8" aria-hidden="true" tabindex="-1"></a> R S or I X X X X</span>
<span id="cb1-9"><a href="#cb1-9" aria-hidden="true" tabindex="-1"></a> <span class="sc">&lt;</span><span class="cn">NA</span><span class="sc">&gt;</span> S or I X X <span class="sc">-</span> <span class="sc">-</span></span>
<span id="cb1-10"><a href="#cb1-10" aria-hidden="true" tabindex="-1"></a> S or I R X X X X</span>
<span id="cb1-11"><a href="#cb1-11" aria-hidden="true" tabindex="-1"></a> R R <span class="sc">-</span> X <span class="sc">-</span> X</span>
<span id="cb1-12"><a href="#cb1-12" aria-hidden="true" tabindex="-1"></a> <span class="sc">&lt;</span><span class="cn">NA</span><span class="sc">&gt;</span> R <span class="sc">-</span> <span class="sc">-</span> <span class="sc">-</span> <span class="sc">-</span></span>
<span id="cb1-13"><a href="#cb1-13" aria-hidden="true" tabindex="-1"></a> S or I <span class="sc">&lt;</span><span class="cn">NA</span><span class="sc">&gt;</span> X X <span class="sc">-</span> <span class="sc">-</span></span>
<span id="cb1-14"><a href="#cb1-14" aria-hidden="true" tabindex="-1"></a> R <span class="sc">&lt;</span><span class="cn">NA</span><span class="sc">&gt;</span> <span class="sc">-</span> <span class="sc">-</span> <span class="sc">-</span> <span class="sc">-</span></span>
<span id="cb1-15"><a href="#cb1-15" aria-hidden="true" tabindex="-1"></a> <span class="er">&lt;</span><span class="cn">NA</span><span class="sc">&gt;</span> <span class="er">&lt;</span><span class="cn">NA</span><span class="sc">&gt;</span> <span class="sc">-</span> <span class="sc">-</span> <span class="sc">-</span> <span class="sc">-</span></span>
<span id="cb1-16"><a href="#cb1-16" aria-hidden="true" tabindex="-1"></a><span class="sc">--------------------------------------------------------------------</span></span></code></pre><p></p></div>
<p>Please note that, in combination therapies, for <code>only_all_tested = TRUE</code> applies that:</p>
<p></p><div class="sourceCode"><pre><code><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">count_S</span>() <span class="sc">+</span> <span class="fu">count_I</span>() <span class="sc">+</span> <span class="fu">count_R</span>() <span class="ot">=</span> <span class="fu">count_all</span>()</span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">proportion_S</span>() <span class="sc">+</span> <span class="fu">proportion_I</span>() <span class="sc">+</span> <span class="fu">proportion_R</span>() <span class="ot">=</span> <span class="dv">1</span></span></code></pre><p></p></div>
<p>and that, in combination therapies, for <code>only_all_tested = FALSE</code> applies that:</p>
<p></p><div class="sourceCode"><pre><code><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">count_S</span>() <span class="sc">+</span> <span class="fu">count_I</span>() <span class="sc">+</span> <span class="fu">count_R</span>() <span class="sc">&gt;=</span> <span class="fu">count_all</span>()</span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">proportion_S</span>() <span class="sc">+</span> <span class="fu">proportion_I</span>() <span class="sc">+</span> <span class="fu">proportion_R</span>() <span class="sc">&gt;=</span> <span class="dv">1</span></span></code></pre><p></p></div>
<p>Using <code>only_all_tested</code> has no impact when only using one antibiotic as input.</p>
</div>
<div class="section level2">
<h2 id="interpretation-of-sir">Interpretation of SIR<a class="anchor" aria-label="anchor" href="#interpretation-of-sir"></a></h2>
<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 (<a href="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>
<li><p><strong>I - Susceptible, increased exposure</strong> <em><br>
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></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><a href="count.html">count_susceptible()</a></code> (equal to <code><a href="count.html">count_SI()</a></code>) to count susceptible isolates.</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="count.html">count()</a></code> to count resistant and susceptible isolates.</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="co"># example_isolates is a data set available in the AMR package.</span></span></span>
<span class="r-in"><span><span class="co"># run ?example_isolates for more info.</span></span></span>
<span class="r-in"><span><span class="va">example_isolates</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #949494;"># A tibble: 2,000 × 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-01-02 A77334 65 F Clinical B_ESCHR_COLI R NA NA NA </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 2</span> 2002-01-03 A77334 65 F Clinical B_ESCHR_COLI R NA NA NA </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 3</span> 2002-01-07 067927 45 F ICU B_STPHY_EPDR R NA R NA </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 4</span> 2002-01-07 067927 45 F ICU B_STPHY_EPDR R NA R NA </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 5</span> 2002-01-13 067927 45 F ICU B_STPHY_EPDR R NA R NA </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 6</span> 2002-01-13 067927 45 F ICU B_STPHY_EPDR R NA R NA </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 7</span> 2002-01-14 462729 78 M Clinical B_STPHY_AURS R NA S R </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 8</span> 2002-01-14 462729 78 M Clinical B_STPHY_AURS R NA S R </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 9</span> 2002-01-16 067927 45 F ICU B_STPHY_EPDR R NA R NA </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">10</span> 2002-01-17 858515 79 F ICU B_STPHY_EPDR R NA S NA </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #949494;"># 1,990 more rows</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>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #949494;"># FOS &lt;sir&gt;, LNZ &lt;sir&gt;, CIP &lt;sir&gt;, MFX &lt;sir&gt;, VAN &lt;sir&gt;, TEC &lt;sir&gt;,</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #949494;"># TCY &lt;sir&gt;, TGC &lt;sir&gt;, DOX &lt;sir&gt;, ERY &lt;sir&gt;, CLI &lt;sir&gt;, AZM &lt;sir&gt;,</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #949494;"># IPM &lt;sir&gt;, MEM &lt;sir&gt;, MTR &lt;sir&gt;, CHL &lt;sir&gt;, COL &lt;sir&gt;, MUP &lt;sir&gt;, …</span></span>
<span class="r-in"><span></span></span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="co"># base R ------------------------------------------------------------</span></span></span>
<span class="r-in"><span><span class="co"># determines %R</span></span></span>
<span class="r-in"><span><span class="fu">resistance</span><span class="op">(</span><span class="va">example_isolates</span><span class="op">$</span><span class="va">AMX</span><span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [1] 0.5955556</span>
<span class="r-in"><span><span class="fu">sir_confidence_interval</span><span class="op">(</span><span class="va">example_isolates</span><span class="op">$</span><span class="va">AMX</span><span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [1] 0.5688204 0.6218738</span>
<span class="r-in"><span><span class="fu">sir_confidence_interval</span><span class="op">(</span><span class="va">example_isolates</span><span class="op">$</span><span class="va">AMX</span>,</span></span>
<span class="r-in"><span> confidence_level <span class="op">=</span> <span class="fl">0.975</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] 0.5650148 0.6255670</span>
<span class="r-in"><span><span class="fu">sir_confidence_interval</span><span class="op">(</span><span class="va">example_isolates</span><span class="op">$</span><span class="va">AMX</span>,</span></span>
<span class="r-in"><span> confidence_level <span class="op">=</span> <span class="fl">0.975</span>,</span></span>
<span class="r-in"><span> collapse <span class="op">=</span> <span class="st">", "</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] "0.565, 0.626"</span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="co"># determines %S+I:</span></span></span>
<span class="r-in"><span><span class="fu">susceptibility</span><span class="op">(</span><span class="va">example_isolates</span><span class="op">$</span><span class="va">AMX</span><span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [1] 0.4044444</span>
<span class="r-in"><span><span class="fu">sir_confidence_interval</span><span class="op">(</span><span class="va">example_isolates</span><span class="op">$</span><span class="va">AMX</span>,</span></span>
<span class="r-in"><span> ab_result <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">"I"</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] 0.3781262 0.4311796</span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="co"># be more specific</span></span></span>
<span class="r-in"><span><span class="fu">proportion_S</span><span class="op">(</span><span class="va">example_isolates</span><span class="op">$</span><span class="va">AMX</span><span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [1] 0.4022222</span>
<span class="r-in"><span><span class="fu">proportion_SI</span><span class="op">(</span><span class="va">example_isolates</span><span class="op">$</span><span class="va">AMX</span><span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [1] 0.4044444</span>
<span class="r-in"><span><span class="fu">proportion_I</span><span class="op">(</span><span class="va">example_isolates</span><span class="op">$</span><span class="va">AMX</span><span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [1] 0.002222222</span>
<span class="r-in"><span><span class="fu">proportion_IR</span><span class="op">(</span><span class="va">example_isolates</span><span class="op">$</span><span class="va">AMX</span><span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [1] 0.5977778</span>
<span class="r-in"><span><span class="fu">proportion_R</span><span class="op">(</span><span class="va">example_isolates</span><span class="op">$</span><span class="va">AMX</span><span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> [1] 0.5955556</span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="co"># dplyr -------------------------------------------------------------</span></span></span>
<span class="r-in"><span><span class="co"># \donttest{</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">example_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/group_by.html" class="external-link">group_by</a></span><span class="op">(</span><span class="va">ward</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/summarise.html" class="external-link">summarise</a></span><span class="op">(</span></span></span>
<span class="r-in"><span> r <span class="op">=</span> <span class="fu">resistance</span><span class="op">(</span><span class="va">CIP</span><span class="op">)</span>,</span></span>
<span class="r-in"><span> n <span class="op">=</span> <span class="fu"><a href="count.html">n_sir</a></span><span class="op">(</span><span class="va">CIP</span><span class="op">)</span></span></span>
<span class="r-in"><span> <span class="op">)</span> <span class="co"># n_sir works like n_distinct in dplyr, see ?n_sir</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: 3 × 3</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> ward r n</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;dbl&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 0.147 869</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">2</span> ICU 0.190 447</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">3</span> Outpatient 0.161 93</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">example_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/group_by.html" class="external-link">group_by</a></span><span class="op">(</span><span class="va">ward</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/summarise.html" class="external-link">summarise</a></span><span class="op">(</span></span></span>
<span class="r-in"><span> cipro_R <span class="op">=</span> <span class="fu">resistance</span><span class="op">(</span><span class="va">CIP</span><span class="op">)</span>,</span></span>
<span class="r-in"><span> ci_min <span class="op">=</span> <span class="fu">sir_confidence_interval</span><span class="op">(</span><span class="va">CIP</span>, side <span class="op">=</span> <span class="st">"min"</span><span class="op">)</span>,</span></span>
<span class="r-in"><span> ci_max <span class="op">=</span> <span class="fu">sir_confidence_interval</span><span class="op">(</span><span class="va">CIP</span>, side <span class="op">=</span> <span class="st">"max"</span><span class="op">)</span>,</span></span>
<span class="r-in"><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: 3 × 4</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> ward cipro_R ci_min ci_max</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;dbl&gt;</span> <span style="color: #949494; font-style: italic;">&lt;dbl&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> Clinical 0.147 0.124 0.173</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">2</span> ICU 0.190 0.155 0.230</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">3</span> Outpatient 0.161 0.093<span style="text-decoration: underline;">2</span> 0.252</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"># scoped dplyr verbs with antibiotic selectors</span></span></span>
<span class="r-in"><span> <span class="co"># (you could also use across() of course)</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>
<span class="r-in"><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">ward</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/summarise_all.html" class="external-link">summarise_at</a></span><span class="op">(</span></span></span>
<span class="r-in"><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="fu"><a href="antibiotic_class_selectors.html">aminoglycosides</a></span><span class="op">(</span><span class="op">)</span>, <span class="fu"><a href="antibiotic_class_selectors.html">carbapenems</a></span><span class="op">(</span><span class="op">)</span><span class="op">)</span>,</span></span>
<span class="r-in"><span> <span class="va">resistance</span></span></span>
<span class="r-in"><span> <span class="op">)</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> For aminoglycosides() using columns 'GEN' (gentamicin), 'TOB'</span>
<span class="r-msg co"><span class="r-pr">#&gt;</span> (tobramycin), 'AMK' (amikacin), and 'KAN' (kanamycin)</span>
<span class="r-msg co"><span class="r-pr">#&gt;</span> For carbapenems() using columns 'IPM' (imipenem) and 'MEM' (meropenem)</span>
<span class="r-wrn co"><span class="r-pr">#&gt;</span> <span class="warning">Warning: </span>There was 1 warning in `summarise()`.</span>
<span class="r-wrn co"><span class="r-pr">#&gt;</span> <span style="color: #00BBBB;"></span> In argument: `KAN = (function (..., minimum = 30, as_percent = FALSE,</span>
<span class="r-wrn co"><span class="r-pr">#&gt;</span> only_all_tested = FALSE) ...`.</span>
<span class="r-wrn co"><span class="r-pr">#&gt;</span> <span style="color: #00BBBB;"></span> In group 3: `ward = "Outpatient"`.</span>
<span class="r-wrn co"><span class="r-pr">#&gt;</span> Caused by warning:</span>
<span class="r-wrn co"><span class="r-pr">#&gt;</span> <span style="color: #BBBB00;">!</span> Introducing NA: only 23 results available for KAN in group: ward =</span>
<span class="r-wrn co"><span class="r-pr">#&gt;</span> "Outpatient" (minimum = 30).</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #949494;"># A tibble: 3 × 7</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> ward GEN TOB AMK KAN IPM MEM</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;dbl&gt;</span> <span style="color: #949494; font-style: italic;">&lt;dbl&gt;</span> <span style="color: #949494; font-style: italic;">&lt;dbl&gt;</span> <span style="color: #949494; font-style: italic;">&lt;dbl&gt;</span> <span style="color: #949494; font-style: italic;">&lt;dbl&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> Clinical 0.229 0.315 0.626 1 0.049<span style="text-decoration: underline;">8</span> 0.045<span style="text-decoration: underline;">8</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">2</span> ICU 0.290 0.400 0.662 1 0.086<span style="text-decoration: underline;">2</span> 0.089<span style="text-decoration: underline;">4</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">3</span> Outpatient 0.2 0.368 0.605 <span style="color: #BB0000;">NA</span> 0.054<span style="text-decoration: underline;">1</span> 0.054<span style="text-decoration: underline;">1</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">example_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/group_by.html" class="external-link">group_by</a></span><span class="op">(</span><span class="va">ward</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/summarise.html" class="external-link">summarise</a></span><span class="op">(</span></span></span>
<span class="r-in"><span> R <span class="op">=</span> <span class="fu">resistance</span><span class="op">(</span><span class="va">CIP</span>, as_percent <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span>,</span></span>
<span class="r-in"><span> SI <span class="op">=</span> <span class="fu">susceptibility</span><span class="op">(</span><span class="va">CIP</span>, as_percent <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span>,</span></span>
<span class="r-in"><span> n1 <span class="op">=</span> <span class="fu"><a href="count.html">count_all</a></span><span class="op">(</span><span class="va">CIP</span><span class="op">)</span>, <span class="co"># the actual total; sum of all three</span></span></span>
<span class="r-in"><span> n2 <span class="op">=</span> <span class="fu"><a href="count.html">n_sir</a></span><span class="op">(</span><span class="va">CIP</span><span class="op">)</span>, <span class="co"># same - analogous to n_distinct</span></span></span>
<span class="r-in"><span> total <span class="op">=</span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/context.html" class="external-link">n</a></span><span class="op">(</span><span class="op">)</span></span></span>
<span class="r-in"><span> <span class="op">)</span> <span class="co"># NOT the number of tested isolates!</span></span></span>
<span class="r-in"><span></span></span>
<span class="r-in"><span> <span class="co"># Calculate co-resistance between amoxicillin/clav acid and gentamicin,</span></span></span>
<span class="r-in"><span> <span class="co"># so we can see that combination therapy does a lot more than mono therapy:</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 class="fu">susceptibility</span><span class="op">(</span><span class="va">AMC</span><span class="op">)</span> <span class="co"># %SI = 76.3%</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 class="fu"><a href="count.html">count_all</a></span><span class="op">(</span><span class="va">AMC</span><span class="op">)</span> <span class="co"># n = 1879</span></span></span>
<span class="r-in"><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 class="fu">susceptibility</span><span class="op">(</span><span class="va">GEN</span><span class="op">)</span> <span class="co"># %SI = 75.4%</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 class="fu"><a href="count.html">count_all</a></span><span class="op">(</span><span class="va">GEN</span><span class="op">)</span> <span class="co"># n = 1855</span></span></span>
<span class="r-in"><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 class="fu">susceptibility</span><span class="op">(</span><span class="va">AMC</span>, <span class="va">GEN</span><span class="op">)</span> <span class="co"># %SI = 94.1%</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 class="fu"><a href="count.html">count_all</a></span><span class="op">(</span><span class="va">AMC</span>, <span class="va">GEN</span><span class="op">)</span> <span class="co"># n = 1939</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"># See Details on how `only_all_tested` works. Example:</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>
<span class="r-in"><span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/summarise.html" class="external-link">summarise</a></span><span class="op">(</span></span></span>
<span class="r-in"><span> numerator <span class="op">=</span> <span class="fu"><a href="count.html">count_susceptible</a></span><span class="op">(</span><span class="va">AMC</span>, <span class="va">GEN</span><span class="op">)</span>,</span></span>
<span class="r-in"><span> denominator <span class="op">=</span> <span class="fu"><a href="count.html">count_all</a></span><span class="op">(</span><span class="va">AMC</span>, <span class="va">GEN</span><span class="op">)</span>,</span></span>
<span class="r-in"><span> proportion <span class="op">=</span> <span class="fu">susceptibility</span><span class="op">(</span><span class="va">AMC</span>, <span class="va">GEN</span><span class="op">)</span></span></span>
<span class="r-in"><span> <span class="op">)</span></span></span>
<span class="r-in"><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>
<span class="r-in"><span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/summarise.html" class="external-link">summarise</a></span><span class="op">(</span></span></span>
<span class="r-in"><span> numerator <span class="op">=</span> <span class="fu"><a href="count.html">count_susceptible</a></span><span class="op">(</span><span class="va">AMC</span>, <span class="va">GEN</span>, only_all_tested <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span>,</span></span>
<span class="r-in"><span> denominator <span class="op">=</span> <span class="fu"><a href="count.html">count_all</a></span><span class="op">(</span><span class="va">AMC</span>, <span class="va">GEN</span>, only_all_tested <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span>,</span></span>
<span class="r-in"><span> proportion <span class="op">=</span> <span class="fu">susceptibility</span><span class="op">(</span><span class="va">AMC</span>, <span class="va">GEN</span>, only_all_tested <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span></span></span>
<span class="r-in"><span> <span class="op">)</span></span></span>
<span class="r-in"><span></span></span>
<span class="r-in"><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>
<span class="r-in"><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">ward</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/summarise.html" class="external-link">summarise</a></span><span class="op">(</span></span></span>
<span class="r-in"><span> cipro_p <span class="op">=</span> <span class="fu">susceptibility</span><span class="op">(</span><span class="va">CIP</span>, as_percent <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span>,</span></span>
<span class="r-in"><span> cipro_n <span class="op">=</span> <span class="fu"><a href="count.html">count_all</a></span><span class="op">(</span><span class="va">CIP</span><span class="op">)</span>,</span></span>
<span class="r-in"><span> genta_p <span class="op">=</span> <span class="fu">susceptibility</span><span class="op">(</span><span class="va">GEN</span>, as_percent <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span>,</span></span>
<span class="r-in"><span> genta_n <span class="op">=</span> <span class="fu"><a href="count.html">count_all</a></span><span class="op">(</span><span class="va">GEN</span><span class="op">)</span>,</span></span>
<span class="r-in"><span> combination_p <span class="op">=</span> <span class="fu">susceptibility</span><span class="op">(</span><span class="va">CIP</span>, <span class="va">GEN</span>, as_percent <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span>,</span></span>
<span class="r-in"><span> combination_n <span class="op">=</span> <span class="fu"><a href="count.html">count_all</a></span><span class="op">(</span><span class="va">CIP</span>, <span class="va">GEN</span><span class="op">)</span></span></span>
<span class="r-in"><span> <span class="op">)</span></span></span>
<span class="r-in"><span></span></span>
<span class="r-in"><span> <span class="co"># Get proportions S/I/R immediately of all sir columns</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>
<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="va">AMX</span>, <span class="va">CIP</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">proportion_df</span><span class="op">(</span>translate <span class="op">=</span> <span class="cn">FALSE</span><span class="op">)</span></span></span>
<span class="r-in"><span></span></span>
<span class="r-in"><span> <span class="co"># It also supports grouping variables</span></span></span>
<span class="r-in"><span> <span class="co"># (use sir_df to also include the count)</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>
<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="va">ward</span>, <span class="va">AMX</span>, <span class="va">CIP</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/group_by.html" class="external-link">group_by</a></span><span class="op">(</span><span class="va">ward</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">sir_df</span><span class="op">(</span>translate <span class="op">=</span> <span class="cn">FALSE</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: 12 × 7</span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> ward antibiotic interpretation value ci_min ci_max isolates</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">*</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;ord&gt;</span> <span style="color: #949494; font-style: italic;">&lt;dbl&gt;</span> <span style="color: #949494; font-style: italic;">&lt;dbl&gt;</span> <span style="color: #949494; font-style: italic;">&lt;dbl&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 AMX SI 0.423 0.389 0.457 357</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 2</span> Clinical AMX R 0.577 0.543 0.611 487</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 3</span> Clinical CIP SI 0.853 0.827 0.876 741</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 4</span> Clinical CIP R 0.147 0.124 0.173 128</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 5</span> ICU AMX SI 0.369 0.323 0.417 158</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 6</span> ICU AMX R 0.631 0.583 0.677 270</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 7</span> ICU CIP SI 0.810 0.770 0.845 362</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 8</span> ICU CIP R 0.190 0.155 0.230 85</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;"> 9</span> Outpatient AMX SI 0.397 0.288 0.515 31</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">10</span> Outpatient AMX R 0.603 0.485 0.712 47</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">11</span> Outpatient CIP SI 0.839 0.748 0.907 78</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> <span style="color: #BCBCBC;">12</span> Outpatient CIP R 0.161 0.093<span style="text-decoration: underline;">2</span> 0.252 15</span>
<span class="r-in"><span><span class="co"># }</span></span></span>
</code></pre></div>
</div>
</main><aside class="col-md-3"><nav id="toc"><h2>On this page</h2>
</nav></aside></div>
<footer><div class="pkgdown-footer-left">
<p></p><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></p><p><a target="_blank" href="https://www.rug.nl" class="external-link"><img src="https://github.com/msberends/AMR/raw/main/pkgdown/logos/logo_rug.svg" style="max-width: 150px;"></a><a target="_blank" href="https://www.umcg.nl" class="external-link"><img src="https://github.com/msberends/AMR/raw/main/pkgdown/logos/logo_umcg.svg" style="max-width: 150px;"></a></p>
</div>
</footer></div>
</body></html>