diff --git a/NAMESPACE b/NAMESPACE index aaf878ca..233df179 100755 --- a/NAMESPACE +++ b/NAMESPACE @@ -55,6 +55,8 @@ export(as.mic) export(as.mo) export(as.rsi) export(atc_certe) +export(atc_ddd) +export(atc_groups) export(atc_name) export(atc_official) export(atc_online_ddd) diff --git a/NEWS.md b/NEWS.md index 0ddafb84..4590581d 100755 --- a/NEWS.md +++ b/NEWS.md @@ -48,13 +48,13 @@ #### Changed * Added 65 antibiotics to the `antibiotics` data set, from the [Pharmaceuticals Community Register](http://ec.europa.eu/health/documents/community-register/html/atc.htm) of the European Commission * Removed columns `atc_group1_nl` and `atc_group2_nl` from the `antibiotics` data set -* Function `atc_ddd` has been renamed `atc_online_ddd()` -* Function `atc_groups` has been renamed `atc_online_groups()` +* Functions `atc_ddd()` and `atc_groups()` have been renamed `atc_online_ddd()` and `atc_online_groups()`. The old function are deprecated and will be removed in a future version. +* Function `guess_mo()` is now deprecated in favour of `as.mo()` and will be removed in future versions +* Function `guess_atc()` is now deprecated in favour of `as.atc()` and will be removed in future versions * Function `eucast_rules()`: * Updated EUCAST Clinical breakpoints to [version 9.0 of 1 January 2019](http://www.eucast.org/clinical_breakpoints/) * Fixed a critical bug where some rules that depend on previous applied rules would not be applied adequately * Emphasised in manual that penicillin is meant as benzylpenicillin (ATC [J01CE01](https://www.whocc.no/atc_ddd_index/?code=J01CE01)) -* Function `guess_mo()` is now deprecated in favour of `as.mo()` and will be removed in future versions * Improvements for `as.mo()`: * Fix for vector containing only empty values * Finds better results when input is in other languages diff --git a/R/atc.R b/R/atc.R index 4a6055ed..bcc791c0 100755 --- a/R/atc.R +++ b/R/atc.R @@ -146,17 +146,12 @@ as.atc <- function(x) { x.new } -#' @rdname AMR-deprecated -#' @export -guess_atc <- as.atc - #' @rdname as.atc #' @export is.atc <- function(x) { identical(class(x), "atc") } - #' @exportMethod print.atc #' @export #' @noRd diff --git a/R/deprecated.R b/R/deprecated.R index 8c13028f..ca95703b 100755 --- a/R/deprecated.R +++ b/R/deprecated.R @@ -54,6 +54,13 @@ guess_mo <- function(...) { as.mo(...) } +#' @rdname AMR-deprecated +#' @export +guess_atc <- function(...) { + .Deprecated(new = "as.atc", package = "AMR") + as.atc(...) +} + #' @rdname AMR-deprecated #' @export ab_property <- function(...) { @@ -109,3 +116,18 @@ ab_tradenames <- function(...) { .Deprecated(new = "atc_tradenames", package = "AMR") atc_tradenames(...) } + +#' @rdname AMR-deprecated +#' @export +atc_ddd <- function(...) { + .Deprecated(new = "atc_online_ddd", package = "AMR") + atc_online_ddd(...) +} + +#' @rdname AMR-deprecated +#' @export +atc_groups <- function(...) { + .Deprecated(new = "atc_online_groups", package = "AMR") + atc_online_groups(...) +} + diff --git a/docs/articles/AMR.html b/docs/articles/AMR.html index 34234277..80381a47 100644 --- a/docs/articles/AMR.html +++ b/docs/articles/AMR.html @@ -178,7 +178,7 @@
AMR.Rmd
Note: values on this page will change with every website update since they are based on randomly created values and the page was written in RMarkdown. However, the methodology remains unchanged. This page was generated on 26 January 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 RMarkdown. However, the methodology remains unchanged. This page was generated on 27 January 2019.
As with many uses in R, we need some additional packages for AMR analysis. Our package works closely together with the tidyverse packages dplyr
and ggplot2
by Dr Hadley Wickham. The tidyverse tremendously improves the way we conduct data science - it allows for a very natural way of writing syntaxes and creating beautiful plots in R.
Our AMR
package depends on these packages and even extends their use and functions.
library(dplyr)
-library(ggplot2)
-library(AMR)
-
-# (if not yet installed, install with:)
-# install.packages(c("tidyverse", "AMR"))
library(dplyr)
+library(ggplot2)
+library(AMR)
+
+# (if not yet installed, install with:)
+# install.packages(c("tidyverse", "AMR"))
To start with patients, we need a unique list of patients.
- +The LETTERS
object is available in R - it’s a vector with 26 characters: A
to Z
. The patients
object we just created is now a vector of length 260, with values (patient IDs) varying from A1
to Z10
. Now we we also set the gender of our patients, by putting the ID and the gender in a table:
patients_table <- data.frame(patient_id = patients,
+ gender = c(rep("M", 135),
+ rep("F", 125)))
The first 135 patient IDs are now male, the other 125 are female.
Let’s pretend that our data consists of blood cultures isolates from 1 January 2010 until 1 January 2018.
- +This dates
object now contains all days in our date range.
For this tutorial, we will uses four different microorganisms: Escherichia coli, Staphylococcus aureus, Streptococcus pneumoniae, and Klebsiella pneumoniae:
-bacteria <- c("Escherichia coli", "Staphylococcus aureus",
- "Streptococcus pneumoniae", "Klebsiella pneumoniae")
bacteria <- c("Escherichia coli", "Staphylococcus aureus",
+ "Streptococcus pneumoniae", "Klebsiella pneumoniae")
For completeness, we can also add the hospital where the patients was admitted and we need to define valid antibmicrobial results for our randomisation:
- +Using the sample()
function, we can randomly select items from all objects we defined earlier. To let our fake data reflect reality a bit, we will also approximately define the probabilities of bacteria and the antibiotic results with the prob
parameter.
data <- data.frame(date = sample(dates, 5000, replace = TRUE),
- patient_id = sample(patients, 5000, replace = TRUE),
- hospital = sample(hospitals, 5000, replace = TRUE, prob = c(0.30, 0.35, 0.15, 0.20)),
- bacteria = sample(bacteria, 5000, replace = TRUE, prob = c(0.50, 0.25, 0.15, 0.10)),
- amox = sample(ab_interpretations, 5000, replace = TRUE, prob = c(0.60, 0.05, 0.35)),
- amcl = sample(ab_interpretations, 5000, replace = TRUE, prob = c(0.75, 0.10, 0.15)),
- cipr = sample(ab_interpretations, 5000, replace = TRUE, prob = c(0.80, 0.00, 0.20)),
- gent = sample(ab_interpretations, 5000, replace = TRUE, prob = c(0.92, 0.00, 0.08))
- )
data <- data.frame(date = sample(dates, 5000, replace = TRUE),
+ patient_id = sample(patients, 5000, replace = TRUE),
+ hospital = sample(hospitals, 5000, replace = TRUE, prob = c(0.30, 0.35, 0.15, 0.20)),
+ bacteria = sample(bacteria, 5000, replace = TRUE, prob = c(0.50, 0.25, 0.15, 0.10)),
+ amox = sample(ab_interpretations, 5000, replace = TRUE, prob = c(0.60, 0.05, 0.35)),
+ amcl = sample(ab_interpretations, 5000, replace = TRUE, prob = c(0.75, 0.10, 0.15)),
+ cipr = sample(ab_interpretations, 5000, replace = TRUE, prob = c(0.80, 0.00, 0.20)),
+ gent = sample(ab_interpretations, 5000, replace = TRUE, prob = c(0.92, 0.00, 0.08))
+ )
Using the left_join()
function from the dplyr
package, we can ‘map’ the gender to the patient ID using the patients_table
object we created earlier:
data <- data %>% left_join(patients_table)
The resulting data set contains 5,000 blood culture isolates. With the head()
function we can preview the first 6 values of this data set:
head(data)
date | @@ -306,69 +306,69 @@|||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
2012-01-02 | -K9 | +2015-08-07 | +D6 | Hospital A | -Escherichia coli | -I | -S | +Staphylococcus aureus | +R | +R | S | S | M |
2011-05-22 | -Y3 | +2016-06-04 | +T3 | Hospital B | -Streptococcus pneumoniae | -S | +Staphylococcus aureus | +R | S | S | S | F | |
2015-11-10 | -F1 | +2012-09-25 | +R6 | Hospital C | Staphylococcus aureus | -S | -S | -S | -S | -M | -|||
2011-10-10 | -X7 | -Hospital D | -Staphylococcus aureus | R | S | S | S | F | |||||
2017-11-10 | -B3 | -Hospital D | +|||||||||||
2015-10-07 | +A4 | +Hospital B | Staphylococcus aureus | -R | S | R | +R | S | M | ||||
2014-11-09 | -O5 | -Hospital B | +|||||||||||
2016-04-12 | +S6 | +Hospital D | Klebsiella pneumoniae | -S | -S | R | S | +S | +S | +F | +|||
2010-11-24 | +Z3 | +Hospital C | +Escherichia coli | +R | +S | +S | +S | F | |||||
1 | -2010-08-27 | -Q10 | +2010-02-28 | +H3 | B_ESCHR_COL | -R | S | -R | +S | +S | S | TRUE | |
2 | -2010-10-24 | -Q10 | +2010-05-15 | +H3 | B_ESCHR_COL | -S | +R | S | S | S | @@ -514,87 +514,87 @@|||
3 | -2010-10-26 | -Q10 | +2010-07-09 | +H3 | B_ESCHR_COL | +R | S | S | -S | -S | +R | FALSE | |
4 | -2011-12-25 | -Q10 | +2011-01-05 | +H3 | B_ESCHR_COL | +S | +S | R | S | +FALSE | +|||
5 | +2011-08-01 | +H3 | +B_ESCHR_COL | +S | +I | S | S | TRUE | |||||
5 | -2012-05-04 | -Q10 | -B_ESCHR_COL | -I | -I | -S | -R | -FALSE | -|||||
6 | -2012-05-18 | -Q10 | +2011-08-28 | +H3 | B_ESCHR_COL | S | -I | +S | S | S | FALSE | ||
7 | -2012-05-23 | -Q10 | +2011-10-28 | +H3 | B_ESCHR_COL | S | -I | +S | S | S | FALSE | ||
8 | -2012-06-18 | -Q10 | -B_ESCHR_COL | -R | -R | -S | -R | -FALSE | -|||||
9 | -2013-10-02 | -Q10 | +2012-11-10 | +H3 | B_ESCHR_COL | S | S | -R | +S | S | TRUE | ||
10 | -2013-10-22 | -Q10 | +|||||||||||
9 | +2013-01-14 | +H3 | B_ESCHR_COL | S | +R | +R | +S | +FALSE | +|||||
10 | +2013-03-14 | +H3 | +B_ESCHR_COL | +R | S | S | S | @@ -604,16 +604,16 @@
Only 3 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 show 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(.)) %>%
- mutate(first_weighted = first_isolate(.))
-# NOTE: Using column `bacteria` as input for `col_mo`.
-# 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.
-# [Criterion] Inclusion based on key antibiotics, ignoring I.
-# => Found 4,414 first weighted isolates (88.3% of total)
data <- data %>%
+ mutate(keyab = key_antibiotics(.)) %>%
+ mutate(first_weighted = first_isolate(.))
+# NOTE: Using column `bacteria` as input for `col_mo`.
+# 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.
+# [Criterion] Inclusion based on key antibiotics, ignoring I.
+# => Found 4,388 first weighted isolates (87.8% of total)
isolate | @@ -630,22 +630,22 @@|||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | -2010-08-27 | -Q10 | +2010-02-28 | +H3 | B_ESCHR_COL | -R | S | -R | +S | +S | S | TRUE | TRUE | ||
2 | -2010-10-24 | -Q10 | +2010-05-15 | +H3 | B_ESCHR_COL | -S | +R | S | S | S | @@ -654,59 +654,59 @@|||||
3 | -2010-10-26 | -Q10 | -B_ESCHR_COL | -S | -S | -S | -S | -FALSE | -FALSE | -||||||
4 | -2011-12-25 | -Q10 | +2010-07-09 | +H3 | B_ESCHR_COL | R | S | S | -S | +R | +FALSE | TRUE | +|||
4 | +2011-01-05 | +H3 | +B_ESCHR_COL | +S | +S | +R | +S | +FALSE | TRUE | ||||||
5 | -2012-05-04 | -Q10 | +2011-08-01 | +H3 | B_ESCHR_COL | -I | +S | I | S | -R | -FALSE | +S | +TRUE | TRUE | |
6 | -2012-05-18 | -Q10 | +2011-08-28 | +H3 | B_ESCHR_COL | S | -I | +S | S | S | FALSE | -TRUE | +FALSE | ||
7 | -2012-05-23 | -Q10 | +2011-10-28 | +H3 | B_ESCHR_COL | S | -I | +S | S | S | FALSE | @@ -714,34 +714,34 @@||||
8 | -2012-06-18 | -Q10 | +2012-11-10 | +H3 | B_ESCHR_COL | -R | -R | S | -R | -FALSE | +S | +S | +S | +TRUE | TRUE |
9 | -2013-10-02 | -Q10 | +2013-01-14 | +H3 | B_ESCHR_COL | S | -S | +R | R | S | -TRUE | +FALSE | TRUE | ||
10 | -2013-10-22 | -Q10 | +2013-03-14 | +H3 | B_ESCHR_COL | -S | +R | S | S | S | @@ -750,19 +750,18 @@
Instead of 3, now 8 isolates are flagged. In total, 88.3% of all isolates are marked ‘first weighted’ - 146.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.
+Instead of 3, now 8 isolates are flagged. In total, 87.8% of all isolates are marked ‘first weighted’ - 146.5% more than when using the CLSI guideline. In real life, this novel algorithm will yield 5-10% more isolates than the classic CLSI guideline.
As with filter_first_isolate()
, there’s a shortcut for this new algorithm too:
So we end up with 4,414 isolates for analysis.
+data_1st <- data %>%
+ filter_first_weighted_isolate()
So we end up with 4,388 isolates for analysis.
We can remove unneeded columns:
- +Now our data looks like:
- +head(data_1st)
date | patient_id | hospital | @@ -779,43 +778,40 @@|||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
2 | -2011-05-22 | -Y3 | -Hospital B | -B_STRPTC_PNE | -S | -S | -S | +2015-08-07 | +D6 | +Hospital A | +B_STPHY_AUR | R | -F | +R | +S | +S | +M | Gram positive | -Streptococcus | -pneumoniae | +Staphylococcus | +aureus | TRUE |
3 | -2015-11-10 | -F1 | +2016-06-04 | +T3 | +Hospital B | +B_STPHY_AUR | +R | +S | +S | +S | +F | +Gram positive | +Staphylococcus | +aureus | +TRUE | +||||||||
2012-09-25 | +R6 | Hospital C | B_STPHY_AUR | -S | -S | -S | -S | -M | -Gram positive | -Staphylococcus | -aureus | -TRUE | -|||||||||||
4 | -2011-10-10 | -X7 | -Hospital D | -B_STPHY_AUR | R | S | S | @@ -827,14 +823,13 @@TRUE | |||||||||||||||
5 | -2017-11-10 | -B3 | -Hospital D | +2015-10-07 | +A4 | +Hospital B | B_STPHY_AUR | -R | S | R | +R | S | M | Gram positive | @@ -843,14 +838,13 @@TRUE | ||||||||
6 | -2014-11-09 | -O5 | -Hospital B | +2016-04-12 | +S6 | +Hospital D | B_KLBSL_PNE | R | S | -R | +S | S | F | Gram negative | @@ -859,16 +853,15 @@TRUE | ||||||||
7 | -2013-01-26 | -F4 | -Hospital B | +2010-11-24 | +Z3 | +Hospital C | B_ESCHR_COL | +R | S | S | S | -S | -M | +F | Gram negative | Escherichia | coli | @@ -884,12 +877,12 @@ Analysing the data||||||
1 | Escherichia coli | -2,153 | -48.8% | -2,153 | -48.8% | +2,157 | +49.2% | +2,157 | +49.2% | ||||||||||||||
2 | Staphylococcus aureus | -1,107 | -25.1% | -3,260 | -73.9% | +1,089 | +24.8% | +3,246 | +74.0% | ||||||||||||||
3 | Streptococcus pneumoniae | -677 | -15.3% | -3,937 | -89.2% | +694 | +15.8% | +3,940 | +89.8% | ||||||||||||||
4 | Klebsiella pneumoniae | -477 | -10.8% | -4,414 | +448 | +10.2% | +4,388 | 100.0% |
hospital | @@ -955,27 +948,27 @@ Longest: 24||
---|---|---|
Hospital A | -0.4615385 | +0.4517110 |
Hospital B | -0.4961089 | +0.4460916 |
Hospital C | -0.4975767 | +0.4834337 |
Hospital D | -0.4942288 | +0.4854054 |
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(amox),
- available = n_rsi(amox))
data_1st %>%
+ group_by(hospital) %>%
+ summarise(amoxicillin = portion_IR(amox),
+ available = n_rsi(amox))
hospital | @@ -985,32 +978,32 @@ Longest: 24||||
---|---|---|---|---|
Hospital A | -0.4615385 | -1300 | +0.4517110 | +1315 |
Hospital B | -0.4961089 | -1542 | +0.4460916 | +1484 |
Hospital C | -0.4975767 | -619 | +0.4834337 | +664 |
Hospital D | -0.4942288 | -953 | +0.4854054 | +925 |
These functions can also be used to get the portion of multiple antibiotics, to calculate co-resistance very easily:
-data_1st %>%
- group_by(genus) %>%
- summarise(amoxicillin = portion_S(amcl),
- gentamicin = portion_S(gent),
- "amox + gent" = portion_S(amcl, gent))
data_1st %>%
+ group_by(genus) %>%
+ summarise(amoxicillin = portion_S(amcl),
+ gentamicin = portion_S(gent),
+ "amox + gent" = portion_S(amcl, gent))
genus | @@ -1021,94 +1014,94 @@ Longest: 24||||||
---|---|---|---|---|---|---|
Escherichia | -0.7445425 | -0.9173247 | -0.9804923 | +0.7301808 | +0.9151599 | +0.9772833 |
Klebsiella | -0.7169811 | -0.9119497 | -0.9769392 | +0.7142857 | +0.9040179 | +0.9888393 |
Staphylococcus | -0.7705510 | -0.9168925 | -0.9828365 | +0.7557392 | +0.9155188 | +0.9770432 |
Streptococcus | -0.7474151 | +0.7305476 | 0.0000000 | -0.7474151 | +0.7305476 |
To make a transition to the next part, let’s see how this difference could be plotted:
-data_1st %>%
- group_by(genus) %>%
- summarise("1. Amoxicillin" = portion_S(amcl),
- "2. Gentamicin" = portion_S(gent),
- "3. Amox + gent" = portion_S(amcl, gent)) %>%
- tidyr::gather("Antibiotic", "S", -genus) %>%
- ggplot(aes(x = genus,
- y = S,
- fill = Antibiotic)) +
- geom_col(position = "dodge2")
data_1st %>%
+ group_by(genus) %>%
+ summarise("1. Amoxicillin" = portion_S(amcl),
+ "2. Gentamicin" = portion_S(gent),
+ "3. Amox + gent" = portion_S(amcl, gent)) %>%
+ tidyr::gather("Antibiotic", "S", -genus) %>%
+ ggplot(aes(x = genus,
+ y = S,
+ fill = Antibiotic)) +
+ geom_col(position = "dodge2")
To show results in plots, most R users would nowadays use the ggplot2
package. This package lets you create plots in layers. You can read more about it on their website. A quick example would look like these syntaxes:
ggplot(data = a_data_set,
- mapping = aes(x = year,
- y = value)) +
- geom_col() +
- labs(title = "A title",
- subtitle = "A subtitle",
- x = "My X axis",
- y = "My Y axis")
-
-ggplot(a_data_set,
- aes(year, value) +
- geom_bar()
ggplot(data = a_data_set,
+ mapping = aes(x = year,
+ y = value)) +
+ geom_col() +
+ labs(title = "A title",
+ subtitle = "A subtitle",
+ x = "My X axis",
+ y = "My Y axis")
+
+ggplot(a_data_set,
+ aes(year, value) +
+ geom_bar()
The AMR
package contains functions to extend this ggplot2
package, for example geom_rsi()
. It automatically transforms data with count_df()
or portion_df()
and show results in stacked bars. Its simplest and shortest example:
Omit the translate_ab = FALSE
to have the antibiotic codes (amox, amcl, cipr, gent) translated to official WHO names (amoxicillin, amoxicillin and betalactamase inhibitor, ciprofloxacin, gentamicin).
If we group on e.g. the genus
column and add some additional functions from our package, we can create this:
# group the data on `genus`
-ggplot(data_1st %>% group_by(genus)) +
- # create bars with genus on x axis
- # it looks for variables with class `rsi`,
- # of which we have 4 (earlier created with `as.rsi`)
- geom_rsi(x = "genus") +
- # split plots on antibiotic
- facet_rsi(facet = "Antibiotic") +
- # make R red, I yellow and S green
- scale_rsi_colours() +
- # show percentages on y axis
- scale_y_percent(breaks = 0:4 * 25) +
- # turn 90 degrees, make it bars instead of columns
- coord_flip() +
- # add labels
- labs(title = "Resistance per genus and antibiotic",
- subtitle = "(this is fake data)") +
- # and print genus in italic to follow our convention
- # (is now y axis because we turned the plot)
- theme(axis.text.y = element_text(face = "italic"))
# group the data on `genus`
+ggplot(data_1st %>% group_by(genus)) +
+ # create bars with genus on x axis
+ # it looks for variables with class `rsi`,
+ # of which we have 4 (earlier created with `as.rsi`)
+ geom_rsi(x = "genus") +
+ # split plots on antibiotic
+ facet_rsi(facet = "Antibiotic") +
+ # make R red, I yellow and S green
+ scale_rsi_colours() +
+ # show percentages on y axis
+ scale_y_percent(breaks = 0:4 * 25) +
+ # turn 90 degrees, make it bars instead of columns
+ coord_flip() +
+ # add labels
+ labs(title = "Resistance per genus and antibiotic",
+ subtitle = "(this is fake data)") +
+ # and print genus in italic to follow our convention
+ # (is now y axis because we turned the plot)
+ theme(axis.text.y = element_text(face = "italic"))
To simplify this, we also created the ggplot_rsi()
function, which combines almost all above functions:
data_1st %>%
- group_by(genus) %>%
- ggplot_rsi(x = "genus",
- facet = "Antibiotic",
- breaks = 0:4 * 25,
- datalabels = FALSE) +
- coord_flip()
data_1st %>%
+ group_by(genus) %>%
+ ggplot_rsi(x = "genus",
+ facet = "Antibiotic",
+ breaks = 0:4 * 25,
+ datalabels = FALSE) +
+ coord_flip()
We can transform the data and apply the test in only a couple of lines:
-septic_patients %>%
- filter(hospital_id %in% c("A", "D")) %>% # filter on only hospitals A and D
- select(hospital_id, fosf) %>% # select the hospitals and fosfomycin
- group_by(hospital_id) %>% # group on the hospitals
- count_df(combine_IR = 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()
- fisher.test() # do Fisher's Exact Test
-#
-# Fisher's Exact Test for Count Data
-#
-# data: .
-# p-value = 0.03104
-# alternative hypothesis: true odds ratio is not equal to 1
-# 95 percent confidence interval:
-# 1.054283 4.735995
-# sample estimates:
-# odds ratio
-# 2.228006
septic_patients %>%
+ filter(hospital_id %in% c("A", "D")) %>% # filter on only hospitals A and D
+ select(hospital_id, fosf) %>% # select the hospitals and fosfomycin
+ group_by(hospital_id) %>% # group on the hospitals
+ count_df(combine_IR = 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()
+ fisher.test() # do Fisher's Exact Test
+#
+# Fisher's Exact Test for Count Data
+#
+# data: .
+# p-value = 0.03104
+# alternative hypothesis: true odds ratio is not equal to 1
+# 95 percent confidence interval:
+# 1.054283 4.735995
+# sample estimates:
+# odds ratio
+# 2.228006
As can be seen, the p value is 0.03, which means that the fosfomycin resistances found in hospital A and D are really different.
antibiotics
data set, from the Pharmaceuticals Community Register of the European Commissionatc_group1_nl
and atc_group2_nl
from the antibiotics
data setatc_ddd
has been renamed atc_online_ddd()
-atc_groups
has been renamed atc_online_groups()
-atc_ddd()
and atc_groups()
have been renamed atc_online_ddd()
and atc_online_groups()
. The old function are deprecated and will be removed in a future version.guess_mo()
is now deprecated in favour of as.mo()
and will be removed in future versionsguess_atc()
is now deprecated in favour of as.atc()
and will be removed in future versionseucast_rules()
:guess_mo()
is now deprecated in favour of as.mo()
and will be removed in future versionsas.mo()
:guess_atc(x) - -ratio(x, ratio) +ratio(x, ratio) guess_mo(...) +guess_atc(...) + ab_property(...) ab_atc(...) @@ -247,7 +247,11 @@ ab_umcg(...) -ab_tradenames(...)+ab_tradenames(...) + +atc_ddd(...) + +atc_groups(...)
guess_atc()
ratio()
guess_mo()
ab_property()
ab_atc()
ab_official()
ab_name()
ab_trivial_nl()
ab_certe()
ab_umcg()
ab_tradenames()
ratio()
guess_mo()
guess_atc()
ab_property()
ab_atc()
ab_official()
ab_name()
ab_trivial_nl()
ab_certe()
ab_umcg()
ab_tradenames()
atc_ddd()
atc_groups()
Deprecated functions