diff --git a/R/mo.R b/R/mo.R index 3d44c66c..09be7250 100755 --- a/R/mo.R +++ b/R/mo.R @@ -219,7 +219,6 @@ exec_as.mo <- function(x, Becker = FALSE, Lancefield = FALSE, # conversion of old MO codes from v0.5.0 (ITIS) to later versions (Catalogue of Life) if (any(x %like% "^[BFP]_[A-Z]{3,7}")) { - print("is any") leftpart <- gsub("^([BFP]_[A-Z]{3,7}).*", "\\1", x) if (any(leftpart %in% names(mo_codes_v0.5.0))) { rightpart <- gsub("^[BFP]_[A-Z]{3,7}(.*)", "\\1", x) @@ -267,9 +266,12 @@ exec_as.mo <- function(x, Becker = FALSE, Lancefield = FALSE, x <- microorganismsDT[data.table(mo = x), on = "mo", ..property][[1]] } else if (all(x %in% microorganismsDT[prevalence == 1, "fullname"][[1]])) { - # we need special treatment for prevalent full names, they are likely! + # we need special treatment for very prevalent full names, they are likely! # e.g. as.mo("Staphylococcus aureus") x <- microorganismsDT[prevalence == 1][data.table(fullname = x), on = "fullname", ..property][[1]] + } else if (all(x %in% microorganismsDT[prevalence == 2, "fullname"][[1]])) { + # same for common full names, they are also likely + x <- microorganismsDT[prevalence == 2][data.table(fullname = x), on = "fullname", ..property][[1]] } else if (all(toupper(x) %in% microorganisms.codes[, "code"])) { # commonly used MO codes diff --git a/docs/articles/AMR.html b/docs/articles/AMR.html index b0b78828..7515f28e 100644 --- a/docs/articles/AMR.html +++ b/docs/articles/AMR.html @@ -327,52 +327,52 @@ -2017-09-14 -X8 -Hospital A -Escherichia coli -S +2017-04-07 +O7 +Hospital B +Staphylococcus aureus +R S S S F -2011-10-29 -H5 -Hospital D -Streptococcus pneumoniae -S -S -S -S -M - - -2013-02-03 -D7 -Hospital D -Streptococcus pneumoniae -S -S -S -S -M - - -2013-01-14 -U1 -Hospital C -Escherichia coli -S -S +2017-04-12 +H4 +Hospital B +Staphylococcus aureus +R S R -F +S +M -2010-02-23 -O7 +2013-08-17 +C3 +Hospital B +Streptococcus pneumoniae +R +R +S +S +M + + +2015-05-18 +E9 +Hospital B +Klebsiella pneumoniae +R +R +S +S +M + + +2012-12-26 +W4 Hospital A Staphylococcus aureus R @@ -382,15 +382,15 @@ F -2010-09-26 -E6 +2016-09-28 +W1 Hospital D -Klebsiella pneumoniae -R -I +Staphylococcus aureus R S -M +S +S +F @@ -411,8 +411,8 @@ #> #> Item Count Percent Cum. Count Cum. Percent #> --- ----- ------- -------- ----------- ------------- -#> 1 M 10,391 52.0% 10,391 52.0% -#> 2 F 9,609 48.0% 20,000 100.0% +#> 1 M 10,466 52.3% 10,466 52.3% +#> 2 F 9,534 47.7% 20,000 100.0%

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 %>%
@@ -423,50 +423,48 @@
 

Finally, we will apply EUCAST rules on our antimicrobial results. In Europe, most medical microbiological laboratories already apply these rules. Our package features their latest insights on intrinsic resistance and exceptional phenotypes. Moreover, the eucast_rules() function can also apply additional rules, like forcing ampicillin = R when amoxicillin/clavulanic acid = R.

Because the amoxicillin (column amox) and amoxicillin/clavulanic acid (column amcl) in our data were generated randomly, some rows will undoubtedly contain amox = S and amcl = R, which is technically impossible. The eucast_rules() fixes this:

data <- eucast_rules(data, col_mo = "bacteria")
-#> [1] "is any"
-#> [1] "is any"
+#> 
+#> Rules by the European Committee on Antimicrobial Susceptibility Testing (EUCAST)
 #> 
-#> Rules by the European Committee on Antimicrobial Susceptibility Testing (EUCAST)
-#> 
-#> EUCAST Clinical Breakpoints (v9.0, 2019)
-#> Enterobacteriales (Order) (no changes)
-#> Staphylococcus (no changes)
-#> Enterococcus (no changes)
-#> Streptococcus groups A, B, C, G (no changes)
-#> Streptococcus pneumoniae (no changes)
-#> Viridans group streptococci (no changes)
-#> Haemophilus influenzae (no changes)
-#> Moraxella catarrhalis (no changes)
-#> Anaerobic Gram positives (no changes)
-#> Anaerobic Gram negatives (no changes)
-#> Pasteurella multocida (no changes)
-#> Campylobacter jejuni and C. coli (no changes)
-#> Aerococcus sanguinicola and A. urinae (no changes)
-#> Kingella kingae (no changes)
-#> 
-#> EUCAST Expert Rules, Intrinsic Resistance and Exceptional Phenotypes (v3.1, 2016)
-#> Table 1:  Intrinsic resistance in Enterobacteriaceae (1230 changes)
-#> Table 2:  Intrinsic resistance in non-fermentative Gram-negative bacteria (no changes)
-#> Table 3:  Intrinsic resistance in other Gram-negative bacteria (no changes)
-#> Table 4:  Intrinsic resistance in Gram-positive bacteria (2700 changes)
-#> Table 8:  Interpretive rules for B-lactam agents and Gram-positive cocci (no changes)
-#> Table 9:  Interpretive rules for B-lactam agents and Gram-negative rods (no changes)
-#> Table 10: Interpretive rules for B-lactam agents and other Gram-negative bacteria (no changes)
-#> Table 11: Interpretive rules for macrolides, lincosamides, and streptogramins (no changes)
-#> Table 12: Interpretive rules for aminoglycosides (no changes)
-#> Table 13: Interpretive rules for quinolones (no changes)
-#> 
-#> Other rules
-#> Non-EUCAST: ampicillin = R where amoxicillin/clav acid = R (no changes)
-#> Non-EUCAST: piperacillin = R where piperacillin/tazobactam = R (no changes)
-#> Non-EUCAST: trimethoprim = R where trimethoprim/sulfa = R (no changes)
-#> Non-EUCAST: amoxicillin/clav acid = S where ampicillin = S (no changes)
-#> Non-EUCAST: piperacillin/tazobactam = S where piperacillin = S (no changes)
-#> Non-EUCAST: trimethoprim/sulfa = S where trimethoprim = S (no changes)
-#> 
-#> => EUCAST rules affected 7,267 out of 20,000 rows
-#>    -> added 0 test results
-#>    -> changed 3,930 test results (0 to S; 0 to I; 3,930 to R)
+#> EUCAST Clinical Breakpoints (v9.0, 2019) +#> Enterobacteriales (Order) (no changes) +#> Staphylococcus (no changes) +#> Enterococcus (no changes) +#> Streptococcus groups A, B, C, G (no changes) +#> Streptococcus pneumoniae (no changes) +#> Viridans group streptococci (no changes) +#> Haemophilus influenzae (no changes) +#> Moraxella catarrhalis (no changes) +#> Anaerobic Gram positives (no changes) +#> Anaerobic Gram negatives (no changes) +#> Pasteurella multocida (no changes) +#> Campylobacter jejuni and C. coli (no changes) +#> Aerococcus sanguinicola and A. urinae (no changes) +#> Kingella kingae (no changes) +#> +#> EUCAST Expert Rules, Intrinsic Resistance and Exceptional Phenotypes (v3.1, 2016) +#> Table 1: Intrinsic resistance in Enterobacteriaceae (1291 changes) +#> Table 2: Intrinsic resistance in non-fermentative Gram-negative bacteria (no changes) +#> Table 3: Intrinsic resistance in other Gram-negative bacteria (no changes) +#> Table 4: Intrinsic resistance in Gram-positive bacteria (2705 changes) +#> Table 8: Interpretive rules for B-lactam agents and Gram-positive cocci (no changes) +#> Table 9: Interpretive rules for B-lactam agents and Gram-negative rods (no changes) +#> Table 10: Interpretive rules for B-lactam agents and other Gram-negative bacteria (no changes) +#> Table 11: Interpretive rules for macrolides, lincosamides, and streptogramins (no changes) +#> Table 12: Interpretive rules for aminoglycosides (no changes) +#> Table 13: Interpretive rules for quinolones (no changes) +#> +#> Other rules +#> Non-EUCAST: ampicillin = R where amoxicillin/clav acid = R (no changes) +#> Non-EUCAST: piperacillin = R where piperacillin/tazobactam = R (no changes) +#> Non-EUCAST: trimethoprim = R where trimethoprim/sulfa = R (no changes) +#> Non-EUCAST: amoxicillin/clav acid = S where ampicillin = S (no changes) +#> Non-EUCAST: piperacillin/tazobactam = S where piperacillin = S (no changes) +#> Non-EUCAST: trimethoprim/sulfa = S where trimethoprim = S (no changes) +#> +#> => EUCAST rules affected 7,376 out of 20,000 rows +#> -> added 0 test results +#> -> changed 3,996 test results (0 to S; 0 to I; 3,996 to R)

@@ -475,11 +473,7 @@ + species = mo_species(bacteria))

