1
0
mirror of https://github.com/msberends/AMR.git synced 2024-12-27 08:46:12 +01:00
AMR/articles/resistance_predict.html

367 lines
27 KiB
HTML
Raw Normal View History

2022-08-21 16:59:35 +02:00
<!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="AMR">
<title>How to predict antimicrobial resistance • 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.1.3/bootstrap.min.css" rel="stylesheet">
<script src="../deps/bootstrap-5.1.3/bootstrap.bundle.min.js"></script><link href="../deps/Fira_Code-0.4.2/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.rawgit.com/afeld/bootstrap-toc/v1.0.1/dist/bootstrap-toc.min.js"></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="How to predict antimicrobial resistance">
<meta property="og:description" content="AMR">
<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">
2022-10-05 12:32:07 +02:00
<meta name="twitter:site" content="@msberends">
2022-08-21 16:59:35 +02:00
<!-- 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>
2022-10-29 14:24:08 +02:00
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">1.8.2.9034</small>
2022-08-21 16:59:35 +02:00
<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">
<a class="nav-link" href="../index.html">
<span class="fa fa-home"></span>
Home
</a>
</li>
<li class="active 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="../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>
Data sets for download / own use
</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/SPSS.html">
<span class="fa fa-file-upload"></span>
Import data from SPSS/SAS/Stata
</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 properties of a microorganism
</a>
<a class="dropdown-item" href="../reference/ab_property.html">
<span class="fa fa-capsules"></span>
Get properties of an antibiotic
</a>
</div>
</li>
<li class="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>
<li class="nav-item">
<a class="nav-link" href="../news/index.html">
<span class="far fa far fa-newspaper"></span>
Changelog
</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="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-article">
<div class="row">
<main id="main" class="col-md-9"><div class="page-header">
<img src="../logo.svg" class="logo" alt=""><h1>How to predict antimicrobial resistance</h1>
<small class="dont-index">Source: <a href="https://github.com/msberends/AMR/blob/HEAD/vignettes/resistance_predict.Rmd" class="external-link"><code>vignettes/resistance_predict.Rmd</code></a></small>
<div class="d-none name"><code>resistance_predict.Rmd</code></div>
</div>
<div class="section level2">
<h2 id="needed-r-packages">Needed R packages<a class="anchor" aria-label="anchor" href="#needed-r-packages"></a>
</h2>
2022-10-29 14:24:08 +02:00
<p>As with many uses in R, we need some additional packages for AMR data
analysis. Our package works closely together with the <a href="https://www.tidyverse.org" class="external-link">tidyverse packages</a> <a href="https://dplyr.tidyverse.org/" class="external-link"><code>dplyr</code></a> and <a href="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 <code>AMR</code> package depends on these packages and even
extends their use and functions.</p>
2022-08-21 16:59:35 +02:00
<div class="sourceCode" id="cb1"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://dplyr.tidyverse.org" class="external-link">dplyr</a></span><span class="op">)</span></span>
<span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://ggplot2.tidyverse.org" class="external-link">ggplot2</a></span><span class="op">)</span></span>
<span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://msberends.github.io/AMR/">AMR</a></span><span class="op">)</span></span>
<span></span>
<span><span class="co"># (if not yet installed, install with:)</span></span>
<span><span class="co"># install.packages(c("tidyverse", "AMR"))</span></span></code></pre></div>
</div>
<div class="section level2">
<h2 id="prediction-analysis">Prediction analysis<a class="anchor" aria-label="anchor" href="#prediction-analysis"></a>
</h2>
2022-10-29 14:24:08 +02:00
<p>Our package contains a function <code><a href="../reference/resistance_predict.html">resistance_predict()</a></code>,
which takes the same input as functions for <a href="./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>
2022-08-21 16:59:35 +02:00
<p>It is basically as easy as:</p>
2022-08-28 22:45:38 +02:00
<div class="sourceCode" id="cb2"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># resistance prediction of piperacillin/tazobactam (TZP):</span></span>
<span><span class="fu"><a href="../reference/resistance_predict.html">resistance_predict</a></span><span class="op">(</span>tbl <span class="op">=</span> <span class="va">example_isolates</span>, col_date <span class="op">=</span> <span class="st">"date"</span>, col_ab <span class="op">=</span> <span class="st">"TZP"</span>, model <span class="op">=</span> <span class="st">"binomial"</span><span class="op">)</span></span>
<span></span>
<span><span class="co"># or:</span></span>
<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="fu"><a href="../reference/resistance_predict.html">resistance_predict</a></span><span class="op">(</span></span>
<span> col_ab <span class="op">=</span> <span class="st">"TZP"</span>,</span>
<span> model <span class="op">=</span> <span class="st">"binomial"</span></span>
<span> <span class="op">)</span></span>
<span></span>
<span><span class="co"># to bind it to object 'predict_TZP' for example:</span></span>
<span><span class="va">predict_TZP</span> <span class="op">&lt;-</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="fu"><a href="../reference/resistance_predict.html">resistance_predict</a></span><span class="op">(</span></span>
<span> col_ab <span class="op">=</span> <span class="st">"TZP"</span>,</span>
<span> model <span class="op">=</span> <span class="st">"binomial"</span></span>
<span> <span class="op">)</span></span></code></pre></div>
2022-10-29 14:24:08 +02:00
<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>
2022-08-21 17:29:49 +02:00
<div class="sourceCode" id="cb3"><pre class="downlit sourceCode r">
2022-08-21 16:59:35 +02:00
<code class="sourceCode R"><span><span class="va">predict_TZP</span></span>
2022-08-28 22:45:38 +02:00
<span><span class="co"># <span style="color: #949494;"># A tibble: 31 × 7</span></span></span>
<span><span class="co"># year value se_min se_max observations observed estimated</span></span>
<span><span class="co"># <span style="color: #BCBCBC;">*</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;int&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>
<span><span class="co"># <span style="color: #BCBCBC;"> 1</span> <span style="text-decoration: underline;">2</span>002 0.2 <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> 15 0.2 0.056<span style="text-decoration: underline;">2</span></span></span>
<span><span class="co"># <span style="color: #BCBCBC;"> 2</span> <span style="text-decoration: underline;">2</span>003 0.062<span style="text-decoration: underline;">5</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> 32 0.062<span style="text-decoration: underline;">5</span> 0.061<span style="text-decoration: underline;">6</span></span></span>
<span><span class="co"># <span style="color: #BCBCBC;"> 3</span> <span style="text-decoration: underline;">2</span>004 0.085<span style="text-decoration: underline;">4</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> 82 0.085<span style="text-decoration: underline;">4</span> 0.067<span style="text-decoration: underline;">6</span></span></span>
<span><span class="co"># <span style="color: #BCBCBC;"> 4</span> <span style="text-decoration: underline;">2</span>005 0.05 <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> 60 0.05 0.074<span style="text-decoration: underline;">1</span></span></span>
<span><span class="co"># <span style="color: #BCBCBC;"> 5</span> <span style="text-decoration: underline;">2</span>006 0.050<span style="text-decoration: underline;">8</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> 59 0.050<span style="text-decoration: underline;">8</span> 0.081<span style="text-decoration: underline;">2</span></span></span>
<span><span class="co"># <span style="color: #BCBCBC;"> 6</span> <span style="text-decoration: underline;">2</span>007 0.121 <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> 66 0.121 0.088<span style="text-decoration: underline;">9</span></span></span>
<span><span class="co"># <span style="color: #BCBCBC;"> 7</span> <span style="text-decoration: underline;">2</span>008 0.041<span style="text-decoration: underline;">7</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> 72 0.041<span style="text-decoration: underline;">7</span> 0.097<span style="text-decoration: underline;">2</span></span></span>
<span><span class="co"># <span style="color: #BCBCBC;"> 8</span> <span style="text-decoration: underline;">2</span>009 0.016<span style="text-decoration: underline;">4</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> 61 0.016<span style="text-decoration: underline;">4</span> 0.106 </span></span>
<span><span class="co"># <span style="color: #BCBCBC;"> 9</span> <span style="text-decoration: underline;">2</span>010 0.056<span style="text-decoration: underline;">6</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> 53 0.056<span style="text-decoration: underline;">6</span> 0.116 </span></span>
<span><span class="co"># <span style="color: #BCBCBC;">10</span> <span style="text-decoration: underline;">2</span>011 0.183 <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> 93 0.183 0.127 </span></span>
<span><span class="co"># <span style="color: #949494;"># … with 21 more rows</span></span></span></code></pre></div>
2022-10-29 14:24:08 +02:00
<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>
2022-08-21 17:29:49 +02:00
<div class="sourceCode" id="cb4"><pre class="downlit sourceCode r">
2022-08-21 16:59:35 +02:00
<code class="sourceCode R"><span><span class="fu"><a href="../reference/plot.html">plot</a></span><span class="op">(</span><span class="va">predict_TZP</span><span class="op">)</span></span></code></pre></div>
<p><img src="resistance_predict_files/figure-html/unnamed-chunk-4-1.png" width="720"></p>
2022-10-29 14:24:08 +02:00
<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><a href="../reference/resistance_predict.html">ggplot_rsi_predict()</a></code> to create more appealing
plots:</p>
2022-08-21 17:29:49 +02:00
<div class="sourceCode" id="cb5"><pre class="downlit sourceCode r">
2022-08-21 16:59:35 +02:00
<code class="sourceCode R"><span><span class="fu"><a href="../reference/resistance_predict.html">ggplot_rsi_predict</a></span><span class="op">(</span><span class="va">predict_TZP</span><span class="op">)</span></span></code></pre></div>
<p><img src="resistance_predict_files/figure-html/unnamed-chunk-5-1.png" width="720"></p>
2022-08-21 17:29:49 +02:00
<div class="sourceCode" id="cb6"><pre class="downlit sourceCode r">
2022-08-21 16:59:35 +02:00
<code class="sourceCode R"><span></span>
<span><span class="co"># choose for error bars instead of a ribbon</span></span>
<span><span class="fu"><a href="../reference/resistance_predict.html">ggplot_rsi_predict</a></span><span class="op">(</span><span class="va">predict_TZP</span>, ribbon <span class="op">=</span> <span class="cn">FALSE</span><span class="op">)</span></span></code></pre></div>
<p><img src="resistance_predict_files/figure-html/unnamed-chunk-5-2.png" width="720"></p>
<div class="section level3">
<h3 id="choosing-the-right-model">Choosing the right model<a class="anchor" aria-label="anchor" href="#choosing-the-right-model"></a>
</h3>
2022-10-29 14:24:08 +02:00
<p>Resistance is not easily predicted; if we look at vancomycin
resistance in Gram-positive bacteria, the spread (i.e. standard error)
is enormous:</p>
2022-08-21 17:29:49 +02:00
<div class="sourceCode" id="cb7"><pre class="downlit sourceCode r">
2022-08-21 16:59:35 +02:00
<code class="sourceCode R"><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="fu"><a href="https://dplyr.tidyverse.org/reference/filter.html" class="external-link">filter</a></span><span class="op">(</span><span class="fu"><a href="../reference/mo_property.html">mo_gramstain</a></span><span class="op">(</span><span class="va">mo</span>, language <span class="op">=</span> <span class="cn">NULL</span><span class="op">)</span> <span class="op">==</span> <span class="st">"Gram-positive"</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span></span>
2022-08-28 22:45:38 +02:00
<span> <span class="fu"><a href="../reference/resistance_predict.html">resistance_predict</a></span><span class="op">(</span>col_ab <span class="op">=</span> <span class="st">"VAN"</span>, year_min <span class="op">=</span> <span class="fl">2010</span>, info <span class="op">=</span> <span class="cn">FALSE</span>, model <span class="op">=</span> <span class="st">"binomial"</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span></span>
2022-08-21 16:59:35 +02:00
<span> <span class="fu"><a href="../reference/resistance_predict.html">ggplot_rsi_predict</a></span><span class="op">(</span><span class="op">)</span></span>
<span><span class="co"># Using column 'date' as input for `col_date`.</span></span></code></pre></div>
<p><img src="resistance_predict_files/figure-html/unnamed-chunk-6-1.png" width="720"></p>
2022-10-29 14:24:08 +02:00
<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>
2022-08-21 16:59:35 +02:00
<p>Valid values are:</p>
<table class="table">
<colgroup>
<col width="32%">
<col width="25%">
<col width="42%">
</colgroup>
<thead><tr class="header">
<th>Input values</th>
<th>Function used by R</th>
<th>Type of model</th>
</tr></thead>
<tbody>
<tr class="odd">
<td>
2022-10-29 14:24:08 +02:00
<code>"binomial"</code> or <code>"binom"</code> or
<code>"logit"</code>
2022-08-21 16:59:35 +02:00
</td>
<td><code>glm(..., family = binomial)</code></td>
<td>Generalised linear model with binomial distribution</td>
</tr>
<tr class="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>
</tr>
<tr class="odd">
<td>
<code>"lin"</code> or <code>"linear"</code>
</td>
<td><code><a href="https://rdrr.io/r/stats/lm.html" class="external-link">lm()</a></code></td>
<td>Linear model</td>
</tr>
</tbody>
</table>
2022-10-29 14:24:08 +02:00
<p>For the vancomycin resistance in Gram-positive bacteria, a linear
model might be more appropriate:</p>
2022-08-21 17:29:49 +02:00
<div class="sourceCode" id="cb8"><pre class="downlit sourceCode r">
2022-08-21 16:59:35 +02:00
<code class="sourceCode R"><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="fu"><a href="https://dplyr.tidyverse.org/reference/filter.html" class="external-link">filter</a></span><span class="op">(</span><span class="fu"><a href="../reference/mo_property.html">mo_gramstain</a></span><span class="op">(</span><span class="va">mo</span>, language <span class="op">=</span> <span class="cn">NULL</span><span class="op">)</span> <span class="op">==</span> <span class="st">"Gram-positive"</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span></span>
2022-08-28 22:45:38 +02:00
<span> <span class="fu"><a href="../reference/resistance_predict.html">resistance_predict</a></span><span class="op">(</span>col_ab <span class="op">=</span> <span class="st">"VAN"</span>, year_min <span class="op">=</span> <span class="fl">2010</span>, info <span class="op">=</span> <span class="cn">FALSE</span>, model <span class="op">=</span> <span class="st">"linear"</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span></span>
2022-08-21 16:59:35 +02:00
<span> <span class="fu"><a href="../reference/resistance_predict.html">ggplot_rsi_predict</a></span><span class="op">(</span><span class="op">)</span></span>
<span><span class="co"># Using column 'date' as input for `col_date`.</span></span></code></pre></div>
<p><img src="resistance_predict_files/figure-html/unnamed-chunk-7-1.png" width="720"></p>
2022-10-29 14:24:08 +02:00
<p>The model itself is also available from the object, as an
<code>attribute</code>:</p>
2022-08-21 17:29:49 +02:00
<div class="sourceCode" id="cb9"><pre class="downlit sourceCode r">
2022-08-21 16:59:35 +02:00
<code class="sourceCode R"><span><span class="va">model</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/attributes.html" class="external-link">attributes</a></span><span class="op">(</span><span class="va">predict_TZP</span><span class="op">)</span><span class="op">$</span><span class="va">model</span></span>
<span></span>
<span><span class="fu"><a href="https://rdrr.io/r/base/summary.html" class="external-link">summary</a></span><span class="op">(</span><span class="va">model</span><span class="op">)</span><span class="op">$</span><span class="va">family</span></span>
<span><span class="co"># </span></span>
<span><span class="co"># Family: binomial </span></span>
<span><span class="co"># Link function: logit</span></span>
<span></span>
<span><span class="fu"><a href="https://rdrr.io/r/base/summary.html" class="external-link">summary</a></span><span class="op">(</span><span class="va">model</span><span class="op">)</span><span class="op">$</span><span class="va">coefficients</span></span>
<span><span class="co"># Estimate Std. Error z value Pr(&gt;|z|)</span></span>
<span><span class="co"># (Intercept) -200.67944891 46.17315349 -4.346237 1.384932e-05</span></span>
<span><span class="co"># year 0.09883005 0.02295317 4.305725 1.664395e-05</span></span></code></pre></div>
</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). Developed at the <a target="_blank" href="https://www.rug.nl" class="external-link">University of Groningen</a> in collaboration with non-profit organisations<br><a target="_blank" href="https://www.certe.nl" class="external-link">Certe Medical Diagnostics and Advice Foundation</a> and <a target="_blank" href="https://www.umcg.nl" class="external-link">University Medical Center Groningen</a>.</p>
</div>
<div class="pkgdown-footer-right">
<p></p>
2022-10-05 12:32:07 +02:00
<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></p>
2022-08-21 16:59:35 +02:00
</div>
</footer>
</div>
</body>
</html>