1
0
mirror of https://github.com/msberends/AMR.git synced 2026-06-24 03:36:21 +02:00

(v3.0.1.9059) Fix WISCA in vignette

This commit is contained in:
2026-06-23 14:38:59 +02:00
parent 3f9f931777
commit 9898b5df4b
41 changed files with 1310 additions and 757 deletions

View File

@@ -73,4 +73,4 @@ License: GPL-2 | file LICENSE
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.3.3
Roxygen: list(markdown = TRUE, old_usage = TRUE)
Roxygen: list(markdown = TRUE)

View File

@@ -17,7 +17,7 @@ Planned as v3.1.0, end of June 2026.
* New `morphology` column in the `microorganisms` data set and corresponding `mo_morphology()` function, returning the cell shape of bacteria. Data sourced from BacDive; values prefixed with "likely" are extrapolated from genus-level consensus. New `add_morphology` argument was added to `mo_gramstain()` to return combined results such as `"Gram-negative rods"`.
* New `amr_course()` to download and unpack course or webinar materials from GitHub in one call
* Typed missing value constants `NA_ab_` and `NA_mo_`, for use in pipelines that need missing values of a specific class
* New function `wisca_plot()` to assess the susceptibility and incidence distributions from the Monte Carlo simulations
* New `wisca_plot()` to assess the susceptibility and incidence distributions from the Monte Carlo simulations
### Fixed
* `as.sir()`

View File

