% Generated by roxygen2: do not edit by hand % Please edit documentation in R/antibiogram.R \name{antibiogram} \alias{antibiogram} \alias{wisca} \alias{retrieve_wisca_parameters} \alias{plot.antibiogram} \alias{autoplot.antibiogram} \alias{wisca_plot} \alias{knit_print.antibiogram} \title{Generate Traditional, Combination, Syndromic, or WISCA Antibiograms} \usage{ 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, ... ) 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, ... ) 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 = ""), ... ) } \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()}}).} \item{antimicrobials}{A vector specifying the antimicrobials containing SIR values to include in the antibiogram (see \emph{Examples}). Will be evaluated using \code{\link[=guess_ab_col]{guess_ab_col()}}. This can be: \itemize{ \item Any antimicrobial name or code that could match (see \code{\link[=guess_ab_col]{guess_ab_col()}}) to any column in \code{x} \item Any \link[=antimicrobial_selectors]{antimicrobial selector}, such as \code{\link[=aminoglycosides]{aminoglycosides()}} or \code{\link[=carbapenems]{carbapenems()}} \item A combination of the above, using \code{c()}, e.g.: \itemize{ \item \code{c(aminoglycosides(), "AMP", "AMC")} \item \code{c(aminoglycosides(), carbapenems())} } \item Column indices using numbers \item Combination therapy, indicated by using \code{"+"}, with or without \link[=antimicrobial_selectors]{antimicrobial selectors}, e.g.: \itemize{ \item \code{"cipro + genta"} \item \code{"TZP+TOB"} \item \code{c("TZP", "TZP+GEN", "TZP+TOB")} \item \code{carbapenems() + "GEN"} \item \code{carbapenems() + c("", "GEN")} \item \code{carbapenems() + c("", aminoglycosides())} } }} \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{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.} \item{formatting_type}{Numeric value (1-22 for WISCA, 1-12 for non-WISCA) indicating how the 'cells' of the antibiogram table should be formatted. See \emph{Details} > \emph{Formatting Type} for a list of options.} \item{col_mo}{Column name of the names or codes of the microorganisms (see \code{\link[=as.mo]{as.mo()}}) - the default is the first column of class \code{\link{mo}}. Values will be coerced using \code{\link[=as.mo]{as.mo()}}.} \item{language}{Language to translate text, which defaults to the system language (see \code{\link[=get_AMR_locale]{get_AMR_locale()}}).} \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{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}).} \item{interval_side}{The side of the confidence interval, either \code{"two-tailed"} (default), \code{"left"} or \code{"right"}.} \item{info}{A \link{logical} to indicate info should be printed - the default is \code{TRUE} only in interactive mode.} \item{parallel}{A \link{logical} to indicate if parallel computing must be used, defaults to \code{FALSE}. Requires the \code{\link[future.apply:future_lapply]{future.apply}} package. For WISCA, Monte Carlo simulations are distributed across workers; for grouped antibiograms, each group is processed by a separate worker. \strong{A non-sequential \code{\link[future:plan]{future::plan()}} must already be active before setting \code{parallel = TRUE}} -- for example, \code{future::plan(future::multisession)}. An error is thrown if \code{parallel = TRUE} is used without a plan set by the user.} \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.} \item{geom}{The plotting style for the point estimate. One of \code{"pointrange"} (default), \code{"point"}, \code{"col"}/\code{"bar"}, or \code{"errorbar"}. \code{"pointrange"} is recommended for coverage data: bars imply a meaningful baseline at zero, which coverage estimates rarely have.} \item{ci}{Logical, whether to draw the credible/confidence interval. Defaults to \code{TRUE}. Ignored (forced \code{TRUE}) when \code{geom = "pointrange"} or \code{"errorbar"}, since the interval is intrinsic to those geoms.} \item{sort}{Logical, whether to order regimens by coverage. Defaults to \code{TRUE}. When faceted (per pathogen) or grouped (syndromic), ordering is applied within each panel/group.} \item{flip}{Logical, whether to draw regimens on the y-axis (horizontal). Defaults to \code{NULL}, which flips automatically when any regimen label exceeds 20 characters (long combination names read poorly on the x-axis). Set \code{TRUE}/\code{FALSE} to override.} \item{caption}{Text to show as caption, will explain non-inferiority for WISCA models.} \item{wisca_plot_type}{Either \code{"susceptibility_incidence"} (default) or \code{"posterior_coverage"}.} \item{italicise}{A \link{logical} to indicate whether the microorganism names in the \link[knitr:kable]{knitr} table should be made italic, using \code{\link[=italicise_taxonomy]{italicise_taxonomy()}}.} \item{na}{Character to use for showing \code{NA} values.} } \description{ Create detailed antibiograms with options for traditional, combination, syndromic, and Bayesian WISCA methods. Adhering to previously described approaches (see \emph{Source}) and especially the Bayesian WISCA model (Weighted-Incidence Syndromic Combination Antibiogram) by Bielicki \emph{et al.}, these functions provide flexible output formats including plots and tables, ideal for integration with R Markdown and Quarto reports. } \details{ These functions return a table with values between 0 and 100 for \emph{susceptibility}, not resistance. \strong{Remember that you should filter your data to let it contain only first isolates!} This is needed to exclude duplicates and to reduce selection bias. Use \code{\link[=first_isolate]{first_isolate()}} to determine them with one of the four available algorithms: isolate-based, patient-based, episode-based, or phenotype-based. For estimating antimicrobial coverage, especially when creating a WISCA, the outcome might become more reliable by only including the top \emph{n} species encountered in the data. You can filter on this top \emph{n} using \code{\link[=top_n_microorganisms]{top_n_microorganisms()}}. For example, use \code{top_n_microorganisms(your_data, n = 10)} as a pre-processing step to only include the top 10 species in the data. The numeric values of an antibiogram are stored in a long format as the \link[=attributes]{attribute} \code{long_numeric}. You can retrieve them using \code{attributes(x)$long_numeric}, where \code{x} is the outcome of \code{\link[=antibiogram]{antibiogram()}} or \code{\link[=wisca]{wisca()}}. This is ideal for e.g. advanced plotting. \subsection{Formatting Type}{ The formatting of the 'cells' of the table can be set with the argument \code{formatting_type}. In these examples, \code{5} indicates the antimicrobial coverage (\code{4-6} the confidence level), \code{15} the number of susceptible isolates, and \code{300} the number of tested (i.e., available) isolates: \enumerate{ \item 5 \item 15 \item 300 \item 15/300 \item 5 (300) \item 5\% (300) \item 5 (N=300) \item 5\% (N=300) \item 5 (15/300) \item 5\% (15/300) \item 5 (N=15/300) \item 5\% (N=15/300) \item 5 (4-6) \item 5\% (4-6\%) - \strong{default for WISCA} \item 5 (4-6,300) \item 5\% (4-6\%,300) \item 5 (4-6,N=300) \item 5\% (4-6\%,N=300) - \strong{default for non-WISCA} \item 5 (4-6,15/300) \item 5\% (4-6\%,15/300) \item 5 (4-6,N=15/300) \item 5\% (4-6\%,N=15/300) } The default can be set globally with the package option \code{\link[=AMR-options]{AMR_antibiogram_formatting_type}}, e.g. \code{options(AMR_antibiogram_formatting_type = 5)}. Do note that for WISCA, the total numbers of tested and susceptible isolates are less useful to report, since these are included in the Bayesian model and apparent from the susceptibility and its confidence level. Set \code{digits} (defaults to \code{0}) to alter the rounding of the susceptibility percentages. } \subsection{Antibiogram Types}{ There are various antibiogram types, as summarised by Klinker \emph{et al.} (2021, \doi{10.1177/20499361211011373}), and they are all supported by \code{\link[=antibiogram]{antibiogram()}}. For clinical coverage estimations, \strong{use WISCA whenever possible}, since it provides more precise coverage estimates by accounting for pathogen incidence and antimicrobial susceptibility, as has been shown by Bielicki \emph{et al.} (2020, \doi{10.1001/jamanetworkopen.2019.21124}). See the section \emph{Explaining WISCA} on this page. Do note that WISCA is pathogen-agnostic, meaning that the outcome is not stratied by pathogen, but rather by syndrome. \enumerate{ \item \strong{Traditional Antibiogram} Case example: Susceptibility of \emph{Pseudomonas aeruginosa} to piperacillin/tazobactam (TZP) Code example: \if{html}{\out{