First isolates

@@ -495,8 +489,8 @@ #> NOTE: Using column `bacteria` as input for `col_mo`. #> NOTE: Using column `date` as input for `col_date`. #> NOTE: Using column `patient_id` as input for `col_patient_id`. -#> => Found 5,663 first isolates (28.3% of total)
-

So only 28.3% is suitable for resistance analysis! We can now filter on it with the filter() function, also from the dplyr package:

+#> => Found 5,641 first isolates (28.2% of total) +

So only 28.2% is suitable for resistance analysis! We can now filter on it with the filter() function, also from the dplyr package:

data_1st <- data %>% 
   filter(first == TRUE)

For future use, the above two syntaxes can be shortened with the filter_first_isolate() function:

@@ -522,54 +516,54 @@ 1 -2010-04-19 -S8 +2010-01-24 +A4 B_ESCHR_COL -S -S +R +R S S TRUE 2 -2010-08-08 -S8 +2010-03-30 +A4 B_ESCHR_COL -S I S +R S FALSE 3 -2010-10-31 -S8 +2010-07-21 +A4 B_ESCHR_COL -R -I -R +S +S +S S FALSE 4 -2010-11-11 -S8 +2010-09-23 +A4 B_ESCHR_COL S -I -R -R +S +S +S FALSE 5 -2011-04-04 -S8 +2010-10-05 +A4 B_ESCHR_COL -S +R S S S @@ -577,8 +571,19 @@ 6 -2011-05-22 -S8 +2010-10-26 +A4 +B_ESCHR_COL +R +S +S +S +FALSE + + +7 +2011-02-03 +A4 B_ESCHR_COL S S @@ -586,47 +591,36 @@ S TRUE - -7 -2011-08-15 -S8 -B_ESCHR_COL -I -R -S -S -FALSE - 8 -2011-08-20 -S8 +2011-02-16 +A4 B_ESCHR_COL -S -S +R S R +S FALSE 9 -2011-08-25 -S8 +2011-04-19 +A4 B_ESCHR_COL S -S +R S S FALSE 10 -2011-12-16 -S8 +2011-05-17 +A4 B_ESCHR_COL -S -S R +R +S S FALSE @@ -638,14 +632,12 @@ mutate(keyab = key_antibiotics(.)) %>% mutate(first_weighted = first_isolate(.)) #> NOTE: Using column `bacteria` as input for `col_mo`. -#> [1] "is any" -#> [1] "is any" -#> NOTE: Using column `bacteria` as input for `col_mo`. -#> NOTE: Using column `date` as input for `col_date`. -#> 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,865 first weighted isolates (79.3% of total) +#> NOTE: Using column `bacteria` as input for `col_mo`. +#> NOTE: Using column `date` as input for `col_date`. +#> 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,939 first weighted isolates (79.7% of total) @@ -662,11 +654,11 @@ - - + + - - + + @@ -674,46 +666,46 @@ - - + + - + - + - - + + - - - + + + - - + + - - - + + + + - - - + + - + @@ -722,47 +714,47 @@ - - + + - - - - - - - - - - - - - + + + + + + + + + + + + + - - + + - - + + - - + + - + @@ -770,23 +762,23 @@ - - + + - - + +
isolate
12010-04-19S82010-01-24A4 B_ESCHR_COLSSRR S S TRUE
22010-08-08S82010-03-30A4 B_ESCHR_COLS I SR S FALSEFALSETRUE
32010-10-31S82010-07-21A4 B_ESCHR_COLRIRSSS S FALSE TRUE
42010-11-11S82010-09-23A4 B_ESCHR_COL SIRRSSSFALSE FALSETRUE
52011-04-04S82010-10-05A4 B_ESCHR_COLSR S S S
62011-05-22S82010-10-26A4 B_ESCHR_COLSSSSTRUETRUE
72011-08-15S8B_ESCHR_COLI R S SS FALSEFALSE
72011-02-03A4B_ESCHR_COLSSSSTRUE TRUE
82011-08-20S82011-02-16A4 B_ESCHR_COLSSR S RS FALSE TRUE
92011-08-25S82011-04-19A4 B_ESCHR_COL SSR S S FALSE
102011-12-16S82011-05-17A4 B_ESCHR_COLSS RRS S FALSE TRUE
-

