diff --git a/DESCRIPTION b/DESCRIPTION index b3b7fa32..98f08d0f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: AMR -Version: 0.8.0.9026 +Version: 0.8.0.9027 Date: 2019-11-10 Title: Antimicrobial Resistance Analysis Authors@R: c( diff --git a/NAMESPACE b/NAMESPACE index 55f6f52e..9e49e241 100755 --- a/NAMESPACE +++ b/NAMESPACE @@ -74,7 +74,6 @@ export(age) export(age_groups) export(anti_join_microorganisms) export(as.ab) -export(as.atc) export(as.disk) export(as.mic) export(as.mo) @@ -94,6 +93,8 @@ export(count_S) export(count_SI) export(count_all) export(count_df) +export(count_resistant) +export(count_susceptible) export(eucast_exceptional_phenotypes) export(eucast_rules) export(facet_rsi) @@ -172,8 +173,14 @@ export(portion_IR) export(portion_R) export(portion_S) export(portion_SI) -export(portion_df) +export(proportion_I) +export(proportion_IR) +export(proportion_R) +export(proportion_S) +export(proportion_SI) +export(proportion_df) export(read.4D) +export(resistance) export(resistance_predict) export(right_join_microorganisms) export(rsi_df) @@ -185,6 +192,7 @@ export(scale_y_percent) export(semi_join_microorganisms) export(set_mo_source) export(skewness) +export(susceptibility) export(theme_rsi) exportMethods("[.ab") exportMethods("[.mo") diff --git a/NEWS.md b/NEWS.md index 23aeff92..1da4a29d 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,17 +1,20 @@ -# AMR 0.8.0.9026 +# AMR 0.8.0.9027 Last updated: 10-Nov-2019 ### New +* Functions `susceptibility()` and `resistance()` as aliases of `proportion_SI()` and `proportion_R()`, respectively. These functions were added to make it more clear that I should be considered susceptible and not resistant. * 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). * This is now the new default guideline for the `mdro()` function * The new Verbose mode (`mdro(...., verbose = TRUE)`) returns an informative data set where the reason for MDRO determination is given for every isolate, and an list of the resistant antimicrobial agents ### Changes +* Removed previously deprecated function `as.rsi()` - this function was replaced by `ab_atc()` +* Renamed all `portion_*` functions to `proportion_*`. All `portion_*` functions are still available as deprecated functions, and will return a warning when used. * When running `as.rsi()` over a data set, it will now print the guideline that will be used if it is not specified by the user * Fix for `eucast_rules()`: *Stenotrophomonas maltophilia* not interpreted "R" to ceftazidime anymore (following EUCAST v3.1) * Adopted Adeolu *et al.* (2016), [PMID 27620848](https://www.ncbi.nlm.nih.gov/pubmed/27620848) for the `microorganisms` data set, which means that the new order Enterobacterales now consists of a part of the existing family *Enterobacteriaceae*, but that this family has been split into other families as well (like *Morganellaceae* and *Yersiniaceae*). Although published in 2016, this information is not yet in the Catalogue of Life version of 2019. All MDRO determinations with `mdro()` will now use the Enterobacterales order for all guidelines before 2016. * Fix for interpreting MIC values with `as.rsi()` where the input is `NA` -* Added "imi" as allowed abbreviation for Imipenem +* Added "imi" and "imp" as allowed abbreviation for Imipenem (IPM) * Fix for automatically determining columns with antibiotic results in `mdro()` and `eucast_rules()` * Added ATC codes for ceftaroline, ceftobiprole and faropenem and fixed two typos in the `antibiotics` data set * More robust way of determining valid MIC values diff --git a/R/amr.R b/R/amr.R index 17f8a0b6..6913002c 100644 --- a/R/amr.R +++ b/R/amr.R @@ -29,28 +29,20 @@ #' #' This package can be used for: #' \itemize{ -#' \item{Reference for microorganisms, since it contains all microbial (sub)species from the Catalogue of Life} +#' \item{Reference for the taxonomy of microorganisms, since the package contains all microbial (sub)species from the Catalogue of Life} #' \item{Interpreting raw MIC and disk diffusion values, based on the latest CLSI or EUCAST guidelines} +#' \item{Determining first isolates to be used for AMR analysis} #' \item{Calculating antimicrobial resistance} #' \item{Determining multi-drug resistance (MDR) / multi-drug resistant organisms (MDRO)} -#' \item{Calculating empirical susceptibility of both mono therapy and combination therapy} +#' \item{Calculating (empirical) susceptibility of both mono therapy and combination therapies} #' \item{Predicting future antimicrobial resistance using regression models} #' \item{Getting properties for any microorganism (like Gram stain, species, genus or family)} -#' \item{Getting properties for any antibiotic (like name, ATC code, defined daily dose or trade name)} +#' \item{Getting properties for any antibiotic (like name, EARS-Net code, ATC code, PubChem code, defined daily dose or trade name)} #' \item{Plotting antimicrobial resistance} -#' \item{Determining first isolates to be used for AMR analysis} #' \item{Applying EUCAST expert rules} -#' \item{Descriptive statistics: frequency tables, kurtosis and skewness} #' } -#' @section Authors: -#' Matthijs S. Berends[1,2] Christian F. Luz[1], Erwin E.A. Hassing[2], Corinna Glasner[1], Alex W. Friedrich[1], Bhanu N.M. Sinha[1] \cr -#' -#' [1] Department of Medical Microbiology, University of Groningen, University Medical Center Groningen, Groningen, the Netherlands - \url{https://www.rug.nl} \url{https://www.umcg.nl} \cr -#' [2] Certe Medical Diagnostics & Advice, Groningen, the Netherlands - \url{https://www.certe.nl} - #' @section Read more on our website!: #' On our website \url{https://msberends.gitlab.io/AMR} you can find \href{https://msberends.gitlab.io/AMR/articles/AMR.html}{a tutorial} about how to conduct AMR analysis, the \href{https://msberends.gitlab.io/AMR/reference}{complete documentation of all functions} (which reads a lot easier than here in R) and \href{https://msberends.gitlab.io/AMR/articles/WHONET.html}{an example analysis using WHONET data}. - #' @section Contact us: #' For suggestions, comments or questions, please contact us at: #' diff --git a/R/availability.R b/R/availability.R index 95fb0fcf..5fe4c018 100644 --- a/R/availability.R +++ b/R/availability.R @@ -21,10 +21,10 @@ #' Check availability of columns #' -#' Easy check for availability of columns in a data set. This makes it easy to get an idea of which antimicrobial combination can be used for calculation with e.g. \code{\link{portion_R}}. +#' Easy check for availability of columns in a data set. This makes it easy to get an idea of which antimicrobial combination can be used for calculation with e.g. \code{\link{resistance}}. #' @param tbl a \code{data.frame} or \code{list} #' @param width number of characters to present the visual availability, defaults to filling the width of the console -#' @details The function returns a \code{data.frame} with columns \code{"resistant"} and \code{"visual_resistance"}. The values in that columns are calculated with \code{\link{portion_R}}. +#' @details The function returns a \code{data.frame} with columns \code{"resistant"} and \code{"visual_resistance"}. The values in that columns are calculated with \code{\link{resistance}}. #' @return \code{data.frame} with column names of \code{tbl} as row names #' @inheritSection AMR Read more on our website! #' @importFrom cleaner percentage @@ -48,7 +48,7 @@ availability <- function(tbl, width = NULL) { 1 - base::sum(base::is.na(x)) / base::length(x) }) n <- base::sapply(tbl, function(x) base::length(x[!base::is.na(x)])) - R <- base::sapply(tbl, function(x) base::ifelse(is.rsi(x), portion_R(x, minimum = 0), NA)) + R <- base::sapply(tbl, function(x) base::ifelse(is.rsi(x), resistance(x, minimum = 0), NA)) R_print <- character(length(R)) R_print[!is.na(R)] <- percentage(R[!is.na(R)]) R_print[is.na(R)] <- "" diff --git a/R/count.R b/R/count.R index 8d6b0ff1..299c8bfc 100755 --- a/R/count.R +++ b/R/count.R @@ -23,20 +23,19 @@ #' #' @description These functions can be used to count resistant/susceptible microbial isolates. All functions support quasiquotation with pipes, can be used in \code{dplyr}s \code{\link[dplyr]{summarise}} and support grouped variables, see \emph{Examples}. #' -#' \code{count_R} and \code{count_IR} can be used to count resistant isolates, \code{count_S} and \code{count_SI} can be used to count susceptible isolates.\cr +#' \code{count_resistant} should be used to count resistant isolates, \code{count_susceptible} should be used to count susceptible isolates.\cr #' @param ... one or more vectors (or columns) with antibiotic interpretations. They will be transformed internally with \code{\link{as.rsi}} if needed. -#' @inheritParams portion +#' @inheritParams proportion #' @inheritSection as.rsi Interpretation of S, I and R -#' @details These functions are meant to count isolates. Use the \code{\link{portion}_*} functions to calculate microbial resistance. +#' @details These functions are meant to count isolates. Use the \code{\link{resistance}}/\code{\link{susceptibility}} functions to calculate microbial resistance/susceptibility. +#' +#' The function \code{count_resistant} is equal to the function \code{count_R}. The function \code{count_susceptible} is equal to the function \code{count_SI}. #' -#' The function \code{n_rsi} is an alias of \code{count_all}. They can be used to count all available isolates, i.e. where all input antibiotics have an available result (S, I or R). Their use is equal to \code{\link{n_distinct}}. Their function is equal to \code{count_S(...) + count_IR(...)}. +#' The function \code{n_rsi} is an alias of \code{count_all}. They can be used to count all available isolates, i.e. where all input antibiotics have an available result (S, I or R). Their use is equal to \code{\link{n_distinct}}. Their function is equal to \code{count_susceptible(...) + count_resistant(...)}. #' -#' The function \code{count_df} takes any variable from \code{data} that has an \code{"rsi"} class (created with \code{\link{as.rsi}}) and counts the amounts of S, I and R. The resulting \emph{tidy data} (see Source) \code{data.frame} will have three rows (S/I/R) and a column for each variable with class \code{"rsi"}. -#' -#' The function \code{rsi_df} works exactly like \code{count_df}, but adds the percentage of S, I and R. -#' @inheritSection portion Combination therapy -#' @source Wickham H. \strong{Tidy Data.} The Journal of Statistical Software, vol. 59, 2014. \url{http://vita.had.co.nz/papers/tidy-data.html} -#' @seealso \code{\link{portion}_*} to calculate microbial resistance and susceptibility. +#' The function \code{count_df} takes any variable from \code{data} that has an \code{"rsi"} class (created with \code{\link{as.rsi}}) and counts the number of S's, I's and R's. The function \code{rsi_df} works exactly like \code{count_df}, but adds the percentage of S, I and R. +#' @inheritSection proportion Combination therapy +#' @seealso \code{\link{proportion}_*} to calculate microbial resistance and susceptibility. #' @return Integer #' @rdname count #' @name count @@ -45,24 +44,28 @@ #' @examples #' # example_isolates is a data set available in the AMR package. #' ?example_isolates +#' +#' count_resistant(example_isolates$AMX) # counts "R" +#' count_susceptible(example_isolates$AMX) # counts "S" and "I" +#' count_all(example_isolates$AMX) # counts "S", "I" and "R" #' -#' # Count resistant isolates -#' count_R(example_isolates$AMX) -#' count_IR(example_isolates$AMX) -#' -#' # Or susceptible isolates +#' # be more specific #' count_S(example_isolates$AMX) #' count_SI(example_isolates$AMX) +#' count_I(example_isolates$AMX) +#' count_IR(example_isolates$AMX) +#' count_R(example_isolates$AMX) #' #' # Count all available isolates #' 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(example_isolates$AMX) -#' portion_SI(example_isolates$AMX) * n_rsi(example_isolates$AMX) +#' # n_rsi() is an alias of count_all(). +#' # Since it counts all available isolates, you can +#' # calculate back to count e.g. susceptible isolates. +#' # These results are the same: +#' count_susceptible(example_isolates$AMX) +#' susceptibility(example_isolates$AMX) * n_rsi(example_isolates$AMX) #' #' library(dplyr) #' example_isolates %>% @@ -76,19 +79,17 @@ #' #' # 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(example_isolates$AMC) # 1433 -#' count_all(example_isolates$AMC) # 1879 +#' # Please mind that `susceptibility()` calculates percentages right away instead. +#' example_isolates %>% count_susceptible(AMC) # 1433 +#' example_isolates %>% count_all(AMC) # 1879 #' -#' count_SI(example_isolates$GEN) # 1399 -#' count_all(example_isolates$GEN) # 1855 +#' example_isolates %>% count_susceptible(GEN) # 1399 +#' example_isolates %>% count_all(GEN) # 1855 #' -#' with(example_isolates, -#' count_SI(AMC, GEN)) # 1764 -#' with(example_isolates, -#' n_rsi(AMC, GEN)) # 1936 -#' -#' # Get portions S/I/R immediately of all rsi columns +#' example_isolates %>% count_susceptible(AMC, GEN) # 1764 +#' example_isolates %>% count_all(AMC, GEN) # 1936 + +#' # Get number of S+I vs. R immediately of selected columns #' example_isolates %>% #' select(AMX, CIP) %>% #' count_df(translate = FALSE) @@ -99,6 +100,24 @@ #' group_by(hospital_id) %>% #' count_df(translate = FALSE) #' +count_resistant <- function(..., only_all_tested = FALSE) { + rsi_calc(..., + ab_result = "R", + only_all_tested = only_all_tested, + only_count = TRUE) +} + +#' @rdname count +#' @export +count_susceptible <- function(..., only_all_tested = FALSE) { + rsi_calc(..., + ab_result = c("S", "I"), + only_all_tested = only_all_tested, + only_count = TRUE) +} + +#' @rdname count +#' @export count_R <- function(..., only_all_tested = FALSE) { rsi_calc(..., ab_result = "R", @@ -109,6 +128,7 @@ count_R <- function(..., only_all_tested = FALSE) { #' @rdname count #' @export count_IR <- function(..., only_all_tested = FALSE) { + warning("Using 'count_IR' is discouraged; use 'count_resistant()' instead to not consider \"I\" being resistant.", call. = FALSE) rsi_calc(..., ab_result = c("I", "R"), only_all_tested = only_all_tested, @@ -136,6 +156,7 @@ count_SI <- function(..., only_all_tested = FALSE) { #' @rdname count #' @export count_S <- function(..., only_all_tested = FALSE) { + warning("Using 'count_S' is discouraged; use 'count_susceptible()' instead to also consider \"I\" being susceptible.", call. = FALSE) rsi_calc(..., ab_result = "S", only_all_tested = only_all_tested, diff --git a/R/deprecated.R b/R/deprecated.R index 8a2f34de..cd4c625b 100755 --- a/R/deprecated.R +++ b/R/deprecated.R @@ -27,14 +27,42 @@ #' @keywords internal #' @name AMR-deprecated #' @rdname AMR-deprecated -as.atc <- function(x) { - .Deprecated("ab_atc", package = "AMR") - AMR::ab_atc(x) -} - -#' @rdname AMR-deprecated -#' @export p.symbol <- function(...) { .Deprecated("p_symbol", package = "AMR") AMR::p_symbol(...) } + +#' @rdname AMR-deprecated +#' @export +portion_R <- function(...) { + .Deprecated("resistance", package = "AMR") + proportion_R(...) +} + +#' @rdname AMR-deprecated +#' @export +portion_IR <- function(...) { + .Deprecated("proportion_IR", package = "AMR") + proportion_IR(...) +} + +#' @rdname AMR-deprecated +#' @export +portion_I <- function(...) { + .Deprecated("proportion_I", package = "AMR") + proportion_I(...) +} + +#' @rdname AMR-deprecated +#' @export +portion_SI <- function(...) { + .Deprecated("susceptibility", package = "AMR") + proportion_SI(...) +} + +#' @rdname AMR-deprecated +#' @export +portion_S <- function(...) { + .Deprecated("proportion_S", package = "AMR") + proportion_S(...) +} diff --git a/R/freq.R b/R/freq.R index ebba431d..b7c49fcc 100755 --- a/R/freq.R +++ b/R/freq.R @@ -63,9 +63,9 @@ freq.rsi <- function(x, ...) { freq.default(x = x, ..., .add_header = list(Drug = paste0(ab_name(ab), " (", ab, ", ", ab_atc(ab), ")"), group = ab_group(ab), - `%SI` = AMR::portion_SI(x, minimum = 0, as_percent = TRUE))) + `%SI` = AMR::susceptibility(x, minimum = 0, as_percent = TRUE))) } else { freq.default(x = x, ..., - .add_header = list(`%SI` = AMR::portion_SI(x, minimum = 0, as_percent = TRUE))) + .add_header = list(`%SI` = AMR::susceptibility(x, minimum = 0, as_percent = TRUE))) } } diff --git a/R/ggplot_rsi.R b/R/ggplot_rsi.R index 9e64bfa1..62eb7074 100755 --- a/R/ggplot_rsi.R +++ b/R/ggplot_rsi.R @@ -23,13 +23,13 @@ #' #' Use these functions to create bar plots for antimicrobial resistance analysis. All functions rely on internal \code{\link[ggplot2]{ggplot}2} functions. #' @param data a \code{data.frame} with column(s) of class \code{"rsi"} (see \code{\link{as.rsi}}) -#' @param position position adjustment of bars, either \code{"fill"} (default when \code{fun} is \code{\link{count_df}}), \code{"stack"} (default when \code{fun} is \code{\link{portion_df}}) or \code{"dodge"} +#' @param position position adjustment of bars, either \code{"fill"}, \code{"stack"} or \code{"dodge"} #' @param x variable to show on x axis, either \code{"antibiotic"} (default) or \code{"interpretation"} or a grouping variable #' @param fill variable to categorise using the plots legend, either \code{"antibiotic"} (default) or \code{"interpretation"} or a grouping variable #' @param breaks numeric vector of positions #' @param limits numeric vector of length two providing limits of the scale, use \code{NA} to refer to the existing minimum or maximum #' @param facet variable to split plots by, either \code{"interpretation"} (default) or \code{"antibiotic"} or a grouping variable -#' @inheritParams portion +#' @inheritParams proportion #' @param nrow (when using \code{facet}) number of rows #' @param colours a named vector with colours for the bars. The names must be one or more of: S, SI, I, IR, R or be \code{FALSE} to use default \code{ggplot2} colours. #' @param datalabels show datalabels using \code{labels_rsi_count} @@ -82,7 +82,7 @@ #' select(AMX, NIT, FOS, TMP, CIP) %>% #' ggplot_rsi() #' -#' # get only portions and no counts: +#' # get only proportions and no counts: #' example_isolates %>% #' select(AMX, NIT, FOS, TMP, CIP) %>% #' ggplot_rsi(datalabels = FALSE) @@ -229,7 +229,7 @@ ggplot_rsi <- function(data, } if (identical(position, "fill")) { - # portions, so use y scale with percentage + # proportions, so use y scale with percentage p <- p + scale_y_percent(breaks = breaks, limits = limits) } diff --git a/R/portion.R b/R/proportion.R similarity index 63% rename from R/portion.R rename to R/proportion.R index 5c52a26c..d7a639a2 100755 --- a/R/portion.R +++ b/R/proportion.R @@ -19,11 +19,11 @@ # Visit our website for more info: https://msberends.gitlab.io/AMR. # # ==================================================================== # -#' Calculate resistance of isolates +#' Calculate microbial resistance #' -#' @description These functions can be used to calculate the (co-)resistance of microbial isolates (i.e. percentage of S, SI, I, IR or R). All functions support quasiquotation with pipes, can be used in \code{dplyr}s \code{\link[dplyr]{summarise}} and support grouped variables, see \emph{Examples}. +#' @description These functions can be used to calculate the (co-)resistance or susceptibility of microbial isolates (i.e. percentage of S, SI, I, IR or R). All functions support quasiquotation with pipes, can be used in \code{dplyr}s \code{\link[dplyr]{summarise}} and support grouped variables, see \emph{Examples}. #' -#' \code{portion_R} and \code{portion_IR} can be used to calculate resistance, \code{portion_S} and \code{portion_SI} can be used to calculate susceptibility.\cr +#' \code{resistance} should be used to calculate resistance, \code{susceptibility} should be used to calculate susceptibility.\cr #' @param ... one or more vectors (or columns) with antibiotic interpretations. They will be transformed internally with \code{\link{as.rsi}} if needed. Use multiple columns to calculate (the lack of) co-resistance: the probability where one of two drugs have a resistant or susceptible result. See Examples. #' @param minimum the minimum allowed number of available (tested) isolates. Any isolate count lower than \code{minimum} will return \code{NA} with a warning. The default number of \code{30} isolates is advised by the Clinical and Laboratory Standards Institute (CLSI) as best practice, see Source. #' @param as_percent a logical to indicate whether the output must be returned as a hundred fold with \% sign (a character). A value of \code{0.123456} will then be returned as \code{"12.3\%"}. @@ -34,15 +34,16 @@ #' @param combine_SI a logical to indicate whether all values of S and I must be merged into one, so the output only consists of S+I vs. R (susceptible vs. resistant). This used to be the parameter \code{combine_IR}, but this now follows the redefinition by EUCAST about the interpretion of I (increased exposure) in 2019, see section 'Interpretation of S, I and R' below. Default is \code{TRUE}. #' @param combine_IR a logical to indicate whether all values of I and R must be merged into one, so the output only consists of S vs. I+R (susceptible vs. non-susceptible). This is outdated, see parameter \code{combine_SI}. #' @inheritSection as.rsi Interpretation of S, I and R -#' @details \strong{Remember that you should filter your table to let it contain only first isolates!} This is needed to exclude duplicates and to reduce selection bias. Use \code{\link{first_isolate}} to determine them in your data set. +#' @details +#' The function \code{resistance} is equal to the function \code{proportion_R}. The function \code{susceptibility} is equal to the function \code{proportion_SI}. +#' +#' \strong{Remember that you should filter your table to let it contain only first isolates!} This is needed to exclude duplicates and to reduce selection bias. Use \code{\link{first_isolate}} to determine them in your data set. #' -#' These functions are not meant to count isolates, but to calculate the portion of resistance/susceptibility. Use the \code{\link[AMR]{count}} functions to count isolates. The function \code{portion_SI()} is essentially equal to \code{count_SI() / count_all()}. \emph{Low counts can infuence the outcome - the \code{portion} functions may camouflage this, since they only return the portion (albeit being dependent on the \code{minimum} parameter).} +#' These functions are not meant to count isolates, but to calculate the proportion of resistance/susceptibility. Use the \code{\link[AMR]{count}} functions to count isolates. The function \code{susceptibility()} is essentially equal to \code{count_susceptible() / count_all()}. \emph{Low counts can infuence the outcome - the \code{proportion} functions may camouflage this, since they only return the proportion (albeit being dependent on the \code{minimum} parameter).} #' -#' The function \code{portion_df} takes any variable from \code{data} that has an \code{"rsi"} class (created with \code{\link{as.rsi}}) and calculates the portions R, I and S. The resulting \emph{tidy data} (see Source) \code{data.frame} will have three rows (S/I/R) and a column for each group and each variable with class \code{"rsi"}. -#' -#' The function \code{rsi_df} works exactly like \code{portion_df}, but adds the number of isolates. +#' The function \code{proportion_df} takes any variable from \code{data} that has an \code{"rsi"} class (created with \code{\link{as.rsi}}) and calculates the proportions R, I and S. The function \code{rsi_df} works exactly like \code{proportion_df}, but adds the number of isolates. #' @section Combination therapy: -#' When using more than one variable for \code{...} (= combination therapy)), use \code{only_all_tested} to only count isolates that are tested for all antibiotics/variables that you test them for. See this example for two antibiotics, Antibiotic A and Antibiotic B, about how \code{portion_SI} works to calculate the \%SI: +#' When using more than one variable for \code{...} (= combination therapy)), use \code{only_all_tested} to only count isolates that are tested for all antibiotics/variables that you test them for. See this example for two antibiotics, Antibiotic A and Antibiotic B, about how \code{susceptibility} works to calculate the \%SI: #' #' \preformatted{ #' -------------------------------------------------------------------- @@ -65,105 +66,96 @@ #' #' Please note that, in combination therapies, for \code{only_all_tested = TRUE} applies that: #' \preformatted{ -#' count_S() + count_I() + count_R() == count_all() -#' portion_S() + portion_I() + portion_R() == 1 +#' count_S() + count_I() + count_R() = count_all() +#' proportion_S() + proportion_I() + proportion_R() = 1 #' } #' and that, in combination therapies, for \code{only_all_tested = FALSE} applies that: #' \preformatted{ -#' count_S() + count_I() + count_R() >= count_all() -#' portion_S() + portion_I() + portion_R() >= 1 +#' count_S() + count_I() + count_R() >= count_all() +#' proportion_S() + proportion_I() + proportion_R() >= 1 #' } #' #' Using \code{only_all_tested} has no impact when only using one antibiotic as input. #' @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/}. -#' -#' Wickham H. \strong{Tidy Data.} The Journal of Statistical Software, vol. 59, 2014. \url{http://vita.had.co.nz/papers/tidy-data.html} #' @seealso \code{\link[AMR]{count}_*} to count resistant and susceptible isolates. #' @return Double or, when \code{as_percent = TRUE}, a character. -#' @rdname portion -#' @name portion +#' @rdname proportion +#' @aliases portion +#' @name proportion #' @export #' @inheritSection AMR Read more on our website! #' @examples #' # example_isolates is a data set available in the AMR package. #' ?example_isolates +#' +#' resistance(example_isolates$AMX) # determines %R +#' susceptibility(example_isolates$AMX) # determines %S+I #' -#' # Calculate resistance -#' portion_R(example_isolates$AMX) -#' portion_IR(example_isolates$AMX) +#' # be more specific +#' proportion_S(example_isolates$AMX) +#' proportion_SI(example_isolates$AMX) +#' proportion_I(example_isolates$AMX) +#' proportion_IR(example_isolates$AMX) +#' proportion_R(example_isolates$AMX) #' -#' # Or susceptibility -#' portion_S(example_isolates$AMX) -#' portion_SI(example_isolates$AMX) -#' - -#' # Do the above with pipes: #' library(dplyr) -#' example_isolates %>% portion_R(AMX) -#' example_isolates %>% portion_IR(AMX) -#' example_isolates %>% portion_S(AMX) -#' example_isolates %>% portion_SI(AMX) +#' example_isolates %>% +#' group_by(hospital_id) %>% +#' summarise(r = resistance(CIP), +#' n = n_rsi(CIP)) # n_rsi works like n_distinct in dplyr, see ?n_rsi #' #' example_isolates %>% #' group_by(hospital_id) %>% -#' summarise(p = portion_SI(CIP), -#' n = n_rsi(CIP)) # n_rsi works like n_distinct in dplyr -#' -#' example_isolates %>% -#' group_by(hospital_id) %>% -#' summarise(R = portion_R(CIP, as_percent = TRUE), -#' I = portion_I(CIP, as_percent = TRUE), -#' S = portion_S(CIP, as_percent = TRUE), +#' summarise(R = resistance(CIP, as_percent = TRUE), +#' SI = susceptibility(CIP, as_percent = TRUE), #' 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! #' #' # Calculate co-resistance between amoxicillin/clav acid and gentamicin, #' # so we can see that combination therapy does a lot more than mono therapy: -#' example_isolates %>% portion_SI(AMC) # %SI = 76.3% +#' example_isolates %>% susceptibility(AMC) # %SI = 76.3% #' example_isolates %>% count_all(AMC) # n = 1879 #' -#' example_isolates %>% portion_SI(GEN) # %SI = 75.4% +#' example_isolates %>% susceptibility(GEN) # %SI = 75.4% #' example_isolates %>% count_all(GEN) # n = 1855 #' -#' example_isolates %>% portion_SI(AMC, GEN) # %SI = 94.1% -#' example_isolates %>% count_all(AMC, GEN) # n = 1939 +#' example_isolates %>% susceptibility(AMC, GEN) # %SI = 94.1% +#' example_isolates %>% count_all(AMC, GEN) # n = 1939 #' #' #' # See Details on how `only_all_tested` works. Example: #' example_isolates %>% -#' summarise(numerator = count_SI(AMC, GEN), +#' summarise(numerator = count_susceptible(AMC, GEN), #' denominator = count_all(AMC, GEN), -#' portion = portion_SI(AMC, GEN)) -#' # numerator denominator portion -#' # 1764 1936 0.9408 +#' proportion = susceptibility(AMC, GEN)) + #' example_isolates %>% -#' summarise(numerator = count_SI(AMC, GEN, only_all_tested = TRUE), +#' summarise(numerator = count_susceptible(AMC, GEN, only_all_tested = TRUE), #' denominator = count_all(AMC, GEN, only_all_tested = TRUE), -#' portion = portion_SI(AMC, GEN, only_all_tested = TRUE)) -#' # numerator denominator portion -#' # 1687 1798 0.9383 +#' proportion = susceptibility(AMC, GEN, only_all_tested = TRUE)) + #' #' #' example_isolates %>% #' group_by(hospital_id) %>% -#' summarise(cipro_p = portion_SI(CIP, as_percent = TRUE), +#' summarise(cipro_p = susceptibility(CIP, as_percent = TRUE), #' cipro_n = count_all(CIP), -#' genta_p = portion_SI(GEN, as_percent = TRUE), +#' genta_p = susceptibility(GEN, as_percent = TRUE), #' genta_n = count_all(GEN), -#' combination_p = portion_SI(CIP, GEN, as_percent = TRUE), +#' combination_p = susceptibility(CIP, GEN, as_percent = TRUE), #' combination_n = count_all(CIP, GEN)) #' -#' # Get portions S/I/R immediately of all rsi columns +#' # Get proportions S/I/R immediately of all rsi columns #' example_isolates %>% #' select(AMX, CIP) %>% -#' portion_df(translate = FALSE) +#' proportion_df(translate = FALSE) #' #' # It also supports grouping variables #' example_isolates %>% #' select(hospital_id, AMX, CIP) %>% #' group_by(hospital_id) %>% -#' portion_df(translate = FALSE) +#' proportion_df(translate = FALSE) #' #' #' \dontrun{ @@ -172,13 +164,13 @@ #' my_table %>% #' filter(first_isolate == TRUE, #' genus == "Helicobacter") %>% -#' summarise(p = portion_S(AMX, MTR), # amoxicillin with metronidazole +#' summarise(p = susceptibility(AMX, MTR), # amoxicillin with metronidazole #' n = count_all(AMX, MTR)) #' } -portion_R <- function(..., - minimum = 30, - as_percent = FALSE, - only_all_tested = FALSE) { +resistance <- function(..., + minimum = 30, + as_percent = FALSE, + only_all_tested = FALSE) { rsi_calc(..., ab_result = "R", minimum = minimum, @@ -187,40 +179,12 @@ portion_R <- function(..., only_count = FALSE) } -#' @rdname portion +#' @rdname proportion #' @export -portion_IR <- function(..., - minimum = 30, - as_percent = FALSE, - only_all_tested = FALSE) { - rsi_calc(..., - ab_result = c("I", "R"), - minimum = minimum, - as_percent = as_percent, - only_all_tested = only_all_tested, - only_count = FALSE) -} - -#' @rdname portion -#' @export -portion_I <- function(..., - minimum = 30, - as_percent = FALSE, - only_all_tested = FALSE) { - rsi_calc(..., - ab_result = "I", - minimum = minimum, - as_percent = as_percent, - only_all_tested = only_all_tested, - only_count = FALSE) -} - -#' @rdname portion -#' @export -portion_SI <- function(..., - minimum = 30, - as_percent = FALSE, - only_all_tested = FALSE) { +susceptibility <- function(..., + minimum = 30, + as_percent = FALSE, + only_all_tested = FALSE) { rsi_calc(..., ab_result = c("S", "I"), minimum = minimum, @@ -229,12 +193,68 @@ portion_SI <- function(..., only_count = FALSE) } -#' @rdname portion +#' @rdname proportion #' @export -portion_S <- function(..., - minimum = 30, - as_percent = FALSE, - only_all_tested = FALSE) { +proportion_R <- function(..., + minimum = 30, + as_percent = FALSE, + only_all_tested = FALSE) { + rsi_calc(..., + ab_result = "R", + minimum = minimum, + as_percent = as_percent, + only_all_tested = only_all_tested, + only_count = FALSE) +} + +#' @rdname proportion +#' @export +proportion_IR <- function(..., + minimum = 30, + as_percent = FALSE, + only_all_tested = FALSE) { + rsi_calc(..., + ab_result = c("I", "R"), + minimum = minimum, + as_percent = as_percent, + only_all_tested = only_all_tested, + only_count = FALSE) +} + +#' @rdname proportion +#' @export +proportion_I <- function(..., + minimum = 30, + as_percent = FALSE, + only_all_tested = FALSE) { + rsi_calc(..., + ab_result = "I", + minimum = minimum, + as_percent = as_percent, + only_all_tested = only_all_tested, + only_count = FALSE) +} + +#' @rdname proportion +#' @export +proportion_SI <- function(..., + minimum = 30, + as_percent = FALSE, + only_all_tested = FALSE) { + rsi_calc(..., + ab_result = c("S", "I"), + minimum = minimum, + as_percent = as_percent, + only_all_tested = only_all_tested, + only_count = FALSE) +} + +#' @rdname proportion +#' @export +proportion_S <- function(..., + minimum = 30, + as_percent = FALSE, + only_all_tested = FALSE) { rsi_calc(..., ab_result = "S", minimum = minimum, @@ -243,18 +263,18 @@ portion_S <- function(..., only_count = FALSE) } -#' @rdname portion +#' @rdname proportion #' @importFrom dplyr %>% select_if bind_rows summarise_if mutate group_vars select everything #' @export -portion_df <- function(data, - translate_ab = "name", - language = get_locale(), - minimum = 30, - as_percent = FALSE, - combine_SI = TRUE, - combine_IR = FALSE) { - - rsi_calc_df(type = "portion", +proportion_df <- function(data, + translate_ab = "name", + language = get_locale(), + minimum = 30, + as_percent = FALSE, + combine_SI = TRUE, + combine_IR = FALSE) { + + rsi_calc_df(type = "proportion", data = data, translate_ab = translate_ab, language = language, diff --git a/R/rsi.R b/R/rsi.R index 1cd4286e..98150360 100755 --- a/R/rsi.R +++ b/R/rsi.R @@ -46,7 +46,7 @@ #' #' Exposure is a function of how the mode of administration, dose, dosing interval, infusion time, as well as distribution and excretion of the antimicrobial agent will influence the infecting organism at the site of infection. #' -#' This AMR package honours this new insight. Use \code{\link{portion_SI}} to determine antimicrobial susceptibility and \code{\link{count_SI}} to count susceptible isolates. +#' This AMR package honours this new insight. Use \code{\link{susceptibility}} (equal to \code{\link{proportion_SI}}) to determine antimicrobial susceptibility and \code{\link{count_susceptible}} (equal to \code{\link{count_SI}}) to count susceptible isolates. #' @return Ordered factor with new class \code{rsi} #' @aliases RSI #' @export diff --git a/R/rsi_calc.R b/R/rsi_calc.R index 8f6c2df7..46750806 100755 --- a/R/rsi_calc.R +++ b/R/rsi_calc.R @@ -22,7 +22,7 @@ #' @importFrom rlang enquos as_label dots2vars <- function(...) { # this function is to give more informative output about - # variable names in count_* and portion_* functions + # variable names in count_* and proportion_* functions paste( unlist( lapply(enquos(...), @@ -46,9 +46,9 @@ rsi_calc <- function(..., as_percent = FALSE, only_all_tested = FALSE, only_count = FALSE) { - + data_vars <- dots2vars(...) - + if (!is.numeric(minimum)) { stop("`minimum` must be numeric", call. = FALSE) } @@ -58,47 +58,47 @@ rsi_calc <- function(..., if (!is.logical(only_all_tested)) { stop("`only_all_tested` must be logical", call. = FALSE) } - + dots_df <- ...elt(1) # it needs this evaluation dots <- base::eval(base::substitute(base::alist(...))) if ("also_single_tested" %in% names(dots)) { - stop("`also_single_tested` was replaced by `only_all_tested`. Please read Details in the help page (`?portion`) as this may have a considerable impact on your analysis.", call. = FALSE) + stop("`also_single_tested` was replaced by `only_all_tested`. Please read Details in the help page (`?proportion`) as this may have a considerable impact on your analysis.", call. = FALSE) } ndots <- length(dots) - - if ("data.frame" %in% class(dots_df)) { - # data.frame passed with other columns, like: example_isolates %>% portion_S(amcl, gent) - dots <- as.character(dots) - dots <- dots[dots != "."] + + if ("data.frame" %in% class(dots_df)) { + # data.frame passed with other columns, like: example_isolates %>% proportion_S(amcl, gent) + dots <- as.character(dots) + dots <- dots[dots != "."] if (length(dots) == 0 | all(dots == "df")) { - # for complete data.frames, like example_isolates %>% select(amcl, gent) %>% portion_S() + # for complete data.frames, like example_isolates %>% select(amcl, gent) %>% proportion_S() # and the old rsi function, that has "df" as name of the first parameter x <- dots_df } else { x <- dots_df[, dots] } } else if (ndots == 1) { - # only 1 variable passed (can also be data.frame), like: portion_S(example_isolates$amcl) and example_isolates$amcl %>% portion_S() + # only 1 variable passed (can also be data.frame), like: proportion_S(example_isolates$amcl) and example_isolates$amcl %>% proportion_S() x <- dots_df } else { - # multiple variables passed without pipe, like: portion_S(example_isolates$amcl, example_isolates$gent) + # multiple variables passed without pipe, like: proportion_S(example_isolates$amcl, example_isolates$gent) x <- NULL try(x <- as.data.frame(dots), silent = TRUE) if (is.null(x)) { - # support for: with(example_isolates, portion_S(amcl, gent)) + # support for: with(example_isolates, proportion_S(amcl, gent)) x <- as.data.frame(rlang::list2(...)) } } - + if (is.null(x)) { warning("argument is NULL (check if columns exist): returning NA", call. = FALSE) return(NA) } - + print_warning <- FALSE - + ab_result <- as.rsi(ab_result) - + if (is.data.frame(x)) { rsi_integrity_check <- character(0) for (i in seq_len(ncol(x))) { @@ -113,7 +113,7 @@ rsi_calc <- function(..., # this will give a warning for invalid results, of all input columns (so only 1 warning) rsi_integrity_check <- as.rsi(rsi_integrity_check) } - + if (only_all_tested == TRUE) { # THE NUMBER OF ISOLATES WHERE *ALL* ABx ARE S/I/R x <- apply(X = x %>% mutate_all(as.integer), @@ -140,16 +140,16 @@ rsi_calc <- function(..., numerator <- sum(x %in% ab_result, na.rm = TRUE) denominator <- sum(x %in% levels(ab_result), na.rm = TRUE) } - + if (print_warning == TRUE) { warning("Increase speed by transforming to class `rsi` on beforehand: df %>% mutate_if(is.rsi.eligible, as.rsi)", call. = FALSE) } - + if (only_count == TRUE) { return(numerator) } - + if (denominator < minimum) { if (data_vars != "") { data_vars <- paste(" for", data_vars) @@ -159,7 +159,7 @@ rsi_calc <- function(..., } else { fraction <- numerator / denominator } - + if (as_percent == TRUE) { percentage(fraction, digits = 1) } else { @@ -169,7 +169,7 @@ rsi_calc <- function(..., #' @importFrom dplyr %>% summarise_if mutate select everything bind_rows #' @importFrom tidyr gather -rsi_calc_df <- function(type, # "portion" or "count" +rsi_calc_df <- function(type, # "proportion" or "count" data, translate_ab = "name", language = get_locale(), @@ -178,79 +178,81 @@ rsi_calc_df <- function(type, # "portion" or "count" combine_SI = TRUE, combine_IR = FALSE, combine_SI_missing = FALSE) { - + if (!"data.frame" %in% class(data)) { stop(paste0("`", type, "_df` must be called on a data.frame"), call. = FALSE) } - + if (isTRUE(combine_IR) & isTRUE(combine_SI_missing)) { combine_SI <- FALSE } if (isTRUE(combine_SI) & isTRUE(combine_IR)) { stop("either `combine_SI` or `combine_IR` can be TRUE, not both", call. = FALSE) } - + if (!any(sapply(data, is.rsi), na.rm = TRUE)) { stop("No columns with class 'rsi' found. See ?as.rsi.", call. = FALSE) } - + if (as.character(translate_ab) %in% c("TRUE", "official")) { translate_ab <- "name" } - + get_summaryfunction <- function(int, type) { - # look for portion_S, count_S, etc: + # look for proportion_S, count_S, etc: int_fn <- get(paste0(type, "_", int), envir = asNamespace("AMR")) - - if (type == "portion") { - summ <- summarise_if(.tbl = data, - .predicate = is.rsi, - .funs = int_fn, - minimum = minimum, - as_percent = as_percent) - } else if (type == "count") { - summ <- summarise_if(.tbl = data, - .predicate = is.rsi, - .funs = int_fn) - } + + suppressWarnings( + if (type == "proportion") { + summ <- summarise_if(.tbl = data, + .predicate = is.rsi, + .funs = int_fn, + minimum = minimum, + as_percent = as_percent) + } else if (type == "count") { + summ <- summarise_if(.tbl = data, + .predicate = is.rsi, + .funs = int_fn) + } + ) summ %>% mutate(interpretation = int) %>% select(interpretation, everything()) } - + resS <- get_summaryfunction("S", type) resI <- get_summaryfunction("I", type) resR <- get_summaryfunction("R", type) resSI <- get_summaryfunction("SI", type) resIR <- get_summaryfunction("IR", type) data.groups <- group_vars(data) - + if (isFALSE(combine_SI) & isFALSE(combine_IR)) { res <- bind_rows(resS, resI, resR) %>% mutate(interpretation = factor(interpretation, levels = c("S", "I", "R"), ordered = TRUE)) - + } else if (isTRUE(combine_IR)) { res <- bind_rows(resS, resIR) %>% mutate(interpretation = factor(interpretation, levels = c("S", "IR"), ordered = TRUE)) - + } else if (isTRUE(combine_SI)) { res <- bind_rows(resSI, resR) %>% mutate(interpretation = factor(interpretation, levels = c("SI", "R"), ordered = TRUE)) } - + res <- res %>% gather(antibiotic, value, -interpretation, -data.groups) %>% select(antibiotic, everything()) - + if (!translate_ab == FALSE) { res <- res %>% mutate(antibiotic = AMR::ab_property(antibiotic, property = translate_ab, language = language)) } - + res } diff --git a/R/rsi_df.R b/R/rsi_df.R index 11520b0f..8cae673a 100644 --- a/R/rsi_df.R +++ b/R/rsi_df.R @@ -19,7 +19,7 @@ # Visit our website for more info: https://msberends.gitlab.io/AMR. # # ==================================================================== # -#' @rdname portion +#' @rdname proportion #' @rdname count #' @export rsi_df <- function(data, @@ -29,17 +29,17 @@ rsi_df <- function(data, as_percent = FALSE, combine_SI = TRUE, combine_IR = FALSE) { - - portions <- rsi_calc_df(type = "portion", - data = data, - translate_ab = translate_ab, - language = language, - minimum = minimum, - as_percent = as_percent, - combine_SI = combine_SI, - combine_IR = combine_IR, - combine_SI_missing = missing(combine_SI)) - + + proportions <- rsi_calc_df(type = "proportion", + data = data, + translate_ab = translate_ab, + language = language, + minimum = minimum, + as_percent = as_percent, + combine_SI = combine_SI, + combine_IR = combine_IR, + combine_SI_missing = missing(combine_SI)) + counts <- rsi_calc_df(type = "count", data = data, translate_ab = FALSE, @@ -49,9 +49,9 @@ rsi_df <- function(data, combine_SI = combine_SI, combine_IR = combine_IR, combine_SI_missing = missing(combine_SI)) - - data.frame(portions, + + data.frame(proportions, isolates = counts$value, stringsAsFactors = FALSE) - + } diff --git a/docs/404.html b/docs/404.html index 8a2fef72..85a60953 100644 --- a/docs/404.html +++ b/docs/404.html @@ -84,7 +84,7 @@ AMR (for R) - 0.8.0.9026 + 0.8.0.9027 diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index 8c17520a..ca0d66d8 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -84,7 +84,7 @@ AMR (for R) - 0.8.0.9026 + 0.8.0.9027 diff --git a/docs/articles/AMR.html b/docs/articles/AMR.html index a65f8394..79e9cad2 100644 --- a/docs/articles/AMR.html +++ b/docs/articles/AMR.html @@ -41,7 +41,7 @@ AMR (for R) - 0.8.0.9021 + 0.8.0.9027 @@ -187,7 +187,7 @@

How to conduct AMR analysis

Matthijs S. Berends

-

09 November 2019

+

10 November 2019

@@ -196,7 +196,7 @@ -

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 09 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 10 November 2019.

Introduction

@@ -212,21 +212,21 @@ -2019-11-09 +2019-11-10 abcd Escherichia coli S S -2019-11-09 +2019-11-10 abcd Escherichia coli S R -2019-11-09 +2019-11-10 efgh Escherichia coli R @@ -321,68 +321,68 @@ -2011-07-25 -L6 -Hospital D +2016-01-11 +N1 +Hospital C Staphylococcus aureus S -S R S -M - - -2015-11-29 -J1 -Hospital B -Klebsiella pneumoniae -S -S -R -S -M - - -2012-04-04 -C3 -Hospital B -Escherichia coli -R -S -S S M -2017-10-06 -W8 -Hospital B -Escherichia coli -S -S -S -S -F - - -2013-07-22 -Q6 +2010-12-17 +D2 Hospital D Escherichia coli -R +S +S +S +S +M + + +2016-07-05 +L5 +Hospital B +Escherichia coli +I I S S -F +M -2011-06-05 -W7 -Hospital B -Escherichia coli +2016-12-23 +C5 +Hospital A +Klebsiella pneumoniae R S +R S +M + + +2011-06-29 +F3 +Hospital A +Escherichia coli +R +R +R +R +M + + +2011-07-01 +N10 +Hospital A +Escherichia coli +R +R +R S F @@ -406,8 +406,8 @@ # # Item Count Percent Cum. Count Cum. Percent # --- ----- ------- -------- ----------- ------------- -# 1 M 10,398 51.99% 10,398 51.99% -# 2 F 9,602 48.01% 20,000 100.00% +# 1 M 10,264 51.32% 10,264 51.32% +# 2 F 9,736 48.68% 20,000 100.00%

So, we can draw at least two conclusions immediately. From a data scientists perspective, the data looks clean: only values M and F. From a researchers perspective: there are slightly more men. Nothing we didn’t already know.

The data is already quite clean, but we still need to transform some variables. The 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,452 values changed)
+# Streptococcus pneumoniae (1,477 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,294 values changed)
+# Table 01: Intrinsic resistance in Enterobacteriaceae (1,306 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,721 values changed)
+# Table 04: Intrinsic resistance in Gram-positive bacteria (2,791 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,24 +452,24 @@
 # Table 13: Interpretive rules for quinolones (no changes)
 # 
 # Other rules
