mirror of
https://github.com/msberends/AMR.git
synced 2025-07-10 12:21:53 +02:00
new antibiotics
This commit is contained in:
55
R/count.R
55
R/count.R
@ -44,55 +44,55 @@
|
||||
#' ?septic_patients
|
||||
#'
|
||||
#' # Count resistant isolates
|
||||
#' count_R(septic_patients$amox)
|
||||
#' count_IR(septic_patients$amox)
|
||||
#' count_R(septic_patients$AMX)
|
||||
#' count_IR(septic_patients$AMX)
|
||||
#'
|
||||
#' # Or susceptible isolates
|
||||
#' count_S(septic_patients$amox)
|
||||
#' count_SI(septic_patients$amox)
|
||||
#' count_S(septic_patients$AMX)
|
||||
#' count_SI(septic_patients$AMX)
|
||||
#'
|
||||
#' # Count all available isolates
|
||||
#' count_all(septic_patients$amox)
|
||||
#' n_rsi(septic_patients$amox)
|
||||
#' count_all(septic_patients$AMX)
|
||||
#' n_rsi(septic_patients$AMX)
|
||||
#'
|
||||
#' # Since n_rsi counts available isolates, you can
|
||||
#' # calculate back to count e.g. non-susceptible isolates.
|
||||
#' # This results in the same:
|
||||
#' count_IR(septic_patients$amox)
|
||||
#' portion_IR(septic_patients$amox) * n_rsi(septic_patients$amox)
|
||||
#' count_IR(septic_patients$AMX)
|
||||
#' portion_IR(septic_patients$AMX) * n_rsi(septic_patients$AMX)
|
||||
#'
|
||||
#' library(dplyr)
|
||||
#' septic_patients %>%
|
||||
#' group_by(hospital_id) %>%
|
||||
#' summarise(R = count_R(cipr),
|
||||
#' I = count_I(cipr),
|
||||
#' S = count_S(cipr),
|
||||
#' n1 = count_all(cipr), # the actual total; sum of all three
|
||||
#' n2 = n_rsi(cipr), # same - analogous to n_distinct
|
||||
#' summarise(R = count_R(CIP),
|
||||
#' I = count_I(CIP),
|
||||
#' S = count_S(CIP),
|
||||
#' n1 = count_all(CIP), # the actual total; sum of all three
|
||||
#' n2 = n_rsi(CIP), # same - analogous to n_distinct
|
||||
#' total = n()) # NOT the number of tested isolates!
|
||||
#'
|
||||
#' # 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_S` calculates percentages right away instead.
|
||||
#' count_S(septic_patients$amcl) # S = 1342 (71.4%)
|
||||
#' count_all(septic_patients$amcl) # n = 1879
|
||||
#' count_S(septic_patients$AMC) # S = 1342 (71.4%)
|
||||
#' count_all(septic_patients$AMC) # n = 1879
|
||||
#'
|
||||
#' count_S(septic_patients$gent) # S = 1372 (74.0%)
|
||||
#' count_all(septic_patients$gent) # n = 1855
|
||||
#' count_S(septic_patients$GEN) # S = 1372 (74.0%)
|
||||
#' count_all(septic_patients$GEN) # n = 1855
|
||||
#'
|
||||
#' with(septic_patients,
|
||||
#' count_S(amcl, gent)) # S = 1660 (92.3%)
|
||||
#' count_S(AMC, GEN)) # S = 1660 (92.3%)
|
||||
#' with(septic_patients, # n = 1798
|
||||
#' n_rsi(amcl, gent))
|
||||
#' n_rsi(AMC, GEN))
|
||||
#'
|
||||
#' # Get portions S/I/R immediately of all rsi columns
|
||||
#' septic_patients %>%
|
||||
#' select(amox, cipr) %>%
|
||||
#' select(AMX, CIP) %>%
|
||||
#' count_df(translate = FALSE)
|
||||
#'
|
||||
#' # It also supports grouping variables
|
||||
#' septic_patients %>%
|
||||
#' select(hospital_id, amox, cipr) %>%
|
||||
#' select(hospital_id, AMX, CIP) %>%
|
||||
#' group_by(hospital_id) %>%
|
||||
#' count_df(translate = FALSE)
|
||||
#'
|
||||
@ -172,7 +172,8 @@ n_rsi <- function(...) {
|
||||
#' @importFrom dplyr %>% select_if bind_rows summarise_if mutate group_vars select everything
|
||||
#' @export
|
||||
count_df <- function(data,
|
||||
translate_ab = getOption("get_antibiotic_names", "official"),
|
||||
translate_ab = "name",
|
||||
language = get_locale(),
|
||||
combine_IR = FALSE) {
|
||||
|
||||
if (!"data.frame" %in% class(data)) {
|
||||
@ -183,10 +184,9 @@ count_df <- function(data,
|
||||
stop("No columns with class 'rsi' found. See ?as.rsi.")
|
||||
}
|
||||
|
||||
if (as.character(translate_ab) == "TRUE") {
|
||||
translate_ab <- "official"
|
||||
if (as.character(translate_ab) %in% c("TRUE", "official")) {
|
||||
translate_ab <- "name"
|
||||
}
|
||||
options(get_antibiotic_names = translate_ab)
|
||||
|
||||
resS <- summarise_if(.tbl = data,
|
||||
.predicate = is.rsi,
|
||||
@ -227,10 +227,7 @@ count_df <- function(data,
|
||||
}
|
||||
|
||||
if (!translate_ab == FALSE) {
|
||||
if (!tolower(translate_ab) %in% tolower(colnames(AMR::antibiotics))) {
|
||||
stop("Parameter `translate_ab` does not occur in the `antibiotics` data set.", call. = FALSE)
|
||||
}
|
||||
res <- res %>% mutate(Antibiotic = abname(Antibiotic, from = "guess", to = translate_ab))
|
||||
res <- res %>% mutate(Antibiotic = ab_property(Antibiotic, property = translate_ab, language = language))
|
||||
}
|
||||
|
||||
res
|
||||
|
Reference in New Issue
Block a user