Instead of 2, now 9 isolates are flagged. In total, 79.3% of all isolates are marked ‘first weighted’ - 51% 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 8 isolates are flagged. In total, 79.7% of all isolates are marked ‘first weighted’ - 51.5% 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:

data_1st <- data %>% 
   filter_first_weighted_isolate()
-

So we end up with 15,865 isolates for analysis.

+

So we end up with 15,939 isolates for analysis.

We can remove unneeded columns:

data_1st <- data_1st %>% 
   select(-c(first, keyab))
@@ -812,28 +804,28 @@ 2 -2011-10-29 -H5 -Hospital D -B_STRPT_PNE -S -S +2017-04-12 +H4 +Hospital B +B_STPHY_AUR +R S R +S M Gram positive -Streptococcus -pneumoniae +Staphylococcus +aureus TRUE 3 -2013-02-03 -D7 -Hospital D +2013-08-17 +C3 +Hospital B B_STRPT_PNE -S -S +R +R S R M @@ -844,24 +836,24 @@ 4 -2013-01-14 -U1 -Hospital C -B_ESCHR_COL -S -S -S +2015-05-18 +E9 +Hospital B +B_KLBSL_PNE R -F +R +S +S +M Gram negative -Escherichia -coli +Klebsiella +pneumoniae TRUE 5 -2010-02-23 -O7 +2012-12-26 +W4 Hospital A B_STPHY_AUR R @@ -876,36 +868,36 @@ 6 -2010-09-26 -E6 +2016-09-28 +W1 Hospital D -B_KLBSL_PNE -R -I -R -S -M -Gram negative -Klebsiella -pneumoniae -TRUE - - -8 -2017-06-19 -J3 -Hospital B B_STPHY_AUR +R S S S -S -M +F Gram positive Staphylococcus aureus TRUE + +7 +2016-05-04 +R2 +Hospital B +B_ESCHR_COL +S +S +R +S +F +Gram negative +Escherichia +coli +TRUE +

