diff --git a/R/age.R b/R/age.R index 47e1e502..26dbaa2a 100755 --- a/R/age.R +++ b/R/age.R @@ -50,8 +50,8 @@ age <- function(x, reference = Sys.Date()) { as.integer(years_gap)) if (any(ages < 0, na.rm = TRUE)) { - warning("NAs introduced for ages below 0.") ages[ages < 0] <- NA_integer_ + warning("NAs introduced for ages below 0.") } if (any(ages > 120, na.rm = TRUE)) { warning("Some ages are > 120.") @@ -71,7 +71,7 @@ age <- function(x, reference = Sys.Date()) { #' The default is to split on young children (0-11), youth (12-24), young adults (25-54), middle-aged adults (55-74) and elderly (75+).} #' \item{A character:} #' \itemize{ -#' \item{\code{"children"}, equivalent of: \code{c(0, 1, 2, 4, 6, 13, 18)}. This will split on 0, 1, 2-3, 4-5, 6-12, 13-17 and 18+.} +#' \item{\code{"children"} or \code{"kids"}, equivalent of: \code{c(0, 1, 2, 4, 6, 13, 18)}. This will split on 0, 1, 2-3, 4-5, 6-12, 13-17 and 18+.} #' \item{\code{"elderly"} or \code{"seniors"}, equivalent of: \code{c(65, 75, 85)}. This will split on 0-64, 65-74, 75-84, 85+.} #' \item{\code{"fives"}, equivalent of: \code{1:20 * 5}. This will split on 0-4, 5-9, 10-14, ..., 90-94, 95-99, 100+.} #' \item{\code{"tens"}, equivalent of: \code{1:10 * 10}. This will split on 0-9, 10-19, 20-29, ... 80-89, 90-99, 100+.} @@ -107,17 +107,15 @@ age <- function(x, reference = Sys.Date()) { #' # resistance of ciprofloxacine per age group #' library(dplyr) #' septic_patients %>% -#' mutate(first_isolate = first_isolate(.)) %>% -#' filter(first_isolate == TRUE, -#' mo == as.mo("E. coli")) %>% +#' filter_first_isolate) %>% +#' filter(mo == as.mo("E. coli")) %>% #' group_by(age_group = age_groups(age)) %>% -#' select(age_group, -#' CIP) %>% +#' select(age_group, CIP) %>% #' ggplot_rsi(x = "age_group") age_groups <- function(x, split_at = c(12, 25, 55, 75)) { if (is.character(split_at)) { split_at <- split_at[1L] - if (split_at %like% "^(child|kid)") { + if (split_at %like% "^(child|kid|junior)") { split_at <- c(0, 1, 2, 4, 6, 13, 18) } else if (split_at %like% "^(elder|senior)") { split_at <- c(65, 75, 85) @@ -133,10 +131,12 @@ age_groups <- function(x, split_at = c(12, 25, 55, 75)) { } split_at <- sort(unique(split_at)) if (!split_at[1] == 0) { + # add base number 0 split_at <- c(0, split_at) } + split_at <- split_at[!is.na(split_at)] if (length(split_at) == 1) { - # only 0 available + # only 0 is available stop("invalid value for `split_at`.") } diff --git a/docs/articles/AMR.html b/docs/articles/AMR.html index 2519e790..b66f2e0c 100644 --- a/docs/articles/AMR.html +++ b/docs/articles/AMR.html @@ -40,7 +40,7 @@ AMR (for R) - 0.6.1.9037 + 0.6.1.9040 @@ -334,69 +334,69 @@ -2016-12-11 -T9 +2010-08-30 +X2 Hospital B -Escherichia coli -R +Staphylococcus aureus +S S S S F -2013-02-14 -A3 -Hospital B -Escherichia coli -S -S -R -S -M - - -2011-05-14 -W4 -Hospital D -Streptococcus pneumoniae -R -S -S -S -F - - -2010-02-09 -G3 -Hospital C -Escherichia coli -R -S -R -S -M - - -2016-04-24 -B7 +2015-08-09 +E8 Hospital A -Escherichia coli +Staphylococcus aureus +R S -I S S M + +2014-05-04 +M8 +Hospital D +Staphylococcus aureus +R +S +R +S +M + -2010-02-20 -L7 +2013-05-31 +J10 +Hospital B +Staphylococcus aureus +R +R +S +S +M + + +2014-07-13 +H9 Hospital C -Escherichia coli +Streptococcus pneumoniae +S +S R +S +M + + +2015-03-14 +I6 +Hospital D +Staphylococcus aureus R S S +S M @@ -418,8 +418,8 @@ # # Item Count Percent Cum. Count Cum. Percent # --- ----- ------- -------- ----------- ------------- -# 1 M 10,367 51.8% 10,367 51.8% -# 2 F 9,633 48.2% 20,000 100.0% +# 1 M 10,432 52.2% 10,432 52.2% +# 2 F 9,568 47.8% 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 %>%
@@ -449,14 +449,14 @@
 # Pasteurella multocida (no new changes)
 # Staphylococcus (no new changes)
 # Streptococcus groups A, B, C, G (no new changes)
-# Streptococcus pneumoniae (1390 new changes)
+# Streptococcus pneumoniae (1464 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 (1264 new changes)
+# Table 01: Intrinsic resistance in Enterobacteriaceae (1265 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 (2725 new changes)
+# Table 04: Intrinsic resistance in Gram-positive bacteria (2753 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 (2301 new changes)
-# Non-EUCAST: ampicillin = R where amoxicillin/clav acid = R (114 new changes)
+# Non-EUCAST: amoxicillin/clav acid = S where ampicillin = S (2272 new changes)
+# Non-EUCAST: ampicillin = R where amoxicillin/clav acid = R (108 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,521 out of 20,000 rows, making a total of 7,794 edits
+# EUCAST rules affected 6,521 out of 20,000 rows, making a total of 7,862 edits
 # => added 0 test results
 # 
-# => 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
+# => changed 7,862 test results
+#    - 112 test results changed from S to I
+#    - 4,682 test results changed from S to R
+#    - 1,085 test results changed from I to S
+#    - 303 test results changed from I to R
+#    - 1,657 test results changed from R to S
+#    - 23 test results changed from R to I
 # --------------------------------------------------------------------------
 # 
 # Use verbose = TRUE to get a data.frame with all specified edits instead.
@@ -509,8 +509,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,627 first isolates (28.1% of total) -

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

+# => Found 5,661 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:

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

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

@@ -536,8 +536,8 @@ 1 -2010-03-09 -J4 +2010-01-13 +L3 B_ESCHR_COL S S @@ -547,30 +547,30 @@ 2 -2010-03-19 -J4 +2010-02-27 +L3 B_ESCHR_COL +S +S +R R -S -S -S FALSE 3 -2010-03-31 -J4 +2010-04-07 +L3 B_ESCHR_COL S S -R +S S FALSE 4 -2010-05-07 -J4 +2010-08-07 +L3 B_ESCHR_COL R S @@ -580,10 +580,10 @@ 5 -2010-06-21 -J4 +2010-08-09 +L3 B_ESCHR_COL -I +R S S S @@ -591,21 +591,21 @@ 6 -2010-07-10 -J4 +2010-09-28 +L3 B_ESCHR_COL S S -R +S S FALSE 7 -2010-11-26 -J4 +2010-10-07 +L3 B_ESCHR_COL -S +R S R S @@ -613,19 +613,19 @@ 8 -2010-12-04 -J4 +2010-12-15 +L3 B_ESCHR_COL +S +S R S -S -S FALSE 9 -2011-03-19 -J4 +2011-10-03 +L3 B_ESCHR_COL S S @@ -635,8 +635,8 @@ 10 -2011-05-16 -J4 +2011-12-06 +L3 B_ESCHR_COL S S @@ -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,074 first weighted isolates (75.4% of total) +# => Found 15,116 first weighted isolates (75.6% of total) @@ -674,8 +674,8 @@ - - + + @@ -686,32 +686,32 @@ - - + + + + + - - - - - + + - + - - + + @@ -722,10 +722,10 @@ - - + + - + @@ -734,44 +734,44 @@ - - + + - + - - + + - + - + - - + + + + - - - - + + @@ -782,8 +782,8 @@ - - + + @@ -794,11 +794,11 @@
isolate
12010-03-09J42010-01-13L3 B_ESCHR_COL S S
22010-03-19J42010-02-27L3 B_ESCHR_COLSSR RSSS FALSE TRUE
32010-03-31J42010-04-07L3 B_ESCHR_COL S SRS S FALSE TRUE
42010-05-07J42010-08-07L3 B_ESCHR_COL R S
52010-06-21J42010-08-09L3 B_ESCHR_COLIR S S S
62010-07-10J42010-09-28L3 B_ESCHR_COL S SRS S FALSE TRUE
72010-11-26J42010-10-07L3 B_ESCHR_COLSR S R S FALSEFALSETRUE
82010-12-04J42010-12-15L3 B_ESCHR_COLSS R SSS FALSE TRUE
92011-03-19J42011-10-03L3 B_ESCHR_COL S S
102011-05-16J42011-12-06L3 B_ESCHR_COL S S
-

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.

+

Instead of 2, now 8 isolates are flagged. In total, 75.6% of all isolates are marked ‘first weighted’ - 47.3% 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,074 isolates for analysis.

+

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

We can remove unneeded columns:

data_1st <- data_1st %>% 
   select(-c(first, keyab))
@@ -822,93 +822,93 @@ -2016-12-11 -T9 +2010-08-30 +X2 Hospital B -B_ESCHR_COL -R +B_STPHY_AUR +S S S S F -Gram negative -Escherichia -coli +Gram positive +Staphylococcus +aureus TRUE -2013-02-14 -A3 -Hospital B -B_ESCHR_COL +2015-08-09 +E8 +Hospital A +B_STPHY_AUR +R S S +S +M +Gram positive +Staphylococcus +aureus +TRUE + + +2014-05-04 +M8 +Hospital D +B_STPHY_AUR +R +S R S M -Gram negative -Escherichia -coli +Gram positive +Staphylococcus +aureus TRUE - -2011-05-14 -W4 -Hospital D -B_STRPT_PNE + +2013-05-31 +J10 +Hospital B +B_STPHY_AUR R R S +S +M +Gram positive +Staphylococcus +aureus +TRUE + + +2014-07-13 +H9 +Hospital C +B_STRPT_PNE +S +S R -F +R +M Gram positive Streptococcus pneumoniae TRUE -2010-02-09 -G3 -Hospital C -B_ESCHR_COL +2015-03-14 +I6 +Hospital D +B_STPHY_AUR 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 +Gram positive +Staphylococcus +aureus TRUE @@ -928,9 +928,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,074 x 13)

+

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

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

Shortest: 16
Longest: 24

@@ -947,33 +947,33 @@ Longest: 24

1 Escherichia coli -7,504 -49.8% -7,504 -49.8% +7,472 +49.4% +7,472 +49.4% 2 Staphylococcus aureus -3,702 -24.6% -11,206 -74.3% +3,773 +25.0% +11,245 +74.4% 3 Streptococcus pneumoniae -2,313 -15.3% -13,519 -89.7% +2,296 +15.2% +13,541 +89.6% 4 Klebsiella pneumoniae -1,555 -10.3% -15,074 +1,575 +10.4% +15,116 100.0% @@ -984,7 +984,7 @@ Longest: 24

Resistance percentages

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:

data_1st %>% portion_R(AMX)
-# [1] 0.4647738
+# [1] 0.4655994

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

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

Hospital A -0.4603103 +0.4690460 Hospital B -0.4641985 +0.4633959 Hospital C -0.4670185 +0.4724376 Hospital D -0.4706464 +0.4590056 @@ -1027,23 +1027,23 @@ Longest: 24

Hospital A -0.4603103 -4447 +0.4690460 +4539 Hospital B -0.4641985 -5321 +0.4633959 +5218 Hospital C -0.4670185 -2274 +0.4724376 +2322 Hospital D -0.4706464 -3032 +0.4590056 +3037 @@ -1063,27 +1063,27 @@ Longest: 24

Escherichia -0.9235075 -0.8956557 -0.9941365 +0.9243844 +0.8899893 +0.9945128 Klebsiella -0.8135048 -0.8926045 -0.9858521 +0.8101587 +0.8996825 +0.9828571 Staphylococcus -0.9240951 -0.9289573 -0.9972988 +0.9207527 +0.9114763 +0.9912536 Streptococcus -0.6182447 +0.6276132 0.0000000 -0.6182447 +0.6276132 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 b7382182..adb4667c 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 48275f63..915bacde 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 5f4f4bfd..65aae47a 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 713cb2ad..98f1c4be 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/EUCAST.html b/docs/articles/EUCAST.html index e3ed41b0..81461b30 100644 --- a/docs/articles/EUCAST.html +++ b/docs/articles/EUCAST.html @@ -40,7 +40,7 @@ AMR (for R) - 0.6.1.9037 + 0.6.1.9040
diff --git a/docs/articles/G_test.html b/docs/articles/G_test.html index cf9e07bd..d2295463 100644 --- a/docs/articles/G_test.html +++ b/docs/articles/G_test.html @@ -40,7 +40,7 @@ AMR (for R) - 0.6.1.9037 + 0.6.1.9040 diff --git a/docs/articles/MDR.html b/docs/articles/MDR.html index d1fd8900..366e073d 100644 --- a/docs/articles/MDR.html +++ b/docs/articles/MDR.html @@ -40,7 +40,7 @@ AMR (for R) - 0.6.1.9037 + 0.6.1.9040 @@ -242,17 +242,17 @@

The data set looks like this now:

head(my_TB_data)
 #   rifampicin isoniazid gatifloxacin ethambutol pyrazinamide moxifloxacin
-# 1          S         S            R          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
+# 1          S         S            R          R            S            R
+# 2          R         S            S          S            S            R
+# 3          S         S            S          S            I            I
+# 4          S         I            R          I            I            S
+# 5          S         R            S          R            R            R
+# 6          R         R            R          R            S            S
 #   kanamycin
 # 1         S
-# 2         S
-# 3         S
-# 4         R
+# 2         R
+# 3         R
+# 4         S
 # 5         R
 # 6         I

We can now add the interpretation of MDR-TB to our data set:

@@ -285,40 +285,40 @@ Unique: 5

1 Mono-resistance -3,249 -65.0% -3,249 -65.0% +3,214 +64.3% +3,214 +64.3% 2 Negative -647 -12.9% -3,896 -77.9% +685 +13.7% +3,899 +78.0% 3 Multidrug resistance -625 -12.5% -4,521 -90.4% +576 +11.5% +4,475 +89.5% 4 Poly-resistance -281 -5.6% -4,802 -96.0% +294 +5.9% +4,769 +95.4% 5 Extensive drug resistance -198 -4.0% +231 +4.6% 5,000 100.0% diff --git a/docs/articles/SPSS.html b/docs/articles/SPSS.html index 5c2a73d4..824388fe 100644 --- a/docs/articles/SPSS.html +++ b/docs/articles/SPSS.html @@ -40,7 +40,7 @@ AMR (for R) - 0.6.1.9037 + 0.6.1.9040 diff --git a/docs/articles/WHONET.html b/docs/articles/WHONET.html index 4699d3eb..4b86c68f 100644 --- a/docs/articles/WHONET.html +++ b/docs/articles/WHONET.html @@ -40,7 +40,7 @@ AMR (for R) - 0.6.1.9037 + 0.6.1.9040 diff --git a/docs/articles/ab_property.html b/docs/articles/ab_property.html index 45fddb28..8a0fc6ae 100644 --- a/docs/articles/ab_property.html +++ b/docs/articles/ab_property.html @@ -40,7 +40,7 @@ AMR (for R) - 0.6.1.9037 + 0.6.1.9040 diff --git a/docs/articles/benchmarks.html b/docs/articles/benchmarks.html index cd7763de..54d11fea 100644 --- a/docs/articles/benchmarks.html +++ b/docs/articles/benchmarks.html @@ -40,7 +40,7 @@ AMR (for R) - 0.6.1.9037 + 0.6.1.9040 @@ -224,14 +224,14 @@ times = 10) print(S.aureus, unit = "ms", signif = 2) # Unit: milliseconds -# expr min lq mean median uq max neval -# 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
+# expr min lq mean median uq max neval +# as.mo("sau") 18.0 18 28 18 18.0 76 10 +# as.mo("stau") 48.0 48 70 48 92.0 130 10 +# as.mo("staaur") 18.0 18 18 18 18.0 19 10 +# as.mo("STAAUR") 17.0 17 27 18 18.0 63 10 +# as.mo("S. aureus") 28.0 28 29 28 29.0 29 10 +# as.mo("S. aureus") 28.0 28 29 28 29.0 30 10 +# as.mo("Staphylococcus aureus") 7.9 8 17 8 8.1 52 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 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.

