mirror of
https://github.com/msberends/AMR.git
synced 2025-07-09 04:02:19 +02:00
(v0.8.0.9027) adding susceptibility() and resistance()
This commit is contained in:
16
R/amr.R
16
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:
|
||||
#'
|
||||
|
@ -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)] <- ""
|
||||
|
83
R/count.R
83
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,
|
||||
|
@ -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(...)
|
||||
}
|
||||
|
4
R/freq.R
4
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)))
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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,
|
2
R/rsi.R
2
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
|
||||
|
100
R/rsi_calc.R
100
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
|
||||
}
|
||||
|
30
R/rsi_df.R
30
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)
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user