Time for the analysis!

@@ -923,9 +915,9 @@
freq(paste(data_1st$genus, data_1st$species))

Or can be used like the dplyr way, which is easier readable:

data_1st %>% freq(genus, species)
-

Frequency table of genus and species from a data.frame (15,865 x 13)

+

Frequency table of genus and species from a data.frame (15,939 x 13)

Columns: 2
-Length: 15,865 (of which NA: 0 = 0.00%)
+Length: 15,939 (of which NA: 0 = 0.00%)
Unique: 4

Shortest: 16
Longest: 24

@@ -942,33 +934,33 @@ Longest: 24

1 Escherichia coli -7,999 -50.4% -7,999 -50.4% +8,055 +50.5% +8,055 +50.5% 2 Staphylococcus aureus -3,900 -24.6% -11,899 -75.0% +3,886 +24.4% +11,941 +74.9% 3 Streptococcus pneumoniae -2,453 -15.5% -14,352 -90.5% +2,439 +15.3% +14,380 +90.2% 4 Klebsiella pneumoniae -1,513 -9.5% -15,865 +1,559 +9.8% +15,939 100.0% @@ -979,7 +971,7 @@ Longest: 24

Resistance percentages

The functions portion_R, portion_RI, portion_I, portion_IS and portion_S can be used to determine the portion of a specific antimicrobial outcome. They can be used on their own:

data_1st %>% portion_IR(amox)
-#> [1] 0.4755121
+#> [1] 0.4705439

Or can be used in conjuction with group_by() and summarise(), both from the dplyr package:

data_1st %>% 
   group_by(hospital) %>% 