+# as.mo("theisl") 470 470 500 520 520 520 10 +# as.mo("THEISL") 470 470 490 470 520 520 10 +# as.mo("T. islandicus") 74 74 79 74 75 120 10 +# as.mo("T. islandicus") 74 74 92 74 120 120 10 +# as.mo("Thermus islandicus") 73 73 80 73 73 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.

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) 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.

+# mo_fullname(x) 637 674 745 720 764 936 10 +

So transforming 500,000 values (!!) of 50 unique values only takes 0.72 seconds (720 ms). You only lose time on your unique input values.

@@ -307,11 +307,11 @@ times = 10) print(run_it, unit = "ms", signif = 3) # Unit: milliseconds -# 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:

+# expr min lq mean median uq max neval +# A 13.10 13.2 13.50 13.40 13.60 14.30 10 +# B 25.50 25.8 30.60 25.80 26.70 70.70 10 +# C 1.62 1.8 1.85 1.81 1.92 2.04 10 +

So going from mo_fullname("Staphylococcus aureus") to "Staphylococcus aureus" takes 0.0018 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_fullname("Staphylococcus aureus"),
@@ -324,14 +324,14 @@
 print(run_it, unit = "ms", signif = 3)
 # Unit: milliseconds
 #  expr   min    lq  mean median    uq   max neval
