diff --git a/R/ab.R b/R/ab.R index 12caf08f..f20b5a38 100755 --- a/R/ab.R +++ b/R/ab.R @@ -28,9 +28,9 @@ #' @inheritSection WHOCC WHOCC #' @export #' @importFrom dplyr %>% filter slice pull -#' @details All entries in the \code{\{link{antibiotics}} data set have three different identifiers: a human readable EARS-Net code (column \code{ab}, used by ECDC and WHONET), an ATC code (column \code{atc}, used by WHO), and a CID code (column \code{cid}, Compound ID, used by PubChem). The data set contains more than 5,000 official brand names from many different countries, as found in PubChem. +#' @details All entries in the \code{\link{antibiotics}} data set have three different identifiers: a human readable EARS-Net code (column \code{ab}, used by ECDC and WHONET), an ATC code (column \code{atc}, used by WHO), and a CID code (column \code{cid}, Compound ID, used by PubChem). The data set contains more than 5,000 official brand names from many different countries, as found in PubChem. #' -#' Use the \code{\link{ab_property}} functions to get properties based on the returned ATC code, see Examples. +#' Use the \code{\link{ab_property}} functions to get properties based on the returned antibiotic ID, see Examples. #' #' In the ATC classification system, the active substances are classified in a hierarchy with five different levels. The system has fourteen main anatomical/pharmacological groups or 1st levels. Each ATC main group is divided into 2nd levels which could be either pharmacological or therapeutic groups. The 3rd and 4th levels are chemical, pharmacological or therapeutic subgroups and the 5th level is the chemical substance. The 2nd, 3rd and 4th levels are often used to identify pharmacological subgroups when that is considered more appropriate than therapeutic or chemical subgroups. #' Source: \url{https://www.whocc.no/atc/structure_and_principles/} diff --git a/R/misc.R b/R/misc.R index 8335c362..129d54b5 100755 --- a/R/misc.R +++ b/R/misc.R @@ -147,7 +147,7 @@ search_type_in_df <- function(tbl, type) { if (!is.null(found)) { msg <- paste0("NOTE: Using column `", bold(found), "` as input for `col_", type, "`.") if (type %in% c("keyantibiotics", "specimen")) { - msg <- paste(msg, "Use", bold(paste0("col_", type), " = FALSE"), "to prevent this.") + msg <- paste(msg, "Use", bold(paste0("col_", type), "= FALSE"), "to prevent this.") } message(blue(msg)) } diff --git a/docs/articles/AMR.html b/docs/articles/AMR.html index f1fd8915..db712e20 100644 --- a/docs/articles/AMR.html +++ b/docs/articles/AMR.html @@ -327,9 +327,31 @@ -2014-11-13 -S2 -Hospital B +2017-11-01 +W7 +Hospital D +Streptococcus pneumoniae +S +S +S +S +F + + +2012-09-25 +R9 +Hospital A +Streptococcus pneumoniae +S +S +S +S +F + + +2013-05-22 +V2 +Hospital A Escherichia coli S S @@ -338,10 +360,10 @@ F -2013-01-01 -V1 +2017-03-29 +W6 Hospital C -Streptococcus pneumoniae +Escherichia coli S S S @@ -349,46 +371,24 @@ F -2016-11-12 -G5 -Hospital A -Klebsiella pneumoniae -S -S -S -S -M - - -2011-09-23 -U6 -Hospital A -Klebsiella pneumoniae -R -I -R -S -F - - -2010-04-06 -C9 -Hospital D -Streptococcus pneumoniae -S -S -S -S -M - - -2012-04-11 -D2 -Hospital B +2017-09-07 +N7 +Hospital C Staphylococcus aureus +S R S S +F + + +2012-09-27 +B7 +Hospital B +Escherichia coli +S +R +S S M @@ -411,8 +411,8 @@ #> #> Item Count Percent Cum. Count Cum. Percent #> --- ----- ------- -------- ----------- ------------- -#> 1 M 10,325 51.6% 10,325 51.6% -#> 2 F 9,675 48.4% 20,000 100.0% +#> 1 M 10,580 52.9% 10,580 52.9% +#> 2 F 9,420 47.1% 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 %>%
@@ -442,14 +442,14 @@
 #> Pasteurella multocida (no new changes)
 #> Staphylococcus (no new changes)
 #> Streptococcus groups A, B, C, G (no new changes)