@@ -992,19 +984,19 @@ Longest: 24

Hospital A -0.4644901 +0.4616191 Hospital B -0.4754156 +0.4714054 Hospital C -0.4927721 +0.4865089 Hospital D -0.4793125 +0.4703324 @@ -1022,23 +1014,23 @@ Longest: 24

Hospital A -0.4644901 -4717 +0.4616191 +4768 Hospital B -0.4754156 -5654 +0.4714054 +5543 Hospital C -0.4927721 -2352 +0.4865089 +2409 Hospital D -0.4793125 -3142 +0.4703324 +3219 @@ -1058,27 +1050,27 @@ Longest: 24

Escherichia -0.7249656 -0.8993624 -0.9729966 +0.7251397 +0.9020484 +0.9738051 Klebsiella -0.7336418 -0.9035030 -0.9801718 +0.7305965 +0.8941629 +0.9737011 Staphylococcus -0.7261538 -0.9179487 -0.9789744 +0.7174472 +0.9217705 +0.9804426 Streptococcus -0.7382797 +0.7437474 0.0000000 -0.7382797 +0.7437474 diff --git a/docs/articles/AMR_files/figure-html/plot 1-1.png b/docs/articles/AMR_files/figure-html/plot 1-1.png index 1fd60fa7..b6f8a3eb 100644 Binary files a/docs/articles/AMR_files/figure-html/plot 1-1.png and b/docs/articles/AMR_files/figure-html/plot 1-1.png differ diff --git a/docs/articles/AMR_files/figure-html/plot 3-1.png b/docs/articles/AMR_files/figure-html/plot 3-1.png index 984c4d91..bc660051 100644 Binary files a/docs/articles/AMR_files/figure-html/plot 3-1.png and b/docs/articles/AMR_files/figure-html/plot 3-1.png differ diff --git a/docs/articles/AMR_files/figure-html/plot 4-1.png b/docs/articles/AMR_files/figure-html/plot 4-1.png index 9b07fca2..847dd9de 100644 Binary files a/docs/articles/AMR_files/figure-html/plot 4-1.png and b/docs/articles/AMR_files/figure-html/plot 4-1.png differ diff --git a/docs/articles/AMR_files/figure-html/plot 5-1.png b/docs/articles/AMR_files/figure-html/plot 5-1.png index 82246e78..6847eec7 100644 Binary files a/docs/articles/AMR_files/figure-html/plot 5-1.png and b/docs/articles/AMR_files/figure-html/plot 5-1.png differ diff --git a/docs/articles/WHONET.html b/docs/articles/WHONET.html index a8905be0..dea88275 100644 --- a/docs/articles/WHONET.html +++ b/docs/articles/WHONET.html @@ -231,7 +231,6 @@

No errors or warnings, so all values are transformed succesfully. Let’s check it though, with a couple of frequency tables:

-

[1] “is any” [1] “is any” [1] “is any”

Frequency table of mo from a data.frame (500 x 54)

Class: mo (character)
Length: 500 (of which NA: 0 = 0.00%)
diff --git a/docs/articles/benchmarks.html b/docs/articles/benchmarks.html index 8f718c6f..9564482c 100644 --- a/docs/articles/benchmarks.html +++ b/docs/articles/benchmarks.html @@ -217,14 +217,14 @@ times = 10) print(S.aureus, unit = "ms", signif = 3) #> Unit: milliseconds -#> expr min lq mean median uq max neval -#> as.mo("sau") 12.7 12.7 22.7 13.2 13.5 71.1 10 -#> as.mo("stau") 87.6 87.8 90.2 87.9 90.6 104.0 10 -#> as.mo("staaur") 12.6 12.6 12.8 12.7 12.8 13.6 10 -#> as.mo("S. aureus") 24.0 24.2 32.0 24.5 25.4 63.2 10 -#> as.mo("S. aureus") 24.1 24.1 29.3 24.2 24.6 74.0 10 -#> as.mo("STAAUR") 12.6 12.7 16.6 12.7 12.8 51.5 10 -#> as.mo("Staphylococcus aureus") 13.5 13.5 17.9 13.6 14.5 54.5 10