-#     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
+# A 0.517 0.559 0.605 0.582 0.648 0.771 10 +# B 0.549 0.602 0.681 0.684 0.720 0.856 10 +# C 1.640 1.710 1.830 1.790 2.000 2.090 10 +# D 0.620 0.672 0.768 0.759 0.846 0.985 10 +# E 0.487 0.576 0.659 0.673 0.749 0.834 10 +# F 0.489 0.590 0.639 0.637 0.692 0.751 10 +# G 0.471 0.478 0.646 0.689 0.753 0.856 10 +# H 0.200 0.251 0.348 0.341 0.454 0.531 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.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
+# en 18.47 18.50 23.02 18.55 18.75 62.99 10 +# de 23.26 23.35 23.55 23.52 23.75 23.93 10 +# nl 36.79 36.90 50.46 37.27 81.55 81.90 10 +# es 23.28 23.40 27.94 23.50 23.64 67.84 10 +# it 23.12 23.23 23.38 23.33 23.60 23.67 10 +# fr 23.30 23.38 23.61 23.47 23.86 24.32 10 +# pt 23.33 23.38 23.63 23.64 23.87 23.95 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 8c759f38..1644365b 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 e235c3d2..fe9e6433 100644 --- a/docs/articles/freq.html +++ b/docs/articles/freq.html @@ -40,7 +40,7 @@ AMR (for R) - 0.6.1.9037 + 0.6.1.9040 @@ -199,7 +199,7 @@

