1
0
mirror of https://github.com/msberends/AMR.git synced 2025-07-11 05:02:06 +02:00

allow column name for ab in as.sir()

This commit is contained in:
2024-05-20 21:29:13 +02:00
parent fc269e667d
commit d214f74e25
10 changed files with 139 additions and 106 deletions

View File

@ -135,13 +135,20 @@ sir_calc <- function(...,
x_transposed <- as.list(as.data.frame(t(x), stringsAsFactors = FALSE))
if (isTRUE(only_all_tested)) {
get_integers <- function(x) {
ints <- rep(NA_integer_, length(x))
ints[x == "S"] <- 1L
ints[x %in% c("SDD", "I")] <- 2L
ints[x == "R"] <- 3L
ints
}
# no NAs in any column
y <- apply(
X = as.data.frame(lapply(x, as.integer), stringsAsFactors = FALSE),
X = as.data.frame(lapply(x, get_integers), stringsAsFactors = FALSE),
MARGIN = 1,
FUN = min
)
numerator <- sum(as.integer(y) %in% as.integer(ab_result), na.rm = TRUE)
numerator <- sum(!is.na(y) & y %in% get_integers(ab_result), na.rm = TRUE)
denominator <- sum(vapply(FUN.VALUE = logical(1), x_transposed, function(y) !(anyNA(y))))
} else {
# may contain NAs in any column
@ -359,6 +366,8 @@ sir_calc_df <- function(type, # "proportion", "count" or "both"
# the same data structure as output, regardless of input
out$interpretation <- factor(out$interpretation, levels = c("S", "SDD", "I", "R", "N"), ordered = TRUE)
}
out <- out[!is.na(out$interpretation), , drop = FALSE]
if (data_has_groups) {
# ordering by the groups and two more: "antibiotic" and "interpretation"