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.
We created a package dedicated to data cleaning and checking, called the clean
package. It gets automatically installed with the AMR
package, so we only have to load it:
It contains the freq()
function, to create frequency tables.
So let’s check our data, with a couple of frequency tables:
Frequency table
Class: mo (character)
Length: 500 (of which NA: 0 = 0.00%)
Unique: 39
Families: 10
Genera: 17
Species: 39
Item | Count | Percent | Cum. Count | Cum. Percent | |
---|---|---|---|---|---|
1 | B_ESCHR_COL | 245 | 49.0% | 245 | 49.0% |
2 | B_STPHY_CNS | 74 | 14.8% | 319 | 63.8% |
3 | B_STPHY_EPI | 38 | 7.6% | 357 | 71.4% |
4 | B_STRPT_PNE | 31 | 6.2% | 388 | 77.6% |
5 | B_STPHY_HOM | 21 | 4.2% | 409 | 81.8% |
6 | B_PROTS_MIR | 9 | 1.8% | 418 | 83.6% |
7 | B_ENTRC_IUM | 8 | 1.6% | 426 | 85.2% |
8 | B_STPHY_CAP | 8 | 1.6% | 434 | 86.8% |
9 | B_ENTRB_CLO | 5 | 1.0% | 439 | 87.8% |
10 | B_ENTRC_COL | 4 | 0.8% | 443 | 88.6% |
(omitted 29 entries, n = 57 [11.4%])
# our transformed antibiotic columns
# amoxicillin/clavulanic acid (J01CR02) as an example
data %>% freq(AMC_ND2)
Frequency table
Class: factor > ordered > rsi (numeric)
Length: 500 (of which NA: 19 = 3.80%)
Levels: 3: S < I < R
Unique: 3
%SI: 78.6%
Item | Count | Percent | Cum. Count | Cum. Percent | |
---|---|---|---|---|---|
1 | S | 356 | 74.0% | 356 | 74.0% |
2 | R | 103 | 21.4% | 459 | 95.4% |
3 | I | 22 | 4.6% | 481 | 100.0% |