@@ -400,6 +400,51 @@
#' plot(ab1)
#' plot(ab2)
#' }
wisca <- function(x,
antimicrobials = where(is.sir),
ab_transform = "name",
syndromic_group = NULL,
only_all_tested = FALSE,
digits = 1,
formatting_type = getOption("AMR_antibiogram_formatting_type", 14),
col_mo = NULL,
language = get_AMR_locale(),
combine_SI = TRUE,
sep = " + ",
sort_columns = TRUE,
simulations = 1000,
conf_interval = 0.95,
interval_side = "two-tailed",
info = interactive(),
parallel = FALSE,
...) {
stop_ifnot(is.null(mo_transform), "{.arg mo_transform} must not be set if creating a WISCA; the incidence of the different species are already modelled into WISCA and cannot be taken separately.", call = FALSE)
antibiogram(
x = x,
antimicrobials = antimicrobials,
ab_transform = ab_transform,
syndromic_group = syndromic_group,
add_total_n = FALSE,
only_all_tested = only_all_tested,
digits = digits,
formatting_type = formatting_type,
col_mo = col_mo,
language = language,
combine_SI = combine_SI,
sep = sep,
sort_columns = sort_columns,
wisca = TRUE,
simulations = simulations,
conf_interval = conf_interval,
interval_side = interval_side,
info = info,
parallel = parallel,
...
)
}
#' @export
#' @rdname antibiogram
antibiogram <- function(x,
antimicrobials = where(is.sir),
mo_transform = "shortname",
@@ -489,6 +534,24 @@ antibiogram.default <- function(x,
meet_criteria(info, allow_class = "logical", has_length = 1)
meet_criteria(parallel, allow_class = "logical", has_length = 1)
# get syndromic groups
if (!is.null(syndromic_group)) {
if (length(syndromic_group) == 1 && syndromic_group %in% colnames(x)) {
x$`.syndromic_group` <- x[, syndromic_group, drop = TRUE]
} else if (length(syndromic_group) > 1 && all(syndromic_group %in% colnames(x))) {
x$`.syndromic_group` <- do.call(paste, c(x[syndromic_group], list(sep = "||")))
attr(x, "antibiogram_groups") <- syndromic_group
} else if (!is.null(syndromic_group) && length(syndromic_group) == 1) {
x$`.syndromic_group` <- syndromic_group
} else {
stop_("{.arg syndromic_group} should be a 1-dimensional computed value, or 1 or more column names of {.arg x}.")
}
x$`.syndromic_group`[is.na(x$`.syndromic_group`) | x$`.syndromic_group` == ""] <- paste0("(", translate_AMR("unknown", language = language), ")")
has_syndromic_group <- TRUE
} else {
has_syndromic_group <- FALSE
}
# parallel gate - identical pattern to as.sir()
if (requireNamespace("future.apply", quietly = TRUE)) {
if (!inherits(future::plan(), "sequential")) {
@@ -497,10 +560,14 @@ antibiogram.default <- function(x,
}
parallel <- TRUE
}
if (wisca && interactive() && inherits(future::plan(), "sequential") && isFALSE(parallel) && simulations > 100) {
if (wisca && interactive() && message_not_thrown_before("antibiogram", "wisca_parallel") && inherits(future::plan(), "sequential") && isFALSE(parallel) && simulations > 100) {
advised_multi <- ifelse(.Platform$OS.type == "windows" || in_rstudio(), "multisession", "multicore")
sims <- simulations * length(antimicrobials)
if (has_syndromic_group) {
sims <- sims * length(unique(x$`.syndromic_group`))
}
message_("Are you sure you want to run in non-parallel (=sequential) mode?", as_note = FALSE)
message_("WISCA can take a long time for the ", simulations * length(antimicrobials), " simulations you require, and you already have the {.pkg future} package installed.", as_note = FALSE)
message_("WISCA can take a ", ifelse(sims > 10000, font_bold("very "), ""), "long time for the ", format(sims, decimal.mark = ".", big.mark = " "), " simulations you require, and you already have the {.pkg future} package installed.", as_note = FALSE)
q <- utils::menu(c(
"Yes, still run in sequential mode",
format_inline_("No, run in parallel mode and set {.help [future::plan(", advised_multi, ")](future::plan)}, and reset after WISCA finishes"),
@@ -511,17 +578,30 @@ antibiogram.default <- function(x,
return(invisible(NULL))
} else if (q %in% c(2, 3)) {
parallel <- TRUE
AMR_env$wisca_parallel_choice <- "parallel"
obj <- get(advised_multi, envir = asNamespace("future"))
future::plan(obj)
if (q == 2) {
on.exit({
# clean-up parallel setting
message_("Resetting {.fn future::plan}...", as_note = FALSE)
future::plan(future::sequential)
message_("Parallel setting was reset to `future::plan(future::sequential)`.", as_check = TRUE)
})
AMR_env$wisca_parallel_choice <- "parallel_reset"
}
} else {
AMR_env$wisca_parallel_choice <- "sequential"
}
} else if (wisca && !is.null(AMR_env$wisca_parallel_choice)) {
if (AMR_env$wisca_parallel_choice %in% c("parallel", "parallel_reset")) {
parallel <- TRUE
}
}
if (identical(AMR_env$wisca_parallel_choice, "parallel_reset") && inherits(future::plan(), "uniprocess", which = FALSE) == FALSE) {
on.exit(
{
message_("Resetting {.fn future::plan}...", as_note = FALSE)
future::plan(future::sequential)
AMR_env$wisca_parallel_choice <- NULL
message_("Parallel setting was reset to `future::plan(future::sequential)`.", as_check = TRUE)
},
add = TRUE
)
}
}
if (isTRUE(parallel)) {
@@ -574,19 +654,6 @@ antibiogram.default <- function(x,
}
x$`.mo`[x$`.mo` %in% c(NA, "UNKNOWN")] <- "(??)"
# get syndromic groups
if (!is.null(syndromic_group)) {
if (length(syndromic_group) == 1 && syndromic_group %in% colnames(x)) {
x$`.syndromic_group` <- x[, syndromic_group, drop = TRUE]
} else if (!is.null(syndromic_group)) {
x$`.syndromic_group` <- syndromic_group
}
x$`.syndromic_group`[is.na(x$`.syndromic_group`) | x$`.syndromic_group` == ""] <- paste0("(", translate_AMR("unknown", language = language), ")")
has_syndromic_group <- TRUE
} else {
has_syndromic_group <- FALSE
}
# get antimicrobials
ab_trycatch <- tryCatch(colnames(suppressWarnings(x[, antimicrobials, drop = FALSE])), error = function(e) NULL)
if (is.null(ab_trycatch)) {
@@ -1127,12 +1194,21 @@ antibiogram.default <- function(x,
}
if (wisca) {
names(wisca_draws) <- out$ab
names(wisca_components) <- out$ab
names(wisca_draws) <- out$ab[!is.na(out$out_value)]
names(wisca_components) <- out$ab[!is.na(out$out_value)]
}
if (!is.null(attr(x, "antibiogram_groups", exact = TRUE))) {
new_df <- as.data.frame(new_df)
grps <- attr(x, "antibiogram_groups", exact = TRUE)
parts <- strsplit(new_df[[1]], "||", fixed = TRUE)
new_cols <- do.call(rbind, parts)
colnames(new_cols) <- grps
new_df <- cbind(as.data.frame(new_cols), new_df[-1])
}
out <- structure(as_original_data_class(new_df, class(x), extra_class = "antibiogram"),
has_syndromic_group = has_syndromic_group,
antibiogram_groups = attr(x, "antibiogram_groups", exact = TRUE),
combine_SI = combine_SI,
wisca = wisca,
conf_interval = conf_interval,
@@ -1174,200 +1250,29 @@ antibiogram.grouped_df <- function(x,
...) {
stop_ifnot(is.null(mo_transform), "{.arg mo_transform} must not be set if creating an antibiogram using a grouped tibble. The groups will become the variables over which the antimicrobials are calculated, which could include the pathogen information (though not necessary). Nonetheless, this makes {.arg mo_transform} redundant.", call = FALSE)
stop_ifnot(is.null(syndromic_group), "{.arg syndromic_group} must not be set if creating an antibiogram using a grouped tibble. The groups will become the variables over which the antimicrobials are calculated, making {.arg syndromic_group} redundant.", call = FALSE)
meet_criteria(parallel, allow_class = "logical", has_length = 1)
meet_criteria(wisca, allow_class = "logical", has_length = 1)
groups <- attributes(x)$groups
n_groups <- NROW(groups)
group_cols <- intersect(colnames(groups), colnames(x))
# paste group together, will be split later in antibiogram.default()
x$.group <- do.call(paste, c(x[group_cols], list(sep = "||")))
attr(x, "antibiogram_groups") <- group_cols
# parallel gate - identical pattern to as.sir()
if (requireNamespace("future.apply", quietly = TRUE) && !inherits(future::plan(), "sequential")) {
if (isFALSE(parallel)) {
message_("Assuming {.code parallel = TRUE} since parallel computing has been set up using the {.pkg future} package before. Set {.help [{.fun plan}](future::plan)} to sequential to prevent this.")
}
parallel <- TRUE
}
if (isTRUE(parallel)) {
stop_ifnot(
requireNamespace("future.apply", quietly = TRUE),
"Setting {.code parallel = TRUE} requires the {.pkg future.apply} package.\n",
"Install it with {.code install.packages(\"future.apply\")}."
)
stop_if(inherits(future::plan(), "sequential"),
"Setting {.code parallel = TRUE} requires a non-sequential {.help [{.fun future::plan}](future::plan)} to be active.\n",
"For your system, you could first run: {.code library(future); ",
ifelse(.Platform$OS.type == "windows" || in_rstudio(),
"plan(multisession)",
"plan(multicore)"
),
"}",
call = FALSE
)
n_workers <- future::nbrOfWorkers()
} else {
n_workers <- 1L
}
use_parallel <- isTRUE(parallel) && n_workers > 1L && n_groups > 1L
x_df <- as.data.frame(x)
run_group <- function(i) {
rows <- unlist(groups[i, ]$.rows)
if (length(rows) == 0L) {
return(NULL)
}
antibiogram(x_df[rows, , drop = FALSE],
antimicrobials = antimicrobials,
mo_transform = NULL,
ab_transform = ab_transform,
syndromic_group = NULL,
add_total_n = add_total_n,
only_all_tested = only_all_tested,
digits = digits,
formatting_type = formatting_type,
col_mo = col_mo,
language = language,
minimum = minimum,
combine_SI = combine_SI,
sep = sep,
sort_columns = sort_columns,
wisca = wisca,
simulations = simulations,
conf_interval = conf_interval,
interval_side = interval_side,
info = FALSE,
parallel = FALSE # never nest parallelism in workers
)
}
if (use_parallel) {
if (isTRUE(info)) {
message_("Running antibiogram for ", n_groups, " groups in parallel using ", n_workers, " workers...", as_note = FALSE, appendLF = FALSE)
}
results_raw <- future.apply::future_lapply(seq_len(n_groups), run_group, future.seed = TRUE)
if (isTRUE(info)) message_(font_green_bg(" DONE "), as_note = FALSE)
} else {
progress <- progress_ticker(
n = n_groups,
n_min = 5,
print = info,
title = paste("Calculating AMR for", n_groups, "groups")
)
on.exit(close(progress), add = TRUE)
results_raw <- vector("list", n_groups)
for (i in seq_len(n_groups)) {
progress$tick()
results_raw[[i]] <- run_group(i)
}
close(progress)
}
out <- NULL
wisca_parameters <- NULL
long_numeric <- NULL
for (i in seq_len(n_groups)) {
new_out <- results_raw[[i]]
new_wisca_parameters <- attributes(new_out)$wisca_parameters
new_long_numeric <- attributes(new_out)$long_numeric
if (is.null(new_out) || NROW(new_out) == 0) {
next
}
# remove first column 'Pathogen' (in whatever language), except WISCA since that never has Pathogen column
if (isFALSE(wisca)) {
new_out <- new_out[, -1, drop = FALSE]
new_long_numeric <- new_long_numeric[, -1, drop = FALSE]
}
# add group names to data set
for (col in rev(seq_len(NCOL(groups) - 1))) {
col_name <- colnames(groups)[col]
col_value <- groups[i, col, drop = TRUE]
new_out[, col_name] <- col_value
new_out <- new_out[, c(col_name, setdiff(names(new_out), col_name))] # set place to 1st col
if (wisca) {
new_wisca_parameters[, col_name] <- col_value
new_wisca_parameters <- new_wisca_parameters[, c(col_name, setdiff(names(new_wisca_parameters), col_name))] # set place to 1st col
}
new_long_numeric[, col_name] <- col_value
new_long_numeric <- new_long_numeric[, c(col_name, setdiff(names(new_long_numeric), col_name))] # set place to 1st col
}
if (is.null(out)) {
out <- new_out
wisca_parameters <- new_wisca_parameters
long_numeric <- new_long_numeric
} else {
out <- rbind_AMR(out, new_out)
wisca_parameters <- rbind_AMR(wisca_parameters, new_wisca_parameters)
long_numeric <- rbind_AMR(long_numeric, new_long_numeric)
}
}
wisca_draws_all <- NULL
wisca_components_all <- NULL
if (wisca) {
wisca_draws_all <- unlist(lapply(results_raw, function(r) attributes(r)$wisca_draws), recursive = FALSE)
wisca_components_all <- unlist(lapply(results_raw, function(r) attributes(r)$wisca_components), recursive = FALSE)
}
out <- structure(as_original_data_class(out, class(x), extra_class = "antibiogram"),
has_syndromic_group = FALSE,
combine_SI = isTRUE(combine_SI),
wisca = wisca,
conf_interval = conf_interval,
simulations = if (isFALSE(wisca)) NULL else simulations,
formatting_type = formatting_type,
sep = sep,
wisca_parameters = if (isFALSE(wisca)) NULL else as_original_data_class(wisca_parameters, class(x)),
long_numeric = as_original_data_class(long_numeric, class(x)),
wisca_draws = if (isFALSE(wisca)) NULL else wisca_draws_all,
wisca_components = if (isFALSE(wisca)) NULL else wisca_components_all
)
rownames(out) <- NULL
out
}
#' @export
#' @rdname antibiogram
wisca <- function(x,
antimicrobials = where(is.sir),
ab_transform = "name",
syndromic_group = NULL,
only_all_tested = FALSE,
digits = 1,
formatting_type = getOption("AMR_antibiogram_formatting_type", 14),
col_mo = NULL,
language = get_AMR_locale(),
combine_SI = TRUE,
sep = " + ",
sort_columns = TRUE,
simulations = 1000,
conf_interval = 0.95,
interval_side = "two-tailed",
info = interactive(),
parallel = FALSE,
...) {
antibiogram(
x = x,
antibiogram.default(x,
antimicrobials = antimicrobials,
mo_transform = mo_transform,
ab_transform = ab_transform,
mo_transform = NULL,
syndromic_group = syndromic_group,
add_total_n = FALSE,
syndromic_group = ".group",
add_total_n = add_total_n,
only_all_tested = only_all_tested,
digits = digits,
formatting_type = formatting_type,
col_mo = col_mo,
language = language,
minimum = minimum,
combine_SI = combine_SI,
sep = sep,
sort_columns = sort_columns,
wisca = TRUE,
wisca = wisca,
simulations = simulations,
conf_interval = conf_interval,
interval_side = interval_side,
@@ -1480,7 +1385,7 @@ tbl_format_footer.antibiogram <- function(x, ...) {
return(footer)
}
wisca_text <- ifelse(isTRUE(attributes(x)$wisca),
paste0("\n# ", font_bold("Be aware"), " that in a WISCA, overlapping CIs indicate ", font_bold("non-inferiority"), "."),
paste0("\n# ", font_bold("Be aware"), " that in a WISCA, overlapping CIs indicate non-inferiority."),
""
)
c(footer, font_subtle(paste0(
@@ -1577,10 +1482,17 @@ autoplot.antibiogram <- function(object,
group_name <- paste(groups, collapse = "/")
if (length(groups) > 1) {
df$syndromic_group <- apply(df[groups], 1, function(x) {
paste(stats::na.omit(x), collapse = "/")
paste(stats::na.omit(x), collapse = " / ")
})
} else if ("syndromic_group" %in% colnames(df)) {
group_name <- colnames(object)[1]
if (is.null(attributes(object)$antibiogram_groups)) {
# translated value of "Syndromic group"
group_name <- colnames(object)[1]
} else {
# multiple groups, created with a grouped tibble or when syndromic_group was length >1
group_name <- paste0(attributes(object)$antibiogram_groups, collapse = " / ")
df$syndromic_group <- gsub("||", " / ", df$syndromic_group, fixed = TRUE)
}
}
has_syndromic <- "syndromic_group" %in% colnames(df)
has_facet <- !all(as.character(df$mo) == "", na.rm = TRUE)
@@ -1694,6 +1606,7 @@ wisca_plot <- function(wisca_model,
isTRUE(attributes(wisca_model)$wisca),
"This function only applies to WISCA models."
)
meet_criteria(wisca_plot_type, allow_class = "character", has_length = 1, is_in = c("susceptibility_incidence", "posterior_coverage"))
wisca_plot_type <- match.arg(wisca_plot_type)
sep <- attributes(wisca_model)$sep %||% " + "
@@ -1791,7 +1704,7 @@ plot_wisca_susceptibility_incidence <- function(wisca_model, sep) {
label_order <- vapply(draw_order, function(g) {
if (!is.null(sep)) gsub(sep, paste0(trimws(sep, which = "right"), "\n"), g, fixed = TRUE) else g
}, character(1))
label_order <- label_order[label_order %in% reg_labels]
label_order <- unique(label_order[label_order %in% reg_labels])
df$regimen <- factor(df$regimen, levels = label_order)
}

Binary file not shown.

View File

@@ -120,14 +120,13 @@ all_disk_predictors <- function() {
#' @rdname amr-tidymodels
#' @export
step_mic_log2 <- function(
recipe,
...,
role = NA,
trained = FALSE,
columns = NULL,
skip = FALSE,
id = recipes::rand_id("mic_log2")
) {
recipe,
...,
role = NA,
trained = FALSE,
columns = NULL,
skip = FALSE,
id = recipes::rand_id("mic_log2")) {
recipes::add_step(
recipe,
step_mic_log2_new(
@@ -196,14 +195,13 @@ tidy.step_mic_log2 <- function(x, ...) {
#' @rdname amr-tidymodels
#' @export
step_sir_numeric <- function(
recipe,
...,
role = NA,
trained = FALSE,
columns = NULL,
skip = FALSE,
id = recipes::rand_id("sir_numeric")
) {
recipe,
...,
role = NA,
trained = FALSE,
columns = NULL,
skip = FALSE,
id = recipes::rand_id("sir_numeric")) {
recipes::add_step(
recipe,
step_sir_numeric_new(

Binary file not shown.

Binary file not shown.

118
index.md
View File

@@ -26,9 +26,12 @@
<div style="display: flex; font-size: 0.8em;">
<p style="text-align:left; width: 50%;">
<small><a href="https://amr-for-r.org/">amr-for-r.org</a></small>
</p>
<p style="text-align:right; width: 50%;">
<small><a href="https://doi.org/10.18637/jss.v104.i03" target="_blank">doi.org/10.18637/jss.v104.i03</a></small>
</p>
@@ -171,26 +174,24 @@ example_isolates %>%
#> Using column mo as input for `mo_fullname()`
#> Using column mo as input for `mo_is_gram_negative()`
#> Using column mo as input for `mo_is_intrinsic_resistant()`
#> Determining intrinsic resistance based on 'EUCAST Expected
#> Resistant Phenotypes' v1.2 (2023). This note will be shown
#> once per session.
#> For `aminoglycosides()` using columns GEN (gentamicin), TOB
#> (tobramycin), AMK (amikacin), and KAN (kanamycin)
#> For `carbapenems()` using columns IPM (imipenem) and MEM
#> (meropenem)
#> Determining intrinsic resistance based on 'EUCAST Expected Resistant
#> Phenotypes' v1.2 (2023). This note will be shown once per session.
#> For `aminoglycosides()` using columns GEN (gentamicin), TOB (tobramycin), AMK
#> (amikacin), and KAN (kanamycin)
#> For `carbapenems()` using columns IPM (imipenem) and MEM (meropenem)
#> # A tibble: 35 × 7
#> bacteria GEN TOB AMK KAN IPM MEM
#> <chr> <sir> <sir> <sir> <sir> <sir> <sir>
#> 1 Pseudomonas aer I S NA R S NA
#> 2 Pseudomonas aer I S NA R S NA
#> 3 Pseudomonas aer I S NA R S NA
#> 4 Pseudomonas aer S S S R NA S
#> 5 Pseudomonas aer S S S R S S
#> 6 Pseudomonas aer S S S R S S
#> 7 Stenotrophomona R R R R R R
#> 8 Pseudomonas aer S S S R NA S
#> 9 Pseudomonas aer S S S R NA S
#> 10 Pseudomonas aer S S S R S S
#> bacteria GEN TOB AMK KAN IPM MEM
#> <chr> <sir> <sir> <sir> <sir> <sir> <sir>
#> 1 Pseudomonas aeruginosa I S NA R S NA
#> 2 Pseudomonas aeruginosa I S NA R S NA
#> 3 Pseudomonas aeruginosa I S NA R S NA
#> 4 Pseudomonas aeruginosa S S S R NA S
#> 5 Pseudomonas aeruginosa S S S R S S
#> 6 Pseudomonas aeruginosa S S S R S S
#> 7 Stenotrophomonas maltophilia R R R R R R
#> 8 Pseudomonas aeruginosa S S S R NA S
#> 9 Pseudomonas aeruginosa S S S R NA S
#> 10 Pseudomonas aeruginosa S S S R S S
#> # 25 more rows
```
@@ -214,24 +215,23 @@ output format automatically (such as markdown, LaTeX, HTML, etc.).
``` r
antibiogram(example_isolates,
antimicrobials = c(aminoglycosides(), carbapenems()))
#> For `aminoglycosides()` using columns GEN (gentamicin), TOB
#> (tobramycin), AMK (amikacin), and KAN (kanamycin)
#> For `carbapenems()` using columns IPM (imipenem) and MEM
#> (meropenem)
#> For `aminoglycosides()` using columns GEN (gentamicin), TOB (tobramycin), AMK
#> (amikacin), and KAN (kanamycin)
#> For `carbapenems()` using columns IPM (imipenem) and MEM (meropenem)
```
| Pathogen | Amikacin | Gentamicin | Imipenem | Kanamycin | Meropenem | Tobramycin |
|:-----------------|:---------------------|:--------------------|:---------------------|:----------------|:---------------------|:--------------------|
| CoNS | 0% (0-8%,N=43) | 86% (82-90%,N=309) | 52% (37-67%,N=48) | 0% (0-8%,N=43) | 52% (37-67%,N=48) | 22% (12-35%,N=55) |
| *E. coli* | 100% (98-100%,N=171) | 98% (96-99%,N=460) | 100% (99-100%,N=422) | NA | 100% (99-100%,N=418) | 97% (96-99%,N=462) |
| *E. faecalis* | 0% (0-9%,N=39) | 0% (0-9%,N=39) | 100% (91-100%,N=38) | 0% (0-9%,N=39) | NA | 0% (0-9%,N=39) |
| *K. pneumoniae* | NA | 90% (79-96%,N=58) | 100% (93-100%,N=51) | NA | 100% (93-100%,N=53) | 90% (79-96%,N=58) |
| *P. aeruginosa* | NA | 100% (88-100%,N=30) | NA | 0% (0-12%,N=30) | NA | 100% (88-100%,N=30) |
| *P. mirabilis* | NA | 94% (80-99%,N=34) | 94% (79-99%,N=32) | NA | NA | 94% (80-99%,N=34) |
| *S. aureus* | NA | 99% (97-100%,N=233) | NA | NA | NA | 98% (92-100%,N=86) |
| *S. epidermidis* | 0% (0-8%,N=44) | 79% (71-85%,N=163) | NA | 0% (0-8%,N=44) | NA | 51% (40-61%,N=89) |
| *S. hominis* | NA | 92% (84-97%,N=80) | NA | NA | NA | 85% (74-93%,N=62) |
| *S. pneumoniae* | 0% (0-3%,N=117) | 0% (0-3%,N=117) | NA | 0% (0-3%,N=117) | NA | 0% (0-3%,N=117) |
| Pathogen | Amikacin | Gentamicin | Imipenem | Kanamycin | Meropenem | Tobramycin |
|:---|:---|:---|:---|:---|:---|:---|
| CoNS | 0% (0-8%,N=43) | 86% (82-90%,N=309) | 52% (37-67%,N=48) | 0% (0-8%,N=43) | 52% (37-67%,N=48) | 22% (12-35%,N=55) |
| *E. coli* | 100% (98-100%,N=171) | 98% (96-99%,N=460) | 100% (99-100%,N=422) | NA | 100% (99-100%,N=418) | 97% (96-99%,N=462) |
| *E. faecalis* | 0% (0-9%,N=39) | 0% (0-9%,N=39) | 100% (91-100%,N=38) | 0% (0-9%,N=39) | NA | 0% (0-9%,N=39) |
| *K. pneumoniae* | NA | 90% (79-96%,N=58) | 100% (93-100%,N=51) | NA | 100% (93-100%,N=53) | 90% (79-96%,N=58) |
| *P. aeruginosa* | NA | 100% (88-100%,N=30) | NA | 0% (0-12%,N=30) | NA | 100% (88-100%,N=30) |
| *P. mirabilis* | NA | 94% (80-99%,N=34) | 94% (79-99%,N=32) | NA | NA | 94% (80-99%,N=34) |
| *S. aureus* | NA | 99% (97-100%,N=233) | NA | NA | NA | 98% (92-100%,N=86) |
| *S. epidermidis* | 0% (0-8%,N=44) | 79% (71-85%,N=163) | NA | 0% (0-8%,N=44) | NA | 51% (40-61%,N=89) |
| *S. hominis* | NA | 92% (84-97%,N=80) | NA | NA | NA | 85% (74-93%,N=62) |
| *S. pneumoniae* | 0% (0-3%,N=117) | 0% (0-3%,N=117) | NA | 0% (0-3%,N=117) | NA | 0% (0-3%,N=117) |
In combination antibiograms, it is clear that combined antimicrobials
yield higher empiric coverage:
@@ -242,10 +242,10 @@ antibiogram(example_isolates,
mo_transform = "gramstain")
```
| Pathogen | Piperacillin/tazobactam | Piperacillin/tazobactam + Gentamicin | Piperacillin/tazobactam + Tobramycin |
|:--------------|:------------------------|:-------------------------------------|:-------------------------------------|
| Gram-negative | 88% (85-91%,N=641) | 99% (97-99%,N=691) | 98% (97-99%,N=693) |
| Gram-positive | 86% (82-89%,N=345) | 98% (96-98%,N=1044) | 95% (93-97%,N=550) |
| Pathogen | Piperacillin/tazobactam | Piperacillin/tazobactam + Gentamicin | Piperacillin/tazobactam + Tobramycin |
|:---|:---|:---|:---|
| Gram-negative | 88% (85-91%,N=641) | 99% (97-99%,N=691) | 98% (97-99%,N=693) |
| Gram-positive | 86% (82-89%,N=345) | 98% (96-98%,N=1044) | 95% (93-97%,N=550) |
Like many other functions in this package, `antibiogram()` comes with
support for 28 languages that are often detected automatically based on
@@ -318,18 +318,16 @@ example_isolates %>%
summarise(across(c(GEN, TOB),
list(total_R = resistance,
conf_int = function(x) sir_confidence_interval(x, collapse = "-"))))
#> `resistance()` assumes the EUCAST guideline and thus
#> considers the 'I' category susceptible. Set the `guideline`
#> argument or the `AMR_guideline` option to either "CLSI" or
#> "EUCAST", see `?AMR-options`.
#> `resistance()` assumes the EUCAST guideline and thus considers the 'I'
#> category susceptible. Set the `guideline` argument or the `AMR_guideline`
#> option to either "CLSI" or "EUCAST", see `?AMR-options`.
#> This message will be shown once per session.
#> # A tibble: 3 × 5
#> ward GEN_total_R GEN_conf_int TOB_total_R
#> <chr> <dbl> <chr> <dbl>
#> 1 Clinical 0.229 0.205-0.254 0.315
#> 2 ICU 0.290 0.253-0.33 0.400
#> 3 Outpatient 0.2 0.131-0.285 0.368
#> # 1 more variable: TOB_conf_int <chr>
#> ward GEN_total_R GEN_conf_int TOB_total_R TOB_conf_int
#> <chr> <dbl> <chr> <dbl> <chr>
#> 1 Clinical 0.229 0.205-0.254 0.315 0.284-0.347
#> 2 ICU 0.290 0.253-0.33 0.400 0.353-0.449
#> 3 Outpatient 0.2 0.131-0.285 0.368 0.254-0.493
```
Or use [antimicrobial
@@ -346,16 +344,15 @@ out <- example_isolates %>%
# calculate AMR using resistance(), over all aminoglycosides and polymyxins:
summarise(across(c(aminoglycosides(), polymyxins()),
resistance))
#> For `aminoglycosides()` using columns GEN (gentamicin), TOB
#> (tobramycin), AMK (amikacin), and KAN (kanamycin)
#> For `aminoglycosides()` using columns GEN (gentamicin), TOB (tobramycin), AMK
#> (amikacin), and KAN (kanamycin)
#> For `polymyxins()` using column COL (colistin)
#> Warning: There was 1 warning in `summarise()`.
#> In argument: `across(c(aminoglycosides(), polymyxins()),
#> resistance)`.
#> In argument: `across(c(aminoglycosides(), polymyxins()), resistance)`.
#> In group 3: `ward = "Outpatient"`.
#> Caused by warning:
#> ! Introducing NA: only 23 results available for KAN in group:
#> ward = "Outpatient" (whilst `minimum = 30`).
#> ! Introducing NA: only 23 results available for KAN in group: ward = "Outpatient"
#> (whilst `minimum = 30`).
out
#> # A tibble: 3 × 6
#> ward GEN TOB AMK KAN COL
@@ -369,12 +366,11 @@ out
# transform the antibiotic columns to names:
out %>% set_ab_names()
#> # A tibble: 3 × 6
#> ward gentamicin tobramycin amikacin kanamycin
#> <chr> <dbl> <dbl> <dbl> <dbl>
#> 1 Clinical 0.229 0.315 0.626 1
#> 2 ICU 0.290 0.400 0.662 1
#> 3 Outpatient 0.2 0.368 0.605 NA
#> # 1 more variable: colistin <dbl>
#> ward gentamicin tobramycin amikacin kanamycin colistin
#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 Clinical 0.229 0.315 0.626 1 0.780
#> 2 ICU 0.290 0.400 0.662 1 0.857
#> 3 Outpatient 0.2 0.368 0.605 NA 0.889
```
``` r

View File

@@ -4,9 +4,15 @@
\alias{ab_from_text}
\title{Retrieve Antimicrobial Drug Names and Doses from Clinical Text}
\usage{
ab_from_text(text, type = c("drug", "dose", "administration"),
collapse = NULL, translate_ab = FALSE, thorough_search = NULL,
info = interactive(), ...)
ab_from_text(
text,
type = c("drug", "dose", "administration"),
collapse = NULL,
translate_ab = FALSE,
thorough_search = NULL,
info = interactive(),
...
)
}
\arguments{
\item{text}{Text to analyse.}

View File

@@ -47,8 +47,13 @@ ab_url(x, open = FALSE, ...)
ab_property(x, property = "name", language = get_AMR_locale(), ...)
set_ab_names(data, ..., property = "name", language = get_AMR_locale(),
snake_case = NULL)
set_ab_names(
data,
...,
property = "name",
language = get_AMR_locale(),
snake_case = NULL
)
}
\arguments{
\item{x}{Any (vector of) text that can be coerced to a valid antibiotic drug code with \code{\link[=as.ab]{as.ab()}}.}

View File

@@ -4,8 +4,7 @@
\alias{age_groups}
\title{Split Ages into Age Groups}
\usage{
age_groups(x, split_at = c(0, 12, 25, 55, 75), names = NULL,
na.rm = FALSE)
age_groups(x, split_at = c(0, 12, 25, 55, 75), names = NULL, na.rm = FALSE)
}
\arguments{
\item{x}{Age, e.g. calculated with \code{\link[=age]{age()}}.}

View File

@@ -24,11 +24,25 @@ all_disk()
all_disk_predictors()
step_mic_log2(recipe, ..., role = NA, trained = FALSE, columns = NULL,
skip = FALSE, id = recipes::rand_id("mic_log2"))
step_mic_log2(
recipe,
...,
role = NA,
trained = FALSE,
columns = NULL,
skip = FALSE,
id = recipes::rand_id("mic_log2")
)
step_sir_numeric(recipe, ..., role = NA, trained = FALSE, columns = NULL,
skip = FALSE, id = recipes::rand_id("sir_numeric"))
step_sir_numeric(
recipe,
...,
role = NA,
trained = FALSE,
columns = NULL,
skip = FALSE,
id = recipes::rand_id("sir_numeric")
)
}
\arguments{
\item{recipe}{A recipe object. The step will be added to the sequence of

View File

@@ -10,37 +10,78 @@
\alias{knit_print.antibiogram}
\title{Generate Traditional, Combination, Syndromic, or WISCA Antibiograms}
\usage{
antibiogram(x, antimicrobials = where(is.sir), mo_transform = "shortname",
ab_transform = "name", syndromic_group = NULL, add_total_n = FALSE,
only_all_tested = FALSE, digits = ifelse(wisca, 1, 0),
formatting_type = getOption("AMR_antibiogram_formatting_type",
ifelse(wisca, 14, 18)), col_mo = NULL, language = get_AMR_locale(),
minimum = 30, combine_SI = TRUE, sep = " + ", sort_columns = TRUE,
wisca = FALSE, simulations = 1000, conf_interval = 0.95,
interval_side = "two-tailed", info = interactive(), parallel = FALSE,
...)
wisca(x, antimicrobials = where(is.sir), ab_transform = "name",
syndromic_group = NULL, only_all_tested = FALSE, digits = 1,
wisca(
x,
antimicrobials = where(is.sir),
ab_transform = "name",
syndromic_group = NULL,
only_all_tested = FALSE,
digits = 1,
formatting_type = getOption("AMR_antibiogram_formatting_type", 14),
col_mo = NULL, language = get_AMR_locale(), combine_SI = TRUE,
sep = " + ", sort_columns = TRUE, simulations = 1000,
conf_interval = 0.95, interval_side = "two-tailed",
info = interactive(), parallel = FALSE, ...)
col_mo = NULL,
language = get_AMR_locale(),
combine_SI = TRUE,
sep = " + ",
sort_columns = TRUE,
simulations = 1000,
conf_interval = 0.95,
interval_side = "two-tailed",
info = interactive(),
parallel = FALSE,
...
)
antibiogram(
x,
antimicrobials = where(is.sir),
mo_transform = "shortname",
ab_transform = "name",
syndromic_group = NULL,
add_total_n = FALSE,
only_all_tested = FALSE,
digits = ifelse(wisca, 1, 0),
formatting_type = getOption("AMR_antibiogram_formatting_type", ifelse(wisca, 14, 18)),
col_mo = NULL,
language = get_AMR_locale(),
minimum = 30,
combine_SI = TRUE,
sep = " + ",
sort_columns = TRUE,
wisca = FALSE,
simulations = 1000,
conf_interval = 0.95,
interval_side = "two-tailed",
info = interactive(),
parallel = FALSE,
...
)
retrieve_wisca_parameters(wisca_model, ...)
\method{plot}{antibiogram}(x, ...)
\method{autoplot}{antibiogram}(object, geom = c("pointrange", "point", "col",
"bar", "errorbar"), ci = TRUE, sort = TRUE, flip = NULL,
caption = NULL, ...)
\method{autoplot}{antibiogram}(
object,
geom = c("pointrange", "point", "col", "bar", "errorbar"),
ci = TRUE,
sort = TRUE,
flip = NULL,
caption = NULL,
...
)
wisca_plot(wisca_model, wisca_plot_type = c("susceptibility_incidence",
"posterior_coverage"), ...)
wisca_plot(
wisca_model,
wisca_plot_type = c("susceptibility_incidence", "posterior_coverage"),
...
)
\method{knit_print}{antibiogram}(x, italicise = TRUE,
na = getOption("knitr.kable.NA", default = ""), ...)
\method{knit_print}{antibiogram}(
x,
italicise = TRUE,
na = getOption("knitr.kable.NA", default = ""),
...
)
}
\arguments{
\item{x}{A \link{data.frame} containing at least a column with microorganisms and columns with antimicrobial results (class 'sir', see \code{\link[=as.sir]{as.sir()}}).}
@@ -66,14 +107,10 @@ wisca_plot(wisca_model, wisca_plot_type = c("susceptibility_incidence",
}
}}
\item{mo_transform}{A character to transform microorganism input - must be \code{"name"}, \code{"shortname"} (default), \code{"gramstain"}, or one of the column names of the \link{microorganisms} data set: \code{"mo"}, \code{"fullname"}, \code{"status"}, \code{"domain"}, \code{"kingdom"}, \code{"phylum"}, \code{"class"}, \code{"order"}, \code{"family"}, \code{"genus"}, \code{"species"}, \code{"subspecies"}, \code{"rank"}, \code{"ref"}, \code{"oxygen_tolerance"}, \code{"morphology"}, \code{"source"}, \code{"lpsn"}, \code{"lpsn_parent"}, \code{"lpsn_renamed_to"}, \code{"mycobank"}, \code{"mycobank_parent"}, \code{"mycobank_renamed_to"}, \code{"gbif"}, \code{"gbif_parent"}, \code{"gbif_renamed_to"}, \code{"prevalence"}, or \code{"snomed"}. Can also be \code{NULL} to not transform the input or \code{NA} to consider all microorganisms 'unknown'.}
\item{ab_transform}{A character to transform antimicrobial input - must be one of the column names of the \link{antimicrobials} data set (defaults to \code{"name"}): \code{"ab"}, \code{"cid"}, \code{"name"}, \code{"group"}, \code{"atc"}, \code{"atc_group1"}, \code{"atc_group2"}, \code{"abbreviations"}, \code{"synonyms"}, \code{"oral_ddd"}, \code{"oral_units"}, \code{"iv_ddd"}, \code{"iv_units"}, or \code{"loinc"}. Can also be \code{NULL} to not transform the input.}
\item{syndromic_group}{A column name of \code{x}, or values calculated to split rows of \code{x}, e.g. by using \code{\link[=ifelse]{ifelse()}} or \code{\link[dplyr:case-and-replace-when]{case_when()}}. See \emph{Examples}.}
\item{add_total_n}{\emph{(deprecated in favour of \code{formatting_type})} A \link{logical} to indicate whether \code{n_tested} available numbers per pathogen should be added to the table (default is \code{TRUE}). This will add the lowest and highest number of available isolates per antimicrobial (e.g, if for \emph{E. coli} 200 isolates are available for ciprofloxacin and 150 for amoxicillin, the returned number will be "150-200"). This option is unavailable when \code{wisca = TRUE}; in that case, use \code{\link[=retrieve_wisca_parameters]{retrieve_wisca_parameters()}} to get the parameters used for WISCA.}
\item{only_all_tested}{(for combination antibiograms): a \link{logical} to indicate that isolates must be tested for all antimicrobials, see \emph{Details}.}
\item{digits}{Number of digits to use for rounding the antimicrobial coverage, defaults to 1 for WISCA and 0 otherwise.}
@@ -84,18 +121,12 @@ wisca_plot(wisca_model, wisca_plot_type = c("susceptibility_incidence",
\item{language}{Language to translate text, which defaults to the system language (see \code{\link[=get_AMR_locale]{get_AMR_locale()}}).}
\item{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 \emph{Source}.}
\item{combine_SI}{A \link{logical} to indicate whether all susceptibility should be determined by results of either S, SDD, or I, instead of only S (default is \code{TRUE}).}
\item{sep}{A separating character for antimicrobial columns in combination antibiograms.}
\item{sort_columns}{A \link{logical} to indicate whether the antimicrobial columns must be sorted on name.}
\item{wisca}{A \link{logical} to indicate whether a Weighted-Incidence Syndromic Combination Antibiogram (WISCA) must be generated (default is \code{FALSE}). This will use a Bayesian decision model to estimate regimen coverage probabilities using \href{https://en.wikipedia.org/wiki/Monte_Carlo_method}{Monte Carlo simulations}. Per \doi{10.1093/jac/dkv397}, susceptibility priors are \eqn{\beta(0.5, 0.5)} (Jeffreys) and intrinsically resistant pairs (based on \link{intrinsic_resistant}) use \eqn{\beta(1, 9999)}.
Set \code{simulations}, \code{conf_interval}, and \code{interval_side} to adjust.}
\item{simulations}{(for WISCA) a numerical value to set the number of Monte Carlo simulations.}
\item{conf_interval}{A numerical value to set confidence interval (default is \code{0.95}).}
@@ -108,6 +139,16 @@ Set \code{simulations}, \code{conf_interval}, and \code{interval_side} to adjust
\item{...}{Currently unused.}
\item{mo_transform}{A character to transform microorganism input - must be \code{"name"}, \code{"shortname"} (default), \code{"gramstain"}, or one of the column names of the \link{microorganisms} data set: \code{"mo"}, \code{"fullname"}, \code{"status"}, \code{"domain"}, \code{"kingdom"}, \code{"phylum"}, \code{"class"}, \code{"order"}, \code{"family"}, \code{"genus"}, \code{"species"}, \code{"subspecies"}, \code{"rank"}, \code{"ref"}, \code{"oxygen_tolerance"}, \code{"morphology"}, \code{"source"}, \code{"lpsn"}, \code{"lpsn_parent"}, \code{"lpsn_renamed_to"}, \code{"mycobank"}, \code{"mycobank_parent"}, \code{"mycobank_renamed_to"}, \code{"gbif"}, \code{"gbif_parent"}, \code{"gbif_renamed_to"}, \code{"prevalence"}, or \code{"snomed"}. Can also be \code{NULL} to not transform the input or \code{NA} to consider all microorganisms 'unknown'.}
\item{add_total_n}{\emph{(deprecated in favour of \code{formatting_type})} A \link{logical} to indicate whether \code{n_tested} available numbers per pathogen should be added to the table (default is \code{TRUE}). This will add the lowest and highest number of available isolates per antimicrobial (e.g, if for \emph{E. coli} 200 isolates are available for ciprofloxacin and 150 for amoxicillin, the returned number will be "150-200"). This option is unavailable when \code{wisca = TRUE}; in that case, use \code{\link[=retrieve_wisca_parameters]{retrieve_wisca_parameters()}} to get the parameters used for WISCA.}
\item{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 \emph{Source}.}
\item{wisca}{A \link{logical} to indicate whether a Weighted-Incidence Syndromic Combination Antibiogram (WISCA) must be generated (default is \code{FALSE}). This will use a Bayesian decision model to estimate regimen coverage probabilities using \href{https://en.wikipedia.org/wiki/Monte_Carlo_method}{Monte Carlo simulations}. Per \doi{10.1093/jac/dkv397}, susceptibility priors are \eqn{\beta(0.5, 0.5)} (Jeffreys) and intrinsically resistant pairs (based on \link{intrinsic_resistant}) use \eqn{\beta(1, 9999)}.
Set \code{simulations}, \code{conf_interval}, and \code{interval_side} to adjust.}
\item{wisca_model}{The outcome of \code{\link[=wisca]{wisca()}} or \code{\link[=antibiogram]{antibiogram(..., wisca = TRUE)}}.}
\item{object}{An \code{\link[=antibiogram]{antibiogram()}} object.}

View File

@@ -45,8 +45,12 @@
\alias{not_intrinsic_resistant}
\title{Antimicrobial Selectors}
\usage{
aminoglycosides(only_sir_columns = FALSE, only_treatable = TRUE,
return_all = TRUE, ...)
aminoglycosides(
only_sir_columns = FALSE,
only_treatable = TRUE,
return_all = TRUE,
...
)
aminopenicillins(only_sir_columns = FALSE, return_all = TRUE, ...)
@@ -54,41 +58,68 @@ antifungals(only_sir_columns = FALSE, return_all = TRUE, ...)
antimycobacterials(only_sir_columns = FALSE, return_all = TRUE, ...)
betalactams(only_sir_columns = FALSE, only_treatable = TRUE,
return_all = TRUE, ...)
betalactams(
only_sir_columns = FALSE,
only_treatable = TRUE,
return_all = TRUE,
...
)
betalactams_with_inhibitor(only_sir_columns = FALSE, return_all = TRUE,
...)
betalactams_with_inhibitor(only_sir_columns = FALSE, return_all = TRUE, ...)
carbapenems(only_sir_columns = FALSE, only_treatable = TRUE,
return_all = TRUE, ...)
carbapenems(
only_sir_columns = FALSE,
only_treatable = TRUE,
return_all = TRUE,
...
)
cephalosporins(only_sir_columns = FALSE, only_treatable = TRUE,
return_all = TRUE, ...)
cephalosporins(
only_sir_columns = FALSE,
only_treatable = TRUE,
return_all = TRUE,
...
)
cephalosporins_1st(only_sir_columns = FALSE, return_all = TRUE, ...)
cephalosporins_2nd(only_sir_columns = FALSE, return_all = TRUE, ...)
cephalosporins_3rd(only_sir_columns = FALSE, only_treatable = TRUE,
return_all = TRUE, ...)
cephalosporins_3rd(
only_sir_columns = FALSE,
only_treatable = TRUE,
return_all = TRUE,
...
)
cephalosporins_4th(only_sir_columns = FALSE, return_all = TRUE, ...)
cephalosporins_5th(only_sir_columns = FALSE, return_all = TRUE, ...)
fluoroquinolones(only_sir_columns = FALSE, only_treatable = TRUE,
return_all = TRUE, ...)
fluoroquinolones(
only_sir_columns = FALSE,
only_treatable = TRUE,
return_all = TRUE,
...
)
glycopeptides(only_sir_columns = FALSE, return_all = TRUE, ...)
ionophores(only_sir_columns = FALSE, return_all = TRUE, ...)
isoxazolylpenicillins(only_sir_columns = FALSE, only_treatable = TRUE,
return_all = TRUE, ...)
isoxazolylpenicillins(
only_sir_columns = FALSE,
only_treatable = TRUE,
return_all = TRUE,
...
)
lincosamides(only_sir_columns = FALSE, only_treatable = TRUE,
return_all = TRUE, ...)
lincosamides(
only_sir_columns = FALSE,
only_treatable = TRUE,
return_all = TRUE,
...
)
lipoglycopeptides(only_sir_columns = FALSE, return_all = TRUE, ...)
@@ -108,11 +139,19 @@ phenicols(only_sir_columns = FALSE, return_all = TRUE, ...)
phosphonics(only_sir_columns = FALSE, return_all = TRUE, ...)
polymyxins(only_sir_columns = FALSE, only_treatable = TRUE,
return_all = TRUE, ...)
polymyxins(
only_sir_columns = FALSE,
only_treatable = TRUE,
return_all = TRUE,
...
)
quinolones(only_sir_columns = FALSE, only_treatable = TRUE,
return_all = TRUE, ...)
quinolones(
only_sir_columns = FALSE,
only_treatable = TRUE,
return_all = TRUE,
...
)
rifamycins(only_sir_columns = FALSE, return_all = TRUE, ...)
@@ -122,25 +161,43 @@ streptogramins(only_sir_columns = FALSE, return_all = TRUE, ...)
sulfonamides(only_sir_columns = FALSE, return_all = TRUE, ...)
tetracyclines(only_sir_columns = FALSE, only_treatable = TRUE,
return_all = TRUE, ...)
tetracyclines(
only_sir_columns = FALSE,
only_treatable = TRUE,
return_all = TRUE,
...
)
trimethoprims(only_sir_columns = FALSE, return_all = TRUE, ...)
ureidopenicillins(only_sir_columns = FALSE, return_all = TRUE, ...)
amr_class(amr_class, only_sir_columns = FALSE, only_treatable = TRUE,
return_all = TRUE, ...)
amr_class(
amr_class,
only_sir_columns = FALSE,
only_treatable = TRUE,
return_all = TRUE,
...
)
amr_selector(filter, only_sir_columns = FALSE, only_treatable = TRUE,
return_all = TRUE, ...)
amr_selector(
filter,
only_sir_columns = FALSE,
only_treatable = TRUE,
return_all = TRUE,
...
)
administrable_per_os(only_sir_columns = FALSE, return_all = TRUE, ...)
administrable_iv(only_sir_columns = FALSE, return_all = TRUE, ...)
not_intrinsic_resistant(only_sir_columns = FALSE, col_mo = NULL,
version_expected_phenotypes = 1.2, ...)
not_intrinsic_resistant(
only_sir_columns = FALSE,
col_mo = NULL,
version_expected_phenotypes = 1.2,
...
)
}
\arguments{
\item{only_sir_columns}{A \link{logical} to indicate whether only antimicrobial columns must be included that were transformed to class \link[=as.sir]{sir} on beforehand. Defaults to \code{FALSE}.}

View File

@@ -9,8 +9,13 @@
\alias{NA_ab_}
\title{Transform Input to an Antibiotic ID}
\usage{
as.ab(x, flag_multiple_results = TRUE, language = get_AMR_locale(),
info = interactive(), ...)
as.ab(
x,
flag_multiple_results = TRUE,
language = get_AMR_locale(),
info = interactive(),
...
)
is.ab(x)

View File

@@ -12,15 +12,19 @@
\alias{droplevels.mic}
\title{Transform Input to Minimum Inhibitory Concentrations (MIC)}
\usage{
as.mic(x, na.rm = FALSE, keep_operators = "all",
round_to_next_log2 = FALSE)
as.mic(x, na.rm = FALSE, keep_operators = "all", round_to_next_log2 = FALSE)
is.mic(x)
NA_mic_
rescale_mic(x, mic_range, keep_operators = "edges", as.mic = TRUE,
round_to_next_log2 = FALSE)
rescale_mic(
x,
mic_range,
keep_operators = "edges",
as.mic = TRUE,
round_to_next_log2 = FALSE
)
mic_p50(x, na.rm = FALSE, ...)

View File

@@ -13,14 +13,20 @@
\alias{NA_mo_}
\title{Transform Arbitrary Input to Valid Microbial Taxonomy}
\usage{
as.mo(x, Becker = FALSE, Lancefield = FALSE,
as.mo(
x,
Becker = FALSE,
Lancefield = FALSE,
minimum_matching_score = NULL,
keep_synonyms = getOption("AMR_keep_synonyms", FALSE),
reference_df = get_mo_source(),
ignore_pattern = getOption("AMR_ignore_pattern", NULL),
cleaning_regex = getOption("AMR_cleaning_regex", mo_cleaning_regex()),
only_fungi = getOption("AMR_only_fungi", FALSE),
language = get_AMR_locale(), info = interactive(), ...)
language = get_AMR_locale(),
info = interactive(),
...
)
is.mo(x)

View File

@@ -22,48 +22,86 @@ is.sir(x)
is_sir_eligible(x, threshold = 0.05)
\method{as.sir}{default}(x, S = "^(S|U|1)+$", I = "^(I|2)+$",
R = "^(R|3)+$", NI = "^(N|NI|V|4)+$", SDD = "^(SDD|D|H|5)+$",
WT = "^(WT|6)+$", NWT = "^(NWT|7)+$", NS = "^(NS|8)+$",
info = interactive(), ...)
\method{as.sir}{default}(
x,
S = "^(S|U|1)+$",
I = "^(I|2)+$",
R = "^(R|3)+$",
NI = "^(N|NI|V|4)+$",
SDD = "^(SDD|D|H|5)+$",
WT = "^(WT|6)+$",
NWT = "^(NWT|7)+$",
NS = "^(NS|8)+$",
info = interactive(),
...
)
\method{as.sir}{mic}(x, mo = NULL, ab = deparse(substitute(x)),
guideline = getOption("AMR_guideline", "EUCAST"), uti = NULL,
\method{as.sir}{mic}(
x,
mo = NULL,
ab = deparse(substitute(x)),
guideline = getOption("AMR_guideline", "EUCAST"),
uti = NULL,
capped_mic_handling = getOption("AMR_capped_mic_handling", "standard"),
as_wt_nwt = identical(breakpoint_type, "ECOFF"),
add_intrinsic_resistance = FALSE,
reference_data = AMR::clinical_breakpoints,
substitute_missing_r_breakpoint = getOption("AMR_substitute_missing_r_breakpoint",
FALSE), include_screening = getOption("AMR_include_screening", FALSE),
FALSE),
include_screening = getOption("AMR_include_screening", FALSE),
include_PKPD = getOption("AMR_include_PKPD", TRUE),
breakpoint_type = getOption("AMR_breakpoint_type", "human"), host = NULL,
language = get_AMR_locale(), verbose = FALSE, info = interactive(),
conserve_capped_values = NULL, ...)
breakpoint_type = getOption("AMR_breakpoint_type", "human"),
host = NULL,
language = get_AMR_locale(),
verbose = FALSE,
info = interactive(),
conserve_capped_values = NULL,
...
)
\method{as.sir}{disk}(x, mo = NULL, ab = deparse(substitute(x)),
guideline = getOption("AMR_guideline", "EUCAST"), uti = NULL,
\method{as.sir}{disk}(
x,
mo = NULL,
ab = deparse(substitute(x)),
guideline = getOption("AMR_guideline", "EUCAST"),
uti = NULL,
as_wt_nwt = identical(breakpoint_type, "ECOFF"),
add_intrinsic_resistance = FALSE,
reference_data = AMR::clinical_breakpoints,
substitute_missing_r_breakpoint = getOption("AMR_substitute_missing_r_breakpoint",
FALSE), include_screening = getOption("AMR_include_screening", FALSE),
FALSE),
include_screening = getOption("AMR_include_screening", FALSE),
include_PKPD = getOption("AMR_include_PKPD", TRUE),
breakpoint_type = getOption("AMR_breakpoint_type", "human"), host = NULL,
language = get_AMR_locale(), verbose = FALSE, info = interactive(),
...)
breakpoint_type = getOption("AMR_breakpoint_type", "human"),
host = NULL,
language = get_AMR_locale(),
verbose = FALSE,
info = interactive(),
...
)
\method{as.sir}{data.frame}(x, ..., col_mo = NULL,
guideline = getOption("AMR_guideline", "EUCAST"), uti = NULL,
\method{as.sir}{data.frame}(
x,
...,
col_mo = NULL,
guideline = getOption("AMR_guideline", "EUCAST"),
uti = NULL,
capped_mic_handling = getOption("AMR_capped_mic_handling", "standard"),
as_wt_nwt = identical(breakpoint_type, "ECOFF"),
add_intrinsic_resistance = FALSE,
reference_data = AMR::clinical_breakpoints,
substitute_missing_r_breakpoint = getOption("AMR_substitute_missing_r_breakpoint",
FALSE), include_screening = getOption("AMR_include_screening", FALSE),
FALSE),
include_screening = getOption("AMR_include_screening", FALSE),
include_PKPD = getOption("AMR_include_PKPD", TRUE),
breakpoint_type = getOption("AMR_breakpoint_type", "human"), host = NULL,
language = get_AMR_locale(), verbose = FALSE, info = interactive(),
parallel = FALSE, conserve_capped_values = NULL)
breakpoint_type = getOption("AMR_breakpoint_type", "human"),
host = NULL,
language = get_AMR_locale(),
verbose = FALSE,
info = interactive(),
parallel = FALSE,
conserve_capped_values = NULL
)
sir_interpretation_history(clean = FALSE)
}

View File

@@ -10,9 +10,13 @@
\url{https://atcddd.fhi.no/atc_ddd_alterations__cumulative/ddd_alterations/abbrevations/}
}
\usage{
atc_online_property(atc_code, property, administration = "O",
atc_online_property(
atc_code,
property,
administration = "O",
url = "https://atcddd.fhi.no/atc_ddd_index/?code=\%s&showdescription=no",
url_vet = "https://atcddd.fhi.no/atcvet/atcvet_index/?code=\%s&showdescription=no")
url_vet = "https://atcddd.fhi.no/atcvet/atcvet_index/?code=\%s&showdescription=no"
)
atc_online_groups(atc_code, ...)

View File

@@ -4,9 +4,15 @@
\alias{av_from_text}
\title{Retrieve Antiviral Drug Names and Doses from Clinical Text}
\usage{
av_from_text(text, type = c("drug", "dose", "administration"),
collapse = NULL, translate_av = FALSE, thorough_search = NULL,
info = interactive(), ...)
av_from_text(
text,
type = c("drug", "dose", "administration"),
collapse = NULL,
translate_av = FALSE,
thorough_search = NULL,
info = interactive(),
...
)
}
\arguments{
\item{text}{Text to analyse.}

View File

@@ -5,14 +5,26 @@
\alias{format.bug_drug_combinations}
\title{Determine Bug-Drug Combinations}
\usage{
bug_drug_combinations(x, col_mo = NULL, FUN = mo_shortname,
include_n_rows = FALSE, ...)
bug_drug_combinations(
x,
col_mo = NULL,
FUN = mo_shortname,
include_n_rows = FALSE,
...
)
\method{format}{bug_drug_combinations}(x, translate_ab = "name (ab, atc)",
language = get_AMR_locale(), minimum = 30, combine_SI = TRUE,
add_ab_group = TRUE, remove_intrinsic_resistant = FALSE,
decimal.mark = getOption("OutDec"), big.mark = ifelse(decimal.mark ==
",", ".", ","), ...)
\method{format}{bug_drug_combinations}(
x,
translate_ab = "name (ab, atc)",
language = get_AMR_locale(),
minimum = 30,
combine_SI = TRUE,
add_ab_group = TRUE,
remove_intrinsic_resistant = FALSE,
decimal.mark = getOption("OutDec"),
big.mark = ifelse(decimal.mark == ",", ".", ","),
...
)
}
\arguments{
\item{x}{A data set with antimicrobials columns, such as \code{amox}, \code{AMX} and \code{AMC}.}

View File

@@ -14,11 +14,17 @@
\alias{count_df}
\title{Count Available Isolates}
\usage{
count_resistant(..., only_all_tested = FALSE,
guideline = getOption("AMR_guideline", "EUCAST"))
count_resistant(
...,
only_all_tested = FALSE,
guideline = getOption("AMR_guideline", "EUCAST")
)
count_susceptible(..., only_all_tested = FALSE,
guideline = getOption("AMR_guideline", "EUCAST"))
count_susceptible(
...,
only_all_tested = FALSE,
guideline = getOption("AMR_guideline", "EUCAST")
)
count_S(..., only_all_tested = FALSE)
@@ -34,8 +40,12 @@ count_all(..., only_all_tested = FALSE)
n_sir(..., only_all_tested = FALSE)
count_df(data, translate_ab = "name", language = get_AMR_locale(),
combine_SI = TRUE)
count_df(
data,
translate_ab = "name",
language = get_AMR_locale(),
combine_SI = TRUE
)
}
\arguments{
\item{...}{One or more vectors (or columns) with antibiotic interpretations. They will be transformed internally with \code{\link[=as.sir]{as.sir()}} if needed.}

View File

@@ -4,9 +4,13 @@
\alias{export_ncbi_biosample}
\title{Export Data Set as NCBI BioSample Antibiogram}
\usage{
export_ncbi_biosample(x, filename = paste0("biosample_", format(Sys.time(),
"\%Y-\%m-\%d-\%H\%M\%S"), ".xlsx"), type = "pathogen MIC",
columns = where(is.mic), save_as_xlsx = TRUE)
export_ncbi_biosample(
x,
filename = paste0("biosample_", format(Sys.time(), "\%Y-\%m-\%d-\%H\%M\%S"), ".xlsx"),
type = "pathogen MIC",
columns = where(is.mic),
save_as_xlsx = TRUE
)
}
\arguments{
\item{x}{A data set.}

View File

@@ -5,18 +5,38 @@
\alias{filter_first_isolate}
\title{Determine First Isolates}
\usage{
first_isolate(x = NULL, col_date = NULL, col_patient_id = NULL,
col_mo = NULL, col_testcode = NULL, col_specimen = NULL,
col_icu = NULL, col_keyantimicrobials = NULL, episode_days = 365,
testcodes_exclude = NULL, icu_exclude = FALSE, specimen_group = NULL,
type = "points", method = c("phenotype-based", "episode-based",
"patient-based", "isolate-based"), ignore_I = TRUE, points_threshold = 2,
info = interactive(), include_unknown = FALSE,
include_untested_sir = TRUE, ...)
first_isolate(
x = NULL,
col_date = NULL,
col_patient_id = NULL,
col_mo = NULL,
col_testcode = NULL,
col_specimen = NULL,
col_icu = NULL,
col_keyantimicrobials = NULL,
episode_days = 365,
testcodes_exclude = NULL,
icu_exclude = FALSE,
specimen_group = NULL,
type = "points",
method = c("phenotype-based", "episode-based", "patient-based", "isolate-based"),
ignore_I = TRUE,
points_threshold = 2,
info = interactive(),
include_unknown = FALSE,
include_untested_sir = TRUE,
...
)
filter_first_isolate(x = NULL, col_date = NULL, col_patient_id = NULL,
col_mo = NULL, episode_days = 365, method = c("phenotype-based",
"episode-based", "patient-based", "isolate-based"), ...)
filter_first_isolate(
x = NULL,
col_date = NULL,
col_patient_id = NULL,
col_mo = NULL,
episode_days = 365,
method = c("phenotype-based", "episode-based", "patient-based", "isolate-based"),
...
)
}
\arguments{
\item{x}{A \link{data.frame} containing isolates. Can be left blank for automatic determination, see \emph{Examples}.}

View File

@@ -46,7 +46,7 @@ A list with class \code{"htest"} containing the following
\code{(observed - expected) / sqrt(expected)}.}
\item{stdres}{standardized residuals,
\code{(observed - expected) / sqrt(V)}, where \code{V} is the
residual cell variance {(\if{html}{\out{<a href="#reference+chisq.test.Rd+R+3AAgresti+3A2007" class="citation">}}Agresti 2007\if{html}{\out{</a>}}, section 2.4.5)}
residual cell variance (Agresti, 2007, section 2.4.5
for the case where \code{x} is a matrix, \code{n * p * (1 - p)} otherwise).}
}
\description{

View File

@@ -17,13 +17,30 @@ As per their GPL-2 licence that demands documentation of code changes, the chang
}
}
\usage{
ggplot_pca(x, choices = 1:2, scale = 1, pc.biplot = TRUE,
labels = NULL, labels_textsize = 3, labels_text_placement = 1.5,
groups = NULL, ellipse = TRUE, ellipse_prob = 0.68,
ellipse_size = 0.5, ellipse_alpha = 0.5, points_size = 2,
points_alpha = 0.25, arrows = TRUE, arrows_colour = "darkblue",
arrows_size = 0.5, arrows_textsize = 3, arrows_textangled = TRUE,
arrows_alpha = 0.75, base_textsize = 10, ...)
ggplot_pca(
x,
choices = 1:2,
scale = 1,
pc.biplot = TRUE,
labels = NULL,
labels_textsize = 3,
labels_text_placement = 1.5,
groups = NULL,
ellipse = TRUE,
ellipse_prob = 0.68,
ellipse_size = 0.5,
ellipse_alpha = 0.5,
points_size = 2,
points_alpha = 0.25,
arrows = TRUE,
arrows_colour = "darkblue",
arrows_size = 0.5,
arrows_textsize = 3,
arrows_textangled = TRUE,
arrows_alpha = 0.75,
base_textsize = 10,
...
)
}
\arguments{
\item{x}{An object returned by \code{\link[=pca]{pca()}}, \code{\link[=prcomp]{prcomp()}} or \code{\link[=princomp]{princomp()}}.}
@@ -42,9 +59,8 @@ ggplot_pca(x, choices = 1:2, scale = 1, pc.biplot = TRUE,
}
\item{pc.biplot}{
If true, use what {\if{html}{\cite{}\out{<a href="#reference+biplot.princomp.Rd+R+3AGabriel+3A1971" class="citation">}}Gabriel (1971)\if{html}{\out{</a>}}} refers to as a
\dQuote{principal component biplot},
with \code{lambda = 1} and observations scaled up by sqrt(n) and
If true, use what Gabriel (1971) refers to as a "principal component
biplot", with \code{lambda = 1} and observations scaled up by sqrt(n) and
variables scaled down by sqrt(n). Then inner products between
variables approximate covariances and distances between observations
approximate Mahalanobis distance.

View File

@@ -5,18 +5,42 @@
\alias{geom_sir}
\title{AMR Plots with \code{ggplot2}}
\usage{
ggplot_sir(data, position = NULL, x = "antibiotic",
fill = "interpretation", facet = NULL, breaks = seq(0, 1, 0.1),
limits = NULL, translate_ab = "name", combine_SI = TRUE,
minimum = 30, language = get_AMR_locale(), nrow = NULL, colours = c(S
= "#3CAEA3", SDD = "#8FD6C4", SI = "#3CAEA3", I = "#F6D55C", IR = "#ED553B",
R = "#ED553B"), datalabels = TRUE, datalabels.size = 2.5,
datalabels.colour = "grey15", title = NULL, subtitle = NULL,
caption = NULL, x.title = "Antimicrobial", y.title = "Proportion", ...)
ggplot_sir(
data,
position = NULL,
x = "antibiotic",
fill = "interpretation",
facet = NULL,
breaks = seq(0, 1, 0.1),
limits = NULL,
translate_ab = "name",
combine_SI = TRUE,
minimum = 30,
language = get_AMR_locale(),
nrow = NULL,
colours = c(S = "#3CAEA3", SDD = "#8FD6C4", SI = "#3CAEA3", I = "#F6D55C", IR =
"#ED553B", R = "#ED553B"),
datalabels = TRUE,
datalabels.size = 2.5,
datalabels.colour = "grey15",
title = NULL,
subtitle = NULL,
caption = NULL,
x.title = "Antimicrobial",
y.title = "Proportion",
...
)
geom_sir(position = NULL, x = c("antibiotic", "interpretation"),
fill = "interpretation", translate_ab = "name", minimum = 30,
language = get_AMR_locale(), combine_SI = TRUE, ...)
geom_sir(
position = NULL,
x = c("antibiotic", "interpretation"),
fill = "interpretation",
translate_ab = "name",
minimum = 30,
language = get_AMR_locale(),
combine_SI = TRUE,
...
)
}
\arguments{
\item{data}{A \link{data.frame} with column(s) of class \code{\link{sir}} (see \code{\link[=as.sir]{as.sir()}}).}

View File

@@ -4,8 +4,12 @@
\alias{guess_ab_col}
\title{Guess Antibiotic Column}
\usage{
guess_ab_col(x = NULL, search_string = NULL, verbose = FALSE,
only_sir_columns = FALSE)
guess_ab_col(
x = NULL,
search_string = NULL,
verbose = FALSE,
only_sir_columns = FALSE
)
}
\arguments{
\item{x}{A \link{data.frame}.}

View File

@@ -8,21 +8,42 @@
\alias{eucast_dosage}
\title{Apply Interpretive Rules}
\usage{
interpretive_rules(x, col_mo = NULL, info = interactive(),
interpretive_rules(
x,
col_mo = NULL,
info = interactive(),
rules = getOption("AMR_interpretive_rules", default = c("breakpoints",
"expected_phenotypes")), guideline = getOption("AMR_guideline", "EUCAST"),
verbose = FALSE, version_breakpoints = 16,
version_expected_phenotypes = 1.2, version_expertrules = 3.3,
ampc_cephalosporin_resistance = NA, only_sir_columns = any(is.sir(x)),
custom_rules = NULL, overwrite = FALSE, add_if_missing = TRUE, ...)
"expected_phenotypes")),
guideline = getOption("AMR_guideline", "EUCAST"),
verbose = FALSE,
version_breakpoints = 16,
version_expected_phenotypes = 1.2,
version_expertrules = 3.3,
ampc_cephalosporin_resistance = NA,
only_sir_columns = any(is.sir(x)),
custom_rules = NULL,
overwrite = FALSE,
add_if_missing = TRUE,
...
)
eucast_rules(x, col_mo = NULL, info = interactive(),
eucast_rules(
x,
col_mo = NULL,
info = interactive(),
rules = getOption("AMR_interpretive_rules", default = c("breakpoints",
"expected_phenotypes")), ...)
"expected_phenotypes")),
...
)
clsi_rules(x, col_mo = NULL, info = interactive(),
clsi_rules(
x,
col_mo = NULL,
info = interactive(),
rules = getOption("AMR_interpretive_rules", default = c("breakpoints",
"expected_phenotypes")), ...)
"expected_phenotypes")),
...
)
eucast_dosage(ab, administration = "iv", version_breakpoints = 15)
}

View File

@@ -6,19 +6,31 @@
\alias{antimicrobials_equal}
\title{(Key) Antimicrobials for First Weighted Isolates}
\usage{
key_antimicrobials(x = NULL, col_mo = NULL, universal = c("ampicillin",
"amoxicillin/clavulanic acid", "cefuroxime", "piperacillin/tazobactam",
"ciprofloxacin", "trimethoprim/sulfamethoxazole"),
gram_negative = c("gentamicin", "tobramycin", "colistin", "cefotaxime",
"ceftazidime", "meropenem"), gram_positive = c("vancomycin", "teicoplanin",
"tetracycline", "erythromycin", "oxacillin", "rifampin"),
antifungal = c("anidulafungin", "caspofungin", "fluconazole", "miconazole",
"nystatin", "voriconazole"), only_sir_columns = any(is.sir(x)), ...)
key_antimicrobials(
x = NULL,
col_mo = NULL,
universal = c("ampicillin", "amoxicillin/clavulanic acid", "cefuroxime",
"piperacillin/tazobactam", "ciprofloxacin", "trimethoprim/sulfamethoxazole"),
gram_negative = c("gentamicin", "tobramycin", "colistin", "cefotaxime", "ceftazidime",
"meropenem"),
gram_positive = c("vancomycin", "teicoplanin", "tetracycline", "erythromycin",
"oxacillin", "rifampin"),
antifungal = c("anidulafungin", "caspofungin", "fluconazole", "miconazole", "nystatin",
"voriconazole"),
only_sir_columns = any(is.sir(x)),
...
)
all_antimicrobials(x = NULL, only_sir_columns = any(is.sir(x)), ...)
antimicrobials_equal(y, z, type = c("points", "keyantimicrobials"),
ignore_I = TRUE, points_threshold = 2, ...)
antimicrobials_equal(
y,
z,
type = c("points", "keyantimicrobials"),
ignore_I = TRUE,
points_threshold = 2,
...
)
}
\arguments{
\item{x}{A \link{data.frame} with antimicrobials columns, like \code{AMX} or \code{amox}. Can be left blank to determine automatically.}

View File

@@ -15,11 +15,24 @@
\alias{eucast_exceptional_phenotypes}
\title{Determine Multidrug-Resistant Organisms (MDRO)}
\usage{
mdro(x = NULL, guideline = "CMI 2012", col_mo = NULL, esbl = NA,
carbapenemase = NA, mecA = NA, mecC = NA, vanA = NA, vanB = NA,
info = interactive(), pct_required_classes = 0.5, combine_SI = TRUE,
verbose = FALSE, only_sir_columns = any(is.sir(x)),
infer_from_combinations = TRUE, ...)
mdro(
x = NULL,
guideline = "CMI 2012",
col_mo = NULL,
esbl = NA,
carbapenemase = NA,
mecA = NA,
mecC = NA,
vanA = NA,
vanB = NA,
info = interactive(),
pct_required_classes = 0.5,
combine_SI = TRUE,
verbose = FALSE,
only_sir_columns = any(is.sir(x)),
infer_from_combinations = TRUE,
...
)
brmo(x = NULL, only_sir_columns = any(is.sir(x)), ...)
@@ -27,11 +40,14 @@ mrgn(x = NULL, only_sir_columns = any(is.sir(x)), verbose = FALSE, ...)
mdr_tb(x = NULL, only_sir_columns = any(is.sir(x)), verbose = FALSE, ...)
mdr_cmi2012(x = NULL, only_sir_columns = any(is.sir(x)), verbose = FALSE,
...)
mdr_cmi2012(x = NULL, only_sir_columns = any(is.sir(x)), verbose = FALSE, ...)
eucast_exceptional_phenotypes(x = NULL, only_sir_columns = any(is.sir(x)),
verbose = FALSE, ...)
eucast_exceptional_phenotypes(
x = NULL,
only_sir_columns = any(is.sir(x)),
verbose = FALSE,
...
)
}
\arguments{
\item{x}{A \link{data.frame} with antimicrobials columns, like \code{AMX} or \code{amox}. Can be left blank for automatic determination.}

View File

@@ -41,119 +41,270 @@
\alias{mo_url}
\title{Get Properties of a Microorganism}
\usage{
mo_name(x, language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE), ...)
mo_fullname(x, language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE), ...)
mo_shortname(x, language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE), ...)
mo_subspecies(x, language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE), ...)
mo_species(x, language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE), ...)
mo_genus(x, language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE), ...)
mo_family(x, language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE), ...)
mo_order(x, language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE), ...)
mo_class(x, language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE), ...)
mo_phylum(x, language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE), ...)
mo_kingdom(x, language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE), ...)
mo_domain(x, language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE), ...)
mo_type(x, language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE), ...)
mo_status(x, language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE), ...)
mo_pathogenicity(x, language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE), ...)
mo_gramstain(x, language = get_AMR_locale(),
mo_name(
x,
language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE),
add_morphology = FALSE, ...)
...
)
mo_is_gram_negative(x, language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE), ...)
mo_fullname(
x,
language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE),
...
)
mo_is_gram_positive(x, language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE), ...)
mo_shortname(
x,
language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE),
...
)
mo_is_yeast(x, language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE), ...)
mo_subspecies(
x,
language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE),
...
)
mo_is_intrinsic_resistant(x, ab, language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE), ...)
mo_species(
x,
language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE),
...
)
mo_oxygen_tolerance(x, language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE), ...)
mo_genus(
x,
language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE),
...
)
mo_is_anaerobic(x, language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE), ...)
mo_family(
x,
language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE),
...
)
mo_morphology(x, language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE), ...)
mo_order(
x,
language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE),
...
)
mo_snomed(x, language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE), ...)
mo_class(
x,
language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE),
...
)
mo_ref(x, language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE), ...)
mo_phylum(
x,
language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE),
...
)
mo_authors(x, language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE), ...)
mo_kingdom(
x,
language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE),
...
)
mo_year(x, language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE), ...)
mo_domain(
x,
language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE),
...
)
mo_lpsn(x, language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE), ...)
mo_type(
x,
language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE),
...
)
mo_mycobank(x, language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE), ...)
mo_status(
x,
language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE),
...
)
mo_gbif(x, language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE), ...)
mo_pathogenicity(
x,
language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE),
...
)
mo_rank(x, language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE), ...)
mo_gramstain(
x,
language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE),
add_morphology = FALSE,
...
)
mo_taxonomy(x, language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE), ...)
mo_is_gram_negative(
x,
language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE),
...
)
mo_synonyms(x, language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE), ...)
mo_is_gram_positive(
x,
language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE),
...
)
mo_is_yeast(
x,
language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE),
...
)
mo_is_intrinsic_resistant(
x,
ab,
language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE),
...
)
mo_oxygen_tolerance(
x,
language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE),
...
)
mo_is_anaerobic(
x,
language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE),
...
)
mo_morphology(
x,
language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE),
...
)
mo_snomed(
x,
language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE),
...
)
mo_ref(
x,
language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE),
...
)
mo_authors(
x,
language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE),
...
)
mo_year(
x,
language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE),
...
)
mo_lpsn(
x,
language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE),
...
)
mo_mycobank(
x,
language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE),
...
)
mo_gbif(
x,
language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE),
...
)
mo_rank(
x,
language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE),
...
)
mo_taxonomy(
x,
language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE),
...
)
mo_synonyms(
x,
language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE),
...
)
mo_current(x, language = get_AMR_locale(), ...)
mo_group_members(x, language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE), ...)
mo_group_members(
x,
language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE),
...
)
mo_info(x, language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE), ...)
mo_info(
x,
language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE),
...
)
mo_url(x, open = FALSE, language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE), ...)
mo_url(
x,
open = FALSE,
language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE),
...
)
mo_property(x, property = "fullname", language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE), ...)
mo_property(
x,
property = "fullname",
language = get_AMR_locale(),
keep_synonyms = getOption("AMR_keep_synonyms", FALSE),
...
)
}
\arguments{
\item{x}{Any \link{character} (vector) that can be coerced to a valid microorganism code with \code{\link[=as.mo]{as.mo()}}. Can be left blank for auto-guessing the column containing microorganism codes if used in a data set, see \emph{Examples}.}

View File

@@ -6,8 +6,10 @@
\alias{get_mo_source}
\title{User-Defined Reference Data Set for Microorganisms}
\usage{
set_mo_source(path, destination = getOption("AMR_mo_source",
"~/mo_source.rds"))
set_mo_source(
path,
destination = getOption("AMR_mo_source", "~/mo_source.rds")
)
get_mo_source(destination = getOption("AMR_mo_source", "~/mo_source.rds"))
}

View File

@@ -4,8 +4,15 @@
\alias{pca}
\title{Principal Component Analysis (for AMR)}
\usage{
pca(x, ..., retx = TRUE, center = TRUE, scale. = TRUE, tol = NULL,
rank. = NULL)
pca(
x,
...,
retx = TRUE,
center = TRUE,
scale. = TRUE,
tol = NULL,
rank. = NULL
)
}
\arguments{
\item{x}{A \link{data.frame} containing \link{numeric} columns.}

View File

@@ -33,80 +33,135 @@ scale_colour_mic(keep_operators = "edges", mic_range = NULL, ...)
scale_fill_mic(keep_operators = "edges", mic_range = NULL, ...)
scale_x_sir(colours_SIR = c(S = "#3CAEA3", SDD = "#8FD6C4", I = "#F6D55C", R
= "#ED553B"), language = get_AMR_locale(),
eucast_I = getOption("AMR_guideline", "EUCAST") == "EUCAST", ...)
scale_x_sir(
colours_SIR = c(S = "#3CAEA3", SDD = "#8FD6C4", I = "#F6D55C", R = "#ED553B"),
language = get_AMR_locale(),
eucast_I = getOption("AMR_guideline", "EUCAST") == "EUCAST",
...
)
scale_colour_sir(colours_SIR = c(S = "#3CAEA3", SDD = "#8FD6C4", I =
"#F6D55C", R = "#ED553B"), language = get_AMR_locale(),
eucast_I = getOption("AMR_guideline", "EUCAST") == "EUCAST", ...)
scale_colour_sir(
colours_SIR = c(S = "#3CAEA3", SDD = "#8FD6C4", I = "#F6D55C", R = "#ED553B"),
language = get_AMR_locale(),
eucast_I = getOption("AMR_guideline", "EUCAST") == "EUCAST",
...
)
scale_fill_sir(colours_SIR = c(S = "#3CAEA3", SDD = "#8FD6C4", I = "#F6D55C",
R = "#ED553B"), language = get_AMR_locale(),
eucast_I = getOption("AMR_guideline", "EUCAST") == "EUCAST", ...)
scale_fill_sir(
colours_SIR = c(S = "#3CAEA3", SDD = "#8FD6C4", I = "#F6D55C", R = "#ED553B"),
language = get_AMR_locale(),
eucast_I = getOption("AMR_guideline", "EUCAST") == "EUCAST",
...
)
\method{plot}{mic}(x, mo = NULL, ab = NULL,
\method{plot}{mic}(
x,
mo = NULL,
ab = NULL,
guideline = getOption("AMR_guideline", "EUCAST"),
main = deparse(substitute(x)), ylab = translate_AMR("Frequency", language
= language),
xlab = translate_AMR("Minimum Inhibitory Concentration (mg/L)", language =
language), colours_SIR = c(S = "#3CAEA3", SDD = "#8FD6C4", I = "#F6D55C", R
= "#ED553B"), language = get_AMR_locale(), expand = TRUE,
main = deparse(substitute(x)),
ylab = translate_AMR("Frequency", language = language),
xlab = translate_AMR("Minimum Inhibitory Concentration (mg/L)", language = language),
colours_SIR = c(S = "#3CAEA3", SDD = "#8FD6C4", I = "#F6D55C", R = "#ED553B"),
language = get_AMR_locale(),
expand = TRUE,
include_PKPD = getOption("AMR_include_PKPD", TRUE),
breakpoint_type = getOption("AMR_breakpoint_type", "human"), ...)
breakpoint_type = getOption("AMR_breakpoint_type", "human"),
...
)
\method{autoplot}{mic}(object, mo = NULL, ab = NULL,
\method{autoplot}{mic}(
object,
mo = NULL,
ab = NULL,
guideline = getOption("AMR_guideline", "EUCAST"),
title = deparse(substitute(object)), ylab = translate_AMR("Frequency",
language = language),
xlab = translate_AMR("Minimum Inhibitory Concentration (mg/L)", language =
language), colours_SIR = c(S = "#3CAEA3", SDD = "#8FD6C4", I = "#F6D55C", R
= "#ED553B"), language = get_AMR_locale(), expand = TRUE,
title = deparse(substitute(object)),
ylab = translate_AMR("Frequency", language = language),
xlab = translate_AMR("Minimum Inhibitory Concentration (mg/L)", language = language),
colours_SIR = c(S = "#3CAEA3", SDD = "#8FD6C4", I = "#F6D55C", R = "#ED553B"),
language = get_AMR_locale(),
expand = TRUE,
include_PKPD = getOption("AMR_include_PKPD", TRUE),
breakpoint_type = getOption("AMR_breakpoint_type", "human"), ...)
breakpoint_type = getOption("AMR_breakpoint_type", "human"),
...
)
\method{plot}{disk}(x, main = deparse(substitute(x)),
\method{plot}{disk}(
x,
main = deparse(substitute(x)),
ylab = translate_AMR("Frequency", language = language),
xlab = translate_AMR("Disk diffusion diameter (mm)", language = language),
mo = NULL, ab = NULL, guideline = getOption("AMR_guideline", "EUCAST"),
colours_SIR = c(S = "#3CAEA3", SDD = "#8FD6C4", I = "#F6D55C", R =
"#ED553B"), language = get_AMR_locale(), expand = TRUE,
mo = NULL,
ab = NULL,
guideline = getOption("AMR_guideline", "EUCAST"),
colours_SIR = c(S = "#3CAEA3", SDD = "#8FD6C4", I = "#F6D55C", R = "#ED553B"),
language = get_AMR_locale(),
expand = TRUE,
include_PKPD = getOption("AMR_include_PKPD", TRUE),
breakpoint_type = getOption("AMR_breakpoint_type", "human"), ...)
breakpoint_type = getOption("AMR_breakpoint_type", "human"),
...
)
\method{autoplot}{disk}(object, mo = NULL, ab = NULL,
title = deparse(substitute(object)), ylab = translate_AMR("Frequency",
language = language), xlab = translate_AMR("Disk diffusion diameter (mm)",
language = language), guideline = getOption("AMR_guideline", "EUCAST"),
colours_SIR = c(S = "#3CAEA3", SDD = "#8FD6C4", I = "#F6D55C", R =
"#ED553B"), language = get_AMR_locale(), expand = TRUE,
\method{autoplot}{disk}(
object,
mo = NULL,
ab = NULL,
title = deparse(substitute(object)),
ylab = translate_AMR("Frequency", language = language),
xlab = translate_AMR("Disk diffusion diameter (mm)", language = language),
guideline = getOption("AMR_guideline", "EUCAST"),
colours_SIR = c(S = "#3CAEA3", SDD = "#8FD6C4", I = "#F6D55C", R = "#ED553B"),
language = get_AMR_locale(),
expand = TRUE,
include_PKPD = getOption("AMR_include_PKPD", TRUE),
breakpoint_type = getOption("AMR_breakpoint_type", "human"), ...)
breakpoint_type = getOption("AMR_breakpoint_type", "human"),
...
)
\method{plot}{sir}(x, ylab = translate_AMR("Percentage", language =
language), xlab = translate_AMR("Antimicrobial Interpretation", language =
language), main = deparse(substitute(x)), language = get_AMR_locale(),
...)
\method{autoplot}{sir}(object, title = deparse(substitute(object)),
\method{plot}{sir}(
x,
ylab = translate_AMR("Percentage", language = language),
xlab = translate_AMR("Antimicrobial Interpretation", language = language),
ylab = translate_AMR("Frequency", language = language), colours_SIR = c(S
= "#3CAEA3", SDD = "#8FD6C4", I = "#F6D55C", R = "#ED553B"),
language = get_AMR_locale(), ...)
main = deparse(substitute(x)),
language = get_AMR_locale(),
...
)
\method{autoplot}{sir}(
object,
title = deparse(substitute(object)),
xlab = translate_AMR("Antimicrobial Interpretation", language = language),
ylab = translate_AMR("Frequency", language = language),
colours_SIR = c(S = "#3CAEA3", SDD = "#8FD6C4", I = "#F6D55C", R = "#ED553B"),
language = get_AMR_locale(),
...
)
facet_sir(facet = c("interpretation", "antibiotic"), nrow = NULL)
scale_y_percent(breaks = function(x) seq(0, max(x, na.rm = TRUE), 0.1),
limits = c(0, NA))
scale_y_percent(
breaks = function(x) seq(0, max(x, na.rm = TRUE), 0.1),
limits = c(0, NA)
)
scale_sir_colours(..., aesthetics, colours_SIR = c(S = "#3CAEA3", SDD =
"#8FD6C4", I = "#F6D55C", R = "#ED553B"))
scale_sir_colours(
...,
aesthetics,
colours_SIR = c(S = "#3CAEA3", SDD = "#8FD6C4", I = "#F6D55C", R = "#ED553B")
)
theme_sir()
labels_sir_count(position = NULL, x = "antibiotic",
translate_ab = "name", minimum = 30, language = get_AMR_locale(),
combine_SI = TRUE, datalabels.size = 3, datalabels.colour = "grey15")
labels_sir_count(
position = NULL,
x = "antibiotic",
translate_ab = "name",
minimum = 30,
language = get_AMR_locale(),
combine_SI = TRUE,
datalabels.size = 3,
datalabels.colour = "grey15"
)
}
\arguments{
\item{keep_operators}{A \link{character} specifying how to handle operators (such as \code{>} and \code{<=}) in the input. Accepts one of three values: \code{"all"} (or \code{TRUE}) to keep all operators, \code{"none"} (or \code{FALSE}) to remove all operators, or \code{"edges"} to keep operators only at both ends of the range.}

View File

@@ -15,40 +15,62 @@
\alias{sir_df}
\title{Calculate Antimicrobial Resistance}
\usage{
resistance(..., minimum = 30, as_percent = FALSE,
only_all_tested = FALSE, guideline = getOption("AMR_guideline",
"EUCAST"))
resistance(
...,
minimum = 30,
as_percent = FALSE,
only_all_tested = FALSE,
guideline = getOption("AMR_guideline", "EUCAST")
)
susceptibility(..., minimum = 30, as_percent = FALSE,
only_all_tested = FALSE, guideline = getOption("AMR_guideline",
"EUCAST"))
susceptibility(
...,
minimum = 30,
as_percent = FALSE,
only_all_tested = FALSE,
guideline = getOption("AMR_guideline", "EUCAST")
)
sir_confidence_interval(..., ab_result = "R", minimum = 30,
as_percent = FALSE, only_all_tested = FALSE, confidence_level = 0.95,
side = "both", collapse = FALSE)
sir_confidence_interval(
...,
ab_result = "R",
minimum = 30,
as_percent = FALSE,
only_all_tested = FALSE,
confidence_level = 0.95,
side = "both",
collapse = FALSE
)
proportion_R(..., 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_IR(..., minimum = 30, as_percent = FALSE, only_all_tested = FALSE)
proportion_I(..., 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_SI(..., minimum = 30, as_percent = FALSE, only_all_tested = FALSE)
proportion_S(..., 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_AMR_locale(),
minimum = 30, as_percent = FALSE, combine_SI = TRUE,
confidence_level = 0.95)
proportion_df(
data,
translate_ab = "name",
language = get_AMR_locale(),
minimum = 30,
as_percent = FALSE,
combine_SI = TRUE,
confidence_level = 0.95
)
sir_df(data, translate_ab = "name", language = get_AMR_locale(),
minimum = 30, as_percent = FALSE, combine_SI = TRUE,
confidence_level = 0.95)
sir_df(
data,
translate_ab = "name",
language = get_AMR_locale(),
minimum = 30,
as_percent = FALSE,
combine_SI = TRUE,
confidence_level = 0.95
)
}
\arguments{
\item{...}{One or more vectors (or columns) with antibiotic interpretations. They will be transformed internally with \code{\link[=as.sir]{as.sir()}} 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 \emph{Examples}.}

View File

@@ -7,11 +7,23 @@
\alias{random_sir}
\title{Random MIC Values/Disk Zones/SIR Generation}
\usage{
random_mic(size = NULL, mo = NULL, ab = NULL, skew = "right",
severity = 1, ...)
random_mic(
size = NULL,
mo = NULL,
ab = NULL,
skew = "right",
severity = 1,
...
)
random_disk(size = NULL, mo = NULL, ab = NULL, skew = "left",
severity = 1, ...)
random_disk(
size = NULL,
mo = NULL,
ab = NULL,
skew = "left",
severity = 1,
...
)
random_sir(size = NULL, prob_SIR = c(0.33, 0.33, 0.33), ...)
}

View File

@@ -8,22 +8,51 @@
\alias{autoplot.resistance_predict}
\title{Predict Antimicrobial Resistance}
\usage{
resistance_predict(x, col_ab, col_date = NULL, year_min = NULL,
year_max = NULL, year_every = 1, minimum = 30, model = NULL,
I_as_S = TRUE, preserve_measurements = TRUE, info = interactive(), ...)
resistance_predict(
x,
col_ab,
col_date = NULL,
year_min = NULL,
year_max = NULL,
year_every = 1,
minimum = 30,
model = NULL,
I_as_S = TRUE,
preserve_measurements = TRUE,
info = interactive(),
...
)
sir_predict(x, col_ab, col_date = NULL, year_min = NULL, year_max = NULL,
year_every = 1, minimum = 30, model = NULL, I_as_S = TRUE,
preserve_measurements = TRUE, info = interactive(), ...)
sir_predict(
x,
col_ab,
col_date = NULL,
year_min = NULL,
year_max = NULL,
year_every = 1,
minimum = 30,
model = NULL,
I_as_S = TRUE,
preserve_measurements = TRUE,
info = interactive(),
...
)
\method{plot}{resistance_predict}(x, main = paste("Resistance Prediction of",
x_name), ...)
\method{plot}{resistance_predict}(x, main = paste("Resistance Prediction of", x_name), ...)
ggplot_sir_predict(x, main = paste("Resistance Prediction of", x_name),
ribbon = TRUE, ...)
ggplot_sir_predict(
x,
main = paste("Resistance Prediction of", x_name),
ribbon = TRUE,
...
)
\method{autoplot}{resistance_predict}(object,
main = paste("Resistance Prediction of", x_name), ribbon = TRUE, ...)
\method{autoplot}{resistance_predict}(
object,
main = paste("Resistance Prediction of", x_name),
ribbon = TRUE,
...
)
}
\arguments{
\item{x}{A \link{data.frame} containing isolates. Can be left blank for automatic determination, see \emph{Examples}.}

View File

@@ -4,8 +4,14 @@
\alias{top_n_microorganisms}
\title{Filter Top \emph{n} Microorganisms}
\usage{
top_n_microorganisms(x, n, property = "species", n_for_each = NULL,
col_mo = NULL, ...)
top_n_microorganisms(
x,
n,
property = "species",
n_for_each = NULL,
col_mo = NULL,
...
)
}
\arguments{
\item{x}{A data frame containing microbial data.}

View File

@@ -247,24 +247,69 @@ our_data_1st[all(betalactams() == "R"), ]
## Generate antibiograms
Since AMR v2.0 (March 2023), it is very easy to create different types of antibiograms, with support for 20 different languages.
The `AMR` package supports `r length(AMR:::LANGUAGES_SUPPORTED)` different languages for antibiograms and provides four types, as proposed by Klinker *et al.* (2021, [DOI 10.1177/20499361211011373](https://doi.org/10.1177/20499361211011373)):
There are four antibiogram types, as proposed by Klinker *et al.* (2021, [DOI 10.1177/20499361211011373](https://doi.org/10.1177/20499361211011373)), and they are all supported by the new `antibiogram()` function:
1. **Traditional Antibiogram (TA)** -- susceptibility of a species to individual antibiotics
2. **Combination Antibiogram (CA)** -- susceptibility of a species to combination regimens
3. **Syndromic Antibiogram (SA)** -- susceptibility of a species, stratified by clinical syndrome or setting
4. **Weighted-Incidence Syndromic Combination Antibiogram (WISCA)** -- estimated empirical coverage of a *regimen* for a *syndrome*, weighted by pathogen incidence and with quantified uncertainty
1. **Traditional Antibiogram (TA)** e.g, for the susceptibility of *Pseudomonas aeruginosa* to piperacillin/tazobactam (TZP)
2. **Combination Antibiogram (CA)** e.g, for the sdditional susceptibility of *Pseudomonas aeruginosa* to TZP + tobramycin versus TZP alone
3. **Syndromic Antibiogram (SA)** e.g, for the susceptibility of *Pseudomonas aeruginosa* to TZP among respiratory specimens (obtained among ICU patients only)
4. **Weighted-Incidence Syndromic Combination Antibiogram (WISCA)** e.g, for the susceptibility of *Pseudomonas aeruginosa* to TZP among respiratory specimens (obtained among ICU patients only) for male patients age >=65 years with heart failure
**If your goal is to guide empirical therapy, WISCA should be your default.** The reason is simple: when you start empirical treatment, you do not know which pathogen is causing the infection. Your next patient will not present with a species label attached to them. What matters is the probability that the *regimen* you choose will cover *whatever pathogen turns out to be the cause*, given the local epidemiology of the syndrome. Traditional antibiograms do not answer that question. They fragment information by species, ignore how frequently each species causes the syndrome, do not evaluate combination regimens, and provide no measure of uncertainty. WISCA addresses all of these limitations using a Bayesian framework (Hebert *et al.*, 2012; Bielicki *et al.*, 2016). See the [WISCA vignette](https://amr-for-r.org/articles/WISCA.html) for the full explanation.
In this section, we show how to use the `antibiogram()` function to create any of the above antibiogram types. For starters, this is what the included `example_isolates` data set looks like:
Traditional, combination, and syndromic antibiograms remain useful for **surveillance** purposes, i.e., tracking resistance trends per species over time. But if you care about clinical impact, about choosing the right empirical regimen for your patient, use WISCA.
For starters, this is what the included `example_isolates` data set looks like:
```{r}
example_isolates
```
### WISCA (recommended for empirical therapy guidance)
Use the `wisca()` function, or equivalently `antibiogram(..., wisca = TRUE)`. WISCA produces a single coverage estimate per regimen for the entire syndrome, weighted by pathogen incidence, with a 95% credible interval from Bayesian Monte Carlo simulation:
```{r wisca}
wisca_result <- example_isolates %>%
wisca(
antimicrobials = c("TZP", "TZP+TOB", "TZP+GEN"),
minimum = 10
) # Recommended threshold: ≥30
wisca_result
```
The output tells you: *"given the species distribution in your data, there is an estimated X% probability that this regimen covers the infection, with 95% credible interval [lower, upper]"*. That is the clinically relevant question.
For **syndrome-specific** or **patient-specific WISCA**, use the `syndromic_group` argument or group your data first. You can stratify by anything: ward, age group, risk profile, acquisition type. The `syndromic_group` argument accepts any column or expression:
```{r wisca_grouped}
wisca_out <- example_isolates %>%
top_n_microorganisms(n = 10) %>%
group_by(
age_group = age_groups(age, c(25, 50, 75)),
gender
) %>%
wisca(antimicrobials = c("TZP", "TZP+TOB", "TZP+GEN"))
wisca_out
```
Keep in mind that more granular stratification produces more relevant estimates for each subgroup, but with wider credible intervals due to smaller sample sizes. There is always a trade-off between granularity and precision. If local numbers are small, consider pooling data from multiple sites (Bielicki *et al.*, 2016).
For reliable WISCA results, ensure your data includes **only first isolates** (use `first_isolate()`) and consider filtering for **the top *n* species** (use `top_n_microorganisms()`), since rare contaminants can distort coverage estimates.
After creating the WISCA model, assessments can be done on the distributions of the Monte Carlo simulations that WISCA carried out:
```{r wisca_plots}
wisca_plot(wisca_out)
wisca_plot(wisca_out, wisca_plot_type = "posterior_coverage")
# a ggplot2 extension for WISCAs and other antibiograms:
ggplot2::autoplot(wisca_out)
```
### Traditional Antibiogram
To create a traditional antibiogram, simply state which antibiotics should be used. The `antibiotics` argument in the `antibiogram()` function supports any (combination) of the previously mentioned antibiotic class selectors:
If you need per-species susceptibility rates, e.g., for AMR surveillance reports, the traditional antibiogram remains the right tool. It reports the proportion of susceptible isolates per species per antibiotic:
```{r trad}
antibiogram(example_isolates,
@@ -285,9 +330,9 @@ antibiogram(example_isolates,
)
```
### Combined Antibiogram
### Combination Antibiogram
To create a combined antibiogram, use antibiotic codes or names with a plus `+` character like this:
A combination antibiogram shows how much additional susceptibility a second agent adds for a given species. This is useful for surveillance of combination regimens, but note that it is still species-stratified and does not account for pathogen incidence in the syndrome:
```{r comb}
combined_ab <- antibiogram(example_isolates,
@@ -299,7 +344,7 @@ combined_ab
### Syndromic Antibiogram
To create a syndromic antibiogram, the `syndromic_group` argument must be used. This can be any column in the data, or e.g. an `ifelse()` with calculations based on certain columns:
A syndromic antibiogram stratifies per-species susceptibility by clinical context (ward, specimen type, etc.). It adds clinical context to the traditional antibiogram but is still species-level, without incidence weighting or uncertainty quantification. For surveillance by setting this is fine; for empirical therapy guidance, WISCA is preferred:
```{r synd}
antibiogram(example_isolates,
@@ -308,40 +353,12 @@ antibiogram(example_isolates,
)
```
### Weighted-Incidence Syndromic Combination Antibiogram (WISCA)
To create a **Weighted-Incidence Syndromic Combination Antibiogram (WISCA)**, simply set `wisca = TRUE` in the `antibiogram()` function, or use the dedicated `wisca()` function. Unlike traditional antibiograms, WISCA provides syndrome-based susceptibility estimates, weighted by pathogen incidence and antimicrobial susceptibility patterns.
```{r wisca}
example_isolates %>%
wisca(
antibiotics = c("TZP", "TZP+TOB", "TZP+GEN"),
minimum = 10
) # Recommended threshold: ≥30
```
WISCA uses a **Bayesian decision model** to integrate data from multiple pathogens, improving empirical therapy guidance, especially for low-incidence infections. It is **pathogen-agnostic**, meaning results are syndrome-based rather than stratified by microorganism.
For reliable results, ensure your data includes **only first isolates** (use `first_isolate()`) and consider filtering for **the top *n* species** (use `top_n_microorganisms()`), as WISCA outcomes are most meaningful when based on robust incidence estimates.
For **patient- or syndrome-specific WISCA**, run the function on a grouped `tibble`, i.e., using `group_by()` first:
```{r wisca_grouped}
example_isolates %>%
top_n_microorganisms(n = 10) %>%
group_by(
age_group = age_groups(age, c(25, 50, 75)),
gender
) %>%
wisca(antibiotics = c("TZP", "TZP+TOB", "TZP+GEN"))
```
### Plotting antibiograms
Antibiograms can be plotted using `autoplot()` from the `ggplot2` packages, since this `AMR` package provides an extension to that function:
All antibiogram types, including WISCA, can be plotted using `autoplot()` from the `ggplot2` package, since this `AMR` package provides an extension to that function:
```{r}
autoplot(combined_ab)
autoplot(wisca_result)
```
To calculate antimicrobial resistance in a more sensible way, also by correcting for too few results, we use the `resistance()` and `susceptibility()` functions.
@@ -417,4 +434,4 @@ autoplot(mic_values, mo = "K. pneumoniae", ab = "cipro", guideline = "EUCAST 202
----
*Author: Dr. Matthijs Berends, 23rd Feb 2025*
*Author: Dr. Matthijs Berends, 23rd June 2026*

View File

@@ -22,75 +22,58 @@ knitr::opts_chunk$set(
)
```
> This explainer was largely written by our [AMR for R Assistant](https://chat.amr-for-r.org), a ChatGPT manually-trained model able to answer any question about the `AMR` package.
## Why WISCA?
## Introduction
When a clinician starts empirical antimicrobial therapy, the causative pathogen is unknown. The question they need answered is not *"what proportion of* E. coli *is susceptible to ciprofloxacin?"* but rather *"what is the probability that this regimen will adequately cover whatever pathogen turns out to be causing my patient's infection?"*
Clinical guidelines for empirical antimicrobial therapy require *probabilistic reasoning*: what is the chance that a regimen will cover the likely infecting organisms, before culture results are available?
The traditional cumulative antibiogram, as standardised by CLSI M39, cannot answer that question. It presents susceptibility percentages per species per antibiotic, but:
This is the purpose of **WISCA**, or **Weighted-Incidence Syndromic Combination Antibiogram**.
- **It fragments information by organism.** The clinician must mentally combine susceptibility rates across multiple species, weighting by how often each species causes the syndrome, a calculation nobody does at the bedside.
- **It ignores pathogen incidence.** A species that causes 2% of infections is given the same visual weight as one that causes 60%.
- **It does not evaluate combination regimens.** Much empirical therapy consists of two or more agents, but the traditional antibiogram only shows monotherapy per organism.
- **It provides no measure of uncertainty.** A reported "90% susceptible" based on 50 isolates has a 95% confidence interval of roughly 78-97% (Clopper-Pearson), yet the antibiogram presents it as a point estimate without context.
WISCA is a Bayesian approach that integrates:
**WISCA** (Weighted-Incidence Syndromic Combination Antibiogram) resolves all four limitations. It estimates the probability that a regimen will provide adequate empirical coverage for a given infection syndrome, weighted by local pathogen incidence, with full uncertainty quantification via Bayesian inference.
- **Pathogen prevalence** (how often each species causes the syndrome),
- **Regimen susceptibility** (how often a regimen works *if* the pathogen is known),
The concept was introduced by Hebert *et al.* (2012), who demonstrated that traditional antibiogram susceptibility rates could be misleading: ciprofloxacin appeared 84% effective against *E. coli* in the traditional antibiogram, but WISCA revealed only 62% coverage for UTI and 37% for abdominal infections, because enterococci (intrinsically resistant) and other species contribute substantially to these syndromes. Randhawa *et al.* (2014) showed that WISCA-guided regimen selection could improve time-to-adequate-coverage on the ICU by over 40%. Bielicki *et al.* (2016) introduced the Bayesian framework now used in this package, enabling credible intervals and multi-centre pooling. Cook *et al.* (2022) applied it globally across 52 hospitals in 23 countries.
to estimate the **overall empirical coverage** of antimicrobial regimens, with quantified uncertainty.
This vignette explains how WISCA works, why it is useful, and how to apply it using the `AMR` package.
## Why traditional antibiograms fall short
A standard antibiogram gives you:
```
Species → Antibiotic → Susceptibility %
```
But clinicians dont know the species *a priori*. They need to choose a regimen that covers the **likely pathogens**, without knowing which one is present.
Traditional antibiograms calculate the susceptibility % as just the number of resistant isolates divided by the total number of tested isolates. Therefore, traditional antibiograms:
- Fragment information by organism,
- Do not weight by real-world prevalence,
- Do not account for combination therapy or sample size,
- Do not provide uncertainty.
## The idea of WISCA
## The idea
WISCA asks:
> "What is the **probability** that this regimen **will cover** the pathogen, given the syndrome?"
This means combining two things:
This means combining two quantities:
- **Incidence** of each pathogen in the syndrome,
- **Pathogen incidence** in the syndrome (how often each species causes it),
- **Susceptibility** of each pathogen to the regimen.
We can write this as:
$$\text{Coverage} = \sum_i (\text{Incidence}_i \times \text{Susceptibility}_i)$$
For example, suppose:
For example, suppose in your hospital:
- *E. coli* causes 60% of cases, and 90% of *E. coli* are susceptible to a drug.
- *Klebsiella* causes 40% of cases, and 70% of *Klebsiella* are susceptible.
- *E. coli* causes 60% of UTIs, and 90% of *E. coli* are susceptible to a drug.
- *Klebsiella* causes 40% of UTIs, and 70% of *Klebsiella* are susceptible.
Then:
$$\text{Coverage} = (0.6 \times 0.9) + (0.4 \times 0.7) = 0.82$$
But in real data, incidence and susceptibility are **estimated from samples**, so they carry uncertainty. WISCA models this **probabilistically**, using conjugate Bayesian distributions.
That 82% is a far more clinically meaningful number than the species-level "90% of *E. coli*" and "70% of *Klebsiella*" reported separately in a traditional antibiogram, because it directly answers the question the clinician actually faces.
## The Bayesian engine behind WISCA
But in real data, both incidence and susceptibility are **estimated from finite samples**, so they carry uncertainty. A sample of 50 isolates is not a census. WISCA models this uncertainty **probabilistically**, using conjugate Bayesian distributions.
## The Bayesian engine
### Pathogen incidence
Let:
- $K$ be the number of pathogens,
- $\boldsymbol{\alpha} = (1, 1, \ldots, 1)$ be a $\text{Dirichlet}$ prior (uniform),
- $\boldsymbol{n} = (n_1, \ldots, n_K)$ be the observed counts per species.
- $\boldsymbol{\alpha} = (1, 1, \ldots, 1)$ be a $\text{Dirichlet}$ prior (uniform, non-informative),
- $\boldsymbol{n} = (n_1, \ldots, n_K)$ be the observed isolate counts per species.
Then the posterior incidence is:
@@ -100,15 +83,17 @@ To simulate from this, we use:
$$x_i \sim \text{Gamma}(\alpha_i + n_i,\ 1), \quad p_i = \frac{x_i}{\sum_{j=1}^{K} x_j}$$
The Dirichlet is the conjugate prior for multinomial data. With the non-informative prior $\text{Dirichlet}(1, 1, \ldots, 1)$, the posterior is dominated by the data once sample sizes are reasonable. With small samples, the posterior is appropriately more diffuse, reflecting genuine uncertainty, and the resulting credible intervals will be wider.
### Susceptibility
Each pathogen--regimen pair has a prior and data:
Each pathogen-regimen pair has a prior and observed data:
- Default prior: $\text{Beta}(0.5, 0.5)$ (Jeffreys prior)
- Intrinsically resistant pairs: $\text{Beta}(1, 9999)$, forcing near-zero susceptibility regardless of observed data (based on EUCAST Expected Resistant Phenotypes)
- Data: $S$ susceptible out of $N$ tested
The $S$ category could also include values SDD (susceptible, dose-dependent) and I (intermediate \[CLSI\], or susceptible, increased exposure \[EUCAST\]).
The $S$ category could also include values SDD (susceptible, dose-dependent) and I (intermediate [CLSI], or susceptible, increased exposure [EUCAST]).
Then the posterior is:
@@ -129,9 +114,25 @@ Repeat this simulation (e.g., 1000 times) and summarise:
- **Mean** = expected coverage
- **Quantiles** = credible interval (95% by default)
Because each simulation draws from the full posterior, the resulting distribution of coverage estimates naturally captures the joint uncertainty in both pathogen incidence and susceptibility. The credible interval tells you how confident you can be in the coverage estimate, something a traditional antibiogram never provides.
## When to use WISCA vs. traditional antibiograms
| Goal | Recommended approach |
|------|---------------------|
| Guide empirical therapy decisions | **WISCA** |
| Compare regimens for a syndrome | **WISCA** |
| Evaluate combination regimens | **WISCA** |
| Antimicrobial stewardship (A-team) | **WISCA** |
| Track resistance trends per species | Traditional / Combination |
| AMR surveillance reporting | Traditional / Syndromic |
| Understand species-level epidemiology | Traditional |
In short: if the end goal involves a *patient* who does not yet have a culture result, WISCA is the appropriate tool. If the end goal is *surveillance* of resistance at the species level, the traditional antibiogram remains fit for purpose.
## Practical use in the `AMR` package
### Prepare data and simulate synthetic syndrome
### Prepare data
```{r}
library(AMR)
@@ -140,11 +141,11 @@ data <- example_isolates
# Structure of our data
data
# Add a fake syndrome column
data$syndrome <- ifelse(data$mo %like% "coli", "UTI", "No UTI")
# Add a synthetic syndrome column for demonstration
data$syndrome <- ifelse(data$mo %like% "coli", "UTI", "Non-UTI")
```
### Basic WISCA antibiogram
### Basic WISCA
```{r}
wisca(data,
@@ -154,6 +155,8 @@ wisca(data,
### Use combination regimens
Combination regimens are specified with a `+` separator. WISCA evaluates whether *at least one* agent in the combination covers the pathogen:
```{r}
wisca(data,
antimicrobials = c("AMC", "AMC + CIP", "AMC + GEN")
@@ -162,6 +165,8 @@ wisca(data,
### Stratify by syndrome
Use `syndromic_group` to produce separate WISCA estimates per clinical stratum. You can pass a column name or any expression:
```{r}
wisca(data,
antimicrobials = c("AMC", "AMC + CIP", "AMC + GEN"),
@@ -179,6 +184,12 @@ wisca(data,
)
```
### Interpreting the output
Each row shows the estimated empirical coverage for a regimen, with a 95% credible interval. When comparing regimens:
- **Overlapping credible intervals** mean there is no statistically significant difference in coverage. If a narrower-spectrum regimen overlaps with a broader one, the narrower-spectrum option can be preferred on stewardship grounds.
- **Non-overlapping credible intervals** indicate a clinically meaningful difference in coverage.
## Sensible defaults, which can be customised
@@ -186,19 +197,26 @@ wisca(data,
- `conf_interval = 0.95`: coverage interval width
- `combine_SI = TRUE`: count "I" and "SDD" as susceptible
## Practical considerations
- **First isolates only**: always deduplicate using `first_isolate()` before running WISCA. Repeat isolates introduce bias.
- **Pathogen selection**: consider filtering with `top_n_microorganisms()`. Including rare contaminants (e.g. CoNS without clinical context) can distort estimates and may artificially lower coverage (Cook *et al.*, 2022).
- **Sample size**: coverage estimates become reliable with approximately 100+ isolates. For smaller datasets, consider pooling data from multiple sites, but only after verifying that pathogen distributions are sufficiently similar (Bielicki *et al.*, 2016).
- **Culture request bias**: WISCA is only as good as the data it is based on. If cultures are selectively requested (e.g. only after treatment failure), the dataset will be biased towards resistant isolates. A robust culture policy is essential for reliable estimates.
## Limitations
- It assumes your data are representative
- No adjustment for patient-level covariates, although these could be passed onto the `syndromic_group` argument
- WISCA does not model resistance over time, you might want to use `tidymodels` for that, for which we [wrote a basic introduction](https://amr-for-r.org/articles/AMR_with_tidymodels.html)
- It assumes your data are representative of the patient population you are treating
- No direct adjustment for patient-level covariates, although these can be passed onto the `syndromic_group` argument for stratification
- WISCA does not model resistance trends over time; for that, you might want to use `tidymodels`, for which we [wrote a basic introduction](https://amr-for-r.org/articles/AMR_with_tidymodels.html)
## Summary
WISCA enables:
- Empirical regimen comparison,
- Syndrome-specific coverage estimation,
- Fully probabilistic interpretation.
- **Empirical regimen comparison**, answering the clinician's actual question
- **Syndrome-specific coverage estimation**, stratifiable by any clinical variable
- **Fully probabilistic interpretation**, with credible intervals that honestly communicate uncertainty
It is available in the `AMR` package via either:
@@ -208,6 +226,9 @@ wisca(...)
antibiogram(..., wisca = TRUE)
```
## Reference
## References
Bielicki, JA, et al. (2016). *Selecting appropriate empirical antibiotic regimens for paediatric bloodstream infections: application of a Bayesian decision model to local and pooled antimicrobial resistance surveillance data.* **J Antimicrob Chemother**. 71(3):794-802. https://doi.org/10.1093/jac/dkv397
1. Hebert C, Ridgway J, Vekhter B, Brown EC, Weber SG, Robicsek A. Demonstration of the weighted-incidence syndromic combination antibiogram: an empiric prescribing decision aid. *Infect Control Hosp Epidemiol.* 2012;33(4):381-388. https://doi.org/10.1086/664768
2. Randhawa V, Sarwar S, Walker S, Elligsen M, Palmay L, Daneman N. Weighted-incidence syndromic combination antibiograms to guide empiric treatment of critical care infections: a retrospective cohort study. *Crit Care.* 2014;18(3):R112. https://doi.org/10.1186/cc13901
3. Bielicki JA, Sharland M, Johnson AP, Henderson KL, Cromwell DA. Selecting appropriate empirical antibiotic regimens for paediatric bloodstream infections: application of a Bayesian decision model to local and pooled antimicrobial resistance surveillance data. *J Antimicrob Chemother.* 2016;71(3):794-802. https://doi.org/10.1093/jac/dkv397
4. Cook A, Sharland M, Yau Y, Bielicki J. Improving empiric antibiotic prescribing in pediatric bloodstream infections: a potential application of weighted-incidence syndromic combination antibiograms (WISCA). *Expert Rev Anti Infect Ther.* 2022;20(3):445-456. https://doi.org/10.1080/14787210.2021.1967145