How to create frequency tables

Matthijs S. Berends

-

28 May 2019

+

29 May 2019

@@ -211,13 +211,23 @@

Introduction

-

Frequency tables (or frequency distributions) are summaries of the distribution of values in a sample. With the freq function, you can create univariate frequency tables. Multiple variables will be pasted into one variable, so it forces a univariate distribution. We take the septic_patients dataset (included in this AMR package) as example.

+

Frequency tables (or frequency distributions) are summaries of the distribution of values in a sample. With the freq() function, you can create univariate frequency tables. Multiple variables will be pasted into one variable, so it forces a univariate distribution. We take the septic_patients dataset (included in this AMR package) as example.

Frequencies of one variable

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:

-
septic_patients %>% freq(gender)
+
# Any of these will work:
+# freq(septic_patients$gender)
+# freq(septic_patients[, "gender"])
+
+# Using tidyverse:
+# septic_patients$gender %>% freq()
+# septic_patients[, "gender"] %>% freq()
+# septic_patients %>% freq("gender")
+
+# Probably the fastest and easiest:
+septic_patients %>% freq(gender)  

Frequency table of gender from a data.frame (2,000 x 49)

Class: character
Length: 2,000 (of which NA: 0 = 0.00%)
@@ -489,8 +499,10 @@ Outliers: 15 (unique count: 12)

  • Mean

  • Standard deviation

  • Coefficient of variation (CV), the standard deviation divided by the mean

  • -
  • Five numbers of Tukey (min, Q1, median, Q3, max)

  • -
  • Coefficient of quartile variation (CQV, sometimes called coefficient of dispersion), calculated as (Q3 - Q1) / (Q3 + Q1) using quantile with type = 6 as quantile algorithm to comply with SPSS standards

  • +
  • Mean absolute deviation (MAD), the median of the absolute deviations from the median - a more robust statistic than the standard deviation

  • +
  • Five numbers of Tukey, namely: the minimum, Q1, median, Q3 and maximum

  • +
  • Interquartile range (IQR), the distance between Q1 and Q3

  • +
  • Coefficient of quartile variation (CQV, sometimes called coefficient of dispersion), calculated as (Q3 - Q1) / (Q3 + Q1) using quantile() with type = 6 as quantile algorithm to comply with SPSS standards

  • Outliers (total count and unique count)

  • So for example, the above frequency table quickly shows the median age of patients being 74.

    @@ -498,7 +510,7 @@ Outliers: 15 (unique count: 12)

    Frequencies of factors

    -

    To sort frequencies of factors on factor level instead of item count, use the sort.count parameter.

    +

    To sort frequencies of factors on their levels instead of item count, use the sort.count parameter.

    sort.count is TRUE by default. Compare this default behaviour…

    @@ -551,7 +563,7 @@ Unique: 4

    -

    … with this, where items are now sorted on count:

    +

    … to this, where items are now sorted on factor levels:

    septic_patients %>%
       freq(hospital_id, sort.count = FALSE)

    Frequency table of hospital_id from a data.frame (2,000 x 49)

    @@ -603,7 +615,7 @@ Unique: 4

    -

    All classes will be printed into the header (default is FALSE when using markdown like this document). Variables with the new rsi class of this AMR package are actually ordered factors and have three classes (look at Class in the header):

    +

    All classes will be printed into the header. Variables with the new rsi class of this AMR package are actually ordered factors and have three classes (look at Class in the header):

    septic_patients %>%
       freq(AMX, header = TRUE)

    Frequency table of AMX from a data.frame (2,000 x 49)

    @@ -791,68 +803,14 @@ Group: Beta-lactams/penicillins
    -
    septic_patients %>%
    -  freq(AMX, na.rm = FALSE)
    -

    Frequency table of AMX from a data.frame (2,000 x 49)

    -

    Class: factor > ordered > rsi (numeric)
    -Length: 2,000 (of which NA: 771 = 38.55%)
    -Levels: 3: S < I < R
    -Unique: 4

    -

    Drug: Amoxicillin (AMX, J01CA04)
    -Group: Beta-lactams/penicillins
    -%SI: 44.43%

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    ItemCountPercentCum. CountCum. Percent
    1(NA)77138.6%77138.6%
    2R68334.2%1,45472.7%
    3S54327.2%1,99799.8%
    4I30.2%2,000100.0%

    Parameter row.names

    A frequency table shows row indices. To remove them, use row.names = FALSE:

    -
    septic_patients %>%
    -  freq(hospital_id, row.names = FALSE)
    +
    septic_patients %>%
    +  freq(hospital_id, row.names = FALSE)

    Frequency table of hospital_id from a data.frame (2,000 x 49)

    Class: factor (numeric)
    Length: 2,000 (of which NA: 0 = 0.00%)
    @@ -902,58 +860,22 @@ Unique: 4

    Parameter markdown

    -

    The markdown parameter is TRUE at default in non-interactive sessions, like in reports created with R Markdown. This will always print all rows, unless nmax is set.

    -
    septic_patients %>%
    -  freq(hospital_id, markdown = TRUE)
    -

    Frequency table of hospital_id from a data.frame (2,000 x 49)

    -

    Class: factor (numeric)
    -Length: 2,000 (of which NA: 0 = 0.00%)
    -Levels: 4: A, B, C, D
    -Unique: 4

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    ItemCountPercentCum. CountCum. Percent
    1D76238.1%76238.1%
    2B66333.2%1,42571.2%
    3A32116.0%1,74687.3%
    4C25412.7%2,000100.0%
    +

    The markdown parameter is TRUE at default in non-interactive sessions, like in reports created with R Markdown. This will always print all rows, unless nmax is set. Without markdown (like in regular R), a frequency table would print like:

    +
    diff --git a/docs/articles/mo_property.html b/docs/articles/mo_property.html index 7cb6f9b7..b8d982e0 100644 --- a/docs/articles/mo_property.html +++ b/docs/articles/mo_property.html @@ -40,7 +40,7 @@ AMR (for R) - 0.6.1.9037 + 0.6.1.9040 diff --git a/docs/articles/resistance_predict.html b/docs/articles/resistance_predict.html index 164d05a1..554ed231 100644 --- a/docs/articles/resistance_predict.html +++ b/docs/articles/resistance_predict.html @@ -40,7 +40,7 @@ AMR (for R) - 0.6.1.9037 + 0.6.1.9040 diff --git a/docs/reference/AMR-deprecated.html b/docs/reference/AMR-deprecated.html index ab097097..8b571995 100644 --- a/docs/reference/AMR-deprecated.html +++ b/docs/reference/AMR-deprecated.html @@ -80,7 +80,7 @@ AMR (for R) - 0.6.1.9037 + 0.6.1.9040 diff --git a/docs/reference/AMR.html b/docs/reference/AMR.html index e7bf6967..5d05a7bc 100644 --- a/docs/reference/AMR.html +++ b/docs/reference/AMR.html @@ -80,7 +80,7 @@ AMR (for R) - 0.6.1.9037 + 0.6.1.9040 diff --git a/docs/reference/WHOCC.html b/docs/reference/WHOCC.html index a245fc5a..5b7e0c27 100644 --- a/docs/reference/WHOCC.html +++ b/docs/reference/WHOCC.html @@ -80,7 +80,7 @@ AMR (for R) - 0.6.1.9037 + 0.6.1.9040 diff --git a/docs/reference/WHONET.html b/docs/reference/WHONET.html index 836e1651..2446f2a4 100644 --- a/docs/reference/WHONET.html +++ b/docs/reference/WHONET.html @@ -80,7 +80,7 @@ AMR (for R) - 0.6.1.9037 + 0.6.1.9040 diff --git a/docs/reference/ab_property.html b/docs/reference/ab_property.html index 422e208b..b937ae9c 100644 --- a/docs/reference/ab_property.html +++ b/docs/reference/ab_property.html @@ -80,7 +80,7 @@ AMR (for R) - 0.6.1.9037 + 0.6.1.9040 diff --git a/docs/reference/age.html b/docs/reference/age.html index 22ecb8c4..83e513bd 100644 --- a/docs/reference/age.html +++ b/docs/reference/age.html @@ -80,7 +80,7 @@ AMR (for R) - 0.6.1.9037 + 0.6.1.9040 diff --git a/docs/reference/age_groups.html b/docs/reference/age_groups.html index da33dcd1..0b522293 100644 --- a/docs/reference/age_groups.html +++ b/docs/reference/age_groups.html @@ -80,7 +80,7 @@ AMR (for R) - 0.6.1.9037 + 0.6.1.9040 diff --git a/docs/reference/antibiotics.html b/docs/reference/antibiotics.html index c1bcb191..bf763a4a 100644 --- a/docs/reference/antibiotics.html +++ b/docs/reference/antibiotics.html @@ -80,7 +80,7 @@ AMR (for R) - 0.6.1.9037 + 0.6.1.9040 diff --git a/docs/reference/as.ab.html b/docs/reference/as.ab.html index f9b5006c..876cb266 100644 --- a/docs/reference/as.ab.html +++ b/docs/reference/as.ab.html @@ -80,7 +80,7 @@ AMR (for R) - 0.6.1.9037 + 0.6.1.9040 diff --git a/docs/reference/as.atc.html b/docs/reference/as.atc.html index e01375e6..920e5100 100644 --- a/docs/reference/as.atc.html +++ b/docs/reference/as.atc.html @@ -80,7 +80,7 @@ AMR (for R) - 0.6.1.9037 + 0.6.1.9040 diff --git a/docs/reference/as.disk.html b/docs/reference/as.disk.html index 8d8d8ce1..e4f03dc4 100644 --- a/docs/reference/as.disk.html +++ b/docs/reference/as.disk.html @@ -80,7 +80,7 @@ AMR (for R) - 0.6.1.9037 + 0.6.1.9040 diff --git a/docs/reference/as.mic.html b/docs/reference/as.mic.html index 9dff64e2..c4d48b19 100644 --- a/docs/reference/as.mic.html +++ b/docs/reference/as.mic.html @@ -80,7 +80,7 @@ AMR (for R) - 0.6.1.9037 + 0.6.1.9040 diff --git a/docs/reference/as.mo.html b/docs/reference/as.mo.html index e1cfadae..3946b10f 100644 --- a/docs/reference/as.mo.html +++ b/docs/reference/as.mo.html @@ -80,7 +80,7 @@ AMR (for R) - 0.6.1.9037 + 0.6.1.9040 diff --git a/docs/reference/as.rsi.html b/docs/reference/as.rsi.html index fb78156b..84180295 100644 --- a/docs/reference/as.rsi.html +++ b/docs/reference/as.rsi.html @@ -80,7 +80,7 @@ AMR (for R) - 0.6.1.9037 + 0.6.1.9040 diff --git a/docs/reference/atc_online.html b/docs/reference/atc_online.html index 941c1813..85f572c1 100644 --- a/docs/reference/atc_online.html +++ b/docs/reference/atc_online.html @@ -80,7 +80,7 @@ AMR (for R) - 0.6.1.9037 + 0.6.1.9040 diff --git a/docs/reference/availability.html b/docs/reference/availability.html index c6f19be3..2e559fa1 100644 --- a/docs/reference/availability.html +++ b/docs/reference/availability.html @@ -80,7 +80,7 @@ AMR (for R) - 0.6.1.9037 + 0.6.1.9040 diff --git a/docs/reference/catalogue_of_life.html b/docs/reference/catalogue_of_life.html index c24c0dc9..690a4796 100644 --- a/docs/reference/catalogue_of_life.html +++ b/docs/reference/catalogue_of_life.html @@ -80,7 +80,7 @@ AMR (for R) - 0.6.1.9037 + 0.6.1.9040 diff --git a/docs/reference/catalogue_of_life_version.html b/docs/reference/catalogue_of_life_version.html index 8c7a614f..7c298f73 100644 --- a/docs/reference/catalogue_of_life_version.html +++ b/docs/reference/catalogue_of_life_version.html @@ -80,7 +80,7 @@ AMR (for R) - 0.6.1.9037 + 0.6.1.9040 diff --git a/docs/reference/count.html b/docs/reference/count.html index 251c2833..3c1eae5f 100644 --- a/docs/reference/count.html +++ b/docs/reference/count.html @@ -81,7 +81,7 @@ count_R and count_IR can be used to count resistant isolates, count_S and count_ AMR (for R) - 0.6.1.9037 + 0.6.1.9040 diff --git a/docs/reference/eucast_rules.html b/docs/reference/eucast_rules.html index f33e1baf..ebde0736 100644 --- a/docs/reference/eucast_rules.html +++ b/docs/reference/eucast_rules.html @@ -80,7 +80,7 @@ AMR (for R) - 0.6.1.9037 + 0.6.1.9040 diff --git a/docs/reference/filter_ab_class.html b/docs/reference/filter_ab_class.html index 523ca1c3..2ef180d2 100644 --- a/docs/reference/filter_ab_class.html +++ b/docs/reference/filter_ab_class.html @@ -80,7 +80,7 @@ AMR (for R) - 0.6.1.9037 + 0.6.1.9040 diff --git a/docs/reference/first_isolate.html b/docs/reference/first_isolate.html index d80d98bb..28233ee9 100644 --- a/docs/reference/first_isolate.html +++ b/docs/reference/first_isolate.html @@ -80,7 +80,7 @@ AMR (for R) - 0.6.1.9037 + 0.6.1.9040 diff --git a/docs/reference/freq.html b/docs/reference/freq.html index 18f28f9c..ad7e1256 100644 --- a/docs/reference/freq.html +++ b/docs/reference/freq.html @@ -81,7 +81,7 @@ top_freq can be used to get the top/bottom n items of a frequency table, with co AMR (for R) - 0.6.1.9037 + 0.6.1.9040 diff --git a/docs/reference/g.test.html b/docs/reference/g.test.html index 58170288..1c5c12b3 100644 --- a/docs/reference/g.test.html +++ b/docs/reference/g.test.html @@ -80,7 +80,7 @@ AMR (for R) - 0.6.1.9037 + 0.6.1.9040 diff --git a/docs/reference/ggplot_rsi.html b/docs/reference/ggplot_rsi.html index 7885783e..bc8fe9cc 100644 --- a/docs/reference/ggplot_rsi.html +++ b/docs/reference/ggplot_rsi.html @@ -80,7 +80,7 @@ AMR (for R) - 0.6.1.9037 + 0.6.1.9040 diff --git a/docs/reference/guess_ab_col.html b/docs/reference/guess_ab_col.html index 0d7bdfe7..47596e9e 100644 --- a/docs/reference/guess_ab_col.html +++ b/docs/reference/guess_ab_col.html @@ -80,7 +80,7 @@ AMR (for R) - 0.6.1.9037 + 0.6.1.9040 diff --git a/docs/reference/join.html b/docs/reference/join.html index e58f4fd1..1fb1f396 100644 --- a/docs/reference/join.html +++ b/docs/reference/join.html @@ -80,7 +80,7 @@ AMR (for R) - 0.6.1.9037 + 0.6.1.9040 diff --git a/docs/reference/key_antibiotics.html b/docs/reference/key_antibiotics.html index c6ab9213..af9f67cb 100644 --- a/docs/reference/key_antibiotics.html +++ b/docs/reference/key_antibiotics.html @@ -80,7 +80,7 @@ AMR (for R) - 0.6.1.9037 + 0.6.1.9040 diff --git a/docs/reference/kurtosis.html b/docs/reference/kurtosis.html index 693ed9a7..e35983c5 100644 --- a/docs/reference/kurtosis.html +++ b/docs/reference/kurtosis.html @@ -80,7 +80,7 @@ AMR (for R) - 0.6.1.9037 + 0.6.1.9040 diff --git a/docs/reference/like.html b/docs/reference/like.html index 08012d4c..f3772fab 100644 --- a/docs/reference/like.html +++ b/docs/reference/like.html @@ -80,7 +80,7 @@ AMR (for R) - 0.6.1.9037 + 0.6.1.9040 diff --git a/docs/reference/mdro.html b/docs/reference/mdro.html index a1259a37..ee4b59d6 100644 --- a/docs/reference/mdro.html +++ b/docs/reference/mdro.html @@ -80,7 +80,7 @@ AMR (for R) - 0.6.1.9037 + 0.6.1.9040 diff --git a/docs/reference/microorganisms.codes.html b/docs/reference/microorganisms.codes.html index 9b5d5608..93c1a8f8 100644 --- a/docs/reference/microorganisms.codes.html +++ b/docs/reference/microorganisms.codes.html @@ -80,7 +80,7 @@ AMR (for R) - 0.6.1.9037 + 0.6.1.9040 diff --git a/docs/reference/microorganisms.html b/docs/reference/microorganisms.html index 13040cec..3c19f843 100644 --- a/docs/reference/microorganisms.html +++ b/docs/reference/microorganisms.html @@ -80,7 +80,7 @@ AMR (for R) - 0.6.1.9037 + 0.6.1.9040 diff --git a/docs/reference/microorganisms.old.html b/docs/reference/microorganisms.old.html index 8a7a0c19..e3fb049e 100644 --- a/docs/reference/microorganisms.old.html +++ b/docs/reference/microorganisms.old.html @@ -80,7 +80,7 @@ AMR (for R) - 0.6.1.9037 + 0.6.1.9040 diff --git a/docs/reference/mo_property.html b/docs/reference/mo_property.html index b0f23e4e..ca4a0c75 100644 --- a/docs/reference/mo_property.html +++ b/docs/reference/mo_property.html @@ -80,7 +80,7 @@ AMR (for R) - 0.6.1.9037 + 0.6.1.9040 diff --git a/docs/reference/mo_source.html b/docs/reference/mo_source.html index 0964e0b7..0172d1cc 100644 --- a/docs/reference/mo_source.html +++ b/docs/reference/mo_source.html @@ -81,7 +81,7 @@ This is the fastest way to have your organisation (or analysis) specific codes p AMR (for R) - 0.6.1.9037 + 0.6.1.9040 diff --git a/docs/reference/p.symbol.html b/docs/reference/p.symbol.html index 1aa8091b..3af3c71d 100644 --- a/docs/reference/p.symbol.html +++ b/docs/reference/p.symbol.html @@ -80,7 +80,7 @@ AMR (for R) - 0.6.1.9037 + 0.6.1.9040 diff --git a/docs/reference/portion.html b/docs/reference/portion.html index e885ebd7..d763e4ec 100644 --- a/docs/reference/portion.html +++ b/docs/reference/portion.html @@ -81,7 +81,7 @@ portion_R and portion_IR can be used to calculate resistance, portion_S and port AMR (for R) - 0.6.1.9037 + 0.6.1.9040 diff --git a/docs/reference/read.4D.html b/docs/reference/read.4D.html index 2dd2cc1e..243d6c6d 100644 --- a/docs/reference/read.4D.html +++ b/docs/reference/read.4D.html @@ -80,7 +80,7 @@ AMR (for R) - 0.6.1.9037 + 0.6.1.9040 diff --git a/docs/reference/resistance_predict.html b/docs/reference/resistance_predict.html index e39c9fc2..2b9926da 100644 --- a/docs/reference/resistance_predict.html +++ b/docs/reference/resistance_predict.html @@ -80,7 +80,7 @@ AMR (for R) - 0.6.1.9037 + 0.6.1.9040 diff --git a/docs/reference/rsi_translation.html b/docs/reference/rsi_translation.html index 0af8760c..26a0ac8c 100644 --- a/docs/reference/rsi_translation.html +++ b/docs/reference/rsi_translation.html @@ -80,7 +80,7 @@ AMR (for R) - 0.6.1.9037 + 0.6.1.9040 diff --git a/docs/reference/septic_patients.html b/docs/reference/septic_patients.html index 20a9d4e6..16c29f1f 100644 --- a/docs/reference/septic_patients.html +++ b/docs/reference/septic_patients.html @@ -80,7 +80,7 @@ AMR (for R) - 0.6.1.9037 + 0.6.1.9040 diff --git a/docs/reference/skewness.html b/docs/reference/skewness.html index 59408ecf..ee6ee896 100644 --- a/docs/reference/skewness.html +++ b/docs/reference/skewness.html @@ -81,7 +81,7 @@ When negative: the left tail is longer; the mass of the distribution is concentr AMR (for R) - 0.6.1.9037 + 0.6.1.9040 diff --git a/docs/reference/translate.html b/docs/reference/translate.html index 46c3e605..fd288fe0 100644 --- a/docs/reference/translate.html +++ b/docs/reference/translate.html @@ -80,7 +80,7 @@ AMR (for R) - 0.6.1.9037 + 0.6.1.9040 diff --git a/man/age_groups.Rd b/man/age_groups.Rd index d4ef3322..cd0e5101 100644 --- a/man/age_groups.Rd +++ b/man/age_groups.Rd @@ -24,7 +24,7 @@ To split ages, the input can be: The default is to split on young children (0-11), youth (12-24), young adults (25-54), middle-aged adults (55-74) and elderly (75+).} \item{A character:} \itemize{ - \item{\code{"children"}, equivalent of: \code{c(0, 1, 2, 4, 6, 13, 18)}. This will split on 0, 1, 2-3, 4-5, 6-12, 13-17 and 18+.} + \item{\code{"children"} or \code{"kids"}, equivalent of: \code{c(0, 1, 2, 4, 6, 13, 18)}. This will split on 0, 1, 2-3, 4-5, 6-12, 13-17 and 18+.} \item{\code{"elderly"} or \code{"seniors"}, equivalent of: \code{c(65, 75, 85)}. This will split on 0-64, 65-74, 75-84, 85+.} \item{\code{"fives"}, equivalent of: \code{1:20 * 5}. This will split on 0-4, 5-9, 10-14, ..., 90-94, 95-99, 100+.} \item{\code{"tens"}, equivalent of: \code{1:10 * 10}. This will split on 0-9, 10-19, 20-29, ... 80-89, 90-99, 100+.} @@ -61,12 +61,10 @@ age_groups(ages, c(1, 2, 4, 6, 13, 17)) # resistance of ciprofloxacine per age group library(dplyr) septic_patients \%>\% - mutate(first_isolate = first_isolate(.)) \%>\% - filter(first_isolate == TRUE, - mo == as.mo("E. coli")) \%>\% + filter_first_isolate) \%>\% + filter(mo == as.mo("E. coli")) \%>\% group_by(age_group = age_groups(age)) \%>\% - select(age_group, - CIP) \%>\% + select(age_group, CIP) \%>\% ggplot_rsi(x = "age_group") } \seealso{ diff --git a/vignettes/freq.Rmd b/vignettes/freq.Rmd index 81028383..e450dc2d 100644 --- a/vignettes/freq.Rmd +++ b/vignettes/freq.Rmd @@ -28,13 +28,23 @@ library(AMR) ## Introduction -Frequency tables (or frequency distributions) are summaries of the distribution of values in a sample. With the `freq` function, you can create univariate frequency tables. Multiple variables will be pasted into one variable, so it forces a univariate distribution. We take the `septic_patients` dataset (included in this AMR package) as example. +Frequency tables (or frequency distributions) are summaries of the distribution of values in a sample. With the `freq()` function, you can create univariate frequency tables. Multiple variables will be pasted into one variable, so it forces a univariate distribution. We take the `septic_patients` dataset (included in this AMR package) as example. ## Frequencies of one variable 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: ```{r, echo = TRUE} -septic_patients %>% freq(gender) +# Any of these will work: +# freq(septic_patients$gender) +# freq(septic_patients[, "gender"]) + +# Using tidyverse: +# septic_patients$gender %>% freq() +# septic_patients[, "gender"] %>% freq() +# septic_patients %>% freq("gender") + +# Probably the fastest and easiest: +septic_patients %>% freq(gender) ``` This immediately shows the class of the variable, its length and availability (i.e. the amount of `NA`), the amount of unique values and (most importantly) that among septic patients men are more prevalent than women. @@ -84,9 +94,13 @@ So the following properties are determined, where `NA` values are always ignored * **Coefficient of variation** (CV), the standard deviation divided by the mean -* **Five numbers of Tukey** (min, Q1, median, Q3, max) +* **Mean absolute deviation** (MAD), the median of the absolute deviations from the median - a more robust statistic than the standard deviation -* **Coefficient of quartile variation** (CQV, sometimes called coefficient of dispersion), calculated as (Q3 - Q1) / (Q3 + Q1) using quantile with `type = 6` as quantile algorithm to comply with SPSS standards +* **Five numbers of Tukey**, namely: the minimum, Q1, median, Q3 and maximum + +* **Interquartile range** (IQR), the distance between Q1 and Q3 + +* **Coefficient of quartile variation** (CQV, sometimes called *coefficient of dispersion*), calculated as (Q3 - Q1) / (Q3 + Q1) using `quantile()` with `type = 6` as quantile algorithm to comply with SPSS standards * **Outliers** (total count and unique count) @@ -94,7 +108,7 @@ So for example, the above frequency table quickly shows the median age of patien ## Frequencies of factors -To sort frequencies of factors on factor level instead of item count, use the `sort.count` parameter. +To sort frequencies of factors on their levels instead of item count, use the `sort.count` parameter. `sort.count` is `TRUE` by default. Compare this default behaviour... @@ -103,14 +117,14 @@ septic_patients %>% freq(hospital_id) ``` -... with this, where items are now sorted on count: +... to this, where items are now sorted on factor levels: ```{r, echo = TRUE} septic_patients %>% freq(hospital_id, sort.count = FALSE) ``` -All classes will be printed into the header (default is `FALSE` when using markdown like this document). Variables with the new `rsi` class of this AMR package are actually ordered factors and have three classes (look at `Class` in the header): +All classes will be printed into the header. Variables with the new `rsi` class of this AMR package are actually ordered factors and have three classes (look at `Class` in the header): ```{r, echo = TRUE} septic_patients %>% @@ -147,8 +161,6 @@ dim(my_df) With the `na.rm` parameter you can remove `NA` values from the frequency table (defaults to `TRUE`, but the number of `NA` values will always be shown into the header): ```{r, echo = TRUE} -septic_patients %>% - freq(AMX, na.rm = FALSE) septic_patients %>% freq(AMX, na.rm = FALSE) ``` @@ -162,9 +174,9 @@ septic_patients %>% ``` ### Parameter `markdown` -The `markdown` parameter is `TRUE` at default in non-interactive sessions, like in reports created with R Markdown. This will always print all rows, unless `nmax` is set. +The `markdown` parameter is `TRUE` at default in non-interactive sessions, like in reports created with R Markdown. This will always print all rows, unless `nmax` is set. Without markdown (like in regular R), a frequency table would print like: -```{r, echo = TRUE} +```{r, echo = TRUE, results = 'markup'} septic_patients %>% - freq(hospital_id, markdown = TRUE) + freq(hospital_id, markdown = FALSE) ```