WHONET.Rmd
This tutorial assumes you already imported the WHONET data with e.g. the readxl
package. 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.
An example syntax could look like this:
This package comes with an example data set WHONET
. We will use it for this analysis.
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: https://www.tidyverse.org/.
We will have to transform some variables to simplify and automate the analysis:
mo
) using the ITIS reference data set, which contains all ~20,000 microorganisms from the taxonomic kingdoms Bacteria, Fungi and Protozoa. We do the tranformation with as.mo()
. This function also recognises almost all WHONET abbreviations of microorganisms."S"
, "I"
or "R"
. That is exactly where the as.rsi()
function is for.# transform variables
data <- WHONET %>%
# get microbial ID based on given organism
mutate(mo = as.mo(Organism)) %>%
# transform everything from "AMP_ND10" to "CIP_EE" to the new `rsi` class
mutate_at(vars(AMP_ND10:CIP_EE), as.rsi)
No errors or warnings, so all values are transformed succesfully. Let’s check it though, with a couple of frequency tables:
Frequency table of mo
from a data.frame
(500 x 54)
Class: mo
(character
)
Length: 500 (of which NA: 0 = 0.00%)
Unique: 56
Families: 14
Genera: 23
Species: 51
Item | Count | Percent | Cum. Count | Cum. Percent | |
---|---|---|---|---|---|
1 | B_ESCHR_COL | 127 | 25.4% | 127 | 25.4% |
2 | B_STPHY_CNS | 80 | 16.0% | 207 | 41.4% |
3 | B_STPHY_AUR | 50 | 10.0% | 257 | 51.4% |
4 | B_STPHY_EPI | 37 | 7.4% | 294 | 58.8% |
5 | B_STRPTC_PNE | 31 | 6.2% | 325 | 65.0% |
6 | B_STPHY_HOM | 23 | 4.6% | 348 | 69.6% |
7 | B_PROTS_MIR | 13 | 2.6% | 361 | 72.2% |
8 | B_KLBSL_PNE | 11 | 2.2% | 372 | 74.4% |
9 | B_PDMNS_AER | 8 | 1.6% | 380 | 76.0% |
10 | B_STPHY_CAP | 8 | 1.6% | 388 | 77.6% |
(omitted 46 entries, n = 112 [22.4%])
# our transformed antibiotic columns
# amoxicillin/clavulanic acid (J01CR02) as an example
data %>% freq(AMC_ND2)
Frequency table of AMC_ND2
from a data.frame
(500 x 54)
Class: factor
> ordered
> rsi
(numeric
)
Levels: S < I < R
Length: 500 (of which NA: 41 = 8.20%)
Unique: 3
%IR: 28.98% (ratio S : IR = 1.0 : 0.4)
Item | Count | Percent | Cum. Count | Cum. Percent | |
---|---|---|---|---|---|
1 | S | 326 | 71.0% | 326 | 71.0% |
2 | R | 111 | 24.2% | 437 | 95.2% |
3 | I | 22 | 4.8% | 459 | 100.0% |