diff --git a/DESCRIPTION b/DESCRIPTION index a74f7569..0e3d47cd 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: AMR -Version: 0.6.1.9037 -Date: 2019-05-23 +Version: 0.6.1.9040 +Date: 2019-05-28 Title: Antimicrobial Resistance Analysis Authors@R: c( person( diff --git a/NEWS.md b/NEWS.md index 588f0965..855acb63 100755 --- a/NEWS.md +++ b/NEWS.md @@ -28,13 +28,15 @@ * Frequency tables (`freq()`): * speed improvement for microbial IDs * fixed level names in markdown - * * Removed all hardcoded EUCAST rules and replaced them with a new reference file: `./inst/eucast/eucast.tsv` * Added ceftazidim intrinsic resistance to *Streptococci* * Changed default settings for `age_groups()`, to let groups of fives and tens end with 100+ instead of 120+ * Fix for `freq()` for when all values are `NA` * Fix for `first_isolate()` for when dates are missing * Improved speed of `guess_ab_col()` +* Function `as.mo()` now gently interprets any number of whitespace characters (like tabs) as one space +* Small algorithm fix for `as.mo()` +* Removed viruses from data set `microorganisms.codes` and cleaned it up #### Other * Support for R 3.6.0 diff --git a/R/mo.R b/R/mo.R index 4f9e2008..c70b0cc3 100755 --- a/R/mo.R +++ b/R/mo.R @@ -456,10 +456,19 @@ exec_as.mo <- function(x, } else if (!all(x %in% AMR::microorganisms[, property])) { + strip_whitespace <- function(x) { + # all whitespaces (tab, new lines, etc.) should be one space + # and spaces before and after should be omitted + trimws(gsub("[\\s]+", " ", x, perl = TRUE), which = "both") + } + + x <- strip_whitespace(x) x_backup <- x # remove spp and species - x <- trimws(gsub(" +(spp.?|ssp.?|sp.? |ss ?.?|subsp.?|subspecies|biovar |serovar |species)", " ", x_backup, ignore.case = TRUE), which = "both") + x <- gsub(" +(spp.?|ssp.?|sp.? |ss ?.?|subsp.?|subspecies|biovar |serovar |species)", " ", x_backup, ignore.case = TRUE) + x <- strip_whitespace(x) + x_backup_without_spp <- x x_species <- paste(x, "species") # translate to English for supported languages of mo_property @@ -487,8 +496,8 @@ exec_as.mo <- function(x, x <- gsub("e+", "e+", x, ignore.case = TRUE) x <- gsub("o+", "o+", x, ignore.case = TRUE) - # but spaces before and after should be omitted - x <- trimws(x, which = "both") + x <- strip_whitespace(x) + x_trimmed <- x x_trimmed_species <- paste(x_trimmed, "species") x_trimmed_without_group <- gsub(" gro.u.p$", "", x_trimmed, ignore.case = TRUE) @@ -1063,7 +1072,7 @@ exec_as.mo <- function(x, } } } - # (6) try to strip off one element from start and check the remains (only allow 2-part name outcome) ---- + # (6) try to strip off one element from start and check the remains (only allow >= 2-part name outcome) ---- x_strip <- a.x_backup %>% strsplit(" ") %>% unlist() if (length(x_strip) > 1 & nchar(g.x_backup_without_spp) >= 6) { for (i in 2:(length(x_strip))) { @@ -1072,8 +1081,8 @@ exec_as.mo <- function(x, if (!empty_result(found)) { found_result <- found found <- microorganismsDT[mo == found_result[1L], ..property][[1]] - # uncertainty level 2 only if the fullname contains a space (otherwise it will be found with lvl 3) - if (microorganismsDT[mo == found_result[1L], fullname][[1]] %like% " ") { + # uncertainty level 2 only if searched part contains a space (otherwise it will be found with lvl 3) + if (x_strip_collapsed %like% " ") { uncertainties <<- rbind(uncertainties, data.frame(uncertainty = 2, input = a.x_backup, diff --git a/R/mo_property.R b/R/mo_property.R index 40dd5256..206c5345 100755 --- a/R/mo_property.R +++ b/R/mo_property.R @@ -396,7 +396,7 @@ mo_validate <- function(x, property, ...) { tryCatch(x[1L] %in% AMR::microorganisms[1, property], error = function(e) stop(e$message, call. = FALSE)) - if (!all(x %in% AMR::microorganisms[, property]) + if (!all(x %in% pull(AMR::microorganisms, property)) | Becker %in% c(TRUE, "all") | Lancefield %in% c(TRUE, "all")) { exec_as.mo(x, property = property, ...) diff --git a/_pkgdown.yml b/_pkgdown.yml index cf1f13f6..3445ab51 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -177,6 +177,9 @@ authors: Bhanu N. M. Sinha: href: https://www.rug.nl/staff/b.sinha/ +development: + mode: release # improves indexing by search engines + template: assets: pkgdown/logos # use logos in this folder params: diff --git a/data/microorganisms.codes.rda b/data/microorganisms.codes.rda index 85322ea8..8c886e7a 100644 Binary files a/data/microorganisms.codes.rda and b/data/microorganisms.codes.rda differ diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index c91683cf..24593f31 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -78,7 +78,7 @@
diff --git a/docs/articles/AMR.html b/docs/articles/AMR.html index 125f9a2e..2519e790 100644 --- a/docs/articles/AMR.html +++ b/docs/articles/AMR.html @@ -40,7 +40,7 @@ @@ -199,7 +199,7 @@AMR.Rmd
Note: values on this page will change with every website update since they are based on randomly created values and the page was written in R Markdown. However, the methodology remains unchanged. This page was generated on 23 May 2019.
+Note: values on this page will change with every website update since they are based on randomly created values and the page was written in R Markdown. However, the methodology remains unchanged. This page was generated on 28 May 2019.
So, we can draw at least two conclusions immediately. From a data scientist perspective, the data looks clean: only values M
and F
. From a researcher perspective: there are slightly more men. Nothing we didn’t already know.
The data is already quite clean, but we still need to transform some variables. The bacteria
column now consists of text, and we want to add more variables based on microbial IDs later on. So, we will transform this column to valid IDs. The mutate()
function of the dplyr
package makes this really easy:
data <- data %>%
@@ -449,14 +449,14 @@
# Pasteurella multocida (no new changes)
# Staphylococcus (no new changes)
# Streptococcus groups A, B, C, G (no new changes)
-# Streptococcus pneumoniae (1542 new changes)
+# Streptococcus pneumoniae (1390 new changes)
# Viridans group streptococci (no new changes)
#
# EUCAST Expert Rules, Intrinsic Resistance and Exceptional Phenotypes (v3.1, 2016)
-# Table 01: Intrinsic resistance in Enterobacteriaceae (1286 new changes)
+# Table 01: Intrinsic resistance in Enterobacteriaceae (1264 new changes)
# Table 02: Intrinsic resistance in non-fermentative Gram-negative bacteria (no new changes)
# Table 03: Intrinsic resistance in other Gram-negative bacteria (no new changes)
-# Table 04: Intrinsic resistance in Gram-positive bacteria (2788 new changes)
+# Table 04: Intrinsic resistance in Gram-positive bacteria (2725 new changes)
# Table 08: Interpretive rules for B-lactam agents and Gram-positive cocci (no new changes)
# Table 09: Interpretive rules for B-lactam agents and Gram-negative rods (no new changes)
# Table 11: Interpretive rules for macrolides, lincosamides, and streptogramins (no new changes)
@@ -464,24 +464,24 @@
# Table 13: Interpretive rules for quinolones (no new changes)
#
# Other rules
-# Non-EUCAST: amoxicillin/clav acid = S where ampicillin = S (2231 new changes)
-# Non-EUCAST: ampicillin = R where amoxicillin/clav acid = R (126 new changes)
+# Non-EUCAST: amoxicillin/clav acid = S where ampicillin = S (2301 new changes)
+# Non-EUCAST: ampicillin = R where amoxicillin/clav acid = R (114 new changes)
# Non-EUCAST: piperacillin = R where piperacillin/tazobactam = R (no new changes)
# Non-EUCAST: piperacillin/tazobactam = S where piperacillin = S (no new changes)
# Non-EUCAST: trimethoprim = R where trimethoprim/sulfa = R (no new changes)
# Non-EUCAST: trimethoprim/sulfa = S where trimethoprim = S (no new changes)
#
# --------------------------------------------------------------------------
-# EUCAST rules affected 6,562 out of 20,000 rows, making a total of 7,973 edits
+# EUCAST rules affected 6,521 out of 20,000 rows, making a total of 7,794 edits
# => added 0 test results
#
-# => changed 7,973 test results
-# - 114 test results changed from S to I
-# - 4,779 test results changed from S to R
-# - 1,118 test results changed from I to S
-# - 330 test results changed from I to R
-# - 1,606 test results changed from R to S
-# - 26 test results changed from R to I
+# => changed 7,794 test results
+# - 125 test results changed from S to I
+# - 4,678 test results changed from S to R
+# - 1,070 test results changed from I to S
+# - 286 test results changed from I to R
+# - 1,620 test results changed from R to S
+# - 15 test results changed from R to I
# --------------------------------------------------------------------------
#
# Use verbose = TRUE to get a data.frame with all specified edits instead.
So only 28.5% is suitable for resistance analysis! We can now filter on it with the filter()
function, also from the dplyr
package:
So only 28.1% is suitable for resistance analysis! We can now filter on it with the filter()
function, also from the dplyr
package:
For future use, the above two syntaxes can be shortened with the filter_first_isolate()
function:
Only 1 isolates are marked as ‘first’ according to CLSI guideline. But when reviewing the antibiogram, it is obvious that some isolates are absolutely different strains and should be included too. This is why we weigh isolates, based on their antibiogram. The key_antibiotics()
function adds a vector with 18 key antibiotics: 6 broad spectrum ones, 6 small spectrum for Gram negatives and 6 small spectrum for Gram positives. These can be defined by the user.
Only 2 isolates are marked as ‘first’ according to CLSI guideline. But when reviewing the antibiogram, it is obvious that some isolates are absolutely different strains and should be included too. This is why we weigh isolates, based on their antibiogram. The key_antibiotics()
function adds a vector with 18 key antibiotics: 6 broad spectrum ones, 6 small spectrum for Gram negatives and 6 small spectrum for Gram positives. These can be defined by the user.
If a column exists with a name like ‘key(…)ab’ the first_isolate()
function will automatically use it and determine the first weighted isolates. Mind the NOTEs in below output:
data <- data %>%
mutate(keyab = key_antibiotics(.)) %>%
@@ -657,7 +657,7 @@
# NOTE: Using column `patient_id` as input for `col_patient_id`.
# NOTE: Using column `keyab` as input for `col_keyantibiotics`. Use col_keyantibiotics = FALSE to prevent this.
# [Criterion] Inclusion based on key antibiotics, ignoring I.
-# => Found 15,125 first weighted isolates (75.6% of total)
isolate | @@ -674,8 +674,8 @@||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | -2010-04-13 | -S1 | +2010-03-09 | +J4 | B_ESCHR_COL | S | S | @@ -686,22 +686,22 @@|||||||
2 | -2010-06-02 | -S1 | +2010-03-19 | +J4 | B_ESCHR_COL | -S | +R | S | S | S | FALSE | -FALSE | +TRUE | |
3 | -2010-07-21 | -S1 | +2010-03-31 | +J4 | B_ESCHR_COL | -I | +S | S | R | S | @@ -710,56 +710,56 @@||||
4 | -2010-09-19 | -S1 | +2010-05-07 | +J4 | B_ESCHR_COL | R | S | -R | -S | -FALSE | -FALSE | -|||
5 | -2010-09-19 | -S1 | -B_ESCHR_COL | S | S | -S | -R | FALSE | TRUE | |||||
5 | +2010-06-21 | +J4 | +B_ESCHR_COL | +I | +S | +S | +S | +FALSE | +FALSE | +|||||
6 | -2010-10-14 | -S1 | +2010-07-10 | +J4 | B_ESCHR_COL | S | S | -S | +R | S | FALSE | TRUE | ||
7 | -2010-10-28 | -S1 | +2010-11-26 | +J4 | B_ESCHR_COL | S | S | -S | +R | S | FALSE | FALSE | ||
8 | -2010-12-09 | -S1 | +2010-12-04 | +J4 | B_ESCHR_COL | R | S | @@ -770,35 +770,35 @@|||||||
9 | -2010-12-15 | -S1 | +2011-03-19 | +J4 | B_ESCHR_COL | S | S | S | S | -FALSE | +TRUE | TRUE | ||
10 | -2011-01-07 | -S1 | +2011-05-16 | +J4 | B_ESCHR_COL | -R | -I | +S | +S | S | S | FALSE | -TRUE | +FALSE |
Instead of 1, now 7 isolates are flagged. In total, 75.6% of all isolates are marked ‘first weighted’ - 47.1% more than when using the CLSI guideline. In real life, this novel algorithm will yield 5-10% more isolates than the classic CLSI guideline.
+Instead of 2, now 7 isolates are flagged. In total, 75.4% of all isolates are marked ‘first weighted’ - 47.2% more than when using the CLSI guideline. In real life, this novel algorithm will yield 5-10% more isolates than the classic CLSI guideline.
As with filter_first_isolate()
, there’s a shortcut for this new algorithm too:
So we end up with 15,125 isolates for analysis.
+So we end up with 15,074 isolates for analysis.
We can remove unneeded columns:
@@ -806,7 +806,6 @@date | patient_id | hospital | @@ -823,73 +822,8 @@||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | -2012-10-26 | -T6 | -Hospital D | -B_STPHY_AUR | -R | -R | -S | -S | -F | -Gram positive | -Staphylococcus | -aureus | -TRUE | -|||
2 | -2011-10-13 | -Y4 | -Hospital B | -B_STRPT_PNE | -R | -R | -S | -R | -F | -Gram positive | -Streptococcus | -pneumoniae | -TRUE | -|||
3 | -2010-02-09 | -O2 | -Hospital B | -B_STRPT_PNE | -R | -R | -S | -R | -F | -Gram positive | -Streptococcus | -pneumoniae | -TRUE | -|||
6 | -2015-09-19 | -P5 | -Hospital D | -B_STRPT_PNE | -S | -S | -S | -R | -F | -Gram positive | -Streptococcus | -pneumoniae | -TRUE | -|||
7 | -2011-05-13 | -X5 | +2016-12-11 | +T9 | Hospital B | B_ESCHR_COL | R | @@ -903,16 +837,75 @@TRUE | ||||||||
8 | -2015-03-07 | -Z7 | -Hospital C | +2013-02-14 | +A3 | +Hospital B | B_ESCHR_COL | S | S | R | S | +M | +Gram negative | +Escherichia | +coli | +TRUE | +
2011-05-14 | +W4 | +Hospital D | +B_STRPT_PNE | +R | +R | +S | +R | F | +Gram positive | +Streptococcus | +pneumoniae | +TRUE | +||||
2010-02-09 | +G3 | +Hospital C | +B_ESCHR_COL | +R | +S | +R | +S | +M | +Gram negative | +Escherichia | +coli | +TRUE | +||||
2016-04-24 | +B7 | +Hospital A | +B_ESCHR_COL | +S | +S | +S | +S | +M | +Gram negative | +Escherichia | +coli | +TRUE | +||||
2010-02-20 | +L7 | +Hospital C | +B_ESCHR_COL | +R | +R | +S | +S | +M | Gram negative | Escherichia | coli | @@ -935,9 +928,9 @@|||||
1 | Escherichia coli | -7,486 | -49.5% | -7,486 | -49.5% | +7,504 | +49.8% | +7,504 | +49.8% | |||||||
2 | Staphylococcus aureus | -3,731 | -24.7% | -11,217 | -74.2% | +3,702 | +24.6% | +11,206 | +74.3% | |||||||
3 | Streptococcus pneumoniae | -2,360 | -15.6% | -13,577 | -89.8% | +2,313 | +15.3% | +13,519 | +89.7% | |||||||
4 | Klebsiella pneumoniae | -1,548 | -10.2% | -15,125 | +1,555 | +10.3% | +15,074 | 100.0% | ||||||||
Hospital A | -0.4556355 | +0.4603103 | ||||||||||||||
Hospital B | -0.4661553 | +0.4641985 | ||||||||||||||
Hospital C | -0.4759657 | +0.4670185 | ||||||||||||||
Hospital D | -0.4577347 | +0.4706464 |
EUCAST.Rmd
G_test.Rmd
MDR.Rmd
head(my_TB_data)
# rifampicin isoniazid gatifloxacin ethambutol pyrazinamide moxifloxacin
# 1 S S R S R S
-# 2 R R S S R S
-# 3 R S R R S S
-# 4 S I R S R R
-# 5 R S R R S S
-# 6 I I S S R S
+# 2 R R R S S R
+# 3 S S S S S S
+# 4 S S S S S R
+# 5 R R S S R R
+# 6 R S S R S S
# kanamycin
# 1 S
-# 2 R
+# 2 S
# 3 S
# 4 R
-# 5 S
-# 6 R
We can now add the interpretation of MDR-TB to our data set:
my_TB_data$mdr <- mdr_tb(my_TB_data)
# NOTE: No column found as input for `col_mo`, assuming all records contain Mycobacterium tuberculosis.
@@ -285,39 +285,39 @@ Unique: 5
1
Mono-resistance
-3,240
-64.8%
-3,240
-64.8%
+3,249
+65.0%
+3,249
+65.0%
2
Negative
-641
-12.8%
-3,881
-77.6%
+647
+12.9%
+3,896
+77.9%
3
Multidrug resistance
-638
-12.8%
-4,519
+625
+12.5%
+4,521
90.4%
4
Poly-resistance
-279
+281
5.6%
-4,798
+4,802
96.0%
5
Extensive drug resistance
-202
+198
4.0%
5,000
100.0%
diff --git a/docs/articles/SPSS.html b/docs/articles/SPSS.html
index f6e40a30..5c2a73d4 100644
--- a/docs/articles/SPSS.html
+++ b/docs/articles/SPSS.html
@@ -40,7 +40,7 @@
@@ -199,7 +199,7 @@
How to import data from SPSS / SAS / Stata
Matthijs S. Berends
- 23 May 2019
+ 28 May 2019
SPSS.Rmd
@@ -229,7 +229,7 @@
R can be easily automated.
-Over the last years, R Markdown has really made an interesting development. With R Markdown, you can very easily reproduce your reports, whether it’s to Word, Powerpoint, a website, a PDF document or just the raw data to Excel. I use this a lot to generate monthly reports automatically. Just write the code once and enjoy the automatically updated reports at any interval you like.
+Over the last years, R Markdown has really made an interesting development. With R Markdown, you can very easily produce reports, whether format has to be Word, PowerPoint, a website, a PDF document or just the raw data to Excel. It even allows the use of a reference file containing the layout style (e.g. fonts and colours) of your organisation. I use this a lot to generate weekly and monthly reports automatically. Just write the code once and enjoy the automatically updated reports at any interval you like.
For an even more professional environment, you could create Shiny apps: live manipulation of data using a custom made website. The webdesign knowledge needed (JavaScript, CSS, HTML) is almost zero.
@@ -238,8 +238,8 @@
R understands any data type, including SPSS/SAS/Stata.
-And that’s not vice versa I’m afraid. You can import data from any source into R. From SPSS, SAS and Stata (link), from Minitab, Epi Info and EpiData (link), from Excel (link), from flat files like CSV, TXT or TSV (link), or directly from databases and datawarehouses from anywhere on the world (link). You can even scrape websites to download tables that are live on the internet (link).
-And the best part - you can export from R to most data formats as well. So you can import an SPSS file, do your analysis neatly in R and export the resulting tables to Excel files.
+And that’s not vice versa I’m afraid. You can import data from any source into R. From SPSS, SAS and Stata (link), from Minitab, Epi Info and EpiData (link), from Excel (link), from flat files like CSV, TXT or TSV (link), or directly from databases and datawarehouses from anywhere on the world (link). You can even scrape websites to download tables that are live on the internet (link) or get the results of an API call (link).
+And the best part - you can export from R to most data formats as well. So you can import an SPSS file, do your analysis neatly in R and export the resulting tables to Excel files for sharing.
R is completely free and open-source.
diff --git a/docs/articles/WHONET.html b/docs/articles/WHONET.html
index 8a94dba1..4699d3eb 100644
--- a/docs/articles/WHONET.html
+++ b/docs/articles/WHONET.html
@@ -40,7 +40,7 @@
@@ -199,7 +199,7 @@
How to work with WHONET data
Matthijs S. Berends
- 23 May 2019
+ 28 May 2019
WHONET.Rmd
@@ -239,7 +239,7 @@
Frequency table of mo
from a data.frame
(500 x 54)
-Class: mo
(character
)
+
Class: mo (character)
Length: 500 (of which NA: 0 = 0.00%)
Unique: 39
Families: 10
@@ -343,9 +343,9 @@ Species: 38
# 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
)
+
Class: factor > ordered > rsi (numeric)
Length: 500 (of which NA: 19 = 3.80%)
-Levels: 3: S
< I
< R
+Levels: 3: S < I < R
Unique: 3
Drug: Amoxicillin/clavulanic acid (AMC, J01CR02)
Group: Beta-lactams/penicillins
diff --git a/docs/articles/ab_property.html b/docs/articles/ab_property.html
index 37f82f35..45fddb28 100644
--- a/docs/articles/ab_property.html
+++ b/docs/articles/ab_property.html
@@ -40,7 +40,7 @@
@@ -199,7 +199,7 @@
How to get properties of an antibiotic
Matthijs S. Berends
- 23 May 2019
+ 28 May 2019
ab_property.Rmd
diff --git a/docs/articles/benchmarks.html b/docs/articles/benchmarks.html
index 4e1f3989..cd7763de 100644
--- a/docs/articles/benchmarks.html
+++ b/docs/articles/benchmarks.html
@@ -40,7 +40,7 @@
@@ -199,7 +199,7 @@
Benchmarks
Matthijs S. Berends
- 23 May 2019
+ 28 May 2019
benchmarks.Rmd
@@ -225,13 +225,13 @@
print(S.aureus, unit = "ms", signif = 2)
# Unit: milliseconds
# expr min lq mean median uq max neval
-# as.mo("sau") 17.0 18 32.0 18 62.0 68.0 10
-# as.mo("stau") 48.0 48 64.0 53 92.0 96.0 10
-# as.mo("staaur") 17.0 18 18.0 18 18.0 19.0 10
-# as.mo("STAAUR") 17.0 17 18.0 18 18.0 20.0 10
-# as.mo("S. aureus") 28.0 28 33.0 29 29.0 73.0 10
-# as.mo("S. aureus") 28.0 28 44.0 28 29.0 140.0 10
-# as.mo("Staphylococcus aureus") 7.9 8 8.1 8 8.2 8.2 10
+# as.mo("sau") 17.0 17 18.0 18 18.0 18.0 10
+# as.mo("stau") 48.0 48 66.0 48 92.0 92.0 10
+# as.mo("staaur") 17.0 17 23.0 18 19.0 62.0 10
+# as.mo("STAAUR") 17.0 18 18.0 18 18.0 19.0 10
+# as.mo("S. aureus") 28.0 28 37.0 28 29.0 73.0 10
+# as.mo("S. aureus") 28.0 28 44.0 28 28.0 140.0 10
+# as.mo("Staphylococcus aureus") 7.9 8 8.2 8 8.1 8.8 10
In the table above, all measurements are shown in milliseconds (thousands of seconds). A value of 5 milliseconds means it can determine 200 input values per second. It case of 100 milliseconds, this is only 10 input values per second. The second input is the only one that has to be looked up thoroughly. All the others are known codes (the first one is a WHONET code) or common laboratory codes, or common full organism names like the last one. Full organism names are always preferred.
To achieve this speed, the as.mo
function also takes into account the prevalence of human pathogenic microorganisms. The downside is of course that less prevalent microorganisms will be determined less fast. See this example for the ID of Thermus islandicus (B_THERMS_ISL
), a bug probably never found before in humans:
T.islandicus <- microbenchmark(as.mo("theisl"),
@@ -243,12 +243,12 @@
print(T.islandicus, unit = "ms", signif = 2)
# Unit: milliseconds
# expr min lq mean median uq max neval
-# as.mo("theisl") 470 470 500 500 520 520 10
-# as.mo("THEISL") 470 470 510 520 520 530 10
-# as.mo("T. islandicus") 73 74 79 74 74 120 10
-# as.mo("T. islandicus") 73 74 84 74 75 130 10
-# as.mo("Thermus islandicus") 74 74 94 75 120 140 10
-That takes 8.1 times as much time on average. A value of 100 milliseconds means it can only determine ~10 different input values per second. We can conclude that looking up arbitrary codes of less prevalent microorganisms is the worst way to go, in terms of calculation performance. Full names (like Thermus islandicus) are almost fast - these are the most probable input from most data sets.
+# as.mo("theisl") 470 470 500 500 520 530 10
+# as.mo("THEISL") 470 470 500 510 520 520 10
+# as.mo("T. islandicus") 75 75 82 76 76 130 10
+# as.mo("T. islandicus") 74 75 90 75 91 150 10
+# as.mo("Thermus islandicus") 73 74 90 74 120 130 10
+That takes 8.3 times as much time on average. A value of 100 milliseconds means it can only determine ~10 different input values per second. We can conclude that looking up arbitrary codes of less prevalent microorganisms is the worst way to go, in terms of calculation performance. Full names (like Thermus islandicus) are almost fast - these are the most probable input from most data sets.
In the figure below, we compare Escherichia coli (which is very common) with Prevotella brevis (which is moderately common) and with Thermus islandicus (which is very uncommon):
par(mar = c(5, 16, 4, 2)) # set more space for left margin text (16)
@@ -294,8 +294,8 @@
print(run_it, unit = "ms", signif = 3)
# Unit: milliseconds
# expr min lq mean median uq max neval
-# mo_fullname(x) 633 675 747 722 763 933 10
-So transforming 500,000 values (!!) of 50 unique values only takes 0.72 seconds (721 ms). You only lose time on your unique input values.
+# mo_fullname(x) 630 675 709 693 765 858 10
+So transforming 500,000 values (!!) of 50 unique values only takes 0.69 seconds (692 ms). You only lose time on your unique input values.
@@ -307,10 +307,10 @@
times = 10)
print(run_it, unit = "ms", signif = 3)
# Unit: milliseconds
-# expr min lq mean median uq max neval
-# A 12.90 13.1 18.0 13.20 14.10 59.1 10
-# B 25.20 25.3 26.2 26.10 27.00 27.4 10
-# C 1.25 1.4 1.6 1.68 1.69 1.9 10
+# expr min lq mean median uq max neval
+# A 13.10 13.20 13.40 13.40 13.50 13.60 10
+# B 25.30 25.60 30.40 26.10 26.40 70.10 10
+# C 1.28 1.42 1.57 1.66 1.67 1.71 10
So going from mo_fullname("Staphylococcus aureus")
to "Staphylococcus aureus"
takes 0.0017 seconds - it doesn’t even start calculating if the result would be the same as the expected resulting value. That goes for all helper functions:
run_it <- microbenchmark(A = mo_species("aureus"),
B = mo_genus("Staphylococcus"),
@@ -324,14 +324,14 @@
print(run_it, unit = "ms", signif = 3)
# Unit: milliseconds
# expr min lq mean median uq max neval
-# A 0.357 0.374 0.447 0.435 0.514 0.567 10
-# B 0.404 0.507 0.541 0.533 0.575 0.755 10
-# C 1.350 1.400 1.700 1.720 1.890 2.150 10
-# D 0.416 0.550 0.589 0.603 0.632 0.750 10
-# E 0.400 0.480 0.559 0.541 0.667 0.737 10
-# F 0.346 0.384 0.493 0.498 0.628 0.643 10
-# G 0.393 0.421 0.486 0.430 0.570 0.620 10
-# H 0.258 0.280 0.332 0.290 0.377 0.508 10
+# A 0.422 0.441 0.483 0.452 0.483 0.675 10
+# B 0.434 0.512 0.549 0.562 0.593 0.638 10
+# C 1.340 1.530 1.670 1.680 1.860 2.030 10
+# D 0.443 0.471 0.552 0.580 0.611 0.645 10
+# E 0.358 0.398 0.465 0.473 0.516 0.554 10
+# F 0.366 0.397 0.441 0.436 0.485 0.512 10
+# G 0.348 0.462 0.485 0.484 0.517 0.615 10
+# H 0.194 0.262 0.295 0.288 0.327 0.403 10
Of course, when running mo_phylum("Firmicutes")
the function has zero knowledge about the actual microorganism, namely S. aureus. But since the result would be "Firmicutes"
too, there is no point in calculating the result. And because this package ‘knows’ all phyla of all known bacteria (according to the Catalogue of Life), it can just return the initial value immediately.
@@ -358,13 +358,13 @@
print(run_it, unit = "ms", signif = 4)
# Unit: milliseconds
# expr min lq mean median uq max neval
-# en 18.10 18.20 18.30 18.25 18.38 18.57 10
-# de 23.06 23.14 32.22 23.21 23.48 68.37 10
-# nl 36.30 36.40 41.09 36.59 36.85 81.13 10
-# es 22.85 23.07 23.24 23.20 23.46 23.72 10
-# it 22.92 22.99 27.72 23.17 23.61 68.07 10
-# fr 23.02 23.14 27.79 23.23 23.58 68.27 10
-# pt 23.00 23.09 23.24 23.19 23.45 23.52 10
+# en 18.24 18.29 18.60 18.43 18.58 19.88 10
+# de 23.04 23.28 37.00 23.46 68.46 69.60 10
+# nl 36.67 36.75 37.54 37.09 37.17 42.45 10
+# es 23.08 23.19 23.38 23.39 23.58 23.63 10
+# it 22.97 23.30 23.40 23.35 23.54 23.92 10
+# fr 23.28 23.30 23.81 23.46 23.82 26.51 10
+# pt 23.10 23.15 27.87 23.35 23.76 68.33 10
Currently supported are German, Dutch, Spanish, Italian, French and Portuguese.
diff --git a/docs/articles/benchmarks_files/figure-html/unnamed-chunk-5-1.png b/docs/articles/benchmarks_files/figure-html/unnamed-chunk-5-1.png
index 924101ae..8c759f38 100644
Binary files a/docs/articles/benchmarks_files/figure-html/unnamed-chunk-5-1.png and b/docs/articles/benchmarks_files/figure-html/unnamed-chunk-5-1.png differ
diff --git a/docs/articles/freq.html b/docs/articles/freq.html
index 42b0863e..e235c3d2 100644
--- a/docs/articles/freq.html
+++ b/docs/articles/freq.html
@@ -199,7 +199,7 @@
How to create frequency tables
Matthijs S. Berends
- 23 May 2019
+ 28 May 2019
freq.Rmd
@@ -219,7 +219,7 @@
To only show and quickly review the content of one variable, you can just select this variable in various ways. Let’s say we want to get the frequencies of the gender
variable of the septic_patients
dataset:
Frequency table of gender
from a data.frame
(2,000 x 49)
-Class: character
(character
)
+
Class: character
Length: 2,000 (of which NA: 0 = 0.00%)
Unique: 2
Shortest: 1
@@ -424,7 +424,7 @@ Longest: 34
distinct(patient_id, .keep_all = TRUE) %>%
freq(age, nmax = 5, header = TRUE)
Frequency table of age
from a data.frame
(981 x 49)
-Class: numeric
(numeric
)
+
Class: numeric
Length: 981 (of which NA: 0 = 0.00%)
Unique: 73
Mean: 71.08
@@ -503,9 +503,9 @@ Outliers: 15 (unique count: 12)
Frequency table of hospital_id
from a data.frame
(2,000 x 49)
-Class: factor
(numeric
)
+
Class: factor (numeric)
Length: 2,000 (of which NA: 0 = 0.00%)
-Levels: 4: A
, B
, C
, D
+Levels: 4: A, B, C, D
Unique: 4