+#> expr min lq mean median uq max neval +#> as.mo("sau") 15.0 15.0 21.8 15.2 15.5 80.5 10 +#> as.mo("stau") 90.4 90.6 106.0 91.0 92.7 180.0 10 +#> as.mo("staaur") 15.0 15.1 19.2 15.2 15.7 54.5 10 +#> as.mo("S. aureus") 26.5 26.6 34.7 26.9 28.1 65.9 10 +#> as.mo("S. aureus") 26.6 26.7 31.8 26.8 26.9 76.8 10 +#> as.mo("STAAUR") 15.0 15.1 19.2 15.2 15.5 54.2 10 +#> as.mo("Staphylococcus aureus") 13.4 13.5 17.7 13.6 14.7 52.1 10

In the table above, all measurements are shown in milliseconds (thousands of seconds). A value of 10 milliseconds means it can determine 100 input values per second. It case of 50 milliseconds, this is only 20 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 is a WHONET code) or common laboratory codes, or common full organism names like the last one.

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 Mycoplasma leonicaptivi (B_MYCPL_LEO), a bug probably never found before in humans:

M.leonicaptivi <- microbenchmark(as.mo("myle"),
@@ -237,13 +237,13 @@
 print(M.leonicaptivi, unit = "ms", signif = 3)
 #> Unit: milliseconds
 #>                              expr min  lq mean median  uq max neval
-#>                     as.mo("myle") 134 135  144    135 138 184    10
-#>                   as.mo("mycleo") 445 458  479    487 493 500    10
-#>          as.mo("M. leonicaptivi") 204 207  224    214 245 248    10
-#>         as.mo("M.  leonicaptivi") 205 206  223    208 246 250    10
-#>                   as.mo("MYCLEO") 446 448  480    486 492 529    10
-#>  as.mo("Mycoplasma leonicaptivi") 146 149  170    169 191 193    10
-

That takes 9.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.

+#> as.mo("myle") 136 137 141 137 138 176 10 +#> as.mo("mycleo") 447 464 484 487 490 551 10 +#> as.mo("M. leonicaptivi") 206 208 225 210 248 252 10 +#> as.mo("M. leonicaptivi") 207 208 230 229 251 255 10 +#> as.mo("MYCLEO") 444 446 462 446 486 487 10 +#> as.mo("Mycoplasma leonicaptivi") 147 148 170 173 187 192 10 +

That takes 8 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.

In the figure below, we compare Escherichia coli (which is very common) with Prevotella brevis (which is moderately common) and with Mycoplasma leonicaptivi (which is very uncommon):

par(mar = c(5, 16, 4, 2)) # set more space for left margin text (16)
 
@@ -280,21 +280,11 @@
 # now let's see:
 run_it <- microbenchmark(mo_fullname(x),
                          times = 10)
-#> [1] "is any"
-#> [1] "is any"
-#> [1] "is any"
-#> [1] "is any"
-#> [1] "is any"
-#> [1] "is any"
-#> [1] "is any"
-#> [1] "is any"
-#> [1] "is any"
-#> [1] "is any"
-print(run_it, unit = "ms", signif = 3)
-#> Unit: milliseconds
-#>            expr min  lq mean median  uq max neval
-#>  mo_fullname(x) 623 641  708    648 822 864    10
-

So transforming 500,000 values (!) of 95 unique values only takes 0.65 seconds (647 ms). You only lose time on your unique input values.

+print(run_it, unit = "ms", signif = 3) +#> Unit: milliseconds +#> expr min lq mean median uq max neval +#> mo_fullname(x) 615 647 698 649 801 851 10 +

So transforming 500,000 values (!) of 95 unique values only takes 0.65 seconds (649 ms). You only lose time on your unique input values.

@@ -304,22 +294,12 @@ B = mo_fullname("S. aureus"), C = mo_fullname("Staphylococcus aureus"), times = 10) -#> [1] "is any" -#> [1] "is any" -#> [1] "is any" -#> [1] "is any" -#> [1] "is any" -#> [1] "is any" -#> [1] "is any" -#> [1] "is any" -#> [1] "is any" -#> [1] "is any" -print(run_it, unit = "ms", signif = 3) -#> Unit: milliseconds -#> expr min lq mean median uq max neval -#> A 6.500 6.590 6.710 6.680 6.870 6.900 10 -#> B 24.900 25.000 25.300 25.300 25.500 25.800 10 -#> C 0.259 0.383 0.387 0.395 0.411 0.564 10