-#> Streptococcus pneumoniae (1508 new changes)
+#> Streptococcus pneumoniae (1481 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 (1335 new changes)
+#> Table 01: Intrinsic resistance in Enterobacteriaceae (1304 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 (2792 new changes)
+#> Table 04: Intrinsic resistance in Gram-positive bacteria (2729 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)
@@ -457,24 +457,24 @@
 #> Table 13: Interpretive rules for quinolones (no new changes)
 #> 
 #> Other rules
-#> Non-EUCAST: amoxicillin/clav acid = S where ampicillin = S (2206 new changes)
-#> Non-EUCAST: ampicillin = R where amoxicillin/clav acid = R (141 new changes)
+#> Non-EUCAST: amoxicillin/clav acid = S where ampicillin = S (2235 new changes)
+#> Non-EUCAST: ampicillin = R where amoxicillin/clav acid = R (125 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,587 out of 20,000 rows, making a total of 7,982 edits
+#> EUCAST rules affected 6,510 out of 20,000 rows, making a total of 7,874 edits
 #> => added 0 test results
 #> 
-#> => changed 7,982 test results
-#>    - 102 test results changed from S to I
-#>    - 4,844 test results changed from S to R
-#>    - 1,047 test results changed from I to S
-#>    - 345 test results changed from I to R
-#>    - 1,615 test results changed from R to S
-#>    - 29 test results changed from R to I
+#> => changed 7,874 test results
+#>    - 98 test results changed from S to I
+#>    - 4,755 test results changed from S to R
+#>    - 1,023 test results changed from I to S
+#>    - 326 test results changed from I to R
+#>    - 1,654 test results changed from R to S
+#>    - 18 test results changed from R to I
 #> --------------------------------------------------------------------------
 #> 
 #> Use verbose = TRUE to get a data.frame with all specified edits instead.
@@ -502,8 +502,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,711 first isolates (28.6% of total) -

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

+#> => Found 5,686 first isolates (28.4% of total) +

So only 28.4% 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:

@@ -529,8 +529,8 @@ 1 -2010-02-03 -Q6 +2010-01-10 +T7 B_ESCHR_COL S S @@ -540,8 +540,8 @@ 2 -2010-03-18 -Q6 +2010-02-24 +T7 B_ESCHR_COL S S @@ -552,29 +552,29 @@ 3 2010-04-04 -Q6 +T7 B_ESCHR_COL +R S S -S -S +R FALSE 4 -2010-04-12 -Q6 +2010-04-14 +T7 B_ESCHR_COL S S -S +R S FALSE 5 -2010-05-08 -Q6 +2010-05-20 +T7 B_ESCHR_COL S S @@ -584,10 +584,10 @@ 6 -2010-08-03 -Q6 +2010-09-24 +T7 B_ESCHR_COL -R +S S S S @@ -595,8 +595,8 @@ 7 -2010-08-04 -Q6 +2010-10-10 +T7 B_ESCHR_COL S S @@ -606,21 +606,21 @@ 8 -2010-11-02 -Q6 +2010-11-17 +T7 B_ESCHR_COL -R -R +S +S S S FALSE 9 -2010-11-09 -Q6 +2010-12-16 +T7 B_ESCHR_COL -R +S S S S @@ -628,18 +628,18 @@ 10 -2010-12-18 -Q6 +2011-04-02 +T7 B_ESCHR_COL -R -R +I S S -FALSE +S +TRUE -

Only 1 isolates are marked as ‘first’ according to CLSI guideline. But when reviewing the antibiogram, it is obvious that some isolates are absolutely different strains and should be included too. This is why we weigh isolates, based on their antibiogram. The key_antibiotics() function adds a vector with 18 key antibiotics: 6 broad spectrum ones, 6 small spectrum for Gram negatives and 6 small spectrum for Gram positives. These can be defined by the user.

+

Only 2 isolates are marked as ‘first’ according to CLSI guideline. But when reviewing the antibiogram, it is obvious that some isolates are absolutely different strains and should be included too. This is why we weigh isolates, based on their antibiogram. The key_antibiotics() function adds a vector with 18 key antibiotics: 6 broad spectrum ones, 6 small spectrum for Gram negatives and 6 small spectrum for Gram positives. These can be defined by the user.

If a column exists with a name like ‘key(…)ab’ the first_isolate() function will automatically use it and determine the first weighted isolates. Mind the NOTEs in below output:

data <- data %>% 
   mutate(keyab = key_antibiotics(.)) %>% 
@@ -648,9 +648,9 @@
 #> 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.
+#> 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,123 first weighted isolates (75.6% of total)
+#> => Found 15,158 first weighted isolates (75.8% of total) @@ -667,8 +667,8 @@ - - + + @@ -679,8 +679,8 @@ - - + + @@ -692,106 +692,106 @@ - + + - - - + + - - + + - + - + - - + + - + - - + + - + - + - - + + - + - - + + - - + + - + - - + + - + - + - - + + - - + - + +
isolate
12010-02-03Q62010-01-10T7 B_ESCHR_COL S S
22010-03-18Q62010-02-24T7 B_ESCHR_COL S S
3 2010-04-04Q6T7 B_ESCHR_COLR S SSSFALSER FALSETRUE
42010-04-12Q62010-04-14T7 B_ESCHR_COL S SSR S FALSEFALSETRUE
52010-05-08Q62010-05-20T7 B_ESCHR_COL S S S S FALSEFALSETRUE
62010-08-03Q62010-09-24T7 B_ESCHR_COLRS S S S FALSETRUEFALSE
72010-08-04Q62010-10-10T7 B_ESCHR_COL S S S S FALSETRUEFALSE
82010-11-02Q62010-11-17T7 B_ESCHR_COLRRSS S S FALSETRUEFALSE
92010-11-09Q62010-12-16T7 B_ESCHR_COLRS S S S FALSETRUEFALSE
102010-12-18Q62011-04-02T7 B_ESCHR_COLRRI S SFALSESTRUE TRUE
-

Instead of 1, now 6 isolates are flagged. In total, 75.6% of all isolates are marked ‘first weighted’ - 47.1% more than when using the CLSI guideline. In real life, this novel algorithm will yield 5-10% more isolates than the classic CLSI guideline.

+

Instead of 2, now 5 isolates are flagged. In total, 75.8% of all isolates are marked ‘first weighted’ - 47.4% 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,123 isolates for analysis.

+

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

We can remove unneeded columns:

data_1st <- data_1st %>% 
   select(-c(first, keyab))
@@ -799,7 +799,6 @@
head(data_1st)
- @@ -816,10 +815,39 @@ - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -832,80 +860,45 @@ - - - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - + + + - - + + - - - - + + + - - - + + + @@ -928,9 +921,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,123 x 13)

+

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

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

Shortest: 16
Longest: 24

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

- - - - + + + + - - - - + + + + - - - - + + + + - - - + + + @@ -982,13 +975,13 @@ 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. They can be used on their own:

-
data_1st %>% portion_IR(AMX)
-#> [1] 0.5012233
+

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

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

data_1st %>% 
   group_by(hospital) %>% 
-  summarise(amoxicillin = portion_IR(AMX))
+ summarise(amoxicillin = portion_R(AMX))
date patient_id hospital
12014-11-13S2Hospital B2017-11-01W7Hospital DB_STRPT_PNESSSRFGram positiveStreptococcuspneumoniaeTRUE
2012-09-25R9Hospital AB_STRPT_PNESSSRFGram positiveStreptococcuspneumoniaeTRUE
2013-05-22V2Hospital A B_ESCHR_COL S STRUE
32016-11-12G5Hospital AB_KLBSL_PNER2017-03-29W6Hospital CB_ESCHR_COL S S SMGram negativeKlebsiellapneumoniaeTRUE
42011-09-23U6Hospital AB_KLBSL_PNERIR S F Gram negativeKlebsiellapneumoniaeTRUE
52010-04-06C9Hospital DB_STRPT_PNESSSRMGram positiveStreptococcuspneumoniaeEscherichiacoli TRUE
62012-04-11D2Hospital B2017-09-07N7Hospital C B_STPHY_AURR S S SMSF Gram positive Staphylococcus aureus TRUE
82012-08-17Z4Hospital C2012-09-27B7Hospital B B_ESCHR_COLR SR SFSSM Gram negative Escherichia coli
1 Escherichia coli7,46649.4%7,46649.4%7,50049.5%7,50049.5%
2 Staphylococcus aureus3,64924.1%11,11573.5%3,76124.8%11,26174.3%
3 Streptococcus pneumoniae2,38115.7%13,49689.2%2,29715.2%13,55889.4%
4 Klebsiella pneumoniae1,62710.8%15,1231,60010.6%15,158 100.0%
@@ -997,26 +990,26 @@ Longest: 24

- + - + - + - +
hospital
Hospital A0.51006410.4757516
Hospital B0.49456320.4728817
Hospital C0.49604570.4581554
Hospital D0.50367650.4717349

Of course it would be very convenient to know the number of isolates responsible for the percentages. For that purpose the n_rsi() can be used, which works exactly like n_distinct() from the dplyr package. It counts all isolates available for every group (i.e. values S, I or R):

data_1st %>% 
   group_by(hospital) %>% 
