From 248b45da71baf105177a8a67cb690445aad4d40b Mon Sep 17 00:00:00 2001
From: "Matthijs S. Berends" 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 10 November 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 11 November 2019. Now, let’s start the cleaning and the analysis! So, we can draw at least two conclusions immediately. From a data scientists perspective, the data looks clean: only values The data is already quite clean, but we still need to transform some variables. The So only 28.5% is suitable for resistance analysis! We can now filter on it with the So only 28.3% is suitable for resistance analysis! We can now filter on it with the For future use, the above two syntaxes can be shortened with the 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 P1, 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 D2, sorted on date: 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 Instead of 2, now 10 isolates are flagged. In total, 76.2% of all isolates are marked ‘first weighted’ - 47.7% 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.0% of all isolates are marked ‘first weighted’ - 46.8% 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 So we end up with 15,241 isolates for analysis. So we end up with 15,009 isolates for analysis. We can remove unneeded columns: Frequency table Class: character Shortest: 16How to conduct AMR analysis
Matthijs S. Berends
- 10 November 2019
+ 11 November 2019
AMR.Rmd
Introduction
@@ -212,21 +212,21 @@
-
2019-11-10
+2019-11-11
abcd
Escherichia coli
S
S
-
2019-11-10
+2019-11-11
abcd
Escherichia coli
S
R
-
2019-11-10
+2019-11-11
efgh
Escherichia coli
R
@@ -321,71 +321,71 @@
-
+2015-05-08
-P3
+2011-09-25
+O7
+Hospital C
+Staphylococcus aureus
+S
+S
+S
+S
+F
+
+
+2012-04-04
+O9
+Hospital A
+Escherichia coli
+S
+S
+S
+S
+F
+
+
-2015-03-11
+S3
Hospital A
Escherichia coli
R
-I
-S
-S
-F
-
-
-2017-11-03
-Y8
-Hospital C
-Escherichia coli
-R
-S
-S
-S
-F
-
-
2013-09-06
-U9
-Hospital B
-Escherichia coli
-R
S
S
S
F
-
2015-11-16
-E7
+2014-12-11
+G1
Hospital B
Escherichia coli
-I
+S
S
S
S
M
-
-2011-04-18
-F4
-Hospital B
-Streptococcus pneumoniae
-S
-I
-S
-S
-M
-
-
+2010-04-22
-L4
+2013-01-02
+J8
Hospital D
Escherichia coli
S
+S
+S
R
-S
-S
M
+
2014-08-17
+S8
+Hospital C
+Escherichia coli
+S
+S
+S
+S
+F
+M
and F
. From a researchers perspective: there are slightly more men. Nothing we didn’t already know.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,545 values changed)
+# Streptococcus pneumoniae (1,552 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,309 values changed)
+# Table 01: Intrinsic resistance in Enterobacteriaceae (1,279 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,733 values changed)
+# Table 04: Intrinsic resistance in Gram-positive bacteria (2,800 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,23 +452,23 @@
# Table 13: Interpretive rules for quinolones (no changes)
#
# Other rules
-# Non-EUCAST: amoxicillin/clav acid = S where ampicillin = S (2,194 values changed)
-# Non-EUCAST: ampicillin = R where amoxicillin/clav acid = R (121 values changed)
+# Non-EUCAST: amoxicillin/clav acid = S where ampicillin = S (2,257 values changed)
+# Non-EUCAST: ampicillin = R where amoxicillin/clav acid = R (132 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,489 out of 20,000 rows, making a total of 7,902 edits
+# EUCAST rules affected 6,599 out of 20,000 rows, making a total of 8,020 edits
# => added 0 test results
#
-# => changed 7,902 test results
-# - 118 test results changed from S to I
-# - 4,776 test results changed from S to R
-# - 1,063 test results changed from I to S
-# - 318 test results changed from I to R
-# - 1,603 test results changed from R to S
+# => changed 8,020 test results
+# - 119 test results changed from S to I
+# - 4,832 test results changed from S to R
+# - 1,096 test results changed from I to S
+# - 342 test results changed from I to R
+# - 1,607 test results changed from R to S
# - 24 test results changed from R to I
# --------------------------------------------------------------------------
#
@@ -497,8 +497,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,696 first isolates (28.5% of total)
filter()
function, also from the dplyr
package:filter()
function, also from the dplyr
package:filter_first_isolate()
function:
First weighted isolates
-
isolate
@@ -524,19 +524,19 @@
1
-2010-01-26
-P1
+2010-02-14
+D2
B_ESCHR_COLI
-I
-S
-S
R
+S
+S
+S
TRUE
2
-2010-04-19
-P1
+2010-04-27
+D2
B_ESCHR_COLI
S
S
@@ -546,30 +546,30 @@
3
-2010-04-24
-P1
+2010-05-31
+D2
B_ESCHR_COLI
R
-R
-R
+S
+S
S
FALSE
4
-2010-06-11
-P1
+2010-08-21
+D2
B_ESCHR_COLI
S
S
S
-R
+S
FALSE
5
-2010-11-24
-P1
+2010-09-21
+D2
B_ESCHR_COLI
S
S
@@ -579,8 +579,8 @@
6
-2010-12-11
-P1
+2010-10-04
+D2
B_ESCHR_COLI
R
S
@@ -590,8 +590,8 @@
7
-2010-12-23
-P1
+2010-10-11
+D2
B_ESCHR_COLI
S
S
@@ -601,10 +601,10 @@
8
-2011-01-14
-P1
+2010-11-16
+D2
B_ESCHR_COLI
-R
+S
S
S
S
@@ -612,26 +612,26 @@
-9
-2011-01-19
-P1
+2011-03-05
+D2
B_ESCHR_COLI
-R
-R
S
S
-FALSE
-
-
+10
-2011-01-26
-P1
-B_ESCHR_COLI
-R
-I
S
S
TRUE
+
10
+2011-04-18
+D2
+B_ESCHR_COLI
+S
+S
+S
+S
+FALSE
+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.
-
isolate
@@ -662,20 +662,20 @@
1
-2010-01-26
-P1
+2010-02-14
+D2
B_ESCHR_COLI
-I
-S
-S
R
+S
+S
+S
TRUE
TRUE
2
-2010-04-19
-P1
+2010-04-27
+D2
B_ESCHR_COLI
S
S
@@ -686,44 +686,44 @@
3
-2010-04-24
-P1
+2010-05-31
+D2
B_ESCHR_COLI
R
-R
-R
+S
+S
S
FALSE
TRUE
4
-2010-06-11
-P1
+2010-08-21
+D2
B_ESCHR_COLI
S
S
S
-R
+S
FALSE
TRUE
5
-2010-11-24
-P1
+2010-09-21
+D2
B_ESCHR_COLI
S
S
S
S
FALSE
-TRUE
+FALSE
6
-2010-12-11
-P1
+2010-10-04
+D2
B_ESCHR_COLI
R
S
@@ -734,8 +734,8 @@
7
-2010-12-23
-P1
+2010-10-11
+D2
B_ESCHR_COLI
S
S
@@ -746,10 +746,10 @@
8
-2011-01-14
-P1
+2010-11-16
+D2
B_ESCHR_COLI
-R
+S
S
S
S
@@ -758,35 +758,35 @@
+9
-2011-01-19
-P1
+2011-03-05
+D2
B_ESCHR_COLI
-R
-R
+S
+S
+S
+S
+TRUE
+TRUE
+
+
-10
+2011-04-18
+D2
+B_ESCHR_COLI
+S
+S
S
S
FALSE
-TRUE
-
-
10
-2011-01-26
-P1
-B_ESCHR_COLI
-R
-I
-S
-S
-TRUE
-TRUE
+FALSE
filter_first_isolate()
, there’s a shortcut for this new algorithm too:
-1
-2015-05-08
-P3
-Hospital A
-B_ESCHR_COLI
-R
-I
-S
-S
-F
-Gram-negative
-Escherichia
-coli
-TRUE
-
-
-3
-2013-09-06
-U9
-Hospital B
-B_ESCHR_COLI
-R
-S
-S
-S
-F
-Gram-negative
-Escherichia
-coli
-TRUE
-
-
-5
-2011-04-18
-F4
-Hospital B
-B_STRPT_PNMN
-S
-S
-S
-R
-M
-Gram-positive
-Streptococcus
-pneumoniae
-TRUE
-
-
-7
-2016-10-10
-S10
-Hospital D
+2011-09-25
+O7
+Hospital C
B_STPHY_AURS
S
S
@@ -874,36 +826,84 @@
aureus
TRUE
- 8
-2010-01-21
-R3
-Hospital B
-B_STRPT_PNMN
+
+
+3
+2015-03-11
+S3
+Hospital A
+B_ESCHR_COLI
+R
+S
S
S
-R
-R
F
-Gram-positive
-Streptococcus
-pneumoniae
+Gram-negative
+Escherichia
+coli
+TRUE
+
+
+4
+2014-12-11
+G1
+Hospital B
+B_ESCHR_COLI
+S
+S
+S
+S
+M
+Gram-negative
+Escherichia
+coli
+TRUE
+
+
+5
+2013-01-02
+J8
+Hospital D
+B_ESCHR_COLI
+S
+S
+S
+R
+M
+Gram-negative
+Escherichia
+coli
+TRUE
+
+
7
+2013-08-06
+H4
+Hospital B
+B_ESCHR_COLI
+R
+I
+R
+S
+M
+Gram-negative
+Escherichia
+coli
TRUE
@@ -925,7 +925,7 @@
9
-2011-11-23
-B7
-Hospital B
-B_STRPT_PNMN
-R
-R
+2016-10-03
+F3
+Hospital D
+B_ESCHR_COLI
+S
S
R
+S
M
-Gram-positive
-Streptococcus
-pneumoniae
+Gram-negative
+Escherichia
+coli
TRUE
-Length: 15,241 (of which NA: 0 = 0%)
+Length: 15,009 (of which NA: 0 = 0%)
Unique: 4
Longest: 24
The functions resistance()
and susceptibility()
can be used to calculate antimicrobial resistance or susceptibility. For more specific analyses, the functions proportion_S()
, proportion_SI()
, proportion_I()
, proportion_IR()
and proportion_R()
can be used to determine the proportion of a specific antimicrobial outcome.
As per the EUCAST guideline of 2019, we calculate resistance as the proportion of R (proportion_R()
, equal to resistance()
) and susceptibility as the proportion of S and I (proportion_SI()
, equal to susceptibility()
). 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) %>%
@@ -993,19 +993,19 @@ Longest: 24
Hospital A
-0.4637681
+0.4640823
Hospital B
-0.4776811
+0.4663609
Hospital C
-0.4811697
+0.4736130
Hospital D
-0.4694820
+0.4749499
@@ -1023,23 +1023,23 @@ Longest: 24
Hospital A
-0.4637681
-4554
+0.4640823
+4566
Hospital B
-0.4776811
-5399
+0.4663609
+5232
Hospital C
-0.4811697
-2257
+0.4736130
+2217
Hospital D
-0.4694820
-3031
+0.4749499
+2994
@@ -1059,27 +1059,27 @@ Longest: 24
Escherichia
-0.9212433
-0.8984591
-0.9927565
+0.9211982
+0.8896235
+0.9929834
Klebsiella
-0.8298677
-0.8897290
-0.9836169
+0.8239034
+0.8804832
+0.9809282
Staphylococcus
-0.9290305
-0.9258168
-0.9946438
+0.9188023
+0.9209603
+0.9932560
Streptococcus
-0.6067899
+0.5974978
0.0000000
-0.6067899
+0.5974978
@@ -1089,11 +1089,12 @@ Longest: 24
summarise("1. Amoxi/clav" = susceptibility(AMC),
"2. Gentamicin" = susceptibility(GEN),
"3. Amoxi/clav + genta" = susceptibility(AMC, GEN)) %>%
- tidyr::gather("antibiotic", "S", -genus) %>%
- ggplot(aes(x = genus,
- y = S,
- fill = antibiotic)) +
- geom_col(position = "dodge2")
The next example uses the included example_isolates
, which is an anonymised data set containing 2,000 microbial blood culture isolates with their full antibiograms found in septic patients in 4 different hospitals in the Netherlands, between 2001 and 2017. This data.frame
can be used to practice AMR analysis.
We will compare the resistance to fosfomycin (column FOS
) in hospital A and D. The input for the fisher.test()
can be retrieved with a transformation like this:
check_FOS <- example_isolates %>%
- filter(hospital_id %in% c("A", "D")) %>% # filter on only hospitals A and D
- select(hospital_id, FOS) %>% # select the hospitals and fosfomycin
- group_by(hospital_id) %>% # group on the hospitals
- count_df(combine_SI = TRUE) %>% # count all isolates per group (hospital_id)
- tidyr::spread(hospital_id, value) %>% # transform output so A and D are columns
- select(A, D) %>% # and select these only
- as.matrix() # transform to good old matrix for fisher.test()
-
-check_FOS
-# A D
-# [1,] 25 77
-# [2,] 24 33
# use package 'tidyr' to pivot data;
+# it gets installed with this 'AMR' package
+library(tidyr)
+
+check_FOS <- example_isolates %>%
+ filter(hospital_id %in% c("A", "D")) %>% # filter on only hospitals A and D
+ select(hospital_id, FOS) %>% # select the hospitals and fosfomycin
+ group_by(hospital_id) %>% # group on the hospitals
+ count_df(combine_SI = TRUE) %>% # count all isolates per group (hospital_id)
+ pivot_wider(names_from = hospital_id, # transform output so A and D are columns
+ values_from = value) %>%
+ select(A, D) %>% # and only select these columns
+ as.matrix() # transform to a good old matrix for fisher.test()
+
+check_FOS
+# A D
+# [1,] 25 77
+# [2,] 24 33
We can apply the test now with:
# do Fisher's Exact Test
fisher.test(check_FOS)
@@ -1181,7 +1187,7 @@ Longest: 24
# sample estimates:
# odds ratio
# 0.4488318
As can be seen, the p value is 0.031, which means that the fosfomycin resistances found in hospital A and D are really different.
+As can be seen, the p value is 0.031, which means that the fosfomycin resistance found in hospital A and D are really different.
fMmku6Or?<&g#rzRu}^i`i}-?kGBxXf4V5nNF{x=t(|3!4|_2J
znM~`1IV^n%dj$5uBSX+TNpBBMHv2*y@cj&rJf+EJLW9UfG~`KdS9c$BKwU?6=&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