-# Non-EUCAST: amoxicillin/clav acid = S where ampicillin = S (2,287 values changed)
-# Non-EUCAST: ampicillin = R where amoxicillin/clav acid = R (107 values changed)
+# Non-EUCAST: amoxicillin/clav acid = S where ampicillin = S (2,203 values changed)
+# Non-EUCAST: ampicillin = R where amoxicillin/clav acid = R (104 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,525 out of 20,000 rows, making a total of 7,861 edits
+# EUCAST rules affected 6,529 out of 20,000 rows, making a total of 7,881 edits
 # => added 0 test results
 # 
-# => changed 7,861 test results
-#    - 100 test results changed from S to I
-#    - 4,694 test results changed from S to R
-#    - 1,140 test results changed from I to S
-#    - 302 test results changed from I to R
-#    - 1,594 test results changed from R to S
-#    - 31 test results changed from R to I
+# => changed 7,881 test results
+#    - 102 test results changed from S to I
+#    - 4,800 test results changed from S to R
+#    - 1,035 test results changed from I to S
+#    - 291 test results changed from I to R
+#    - 1,625 test results changed from R to S
+#    - 28 test results changed from R to I
 # --------------------------------------------------------------------------
 # 
 # Use eucast_rules(..., verbose = TRUE) (on your original data) to get a data.frame with all specified edits instead.
@@ -497,7 +497,7 @@ # 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,670 first isolates (28.4% of total)
+# => Found 5,674 first isolates (28.4% of total)

So only 28.4% is suitable for resistance analysis! We can now filter on it with the filter() function, also from the dplyr package:

data_1st <- data %>% 
   filter(first == TRUE)
@@ -508,7 +508,7 @@

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 Y8, 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 S8, sorted on date:

@@ -524,10 +524,10 @@ - - + + - + @@ -535,10 +535,10 @@ - - + + - + @@ -546,32 +546,32 @@ - - + + - - + + - - + + - + - - + + - + @@ -579,8 +579,8 @@ - - + + @@ -590,32 +590,32 @@ - - + + - - - + + + - - + + - + - - + + - + @@ -623,18 +623,18 @@ - - + + - +
isolate
12010-04-05Y82010-01-27S8 B_ESCHR_COLIRS S S S
22010-04-09Y82010-06-01S8 B_ESCHR_COLIRS S S S
32010-04-14Y82010-09-13S8 B_ESCHR_COLISSII S S FALSE
42010-05-23Y82010-09-27S8 B_ESCHR_COLI S SSR S FALSE
52010-07-05Y82010-10-15S8 B_ESCHR_COLIRS S S S
62010-07-05Y82010-12-25S8 B_ESCHR_COLI R S
72010-07-10Y82011-02-06S8 B_ESCHR_COLISS R SFALSESSTRUE
82010-08-07Y82011-03-27S8 B_ESCHR_COLI RRS S S FALSE
92010-09-24Y82011-05-14S8 B_ESCHR_COLIRS S S S
102011-02-13Y82011-09-12S8 B_ESCHR_COLI S SRS S FALSE
-

Only 1 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.

+

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.

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(.)) %>% 
@@ -645,7 +645,7 @@
 # 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 15,079 first weighted isolates (75.4% of total)
+# => Found 15,253 first weighted isolates (76.3% of total)
@@ -662,10 +662,10 @@ - - + + - + @@ -674,10 +674,10 @@ - - + + - + @@ -686,34 +686,34 @@ - - + + + + + + + + + + + + + + - + - - - - - - - - - - - - - - + + - + @@ -722,46 +722,46 @@ - - + + - + - - + + - - - + + + - - + + - + - + - - + + - + @@ -770,23 +770,23 @@ - - + + - + - +
isolate
12010-04-05Y82010-01-27S8 B_ESCHR_COLIRS S S S
22010-04-09Y82010-06-01S8 B_ESCHR_COLIRS S S S
32010-04-14Y82010-09-13S8B_ESCHR_COLIIISSFALSEFALSE
42010-09-27S8 B_ESCHR_COLI S SSR S FALSE TRUE
42010-05-23Y8B_ESCHR_COLISSSSFALSEFALSE
52010-07-05Y82010-10-15S8 B_ESCHR_COLIRS S S S
62010-07-05Y82010-12-25S8 B_ESCHR_COLI R S S S FALSEFALSETRUE
72010-07-10Y82011-02-06S8 B_ESCHR_COLISS R SFALSESSTRUE TRUE
82010-08-07Y82011-03-27S8 B_ESCHR_COLI RRS S S FALSETRUEFALSE
92010-09-24Y82011-05-14S8 B_ESCHR_COLIRS S S S
102011-02-13Y82011-09-12S8 B_ESCHR_COLI S SRS S FALSETRUEFALSE
-

Instead of 1, now 7 isolates are flagged. In total, 75.4% of all isolates are marked ‘first weighted’ - 47.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, 76.3% of all isolates are marked ‘first weighted’ - 47.9% 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:

data_1st <- data %>% 
   filter_first_weighted_isolate()
-

So we end up with 15,079 isolates for analysis.

+

So we end up with 15,253 isolates for analysis.

We can remove unneeded columns:

data_1st <- data_1st %>% 
   select(-c(first, keyab))
@@ -811,29 +811,29 @@ -1 -2011-07-25 -L6 +2 +2010-12-17 +D2 Hospital D -B_STPHY_AURS +B_ESCHR_COLI +S S S -R S M -Gram-positive -Staphylococcus -aureus +Gram-negative +Escherichia +coli TRUE 3 -2012-04-04 -C3 +2016-07-05 +L5 Hospital B B_ESCHR_COLI -R -S +I +I S S M @@ -844,31 +844,31 @@ 4 -2017-10-06 -W8 -Hospital B -B_ESCHR_COLI +2016-12-23 +C5 +Hospital A +B_KLBSL_PNMN +R S +R S -S -S -F +M Gram-negative -Escherichia -coli +Klebsiella +pneumoniae TRUE 5 -2013-07-22 -Q6 -Hospital D +2011-06-29 +F3 +Hospital A B_ESCHR_COLI R -I -S -S -F +R +R +R +M Gram-negative Escherichia coli @@ -876,13 +876,13 @@ 6 -2011-06-05 -W7 -Hospital B +2011-07-01 +N10 +Hospital A B_ESCHR_COLI R -S -S +R +R S F Gram-negative @@ -891,19 +891,19 @@ TRUE -9 -2013-04-24 -D1 +8 +2010-01-02 +X9 Hospital B -B_STPHY_AURS +B_ESCHR_COLI S S S S -M -Gram-positive -Staphylococcus -aureus +F +Gram-negative +Escherichia +coli TRUE @@ -925,7 +925,7 @@
data_1st %>% freq(genus, species)

Frequency table

Class: character
-Length: 15,079 (of which NA: 0 = 0%)
+Length: 15,253 (of which NA: 0 = 0%)
Unique: 4

Shortest: 16
Longest: 24

@@ -942,33 +942,33 @@ Longest: 24

1 Escherichia coli -7,442 -49.35% -7,442 -49.35% +7,529 +49.36% +7,529 +49.36% 2 Staphylococcus aureus -3,732 -24.75% -11,174 -74.10% +3,765 +24.68% +11,294 +74.04% 3 Streptococcus pneumoniae -2,323 +2,350 15.41% -13,497 -89.51% +13,644 +89.45% 4 Klebsiella pneumoniae -1,582 -10.49% -15,079 +1,609 +10.55% +15,253 100.00% @@ -977,13 +977,14 @@ Longest: 24

Resistance percentages

-

The functions portion_S(), portion_SI(), portion_I(), portion_IR() and portion_R() can be used to determine the portion of a specific antimicrobial outcome. As per the EUCAST guideline of 2019, we calculate resistance as the portion of R (portion_R()) and susceptibility as the portion of S and I (portion_SI()). These functions can be used on their own:

-
data_1st %>% portion_R(AMX)
-# [1] 0.4668081
+

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:

+
data_1st %>% resistance(AMX)
+# [1] 0.4715794

Or can be used in conjuction with group_by() and summarise(), both from the dplyr package:

data_1st %>% 
   group_by(hospital) %>% 
-  summarise(amoxicillin = portion_R(AMX))
+ summarise(amoxicillin = resistance(AMX))
@@ -992,26 +993,26 @@ Longest: 24

- + - + - + - +
hospital
Hospital A0.46271980.4697103
Hospital B0.47452830.4727821
Hospital C0.47212690.4739112
Hospital D0.45497630.4705116

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_R(AMX),
+  summarise(amoxicillin = resistance(AMX),
             available = n_rsi(AMX))
@@ -1022,32 +1023,32 @@ Longest: 24

- - + + - - + + - - + + - - + +
Hospital A0.462719844930.46971034556
Hospital B0.474528353000.47278215309
Hospital C0.472126923320.47391122319
Hospital D0.454976329540.47051163069
-

These functions can also be used to get the portion of multiple antibiotics, to calculate empiric susceptibility of combination therapies very easily:

+

These functions can also be used to get the proportion of multiple antibiotics, to calculate empiric susceptibility of combination therapies very easily:

data_1st %>% 
   group_by(genus) %>% 
-  summarise(amoxiclav = portion_SI(AMC),
-            gentamicin = portion_SI(GEN),
-            amoxiclav_genta = portion_SI(AMC, GEN))
+ summarise(amoxiclav = susceptibility(AMC), + gentamicin = susceptibility(GEN), + amoxiclav_genta = susceptibility(AMC, GEN)) @@ -1058,36 +1059,36 @@ Longest: 24

- - - + + + - - - + + + - - - + + + - + - +
genus
Escherichia0.92502020.89720510.99650630.92469120.89188470.9929606
Klebsiella0.81605560.89823010.98419720.83095090.90304540.9869484
Staphylococcus0.92175780.91613080.99303320.93014610.91899070.9933599
Streptococcus0.61472230.6251064 0.00000000.61472230.6251064

To make a transition to the next part, let’s see how this difference could be plotted:

data_1st %>% 
   group_by(genus) %>% 
-  summarise("1. Amoxi/clav" = portion_SI(AMC),
-            "2. Gentamicin" = portion_SI(GEN),
-            "3. Amoxi/clav + genta" = portion_SI(AMC, GEN)) %>% 
+  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,
@@ -1111,7 +1112,7 @@ Longest: 24

# or as short as: ggplot(a_data_set) + geom_bar(aes(year))
-

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:

+

The AMR package contains functions to extend this ggplot2 package, for example geom_rsi(). It automatically transforms data with count_df() or proportion_df() and show results in stacked bars. Its simplest and shortest example:

ggplot(data_1st) +
   geom_rsi(translate_ab = FALSE)