+print(run_it, unit = "ms", signif = 3) +#> Unit: milliseconds +#> expr min lq mean median uq max neval +#> A 6.420 6.570 6.670 6.730 6.760 6.780 10 +#> B 27.100 27.200 28.000 27.600 27.800 32.900 10 +#> C 0.255 0.383 0.394 0.412 0.431 0.527 10

So going from mo_fullname("Staphylococcus aureus") to "Staphylococcus aureus" takes 0.0004 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"),
@@ -333,14 +313,14 @@
 print(run_it, unit = "ms", signif = 3)
 #> Unit: milliseconds
 #>  expr   min    lq  mean median    uq   max neval
-#>     A 0.304 0.337 0.393  0.396 0.440 0.513    10
-#>     B 0.297 0.304 0.348  0.349 0.380 0.409    10
-#>     C 0.312 0.361 0.428  0.427 0.513 0.527    10
-#>     D 0.242 0.254 0.302  0.298 0.328 0.414    10
-#>     E 0.243 0.296 0.325  0.328 0.348 0.431    10
-#>     F 0.237 0.257 0.302  0.322 0.329 0.343    10
-#>     G 0.242 0.260 0.306  0.325 0.341 0.345    10
-#>     H 0.244 0.283 0.322  0.335 0.360 0.375    10
+#> A 0.311 0.355 0.435 0.437 0.492 0.566 10 +#> B 0.283 0.299 0.340 0.337 0.362 0.411 10 +#> C 0.393 0.447 0.503 0.496 0.566 0.662 10 +#> D 0.253 0.288 0.324 0.305 0.325 0.523 10 +#> E 0.243 0.249 0.315 0.288 0.342 0.506 10 +#> F 0.239 0.295 0.349 0.327 0.411 0.482 10 +#> G 0.249 0.323 0.364 0.347 0.410 0.493 10 +#> H 0.226 0.303 0.368 0.339 0.478 0.523 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.

@@ -367,13 +347,13 @@ print(run_it, unit = "ms", signif = 4) #> Unit: milliseconds #> expr min lq mean median uq max neval -#> en 14.72 14.90 15.64 15.22 15.27 20.60 10 -#> de 23.41 23.59 27.01 23.69 23.77 57.27 10 -#> nl 23.40 23.58 23.80 23.72 23.83 24.46 10 -#> es 23.18 24.35 37.51 24.80 57.35 58.29 10 -#> it 23.26 23.47 27.11 23.68 24.14 57.07 10 -#> fr 23.37 23.65 27.05 23.76 23.80 57.26 10 -#> pt 23.34 23.47 24.02 23.70 23.86 26.79 10
+#> en 17.14 17.39 20.87 17.54 17.93 50.49 10 +#> de 25.94 26.02 32.71 26.11 26.24 59.33 10 +#> nl 25.41 25.86 29.47 26.04 27.08 59.40 10 +#> es 25.55 25.97 32.75 26.11 26.77 59.62 10 +#> it 25.65 25.90 26.07 26.09 26.11 26.75 10 +#> fr 25.47 25.79 26.10 26.09 26.20 27.23 10 +#> pt 25.72 25.85 29.33 26.07 26.09 59.41 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 cd0b6c3f..9a89bdc9 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/resistance_predict.html b/docs/articles/resistance_predict.html index 15e5cc33..2ef2ffe9 100644 --- a/docs/articles/resistance_predict.html +++ b/docs/articles/resistance_predict.html @@ -305,9 +305,7 @@ filter(mo_gramstain(mo) == "Gram positive") %>% resistance_predict(col_ab = "vanc", year_min = 2010, info = FALSE) %>% ggplot_rsi_predict() -#> [1] "is any" -#> [1] "is any" -#> NOTE: Using column `date` as input for `col_date`. +#> NOTE: Using column `date` as input for `col_date`.

Vancomycin resistance could be 100% in ten years, but might also stay around 0%.

You can define the model with the model parameter. The default model 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.

@@ -352,9 +350,7 @@ filter(mo_gramstain(mo) == "Gram positive") %>% resistance_predict(col_ab = "vanc", year_min = 2010, info = FALSE, model = "linear") %>% ggplot_rsi_predict() -#> [1] "is any" -#> [1] "is any" -#> NOTE: Using column `date` as input for `col_date`. +#> NOTE: Using column `date` as input for `col_date`.

This seems more likely, doesn’t it?

The model itself is also available from the object, as an attribute: