mirror of
https://github.com/msberends/AMR.git
synced 2025-07-09 01:22:25 +02:00
(v1.4.0.9008) like variations
This commit is contained in:
@ -39,7 +39,7 @@
|
||||
</button>
|
||||
<span class="navbar-brand">
|
||||
<a class="navbar-link" href="../index.html">AMR (for R)</a>
|
||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.4.0</span>
|
||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.4.0.9008</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@ -187,7 +187,8 @@
|
||||
|
||||
|
||||
|
||||
</header><script src="WHONET_files/header-attrs-2.3/header-attrs.js"></script><script src="WHONET_files/accessible-code-block-0.0.1/empty-anchor.js"></script><div class="row">
|
||||
</header><script src="WHONET_files/accessible-code-block-0.0.1/empty-anchor.js"></script><link href="WHONET_files/anchor-sections-1.0/anchor-sections.css" rel="stylesheet">
|
||||
<script src="WHONET_files/anchor-sections-1.0/anchor-sections.js"></script><div class="row">
|
||||
<div class="col-md-9 contents">
|
||||
<div class="page-header toc-ignore">
|
||||
<h1 data-toc-skip>How to work with WHONET data</h1>
|
||||
@ -206,9 +207,8 @@
|
||||
<p>This tutorial assumes you already imported the WHONET data with e.g. the <a href="https://readxl.tidyverse.org/"><code>readxl</code> package</a>. In RStudio, this can be done using the menu button ‘Import Dataset’ in the tab ‘Environment’. Choose the option ‘From Excel’ and select your exported file. Make sure date fields are imported correctly.</p>
|
||||
<p>An example syntax could look like this:</p>
|
||||
<div class="sourceCode" id="cb1"><pre class="downlit">
|
||||
<span class="fu"><a href="https://rdrr.io/r/base/library.html">library</a></span>(<span class="kw"><a href="https://readxl.tidyverse.org">readxl</a></span>)
|
||||
<span class="kw">data</span> <span class="op"><-</span> <span class="fu"><a href="https://readxl.tidyverse.org/reference/read_excel.html">read_excel</a></span>(path = <span class="st">"path/to/your/file.xlsx"</span>)
|
||||
</pre></div>
|
||||
<span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op">(</span><span class="va"><a href="https://readxl.tidyverse.org">readxl</a></span><span class="op">)</span>
|
||||
<span class="va">data</span> <span class="op"><-</span> <span class="fu"><a href="https://readxl.tidyverse.org/reference/read_excel.html">read_excel</a></span><span class="op">(</span>path <span class="op">=</span> <span class="st">"path/to/your/file.xlsx"</span><span class="op">)</span></pre></div>
|
||||
<p>This package comes with an <a href="https://msberends.github.io/AMR/reference/WHONET.html">example data set <code>WHONET</code></a>. We will use it for this analysis.</p>
|
||||
</div>
|
||||
<div id="preparation" class="section level3">
|
||||
@ -216,11 +216,10 @@
|
||||
<a href="#preparation" class="anchor"></a>Preparation</h3>
|
||||
<p>First, load the relevant packages if you did not yet did this. I use the tidyverse for all of my analyses. All of them. If you don’t know it yet, I suggest you read about it on their website: <a href="https://www.tidyverse.org/" class="uri">https://www.tidyverse.org/</a>.</p>
|
||||
<div class="sourceCode" id="cb2"><pre class="downlit">
|
||||
<span class="fu"><a href="https://rdrr.io/r/base/library.html">library</a></span>(<span class="kw"><a href="https://dplyr.tidyverse.org">dplyr</a></span>) <span class="co"># part of tidyverse</span>
|
||||
<span class="fu"><a href="https://rdrr.io/r/base/library.html">library</a></span>(<span class="kw"><a href="http://ggplot2.tidyverse.org">ggplot2</a></span>) <span class="co"># part of tidyverse</span>
|
||||
<span class="fu"><a href="https://rdrr.io/r/base/library.html">library</a></span>(<span class="kw"><a href="https://msberends.github.io/AMR">AMR</a></span>) <span class="co"># this package</span>
|
||||
<span class="fu"><a href="https://rdrr.io/r/base/library.html">library</a></span>(<span class="kw"><a href="https://github.com/msberends/cleaner">cleaner</a></span>) <span class="co"># to create frequency tables</span>
|
||||
</pre></div>
|
||||
<span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op">(</span><span class="va"><a href="https://dplyr.tidyverse.org">dplyr</a></span><span class="op">)</span> <span class="co"># part of tidyverse</span>
|
||||
<span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op">(</span><span class="va"><a href="http://ggplot2.tidyverse.org">ggplot2</a></span><span class="op">)</span> <span class="co"># part of tidyverse</span>
|
||||
<span class="kw"><a href="https://rdrr.io/r/base/library.html">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 class="co"># this package</span>
|
||||
<span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op">(</span><span class="va"><a href="https://github.com/msberends/cleaner">cleaner</a></span><span class="op">)</span> <span class="co"># to create frequency tables</span></pre></div>
|
||||
<p>We will have to transform some variables to simplify and automate the analysis:</p>
|
||||
<ul>
|
||||
<li>Microorganisms should be transformed to our own microorganism IDs (called an <code>mo</code>) using <a href="https://msberends.github.io/AMR/reference/catalogue_of_life">our Catalogue of Life reference data set</a>, which contains all ~70,000 microorganisms from the taxonomic kingdoms Bacteria, Fungi and Protozoa. We do the tranformation with <code><a href="../reference/as.mo.html">as.mo()</a></code>. This function also recognises almost all WHONET abbreviations of microorganisms.</li>
|
||||
@ -228,19 +227,17 @@
|
||||
</ul>
|
||||
<div class="sourceCode" id="cb3"><pre class="downlit">
|
||||
<span class="co"># transform variables</span>
|
||||
<span class="kw">data</span> <span class="op"><-</span> <span class="kw">WHONET</span> <span class="op">%>%</span>
|
||||
<span class="va">data</span> <span class="op"><-</span> <span class="va">WHONET</span> <span class="op">%>%</span>
|
||||
<span class="co"># get microbial ID based on given organism</span>
|
||||
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/mutate.html">mutate</a></span>(mo = <span class="fu"><a href="../reference/as.mo.html">as.mo</a></span>(<span class="kw">Organism</span>)) <span class="op">%>%</span>
|
||||
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/mutate.html">mutate</a></span><span class="op">(</span>mo <span class="op">=</span> <span class="fu"><a href="../reference/as.mo.html">as.mo</a></span><span class="op">(</span><span class="va">Organism</span><span class="op">)</span><span class="op">)</span> <span class="op">%>%</span>
|
||||
<span class="co"># transform everything from "AMP_ND10" to "CIP_EE" to the new `rsi` class</span>
|
||||
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/mutate_all.html">mutate_at</a></span>(<span class="fu"><a href="https://dplyr.tidyverse.org/reference/vars.html">vars</a></span>(<span class="kw">AMP_ND10</span><span class="op">:</span><span class="kw">CIP_EE</span>), <span class="kw">as.rsi</span>)
|
||||
</pre></div>
|
||||
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/mutate_all.html">mutate_at</a></span><span class="op">(</span><span class="fu"><a href="https://dplyr.tidyverse.org/reference/vars.html">vars</a></span><span class="op">(</span><span class="va">AMP_ND10</span><span class="op">:</span><span class="va">CIP_EE</span><span class="op">)</span>, <span class="va">as.rsi</span><span class="op">)</span></pre></div>
|
||||
<p>No errors or warnings, so all values are transformed succesfully.</p>
|
||||
<p>We also created a package dedicated to data cleaning and checking, called the <code>cleaner</code> package. Its <code><a href="https://rdrr.io/pkg/cleaner/man/freq.html">freq()</a></code> function can be used to create frequency tables.</p>
|
||||
<p>So let’s check our data, with a couple of frequency tables:</p>
|
||||
<div class="sourceCode" id="cb4"><pre class="downlit">
|
||||
<span class="co"># our newly created `mo` variable, put in the mo_name() function</span>
|
||||
<span class="kw">data</span> <span class="op">%>%</span> <span class="fu"><a href="https://rdrr.io/pkg/cleaner/man/freq.html">freq</a></span>(<span class="fu"><a href="../reference/mo_property.html">mo_name</a></span>(<span class="kw">mo</span>), nmax = <span class="fl">10</span>)
|
||||
</pre></div>
|
||||
<span class="va">data</span> <span class="op">%>%</span> <span class="fu"><a href="https://rdrr.io/pkg/cleaner/man/freq.html">freq</a></span><span class="op">(</span><span class="fu"><a href="../reference/mo_property.html">mo_name</a></span><span class="op">(</span><span class="va">mo</span><span class="op">)</span>, nmax <span class="op">=</span> <span class="fl">10</span><span class="op">)</span></pre></div>
|
||||
<p><strong>Frequency table</strong></p>
|
||||
<p>Class: character<br>
|
||||
Length: 500<br>
|
||||
@ -344,15 +341,16 @@ Longest: 40</p>
|
||||
<div class="sourceCode" id="cb5"><pre class="downlit">
|
||||
<span class="co"># our transformed antibiotic columns</span>
|
||||
<span class="co"># amoxicillin/clavulanic acid (J01CR02) as an example</span>
|
||||
<span class="kw">data</span> <span class="op">%>%</span> <span class="fu"><a href="https://rdrr.io/pkg/cleaner/man/freq.html">freq</a></span>(<span class="kw">AMC_ND2</span>)
|
||||
</pre></div>
|
||||
<span class="va">data</span> <span class="op">%>%</span> <span class="fu"><a href="https://rdrr.io/pkg/cleaner/man/freq.html">freq</a></span><span class="op">(</span><span class="va">AMC_ND2</span><span class="op">)</span></pre></div>
|
||||
<p><strong>Frequency table</strong></p>
|
||||
<p>Class: factor > ordered > rsi (numeric)<br>
|
||||
Length: 500<br>
|
||||
Levels: 3: S < I < R<br>
|
||||
Available: 481 (96.2%, NA: 19 = 3.8%)<br>
|
||||
Unique: 3</p>
|
||||
<p>%SI: 78.59%</p>
|
||||
<p>Drug: Amoxicillin/clavulanic acid (AMC, J01CR02)<br>
|
||||
Drug group: Beta-lactams/penicillins<br>
|
||||
%SI: 78.59%</p>
|
||||
<table class="table">
|
||||
<thead><tr class="header">
|
||||
<th align="left"></th>
|
||||
@ -395,11 +393,10 @@ Unique: 3</p>
|
||||
<a href="#a-first-glimpse-at-results" class="anchor"></a>A first glimpse at results</h3>
|
||||
<p>An easy <code>ggplot</code> will already give a lot of information, using the included <code><a href="../reference/ggplot_rsi.html">ggplot_rsi()</a></code> function:</p>
|
||||
<div class="sourceCode" id="cb6"><pre class="downlit">
|
||||
<span class="kw">data</span> <span class="op">%>%</span>
|
||||
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/group_by.html">group_by</a></span>(<span class="kw">Country</span>) <span class="op">%>%</span>
|
||||
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/select.html">select</a></span>(<span class="kw">Country</span>, <span class="kw">AMP_ND2</span>, <span class="kw">AMC_ED20</span>, <span class="kw">CAZ_ED10</span>, <span class="kw">CIP_ED5</span>) <span class="op">%>%</span>
|
||||
<span class="fu"><a href="../reference/ggplot_rsi.html">ggplot_rsi</a></span>(translate_ab = <span class="st">'ab'</span>, facet = <span class="st">"Country"</span>, datalabels = <span class="fl">FALSE</span>)
|
||||
</pre></div>
|
||||
<span class="va">data</span> <span class="op">%>%</span>
|
||||
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/group_by.html">group_by</a></span><span class="op">(</span><span class="va">Country</span><span class="op">)</span> <span class="op">%>%</span>
|
||||
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/select.html">select</a></span><span class="op">(</span><span class="va">Country</span>, <span class="va">AMP_ND2</span>, <span class="va">AMC_ED20</span>, <span class="va">CAZ_ED10</span>, <span class="va">CIP_ED5</span><span class="op">)</span> <span class="op">%>%</span>
|
||||
<span class="fu"><a href="../reference/ggplot_rsi.html">ggplot_rsi</a></span><span class="op">(</span>translate_ab <span class="op">=</span> <span class="st">'ab'</span>, facet <span class="op">=</span> <span class="st">"Country"</span>, datalabels <span class="op">=</span> <span class="cn">FALSE</span><span class="op">)</span></pre></div>
|
||||
<p><img src="WHONET_files/figure-html/unnamed-chunk-7-1.png" width="720"></p>
|
||||
</div>
|
||||
</div>
|
||||
@ -417,7 +414,7 @@ Unique: 3</p>
|
||||
</div>
|
||||
|
||||
<div class="pkgdown">
|
||||
<p>Site built with <a href="https://pkgdown.r-lib.org/">pkgdown</a> 1.5.1.9000.</p>
|
||||
<p>Site built with <a href="https://pkgdown.r-lib.org/">pkgdown</a> 1.6.1.</p>
|
||||
</div>
|
||||
|
||||
</footer>
|
||||
|
Reference in New Issue
Block a user