diff --git a/docs/articles/AMR_files/figure-html/plot 1-1.png b/docs/articles/AMR_files/figure-html/plot 1-1.png index 5b35bfce..b7ee5fdd 100644 Binary files a/docs/articles/AMR_files/figure-html/plot 1-1.png and b/docs/articles/AMR_files/figure-html/plot 1-1.png differ diff --git a/docs/articles/AMR_files/figure-html/plot 3-1.png b/docs/articles/AMR_files/figure-html/plot 3-1.png index 2356f842..43e75147 100644 Binary files a/docs/articles/AMR_files/figure-html/plot 3-1.png and b/docs/articles/AMR_files/figure-html/plot 3-1.png differ diff --git a/docs/articles/AMR_files/figure-html/plot 4-1.png b/docs/articles/AMR_files/figure-html/plot 4-1.png index a932b081..45a315bd 100644 Binary files a/docs/articles/AMR_files/figure-html/plot 4-1.png and b/docs/articles/AMR_files/figure-html/plot 4-1.png differ diff --git a/docs/articles/AMR_files/figure-html/plot 5-1.png b/docs/articles/AMR_files/figure-html/plot 5-1.png index cebd646f..e7441b65 100644 Binary files a/docs/articles/AMR_files/figure-html/plot 5-1.png and b/docs/articles/AMR_files/figure-html/plot 5-1.png differ diff --git a/docs/articles/index.html b/docs/articles/index.html index d4d1e3c5..7e9ed2fe 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -84,7 +84,7 @@ AMR (for R) - 0.8.0.9026 + 0.8.0.9027 diff --git a/docs/authors.html b/docs/authors.html index ea336d91..a2bec599 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -84,7 +84,7 @@ AMR (for R) - 0.8.0.9026 + 0.8.0.9027 diff --git a/docs/index.html b/docs/index.html index 3ac548ef..fe629e9a 100644 --- a/docs/index.html +++ b/docs/index.html @@ -45,7 +45,7 @@ AMR (for R) - 0.8.0.9026 + 0.8.0.9027 @@ -338,7 +338,7 @@ A methods paper about this package has been preprinted at bioRxiv. It was update
  • It analyses the data with convenient functions that use well-known methods.

    diff --git a/docs/news/index.html b/docs/news/index.html index dde9f15c..75f45c41 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -84,7 +84,7 @@ AMR (for R) - 0.8.0.9026 + 0.8.0.9027 @@ -231,15 +231,16 @@ -
    +

    -AMR 0.8.0.9026 Unreleased +AMR 0.8.0.9027 Unreleased

    Last updated: 10-Nov-2019

    New

      +
    • Functions susceptibility() and resistance() as aliases of proportion_SI() and proportion_R(), respectively. These functions were added to make it more clear that I should be considered susceptible and not resistant.
    • 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).
      • This is now the new default guideline for the mdro() function
      • @@ -252,12 +253,15 @@

        Changes

          +
        • Removed previously deprecated function as.rsi() - this function was replaced by ab_atc() +
        • +
        • Renamed all portion_* functions to proportion_*. All portion_* functions are still available as deprecated functions, and will return a warning when used.
        • When running as.rsi() over a data set, it will now print the guideline that will be used if it is not specified by the user
        • Fix for eucast_rules(): Stenotrophomonas maltophilia not interpreted “R” to ceftazidime anymore (following EUCAST v3.1)
        • Adopted Adeolu et al. (2016), PMID 27620848 for the microorganisms data set, which means that the new order Enterobacterales now consists of a part of the existing family Enterobacteriaceae, but that this family has been split into other families as well (like Morganellaceae and Yersiniaceae). Although published in 2016, this information is not yet in the Catalogue of Life version of 2019. All MDRO determinations with mdro() will now use the Enterobacterales order for all guidelines before 2016.
        • Fix for interpreting MIC values with as.rsi() where the input is NA
        • -
        • Added “imi” as allowed abbreviation for Imipenem
        • +
        • Added “imi” and “imp” as allowed abbreviation for Imipenem (IPM)
        • Fix for automatically determining columns with antibiotic results in mdro() and eucast_rules()
        • Added ATC codes for ceftaroline, ceftobiprole and faropenem and fixed two typos in the antibiotics data set
        • @@ -392,7 +396,7 @@ Since this is a major change, usage of the old also_single_tested w
      • Improved the internal auto-guessing function for determining antimicrobials in your data set (AMR:::get_column_abx())
      • -
      • Removed class atc - using as.atc() is now deprecated in favour of ab_atc() and this will return a character, not the atc class anymore
      • +
      • Removed class atc - using as.atc() is now deprecated in favour of ab_atc() and this will return a character, not the atc class anymore
      • Removed deprecated functions abname(), ab_official(), atc_name(), atc_official(), atc_property(), atc_tradenames(), atc_trivial_nl()
      • Fix and speed improvement for mo_shortname() @@ -403,7 +407,7 @@ Since this is a major change, usage of the old also_single_tested w
      • The antibiotics data set is now sorted by name and all cephalosporins now have their generation between brackets
      • Speed improvement for guess_ab_col() which is now 30 times faster for antibiotic abbreviations
      • Improved filter_ab_class() to be more reliable and to support 5th generation cephalosporins
      • -
      • Function availability() now uses portion_R() instead of portion_IR(), to comply with EUCAST insights
      • +
      • Function availability() now uses portion_R() instead of portion_IR(), to comply with EUCAST insights
      • Functions age() and age_groups() now have a na.rm parameter to remove empty values
      • Renamed function p.symbol() to p_symbol() (the former is now deprecated and will be removed in a future version)
      • Using negative values for x in age_groups() will now introduce NAs and not return an error anymore
      • @@ -433,10 +437,10 @@ Since this is a major change, usage of the old also_single_tested w New
        • -

          Function rsi_df() to transform a data.frame to a data set containing only the microbial interpretation (S, I, R), the antibiotic, the percentage of S/I/R and the number of available isolates. This is a convenient combination of the existing functions count_df() and portion_df() to immediately show resistance percentages and number of available isolates:

          +

          Function rsi_df() to transform a data.frame to a data set containing only the microbial interpretation (S, I, R), the antibiotic, the percentage of S/I/R and the number of available isolates. This is a convenient combination of the existing functions count_df() and portion_df() to immediately show resistance percentages and number of available isolates:

          septic_patients %>%
             select(AMX, CIP) %>%
          -  rsi_df()
          +  rsi_df()
           #      antibiotic  interpretation      value  isolates
           # 1   Amoxicillin              SI  0.4442636       546
           # 2   Amoxicillin               R  0.5557364       683
          @@ -474,7 +478,7 @@ Since this is a major change, usage of the old also_single_tested w
           

          Changed

            -
          • Column names of output count_df() and portion_df() are now lowercase
          • +
          • Column names of output count_df() and portion_df() are now lowercase
          • Fixed bug in translation of microorganism names
          • Fixed bug in determining taxonomic kingdoms
          • Algorithm improvements for as.ab() and as.mo() to understand even more severely misspelled input
          • @@ -552,7 +556,7 @@ Please guess_ab_col()
          • Added ~5,000 more old taxonomic names to the microorganisms.old data set, which leads to better results finding when using the as.mo() function
          • -
          • This package now honours the new EUCAST insight (2019) that S and I are but classified as susceptible, where I is defined as ‘increased exposure’ and not ‘intermediate’ anymore. For functions like portion_df() and count_df() this means that their new parameter combine_SI is TRUE at default. Our plotting function ggplot_rsi() also reflects this change since it uses count_df() internally.
          • +
          • This package now honours the new EUCAST insight (2019) that S and I are but classified as susceptible, where I is defined as ‘increased exposure’ and not ‘intermediate’ anymore. For functions like portion_df() and count_df() this means that their new parameter combine_SI is TRUE at default. Our plotting function ggplot_rsi() also reflects this change since it uses count_df() internally.
          • The age() function gained a new parameter exact to determine ages with decimals
          • Removed deprecated functions guess_mo(), guess_atc(), EUCAST_rules(), interpretive_reading(), rsi()
          • @@ -681,7 +685,7 @@ This data is updated annually - check the included version with the new function ab_certe -> atc_certe() ab_umcg -> atc_umcg() ab_tradenames -> atc_tradenames()
          -These functions use as.atc() internally. The old atc_property has been renamed atc_online_property(). This is done for two reasons: firstly, not all ATC codes are of antibiotics (ab) but can also be of antivirals or antifungals. Secondly, the input must have class atc or must be coerable to this class. Properties of these classes should start with the same class name, analogous to as.mo() and e.g. mo_genus.
        • +These functions use as.atc() internally. The old atc_property has been renamed atc_online_property(). This is done for two reasons: firstly, not all ATC codes are of antibiotics (ab) but can also be of antivirals or antifungals. Secondly, the input must have class atc or must be coerable to this class. Properties of these classes should start with the same class name, analogous to as.mo() and e.g. mo_genus.
        • New functions set_mo_source() and get_mo_source() to use your own predefined MO codes as input for as.mo() and consequently all mo_* functions
        • Support for the upcoming dplyr version 0.8.0
        • New function guess_ab_col() to find an antibiotic column in a table
        • @@ -729,7 +733,7 @@ These functions use as.atc()Removed columns atc_group1_nl and atc_group2_nl from the antibiotics data set
        • Functions atc_ddd() and atc_groups() have been renamed atc_online_ddd() and atc_online_groups(). The old functions 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 guess_atc() is now deprecated in favour of as.atc() and will be removed in future versions
        • Improvements for as.mo():
          • @@ -900,7 +904,7 @@ Using as.mo(..., allow_uncertain = 3)
          • Added parameter combine_IR (TRUE/FALSE) to functions portion_df and count_df, to indicate that all values of I and R must be merged into one, so the output only consists of S vs. IR (susceptible vs. non-susceptible)
          • Fix for portion_*(..., as_percent = TRUE) when minimal number of isolates would not be met
          • -
          • Added parameter also_single_tested for portion_* and count_* functions to also include cases where not all antibiotics were tested but at least one of the tested antibiotics includes the target antimicribial interpretation, see ?portion +
          • Added parameter also_single_tested for portion_* and count_* functions to also include cases where not all antibiotics were tested but at least one of the tested antibiotics includes the target antimicribial interpretation, see ?portion
          • Using portion_* functions now throws a warning when total available isolate is below parameter minimum
          • @@ -1078,9 +1082,9 @@ Using as.mo(..., allow_uncertain = 3)# which is the same as: septic_patients %>% count_IR(amox, cipr) -septic_patients %>% portion_S(amcl) -septic_patients %>% portion_S(amcl, gent) -septic_patients %>% portion_S(amcl, gent, pita)
    +septic_patients %>% portion_S(amcl) +septic_patients %>% portion_S(amcl, gent) +septic_patients %>% portion_S(amcl, gent, pita)
  • Edited ggplot_rsi and geom_rsi so they can cope with count_df. The new fun parameter has value portion_df at default, but can be set to count_df.
  • Fix for ggplot_rsi when the ggplot2 package was not loaded
  • @@ -1333,7 +1337,7 @@ Using as.mo(..., allow_uncertain = 3)

    Contents

    Exposure is a function of how the mode of administration, dose, dosing interval, infusion time, as well as distribution and excretion of the antimicrobial agent will influence the infecting organism at the site of infection.

    -

    This AMR package honours this new insight. Use portion_SI to determine antimicrobial susceptibility and count_SI to count susceptible isolates.

    +

    This AMR package honours this new insight. Use susceptibility (equal to proportion_SI) to determine antimicrobial susceptibility and count_susceptible (equal to count_SI) to count susceptible isolates.

    Read more on our website!

    diff --git a/docs/reference/atc_online.html b/docs/reference/atc_online.html index 0b6f695b..ccf87195 100644 --- a/docs/reference/atc_online.html +++ b/docs/reference/atc_online.html @@ -85,7 +85,7 @@ AMR (for R) - 0.8.0 + 0.8.0.9027 diff --git a/docs/reference/availability.html b/docs/reference/availability.html index 1a5a9425..47b99a68 100644 --- a/docs/reference/availability.html +++ b/docs/reference/availability.html @@ -51,7 +51,7 @@ - + @@ -85,7 +85,7 @@ AMR (for R) - 0.8.0 + 0.8.0.9027 @@ -234,7 +234,7 @@
    -

    Easy check for availability of columns in a data set. This makes it easy to get an idea of which antimicrobial combination can be used for calculation with e.g. portion_R.

    +

    Easy check for availability of columns in a data set. This makes it easy to get an idea of which antimicrobial combination can be used for calculation with e.g. resistance.

    availability(tbl, width = NULL)
    @@ -257,7 +257,7 @@

    data.frame with column names of tbl as row names

    Details

    -

    The function returns a data.frame with columns "resistant" and "visual_resistance". The values in that columns are calculated with portion_R.

    +

    The function returns a data.frame with columns "resistant" and "visual_resistance". The values in that columns are calculated with resistance.

    Read more on our website!

    diff --git a/docs/reference/bug_drug_combinations.html b/docs/reference/bug_drug_combinations.html index 5f823b26..c55ecfc4 100644 --- a/docs/reference/bug_drug_combinations.html +++ b/docs/reference/bug_drug_combinations.html @@ -85,7 +85,7 @@ AMR (for R) - 0.8.0 + 0.8.0.9027 diff --git a/docs/reference/catalogue_of_life.html b/docs/reference/catalogue_of_life.html index 493cdae4..6bd0d959 100644 --- a/docs/reference/catalogue_of_life.html +++ b/docs/reference/catalogue_of_life.html @@ -85,7 +85,7 @@ AMR (for R) - 0.8.0 + 0.8.0.9027 diff --git a/docs/reference/catalogue_of_life_version.html b/docs/reference/catalogue_of_life_version.html index 72d886df..eea29753 100644 --- a/docs/reference/catalogue_of_life_version.html +++ b/docs/reference/catalogue_of_life_version.html @@ -85,7 +85,7 @@ AMR (for R) - 0.8.0.9021 + 0.8.0.9027 diff --git a/docs/reference/count.html b/docs/reference/count.html index 5ef02161..ff8a3cdd 100644 --- a/docs/reference/count.html +++ b/docs/reference/count.html @@ -52,7 +52,7 @@ +count_resistant should be used to count resistant isolates, count_susceptible should be used to count susceptible isolates." /> @@ -86,7 +86,7 @@ count_R and count_IR can be used to count resistant isolates, count_S and count_ AMR (for R) - 0.8.0.9021 + 0.8.0.9027 @@ -236,10 +236,14 @@ count_R and count_IR can be used to count resistant isolates, count_S and count_

    These functions can be used to count resistant/susceptible microbial isolates. All functions support quasiquotation with pipes, can be used in dplyrs summarise and support grouped variables, see Examples.

    -

    count_R and count_IR can be used to count resistant isolates, count_S and count_SI can be used to count susceptible isolates.

    +

    count_resistant should be used to count resistant isolates, count_susceptible should be used to count susceptible isolates.

    -
    count_R(..., only_all_tested = FALSE)
    +    
    count_resistant(..., only_all_tested = FALSE)
    +
    +count_susceptible(..., only_all_tested = FALSE)
    +
    +count_R(..., only_all_tested = FALSE)
     
     count_IR(..., only_all_tested = FALSE)
     
    @@ -289,18 +293,15 @@ count_R and count_IR can be used to count resistant isolates, count_S and count_
         
         
     
    -    

    Source

    - -

    Wickham H. Tidy Data. The Journal of Statistical Software, vol. 59, 2014. http://vita.had.co.nz/papers/tidy-data.html

    Value

    Integer

    Details

    -

    These functions are meant to count isolates. Use the portion_* functions to calculate microbial resistance.

    -

    The function n_rsi is an alias of count_all. They can be used to count all available isolates, i.e. where all input antibiotics have an available result (S, I or R). Their use is equal to n_distinct. Their function is equal to count_S(...) + count_IR(...).

    -

    The function count_df takes any variable from data that has an "rsi" class (created with as.rsi) and counts the amounts of S, I and R. The resulting tidy data (see Source) data.frame will have three rows (S/I/R) and a column for each variable with class "rsi".

    -

    The function rsi_df works exactly like count_df, but adds the percentage of S, I and R.

    +

    These functions are meant to count isolates. Use the resistance/susceptibility functions to calculate microbial resistance/susceptibility.

    +

    The function count_resistant is equal to the function count_R. The function count_susceptible is equal to the function count_SI.

    +

    The function n_rsi is an alias of count_all. They can be used to count all available isolates, i.e. where all input antibiotics have an available result (S, I or R). Their use is equal to n_distinct. Their function is equal to count_susceptible(...) + count_resistant(...).

    +

    The function count_df takes any variable from data that has an "rsi" class (created with as.rsi) and counts the number of S's, I's and R's. The function rsi_df works exactly like count_df, but adds the percentage of S, I and R.

    Interpretation of S, I and R

    @@ -313,12 +314,12 @@ count_R and count_IR can be used to count resistant isolates, count_S and count_

    Exposure is a function of how the mode of administration, dose, dosing interval, infusion time, as well as distribution and excretion of the antimicrobial agent will influence the infecting organism at the site of infection.

    -

    This AMR package honours this new insight. Use portion_SI to determine antimicrobial susceptibility and count_SI to count susceptible isolates.

    +

    This AMR package honours this new insight. Use susceptibility (equal to proportion_SI) to determine antimicrobial susceptibility and count_susceptible (equal to count_SI) to count susceptible isolates.

    Combination therapy

    -

    When using more than one variable for ... (= combination therapy)), use only_all_tested to only count isolates that are tested for all antibiotics/variables that you test them for. See this example for two antibiotics, Antibiotic A and Antibiotic B, about how portion_SI works to calculate the %SI:

    +

    When using more than one variable for ... (= combination therapy)), use only_all_tested to only count isolates that are tested for all antibiotics/variables that you test them for. See this example for two antibiotics, Antibiotic A and Antibiotic B, about how susceptibility works to calculate the %SI:

     --------------------------------------------------------------------
                         only_all_tested = FALSE  only_all_tested = TRUE
    @@ -339,11 +340,11 @@ count_R and count_IR can be used to count resistant isolates, count_S and count_
     

    Please note that, in combination therapies, for only_all_tested = TRUE applies that:

    -   count_S()  +  count_I()  +  count_R()  == count_all()
    -  portion_S() + portion_I() + portion_R() == 1
    +    count_S()    +   count_I()    +   count_R()    = count_all()
    +  proportion_S() + proportion_I() + proportion_R() = 1
     

    and that, in combination therapies, for only_all_tested = FALSE applies that:

    -   count_S()  +  count_I()  +  count_R()  >= count_all()
    -  portion_S() + portion_I() + portion_R() >= 1
    +    count_S()    +   count_I()    +   count_R()    >= count_all()
    +  proportion_S() + proportion_I() + proportion_R() >= 1
     

    Using only_all_tested has no impact when only using one antibiotic as input.

    @@ -354,29 +355,33 @@ count_R and count_IR can be used to count resistant isolates, count_S and count_

    On our website https://msberends.gitlab.io/AMR you can find a tutorial about how to conduct AMR analysis, the complete documentation of all functions (which reads a lot easier than here in R) and an example analysis using WHONET data.

    See also

    -

    portion_* to calculate microbial resistance and susceptibility.

    +

    proportion_* to calculate microbial resistance and susceptibility.

    Examples

    # example_isolates is a data set available in the AMR package.
     ?example_isolates
     
    -# Count resistant isolates
    -count_R(example_isolates$AMX)
    -count_IR(example_isolates$AMX)
    +count_resistant(example_isolates$AMX)   # counts "R"
    +count_susceptible(example_isolates$AMX) # counts "S" and "I"
    +count_all(example_isolates$AMX)         # counts "S", "I" and "R"
     
    -# Or susceptible isolates
    +# be more specific
     count_S(example_isolates$AMX)
     count_SI(example_isolates$AMX)
    +count_I(example_isolates$AMX)
    +count_IR(example_isolates$AMX)
    +count_R(example_isolates$AMX)
     
     # Count all available isolates
     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(example_isolates$AMX)
    -portion_SI(example_isolates$AMX) * n_rsi(example_isolates$AMX)
    +# n_rsi() is an alias of count_all().
    +# Since it counts all available isolates, you can
    +# calculate back to count e.g. susceptible isolates.
    +# These results are the same:
    +count_susceptible(example_isolates$AMX)
    +susceptibility(example_isolates$AMX) * n_rsi(example_isolates$AMX)
     
     library(dplyr)
     example_isolates %>%
    @@ -390,19 +395,16 @@ count_R and count_IR can be used to count resistant isolates, count_S and count_
     
     # 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(example_isolates$AMC)  # 1433
    -count_all(example_isolates$AMC) # 1879
    +# Please mind that `susceptibility()` calculates percentages right away instead.
    +example_isolates %>% count_susceptible(AMC) # 1433
    +example_isolates %>% count_all(AMC)         # 1879
     
    -count_SI(example_isolates$GEN)  # 1399
    -count_all(example_isolates$GEN) # 1855
    +example_isolates %>% count_susceptible(GEN) # 1399
    +example_isolates %>% count_all(GEN)         # 1855
     
    -with(example_isolates,
    -     count_SI(AMC, GEN))        # 1764
    -with(example_isolates,
    -     n_rsi(AMC, GEN))           # 1936
    -
    -# Get portions S/I/R immediately of all rsi columns
    +example_isolates %>% count_susceptible(AMC, GEN) # 1764
    +example_isolates %>% count_all(AMC, GEN)         # 1936
    +# Get number of S+I vs. R immediately of selected columns
     example_isolates %>%
       select(AMX, CIP) %>%
       count_df(translate = FALSE)
    @@ -417,7 +419,6 @@ count_R and count_IR can be used to count resistant isolates, count_S and count_
         

    Contents

    Exposure is a function of how the mode of administration, dose, dosing interval, infusion time, as well as distribution and excretion of the antimicrobial agent will influence the infecting organism at the site of infection.

    -

    This AMR package honours this new insight. Use portion_SI to determine antimicrobial susceptibility and count_SI to count susceptible isolates.

    +

    This AMR package honours this new insight. Use susceptibility (equal to proportion_SI) to determine antimicrobial susceptibility and count_susceptible (equal to count_SI) to count susceptible isolates.

    Read more on our website!

    diff --git a/docs/reference/microorganisms.codes.html b/docs/reference/microorganisms.codes.html index fcccc9e4..c335eb36 100644 --- a/docs/reference/microorganisms.codes.html +++ b/docs/reference/microorganisms.codes.html @@ -85,7 +85,7 @@ AMR (for R) - 0.8.0 + 0.8.0.9027 diff --git a/docs/reference/microorganisms.html b/docs/reference/microorganisms.html index 63a5032d..c9199617 100644 --- a/docs/reference/microorganisms.html +++ b/docs/reference/microorganisms.html @@ -85,7 +85,7 @@ AMR (for R) - 0.8.0.9008 + 0.8.0.9027 diff --git a/docs/reference/microorganisms.old.html b/docs/reference/microorganisms.old.html index 795758ab..8484316a 100644 --- a/docs/reference/microorganisms.old.html +++ b/docs/reference/microorganisms.old.html @@ -85,7 +85,7 @@ AMR (for R) - 0.8.0 + 0.8.0.9027 diff --git a/docs/reference/mo_property.html b/docs/reference/mo_property.html index 055ae38b..c8f4e454 100644 --- a/docs/reference/mo_property.html +++ b/docs/reference/mo_property.html @@ -85,7 +85,7 @@ AMR (for R) - 0.8.0.9008 + 0.8.0.9027 diff --git a/docs/reference/mo_source.html b/docs/reference/mo_source.html index 08710a68..f35068a4 100644 --- a/docs/reference/mo_source.html +++ b/docs/reference/mo_source.html @@ -86,7 +86,7 @@ This is the fastest way to have your organisation (or analysis) specific codes p AMR (for R) - 0.8.0 + 0.8.0.9027 diff --git a/docs/reference/p_symbol.html b/docs/reference/p_symbol.html index 2f57c88f..b4f99832 100644 --- a/docs/reference/p_symbol.html +++ b/docs/reference/p_symbol.html @@ -85,7 +85,7 @@ AMR (for R) - 0.8.0 + 0.8.0.9027 diff --git a/docs/reference/proportion.html b/docs/reference/proportion.html new file mode 100644 index 00000000..20daae60 --- /dev/null +++ b/docs/reference/proportion.html @@ -0,0 +1,514 @@ + + + + + + + + +Calculate microbial resistance — proportion • AMR (for R) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    These functions can be used to calculate the (co-)resistance or susceptibility of microbial isolates (i.e. percentage of S, SI, I, IR or R). All functions support quasiquotation with pipes, can be used in dplyrs summarise and support grouped variables, see Examples.

    +

    resistance should be used to calculate resistance, susceptibility should be used to calculate susceptibility.

    +
    + +
    resistance(..., minimum = 30, as_percent = FALSE,
    +  only_all_tested = FALSE)
    +
    +susceptibility(..., minimum = 30, as_percent = FALSE,
    +  only_all_tested = FALSE)
    +
    +proportion_R(..., minimum = 30, as_percent = FALSE,
    +  only_all_tested = FALSE)
    +
    +proportion_IR(..., minimum = 30, as_percent = FALSE,
    +  only_all_tested = FALSE)
    +
    +proportion_I(..., minimum = 30, as_percent = FALSE,
    +  only_all_tested = FALSE)
    +
    +proportion_SI(..., minimum = 30, as_percent = FALSE,
    +  only_all_tested = FALSE)
    +
    +proportion_S(..., minimum = 30, as_percent = FALSE,
    +  only_all_tested = FALSE)
    +
    +proportion_df(data, translate_ab = "name", language = get_locale(),
    +  minimum = 30, as_percent = FALSE, combine_SI = TRUE,
    +  combine_IR = FALSE)
    +
    +rsi_df(data, translate_ab = "name", language = get_locale(),
    +  minimum = 30, as_percent = FALSE, combine_SI = TRUE,
    +  combine_IR = FALSE)
    + +

    Arguments

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    ...

    one or more vectors (or columns) with antibiotic interpretations. They will be transformed internally with as.rsi if needed. Use multiple columns to calculate (the lack of) co-resistance: the probability where one of two drugs have a resistant or susceptible result. See Examples.

    minimum

    the minimum allowed number of available (tested) isolates. Any isolate count lower than minimum will return NA with a warning. The default number of 30 isolates is advised by the Clinical and Laboratory Standards Institute (CLSI) as best practice, see Source.

    as_percent

    a logical to indicate whether the output must be returned as a hundred fold with % sign (a character). A value of 0.123456 will then be returned as "12.3%".

    only_all_tested

    (for combination therapies, i.e. using more than one variable for ...) a logical to indicate that isolates must be tested for all antibiotics, see section Combination therapy below

    data

    a data.frame containing columns with class rsi (see as.rsi)

    translate_ab

    a column name of the antibiotics data set to translate the antibiotic abbreviations to, using ab_property

    language

    language of the returned text, defaults to system language (see get_locale) and can also be set with getOption("AMR_locale"). Use language = NULL or language = "" to prevent translation.

    combine_SI

    a logical to indicate whether all values of S and I must be merged into one, so the output only consists of S+I vs. R (susceptible vs. resistant). This used to be the parameter combine_IR, but this now follows the redefinition by EUCAST about the interpretion of I (increased exposure) in 2019, see section 'Interpretation of S, I and R' below. Default is TRUE.

    combine_IR

    a logical to indicate whether all values of I and R must be merged into one, so the output only consists of S vs. I+R (susceptible vs. non-susceptible). This is outdated, see parameter combine_SI.

    + +

    Source

    + +

    M39 Analysis and Presentation of Cumulative Antimicrobial Susceptibility Test Data, 4th Edition, 2014, Clinical and Laboratory Standards Institute (CLSI). https://clsi.org/standards/products/microbiology/documents/m39/.

    +

    Value

    + +

    Double or, when as_percent = TRUE, a character.

    +

    Details

    + +

    The function resistance is equal to the function proportion_R. The function susceptibility is equal to the function proportion_SI.

    +

    Remember that you should filter your table to let it contain only first isolates! This is needed to exclude duplicates and to reduce selection bias. Use first_isolate to determine them in your data set.

    +

    These functions are not meant to count isolates, but to calculate the proportion of resistance/susceptibility. Use the count functions to count isolates. The function susceptibility() is essentially equal to count_susceptible() / count_all(). Low counts can infuence the outcome - the proportion functions may camouflage this, since they only return the proportion (albeit being dependent on the minimum parameter).

    +

    The function proportion_df takes any variable from data that has an "rsi" class (created with as.rsi) and calculates the proportions R, I and S. The function rsi_df works exactly like proportion_df, but adds the number of isolates.

    +

    Combination therapy

    + + + +

    When using more than one variable for ... (= combination therapy)), use only_all_tested to only count isolates that are tested for all antibiotics/variables that you test them for. See this example for two antibiotics, Antibiotic A and Antibiotic B, about how susceptibility works to calculate the %SI:

    +
    +--------------------------------------------------------------------
    +                    only_all_tested = FALSE  only_all_tested = TRUE
    +                    -----------------------  -----------------------
    + Drug A    Drug B   include as  include as   include as  include as
    +                    numerator   denominator  numerator   denominator
    +--------  --------  ----------  -----------  ----------  -----------
    + S or I    S or I       X            X            X            X
    +   R       S or I       X            X            X            X
    +  <NA>     S or I       X            X            -            -
    + S or I      R          X            X            X            X
    +   R         R          -            X            -            X
    +  <NA>       R          -            -            -            -
    + S or I     <NA>        X            X            -            -
    +   R        <NA>        -            -            -            -
    +  <NA>      <NA>        -            -            -            -
    +--------------------------------------------------------------------
    +
    + +

    Please note that, in combination therapies, for only_all_tested = TRUE applies that:

    +    count_S()    +   count_I()    +   count_R()    = count_all()
    +  proportion_S() + proportion_I() + proportion_R() = 1
    +

    and that, in combination therapies, for only_all_tested = FALSE applies that:

    +    count_S()    +   count_I()    +   count_R()    >= count_all()
    +  proportion_S() + proportion_I() + proportion_R() >= 1
    +
    + +

    Using only_all_tested has no impact when only using one antibiotic as input.

    +

    Interpretation of S, I and R

    + + + +

    In 2019, the European Committee on Antimicrobial Susceptibility Testing (EUCAST) has decided to change the definitions of susceptibility testing categories S, I and R as shown below (http://www.eucast.org/newsiandr/). Results of several consultations on the new definitions are available on the EUCAST website under "Consultations".

    +
      +
    • S - Susceptible, standard dosing regimen: A microorganism is categorised as "Susceptible, standard dosing regimen", when there is a high likelihood of therapeutic success using a standard dosing regimen of the agent.

    • +
    • I - Susceptible, increased exposure: A microorganism is categorised as "Susceptible, Increased exposure" when there is a high likelihood of therapeutic success because exposure to the agent is increased by adjusting the dosing regimen or by its concentration at the site of infection.

    • +
    • R - Resistant: A microorganism is categorised as "Resistant" when there is a high likelihood of therapeutic failure even when there is increased exposure.

    • +
    + +

    Exposure is a function of how the mode of administration, dose, dosing interval, infusion time, as well as distribution and excretion of the antimicrobial agent will influence the infecting organism at the site of infection.

    +

    This AMR package honours this new insight. Use susceptibility (equal to proportion_SI) to determine antimicrobial susceptibility and count_susceptible (equal to count_SI) to count susceptible isolates.

    +

    Read more on our website!

    + + + +

    On our website https://msberends.gitlab.io/AMR you can find a tutorial about how to conduct AMR analysis, the complete documentation of all functions (which reads a lot easier than here in R) and an example analysis using WHONET data.

    +

    See also

    + +

    count_* to count resistant and susceptible isolates.

    + +

    Examples

    +
    # example_isolates is a data set available in the AMR package.
    +?example_isolates
    +
    +resistance(example_isolates$AMX)     # determines %R
    +susceptibility(example_isolates$AMX) # determines %S+I
    +
    +# be more specific
    +proportion_S(example_isolates$AMX)
    +proportion_SI(example_isolates$AMX)
    +proportion_I(example_isolates$AMX)
    +proportion_IR(example_isolates$AMX)
    +proportion_R(example_isolates$AMX)
    +
    +library(dplyr)
    +example_isolates %>%
    +  group_by(hospital_id) %>%
    +  summarise(r = resistance(CIP),
    +            n = n_rsi(CIP)) # n_rsi works like n_distinct in dplyr, see ?n_rsi
    +
    +example_isolates %>%
    +  group_by(hospital_id) %>%
    +  summarise(R  = resistance(CIP, as_percent = TRUE),
    +            SI = susceptibility(CIP, as_percent = TRUE),
    +            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!
    +
    +# Calculate co-resistance between amoxicillin/clav acid and gentamicin,
    +# so we can see that combination therapy does a lot more than mono therapy:
    +example_isolates %>% susceptibility(AMC)  # %SI = 76.3%
    +example_isolates %>% count_all(AMC)       #   n = 1879
    +
    +example_isolates %>% susceptibility(GEN)  # %SI = 75.4%
    +example_isolates %>% count_all(GEN)       #   n = 1855
    +
    +example_isolates %>% susceptibility(AMC, GEN) # %SI = 94.1%
    +example_isolates %>% count_all(AMC, GEN)      #   n = 1939
    +
    +
    +# See Details on how `only_all_tested` works. Example:
    +example_isolates %>%
    +  summarise(numerator = count_susceptible(AMC, GEN),
    +            denominator = count_all(AMC, GEN),
    +            proportion = susceptibility(AMC, GEN))
    +example_isolates %>%
    +  summarise(numerator = count_susceptible(AMC, GEN, only_all_tested = TRUE),
    +            denominator = count_all(AMC, GEN, only_all_tested = TRUE),
    +            proportion = susceptibility(AMC, GEN, only_all_tested = TRUE))
    +
    +
    +example_isolates %>%
    +  group_by(hospital_id) %>%
    +  summarise(cipro_p = susceptibility(CIP, as_percent = TRUE),
    +            cipro_n = count_all(CIP),
    +            genta_p = susceptibility(GEN, as_percent = TRUE),
    +            genta_n = count_all(GEN),
    +            combination_p = susceptibility(CIP, GEN, as_percent = TRUE),
    +            combination_n = count_all(CIP, GEN))
    +
    +# Get proportions S/I/R immediately of all rsi columns
    +example_isolates %>%
    +  select(AMX, CIP) %>%
    +  proportion_df(translate = FALSE)
    +
    +# It also supports grouping variables
    +example_isolates %>%
    +  select(hospital_id, AMX, CIP) %>%
    +  group_by(hospital_id) %>%
    +  proportion_df(translate = FALSE)
    +
    +
    +if (FALSE) {
    +
    +# calculate current empiric combination therapy of Helicobacter gastritis:
    +my_table %>%
    +  filter(first_isolate == TRUE,
    +         genus == "Helicobacter") %>%
    +  summarise(p = susceptibility(AMX, MTR),  # amoxicillin with metronidazole
    +            n = count_all(AMX, MTR))
    +}
    +
    + +
    + + + +
    + + + + + + + + + + + diff --git a/docs/reference/read.4D.html b/docs/reference/read.4D.html index 2a08252f..6bb71a21 100644 --- a/docs/reference/read.4D.html +++ b/docs/reference/read.4D.html @@ -85,7 +85,7 @@ AMR (for R) - 0.8.0 + 0.8.0.9027 diff --git a/docs/reference/resistance_predict.html b/docs/reference/resistance_predict.html index 06957bd9..8229f361 100644 --- a/docs/reference/resistance_predict.html +++ b/docs/reference/resistance_predict.html @@ -85,7 +85,7 @@ AMR (for R) - 0.8.0 + 0.8.0.9027 @@ -339,7 +339,7 @@

    On our website https://msberends.gitlab.io/AMR you can find a tutorial about how to conduct AMR analysis, the complete documentation of all functions (which reads a lot easier than here in R) and an example analysis using WHONET data.

    See also

    -

    The portion function to calculate resistance,
    lm glm

    +

    The portion function to calculate resistance,
    lm glm

    Examples

    x <- resistance_predict(example_isolates, col_ab = "AMX", year_min = 2010, model = "binomial")
    diff --git a/docs/reference/rsi_translation.html b/docs/reference/rsi_translation.html
    index e2e763e1..d061e360 100644
    --- a/docs/reference/rsi_translation.html
    +++ b/docs/reference/rsi_translation.html
    @@ -85,7 +85,7 @@
           
           
             AMR (for R)
    -        0.8.0
    +        0.8.0.9027
           
         
     
    diff --git a/docs/reference/skewness.html b/docs/reference/skewness.html
    index f56501f7..09fbc614 100644
    --- a/docs/reference/skewness.html
    +++ b/docs/reference/skewness.html
    @@ -86,7 +86,7 @@ When negative: the left tail is longer; the mass of the distribution is concentr
           
           
             AMR (for R)
    -        0.8.0
    +        0.8.0.9027
           
         
     
    diff --git a/docs/reference/translate.html b/docs/reference/translate.html
    index a7dc44dc..e1c442e9 100644
    --- a/docs/reference/translate.html
    +++ b/docs/reference/translate.html
    @@ -85,7 +85,7 @@
           
           
             AMR (for R)
    -        0.8.0
    +        0.8.0.9027
           
         
     
    diff --git a/docs/sitemap.xml b/docs/sitemap.xml
    index fb23b122..092414d3 100644
    --- a/docs/sitemap.xml
    +++ b/docs/sitemap.xml
    @@ -118,7 +118,7 @@
         https://msberends.gitlab.io/AMR/reference/p_symbol.html
       
       
    -    https://msberends.gitlab.io/AMR/reference/portion.html
    +    https://msberends.gitlab.io/AMR/reference/proportion.html
       
       
         https://msberends.gitlab.io/AMR/reference/read.4D.html
    diff --git a/index.md b/index.md
    index 6c5af0ac..3965e0e7 100644
    --- a/index.md
    +++ b/index.md
    @@ -143,7 +143,7 @@ The `AMR` package basically does four important things:
     
     3. It **analyses the data** with convenient functions that use well-known methods.
     
    -   * Calculate the resistance (and even co-resistance) of microbial isolates with the `portion_R()`, `portion_IR()`, `portion_I()`, `portion_SI()` and `portion_S()` functions. Similarly, the *number* of isolates can be determined with the `count_R()`, `count_IR()`, `count_I()`, `count_SI()` and `count_S()` functions. All these functions can be used with the `dplyr` package (e.g. in conjunction with `summarise()`)
    +   * Calculate the microbial susceptibility or resistance (and even co-resistance) with the `susceptibility()` and `resistance()` functions, or be even more specific with the `proportion_R()`, `proportion_IR()`, `proportion_I()`, `proportion_SI()` and `proportion_S()` functions. Similarly, the *number* of isolates can be determined with the `count_resistant()`, `count_susceptible()` and `count_all()` functions. All these functions can be used with the `dplyr` package (e.g. in conjunction with `summarise()`)
        * Plot AMR results with `geom_rsi()`, a function made for the `ggplot2` package
        * Predict antimicrobial resistance for the nextcoming years using logistic regression models with the `resistance_predict()` function
     
    diff --git a/man/AMR-deprecated.Rd b/man/AMR-deprecated.Rd
    index 47350aa6..1210eac9 100644
    --- a/man/AMR-deprecated.Rd
    +++ b/man/AMR-deprecated.Rd
    @@ -2,13 +2,25 @@
     % Please edit documentation in R/deprecated.R
     \name{AMR-deprecated}
     \alias{AMR-deprecated}
    -\alias{as.atc}
     \alias{p.symbol}
    +\alias{portion_R}
    +\alias{portion_IR}
    +\alias{portion_I}
    +\alias{portion_SI}
    +\alias{portion_S}
     \title{Deprecated functions}
     \usage{
    -as.atc(x)
    -
     p.symbol(...)
    +
    +portion_R(...)
    +
    +portion_IR(...)
    +
    +portion_I(...)
    +
    +portion_SI(...)
    +
    +portion_S(...)
     }
     \description{
     These functions are so-called '\link{Deprecated}'. They will be removed in a future release. Using the functions will give a warning with the name of the function it has been replaced by (if there is one).
    diff --git a/man/AMR.Rd b/man/AMR.Rd
    index 8c718125..c310063e 100644
    --- a/man/AMR.Rd
    +++ b/man/AMR.Rd
    @@ -13,28 +13,19 @@ We created this package for both academic research and routine analysis at the F
     
     This package can be used for:
     \itemize{
    -  \item{Reference for microorganisms, since it contains all microbial (sub)species from the Catalogue of Life}
    +  \item{Reference for the taxonomy of microorganisms, since the package contains all microbial (sub)species from the Catalogue of Life}
       \item{Interpreting raw MIC and disk diffusion values, based on the latest CLSI or EUCAST guidelines}
    +  \item{Determining first isolates to be used for AMR analysis}
       \item{Calculating antimicrobial resistance}
       \item{Determining multi-drug resistance (MDR) / multi-drug resistant organisms (MDRO)}
    -  \item{Calculating empirical susceptibility of both mono therapy and combination therapy}
    +  \item{Calculating (empirical) susceptibility of both mono therapy and combination therapies}
       \item{Predicting future antimicrobial resistance using regression models}
       \item{Getting properties for any microorganism (like Gram stain, species, genus or family)}
    -  \item{Getting properties for any antibiotic (like name, ATC code, defined daily dose or trade name)}
    +  \item{Getting properties for any antibiotic (like name, EARS-Net code, ATC code, PubChem code, defined daily dose or trade name)}
       \item{Plotting antimicrobial resistance}
    -  \item{Determining first isolates to be used for AMR analysis}
       \item{Applying EUCAST expert rules}
    -  \item{Descriptive statistics: frequency tables, kurtosis and skewness}
     }
     }
    -\section{Authors}{
    -
    -Matthijs S. Berends[1,2] Christian F. Luz[1], Erwin E.A. Hassing[2],  Corinna Glasner[1],  Alex W. Friedrich[1],  Bhanu N.M. Sinha[1] \cr
    -
    -[1] Department of Medical Microbiology, University of Groningen, University Medical Center Groningen, Groningen, the Netherlands - \url{https://www.rug.nl} \url{https://www.umcg.nl} \cr
    -[2] Certe Medical Diagnostics & Advice, Groningen, the Netherlands - \url{https://www.certe.nl}
    -}
    -
     \section{Read more on our website!}{
     
     On our website \url{https://msberends.gitlab.io/AMR} you can find \href{https://msberends.gitlab.io/AMR/articles/AMR.html}{a tutorial} about how to conduct AMR analysis, the \href{https://msberends.gitlab.io/AMR/reference}{complete documentation of all functions} (which reads a lot easier than here in R) and \href{https://msberends.gitlab.io/AMR/articles/WHONET.html}{an example analysis using WHONET data}.
    diff --git a/man/as.rsi.Rd b/man/as.rsi.Rd
    index ab14187f..8bb4fa52 100755
    --- a/man/as.rsi.Rd
    +++ b/man/as.rsi.Rd
    @@ -63,7 +63,7 @@ In 2019, the European Committee on Antimicrobial Susceptibility Testing (EUCAST)
     
     Exposure is a function of how the mode of administration, dose, dosing interval, infusion time, as well as distribution and excretion of the antimicrobial agent will influence the infecting organism at the site of infection.
     
    -This AMR package honours this new insight. Use \code{\link{portion_SI}} to determine antimicrobial susceptibility and \code{\link{count_SI}} to count susceptible isolates.
    +This AMR package honours this new insight. Use \code{\link{susceptibility}} (equal to \code{\link{proportion_SI}}) to determine antimicrobial susceptibility and \code{\link{count_susceptible}} (equal to \code{\link{count_SI}}) to count susceptible isolates.
     }
     
     \section{Read more on our website!}{
    diff --git a/man/availability.Rd b/man/availability.Rd
    index e499d8dc..38202d10 100644
    --- a/man/availability.Rd
    +++ b/man/availability.Rd
    @@ -15,10 +15,10 @@ availability(tbl, width = NULL)
     \code{data.frame} with column names of \code{tbl} as row names
     }
     \description{
    -Easy check for availability of columns in a data set. This makes it easy to get an idea of which antimicrobial combination can be used for calculation with e.g. \code{\link{portion_R}}.
    +Easy check for availability of columns in a data set. This makes it easy to get an idea of which antimicrobial combination can be used for calculation with e.g. \code{\link{resistance}}.
     }
     \details{
    -The function returns a \code{data.frame} with columns \code{"resistant"} and \code{"visual_resistance"}. The values in that columns are calculated with \code{\link{portion_R}}.
    +The function returns a \code{data.frame} with columns \code{"resistant"} and \code{"visual_resistance"}. The values in that columns are calculated with \code{\link{resistance}}.
     }
     \section{Read more on our website!}{
     
    diff --git a/man/count.Rd b/man/count.Rd
    index 34d5fa4d..fc6ce759 100644
    --- a/man/count.Rd
    +++ b/man/count.Rd
    @@ -2,6 +2,8 @@
     % Please edit documentation in R/count.R
     \name{count}
     \alias{count}
    +\alias{count_resistant}
    +\alias{count_susceptible}
     \alias{count_R}
     \alias{count_IR}
     \alias{count_I}
    @@ -11,10 +13,11 @@
     \alias{n_rsi}
     \alias{count_df}
     \title{Count isolates}
    -\source{
    -Wickham H. \strong{Tidy Data.} The Journal of Statistical Software, vol. 59, 2014. \url{http://vita.had.co.nz/papers/tidy-data.html}
    -}
     \usage{
    +count_resistant(..., only_all_tested = FALSE)
    +
    +count_susceptible(..., only_all_tested = FALSE)
    +
     count_R(..., only_all_tested = FALSE)
     
     count_IR(..., only_all_tested = FALSE)
    @@ -53,16 +56,16 @@ Integer
     \description{
     These functions can be used to count resistant/susceptible microbial isolates. All functions support quasiquotation with pipes, can be used in \code{dplyr}s \code{\link[dplyr]{summarise}} and support grouped variables, see \emph{Examples}.
     
    -\code{count_R} and \code{count_IR} can be used to count resistant isolates, \code{count_S} and \code{count_SI} can be used to count susceptible isolates.\cr
    +\code{count_resistant} should be used to count resistant isolates, \code{count_susceptible} should be used to count susceptible isolates.\cr
     }
     \details{
    -These functions are meant to count isolates. Use the \code{\link{portion}_*} functions to calculate microbial resistance.
    +These functions are meant to count isolates. Use the \code{\link{resistance}}/\code{\link{susceptibility}} functions to calculate microbial resistance/susceptibility.
     
    -The function \code{n_rsi} is an alias of \code{count_all}. They can be used to count all available isolates, i.e. where all input antibiotics have an available result (S, I or R). Their use is equal to \code{\link{n_distinct}}. Their function is equal to \code{count_S(...) + count_IR(...)}.
    +The function \code{count_resistant} is equal to the function \code{count_R}. The function \code{count_susceptible} is equal to the function \code{count_SI}.
     
    -The function \code{count_df} takes any variable from \code{data} that has an \code{"rsi"} class (created with \code{\link{as.rsi}}) and counts the amounts of S, I and R. The resulting \emph{tidy data} (see Source) \code{data.frame} will have three rows (S/I/R) and a column for each variable with class \code{"rsi"}.
    +The function \code{n_rsi} is an alias of \code{count_all}. They can be used to count all available isolates, i.e. where all input antibiotics have an available result (S, I or R). Their use is equal to \code{\link{n_distinct}}. Their function is equal to \code{count_susceptible(...) + count_resistant(...)}.
     
    -The function \code{rsi_df} works exactly like \code{count_df}, but adds the percentage of S, I and R.
    +The function \code{count_df} takes any variable from \code{data} that has an \code{"rsi"} class (created with \code{\link{as.rsi}}) and counts the number of S's, I's and R's. The function \code{rsi_df} works exactly like \code{count_df}, but adds the percentage of S, I and R.
     }
     \section{Interpretation of S, I and R}{
     
    @@ -76,12 +79,12 @@ In 2019, the European Committee on Antimicrobial Susceptibility Testing (EUCAST)
     
     Exposure is a function of how the mode of administration, dose, dosing interval, infusion time, as well as distribution and excretion of the antimicrobial agent will influence the infecting organism at the site of infection.
     
    -This AMR package honours this new insight. Use \code{\link{portion_SI}} to determine antimicrobial susceptibility and \code{\link{count_SI}} to count susceptible isolates.
    +This AMR package honours this new insight. Use \code{\link{susceptibility}} (equal to \code{\link{proportion_SI}}) to determine antimicrobial susceptibility and \code{\link{count_susceptible}} (equal to \code{\link{count_SI}}) to count susceptible isolates.
     }
     
     \section{Combination therapy}{
     
    -When using more than one variable for \code{...} (= combination therapy)), use \code{only_all_tested} to only count isolates that are tested for all antibiotics/variables that you test them for. See this example for two antibiotics, Antibiotic A and Antibiotic B, about how \code{portion_SI} works to calculate the \%SI:
    +When using more than one variable for \code{...} (= combination therapy)), use \code{only_all_tested} to only count isolates that are tested for all antibiotics/variables that you test them for. See this example for two antibiotics, Antibiotic A and Antibiotic B, about how \code{susceptibility} works to calculate the \%SI:
     
     \preformatted{
     --------------------------------------------------------------------
    @@ -104,13 +107,13 @@ When using more than one variable for \code{...} (= combination therapy)), use \
     
     Please note that, in combination therapies, for \code{only_all_tested = TRUE} applies that:
     \preformatted{
    -   count_S()  +  count_I()  +  count_R()  == count_all()
    -  portion_S() + portion_I() + portion_R() == 1
    +    count_S()    +   count_I()    +   count_R()    = count_all()
    +  proportion_S() + proportion_I() + proportion_R() = 1
     }
     and that, in combination therapies, for \code{only_all_tested = FALSE} applies that:
     \preformatted{
    -   count_S()  +  count_I()  +  count_R()  >= count_all()
    -  portion_S() + portion_I() + portion_R() >= 1
    +    count_S()    +   count_I()    +   count_R()    >= count_all()
    +  proportion_S() + proportion_I() + proportion_R() >= 1
     }
     
     Using \code{only_all_tested} has no impact when only using one antibiotic as input.
    @@ -125,23 +128,27 @@ On our website \url{https://msberends.gitlab.io/AMR} you can find \href{https://
     # example_isolates is a data set available in the AMR package.
     ?example_isolates
     
    -# Count resistant isolates
    -count_R(example_isolates$AMX)
    -count_IR(example_isolates$AMX)
    +count_resistant(example_isolates$AMX)   # counts "R"
    +count_susceptible(example_isolates$AMX) # counts "S" and "I"
    +count_all(example_isolates$AMX)         # counts "S", "I" and "R"
     
    -# Or susceptible isolates
    +# be more specific
     count_S(example_isolates$AMX)
     count_SI(example_isolates$AMX)
    +count_I(example_isolates$AMX)
    +count_IR(example_isolates$AMX)
    +count_R(example_isolates$AMX)
     
     # Count all available isolates
     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(example_isolates$AMX)
    -portion_SI(example_isolates$AMX) * n_rsi(example_isolates$AMX)
    +# n_rsi() is an alias of count_all().
    +# Since it counts all available isolates, you can
    +# calculate back to count e.g. susceptible isolates.
    +# These results are the same:
    +count_susceptible(example_isolates$AMX)
    +susceptibility(example_isolates$AMX) * n_rsi(example_isolates$AMX)
     
     library(dplyr)
     example_isolates \%>\%
    @@ -155,19 +162,16 @@ example_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_SI` calculates percentages right away instead.
    -count_SI(example_isolates$AMC)  # 1433
    -count_all(example_isolates$AMC) # 1879
    +# Please mind that `susceptibility()` calculates percentages right away instead.
    +example_isolates \%>\% count_susceptible(AMC) # 1433
    +example_isolates \%>\% count_all(AMC)         # 1879
     
    -count_SI(example_isolates$GEN)  # 1399
    -count_all(example_isolates$GEN) # 1855
    +example_isolates \%>\% count_susceptible(GEN) # 1399
    +example_isolates \%>\% count_all(GEN)         # 1855
     
    -with(example_isolates,
    -     count_SI(AMC, GEN))        # 1764
    -with(example_isolates,
    -     n_rsi(AMC, GEN))           # 1936
    -
    -# Get portions S/I/R immediately of all rsi columns
    +example_isolates \%>\% count_susceptible(AMC, GEN) # 1764
    +example_isolates \%>\% count_all(AMC, GEN)         # 1936
    +# Get number of S+I vs. R immediately of selected columns
     example_isolates \%>\%
       select(AMX, CIP) \%>\%
       count_df(translate = FALSE)
    @@ -180,5 +184,5 @@ example_isolates \%>\%
     
     }
     \seealso{
    -\code{\link{portion}_*} to calculate microbial resistance and susceptibility.
    +\code{\link{proportion}_*} to calculate microbial resistance and susceptibility.
     }
    diff --git a/man/ggplot_rsi.Rd b/man/ggplot_rsi.Rd
    index bcc021b5..09e6f687 100644
    --- a/man/ggplot_rsi.Rd
    +++ b/man/ggplot_rsi.Rd
    @@ -41,7 +41,7 @@ labels_rsi_count(position = NULL, x = "antibiotic",
     \arguments{
     \item{data}{a \code{data.frame} with column(s) of class \code{"rsi"} (see \code{\link{as.rsi}})}
     
    -\item{position}{position adjustment of bars, either \code{"fill"} (default when \code{fun} is \code{\link{count_df}}), \code{"stack"} (default when \code{fun} is \code{\link{portion_df}}) or \code{"dodge"}}
    +\item{position}{position adjustment of bars, either \code{"fill"}, \code{"stack"} or \code{"dodge"}}
     
     \item{x}{variable to show on x axis, either \code{"antibiotic"} (default) or \code{"interpretation"} or a grouping variable}
     
    @@ -131,7 +131,7 @@ example_isolates \%>\%
       select(AMX, NIT, FOS, TMP, CIP) \%>\%
       ggplot_rsi()
     
    -# get only portions and no counts:
    +# get only proportions and no counts:
     example_isolates \%>\%
       select(AMX, NIT, FOS, TMP, CIP) \%>\%
       ggplot_rsi(datalabels = FALSE)
    diff --git a/man/mdro.Rd b/man/mdro.Rd
    index 3ec5afd0..fb39ef0e 100644
    --- a/man/mdro.Rd
    +++ b/man/mdro.Rd
    @@ -175,7 +175,7 @@ In 2019, the European Committee on Antimicrobial Susceptibility Testing (EUCAST)
     
     Exposure is a function of how the mode of administration, dose, dosing interval, infusion time, as well as distribution and excretion of the antimicrobial agent will influence the infecting organism at the site of infection.
     
    -This AMR package honours this new insight. Use \code{\link{portion_SI}} to determine antimicrobial susceptibility and \code{\link{count_SI}} to count susceptible isolates.
    +This AMR package honours this new insight. Use \code{\link{susceptibility}} (equal to \code{\link{proportion_SI}}) to determine antimicrobial susceptibility and \code{\link{count_susceptible}} (equal to \code{\link{count_SI}}) to count susceptible isolates.
     }
     
     \section{Read more on our website!}{
    diff --git a/man/portion.Rd b/man/proportion.Rd
    similarity index 67%
    rename from man/portion.Rd
    rename to man/proportion.Rd
    index 722e1280..b33b7c2e 100644
    --- a/man/portion.Rd
    +++ b/man/proportion.Rd
    @@ -1,37 +1,44 @@
     % Generated by roxygen2: do not edit by hand
    -% Please edit documentation in R/portion.R, R/rsi_df.R
    -\name{portion}
    +% Please edit documentation in R/proportion.R, R/rsi_df.R
    +\name{proportion}
    +\alias{proportion}
    +\alias{resistance}
     \alias{portion}
    -\alias{portion_R}
    -\alias{portion_IR}
    -\alias{portion_I}
    -\alias{portion_SI}
    -\alias{portion_S}
    -\alias{portion_df}
    +\alias{susceptibility}
    +\alias{proportion_R}
    +\alias{proportion_IR}
    +\alias{proportion_I}
    +\alias{proportion_SI}
    +\alias{proportion_S}
    +\alias{proportion_df}
     \alias{rsi_df}
    -\title{Calculate resistance of isolates}
    +\title{Calculate microbial resistance}
     \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/}.
    -
    -Wickham H. \strong{Tidy Data.} The Journal of Statistical Software, vol. 59, 2014. \url{http://vita.had.co.nz/papers/tidy-data.html}
     }
     \usage{
    -portion_R(..., minimum = 30, as_percent = FALSE,
    +resistance(..., minimum = 30, as_percent = FALSE,
       only_all_tested = FALSE)
     
    -portion_IR(..., minimum = 30, as_percent = FALSE,
    +susceptibility(..., minimum = 30, as_percent = FALSE,
       only_all_tested = FALSE)
     
    -portion_I(..., minimum = 30, as_percent = FALSE,
    +proportion_R(..., minimum = 30, as_percent = FALSE,
       only_all_tested = FALSE)
     
    -portion_SI(..., minimum = 30, as_percent = FALSE,
    +proportion_IR(..., minimum = 30, as_percent = FALSE,
       only_all_tested = FALSE)
     
    -portion_S(..., minimum = 30, as_percent = FALSE,
    +proportion_I(..., minimum = 30, as_percent = FALSE,
       only_all_tested = FALSE)
     
    -portion_df(data, translate_ab = "name", language = get_locale(),
    +proportion_SI(..., minimum = 30, as_percent = FALSE,
    +  only_all_tested = FALSE)
    +
    +proportion_S(..., minimum = 30, as_percent = FALSE,
    +  only_all_tested = FALSE)
    +
    +proportion_df(data, translate_ab = "name", language = get_locale(),
       minimum = 30, as_percent = FALSE, combine_SI = TRUE,
       combine_IR = FALSE)
     
    @@ -62,22 +69,22 @@ rsi_df(data, translate_ab = "name", language = get_locale(),
     Double or, when \code{as_percent = TRUE}, a character.
     }
     \description{
    -These functions can be used to calculate the (co-)resistance of microbial isolates (i.e. percentage of S, SI, I, IR or R). All functions support quasiquotation with pipes, can be used in \code{dplyr}s \code{\link[dplyr]{summarise}} and support grouped variables, see \emph{Examples}.
    +These functions can be used to calculate the (co-)resistance or susceptibility of microbial isolates (i.e. percentage of S, SI, I, IR or R). All functions support quasiquotation with pipes, can be used in \code{dplyr}s \code{\link[dplyr]{summarise}} and support grouped variables, see \emph{Examples}.
     
    -\code{portion_R} and \code{portion_IR} can be used to calculate resistance, \code{portion_S} and \code{portion_SI} can be used to calculate susceptibility.\cr
    +\code{resistance} should be used to calculate resistance, \code{susceptibility} should be used to calculate susceptibility.\cr
     }
     \details{
    +The function \code{resistance} is equal to the function \code{proportion_R}. The function \code{susceptibility} is equal to the function \code{proportion_SI}.
    + 
     \strong{Remember that you should filter your table to let it contain only first isolates!} This is needed to exclude duplicates and to reduce selection bias. Use \code{\link{first_isolate}} to determine them in your data set.
     
    -These functions are not meant to count isolates, but to calculate the portion of resistance/susceptibility. Use the \code{\link[AMR]{count}} functions to count isolates. The function \code{portion_SI()} is essentially equal to \code{count_SI() / count_all()}. \emph{Low counts can infuence the outcome - the \code{portion} functions may camouflage this, since they only return the portion (albeit being dependent on the \code{minimum} parameter).}
    +These functions are not meant to count isolates, but to calculate the proportion of resistance/susceptibility. Use the \code{\link[AMR]{count}} functions to count isolates. The function \code{susceptibility()} is essentially equal to \code{count_susceptible() / count_all()}. \emph{Low counts can infuence the outcome - the \code{proportion} functions may camouflage this, since they only return the proportion (albeit being dependent on the \code{minimum} parameter).}
     
    -The function \code{portion_df} takes any variable from \code{data} that has an \code{"rsi"} class (created with \code{\link{as.rsi}}) and calculates the portions R, I and S. The resulting \emph{tidy data} (see Source) \code{data.frame} will have three rows (S/I/R) and a column for each group and each variable with class \code{"rsi"}.
    -
    -The function \code{rsi_df} works exactly like \code{portion_df}, but adds the number of isolates.
    +The function \code{proportion_df} takes any variable from \code{data} that has an \code{"rsi"} class (created with \code{\link{as.rsi}}) and calculates the proportions R, I and S. The function \code{rsi_df} works exactly like \code{proportion_df}, but adds the number of isolates.
     }
     \section{Combination therapy}{
     
    -When using more than one variable for \code{...} (= combination therapy)), use \code{only_all_tested} to only count isolates that are tested for all antibiotics/variables that you test them for. See this example for two antibiotics, Antibiotic A and Antibiotic B, about how \code{portion_SI} works to calculate the \%SI:
    +When using more than one variable for \code{...} (= combination therapy)), use \code{only_all_tested} to only count isolates that are tested for all antibiotics/variables that you test them for. See this example for two antibiotics, Antibiotic A and Antibiotic B, about how \code{susceptibility} works to calculate the \%SI:
     
     \preformatted{
     --------------------------------------------------------------------
    @@ -100,13 +107,13 @@ When using more than one variable for \code{...} (= combination therapy)), use \
     
     Please note that, in combination therapies, for \code{only_all_tested = TRUE} applies that:
     \preformatted{
    -   count_S()  +  count_I()  +  count_R()  == count_all()
    -  portion_S() + portion_I() + portion_R() == 1
    +    count_S()    +   count_I()    +   count_R()    = count_all()
    +  proportion_S() + proportion_I() + proportion_R() = 1
     }
     and that, in combination therapies, for \code{only_all_tested = FALSE} applies that:
     \preformatted{
    -   count_S()  +  count_I()  +  count_R()  >= count_all()
    -  portion_S() + portion_I() + portion_R() >= 1
    +    count_S()    +   count_I()    +   count_R()    >= count_all()
    +  proportion_S() + proportion_I() + proportion_R() >= 1
     }
     
     Using \code{only_all_tested} has no impact when only using one antibiotic as input.
    @@ -124,7 +131,7 @@ In 2019, the European Committee on Antimicrobial Susceptibility Testing (EUCAST)
     
     Exposure is a function of how the mode of administration, dose, dosing interval, infusion time, as well as distribution and excretion of the antimicrobial agent will influence the infecting organism at the site of infection.
     
    -This AMR package honours this new insight. Use \code{\link{portion_SI}} to determine antimicrobial susceptibility and \code{\link{count_SI}} to count susceptible isolates.
    +This AMR package honours this new insight. Use \code{\link{susceptibility}} (equal to \code{\link{proportion_SI}}) to determine antimicrobial susceptibility and \code{\link{count_susceptible}} (equal to \code{\link{count_SI}}) to count susceptible isolates.
     }
     
     \section{Read more on our website!}{
    @@ -136,81 +143,72 @@ On our website \url{https://msberends.gitlab.io/AMR} you can find \href{https://
     # example_isolates is a data set available in the AMR package.
     ?example_isolates
     
    -# Calculate resistance
    -portion_R(example_isolates$AMX)
    -portion_IR(example_isolates$AMX)
    +resistance(example_isolates$AMX)     # determines \%R
    +susceptibility(example_isolates$AMX) # determines \%S+I
     
    -# Or susceptibility
    -portion_S(example_isolates$AMX)
    -portion_SI(example_isolates$AMX)
    +# be more specific
    +proportion_S(example_isolates$AMX)
    +proportion_SI(example_isolates$AMX)
    +proportion_I(example_isolates$AMX)
    +proportion_IR(example_isolates$AMX)
    +proportion_R(example_isolates$AMX)
     
    -# Do the above with pipes:
     library(dplyr)
    -example_isolates \%>\% portion_R(AMX)
    -example_isolates \%>\% portion_IR(AMX)
    -example_isolates \%>\% portion_S(AMX)
    -example_isolates \%>\% portion_SI(AMX)
    +example_isolates \%>\%
    +  group_by(hospital_id) \%>\%
    +  summarise(r = resistance(CIP),
    +            n = n_rsi(CIP)) # n_rsi works like n_distinct in dplyr, see ?n_rsi
     
     example_isolates \%>\%
       group_by(hospital_id) \%>\%
    -  summarise(p = portion_SI(CIP),
    -            n = n_rsi(CIP)) # n_rsi works like n_distinct in dplyr
    -
    -example_isolates \%>\%
    -  group_by(hospital_id) \%>\%
    -  summarise(R = portion_R(CIP, as_percent = TRUE),
    -            I = portion_I(CIP, as_percent = TRUE),
    -            S = portion_S(CIP, as_percent = TRUE),
    +  summarise(R  = resistance(CIP, as_percent = TRUE),
    +            SI = susceptibility(CIP, as_percent = TRUE),
                 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!
     
     # Calculate co-resistance between amoxicillin/clav acid and gentamicin,
     # so we can see that combination therapy does a lot more than mono therapy:
    -example_isolates \%>\% portion_SI(AMC)      # \%SI = 76.3\%
    +example_isolates \%>\% susceptibility(AMC)  # \%SI = 76.3\%
     example_isolates \%>\% count_all(AMC)       #   n = 1879
     
    -example_isolates \%>\% portion_SI(GEN)      # \%SI = 75.4\%
    +example_isolates \%>\% susceptibility(GEN)  # \%SI = 75.4\%
     example_isolates \%>\% count_all(GEN)       #   n = 1855
     
    -example_isolates \%>\% portion_SI(AMC, GEN) # \%SI = 94.1\%
    -example_isolates \%>\% count_all(AMC, GEN)  #   n = 1939
    +example_isolates \%>\% susceptibility(AMC, GEN) # \%SI = 94.1\%
    +example_isolates \%>\% count_all(AMC, GEN)      #   n = 1939
     
     
     # See Details on how `only_all_tested` works. Example:
     example_isolates \%>\%
    -  summarise(numerator = count_SI(AMC, GEN),
    +  summarise(numerator = count_susceptible(AMC, GEN),
                 denominator = count_all(AMC, GEN),
    -            portion = portion_SI(AMC, GEN))
    -#   numerator denominator portion
    -#        1764        1936  0.9408
    +            proportion = susceptibility(AMC, GEN))
     example_isolates \%>\%
    -  summarise(numerator = count_SI(AMC, GEN, only_all_tested = TRUE),
    +  summarise(numerator = count_susceptible(AMC, GEN, only_all_tested = TRUE),
                 denominator = count_all(AMC, GEN, only_all_tested = TRUE),
    -            portion = portion_SI(AMC, GEN, only_all_tested = TRUE))
    -#   numerator denominator portion
    -#       1687        1798   0.9383
    +            proportion = susceptibility(AMC, GEN, only_all_tested = TRUE))
     
     
     example_isolates \%>\%
       group_by(hospital_id) \%>\%
    -  summarise(cipro_p = portion_SI(CIP, as_percent = TRUE),
    +  summarise(cipro_p = susceptibility(CIP, as_percent = TRUE),
                 cipro_n = count_all(CIP),
    -            genta_p = portion_SI(GEN, as_percent = TRUE),
    +            genta_p = susceptibility(GEN, as_percent = TRUE),
                 genta_n = count_all(GEN),
    -            combination_p = portion_SI(CIP, GEN, as_percent = TRUE),
    +            combination_p = susceptibility(CIP, GEN, as_percent = TRUE),
                 combination_n = count_all(CIP, GEN))
     
    -# Get portions S/I/R immediately of all rsi columns
    +# Get proportions S/I/R immediately of all rsi columns
     example_isolates \%>\%
       select(AMX, CIP) \%>\%
    -  portion_df(translate = FALSE)
    +  proportion_df(translate = FALSE)
     
     # It also supports grouping variables
     example_isolates \%>\%
       select(hospital_id, AMX, CIP) \%>\%
       group_by(hospital_id) \%>\%
    -  portion_df(translate = FALSE)
    +  proportion_df(translate = FALSE)
     
     
     \dontrun{
    @@ -219,7 +217,7 @@ example_isolates \%>\%
     my_table \%>\%
       filter(first_isolate == TRUE,
              genus == "Helicobacter") \%>\%
    -  summarise(p = portion_S(AMX, MTR),  # amoxicillin with metronidazole
    +  summarise(p = susceptibility(AMX, MTR),  # amoxicillin with metronidazole
                 n = count_all(AMX, MTR))
     }
     }
    diff --git a/tests/appveyor/appveyor_tool.ps1 b/tests/appveyor/appveyor_tool.ps1
    index bc3fd64f..18f932f5 100644
    --- a/tests/appveyor/appveyor_tool.ps1
    +++ b/tests/appveyor/appveyor_tool.ps1
    @@ -174,7 +174,6 @@ Function Bootstrap {
       Progress "Downloading and installing travis_tool.sh"
       
       cp "tests\appveyor\travis_tool.sh" "..\travis_tool.sh"
    -  # Invoke-WebRequest https://gitlab.com/msberends/AMR/raw/master/tests/appveyor/travis_tool.sh -OutFile "..\travis_tool.sh"
       echo '@bash.exe ../travis_tool.sh %*' | Out-File -Encoding ASCII .\travis_tool.sh.cmd
       cat .\travis_tool.sh.cmd
       bash -c "( echo; echo '^travis_tool\.sh\.cmd$' ) >> .Rbuildignore"
    diff --git a/tests/testthat/test-count.R b/tests/testthat/test-count.R
    index a85d88a1..7dde67d1 100644
    --- a/tests/testthat/test-count.R
    +++ b/tests/testthat/test-count.R
    @@ -22,67 +22,67 @@
     context("count.R")
     
     test_that("counts work", {
    +  
    +  expect_equal(count_resistant(example_isolates$AMX), count_R(example_isolates$AMX))
    +  expect_equal(count_susceptible(example_isolates$AMX), count_SI(example_isolates$AMX))
    +  expect_equal(count_all(example_isolates$AMX), n_rsi(example_isolates$AMX))
    +  
       # AMX resistance in `example_isolates`
    -  expect_equal(count_R(example_isolates$AMX), 683)
    -  expect_equal(count_I(example_isolates$AMX), 3)
    -  expect_equal(count_S(example_isolates$AMX), 543)
    -  expect_equal(count_R(example_isolates$AMX) + count_I(example_isolates$AMX),
    -               count_IR(example_isolates$AMX))
    -  expect_equal(count_S(example_isolates$AMX) + count_I(example_isolates$AMX),
    -               count_SI(example_isolates$AMX))
    -
    +    expect_equal(count_R(example_isolates$AMX), 683)
    +    expect_equal(count_I(example_isolates$AMX), 3)
    +    expect_equal(suppressWarnings(count_S(example_isolates$AMX)), 543)
    +    expect_equal(count_R(example_isolates$AMX) + count_I(example_isolates$AMX),
    +                 suppressWarnings(count_IR(example_isolates$AMX)))
    +    expect_equal(suppressWarnings(count_S(example_isolates$AMX)) + count_I(example_isolates$AMX),
    +                 count_SI(example_isolates$AMX))
    +  
       library(dplyr)
    -  expect_equal(example_isolates %>% count_S(AMC), 1342)
    -  expect_equal(example_isolates %>% count_S(AMC, GEN, only_all_tested = TRUE), 1660)
    -  expect_equal(example_isolates %>% count_S(AMC, GEN, only_all_tested = FALSE), 1728)
    +  expect_equal(example_isolates %>% count_susceptible(AMC), 1433)
    +  expect_equal(example_isolates %>% count_susceptible(AMC, GEN, only_all_tested = TRUE), 1687)
    +  expect_equal(example_isolates %>% count_susceptible(AMC, GEN, only_all_tested = FALSE), 1764)
       expect_equal(example_isolates %>% count_all(AMC, GEN, only_all_tested = TRUE), 1798)
       expect_equal(example_isolates %>% count_all(AMC, GEN, only_all_tested = FALSE), 1936)
       expect_identical(example_isolates %>% count_all(AMC, GEN, only_all_tested = TRUE),
    -                   example_isolates %>% count_S(AMC, GEN, only_all_tested = TRUE) +
    -                     example_isolates %>% count_IR(AMC, GEN, only_all_tested = TRUE))
    +                   example_isolates %>% count_susceptible(AMC, GEN, only_all_tested = TRUE) +
    +                     example_isolates %>% count_resistant(AMC, GEN, only_all_tested = TRUE))
     
       # count of cases
       expect_equal(example_isolates %>%
                      group_by(hospital_id) %>%
    -                 summarise(cipro = count_SI(CIP),
    -                           genta = count_SI(GEN),
    -                           combination = count_SI(CIP, GEN)) %>%
    +                 summarise(cipro = count_susceptible(CIP),
    +                           genta = count_susceptible(GEN),
    +                           combination = count_susceptible(CIP, GEN)) %>%
                      pull(combination),
                    c(253, 465, 192, 558))
     
       # count_df
       expect_equal(
         example_isolates %>% select(AMX) %>% count_df() %>% pull(value),
    -    c(example_isolates$AMX %>% count_SI(),
    -      example_isolates$AMX %>% count_R())
    +    c(example_isolates$AMX %>% count_susceptible(),
    +      example_isolates$AMX %>% count_resistant())
       )
       expect_equal(
         example_isolates %>% select(AMX) %>% count_df(combine_IR = TRUE) %>% pull(value),
    -    c(example_isolates$AMX %>% count_S(),
    -      example_isolates$AMX %>% count_IR())
    +    c(suppressWarnings(example_isolates$AMX %>% count_S()),
    +      suppressWarnings(example_isolates$AMX %>% count_IR()))
       )
       expect_equal(
         example_isolates %>% select(AMX) %>% count_df(combine_SI = FALSE) %>% pull(value),
    -    c(example_isolates$AMX %>% count_S(),
    +    c(suppressWarnings(example_isolates$AMX %>% count_S()),
           example_isolates$AMX %>% count_I(),
           example_isolates$AMX %>% count_R())
       )
    -
    +  
       # warning for speed loss
    -  expect_warning(count_R(as.character(example_isolates$AMC)))
    -  expect_warning(count_I(as.character(example_isolates$AMC)))
    -  expect_warning(count_S(as.character(example_isolates$AMC,
    -                                      example_isolates$GEN)))
    -  expect_warning(count_S(example_isolates$AMC,
    -                         as.character(example_isolates$GEN)))
    -
    +  expect_warning(count_resistant(as.character(example_isolates$AMC)))
    +  expect_warning(count_resistant(example_isolates$AMC,
    +                                 as.character(example_isolates$GEN)))
    +  
       # check for errors
    -  expect_error(count_IR("test", minimum = "test"))
    -  expect_error(count_IR("test", as_percent = "test"))
    -  expect_error(count_I("test", minimum = "test"))
    -  expect_error(count_I("test", as_percent = "test"))
    -  expect_error(count_S("test", minimum = "test"))
    -  expect_error(count_S("test", as_percent = "test"))
    +  expect_error(count_resistant("test", minimum = "test"))
    +  expect_error(count_resistant("test", as_percent = "test"))
    +  expect_error(count_susceptible("test", minimum = "test"))
    +  expect_error(count_susceptible("test", as_percent = "test"))
     
       expect_error(count_df(c("A", "B", "C")))
       expect_error(count_df(example_isolates[, "date"]))
    diff --git a/tests/testthat/test-deprecated.R b/tests/testthat/test-deprecated.R
    index 12baabce..583d6256 100644
    --- a/tests/testthat/test-deprecated.R
    +++ b/tests/testthat/test-deprecated.R
    @@ -22,20 +22,12 @@
     context("deprecated.R")
     
     test_that("deprecated functions work", {
    -
    -  # first 5 chars of official name
    -  expect_equal(suppressWarnings(as.character(as.atc(c("nitro", "cipro")))),
    -               c("J01XE01", "J01MA02"))
    -
    -  # EARS-Net
    -  expect_equal(suppressWarnings(as.character(as.atc("AMX"))),
    -               "J01CA04")
    -
    -  expect_equal(suppressWarnings(guess_ab_col(data.frame(AMP_ND10 = "R",
    -                                                        AMC_ED20 = "S"),
    -                                             as.atc("augmentin"))),
    -               "AMC_ED20")
    -  
       expect_identical(suppressWarnings(p.symbol(seq(0, 1, 0.001))),
                        p_symbol(seq(0, 1, 0.001)))
    +  
    +  expect_equal(suppressWarnings(portion_S(example_isolates$AMX)), proportion_S(example_isolates$AMX))
    +  expect_equal(suppressWarnings(portion_SI(example_isolates$AMX)), proportion_SI(example_isolates$AMX))
    +  expect_equal(suppressWarnings(portion_I(example_isolates$AMX)), proportion_I(example_isolates$AMX))
    +  expect_equal(suppressWarnings(portion_IR(example_isolates$AMX)), proportion_IR(example_isolates$AMX))
    +  expect_equal(suppressWarnings(portion_R(example_isolates$AMX)), proportion_R(example_isolates$AMX))
     })
    diff --git a/tests/testthat/test-ggplot_rsi.R b/tests/testthat/test-ggplot_rsi.R
    index d9ce89ad..479ec537 100644
    --- a/tests/testthat/test-ggplot_rsi.R
    +++ b/tests/testthat/test-ggplot_rsi.R
    @@ -30,26 +30,26 @@ test_that("ggplot_rsi works", {
     
       # data should be equal
       expect_equal(
    -    (example_isolates %>% select(AMC, CIP) %>% ggplot_rsi())$data %>% summarise_all(portion_IR) %>% as.double(),
    -    example_isolates %>% select(AMC, CIP) %>% summarise_all(portion_IR) %>% as.double()
    +    (example_isolates %>% select(AMC, CIP) %>% ggplot_rsi())$data %>% summarise_all(resistance) %>% as.double(),
    +    example_isolates %>% select(AMC, CIP) %>% summarise_all(resistance) %>% as.double()
       )
     
       print(example_isolates %>% select(AMC, CIP) %>% ggplot_rsi(x = "interpretation", facet = "antibiotic"))
       print(example_isolates %>% select(AMC, CIP) %>% ggplot_rsi(x = "antibiotic", facet = "interpretation"))
     
       expect_equal(
    -    (example_isolates %>% select(AMC, CIP) %>% ggplot_rsi(x = "interpretation", facet = "antibiotic"))$data %>% summarise_all(portion_IR) %>% as.double(),
    -    example_isolates %>% select(AMC, CIP) %>% summarise_all(portion_IR) %>% as.double()
    +    (example_isolates %>% select(AMC, CIP) %>% ggplot_rsi(x = "interpretation", facet = "antibiotic"))$data %>% summarise_all(resistance) %>% as.double(),
    +    example_isolates %>% select(AMC, CIP) %>% summarise_all(resistance) %>% as.double()
       )
     
       expect_equal(
    -    (example_isolates %>% select(AMC, CIP) %>% ggplot_rsi(x = "antibiotic", facet = "interpretation"))$data %>% summarise_all(portion_IR) %>% as.double(),
    -    example_isolates %>% select(AMC, CIP) %>% summarise_all(portion_IR) %>% as.double()
    +    (example_isolates %>% select(AMC, CIP) %>% ggplot_rsi(x = "antibiotic", facet = "interpretation"))$data %>% summarise_all(resistance) %>% as.double(),
    +    example_isolates %>% select(AMC, CIP) %>% summarise_all(resistance) %>% as.double()
       )
     
       expect_equal(
    -    (example_isolates %>% select(AMC, CIP) %>% ggplot_rsi(x = "antibiotic", facet = "interpretation"))$data %>% summarise_all(count_IR) %>% as.double(),
    -    example_isolates %>% select(AMC, CIP) %>% summarise_all(count_IR) %>% as.double()
    +    (example_isolates %>% select(AMC, CIP) %>% ggplot_rsi(x = "antibiotic", facet = "interpretation"))$data %>% summarise_all(count_resistant) %>% as.double(),
    +    example_isolates %>% select(AMC, CIP) %>% summarise_all(count_resistant) %>% as.double()
       )
     
       # support for scale_type ab and mo
    diff --git a/tests/testthat/test-portion.R b/tests/testthat/test-portion.R
    deleted file mode 100755
    index 2c9ab72d..00000000
    --- a/tests/testthat/test-portion.R
    +++ /dev/null
    @@ -1,121 +0,0 @@
    -# ==================================================================== #
    -# TITLE                                                                #
    -# Antimicrobial Resistance (AMR) Analysis                              #
    -#                                                                      #
    -# SOURCE                                                               #
    -# https://gitlab.com/msberends/AMR                                     #
    -#                                                                      #
    -# LICENCE                                                              #
    -# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl)  #
    -#                                                                      #
    -# This R package is free software; you can freely use and distribute   #
    -# it for both personal and commercial purposes under the terms of the  #
    -# GNU General Public License version 2.0 (GNU GPL-2), as published by  #
    -# the Free Software Foundation.                                        #
    -#                                                                      #
    -# This R package was created for academic research and was publicly    #
    -# released in the hope that it will be useful, but it comes WITHOUT    #
    -# ANY WARRANTY OR LIABILITY.                                           #
    -# Visit our website for more info: https://msberends.gitlab.io/AMR.    #
    -# ==================================================================== #
    -
    -context("portion.R")
    -
    -test_that("portions works", {
    -  # AMX resistance in `example_isolates`
    -  expect_equal(portion_R(example_isolates$AMX), 0.5557364, tolerance = 0.0001)
    -  expect_equal(portion_I(example_isolates$AMX), 0.002441009, tolerance = 0.0001)
    -  expect_equal(1 - portion_R(example_isolates$AMX) - portion_I(example_isolates$AMX),
    -               portion_S(example_isolates$AMX))
    -  expect_equal(portion_R(example_isolates$AMX) + portion_I(example_isolates$AMX),
    -               portion_IR(example_isolates$AMX))
    -  expect_equal(portion_S(example_isolates$AMX) + portion_I(example_isolates$AMX),
    -               portion_SI(example_isolates$AMX))
    -
    -  expect_equal(example_isolates %>% portion_SI(AMC),
    -               0.7626397,
    -               tolerance = 0.0001)
    -  expect_equal(example_isolates %>% portion_SI(AMC, GEN),
    -               0.9408,
    -               tolerance = 0.0001)
    -  expect_equal(example_isolates %>% portion_SI(AMC, GEN, only_all_tested = TRUE),
    -               0.9382647,
    -               tolerance = 0.0001)
    -
    -  # percentages
    -  expect_equal(example_isolates %>%
    -                 group_by(hospital_id) %>%
    -                 summarise(R = portion_R(CIP, as_percent = TRUE),
    -                           I = portion_I(CIP, as_percent = TRUE),
    -                           S = portion_S(CIP, as_percent = TRUE),
    -                           n = n_rsi(CIP),
    -                           total = n()) %>%
    -                 pull(n) %>%
    -                 sum(),
    -               1409)
    -
    -  # count of cases
    -  expect_equal(example_isolates %>%
    -                 group_by(hospital_id) %>%
    -                 summarise(cipro_p = portion_SI(CIP, as_percent = TRUE),
    -                           cipro_n = n_rsi(CIP),
    -                           genta_p = portion_SI(GEN, as_percent = TRUE),
    -                           genta_n = n_rsi(GEN),
    -                           combination_p = portion_SI(CIP, GEN, as_percent = TRUE),
    -                           combination_n = n_rsi(CIP, GEN)) %>%
    -                 pull(combination_n),
    -               c(305, 617, 241, 711))
    -
    -  expect_warning(portion_R(as.character(example_isolates$AMC)))
    -  expect_warning(portion_S(as.character(example_isolates$AMC)))
    -  expect_warning(portion_S(as.character(example_isolates$AMC,
    -                                        example_isolates$GEN)))
    -  expect_warning(n_rsi(as.character(example_isolates$AMC,
    -                                    example_isolates$GEN)))
    -  expect_equal(suppressWarnings(n_rsi(as.character(example_isolates$AMC,
    -                                                   example_isolates$GEN))),
    -               1879)
    -
    -  # check for errors
    -  expect_error(portion_IR("test", minimum = "test"))
    -  expect_error(portion_IR("test", as_percent = "test"))
    -  expect_error(portion_I("test", minimum = "test"))
    -  expect_error(portion_I("test", as_percent = "test"))
    -  expect_error(portion_S("test", minimum = "test"))
    -  expect_error(portion_S("test", as_percent = "test"))
    -  expect_error(portion_S("test", also_single_tested = TRUE))
    -
    -  # check too low amount of isolates
    -  expect_identical(suppressWarnings(portion_R(example_isolates$AMX, minimum = nrow(example_isolates) + 1)),
    -                   NA)
    -  expect_identical(suppressWarnings(portion_I(example_isolates$AMX, minimum = nrow(example_isolates) + 1)),
    -                   NA)
    -  expect_identical(suppressWarnings(portion_S(example_isolates$AMX, minimum = nrow(example_isolates) + 1)),
    -                   NA)
    -
    -  # warning for speed loss
    -  expect_warning(portion_R(as.character(example_isolates$GEN)))
    -  expect_warning(portion_I(as.character(example_isolates$GEN)))
    -  expect_warning(portion_S(example_isolates$AMC, as.character(example_isolates$GEN)))
    -
    -  # portion_df
    -  expect_equal(
    -    example_isolates %>% select(AMX) %>% portion_df() %>% pull(value),
    -    c(example_isolates$AMX %>% portion_SI(),
    -      example_isolates$AMX %>% portion_R())
    -  )
    -  expect_equal(
    -    example_isolates %>% select(AMX) %>% portion_df(combine_IR = TRUE) %>% pull(value),
    -    c(example_isolates$AMX %>% portion_S(),
    -      example_isolates$AMX %>% portion_IR())
    -  )
    -  expect_equal(
    -    example_isolates %>% select(AMX) %>% portion_df(combine_SI = FALSE) %>% pull(value),
    -    c(example_isolates$AMX %>% portion_S(),
    -      example_isolates$AMX %>% portion_I(),
    -      example_isolates$AMX %>% portion_R())
    -  )
    -  
    -  expect_error(portion_df(c("A", "B", "C")))
    -  expect_error(portion_df(example_isolates[, "date"]))
    -})
    diff --git a/tests/testthat/test-proportion.R b/tests/testthat/test-proportion.R
    new file mode 100755
    index 00000000..5efe895b
    --- /dev/null
    +++ b/tests/testthat/test-proportion.R
    @@ -0,0 +1,124 @@
    +# ==================================================================== #
    +# TITLE                                                                #
    +# Antimicrobial Resistance (AMR) Analysis                              #
    +#                                                                      #
    +# SOURCE                                                               #
    +# https://gitlab.com/msberends/AMR                                     #
    +#                                                                      #
    +# LICENCE                                                              #
    +# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl)  #
    +#                                                                      #
    +# This R package is free software; you can freely use and distribute   #
    +# it for both personal and commercial purposes under the terms of the  #
    +# GNU General Public License version 2.0 (GNU GPL-2), as published by  #
    +# the Free Software Foundation.                                        #
    +#                                                                      #
    +# This R package was created for academic research and was publicly    #
    +# released in the hope that it will be useful, but it comes WITHOUT    #
    +# ANY WARRANTY OR LIABILITY.                                           #
    +# Visit our website for more info: https://msberends.gitlab.io/AMR.    #
    +# ==================================================================== #
    +
    +context("proportion.R")
    +
    +test_that("proportions works", {
    +  expect_equal(proportion_R(example_isolates$AMX), resistance(example_isolates$AMX))
    +  expect_equal(proportion_SI(example_isolates$AMX), susceptibility(example_isolates$AMX))
    +  
    +  # AMX resistance in `example_isolates`
    +  expect_equal(proportion_R(example_isolates$AMX), 0.5557364, tolerance = 0.0001)
    +  expect_equal(proportion_I(example_isolates$AMX), 0.002441009, tolerance = 0.0001)
    +  expect_equal(1 - proportion_R(example_isolates$AMX) - proportion_I(example_isolates$AMX),
    +               proportion_S(example_isolates$AMX))
    +  expect_equal(proportion_R(example_isolates$AMX) + proportion_I(example_isolates$AMX),
    +               proportion_IR(example_isolates$AMX))
    +  expect_equal(proportion_S(example_isolates$AMX) + proportion_I(example_isolates$AMX),
    +               proportion_SI(example_isolates$AMX))
    +
    +  expect_equal(example_isolates %>% proportion_SI(AMC),
    +               0.7626397,
    +               tolerance = 0.0001)
    +  expect_equal(example_isolates %>% proportion_SI(AMC, GEN),
    +               0.9408,
    +               tolerance = 0.0001)
    +  expect_equal(example_isolates %>% proportion_SI(AMC, GEN, only_all_tested = TRUE),
    +               0.9382647,
    +               tolerance = 0.0001)
    +
    +  # percentages
    +  expect_equal(example_isolates %>%
    +                 group_by(hospital_id) %>%
    +                 summarise(R = proportion_R(CIP, as_percent = TRUE),
    +                           I = proportion_I(CIP, as_percent = TRUE),
    +                           S = proportion_S(CIP, as_percent = TRUE),
    +                           n = n_rsi(CIP),
    +                           total = n()) %>%
    +                 pull(n) %>%
    +                 sum(),
    +               1409)
    +
    +  # count of cases
    +  expect_equal(example_isolates %>%
    +                 group_by(hospital_id) %>%
    +                 summarise(cipro_p = proportion_SI(CIP, as_percent = TRUE),
    +                           cipro_n = n_rsi(CIP),
    +                           genta_p = proportion_SI(GEN, as_percent = TRUE),
    +                           genta_n = n_rsi(GEN),
    +                           combination_p = proportion_SI(CIP, GEN, as_percent = TRUE),
    +                           combination_n = n_rsi(CIP, GEN)) %>%
    +                 pull(combination_n),
    +               c(305, 617, 241, 711))
    +
    +  expect_warning(proportion_R(as.character(example_isolates$AMC)))
    +  expect_warning(proportion_S(as.character(example_isolates$AMC)))
    +  expect_warning(proportion_S(as.character(example_isolates$AMC,
    +                                        example_isolates$GEN)))
    +  expect_warning(n_rsi(as.character(example_isolates$AMC,
    +                                    example_isolates$GEN)))
    +  expect_equal(suppressWarnings(n_rsi(as.character(example_isolates$AMC,
    +                                                   example_isolates$GEN))),
    +               1879)
    +
    +  # check for errors
    +  expect_error(proportion_IR("test", minimum = "test"))
    +  expect_error(proportion_IR("test", as_percent = "test"))
    +  expect_error(proportion_I("test", minimum = "test"))
    +  expect_error(proportion_I("test", as_percent = "test"))
    +  expect_error(proportion_S("test", minimum = "test"))
    +  expect_error(proportion_S("test", as_percent = "test"))
    +  expect_error(proportion_S("test", also_single_tested = TRUE))
    +
    +  # check too low amount of isolates
    +  expect_identical(suppressWarnings(proportion_R(example_isolates$AMX, minimum = nrow(example_isolates) + 1)),
    +                   NA)
    +  expect_identical(suppressWarnings(proportion_I(example_isolates$AMX, minimum = nrow(example_isolates) + 1)),
    +                   NA)
    +  expect_identical(suppressWarnings(proportion_S(example_isolates$AMX, minimum = nrow(example_isolates) + 1)),
    +                   NA)
    +
    +  # warning for speed loss
    +  expect_warning(proportion_R(as.character(example_isolates$GEN)))
    +  expect_warning(proportion_I(as.character(example_isolates$GEN)))
    +  expect_warning(proportion_S(example_isolates$AMC, as.character(example_isolates$GEN)))
    +
    +  # proportion_df
    +  expect_equal(
    +    example_isolates %>% select(AMX) %>% proportion_df() %>% pull(value),
    +    c(example_isolates$AMX %>% proportion_SI(),
    +      example_isolates$AMX %>% proportion_R())
    +  )
    +  expect_equal(
    +    example_isolates %>% select(AMX) %>% proportion_df(combine_IR = TRUE) %>% pull(value),
    +    c(example_isolates$AMX %>% proportion_S(),
    +      example_isolates$AMX %>% proportion_IR())
    +  )
    +  expect_equal(
    +    example_isolates %>% select(AMX) %>% proportion_df(combine_SI = FALSE) %>% pull(value),
    +    c(example_isolates$AMX %>% proportion_S(),
    +      example_isolates$AMX %>% proportion_I(),
    +      example_isolates$AMX %>% proportion_R())
    +  )
    +  
    +  expect_error(proportion_df(c("A", "B", "C")))
    +  expect_error(proportion_df(example_isolates[, "date"]))
    +})
    diff --git a/vignettes/AMR.Rmd b/vignettes/AMR.Rmd
    index 45553ba8..1ff4af18 100755
    --- a/vignettes/AMR.Rmd
    +++ b/vignettes/AMR.Rmd
    @@ -321,10 +321,12 @@ data_1st %>%
     
     ## Resistance percentages
     
    -The functions `portion_S()`, `portion_SI()`, `portion_I()`, `portion_IR()` and `portion_R()` can be used to determine the portion of a specific antimicrobial outcome. As per the EUCAST guideline of 2019, we calculate resistance as the portion of R (`portion_R()`) and susceptibility as the portion of S and I (`portion_SI()`). These functions can be used on their own:
    +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:
     
     ```{r}
    -data_1st %>% portion_R(AMX)
    +data_1st %>% resistance(AMX)
     ```
     
     Or can be used in conjuction with `group_by()` and `summarise()`, both from the `dplyr` package:
    @@ -332,12 +334,12 @@ Or can be used in conjuction with `group_by()` and `summarise()`, both from the
     ```{r, eval = FALSE}
     data_1st %>% 
       group_by(hospital) %>% 
    -  summarise(amoxicillin = portion_R(AMX))
    +  summarise(amoxicillin = resistance(AMX))
     ```
     ```{r, echo = FALSE}
     data_1st %>% 
       group_by(hospital) %>% 
    -  summarise(amoxicillin = portion_R(AMX)) %>% 
    +  summarise(amoxicillin = resistance(AMX)) %>% 
       knitr::kable(align = "c", big.mark = ",")
     ```
     
    @@ -346,32 +348,32 @@ Of course it would be very convenient to know the number of isolates responsible
     ```{r, eval = FALSE}
     data_1st %>% 
       group_by(hospital) %>% 
    -  summarise(amoxicillin = portion_R(AMX),
    +  summarise(amoxicillin = resistance(AMX),
                 available = n_rsi(AMX))
     ```
     ```{r, echo = FALSE}
     data_1st %>% 
       group_by(hospital) %>% 
    -  summarise(amoxicillin = portion_R(AMX),
    +  summarise(amoxicillin = resistance(AMX),
                 available = n_rsi(AMX)) %>% 
       knitr::kable(align = "c", big.mark = ",")
     ```
     
    -These functions can also be used to get the portion of multiple antibiotics, to calculate empiric susceptibility of combination therapies very easily:
    +These functions can also be used to get the proportion of multiple antibiotics, to calculate empiric susceptibility of combination therapies very easily:
     
     ```{r, eval = FALSE}
     data_1st %>% 
       group_by(genus) %>% 
    -  summarise(amoxiclav = portion_SI(AMC),
    -            gentamicin = portion_SI(GEN),
    -            amoxiclav_genta = portion_SI(AMC, GEN))
    +  summarise(amoxiclav = susceptibility(AMC),
    +            gentamicin = susceptibility(GEN),
    +            amoxiclav_genta = susceptibility(AMC, GEN))
     ```
     ```{r, echo = FALSE}
     data_1st %>% 
       group_by(genus) %>% 
    -  summarise(amoxiclav = portion_SI(AMC),
    -            gentamicin = portion_SI(GEN),
    -            amoxiclav_genta = portion_SI(AMC, GEN)) %>% 
    +  summarise(amoxiclav = susceptibility(AMC),
    +            gentamicin = susceptibility(GEN),
    +            amoxiclav_genta = susceptibility(AMC, GEN)) %>% 
       knitr::kable(align = "c", big.mark = ",")
     ```
     
    @@ -380,9 +382,9 @@ To make a transition to the next part, let's see how this difference could be pl
     ```{r plot 1}
     data_1st %>% 
       group_by(genus) %>% 
    -  summarise("1. Amoxi/clav" = portion_SI(AMC),
    -            "2. Gentamicin" = portion_SI(GEN),
    -            "3. Amoxi/clav + genta" = portion_SI(AMC, GEN)) %>% 
    +  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,
    @@ -408,7 +410,7 @@ ggplot(a_data_set) +
       geom_bar(aes(year))
     ```
     
    -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:
    +The `AMR` package contains functions to extend this `ggplot2` package, for example `geom_rsi()`. It automatically transforms data with `count_df()` or `proportion_df()` and show results in stacked bars. Its simplest and shortest example:
     
     ```{r plot 3}
     ggplot(data_1st) +