<!-- 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">
<p>As with many uses in R, we need some additional packages for AMR data analysis. Our package works closely together with the <ahref="https://www.tidyverse.org"class="external-link">tidyverse packages</a><ahref="https://dplyr.tidyverse.org/"class="external-link"><code>dplyr</code></a> and <ahref="https://ggplot2.tidyverse.org"class="external-link"><code>ggplot2</code></a>. The tidyverse tremendously improves the way we conduct data science - it allows for a very natural way of writing syntaxes and creating beautiful plots in R.</p>
<p>Our package contains a function <code><ahref="../reference/resistance_predict.html">resistance_predict()</a></code>, which takes the same input as functions for <ahref="./AMR.html">other AMR data analysis</a>. Based on a date column, it calculates cases per year and uses a regression model to predict antimicrobial resistance.</p>
<p>It is basically as easy as:</p>
<divclass="sourceCode"id="cb2"><preclass="sourceCode r"><codeclass="sourceCode r"><spanid="cb2-1"><ahref="#cb2-1"aria-hidden="true"tabindex="-1"></a><spanclass="co"># resistance prediction of piperacillin/tazobactam (TZP):</span></span>
<p>The function will look for a date column itself if <code>col_date</code> is not set.</p>
<p>When running any of these commands, a summary of the regression model will be printed unless using <code>resistance_predict(..., info = FALSE)</code>.</p>
<p>This text is only a printed summary - the actual result (output) of the function is a <code>data.frame</code> containing for each year: the number of observations, the actual observed resistance, the estimated resistance and the standard error below and above the estimation:</p>
<span><spanclass="co"># year value se_min se_max observations observed estimated</span></span>
<span><spanclass="co"># 1 2002 0.20000000 NA NA 15 0.20000000 0.05616378</span></span>
<span><spanclass="co"># 2 2003 0.06250000 NA NA 32 0.06250000 0.06163839</span></span>
<span><spanclass="co"># 3 2004 0.08536585 NA NA 82 0.08536585 0.06760841</span></span>
<span><spanclass="co"># 4 2005 0.05000000 NA NA 60 0.05000000 0.07411100</span></span>
<span><spanclass="co"># 5 2006 0.05084746 NA NA 59 0.05084746 0.08118454</span></span>
<span><spanclass="co"># 6 2007 0.12121212 NA NA 66 0.12121212 0.08886843</span></span>
<span><spanclass="co"># 7 2008 0.04166667 NA NA 72 0.04166667 0.09720264</span></span>
<span><spanclass="co"># 8 2009 0.01639344 NA NA 61 0.01639344 0.10622731</span></span>
<span><spanclass="co"># 9 2010 0.05660377 NA NA 53 0.05660377 0.11598223</span></span>
<span><spanclass="co"># 10 2011 0.18279570 NA NA 93 0.18279570 0.12650615</span></span>
<span><spanclass="co"># 11 2012 0.30769231 NA NA 65 0.30769231 0.13783610</span></span>
<span><spanclass="co"># 12 2013 0.06896552 NA NA 58 0.06896552 0.15000651</span></span>
<span><spanclass="co"># 13 2014 0.10000000 NA NA 60 0.10000000 0.16304829</span></span>
<span><spanclass="co"># 14 2015 0.23636364 NA NA 55 0.23636364 0.17698785</span></span>
<span><spanclass="co"># 15 2016 0.22619048 NA NA 84 0.22619048 0.19184597</span></span>
<span><spanclass="co"># 16 2017 0.16279070 NA NA 86 0.16279070 0.20763675</span></span>
<span><spanclass="co"># 17 2018 0.22436641 0.1938710 0.2548618 NA NA 0.22436641</span></span>
<span><spanclass="co"># 18 2019 0.24203228 0.2062911 0.2777735 NA NA 0.24203228</span></span>
<span><spanclass="co"># 19 2020 0.26062172 0.2191758 0.3020676 NA NA 0.26062172</span></span>
<span><spanclass="co"># 20 2021 0.28011130 0.2325557 0.3276669 NA NA 0.28011130</span></span>
<span><spanclass="co"># 21 2022 0.30046606 0.2464567 0.3544755 NA NA 0.30046606</span></span>
<span><spanclass="co"># 22 2023 0.32163907 0.2609011 0.3823771 NA NA 0.32163907</span></span>
<span><spanclass="co"># 23 2024 0.34357130 0.2759081 0.4112345 NA NA 0.34357130</span></span>
<span><spanclass="co"># 24 2025 0.36619175 0.2914934 0.4408901 NA NA 0.36619175</span></span>
<span><spanclass="co"># 25 2026 0.38941799 0.3076686 0.4711674 NA NA 0.38941799</span></span>
<span><spanclass="co"># 26 2027 0.41315710 0.3244399 0.5018743 NA NA 0.41315710</span></span>
<span><spanclass="co"># 27 2028 0.43730688 0.3418075 0.5328063 NA NA 0.43730688</span></span>
<span><spanclass="co"># 28 2029 0.46175755 0.3597639 0.5637512 NA NA 0.46175755</span></span>
<span><spanclass="co"># 29 2030 0.48639359 0.3782932 0.5944939 NA NA 0.48639359</span></span>
<span><spanclass="co"># 30 2031 0.51109592 0.3973697 0.6248221 NA NA 0.51109592</span></span>
<span><spanclass="co"># 31 2032 0.53574417 0.4169574 0.6545309 NA NA 0.53574417</span></span></code></pre></div>
<p>The function <code>plot</code> is available in base R, and can be extended by other packages to depend the output based on the type of input. We extended its function to cope with resistance predictions:</p>
<p>This is the fastest way to plot the result. It automatically adds the right axes, error bars, titles, number of available observations and type of model.</p>
<p>We also support the <code>ggplot2</code> package with our custom function <code><ahref="../reference/resistance_predict.html">ggplot_rsi_predict()</a></code> to create more appealing plots:</p>
<span><spanclass="fu"><ahref="https://dplyr.tidyverse.org/reference/filter.html"class="external-link">filter</a></span><spanclass="op">(</span><spanclass="fu"><ahref="../reference/mo_property.html">mo_gramstain</a></span><spanclass="op">(</span><spanclass="va">mo</span>, language <spanclass="op">=</span><spanclass="cn">NULL</span><spanclass="op">)</span><spanclass="op">==</span><spanclass="st">"Gram-positive"</span><spanclass="op">)</span><spanclass="op"><ahref="https://magrittr.tidyverse.org/reference/pipe.html"class="external-link">%>%</a></span></span>
<span><spanclass="fu"><ahref="../reference/resistance_predict.html">resistance_predict</a></span><spanclass="op">(</span>col_ab <spanclass="op">=</span><spanclass="st">"VAN"</span>, year_min <spanclass="op">=</span><spanclass="fl">2010</span>, info <spanclass="op">=</span><spanclass="cn">FALSE</span>, model <spanclass="op">=</span><spanclass="st">"binomial"</span><spanclass="op">)</span><spanclass="op"><ahref="https://magrittr.tidyverse.org/reference/pipe.html"class="external-link">%>%</a></span></span>
<p>Vancomycin resistance could be 100% in ten years, but might remain very low.</p>
<p>You can define the model with the <code>model</code> parameter. The model chosen above is a generalised linear regression model using a binomial distribution, assuming that a period of zero resistance was followed by a period of increasing resistance leading slowly to more and more resistance.</p>
<p>Valid values are:</p>
<tableclass="table">
<colgroup>
<colwidth="32%">
<colwidth="25%">
<colwidth="42%">
</colgroup>
<thead><trclass="header">
<th>Input values</th>
<th>Function used by R</th>
<th>Type of model</th>
</tr></thead>
<tbody>
<trclass="odd">
<td>
<code>"binomial"</code> or <code>"binom"</code> or <code>"logit"</code>
</td>
<td><code>glm(..., family = binomial)</code></td>
<td>Generalised linear model with binomial distribution</td>
</tr>
<trclass="even">
<td>
<code>"loglin"</code> or <code>"poisson"</code>
</td>
<td><code>glm(..., family = poisson)</code></td>
<td>Generalised linear model with poisson distribution</td>
<span><spanclass="fu"><ahref="https://dplyr.tidyverse.org/reference/filter.html"class="external-link">filter</a></span><spanclass="op">(</span><spanclass="fu"><ahref="../reference/mo_property.html">mo_gramstain</a></span><spanclass="op">(</span><spanclass="va">mo</span>, language <spanclass="op">=</span><spanclass="cn">NULL</span><spanclass="op">)</span><spanclass="op">==</span><spanclass="st">"Gram-positive"</span><spanclass="op">)</span><spanclass="op"><ahref="https://magrittr.tidyverse.org/reference/pipe.html"class="external-link">%>%</a></span></span>
<span><spanclass="fu"><ahref="../reference/resistance_predict.html">resistance_predict</a></span><spanclass="op">(</span>col_ab <spanclass="op">=</span><spanclass="st">"VAN"</span>, year_min <spanclass="op">=</span><spanclass="fl">2010</span>, info <spanclass="op">=</span><spanclass="cn">FALSE</span>, model <spanclass="op">=</span><spanclass="st">"linear"</span><spanclass="op">)</span><spanclass="op"><ahref="https://magrittr.tidyverse.org/reference/pipe.html"class="external-link">%>%</a></span></span>
<span><spanclass="co"># year 0.09883005 0.02295317 4.305725 1.664395e-05</span></span></code></pre></div>
</div>
</div>
</main><asideclass="col-md-3"><navid="toc"><h2>On this page</h2>
</nav></aside>
</div>
<footer><divclass="pkgdown-footer-left">
<p></p>
<p><code>AMR</code> (for R). Developed at the <atarget="_blank"href="https://www.rug.nl"class="external-link">University of Groningen</a> in collaboration with non-profit organisations<br><atarget="_blank"href="https://www.certe.nl"class="external-link">Certe Medical Diagnostics and Advice Foundation</a> and <atarget="_blank"href="https://www.umcg.nl"class="external-link">University Medical Center Groningen</a>.</p>