mirror of
https://github.com/msberends/AMR.git
synced 2025-07-09 14:21:51 +02:00
(v0.7.1.9006) new rsi calculations, atc class removal
This commit is contained in:
2
R/freq.R
2
R/freq.R
@ -318,7 +318,7 @@ freq <- function(x,
|
||||
df <- df %>%
|
||||
ungroup() %>%
|
||||
# do not repeat group labels
|
||||
mutate_at(vars(x.group), funs(ifelse(lag(.) == ., "", .)))
|
||||
mutate_at(vars(x.group), ~(ifelse(lag(.) == ., "", .)))
|
||||
df[1, 1] <- df.topleft
|
||||
colnames(df)[1:2] <- c("group", "item")
|
||||
|
||||
|
@ -30,7 +30,7 @@ globalVariables(c(".",
|
||||
"count.x",
|
||||
"date_lab",
|
||||
"diff.percent",
|
||||
"First",
|
||||
"First name",
|
||||
"first_isolate_row_index",
|
||||
"fullname",
|
||||
"fullname_lower",
|
||||
@ -46,7 +46,7 @@ globalVariables(c(".",
|
||||
"key_ab_other",
|
||||
"kingdom",
|
||||
"lang",
|
||||
"Last",
|
||||
"Last name",
|
||||
"lookup",
|
||||
"mdr",
|
||||
"median",
|
||||
@ -56,8 +56,6 @@ globalVariables(c(".",
|
||||
"mono_count",
|
||||
"more_than_episode_ago",
|
||||
"name",
|
||||
"name",
|
||||
"name",
|
||||
"new",
|
||||
"observations",
|
||||
"observed",
|
||||
|
3
R/mo.R
3
R/mo.R
@ -135,6 +135,7 @@
|
||||
#' @inheritSection AMR Read more on our website!
|
||||
#' @importFrom dplyr %>% pull left_join
|
||||
#' @examples
|
||||
#' \donttest{
|
||||
#' # These examples all return "B_STPHY_AUR", the ID of S. aureus:
|
||||
#' as.mo("sau") # WHONET code
|
||||
#' as.mo("stau")
|
||||
@ -169,7 +170,7 @@
|
||||
#' # All mo_* functions use as.mo() internally too (see ?mo_property):
|
||||
#' mo_genus("E. coli") # returns "Escherichia"
|
||||
#' mo_gramstain("E. coli") # returns "Gram negative"#'
|
||||
#'
|
||||
#' }
|
||||
#' \dontrun{
|
||||
#' df$mo <- as.mo(df$microorganism_name)
|
||||
#'
|
||||
|
@ -36,7 +36,7 @@
|
||||
#' @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.
|
||||
#'
|
||||
#' 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. \emph{Low counts can infuence the outcome - these \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 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).}
|
||||
#'
|
||||
#' 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"}.
|
||||
#'
|
||||
@ -70,12 +70,12 @@
|
||||
#' -------------------------------------------------------------------------
|
||||
#' }
|
||||
#'
|
||||
#' Please note that for \code{only_all_tested = TRUE} applies that:
|
||||
#' 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
|
||||
#' }
|
||||
#' and that for \code{only_all_tested = FALSE} applies that:
|
||||
#' 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
|
||||
|
@ -166,7 +166,7 @@ resistance_predict <- function(x,
|
||||
df <- x %>%
|
||||
mutate_at(col_ab, as.rsi) %>%
|
||||
mutate_at(col_ab, droplevels) %>%
|
||||
mutate_at(col_ab, funs(
|
||||
mutate_at(col_ab, ~(
|
||||
if (I_as_S == TRUE) {
|
||||
gsub("I", "S", .)
|
||||
} else {
|
||||
|
12
R/rsi_calc.R
12
R/rsi_calc.R
@ -120,9 +120,15 @@ rsi_calc <- function(...,
|
||||
#numerator <- x %>% filter_all(any_vars(. %in% ab_result)) %>% nrow()
|
||||
if (only_all_tested == TRUE) {
|
||||
# THE NUMBER OF ISOLATES WHERE *ALL* ABx ARE S/I/R
|
||||
x_filtered <- x %>% filter_all(all_vars(!is.na(.)))
|
||||
numerator <- x_filtered %>% filter_all(any_vars(. %in% ab_result)) %>% nrow()
|
||||
denominator <- x_filtered %>% nrow()
|
||||
# x_filtered <- x %>% filter_all(all_vars(!is.na(.)))
|
||||
# numerator <- x_filtered %>% filter_all(any_vars(. %in% ab_result)) %>% nrow()
|
||||
# denominator <- x_filtered %>% nrow()
|
||||
x <- apply(X = x %>% mutate_all(as.integer),
|
||||
MARGIN = 1,
|
||||
FUN = base::min)
|
||||
numerator <- sum(as.integer(x) %in% as.integer(ab_result), na.rm = TRUE)
|
||||
denominator <- length(x) - sum(is.na(x))
|
||||
|
||||
} else {
|
||||
# THE NUMBER OF ISOLATES WHERE *ANY* ABx IS S/I/R
|
||||
other_values <- base::setdiff(c(NA, levels(ab_result)), ab_result)
|
||||
|
Reference in New Issue
Block a user