diff --git a/DESCRIPTION b/DESCRIPTION index 65ee3f40..e42345af 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: AMR -Version: 0.7.1.9066 -Date: 2019-08-27 +Version: 0.7.1.9067 +Date: 2019-08-28 Title: Antimicrobial Resistance Analysis Authors@R: c( person(role = c("aut", "cre"), diff --git a/NEWS.md b/NEWS.md index 6d157a75..b75b7874 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# AMR 0.7.1.9066 +# AMR 0.7.1.9067 ### Breaking * Determination of first isolates now **excludes** all 'unknown' microorganisms at default, i.e. microbial code `"UNKNOWN"`. They can be included with the new parameter `include_unknown`: diff --git a/R/first_isolate.R b/R/first_isolate.R index a49bb844..0d9af640 100755 --- a/R/first_isolate.R +++ b/R/first_isolate.R @@ -496,7 +496,7 @@ first_isolate <- function(x, big.mark <- ifelse(decimal.mark != ",", ",", ".") # handle empty microorganisms - if (any(all_first$newvar_mo == "UNKNOWN", na.rm = TRUE)) { + if (any(all_first$newvar_mo == "UNKNOWN", na.rm = TRUE) & info == TRUE) { if (include_unknown == TRUE) { message(blue(paste0("NOTE: Included ", format(sum(all_first$newvar_mo == "UNKNOWN"), decimal.mark = decimal.mark, big.mark = big.mark), @@ -511,7 +511,7 @@ first_isolate <- function(x, all_first[which(all_first$newvar_mo == "UNKNOWN"), 'real_first_isolate'] <- include_unknown # exclude all NAs - if (any(is.na(all_first$newvar_mo))) { + if (any(is.na(all_first$newvar_mo)) & info == TRUE) { message(blue(paste0("NOTE: Excluded ", format(sum(is.na(all_first$newvar_mo)), decimal.mark = decimal.mark, big.mark = big.mark), ' isolates with a microbial ID "NA" (column `', bold(col_mo), '`).'))) diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index 37891d44..6c5db214 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 14fbcb40..74153215 100644 --- a/docs/articles/AMR.html +++ b/docs/articles/AMR.html @@ -40,7 +40,7 @@ @@ -185,7 +185,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 27 August 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 August 2019.
Now, let’s start the cleaning and the analysis!
@@ -406,8 +406,8 @@ # # Item Count Percent Cum. Count Cum. Percent # --- ----- ------- -------- ----------- ------------- -# 1 M 10,514 52.6% 10,514 52.6% -# 2 F 9,486 47.4% 20,000 100.0% +# 1 M 10,360 51.8% 10,360 51.8% +# 2 F 9,640 48.2% 20,000 100.0%So, we can draw at least two conclusions immediately. From a data scientists perspective, the data looks clean: only values M
and F
. From a researchers 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 %>%
@@ -437,14 +437,14 @@
# Pasteurella multocida (no changes)
# Staphylococcus (no changes)
# Streptococcus groups A, B, C, G (no changes)
-# Streptococcus pneumoniae (1,504 values changed)
+# Streptococcus pneumoniae (1,477 values changed)
# Viridans group streptococci (no changes)
#
# EUCAST Expert Rules, Intrinsic Resistance and Exceptional Phenotypes (v3.1, 2016)
-# Table 01: Intrinsic resistance in Enterobacteriaceae (1,298 values changed)
+# Table 01: Intrinsic resistance in Enterobacteriaceae (1,306 values changed)
# Table 02: Intrinsic resistance in non-fermentative Gram-negative bacteria (no changes)
# Table 03: Intrinsic resistance in other Gram-negative bacteria (no changes)
-# Table 04: Intrinsic resistance in Gram-positive bacteria (2,705 values changed)
+# Table 04: Intrinsic resistance in Gram-positive bacteria (2,760 values changed)
# Table 08: Interpretive rules for B-lactam agents and Gram-positive cocci (no changes)
# Table 09: Interpretive rules for B-lactam agents and Gram-negative rods (no changes)
# Table 11: Interpretive rules for macrolides, lincosamides, and streptogramins (no changes)
@@ -452,24 +452,24 @@
# Table 13: Interpretive rules for quinolones (no changes)
#
# Other rules
-# Non-EUCAST: amoxicillin/clav acid = S where ampicillin = S (2,323 values changed)
-# Non-EUCAST: ampicillin = R where amoxicillin/clav acid = R (118 values changed)
+# Non-EUCAST: amoxicillin/clav acid = S where ampicillin = S (2,250 values changed)
+# Non-EUCAST: ampicillin = R where amoxicillin/clav acid = R (100 values changed)
# Non-EUCAST: piperacillin = R where piperacillin/tazobactam = R (no changes)
# Non-EUCAST: piperacillin/tazobactam = S where piperacillin = S (no changes)
# Non-EUCAST: trimethoprim = R where trimethoprim/sulfa = R (no changes)
# Non-EUCAST: trimethoprim/sulfa = S where trimethoprim = S (no changes)
#
# --------------------------------------------------------------------------
-# EUCAST rules affected 6,559 out of 20,000 rows, making a total of 7,948 edits
+# EUCAST rules affected 6,548 out of 20,000 rows, making a total of 7,893 edits
# => added 0 test results
#
-# => changed 7,948 test results
-# - 115 test results changed from S to I
-# - 4,723 test results changed from S to R
-# - 1,098 test results changed from I to S
-# - 338 test results changed from I to R
-# - 1,648 test results changed from R to S
-# - 26 test results changed from R to I
+# => changed 7,893 test results
+# - 102 test results changed from S to I
+# - 4,732 test results changed from S to R
+# - 1,108 test results changed from I to S
+# - 328 test results changed from I to R
+# - 1,603 test results changed from R to S
+# - 20 test results changed from R to I
# --------------------------------------------------------------------------
#
# Use eucast_rules(..., verbose = TRUE) (on your original data) to get a data.frame with all specified edits instead.
So only is suitable for resistance analysis! We can now filter on it with the filter()
function, also from the dplyr
package:
We made a slight twist to the CLSI algorithm, to take into account the antimicrobial susceptibility profile. Have a look at all isolates of patient K7, sorted on date:
+We made a slight twist to the CLSI algorithm, to take into account the antimicrobial susceptibility profile. Have a look at all isolates of patient Q3, sorted on date:
isolate | @@ -524,43 +524,43 @@|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | -2010-02-15 | -K7 | +2010-01-10 | +Q3 | B_ESCHR_COL | +R | S | -S | -S | +R | S | TRUE | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2 | -2010-03-24 | -K7 | +2010-03-10 | +Q3 | B_ESCHR_COL | -R | -R | +S | +S | R | S | FALSE | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3 | -2010-06-05 | -K7 | +2010-04-30 | +Q3 | B_ESCHR_COL | R | S | -R | +S | S | FALSE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4 | -2010-07-16 | -K7 | +2010-07-02 | +Q3 | B_ESCHR_COL | -I | +R | S | S | S | @@ -568,8 +568,19 @@|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5 | -2010-09-22 | -K7 | +2010-10-10 | +Q3 | +B_ESCHR_COL | +S | +S | +R | +S | +FALSE | +|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6 | +2010-11-26 | +Q3 | B_ESCHR_COL | R | S | @@ -577,21 +588,10 @@S | FALSE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6 | -2011-01-18 | -K7 | -B_ESCHR_COL | -S | -S | -S | -S | -FALSE | -|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7 | -2011-01-26 | -K7 | +2011-01-09 | +Q3 | B_ESCHR_COL | S | S | @@ -601,30 +601,30 @@||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
8 | -2011-02-11 | -K7 | +2011-02-01 | +Q3 | B_ESCHR_COL | R | S | +R | +S | +TRUE | +|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
9 | +2011-03-20 | +Q3 | +B_ESCHR_COL | +S | +S | S | S | FALSE | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
9 | -2011-02-17 | -K7 | -B_ESCHR_COL | -I | -S | -S | -S | -TRUE | -|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
10 | -2011-04-01 | -K7 | +2011-08-04 | +Q3 | B_ESCHR_COL | S | S | @@ -645,7 +645,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,107 first weighted isolates (75.5% of total) +# => Found 15,134 first weighted isolates (75.7% of total)
isolate | @@ -662,23 +662,23 @@|||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | -2010-02-15 | -K7 | +2010-01-10 | +Q3 | B_ESCHR_COL | +R | S | -S | -S | +R | S | TRUE | TRUE |
2 | -2010-03-24 | -K7 | +2010-03-10 | +Q3 | B_ESCHR_COL | -R | -R | +S | +S | R | S | FALSE | @@ -686,32 +686,20 @@|
3 | -2010-06-05 | -K7 | +2010-04-30 | +Q3 | B_ESCHR_COL | R | S | -R | +S | S | FALSE | TRUE | |
4 | -2010-07-16 | -K7 | -B_ESCHR_COL | -I | -S | -S | -S | -FALSE | -TRUE | -||||
5 | -2010-09-22 | -K7 | +2010-07-02 | +Q3 | B_ESCHR_COL | R | S | @@ -720,13 +708,25 @@FALSE | FALSE | ||||
6 | -2011-01-18 | -K7 | +|||||||||||
5 | +2010-10-10 | +Q3 | B_ESCHR_COL | S | S | +R | +S | +FALSE | +TRUE | +||||
6 | +2010-11-26 | +Q3 | +B_ESCHR_COL | +R | +S | S | S | FALSE | @@ -734,44 +734,44 @@|||||
7 | -2011-01-26 | -K7 | +2011-01-09 | +Q3 | B_ESCHR_COL | S | S | S | S | FALSE | -FALSE | +TRUE | |
8 | -2011-02-11 | -K7 | +2011-02-01 | +Q3 | B_ESCHR_COL | R | S | +R | S | -S | -FALSE | +TRUE | TRUE |
9 | -2011-02-17 | -K7 | +2011-03-20 | +Q3 | B_ESCHR_COL | -I | S | S | S | -TRUE | +S | +FALSE | TRUE |
10 | -2011-04-01 | -K7 | +2011-08-04 | +Q3 | B_ESCHR_COL | S | S | @@ -782,11 +782,11 @@
Instead of 2, now 7 isolates are flagged. In total, of all isolates are marked ‘first weighted’ - 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, of all isolates are marked ‘first weighted’ - 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,107 isolates for analysis.
+So we end up with 15,134 isolates for analysis.
We can remove unneeded columns:
@@ -812,15 +812,15 @@Frequency table
Class: character
-Length: 15,107 (of which NA: 0 = 0.00%)
+Length: 15,134 (of which NA: 0 = 0.00%)
Unique: 4
Shortest: 16
Longest: 24
The functions portion_S()
, portion_SI()
, portion_I()
, portion_IR()
and portion_R()
can be used to determine the portion of a specific antimicrobial outcome. As per the EUCAST guideline of 2019, we calculate resistance as the portion of R (portion_R()
) and susceptibility as the portion of S and I (portion_SI()
). These functions can be used on their own:
Or can be used in conjuction with group_by()
and summarise()
, both from the dplyr
package:
data_1st %>%
group_by(hospital) %>%
@@ -992,19 +992,19 @@ Longest: 24
Hospital A
-0.4686054
+0.4684865
Hospital B
-0.4644004
+0.4595616
Hospital C
-0.4821269
+0.4685616
Hospital D
-0.4655684
+0.4664897
benchmarks.Rmd
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"),
@@ -229,12 +229,12 @@
print(T.islandicus, unit = "ms", signif = 2)
# Unit: milliseconds
# expr min lq mean median uq max neval
-# as.mo("theisl") 260 270 280 280 290 300 10
-# as.mo("THEISL") 260 280 300 290 300 370 10
-# as.mo("T. islandicus") 130 140 140 140 150 150 10
-# as.mo("T. islandicus") 130 130 130 130 140 150 10
-# as.mo("Thermus islandicus") 47 48 53 50 52 71 10
That takes 9.6 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") 260 280 280 280 290 290 10 +# as.mo("THEISL") 250 260 280 280 290 300 10 +# as.mo("T. islandicus") 120 130 130 130 150 150 10 +# as.mo("T. islandicus") 120 130 140 140 140 150 10 +# as.mo("Thermus islandicus") 47 47 53 48 62 67 10 +That takes 9.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)
@@ -280,8 +280,8 @@
print(run_it, unit = "ms", signif = 3)
# Unit: milliseconds
# expr min lq mean median uq max neval
-# mo_name(x) 611 618 646 642 656 720 10
So transforming 500,000 values (!!) of 50 unique values only takes 0.64 seconds (641 ms). You only lose time on your unique input values.
+# mo_name(x) 587 591 604 594 612 653 10 +So transforming 500,000 values (!!) of 50 unique values only takes 0.59 seconds (594 ms). You only lose time on your unique input values.
So going from mo_name("Staphylococcus aureus")
to "Staphylococcus aureus"
takes 0.0008 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:
So going from mo_name("Staphylococcus aureus")
to "Staphylococcus aureus"
takes 0.0009 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"),
C = mo_name("Staphylococcus aureus"),
@@ -310,14 +310,14 @@
print(run_it, unit = "ms", signif = 3)
# Unit: milliseconds
# expr min lq mean median uq max neval
-# A 0.468 0.472 0.483 0.483 0.487 0.520 10
-# B 0.619 0.621 0.649 0.648 0.656 0.698 10
-# C 0.702 0.732 0.770 0.788 0.799 0.809 10
-# D 0.456 0.457 0.487 0.466 0.475 0.684 10
-# E 0.451 0.463 0.466 0.466 0.471 0.479 10
-# F 0.437 0.457 0.464 0.463 0.469 0.497 10
-# G 0.450 0.454 0.468 0.466 0.477 0.495 10
-# H 0.454 0.458 0.471 0.464 0.471 0.510 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.
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 ce9ef648..817c1125 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/index.html b/docs/articles/index.html index 1533f23e..0fac2ef6 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -78,7 +78,7 @@ diff --git a/docs/articles/resistance_predict.html b/docs/articles/resistance_predict.html index e3b2144a..1de32406 100644 --- a/docs/articles/resistance_predict.html +++ b/docs/articles/resistance_predict.html @@ -40,7 +40,7 @@ @@ -185,7 +185,7 @@resistance_predict.Rmd
as.mo(..., allow_uncertain = 3)
Contents