-  summarise(amoxicillin = portion_IR(AMX),
+  summarise(amoxicillin = portion_R(AMX),
             available = n_rsi(AMX))
@@ -1027,32 +1020,32 @@ Longest: 24

- - + + - - + + - - + + - - + +
Hospital A0.510064145210.47575164557
Hospital B0.494563253340.47288175181
Hospital C0.496045722760.45815542342
Hospital D0.503676529920.47173493078

These functions can also be used to get the portion of multiple antibiotics, to calculate empiric susceptibility of combination therapies very easily:

data_1st %>% 
   group_by(genus) %>% 
-  summarise(amoxiclav = portion_S(AMC),
-            gentamicin = portion_S(GEN),
-            amoxiclav_genta = portion_S(AMC, GEN))
+ summarise(amoxiclav = portion_SI(AMC), + gentamicin = portion_SI(GEN), + amoxiclav_genta = portion_SI(AMC, GEN)) @@ -1063,36 +1056,36 @@ Longest: 24

- - - + + + - - - + + + - - - + + + - + - +
genus
Escherichia0.87757840.89847310.99102600.92160000.89106670.9924000
Klebsiella0.72218810.90534730.97787340.82500000.90187500.9893750
Staphylococcus0.87667850.91888190.98876400.92156340.91757510.9936187
Streptococcus0.57328850.6081846 0.00000000.57328850.6081846

To make a transition to the next part, let’s see how this difference could be plotted:

data_1st %>% 
   group_by(genus) %>% 
-  summarise("1. Amoxi/clav" = portion_S(AMC),
-            "2. Gentamicin" = portion_S(GEN),
-            "3. Amoxi/clav + GEN" = portion_S(AMC, GEN)) %>% 
+  summarise("1. Amoxi/clav" = portion_SI(AMC),
+            "2. Gentamicin" = portion_SI(GEN),
+            "3. Amoxi/clav + genta" = portion_SI(AMC, GEN)) %>% 
   tidyr::gather("Antibiotic", "S", -genus) %>%
   ggplot(aes(x = genus,
              y = S,
@@ -1134,7 +1127,7 @@ Longest: 24

scale_rsi_colours() + # show percentages on y axis scale_y_percent(breaks = 0:4 * 25) + - # turn 90 degrees, make it bars instead of columns + # turn 90 degrees, to make it bars instead of columns coord_flip() + # add labels labs(title = "Resistance per genus and antibiotic", 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 2ee99121..4e242fe4 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 f76f6eb4..eb31b19a 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 a634df72..6a52a798 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 47476b9e..1e18d0fa 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/reference/as.ab.html b/docs/reference/as.ab.html index cf428083..4ef255d8 100644 --- a/docs/reference/as.ab.html +++ b/docs/reference/as.ab.html @@ -260,8 +260,8 @@

Details

-

All entries in the {link{antibiotics} data set have three different identifiers: a human readable EARS-Net code (column ab, used by ECDC and WHONET), an ATC code (column atc, used by WHO), and a CID code (column cid, Compound ID, used by PubChem). The data set contains more than 5,000 official brand names from many different countries, as found in PubChem.

-

Use the ab_property functions to get properties based on the returned ATC code, see Examples.

+

All entries in the antibiotics data set have three different identifiers: a human readable EARS-Net code (column ab, used by ECDC and WHONET), an ATC code (column atc, used by WHO), and a CID code (column cid, Compound ID, used by PubChem). The data set contains more than 5,000 official brand names from many different countries, as found in PubChem.

+

Use the ab_property functions to get properties based on the returned antibiotic ID, see Examples.

In the ATC classification system, the active substances are classified in a hierarchy with five different levels. The system has fourteen main anatomical/pharmacological groups or 1st levels. Each ATC main group is divided into 2nd levels which could be either pharmacological or therapeutic groups. The 3rd and 4th levels are chemical, pharmacological or therapeutic subgroups and the 5th level is the chemical substance. The 2nd, 3rd and 4th levels are often used to identify pharmacological subgroups when that is considered more appropriate than therapeutic or chemical subgroups. Source: https://www.whocc.no/atc/structure_and_principles/

diff --git a/man/as.ab.Rd b/man/as.ab.Rd index 5dd468f2..55760474 100644 --- a/man/as.ab.Rd +++ b/man/as.ab.Rd @@ -19,9 +19,9 @@ Character (vector) with class \code{"ab"}. Unknown values will return \code{NA}. Use this function to determine the antibiotic code of one or more antibiotics. The data set \code{\link{antibiotics}} will be searched for abbreviations, official names and synonyms (brand names). } \details{ -All entries in the \code{\{link{antibiotics}} data set have three different identifiers: a human readable EARS-Net code (column \code{ab}, used by ECDC and WHONET), an ATC code (column \code{atc}, used by WHO), and a CID code (column \code{cid}, Compound ID, used by PubChem). The data set contains more than 5,000 official brand names from many different countries, as found in PubChem. +All entries in the \code{\link{antibiotics}} data set have three different identifiers: a human readable EARS-Net code (column \code{ab}, used by ECDC and WHONET), an ATC code (column \code{atc}, used by WHO), and a CID code (column \code{cid}, Compound ID, used by PubChem). The data set contains more than 5,000 official brand names from many different countries, as found in PubChem. -Use the \code{\link{ab_property}} functions to get properties based on the returned ATC code, see Examples. +Use the \code{\link{ab_property}} functions to get properties based on the returned antibiotic ID, see Examples. In the ATC classification system, the active substances are classified in a hierarchy with five different levels. The system has fourteen main anatomical/pharmacological groups or 1st levels. Each ATC main group is divided into 2nd levels which could be either pharmacological or therapeutic groups. The 3rd and 4th levels are chemical, pharmacological or therapeutic subgroups and the 5th level is the chemical substance. The 2nd, 3rd and 4th levels are often used to identify pharmacological subgroups when that is considered more appropriate than therapeutic or chemical subgroups. Source: \url{https://www.whocc.no/atc/structure_and_principles/} diff --git a/vignettes/AMR.Rmd b/vignettes/AMR.Rmd index 12b80a26..b30f1609 100755 --- a/vignettes/AMR.Rmd +++ b/vignettes/AMR.Rmd @@ -315,10 +315,10 @@ data_1st %>% ## 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. They can be used on their own: +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: ```{r} -data_1st %>% portion_IR(AMX) +data_1st %>% portion_R(AMX) ``` Or can be used in conjuction with `group_by()` and `summarise()`, both from the `dplyr` package: @@ -326,12 +326,12 @@ Or can be used in conjuction with `group_by()` and `summarise()`, both from the ```{r, eval = FALSE} data_1st %>% group_by(hospital) %>% - summarise(amoxicillin = portion_IR(AMX)) + summarise(amoxicillin = portion_R(AMX)) ``` ```{r, echo = FALSE} data_1st %>% group_by(hospital) %>% - summarise(amoxicillin = portion_IR(AMX)) %>% + summarise(amoxicillin = portion_R(AMX)) %>% knitr::kable(align = "c", big.mark = ",") ``` @@ -340,13 +340,13 @@ Of course it would be very convenient to know the number of isolates responsible ```{r, eval = FALSE} data_1st %>% group_by(hospital) %>% - summarise(amoxicillin = portion_IR(AMX), + summarise(amoxicillin = portion_R(AMX), available = n_rsi(AMX)) ``` ```{r, echo = FALSE} data_1st %>% group_by(hospital) %>% - summarise(amoxicillin = portion_IR(AMX), + summarise(amoxicillin = portion_R(AMX), available = n_rsi(AMX)) %>% knitr::kable(align = "c", big.mark = ",") ``` @@ -356,16 +356,16 @@ These functions can also be used to get the portion of multiple antibiotics, to ```{r, eval = FALSE} data_1st %>% group_by(genus) %>% - summarise(amoxiclav = portion_S(AMC), - gentamicin = portion_S(GEN), - amoxiclav_genta = portion_S(AMC, GEN)) + summarise(amoxiclav = portion_SI(AMC), + gentamicin = portion_SI(GEN), + amoxiclav_genta = portion_SI(AMC, GEN)) ``` ```{r, echo = FALSE} data_1st %>% group_by(genus) %>% - summarise(amoxiclav = portion_S(AMC), - gentamicin = portion_S(GEN), - amoxiclav_genta = portion_S(AMC, GEN)) %>% + summarise(amoxiclav = portion_SI(AMC), + gentamicin = portion_SI(GEN), + amoxiclav_genta = portion_SI(AMC, GEN)) %>% knitr::kable(align = "c", big.mark = ",") ``` @@ -374,9 +374,9 @@ To make a transition to the next part, let's see how this difference could be pl ```{r plot 1} data_1st %>% group_by(genus) %>% - summarise("1. Amoxi/clav" = portion_S(AMC), - "2. Gentamicin" = portion_S(GEN), - "3. Amoxi/clav + GEN" = portion_S(AMC, GEN)) %>% + summarise("1. Amoxi/clav" = portion_SI(AMC), + "2. Gentamicin" = portion_SI(GEN), + "3. Amoxi/clav + genta" = portion_SI(AMC, GEN)) %>% tidyr::gather("Antibiotic", "S", -genus) %>% ggplot(aes(x = genus, y = S, @@ -426,7 +426,7 @@ ggplot(data_1st %>% group_by(genus)) + scale_rsi_colours() + # show percentages on y axis scale_y_percent(breaks = 0:4 * 25) + - # turn 90 degrees, make it bars instead of columns + # turn 90 degrees, to make it bars instead of columns coord_flip() + # add labels labs(title = "Resistance per genus and antibiotic",