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 24 December 2020.
+
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 26 December 2020.
Introduction
@@ -233,21 +233,21 @@
-
2020-12-24
+
2020-12-26
abcd
Escherichia coli
S
S
-
2020-12-24
+
2020-12-26
abcd
Escherichia coli
S
R
-
2020-12-24
+
2020-12-26
efgh
Escherichia coli
R
@@ -352,31 +352,9 @@
-
2012-10-07
-
D7
-
Hospital B
-
Escherichia coli
-
R
-
S
-
R
-
S
-
M
-
-
-
2016-11-19
-
V9
+
2011-10-28
+
I1
Hospital A
-
Klebsiella pneumoniae
-
R
-
S
-
S
-
S
-
F
-
-
-
2015-03-30
-
D9
-
Hospital D
Staphylococcus aureus
R
S
@@ -385,38 +363,60 @@
M
-
2012-06-28
-
Z4
-
Hospital B
-
Staphylococcus aureus
-
S
-
S
-
S
-
S
-
F
-
-
-
2014-03-04
-
M4
-
Hospital C
-
Staphylococcus aureus
-
S
-
S
-
S
-
S
-
M
-
-
-
2014-08-18
-
D2
-
Hospital B
+
2011-06-05
+
G5
+
Hospital A
Escherichia coli
R
-
R
+
S
S
S
M
+
+
2014-05-12
+
X7
+
Hospital D
+
Streptococcus pneumoniae
+
S
+
S
+
R
+
S
+
F
+
+
+
2011-02-23
+
K5
+
Hospital A
+
Staphylococcus aureus
+
S
+
S
+
S
+
S
+
M
+
+
+
2017-09-20
+
T5
+
Hospital B
+
Escherichia coli
+
S
+
S
+
R
+
S
+
F
+
+
+
2017-02-10
+
Y6
+
Hospital D
+
Escherichia coli
+
I
+
S
+
S
+
S
+
F
+
Now, let’s start the cleaning and the analysis!
@@ -449,16 +449,16 @@ Longest: 1
1
M
-
10,392
-
51.96%
-
10,392
-
51.96%
+
10,426
+
52.13%
+
10,426
+
52.13%
2
F
-
9,608
-
48.04%
+
9,574
+
47.87%
20,000
100.00%
@@ -515,7 +515,7 @@ Longest: 1
First weighted isolates
-
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 M9, 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 F3, sorted on date:
isolate
@@ -531,19 +531,19 @@ Longest: 1
1
-
2010-01-25
-
M9
+
2010-01-17
+
F3
B_ESCHR_COLI
S
S
R
-
S
+
R
TRUE
2
-
2010-02-01
-
M9
+
2010-03-13
+
F3
B_ESCHR_COLI
S
S
@@ -553,21 +553,21 @@ Longest: 1
3
-
2010-02-22
-
M9
+
2010-04-21
+
F3
B_ESCHR_COLI
+
R
S
-
S
-
S
+
R
S
FALSE
4
-
2010-08-12
-
M9
+
2010-06-24
+
F3
B_ESCHR_COLI
-
I
+
S
S
S
S
@@ -575,19 +575,19 @@ Longest: 1
5
-
2010-08-17
-
M9
+
2010-08-02
+
F3
B_ESCHR_COLI
-
R
-
R
-
R
+
S
+
S
+
S
S
FALSE
6
-
2010-09-18
-
M9
+
2010-08-14
+
F3
B_ESCHR_COLI
S
S
@@ -597,19 +597,19 @@ Longest: 1
7
-
2011-07-05
-
M9
+
2010-10-06
+
F3
B_ESCHR_COLI
-
R
S
-
R
S
-
TRUE
+
S
+
S
+
FALSE
8
-
2011-07-19
-
M9
+
2010-10-17
+
F3
B_ESCHR_COLI
R
R
@@ -619,19 +619,8 @@ Longest: 1
9
-
2011-07-20
-
M9
-
B_ESCHR_COLI
-
S
-
S
-
S
-
S
-
FALSE
-
-
-
10
-
2011-09-04
-
M9
+
2010-11-17
+
F3
B_ESCHR_COLI
R
I
@@ -639,6 +628,17 @@ Longest: 1
S
FALSE
+
+
10
+
2011-02-21
+
F3
+
B_ESCHR_COLI
+
R
+
R
+
S
+
R
+
TRUE
+
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.
@@ -665,20 +665,20 @@ Longest: 1
1
-
2010-01-25
-
M9
+
2010-01-17
+
F3
B_ESCHR_COLI
S
S
R
-
S
+
R
TRUE
TRUE
2
-
2010-02-01
-
M9
+
2010-03-13
+
F3
B_ESCHR_COLI
S
S
@@ -689,68 +689,68 @@ Longest: 1
3
-
2010-02-22
-
M9
+
2010-04-21
+
F3
B_ESCHR_COLI
+
R
S
-
S
-
S
+
R
S
FALSE
-
FALSE
+
TRUE
4
-
2010-08-12
-
M9
+
2010-06-24
+
F3
B_ESCHR_COLI
-
I
+
S
S
S
S
FALSE
-
FALSE
+
TRUE
5
-
2010-08-17
-
M9
+
2010-08-02
+
F3
B_ESCHR_COLI
-
R
-
R
-
R
+
S
+
S
+
S
S
FALSE
-
TRUE
+
FALSE
6
-
2010-09-18
-
M9
+
2010-08-14
+
F3
B_ESCHR_COLI
S
S
S
S
FALSE
-
TRUE
+
FALSE
7
-
2011-07-05
-
M9
+
2010-10-06
+
F3
B_ESCHR_COLI
-
R
S
-
R
S
-
TRUE
-
TRUE
+
S
+
S
+
FALSE
+
FALSE
8
-
2011-07-19
-
M9
+
2010-10-17
+
F3
B_ESCHR_COLI
R
R
@@ -761,36 +761,36 @@ Longest: 1
9
-
2011-07-20
-
M9
-
B_ESCHR_COLI
-
S
-
S
-
S
-
S
-
FALSE
-
TRUE
-
-
-
10
-
2011-09-04
-
M9
+
2010-11-17
+
F3
B_ESCHR_COLI
R
I
S
S
FALSE
+
FALSE
+
+
+
10
+
2011-02-21
+
F3
+
B_ESCHR_COLI
+
R
+
R
+
S
+
R
+
TRUE
TRUE
-
Instead of 2, now 8 isolates are flagged. In total, 78.4% of all isolates are marked ‘first weighted’ - 50.0% 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 6 isolates are flagged. In total, 78.5% of all isolates are marked ‘first weighted’ - 50.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.
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:
head(my_TB_data)# rifampicin isoniazid gatifloxacin ethambutol pyrazinamide moxifloxacin
-# 1 S S R I R S
-# 2 I S R I I R
-# 3 R R R S I R
-# 4 I I R R S S
-# 5 I R I S S R
-# 6 I R I I S I
+# 1 R I R S I S
+# 2 I S I S S R
+# 3 I I I R I R
+# 4 S S I S R I
+# 5 I R S R S R
+# 6 I I I R S I# kanamycin
-# 1 R
-# 2 S
+# 1 S
+# 2 I# 3 I
-# 4 I
+# 4 S# 5 I# 6 R
We can now add the interpretation of MDR-TB to our data set. You can use:
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. It is clear that accepted taxonomic names are extremely fast, but some variations can take up to 500-1000 times as much time.
To improve performance, two important calculations take almost no time at all: repetitive results and already precalculated results.
@@ -284,8 +270,8 @@
print(run_it, unit ="ms", signif =3)# Unit: milliseconds# expr min lq mean median uq max neval
-# mo_name(x) 134 167 201 179 207 310 10
-
So getting official taxonomic names of 2,000,000 (!!) items consisting of 90 unique values only takes 0.179 seconds. You only lose time on your unique input values.
+# mo_name(x) 136 169 210 198 247 317 10
+
So getting official taxonomic names of 2,000,000 (!!) items consisting of 90 unique values only takes 0.198 seconds. You only lose time on your unique input values.
@@ -299,10 +285,10 @@
print(run_it, unit ="ms", signif =3)# Unit: milliseconds# expr min lq mean median uq max neval
-# A 7.59 7.93 8.24 8.09 8.66 9.06 10
-# B 23.60 23.70 29.20 24.30 27.10 66.10 10
-# C 1.84 2.13 2.22 2.19 2.35 2.62 10
-
So going from mo_name("Staphylococcus aureus") to "Staphylococcus aureus" takes 0.0022 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:
+# A 7.21 7.32 7.92 7.69 8.49 9.43 10
+# B 22.60 23.50 28.90 24.70 26.10 69.20 10
+# C 1.87 1.92 2.10 2.08 2.27 2.34 10
+
So going from mo_name("Staphylococcus aureus") to "Staphylococcus aureus" takes 0.0021 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"),
@@ -316,14 +302,14 @@
print(run_it, unit ="ms", signif =3)# Unit: milliseconds# expr min lq mean median uq max neval
-# A 1.69 1.77 1.82 1.83 1.86 1.92 10
-# B 1.78 1.79 1.89 1.91 1.95 2.06 10
-# C 1.74 1.79 1.88 1.87 1.94 2.06 10
-# D 1.75 1.77 1.94 1.95 1.99 2.41 10
-# E 1.70 1.75 1.84 1.81 1.87 2.08 10
-# F 1.66 1.70 1.76 1.74 1.80 1.89 10
-# G 1.68 1.70 1.82 1.75 1.93 2.09 10
-# H 1.66 1.69 1.75 1.74 1.80 1.92 10
+# A 1.34 1.59 1.66 1.65 1.74 2.18 10
+# B 1.34 1.63 1.73 1.72 1.85 2.31 10
+# C 1.41 1.61 1.65 1.65 1.72 1.83 10
+# D 1.59 1.63 1.77 1.77 1.89 2.03 10
+# E 1.33 1.60 1.68 1.65 1.73 2.08 10
+# F 1.31 1.34 1.56 1.52 1.71 2.11 10
+# G 1.34 1.60 1.75 1.64 1.76 2.74 10
+# H 1.32 1.38 1.57 1.63 1.71 1.78 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" anyway, 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.
@@ -350,14 +336,14 @@
times =100)print(run_it, unit ="ms", signif =4)# Unit: milliseconds
-# expr min lq mean median uq max neval
-# en 15.91 16.98 21.87 17.54 18.34 168.50 100
-# de 18.98 20.14 26.30 20.74 22.64 66.68 100
-# nl 31.02 32.71 37.56 33.84 35.81 82.77 100
-# es 19.13 20.06 22.96 20.54 21.42 65.26 100
-# it 18.90 19.84 24.26 20.59 22.80 60.30 100
-# fr 18.89 19.92 23.46 20.49 21.72 62.85 100
-# pt 18.90 19.99 23.80 20.70 22.17 61.42 100
+# expr min lq mean median uq max neval
+# en 15.73 16.35 20.85 16.74 17.71 56.56 100
+# de 18.96 19.62 22.32 19.86 20.46 59.58 100
+# nl 31.06 31.91 37.31 32.78 34.57 75.58 100
+# es 18.92 19.59 23.43 19.92 20.42 62.72 100
+# it 18.80 19.36 22.59 19.74 20.54 62.72 100
+# fr 18.88 19.53 23.89 19.85 20.91 61.56 100
+# pt 18.89 19.51 21.46 19.87 20.29 59.12 100
Currently supported are German, Dutch, Spanish, Italian, French and Portuguese.
diff --git a/docs/articles/benchmarks_files/figure-html/unnamed-chunk-4-1.png b/docs/articles/benchmarks_files/figure-html/unnamed-chunk-4-1.png
index e0037178..19a9dea9 100644
Binary files a/docs/articles/benchmarks_files/figure-html/unnamed-chunk-4-1.png and b/docs/articles/benchmarks_files/figure-html/unnamed-chunk-4-1.png differ
diff --git a/docs/articles/datasets.html b/docs/articles/datasets.html
index 6b0d3dac..a8e6ad88 100644
--- a/docs/articles/datasets.html
+++ b/docs/articles/datasets.html
@@ -12,7 +12,7 @@
-
+
@@ -39,7 +39,7 @@
AMR (for R)
- 1.4.0.9044
+ 1.4.0.9046
diff --git a/docs/articles/index.html b/docs/articles/index.html
index d9882af7..ac6f49d0 100644
--- a/docs/articles/index.html
+++ b/docs/articles/index.html
@@ -19,8 +19,8 @@
+
-
@@ -81,7 +81,7 @@
AMR (for R)
- 1.4.0.9045
+ 1.4.0.9046
diff --git a/docs/articles/resistance_predict.html b/docs/articles/resistance_predict.html
index 82c59521..79bf768c 100644
--- a/docs/articles/resistance_predict.html
+++ b/docs/articles/resistance_predict.html
@@ -12,7 +12,7 @@
-
+
@@ -39,7 +39,7 @@
AMR (for R)
- 1.4.0.9044
+ 1.4.0.9046
diff --git a/docs/articles/welcome_to_AMR.html b/docs/articles/welcome_to_AMR.html
index afd13571..7e649944 100644
--- a/docs/articles/welcome_to_AMR.html
+++ b/docs/articles/welcome_to_AMR.html
@@ -12,7 +12,7 @@
-
+
@@ -39,7 +39,7 @@
AMR (for R)
- 1.4.0.9044
+ 1.4.0.9046
diff --git a/docs/authors.html b/docs/authors.html
index d3d4c60a..5b87ff78 100644
--- a/docs/authors.html
+++ b/docs/authors.html
@@ -19,8 +19,8 @@
+
-
@@ -81,7 +81,7 @@
AMR (for R)
- 1.4.0.9045
+ 1.4.0.9046
diff --git a/docs/countries.png b/docs/countries.png
index 5b995680..587eec03 100644
Binary files a/docs/countries.png and b/docs/countries.png differ
diff --git a/docs/countries_large.png b/docs/countries_large.png
index 5b77adb7..b9ee0ea5 100644
Binary files a/docs/countries_large.png and b/docs/countries_large.png differ
diff --git a/docs/index.html b/docs/index.html
index f96c6373..9618e3b2 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -12,7 +12,7 @@
-
+
@@ -43,7 +43,7 @@
AMR (for R)
- 1.4.0.9045
+ 1.4.0.9046
@@ -210,7 +210,7 @@ Since you are one of our users, we would like to know how you use the package an
-Used in 135 countries Since its first public release in early 2018, this package has been downloaded from 135 countries. Click the map to enlarge and to see the country names.
+Used in 138 countries Since its first public release in early 2018, this package has been downloaded from 138 countries. Click the map to enlarge and to see the country names.
-Last updated: 25 December 2020
+Last updated: 27 December 2020
New
-
Function is_new_episode() to determine patient episodes which are not necessarily based on microorganisms. It also supports grouped variables with e.g. mutate(), filter() and summarise() of the dplyr package:
+
Functions get_episode() and is_new_episode() to determine (patient) episodes which are not necessarily based on microorganisms. The get_episode() function returns the index number of the episode per group, while the is_new_episode() function returns values TRUE/FALSE to indicate whether an item in a vector is the start of a new episode. They also support dplyrs grouping (i.e. using group_by()):
Functions mo_is_gram_negative() and mo_is_gram_positive() as wrappers around mo_gramstain(). They always return TRUE or FALSE (except when the input is NA or the MO code is UNKNOWN), thus always return FALSE for species outside the taxonomic kingdom of Bacteria.
For all function arguments in the code, it is now defined what the exact type of user input should be (inspired by the typed package). If the user input for a certain function does not meet the requirements for a specific argument (such as the class or length), an informative error will be thrown. This makes the package more robust and the use of it more reproducible and reliable. In total, more than 420 arguments were defined.
Support for using dplyr’s across() to interpret MIC values or disk zone diameters, which also automatically determines the column with microorganism names or codes.
+
Support for using dplyr’s across() to interpret MIC values or disk zone diameters, which also automatically determines the column with microorganism names or codes.
# until dplyr 1.0.0
-your_data%>%mutate_if(is.mic, as.rsi)
-your_data%>%mutate_if(is.disk, as.rsi)
+your_data%>%mutate_if(is.mic, as.rsi)
+your_data%>%mutate_if(is.disk, as.rsi)# since dplyr 1.0.0
-your_data%>%mutate(across(where(is.mic), as.rsi))
-your_data%>%mutate(across(where(is.disk), as.rsi))
Cleaning columns in a data.frame now allows you to specify those columns with tidy selection, e.g. as.rsi(df, col1:col9)
Big speed improvement for interpreting MIC values and disk zone diameters. When interpreting 5,000 MIC values of two antibiotics (10,000 values in total), our benchmarks showed a total run time going from 80.7-85.1 seconds to 1.8-2.0 seconds.
@@ -433,14 +433,14 @@
Function ab_from_text() to retrieve antimicrobial drug names, doses and forms of administration from clinical texts in e.g. health care records, which also corrects for misspelling since it uses as.ab() internally
-
Tidyverse selection helpers for antibiotic classes, that help to select the columns of antibiotics that are of a specific antibiotic class, without the need to define the columns or antibiotic abbreviations. They can be used in any function that allows selection helpers, like dplyr::select() and tidyr::pivot_longer():
+
Tidyverse selection helpers for antibiotic classes, that help to select the columns of antibiotics that are of a specific antibiotic class, without the need to define the columns or antibiotic abbreviations. They can be used in any function that allows selection helpers, like dplyr::select() and tidyr::pivot_longer():
library(dplyr)# Columns 'IPM' and 'MEM' are in the example_isolates data setexample_isolates%>%
- select(carbapenems())
+ select(carbapenems())#> Selecting carbapenems: `IPM` (imipenem), `MEM` (meropenem)
@@ -622,14 +622,14 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
Fixed important floating point error for some MIC comparisons in EUCAST 2020 guideline
-
Interpretation from MIC values (and disk zones) to R/SI can now be used with mutate_at() of the dplyr package:
+
Interpretation from MIC values (and disk zones) to R/SI can now be used with mutate_at() of the dplyr package:
yourdata%>%
- mutate_at(vars(antibiotic1:antibiotic25), as.rsi, mo ="E. coli")
+ mutate_at(vars(antibiotic1:antibiotic25), as.rsi, mo ="E. coli")yourdata%>%
- mutate_at(vars(antibiotic1:antibiotic25), as.rsi, mo =.$mybacteria)
+ mutate_at(vars(antibiotic1:antibiotic25), as.rsi, mo =.$mybacteria)
Added antibiotic abbreviations for a laboratory manufacturer (GLIMS) for cefuroxime, cefotaxime, ceftazidime, cefepime, cefoxitin and trimethoprim/sulfamethoxazole
Added uti (as abbreviation of urinary tract infections) as argument to as.rsi(), so interpretation of MIC values and disk zones can be made dependent on isolates specifically from UTIs
Support for a new MDRO guideline: Magiorakos AP, Srinivasan A et al. “Multidrug-resistant, extensively drug-resistant and pandrug-resistant bacteria: an international expert proposal for interim standard definitions for acquired resistance.” Clinical Microbiology and Infection (2012).
@@ -922,7 +922,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
# (run this on your own console, as this page does not support colour printing)library(dplyr)example_isolates%>%
- select(mo:AMC)%>%
+ select(mo:AMC)%>%as_tibble()
@@ -1003,7 +1003,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
septic_patients%>%
- select(AMX, CIP)%>%
+ select(AMX, CIP)%>%rsi_df()# antibiotic interpretation value isolates# 1 Amoxicillin SI 0.4442636 546
@@ -1139,7 +1139,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
boxplot()# grouped boxplots:septic_patients%>%
- group_by(hospital_id)%>%
+ group_by(hospital_id)%>%freq(age)%>%boxplot()
@@ -1288,9 +1288,9 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
New function availability() to check the number of available (non-empty) results in a data.frame
New vignettes about how to conduct AMR analysis, predict antimicrobial resistance, use the G-test and more. These are also available (and even easier readable) on our website: https://msberends.gitlab.io/AMR.
@@ -1400,7 +1400,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
# Determine genus of microorganisms (mo) in `septic_patients` data set:# OLD WAYseptic_patients%>%
- mutate(genus =mo_genus(mo))%>%
+ mutate(genus =mo_genus(mo))%>%freq(genus)# NEW WAYseptic_patients%>%
@@ -1408,7 +1408,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
# Even supports grouping variables:septic_patients%>%
- group_by(gender)%>%
+ group_by(gender)%>%freq(mo_genus(mo))
Header info is now available as a list, with the header function
@@ -1419,7 +1419,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
Fix for header text where all observations are NA
New argument droplevels to exclude empty factor levels when input is a factor
Factor levels will be in header when present in input data (maximum of 5)
@@ -1508,7 +1508,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
septic_patients%>%freq(hospital_id)%>%
- select(-count, -cum_count)# only get item, percent, cum_percent
+ select(-count, -cum_count)# only get item, percent, cum_percent
Now prints in markdown at default in non-interactive sessions
@@ -1672,7 +1672,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
Support for quasiquotation in the functions series count_* and portions_*, and n_rsi. This allows to check for more than 2 vectors or columns.
-septic_patients%>%select(amox, cipr)%>%count_IR()
+septic_patients%>%select(amox, cipr)%>%count_IR()# which is the same as:septic_patients%>%count_IR(amox, cipr)
@@ -1858,7 +1858,7 @@ This works for all drug combinations, such as ampicillin/sulbactam, ceftazidime/
Full support for Windows, Linux and macOS
Full support for old R versions, only R-3.0.0 (April 2013) or later is needed (needed packages may have other dependencies)
-
Function n_rsi to count cases where antibiotic test results were available, to be used in conjunction with dplyr::summarise, see ?rsi
+
Function n_rsi to count cases where antibiotic test results were available, to be used in conjunction with dplyr::summarise, see ?rsi
Function guess_bactid to determine the ID of a microorganism based on genus/species or known abbreviations like MRSA
Function guess_atc to determine the ATC of an antibiotic based on name, trade name, or known abbreviations
Function freq to create frequency tables, with additional info in a header
These functions determine which items in a vector can be considered (the start of) a new episode, based on the argument episode_days. This can be used to determine clinical episodes for any epidemiological analysis. The get_episode() function returns the index number of the episode per group, while the is_new_episode() function returns values TRUE/FALSE to indicate whether an item in a vector is the start of a new episode.
Dates are first sorted from old to new. The oldest date will mark the start of the first episode. After this date, the next date will be marked that is at least episode_days days later than the start of the first episode. From that second marked date on, the next date will be marked that is at least episode_days days later than the start of the second episode which will be the start of the third episode, and so on. Before the vector is being returned, the original order will be restored.
+
The first_isolate() function is a wrapper around the is_new_episode() function, but is more efficient for data sets containing microorganism codes or names.
+
The dplyr package is not required for these functions to work, but these functions support variable grouping and work conveniently inside dplyr verbs such as filter(), mutate() and summarise().
+
Stable lifecycle
+
+
+
+
+The lifecycle of this function is stable. In a stable function, major changes are unlikely. This means that the unlying code will generally evolve by adding new arguments; removing arguments or changing the meaning of existing arguments will be avoided.
+
If the unlying code needs breaking changes, they will occur gradually. For example, a argument will be deprecated and first continue to work, but will emit an message informing you of the change. Next, typically after at least one newly released version on CRAN, the message will be transformed to an error.
# `example_isolates` is a dataset available in the AMR package.
+# See ?example_isolates.
+
+get_episode(example_isolates$date, episode_days =60)
+is_new_episode(example_isolates$date, episode_days =60)
+
+# filter on results from the third 60-day episode using base R
+example_isolates[which(get_episode(example_isolates$date, 60)==3), ]
+
+# \donttest{
+if(require("dplyr")){
+ # is_new_episode() can also be used in dplyr verbs to determine patient
+ # episodes based on any (combination of) grouping variables:
+ example_isolates%>%
+ mutate(condition =sample(x =c("A", "B", "C"),
+ size =2000,
+ replace =TRUE))%>%
+ group_by(condition)%>%
+ mutate(new_episode =is_new_episode(date, 365))
+
+ example_isolates%>%
+ group_by(hospital_id, patient_id)%>%
+ transmute(date,
+ patient_id,
+ new_index =get_episode(date, 60),
+ new_logical =is_new_episode(date, 60))
+
+
+ example_isolates%>%
+ group_by(hospital_id)%>%
+ summarise(patients =n_distinct(patient_id),
+ n_episodes_365 =sum(is_new_episode(date, episode_days =365)),
+ n_episodes_60 =sum(is_new_episode(date, episode_days =60)),
+ n_episodes_30 =sum(is_new_episode(date, episode_days =30)))
+
+
+ # grouping on patients and microorganisms leads to the same results
+ # as first_isolate():
+ x<-example_isolates%>%
+ filter(first_isolate(., include_unknown =TRUE))
+
+ y<-example_isolates%>%
+ group_by(patient_id, mo)%>%
+ filter(is_new_episode(date, 365))
+
+ identical(x$patient_id, y$patient_id)
+
+ # but is_new_episode() has a lot more flexibility than first_isolate(),
+ # since you can now group on anything that seems relevant:
+ example_isolates%>%
+ group_by(patient_id, mo, hospital_id, ward_icu)%>%
+ mutate(flag_episode =is_new_episode(date, 365))
+}
+# }
+
Use these function for the analysis part. You can use susceptibility() or resistance() on any antibiotic column. Be sure to first select the isolates that are appropiate for analysis, by using first_isolate() or is_new_episode(). You can also filter your data on certain resistance in certain antibiotic classes (filter_ab_class()), or determine multi-drug resistant microorganisms (MDRO, mdro()).
+
Use these function for the analysis part. You can use susceptibility() or resistance() on any antibiotic column. Be sure to first select the isolates that are appropiate for analysis, by using first_isolate() or is_new_episode(). You can also filter your data on certain resistance in certain antibiotic classes (filter_ab_class()), or determine multi-drug resistant microorganisms (MDRO, mdro()).
diff --git a/docs/reference/intrinsic_resistant.html b/docs/reference/intrinsic_resistant.html
index 87769278..6b9b6723 100644
--- a/docs/reference/intrinsic_resistant.html
+++ b/docs/reference/intrinsic_resistant.html
@@ -19,8 +19,8 @@
+
-
@@ -82,7 +82,7 @@
AMR (for R)
- 1.4.0.9044
+ 1.4.0.9046
diff --git a/docs/reference/is_new_episode.html b/docs/reference/is_new_episode.html
index 6a1f8a48..ea7ec263 100644
--- a/docs/reference/is_new_episode.html
+++ b/docs/reference/is_new_episode.html
@@ -19,8 +19,8 @@
+
-
@@ -82,7 +82,7 @@
AMR (for R)
- 1.4.0.9044
+ 1.4.0.9046
diff --git a/docs/reference/join.html b/docs/reference/join.html
index dc358759..e70d453d 100644
--- a/docs/reference/join.html
+++ b/docs/reference/join.html
@@ -19,8 +19,8 @@
+
-
@@ -82,7 +82,7 @@
AMR (for R)
- 1.4.0.9044
+ 1.4.0.9046
diff --git a/docs/reference/key_antibiotics.html b/docs/reference/key_antibiotics.html
index 0e63e308..93209875 100644
--- a/docs/reference/key_antibiotics.html
+++ b/docs/reference/key_antibiotics.html
@@ -19,8 +19,8 @@
+
-
@@ -82,7 +82,7 @@
AMR (for R)
- 1.4.0.9044
+ 1.4.0.9046
diff --git a/docs/reference/kurtosis.html b/docs/reference/kurtosis.html
index 6758774a..f9dacfb5 100644
--- a/docs/reference/kurtosis.html
+++ b/docs/reference/kurtosis.html
@@ -19,8 +19,8 @@
+
-
@@ -82,7 +82,7 @@
AMR (for R)
- 1.4.0.9044
+ 1.4.0.9046
diff --git a/docs/reference/lifecycle.html b/docs/reference/lifecycle.html
index 6e274f03..7b22cef1 100644
--- a/docs/reference/lifecycle.html
+++ b/docs/reference/lifecycle.html
@@ -19,8 +19,8 @@
+
-
@@ -84,7 +84,7 @@ This page contains a section for every lifecycle (with text borrowed from the af
AMR (for R)
- 1.4.0.9044
+ 1.4.0.9046
diff --git a/docs/reference/like.html b/docs/reference/like.html
index 81437461..31a8a7cf 100644
--- a/docs/reference/like.html
+++ b/docs/reference/like.html
@@ -19,8 +19,8 @@
+
-
@@ -82,7 +82,7 @@
AMR (for R)
- 1.4.0.9044
+ 1.4.0.9046
diff --git a/docs/reference/mdro.html b/docs/reference/mdro.html
index 56e43601..c30c713a 100644
--- a/docs/reference/mdro.html
+++ b/docs/reference/mdro.html
@@ -19,8 +19,8 @@
+
-
@@ -82,7 +82,7 @@
AMR (for R)
- 1.4.0.9044
+ 1.4.0.9046
diff --git a/docs/reference/microorganisms.codes.html b/docs/reference/microorganisms.codes.html
index 9d54a7c9..033c8fbd 100644
--- a/docs/reference/microorganisms.codes.html
+++ b/docs/reference/microorganisms.codes.html
@@ -19,8 +19,8 @@
+
-
@@ -82,7 +82,7 @@
AMR (for R)
- 1.4.0.9044
+ 1.4.0.9046
diff --git a/docs/reference/microorganisms.html b/docs/reference/microorganisms.html
index 30d7a857..100f9da6 100644
--- a/docs/reference/microorganisms.html
+++ b/docs/reference/microorganisms.html
@@ -19,8 +19,8 @@
+
-
@@ -82,7 +82,7 @@
AMR (for R)
- 1.4.0.9044
+ 1.4.0.9046
diff --git a/docs/reference/microorganisms.old.html b/docs/reference/microorganisms.old.html
index 4c51cc61..9b64ce45 100644
--- a/docs/reference/microorganisms.old.html
+++ b/docs/reference/microorganisms.old.html
@@ -19,8 +19,8 @@
+
-
@@ -82,7 +82,7 @@
AMR (for R)
- 1.4.0.9044
+ 1.4.0.9046
diff --git a/docs/reference/mo_matching_score.html b/docs/reference/mo_matching_score.html
index 8b312240..6578ef4d 100644
--- a/docs/reference/mo_matching_score.html
+++ b/docs/reference/mo_matching_score.html
@@ -19,8 +19,8 @@
+
-
@@ -82,7 +82,7 @@
AMR (for R)
- 1.4.0.9044
+ 1.4.0.9046
diff --git a/docs/reference/mo_property.html b/docs/reference/mo_property.html
index 67489484..79617975 100644
--- a/docs/reference/mo_property.html
+++ b/docs/reference/mo_property.html
@@ -19,8 +19,8 @@
+
-
@@ -82,7 +82,7 @@
AMR (for R)
- 1.4.0.9044
+ 1.4.0.9046
diff --git a/docs/reference/mo_source.html b/docs/reference/mo_source.html
index f978e77a..ea585b5b 100644
--- a/docs/reference/mo_source.html
+++ b/docs/reference/mo_source.html
@@ -19,8 +19,8 @@
+
-
@@ -83,7 +83,7 @@ This is the fastest way to have your organisation (or analysis) specific codes p
AMR (for R)
- 1.4.0.9044
+ 1.4.0.9046
diff --git a/docs/reference/pca.html b/docs/reference/pca.html
index ce27622b..08f03885 100644
--- a/docs/reference/pca.html
+++ b/docs/reference/pca.html
@@ -19,8 +19,8 @@
+
-
@@ -82,7 +82,7 @@
AMR (for R)
- 1.4.0.9044
+ 1.4.0.9046
diff --git a/docs/reference/plot.html b/docs/reference/plot.html
index 94e68755..65478bdd 100644
--- a/docs/reference/plot.html
+++ b/docs/reference/plot.html
@@ -19,8 +19,8 @@
+
-
@@ -82,7 +82,7 @@
AMR (for R)
- 1.4.0.9044
+ 1.4.0.9046
diff --git a/docs/reference/proportion.html b/docs/reference/proportion.html
index 76be1e6d..da4aa2f9 100644
--- a/docs/reference/proportion.html
+++ b/docs/reference/proportion.html
@@ -19,8 +19,8 @@
+
-
@@ -83,7 +83,7 @@ resistance() should be used to calculate resistance, susceptibility() should be
AMR (for R)
- 1.4.0.9044
+ 1.4.0.9046
diff --git a/docs/reference/random.html b/docs/reference/random.html
index fd3565eb..8fe8fa3e 100644
--- a/docs/reference/random.html
+++ b/docs/reference/random.html
@@ -19,8 +19,8 @@
+
-
@@ -82,7 +82,7 @@
AMR (for R)
- 1.4.0.9044
+ 1.4.0.9046
diff --git a/docs/reference/resistance_predict.html b/docs/reference/resistance_predict.html
index f3137959..31fdd23a 100644
--- a/docs/reference/resistance_predict.html
+++ b/docs/reference/resistance_predict.html
@@ -19,8 +19,8 @@
+
-
@@ -82,7 +82,7 @@
AMR (for R)
- 1.4.0.9044
+ 1.4.0.9046
diff --git a/docs/reference/rsi_translation.html b/docs/reference/rsi_translation.html
index 594c9891..bcfe6e26 100644
--- a/docs/reference/rsi_translation.html
+++ b/docs/reference/rsi_translation.html
@@ -19,8 +19,8 @@
+
-
@@ -82,7 +82,7 @@
AMR (for R)
- 1.4.0.9044
+ 1.4.0.9046
diff --git a/docs/reference/skewness.html b/docs/reference/skewness.html
index 96ed23d5..c4d5ab8a 100644
--- a/docs/reference/skewness.html
+++ b/docs/reference/skewness.html
@@ -19,8 +19,8 @@
+
-
@@ -83,7 +83,7 @@ When negative ('left-skewed'): the left tail is longer; the mass of the distribu
AMR (for R)
- 1.4.0.9044
+ 1.4.0.9046
diff --git a/docs/reference/translate.html b/docs/reference/translate.html
index 0b4342a0..fcd33ebe 100644
--- a/docs/reference/translate.html
+++ b/docs/reference/translate.html
@@ -19,8 +19,8 @@
+
-
@@ -82,7 +82,7 @@
AMR (for R)
- 1.4.0.9044
+ 1.4.0.9046
diff --git a/docs/sitemap.xml b/docs/sitemap.xml
index 8071036d..30f3a701 100644
--- a/docs/sitemap.xml
+++ b/docs/sitemap.xml
@@ -84,6 +84,9 @@
https://msberends.github.io/AMR//reference/g.test.html
+
+ https://msberends.github.io/AMR//reference/get_episode.html
+ https://msberends.github.io/AMR//reference/ggplot_pca.html
@@ -96,9 +99,6 @@
https://msberends.github.io/AMR//reference/intrinsic_resistant.html
-
- https://msberends.github.io/AMR//reference/is_new_episode.html
- https://msberends.github.io/AMR//reference/join.html
diff --git a/docs/survey.html b/docs/survey.html
index daddda6c..d99f5c5a 100644
--- a/docs/survey.html
+++ b/docs/survey.html
@@ -19,8 +19,8 @@
+
-
@@ -81,7 +81,7 @@
AMR (for R)
- 1.4.0.9045
+ 1.4.0.9046
diff --git a/index.md b/index.md
index 22902d66..05362cf6 100644
--- a/index.md
+++ b/index.md
@@ -18,8 +18,8 @@ This package is [fully independent of any other R package](https://en.wikipedia.
- Used in 135 countries
- Since its first public release in early 2018, this package has been downloaded from 135 countries. Click the map to enlarge and to see the country names.
+ Used in 138 countries
+ Since its first public release in early 2018, this package has been downloaded from 138 countries. Click the map to enlarge and to see the country names.
##### With `AMR` (for R), there's always a knowledgeable microbiologist by your side!
diff --git a/man/is_new_episode.Rd b/man/get_episode.Rd
similarity index 65%
rename from man/is_new_episode.Rd
rename to man/get_episode.Rd
index 591e49c9..9e478c7d 100644
--- a/man/is_new_episode.Rd
+++ b/man/get_episode.Rd
@@ -1,30 +1,36 @@
% Generated by roxygen2: do not edit by hand
-% Please edit documentation in R/is_new_episode.R
-\name{is_new_episode}
+% Please edit documentation in R/episode.R
+\name{get_episode}
+\alias{get_episode}
\alias{is_new_episode}
\title{Determine (new) episodes for patients}
\usage{
-is_new_episode(x, episode_days = 365, ...)
+get_episode(x, episode_days, ...)
+
+is_new_episode(x, episode_days, ...)
}
\arguments{
\item{x}{vector of dates (class \code{Date} or \code{POSIXt})}
-\item{episode_days}{length of the required episode in days, defaults to 365. Every element in the input will return \code{TRUE} after this number of days has passed since the last included date, independent of calendar years. Please see \emph{Details}.}
+\item{episode_days}{length of the required episode in days, please see \emph{Details}}
\item{...}{arguments passed on to \code{\link[=as.Date]{as.Date()}}}
}
\value{
-a \link{logical} vector
+\itemize{
+\item \code{\link[=get_episode]{get_episode()}}: a \link{double} vector
+\item \code{\link[=is_new_episode]{is_new_episode()}}: a \link{logical} vector
+}
}
\description{
-This function determines which items in a vector can be considered (the start of) a new episode, based on the argument \code{episode_days}. This can be used to determine clinical episodes for any epidemiological analysis.
+These functions determine which items in a vector can be considered (the start of) a new episode, based on the argument \code{episode_days}. This can be used to determine clinical episodes for any epidemiological analysis. The \code{\link[=get_episode]{get_episode()}} function returns the index number of the episode per group, while the \code{\link[=is_new_episode]{is_new_episode()}} function returns values \code{TRUE}/\code{FALSE} to indicate whether an item in a vector is the start of a new episode.
}
\details{
Dates are first sorted from old to new. The oldest date will mark the start of the first episode. After this date, the next date will be marked that is at least \code{episode_days} days later than the start of the first episode. From that second marked date on, the next date will be marked that is at least \code{episode_days} days later than the start of the second episode which will be the start of the third episode, and so on. Before the vector is being returned, the original order will be restored.
-The \code{\link[=first_isolate]{first_isolate()}} function is a wrapper around the \code{\link[=is_new_episode]{is_new_episode()}} function, but more efficient for data sets containing microorganism codes or names.
+The \code{\link[=first_isolate]{first_isolate()}} function is a wrapper around the \code{\link[=is_new_episode]{is_new_episode()}} function, but is more efficient for data sets containing microorganism codes or names.
-The \code{dplyr} package is not required for this function to work, but this function works conveniently inside \code{dplyr} verbs such as \code{\link[dplyr:filter]{filter()}}, \code{\link[dplyr:mutate]{mutate()}} and \code{\link[dplyr:summarise]{summarise()}}.
+The \code{dplyr} package is not required for these functions to work, but these functions support \link[dplyr:group_by]{variable grouping} and work conveniently inside \code{dplyr} verbs such as \code{\link[dplyr:filter]{filter()}}, \code{\link[dplyr:mutate]{mutate()}} and \code{\link[dplyr:summarise]{summarise()}}.
}
\section{Stable lifecycle}{
@@ -43,8 +49,12 @@ On our website \url{https://msberends.github.io/AMR/} you can find \href{https:/
# `example_isolates` is a dataset available in the AMR package.
# See ?example_isolates.
-is_new_episode(example_isolates$date)
+get_episode(example_isolates$date, episode_days = 60)
is_new_episode(example_isolates$date, episode_days = 60)
+
+# filter on results from the third 60-day episode using base R
+example_isolates[which(get_episode(example_isolates$date, 60) == 3), ]
+
\donttest{
if (require("dplyr")) {
# is_new_episode() can also be used in dplyr verbs to determine patient
@@ -54,7 +64,15 @@ if (require("dplyr")) {
size = 2000,
replace = TRUE)) \%>\%
group_by(condition) \%>\%
- mutate(new_episode = is_new_episode(date))
+ mutate(new_episode = is_new_episode(date, 365))
+
+ example_isolates \%>\%
+ group_by(hospital_id, patient_id) \%>\%
+ transmute(date,
+ patient_id,
+ new_index = get_episode(date, 60),
+ new_logical = is_new_episode(date, 60))
+
example_isolates \%>\%
group_by(hospital_id) \%>\%
@@ -71,7 +89,7 @@ if (require("dplyr")) {
y <- example_isolates \%>\%
group_by(patient_id, mo) \%>\%
- filter(is_new_episode(date))
+ filter(is_new_episode(date, 365))
identical(x$patient_id, y$patient_id)
@@ -79,7 +97,10 @@ if (require("dplyr")) {
# since you can now group on anything that seems relevant:
example_isolates \%>\%
group_by(patient_id, mo, hospital_id, ward_icu) \%>\%
- mutate(flag_episode = is_new_episode(date))
+ mutate(flag_episode = is_new_episode(date, 365))
}
}
}
+\seealso{
+\code{\link[=first_isolate]{first_isolate()}}
+}
diff --git a/pkgdown/logos/countries.png b/pkgdown/logos/countries.png
index 5b995680..587eec03 100644
Binary files a/pkgdown/logos/countries.png and b/pkgdown/logos/countries.png differ
diff --git a/pkgdown/logos/countries_large.png b/pkgdown/logos/countries_large.png
index 5b77adb7..b9ee0ea5 100644
Binary files a/pkgdown/logos/countries_large.png and b/pkgdown/logos/countries_large.png differ
diff --git a/tests/testthat/test-count.R b/tests/testthat/test-count.R
index f42b8f52..2f63dadb 100644
--- a/tests/testthat/test-count.R
+++ b/tests/testthat/test-count.R
@@ -79,7 +79,9 @@ test_that("counts work", {
)
# warning for speed loss
+ reset_all_thrown_messages()
expect_warning(count_resistant(as.character(example_isolates$AMC)))
+ reset_all_thrown_messages()
expect_warning(count_resistant(example_isolates$AMC,
as.character(example_isolates$GEN)))
diff --git a/tests/testthat/test-is_new_episode.R b/tests/testthat/test-episode.R
similarity index 98%
rename from tests/testthat/test-is_new_episode.R
rename to tests/testthat/test-episode.R
index 87f4d838..90f7606c 100644
--- a/tests/testthat/test-is_new_episode.R
+++ b/tests/testthat/test-episode.R
@@ -23,7 +23,7 @@
# how to conduct AMR analysis: https://msberends.github.io/AMR/ #
# ==================================================================== #
-context("is_new_episode.R")
+context("episode.R")
test_that("new episodes work", {
skip_on_cran()
diff --git a/tests/testthat/test-filter_ab_class.R b/tests/testthat/test-filter_ab_class.R
index 6709c80d..c6d67f12 100644
--- a/tests/testthat/test-filter_ab_class.R
+++ b/tests/testthat/test-filter_ab_class.R
@@ -28,6 +28,7 @@ context("filter_ab_class.R")
test_that("ATC-group filtering works", {
skip_on_cran()
+ library(dplyr)
expect_gt(example_isolates %>% filter_ab_class("carbapenem") %>% nrow(), 0)
expect_gt(example_isolates %>% filter_aminoglycosides() %>% nrow(), 0)
expect_gt(example_isolates %>% filter_carbapenems() %>% nrow(), 0)
diff --git a/tests/testthat/test-proportion.R b/tests/testthat/test-proportion.R
index 203e2342..438e0072 100755
--- a/tests/testthat/test-proportion.R
+++ b/tests/testthat/test-proportion.R
@@ -76,11 +76,15 @@ test_that("proportions works", {
combination_n = n_rsi(CIP, GEN)) %>%
pull(combination_n),
c(305, 617, 241, 711))
-
+
+ reset_all_thrown_messages()
expect_warning(proportion_R(as.character(example_isolates$AMC)))
+ reset_all_thrown_messages()
expect_warning(proportion_S(as.character(example_isolates$AMC)))
+ reset_all_thrown_messages()
expect_warning(proportion_S(as.character(example_isolates$AMC,
example_isolates$GEN)))
+ reset_all_thrown_messages()
expect_warning(n_rsi(as.character(example_isolates$AMC,
example_isolates$GEN)))
expect_equal(suppressWarnings(n_rsi(as.character(example_isolates$AMC,
@@ -105,8 +109,11 @@ test_that("proportions works", {
NA_real_)
# warning for speed loss
+ reset_all_thrown_messages()
expect_warning(proportion_R(as.character(example_isolates$GEN)))
+ reset_all_thrown_messages()
expect_warning(proportion_I(as.character(example_isolates$GEN)))
+ reset_all_thrown_messages()
expect_warning(proportion_S(example_isolates$AMC, as.character(example_isolates$GEN)))
# proportion_df