<scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"integrity="sha256-U5ZEeKfGNOja007MMD3YBI0A3OSZOQbeG6z2f2Y0hu8="crossorigin="anonymous"></script><!-- Font Awesome icons --><linkrel="stylesheet"href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"integrity="sha256-eZrrJcwDc/3uDhsdt61sL2oOBY362qM3lon1gyExkL0="crossorigin="anonymous">
<ahref="#needed-r-packages"class="anchor"></a>Needed R packages</h2>
<p>As with many uses in R, we need some additional packages for AMR analysis. Our package works closely together with the <ahref="https://www.tidyverse.org">tidyverse packages</a><ahref="https://dplyr.tidyverse.org/"><code>dplyr</code></a> and <ahref="https://ggplot2.tidyverse.org"><code>ggplot2</code></a> by <ahref="https://www.linkedin.com/in/hadleywickham/">Dr Hadley Wickham</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 <code>AMR</code> package depends on these packages and even extends their use and functions.</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 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"><aclass="sourceLine"id="cb2-1"title="1"><spanclass="co"># resistance prediction of piperacillin/tazobactam (pita):</span></a>
<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><ahref="../reference/resistance_predict.html">resistance_predict(..., info = FALSE)</a></code>.</p>
<pre><code>#> NOTE: Using column `date` as input for `col_date`.
#>
#> Logistic regression model (logit) with binomial distribution
#> (Dispersion parameter for binomial family taken to be 1)
#>
#> Null deviance: 59.794 on 14 degrees of freedom
#> Residual deviance: 35.191 on 13 degrees of freedom
#> AIC: 93.464
#>
#> Number of Fisher Scoring iterations: 4</code></pre>
<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>
<aclass="sourceLine"id="cb4-2"title="2"><spanclass="co">#> year value se_min se_max observations observed estimated</span></a>
<aclass="sourceLine"id="cb4-3"title="3"><spanclass="co">#> 1 2003 0.06250000 NA NA 32 0.06250000 0.06177594</span></a>
<aclass="sourceLine"id="cb4-4"title="4"><spanclass="co">#> 2 2004 0.08536585 NA NA 82 0.08536585 0.06846343</span></a>
<aclass="sourceLine"id="cb4-5"title="5"><spanclass="co">#> 3 2005 0.10000000 NA NA 60 0.10000000 0.07581637</span></a>
<aclass="sourceLine"id="cb4-6"title="6"><spanclass="co">#> 4 2006 0.05084746 NA NA 59 0.05084746 0.08388789</span></a>
<aclass="sourceLine"id="cb4-7"title="7"><spanclass="co">#> 5 2007 0.12121212 NA NA 66 0.12121212 0.09273250</span></a>
<aclass="sourceLine"id="cb4-8"title="8"><spanclass="co">#> 6 2008 0.04166667 NA NA 72 0.04166667 0.10240539</span></a>
<aclass="sourceLine"id="cb4-9"title="9"><spanclass="co">#> 7 2009 0.01639344 NA NA 61 0.01639344 0.11296163</span></a>
<aclass="sourceLine"id="cb4-10"title="10"><spanclass="co">#> 8 2010 0.09433962 NA NA 53 0.09433962 0.12445516</span></a>
<aclass="sourceLine"id="cb4-11"title="11"><spanclass="co">#> 9 2011 0.18279570 NA NA 93 0.18279570 0.13693759</span></a>
<aclass="sourceLine"id="cb4-12"title="12"><spanclass="co">#> 10 2012 0.30769231 NA NA 65 0.30769231 0.15045682</span></a>
<aclass="sourceLine"id="cb4-13"title="13"><spanclass="co">#> 11 2013 0.08620690 NA NA 58 0.08620690 0.16505550</span></a>
<aclass="sourceLine"id="cb4-14"title="14"><spanclass="co">#> 12 2014 0.15254237 NA NA 59 0.15254237 0.18076926</span></a>
<aclass="sourceLine"id="cb4-15"title="15"><spanclass="co">#> 13 2015 0.27272727 NA NA 55 0.27272727 0.19762493</span></a>
<aclass="sourceLine"id="cb4-16"title="16"><spanclass="co">#> 14 2016 0.25000000 NA NA 84 0.25000000 0.21563859</span></a>
<aclass="sourceLine"id="cb4-17"title="17"><spanclass="co">#> 15 2017 0.16279070 NA NA 86 0.16279070 0.23481370</span></a>
<aclass="sourceLine"id="cb4-18"title="18"><spanclass="co">#> 16 2018 0.25513926 0.2228376 0.2874409 NA NA 0.25513926</span></a>
<aclass="sourceLine"id="cb4-19"title="19"><spanclass="co">#> 17 2019 0.27658825 0.2386811 0.3144954 NA NA 0.27658825</span></a>
<aclass="sourceLine"id="cb4-20"title="20"><spanclass="co">#> 18 2020 0.29911630 0.2551715 0.3430611 NA NA 0.29911630</span></a>
<aclass="sourceLine"id="cb4-21"title="21"><spanclass="co">#> 19 2021 0.32266085 0.2723340 0.3729877 NA NA 0.32266085</span></a>
<aclass="sourceLine"id="cb4-22"title="22"><spanclass="co">#> 20 2022 0.34714076 0.2901847 0.4040968 NA NA 0.34714076</span></a>
<aclass="sourceLine"id="cb4-23"title="23"><spanclass="co">#> 21 2023 0.37245666 0.3087318 0.4361815 NA NA 0.37245666</span></a>
<aclass="sourceLine"id="cb4-24"title="24"><spanclass="co">#> 22 2024 0.39849187 0.3279750 0.4690088 NA NA 0.39849187</span></a>
<aclass="sourceLine"id="cb4-25"title="25"><spanclass="co">#> 23 2025 0.42511415 0.3479042 0.5023241 NA NA 0.42511415</span></a>
<aclass="sourceLine"id="cb4-26"title="26"><spanclass="co">#> 24 2026 0.45217796 0.3684992 0.5358568 NA NA 0.45217796</span></a>
<aclass="sourceLine"id="cb4-27"title="27"><spanclass="co">#> 25 2027 0.47952757 0.3897276 0.5693275 NA NA 0.47952757</span></a>
<aclass="sourceLine"id="cb4-28"title="28"><spanclass="co">#> 26 2028 0.50700045 0.4115444 0.6024565 NA NA 0.50700045</span></a>
<aclass="sourceLine"id="cb4-29"title="29"><spanclass="co">#> 27 2029 0.53443111 0.4338908 0.6349714 NA NA 0.53443111</span></a></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>
<aclass="sourceLine"id="cb8-7"title="7"><spanclass="co">#></span><spanclass="al">NOTE</span><spanclass="co">: Using column `date` as input for `col_date`.</span></a></code></pre></div>
<p>Vancomycin resistance could be 100% in ten years, but might also stay around 0%.</p>
<p>You can define the model with the <code>model</code> parameter. The default model 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><ahref="https://www.rdocumentation.org/packages/stats/topics/glm">glm(..., family = binomial)</a></code></td>
<td>Generalised linear model with binomial distribution</td>
</tr>
<trclass="even">
<td>
<code>"loglin"</code> or <code>"poisson"</code>
</td>
<td><code><ahref="https://www.rdocumentation.org/packages/stats/topics/glm">glm(..., family = poisson)</a></code></td>
<td>Generalised linear model with poisson distribution</td>
<p>For the vancomycin resistance in Gram positive bacteria, a linear model might be more appropriate since no (left half of a) binomial distribution is to be expected based on the observed years:</p>
<aclass="sourceLine"id="cb9-7"title="7"><spanclass="co">#></span><spanclass="al">NOTE</span><spanclass="co">: Using column `date` as input for `col_date`.</span></a></code></pre></div>
<p>Developed by <ahref="https://www.rug.nl/staff/m.s.berends/">Matthijs S. Berends</a>, <ahref="https://www.rug.nl/staff/c.f.luz/">Christian F. Luz</a>, <ahref="https://www.rug.nl/staff/c.glasner/">Corinna Glasner</a>, <ahref="https://www.rug.nl/staff/a.w.friedrich/">Alex W. Friedrich</a>, <ahref="https://www.rug.nl/staff/b.sinha/">Bhanu N. M. Sinha</a>.</p>
</div>
<divclass="pkgdown">
<p>Site built with <ahref="https://pkgdown.r-lib.org/">pkgdown</a> 1.3.0.</p>