1
0
mirror of https://github.com/msberends/AMR.git synced 2025-07-08 18:41:58 +02:00

(v0.7.1.9063) septic_patients -> example_isolates

This commit is contained in:
2019-08-27 16:45:42 +02:00
parent 7a6fce4eb8
commit 93be16484b
92 changed files with 1143 additions and 818 deletions

View File

@ -129,7 +129,7 @@ age <- function(x, reference = Sys.Date(), exact = FALSE) {
#'
#' # resistance of ciprofloxacine per age group
#' library(dplyr)
#' septic_patients %>%
#' example_isolates %>%
#' filter_first_isolate() %>%
#' filter(mo == as.mo("E. coli")) %>%
#' group_by(age_group = age_groups(age)) %>%

View File

@ -29,16 +29,16 @@
#' @inheritSection AMR Read more on our website!
#' @export
#' @examples
#' availability(septic_patients)
#' availability(example_isolates)
#'
#' library(dplyr)
#' septic_patients %>% availability()
#' example_isolates %>% availability()
#'
#' septic_patients %>%
#' example_isolates %>%
#' select_if(is.rsi) %>%
#' availability()
#'
#' septic_patients %>%
#' example_isolates %>%
#' filter(mo == as.mo("E. coli")) %>%
#' select_if(is.rsi) %>%
#' availability()

View File

@ -23,16 +23,18 @@
#'
#' Determine antimicrobial resistance (AMR) of all bug-drug combinations in your data set where at least 30 (default) isolates are available per species. Use \code{format} on the result to prettify it to a printable format, see Examples.
#' @inheritParams eucast_rules
#' @param combine_RI logical to indicate whether values R and I should be summed
#' @inheritParams rsi_df
#' @importFrom dplyr rename
#' @importFrom tidyr spread
#' @importFrom clean freq
#' @details The function \code{format} calculated the resistance per bug-drug combination. Use \code{combine_RI = FALSE} (default) to test R vs. S+I and \code{combine_RI = TRUE} to test R+I vs. S.
#' @export
#' @source \strong{M39 Analysis and Presentation of Cumulative Antimicrobial Susceptibility Test Data, 4th Edition}, 2014, \emph{Clinical and Laboratory Standards Institute (CLSI)}. \url{https://clsi.org/standards/products/microbiology/documents/m39/}.
#' @inheritSection AMR Read more on our website!
#' @examples
#' \donttest{
#' x <- bug_drug_combinations(septic_patients)
#' x <- bug_drug_combinations(example_isolates)
#' x
#' format(x)
#' }
@ -70,8 +72,8 @@ bug_drug_combinations <- function(x, col_mo = NULL, minimum = 30) {
#' @importFrom tidyr spread
#' @exportMethod format.bugdrug
#' @export
format.bugdrug <- function(x, combine_SI = TRUE, add_ab_group = TRUE, ...) {
if (combine_SI == TRUE) {
format.bugdrug <- function(x, combine_RI = FALSE, add_ab_group = TRUE, ...) {
if (combine_RI == FALSE) {
x$isolates <- x$R
} else {
x$isolates <- x$R + x$I

View File

@ -44,29 +44,29 @@
#' @export
#' @inheritSection AMR Read more on our website!
#' @examples
#' # septic_patients is a data set available in the AMR package. It is true, genuine data.
#' ?septic_patients
#' # example_isolates is a data set available in the AMR package.
#' ?example_isolates
#'
#' # Count resistant isolates
#' count_R(septic_patients$AMX)
#' count_IR(septic_patients$AMX)
#' count_R(example_isolates$AMX)
#' count_IR(example_isolates$AMX)
#'
#' # Or susceptible isolates
#' count_S(septic_patients$AMX)
#' count_SI(septic_patients$AMX)
#' count_S(example_isolates$AMX)
#' count_SI(example_isolates$AMX)
#'
#' # Count all available isolates
#' count_all(septic_patients$AMX)
#' n_rsi(septic_patients$AMX)
#' count_all(example_isolates$AMX)
#' n_rsi(example_isolates$AMX)
#'
#' # Since n_rsi counts available isolates, you can
#' # calculate back to count e.g. non-susceptible isolates.
#' # This results in the same:
#' count_SI(septic_patients$AMX)
#' portion_SI(septic_patients$AMX) * n_rsi(septic_patients$AMX)
#' count_SI(example_isolates$AMX)
#' portion_SI(example_isolates$AMX) * n_rsi(example_isolates$AMX)
#'
#' library(dplyr)
#' septic_patients %>%
#' example_isolates %>%
#' group_by(hospital_id) %>%
#' summarise(R = count_R(CIP),
#' I = count_I(CIP),
@ -78,24 +78,24 @@
#' # Count co-resistance between amoxicillin/clav acid and gentamicin,
#' # so we can see that combination therapy does a lot more than mono therapy.
#' # Please mind that `portion_SI` calculates percentages right away instead.
#' count_SI(septic_patients$AMC) # 1433
#' count_all(septic_patients$AMC) # 1879
#' count_SI(example_isolates$AMC) # 1433
#' count_all(example_isolates$AMC) # 1879
#'
#' count_SI(septic_patients$GEN) # 1399
#' count_all(septic_patients$GEN) # 1855
#' count_SI(example_isolates$GEN) # 1399
#' count_all(example_isolates$GEN) # 1855
#'
#' with(septic_patients,
#' with(example_isolates,
#' count_SI(AMC, GEN)) # 1764
#' with(septic_patients,
#' with(example_isolates,
#' n_rsi(AMC, GEN)) # 1936
#'
#' # Get portions S/I/R immediately of all rsi columns
#' septic_patients %>%
#' example_isolates %>%
#' select(AMX, CIP) %>%
#' count_df(translate = FALSE)
#'
#' # It also supports grouping variables
#' septic_patients %>%
#' example_isolates %>%
#' select(hospital_id, AMX, CIP) %>%
#' group_by(hospital_id) %>%
#' count_df(translate = FALSE)

View File

@ -125,7 +125,7 @@ catalogue_of_life <- list(
#' Data set with 2,000 blood culture isolates from septic patients
#'
#' 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. It is true, genuine data. This \code{data.frame} can be used to practice AMR analysis. For examples, please read \href{https://msberends.gitlab.io/AMR/articles/AMR.html}{the tutorial on our website}.
#' 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 \code{data.frame} can be used to practice AMR analysis. For examples, please read \href{https://msberends.gitlab.io/AMR/articles/AMR.html}{the tutorial on our website}.
#' @format A \code{\link{data.frame}} with 2,000 observations and 49 variables:
#' \describe{
#' \item{\code{date}}{date of receipt at the laboratory}
@ -140,11 +140,11 @@ catalogue_of_life <- list(
#' \item{\code{peni:rifa}}{40 different antibiotics with class \code{rsi} (see \code{\link{as.rsi}}); these column names occur in \code{\link{antibiotics}} data set and can be translated with \code{\link{ab_name}}}
#' }
#' @inheritSection AMR Read more on our website!
"septic_patients"
"example_isolates"
#' Data set with 500 isolates - WHONET example
#'
#' This example data set has the exact same structure as an export file from WHONET. Such files can be used with this package, as this example data set shows. The data itself was based on our \code{\link{septic_patients}} data set.
#' This example data set has the exact same structure as an export file from WHONET. Such files can be used with this package, as this example data set shows. The data itself was based on our \code{\link{example_isolates}} data set.
#' @format A \code{\link{data.frame}} with 500 observations and 53 variables:
#' \describe{
#' \item{\code{Identification number}}{ID of the sample}

View File

@ -37,29 +37,29 @@
#' library(dplyr)
#'
#' # filter on isolates that have any result for any aminoglycoside
#' septic_patients %>% filter_aminoglycosides()
#' example_isolates %>% filter_aminoglycosides()
#'
#' # this is essentially the same as (but without determination of column names):
#' septic_patients %>%
#' example_isolates %>%
#' filter_at(.vars = vars(c("GEN", "TOB", "AMK", "KAN")),
#' .vars_predicate = any_vars(. %in% c("S", "I", "R")))
#'
#'
#' # filter on isolates that show resistance to ANY aminoglycoside
#' septic_patients %>% filter_aminoglycosides("R")
#' example_isolates %>% filter_aminoglycosides("R")
#'
#' # filter on isolates that show resistance to ALL aminoglycosides
#' septic_patients %>% filter_aminoglycosides("R", "all")
#' example_isolates %>% filter_aminoglycosides("R", "all")
#'
#' # filter on isolates that show resistance to
#' # any aminoglycoside and any fluoroquinolone
#' septic_patients %>%
#' example_isolates %>%
#' filter_aminoglycosides("R") %>%
#' filter_fluoroquinolones("R")
#'
#' # filter on isolates that show resistance to
#' # all aminoglycosides and all fluoroquinolones
#' septic_patients %>%
#' example_isolates %>%
#' filter_aminoglycosides("R", "all") %>%
#' filter_fluoroquinolones("R", "all")
filter_ab_class <- function(x,

View File

@ -79,12 +79,12 @@
#' @source Methodology of this function is based on: \strong{M39 Analysis and Presentation of Cumulative Antimicrobial Susceptibility Test Data, 4th Edition}, 2014, \emph{Clinical and Laboratory Standards Institute (CLSI)}. \url{https://clsi.org/standards/products/microbiology/documents/m39/}.
#' @inheritSection AMR Read more on our website!
#' @examples
#' # `septic_patients` is a dataset available in the AMR package. It is true, genuine data.
#' # See ?septic_patients.
#' # `example_isolates` is a dataset available in the AMR package.
#' # See ?example_isolates.
#'
#' library(dplyr)
#' # Filter on first isolates:
#' septic_patients %>%
#' example_isolates %>%
#' mutate(first_isolate = first_isolate(.,
#' col_date = "date",
#' col_patient_id = "patient_id",
@ -92,19 +92,19 @@
#' filter(first_isolate == TRUE)
#'
#' # Which can be shortened to:
#' septic_patients %>%
#' example_isolates %>%
#' filter_first_isolate()
#' # or for first weighted isolates:
#' septic_patients %>%
#' example_isolates %>%
#' filter_first_weighted_isolate()
#'
#' # Now let's see if first isolates matter:
#' A <- septic_patients %>%
#' A <- example_isolates %>%
#' group_by(hospital_id) %>%
#' summarise(count = n_rsi(GEN), # gentamicin availability
#' resistance = portion_IR(GEN)) # gentamicin resistance
#'
#' B <- septic_patients %>%
#' B <- example_isolates %>%
#' filter_first_weighted_isolate() %>% # the 1st isolate filter
#' group_by(hospital_id) %>%
#' summarise(count = n_rsi(GEN), # gentamicin availability

View File

@ -66,11 +66,11 @@
#' library(ggplot2)
#'
#' # get antimicrobial results for drugs against a UTI:
#' ggplot(septic_patients %>% select(AMX, NIT, FOS, TMP, CIP)) +
#' ggplot(example_isolates %>% select(AMX, NIT, FOS, TMP, CIP)) +
#' geom_rsi()
#'
#' # prettify the plot using some additional functions:
#' df <- septic_patients %>% select(AMX, NIT, FOS, TMP, CIP)
#' df <- example_isolates %>% select(AMX, NIT, FOS, TMP, CIP)
#' ggplot(df) +
#' geom_rsi() +
#' scale_y_percent() +
@ -79,17 +79,17 @@
#' theme_rsi()
#'
#' # or better yet, simplify this using the wrapper function - a single command:
#' septic_patients %>%
#' example_isolates %>%
#' select(AMX, NIT, FOS, TMP, CIP) %>%
#' ggplot_rsi()
#'
#' # get only portions and no counts:
#' septic_patients %>%
#' example_isolates %>%
#' select(AMX, NIT, FOS, TMP, CIP) %>%
#' ggplot_rsi(datalabels = FALSE)
#'
#' # add other ggplot2 parameters as you like:
#' septic_patients %>%
#' example_isolates %>%
#' select(AMX, NIT, FOS, TMP, CIP) %>%
#' ggplot_rsi(width = 0.5,
#' colour = "black",
@ -97,12 +97,12 @@
#' linetype = 2,
#' alpha = 0.25)
#'
#' septic_patients %>%
#' example_isolates %>%
#' select(AMX) %>%
#' ggplot_rsi(colours = c(SI = "yellow"))
#'
#' # resistance of ciprofloxacine per age group
#' septic_patients %>%
#' example_isolates %>%
#' mutate(first_isolate = first_isolate(.)) %>%
#' filter(first_isolate == TRUE,
#' mo == as.mo("E. coli")) %>%
@ -114,17 +114,17 @@
#' \donttest{
#'
#' # for colourblind mode, use divergent colours from the viridis package:
#' septic_patients %>%
#' example_isolates %>%
#' select(AMX, NIT, FOS, TMP, CIP) %>%
#' ggplot_rsi() + scale_fill_viridis_d()
#' # a shorter version which also adjusts data label colours:
#' septic_patients %>%
#' example_isolates %>%
#' select(AMX, NIT, FOS, TMP, CIP) %>%
#' ggplot_rsi(colours = FALSE)
#'
#'
#' # it also supports groups (don't forget to use the group var on `x` or `facet`):
#' septic_patients %>%
#' example_isolates %>%
#' select(hospital_id, AMX, NIT, FOS, TMP, CIP) %>%
#' group_by(hospital_id) %>%
#' ggplot_rsi(x = "hospital_id",
@ -135,7 +135,7 @@
#' datalabels = FALSE)
#'
#' # genuine analysis: check 3 most prevalent microorganisms
#' septic_patients %>%
#' example_isolates %>%
#' # create new bacterial ID's, with all CoNS under the same group (Becker et al.)
#' mutate(mo = as.mo(mo, Becker = TRUE)) %>%
#' # filter on top three bacterial ID's

View File

@ -129,7 +129,7 @@ get_column_abx <- function(x,
names(x) <- df_trans$abcode
# add from self-defined dots (...):
# get_column_abx(septic_patients %>% rename(thisone = AMX), amox = "thisone")
# get_column_abx(example_isolates %>% rename(thisone = AMX), amox = "thisone")
dots <- list(...)
if (length(dots) > 0) {
newnames <- suppressWarnings(as.ab(names(dots)))

View File

@ -37,7 +37,7 @@
#' left_join_microorganisms("B_KLBSL_PNE")
#'
#' library(dplyr)
#' septic_patients %>% left_join_microorganisms()
#' example_isolates %>% left_join_microorganisms()
#'
#' df <- data.frame(date = seq(from = as.Date("2018-01-01"),
#' to = as.Date("2018-01-07"),

View File

@ -48,12 +48,12 @@
#' @seealso \code{\link{first_isolate}}
#' @inheritSection AMR Read more on our website!
#' @examples
#' # `septic_patients` is a dataset available in the AMR package. It is true, genuine data.
#' # See ?septic_patients.
#' # `example_isolates` is a dataset available in the AMR package.
#' # See ?example_isolates.
#'
#' library(dplyr)
#' # set key antibiotics to a new variable
#' my_patients <- septic_patients %>%
#' my_patients <- example_isolates %>%
#' mutate(keyab = key_antibiotics(.)) %>%
#' mutate(
#' # now calculate first isolates

View File

@ -49,7 +49,7 @@
#' # get frequencies of bacteria whose name start with 'Ent' or 'ent'
#' library(dplyr)
#' library(clean)
#' septic_patients %>%
#' example_isolates %>%
#' left_join_microorganisms() %>%
#' filter(genus %like% '^ent') %>%
#' freq(genus, species)

View File

@ -54,7 +54,7 @@
#' @examples
#' library(dplyr)
#'
#' septic_patients %>%
#' example_isolates %>%
#' mutate(EUCAST = mdro(.),
#' BRMO = brmo(.))
mdro <- function(x,

View File

@ -86,31 +86,31 @@
#' @export
#' @inheritSection AMR Read more on our website!
#' @examples
#' # septic_patients is a data set available in the AMR package. It is true, genuine data.
#' ?septic_patients
#' # example_isolates is a data set available in the AMR package.
#' ?example_isolates
#'
#' # Calculate resistance
#' portion_R(septic_patients$AMX)
#' portion_IR(septic_patients$AMX)
#' portion_R(example_isolates$AMX)
#' portion_IR(example_isolates$AMX)
#'
#' # Or susceptibility
#' portion_S(septic_patients$AMX)
#' portion_SI(septic_patients$AMX)
#' portion_S(example_isolates$AMX)
#' portion_SI(example_isolates$AMX)
#'
#' # Do the above with pipes:
#' library(dplyr)
#' septic_patients %>% portion_R(AMX)
#' septic_patients %>% portion_IR(AMX)
#' septic_patients %>% portion_S(AMX)
#' septic_patients %>% portion_SI(AMX)
#' example_isolates %>% portion_R(AMX)
#' example_isolates %>% portion_IR(AMX)
#' example_isolates %>% portion_S(AMX)
#' example_isolates %>% portion_SI(AMX)
#'
#' septic_patients %>%
#' example_isolates %>%
#' group_by(hospital_id) %>%
#' summarise(p = portion_SI(CIP),
#' n = n_rsi(CIP)) # n_rsi works like n_distinct in dplyr
#'
#' septic_patients %>%
#' example_isolates %>%
#' group_by(hospital_id) %>%
#' summarise(R = portion_R(CIP, as_percent = TRUE),
#' I = portion_I(CIP, as_percent = TRUE),
@ -121,24 +121,24 @@
#'
#' # Calculate co-resistance between amoxicillin/clav acid and gentamicin,
#' # so we can see that combination therapy does a lot more than mono therapy:
#' septic_patients %>% portion_SI(AMC) # %SI = 76.3%
#' septic_patients %>% count_all(AMC) # n = 1879
#' example_isolates %>% portion_SI(AMC) # %SI = 76.3%
#' example_isolates %>% count_all(AMC) # n = 1879
#'
#' septic_patients %>% portion_SI(GEN) # %SI = 75.4%
#' septic_patients %>% count_all(GEN) # n = 1855
#' example_isolates %>% portion_SI(GEN) # %SI = 75.4%
#' example_isolates %>% count_all(GEN) # n = 1855
#'
#' septic_patients %>% portion_SI(AMC, GEN) # %SI = 94.1%
#' septic_patients %>% count_all(AMC, GEN) # n = 1939
#' example_isolates %>% portion_SI(AMC, GEN) # %SI = 94.1%
#' example_isolates %>% count_all(AMC, GEN) # n = 1939
#'
#'
#' # See Details on how `only_all_tested` works. Example:
#' septic_patients %>%
#' example_isolates %>%
#' summarise(numerator = count_SI(AMC, GEN),
#' denominator = count_all(AMC, GEN),
#' portion = portion_SI(AMC, GEN))
#' # numerator denominator portion
#' # 1764 1936 0.9408
#' septic_patients %>%
#' example_isolates %>%
#' summarise(numerator = count_SI(AMC, GEN, only_all_tested = TRUE),
#' denominator = count_all(AMC, GEN, only_all_tested = TRUE),
#' portion = portion_SI(AMC, GEN, only_all_tested = TRUE))
@ -146,7 +146,7 @@
#' # 1687 1798 0.9383
#'
#'
#' septic_patients %>%
#' example_isolates %>%
#' group_by(hospital_id) %>%
#' summarise(cipro_p = portion_SI(CIP, as_percent = TRUE),
#' cipro_n = count_all(CIP),
@ -156,12 +156,12 @@
#' combination_n = count_all(CIP, GEN))
#'
#' # Get portions S/I/R immediately of all rsi columns
#' septic_patients %>%
#' example_isolates %>%
#' select(AMX, CIP) %>%
#' portion_df(translate = FALSE)
#'
#' # It also supports grouping variables
#' septic_patients %>%
#' example_isolates %>%
#' select(hospital_id, AMX, CIP) %>%
#' group_by(hospital_id) %>%
#' portion_df(translate = FALSE)

View File

@ -61,13 +61,13 @@
#' @importFrom dplyr %>% pull mutate mutate_at n group_by_at summarise filter filter_at all_vars n_distinct arrange case_when n_groups transmute ungroup
#' @inheritSection AMR Read more on our website!
#' @examples
#' x <- resistance_predict(septic_patients, col_ab = "AMX", year_min = 2010, model = "binomial")
#' x <- resistance_predict(example_isolates, col_ab = "AMX", year_min = 2010, model = "binomial")
#' plot(x)
#' ggplot_rsi_predict(x)
#'
#' # use dplyr so you can actually read it:
#' library(dplyr)
#' x <- septic_patients %>%
#' x <- example_isolates %>%
#' filter_first_isolate() %>%
#' filter(mo_genus(mo) == "Staphylococcus") %>%
#' resistance_predict("PEN", model = "binomial")
@ -82,7 +82,7 @@
#' # create nice plots with ggplot2 yourself
#' if (!require(ggplot2)) {
#'
#' data <- septic_patients %>%
#' data <- example_isolates %>%
#' filter(mo == as.mo("E. coli")) %>%
#' resistance_predict(col_ab = "AMX",
#' col_date = "date",

View File

@ -79,12 +79,12 @@
#'
#' # using dplyr's mutate
#' library(dplyr)
#' septic_patients %>%
#' example_isolates %>%
#' mutate_at(vars(PEN:RIF), as.rsi)
#'
#'
#' # fastest way to transform all columns with already valid AB results to class `rsi`:
#' septic_patients %>%
#' example_isolates %>%
#' mutate_if(is.rsi.eligible,
#' as.rsi)
#'

View File

@ -67,11 +67,11 @@ rsi_calc <- function(...,
if ("data.frame" %in% class(dots_df)) {
# data.frame passed with other columns, like:
# septic_patients %>% portion_S(amcl, gent)
# example_isolates %>% portion_S(amcl, gent)
dots <- as.character(dots)
dots <- dots[dots != "."]
if (length(dots) == 0 | all(dots == "df")) {
# for complete data.frames, like septic_patients %>% select(amcl, gent) %>% portion_S()
# for complete data.frames, like example_isolates %>% select(amcl, gent) %>% portion_S()
# and the old rsi function, that has "df" as name of the first parameter
x <- dots_df
} else {
@ -79,16 +79,16 @@ rsi_calc <- function(...,
}
} else if (ndots == 1) {
# only 1 variable passed (can also be data.frame), like:
# portion_S(septic_patients$amcl)
# septic_patients$amcl %>% portion_S()
# portion_S(example_isolates$amcl)
# example_isolates$amcl %>% portion_S()
x <- dots_df
} else {
# multiple variables passed without pipe, like:
# portion_S(septic_patients$amcl, septic_patients$gent)
# portion_S(example_isolates$amcl, example_isolates$gent)
x <- NULL
try(x <- as.data.frame(dots), silent = TRUE)
if (is.null(x)) {
# support for: with(septic_patients, portion_S(amcl, gent))
# support for: with(example_isolates, portion_S(amcl, gent))
x <- as.data.frame(rlang::list2(...))
}
}