diff --git a/DESCRIPTION b/DESCRIPTION
index 26c504a7d..1b14fb83e 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -1,6 +1,6 @@
Package: AMR
-Version: 2.1.1.9125
-Date: 2025-01-17
+Version: 2.1.1.9126
+Date: 2025-01-26
Title: Antimicrobial Resistance Data Analysis
Description: Functions to simplify and standardise antimicrobial resistance (AMR)
data analysis and to work with microbial and antimicrobial properties by
@@ -59,4 +59,4 @@ License: GPL-2 | file LICENSE
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.3.2
-Roxygen: list(markdown = TRUE)
+Roxygen: list(markdown = TRUE, old_usage = TRUE)
diff --git a/NAMESPACE b/NAMESPACE
index 2dade3ccd..d9ca17aa2 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -32,6 +32,8 @@ S3method(Ops,mic)
S3method(Summary,mic)
S3method(all,amr_selector)
S3method(all,amr_selector_any_all)
+S3method(antibiogram,default)
+S3method(antibiogram,grouped_df)
S3method(any,amr_selector)
S3method(any,amr_selector_any_all)
S3method(as.data.frame,ab)
@@ -219,6 +221,7 @@ export(g.test)
export(geom_sir)
export(get_AMR_locale)
export(get_episode)
+export(get_long_numeric_format)
export(get_mo_source)
export(ggplot_pca)
export(ggplot_sir)
@@ -335,9 +338,11 @@ export(streptogramins)
export(susceptibility)
export(tetracyclines)
export(theme_sir)
+export(top_n_microorganisms)
export(translate_AMR)
export(trimethoprims)
export(ureidopenicillins)
+export(wisca)
importFrom(graphics,arrows)
importFrom(graphics,axis)
importFrom(graphics,barplot)
diff --git a/NEWS.md b/NEWS.md
index dd6e175ce..5483caddd 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,4 +1,4 @@
-# AMR 2.1.1.9125
+# AMR 2.1.1.9126
*(this beta version will eventually become v3.0. We're happy to reach a new major milestone soon, which will be all about the new One Health support! Install this beta using [the instructions here](https://msberends.github.io/AMR/#latest-development-version).)*
@@ -6,7 +6,7 @@
This package now supports not only tools for AMR data analysis in clinical settings, but also for veterinary and environmental microbiology. This was made possible through a collaboration with the [University of Prince Edward Island's Atlantic Veterinary College](https://www.upei.ca/avc), Canada. To celebrate this great improvement of the package, we also updated the package logo to reflect this change.
## Breaking
-* Removed all functions and references that used the deprecated `rsi` class, which were all replaced with their `sir` equivalents over a year ago
+* Removed all functions and references that used the deprecated `rsi` class, which were all replaced with their `sir` equivalents two years ago
## New
* **One Health implementation**
@@ -16,6 +16,8 @@ This package now supports not only tools for AMR data analysis in clinical setti
* The `antibiotics` data set contains all veterinary antibiotics, such as pradofloxacin and enrofloxacin. All WHOCC codes for veterinary use have been added as well.
* `ab_atc()` now supports ATC codes of veterinary antibiotics (that all start with "Q")
* `ab_url()` now supports retrieving the WHOCC url of their ATCvet pages
+* Support for WISCA antibiograms**
+ * The `antibiogram()` function now supports creating true Weighted-Incidence Syndromic Combination Antibiograms (WISCA), a powerful Bayesian method for estimating regimen coverage probabilities using pathogen incidence and antimicrobial susceptibility data. WISCA offers improved precision for syndrome-specific treatment, even in datasets with sparse data. A dedicated `wisca()` function is also available for easy usage.
* **Major update to fungal taxonomy and tools for mycologists**
* MycoBank has now been integrated as the primary taxonomic source for fungi. The `microorganisms` data set has been enriched with new columns (`mycobank`, `mycobank_parent`, and `mycobank_renamed_to`) that provide detailed information for fungal species.
* A remarkable addition of over 20,000 new fungal records
@@ -33,7 +35,9 @@ This package now supports not only tools for AMR data analysis in clinical setti
* **Support for `tidymodels`**
* All antimicrobial selectors (such as `aminoglycosides()` and `betalactams()`) are now supported in `tidymodels` packages such as `recipe` and `parsnip`. See for more info [our tutorial](https://msberends.github.io/AMR/articles/AMR_with_tidymodels.html) on using these AMR functions for predictive modelling.
* **Other**
+ * New function `top_n_microorganisms()` to filter a data set to the top *n* of any taxonomic property, e.g., filter to the top 3 species, filter to any species in the top 5 genera, or filter to the top 3 species in each of the top 5 genera
* New function `mo_group_members()` to retrieve the member microorganisms of a microorganism group. For example, `mo_group_members("Strep group C")` returns a vector of all microorganisms that belong to that group.
+
## Changed
* SIR interpretation
@@ -68,12 +72,12 @@ This package now supports not only tools for AMR data analysis in clinical setti
* Updated all antibiotic DDDs from WHOCC
* Added over 1,500 trade names for antibiotics
* Fix for using a manual value for `mo_transform` in `antibiogram()`
+* Fixed a bug for when `antibiogram()` returns an empty data set
* Fix for mapping 'high level' antibiotics in `as.ab()` (amphotericin B-high, gentamicin-high, kanamycin-high, streptomycin-high, tobramycin-high)
* Improved overall algorithm of `as.ab()` for better performance and accuracy
* Improved overall algorithm of `as.mo()` for better performance and accuracy. Specifically:
* More weight is given to genus and species combinations in cases where the subspecies is miswritten, so that the result will be the correct genus and species
* Genera from the World Health Organization's (WHO) Priority Pathogen List now have the highest prevalence
-* Fixed a bug for when `antibiogram()` returns an empty data set
* Fixed a bug for `sir_confidence_interval()` when there are no isolates available
* Updated the prevalence calculation to include genera from the World Health Organization's (WHO) Priority Pathogen List
* Improved algorithm of `first_isolate()` when using the phenotype-based method, to prioritise records with the highest availability of SIR values
@@ -83,14 +87,15 @@ This package now supports not only tools for AMR data analysis in clinical setti
* Added arguments `esbl`, `carbapenemase`, `mecA`, `mecC`, `vanA`, `vanB` to denote column names or logical values indicating presence of these genes (or production of their proteins)
## Other
+* Added Dr. Larisse Bolton as contributor for her fantastic implementation of WISCA in a mathematically solid way
+* Added Matthew Saab, Dr. Jordan Stull, and Prof. Javier Sanchez as contributors for their tremendous input on veterinary breakpoints and interpretations
* Greatly improved `vctrs` integration, a Tidyverse package working in the background for many Tidyverse functions. For users, this means that functions such as `dplyr`'s `bind_rows()`, `rowwise()` and `c_across()` are now supported for e.g. columns of class `mic`. Despite this, this `AMR` package is still zero-dependent on any other package, including `dplyr` and `vctrs`.
* Greatly updated and expanded documentation
-* Added Larisse Bolton, Jordan Stull, Matthew Saab, and Javier Sanchez as contributors, to thank them for their valuable input
* Stopped support for SAS (`.xpt`) files, since their file structure and extremely inefficient and requires more disk space than GitHub allows in a single commit.
## Older Versions
-This changelog only contains changes from AMR v3.0 (October 2024) and later.
+This changelog only contains changes from AMR v3.0 (February 2025) and later.
* For prior v2 versions, please see [our v2 archive](https://github.com/msberends/AMR/blob/v2.1.1/NEWS.md).
* For prior v1 versions, please see [our v1 archive](https://github.com/msberends/AMR/blob/v1.8.2/NEWS.md).
diff --git a/PythonPackage/AMR/AMR.egg-info/PKG-INFO b/PythonPackage/AMR/AMR.egg-info/PKG-INFO
index 3f123a1af..b8389d8fe 100644
--- a/PythonPackage/AMR/AMR.egg-info/PKG-INFO
+++ b/PythonPackage/AMR/AMR.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 2.2
Name: AMR
-Version: 2.1.1.9125
+Version: 2.1.1.9126
Summary: A Python wrapper for the AMR R package
Home-page: https://github.com/msberends/AMR
Author: Matthijs Berends
diff --git a/PythonPackage/AMR/AMR/__init__.py b/PythonPackage/AMR/AMR/__init__.py
index 2ca99691e..26567f233 100644
--- a/PythonPackage/AMR/AMR/__init__.py
+++ b/PythonPackage/AMR/AMR/__init__.py
@@ -26,6 +26,7 @@
from .functions import age
from .functions import age_groups
from .functions import antibiogram
+from .functions import wisca
from .functions import amr_class
from .functions import amr_selector
from .functions import aminoglycosides
@@ -201,5 +202,6 @@
from .functions import sir_predict
from .functions import ggplot_sir_predict
from .functions import skewness
+from .functions import top_n_microorganisms
from .functions import reset_AMR_locale
from .functions import translate_AMR
diff --git a/PythonPackage/AMR/AMR/datasets.py b/PythonPackage/AMR/AMR/datasets.py
index 096ed8a24..6d1dccd68 100644
--- a/PythonPackage/AMR/AMR/datasets.py
+++ b/PythonPackage/AMR/AMR/datasets.py
@@ -3,6 +3,7 @@
RESET = '\033[0m'
import os
+import sys
from rpy2 import robjects
from rpy2.robjects import pandas2ri
from rpy2.robjects.packages import importr, isinstalled
@@ -10,7 +11,7 @@
import importlib.metadata as metadata
# Get the path to the virtual environment
-venv_path = os.getenv('VIRTUAL_ENV') # Path to the active virtual environment
+venv_path = sys.prefix
# Define R library path within the venv
r_lib_path = os.path.join(venv_path, "R_libs")
@@ -19,10 +20,12 @@
# Set the R library path in .libPaths
base = importr('base')
base._libPaths(r_lib_path)
+r_amr_lib_path = base._libPaths()[0]
# Check if the AMR package is installed in R
-if not isinstalled('AMR'):
+if not isinstalled('AMR', lib_loc = r_amr_lib_path):
utils = importr('utils')
+ print(f"{BLUE}AMR:{RESET} Installing AMR package to {BLUE}{r_amr_lib_path}/{RESET}...", flush=True)
utils.install_packages('AMR', repos='https://msberends.r-universe.dev', quiet=True)
# Python package version of AMR
@@ -37,7 +40,7 @@
# Compare R and Python package versions
if r_amr_version != python_amr_version:
try:
- print(f"{BLUE}AMR:{RESET} Updating package version{RESET}", flush=True)
+ print(f"{BLUE}AMR:{RESET} Updating AMR package in {BLUE}{r_amr_lib_path}/{RESET}...", flush=True)
utils = importr('utils')
utils.install_packages('AMR', repos='https://msberends.r-universe.dev', quiet=True)
except Exception as e:
diff --git a/PythonPackage/AMR/AMR/functions.py b/PythonPackage/AMR/AMR/functions.py
index f16818491..020e71f82 100644
--- a/PythonPackage/AMR/AMR/functions.py
+++ b/PythonPackage/AMR/AMR/functions.py
@@ -42,9 +42,9 @@ def ab_class(*args, **kwargs):
def ab_selector(*args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.ab_selector(*args, **kwargs))
-def ab_from_text(*args, **kwargs):
+def ab_from_text(text, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.ab_from_text(*args, **kwargs))
+ return convert_to_python(amr_r.ab_from_text(text, *args, **kwargs))
def ab_name(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.ab_name(x, *args, **kwargs))
@@ -105,18 +105,21 @@ def age(x, *args, **kwargs):
def age_groups(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.age_groups(x, *args, **kwargs))
-def antibiogram(*args, **kwargs):
+def antibiogram(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.antibiogram(*args, **kwargs))
-def amr_class(*args, **kwargs):
+ return convert_to_python(amr_r.antibiogram(x, *args, **kwargs))
+def wisca(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.amr_class(*args, **kwargs))
-def amr_selector(*args, **kwargs):
+ return convert_to_python(amr_r.wisca(x, *args, **kwargs))
+def amr_class(amr_class, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.amr_selector(*args, **kwargs))
-def aminoglycosides(*args, **kwargs):
+ return convert_to_python(amr_r.amr_class(amr_class, *args, **kwargs))
+def amr_selector(filter, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.aminoglycosides(*args, **kwargs))
+ return convert_to_python(amr_r.amr_selector(filter, *args, **kwargs))
+def aminoglycosides(only_sir_columns = False, *args, **kwargs):
+ """See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
+ return convert_to_python(amr_r.aminoglycosides(only_sir_columns = False, *args, **kwargs))
def aminopenicillins(only_sir_columns = False, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.aminopenicillins(only_sir_columns = False, *args, **kwargs))
@@ -126,15 +129,15 @@ def antifungals(only_sir_columns = False, *args, **kwargs):
def antimycobacterials(only_sir_columns = False, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.antimycobacterials(only_sir_columns = False, *args, **kwargs))
-def betalactams(*args, **kwargs):
+def betalactams(only_sir_columns = False, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.betalactams(*args, **kwargs))
+ return convert_to_python(amr_r.betalactams(only_sir_columns = False, *args, **kwargs))
def betalactams_with_inhibitor(only_sir_columns = False, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.betalactams_with_inhibitor(only_sir_columns = False, *args, **kwargs))
-def carbapenems(*args, **kwargs):
+def carbapenems(only_sir_columns = False, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.carbapenems(*args, **kwargs))
+ return convert_to_python(amr_r.carbapenems(only_sir_columns = False, *args, **kwargs))
def cephalosporins(only_sir_columns = False, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.cephalosporins(only_sir_columns = False, *args, **kwargs))
@@ -159,9 +162,9 @@ def fluoroquinolones(only_sir_columns = False, *args, **kwargs):
def glycopeptides(only_sir_columns = False, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.glycopeptides(only_sir_columns = False, *args, **kwargs))
-def lincosamides(*args, **kwargs):
+def lincosamides(only_sir_columns = False, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.lincosamides(*args, **kwargs))
+ return convert_to_python(amr_r.lincosamides(only_sir_columns = False, *args, **kwargs))
def lipoglycopeptides(only_sir_columns = False, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.lipoglycopeptides(only_sir_columns = False, *args, **kwargs))
@@ -180,9 +183,9 @@ def penicillins(only_sir_columns = False, *args, **kwargs):
def phenicols(only_sir_columns = False, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.phenicols(only_sir_columns = False, *args, **kwargs))
-def polymyxins(*args, **kwargs):
+def polymyxins(only_sir_columns = False, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.polymyxins(*args, **kwargs))
+ return convert_to_python(amr_r.polymyxins(only_sir_columns = False, *args, **kwargs))
def quinolones(only_sir_columns = False, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.quinolones(only_sir_columns = False, *args, **kwargs))
@@ -207,9 +210,9 @@ def administrable_per_os(only_sir_columns = False, *args, **kwargs):
def administrable_iv(only_sir_columns = False, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.administrable_iv(only_sir_columns = False, *args, **kwargs))
-def not_intrinsic_resistant(*args, **kwargs):
+def not_intrinsic_resistant(only_sir_columns = False, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.not_intrinsic_resistant(*args, **kwargs))
+ return convert_to_python(amr_r.not_intrinsic_resistant(only_sir_columns = False, *args, **kwargs))
def as_ab(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.as_ab(x, *args, **kwargs))
@@ -237,9 +240,9 @@ def is_mic(x):
def rescale_mic(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.rescale_mic(x, *args, **kwargs))
-def as_mo(*args, **kwargs):
+def as_mo(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.as_mo(*args, **kwargs))
+ return convert_to_python(amr_r.as_mo(x, *args, **kwargs))
def is_mo(x):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.is_mo(x))
@@ -270,9 +273,9 @@ def is_sir_eligible(x, *args, **kwargs):
def sir_interpretation_history(clean):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.sir_interpretation_history(clean))
-def atc_online_property(*args, **kwargs):
+def atc_online_property(atc_code, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.atc_online_property(*args, **kwargs))
+ return convert_to_python(amr_r.atc_online_property(atc_code, *args, **kwargs))
def atc_online_groups(atc_code, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.atc_online_groups(atc_code, *args, **kwargs))
@@ -282,9 +285,9 @@ def atc_online_ddd(atc_code, *args, **kwargs):
def atc_online_ddd_units(atc_code, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.atc_online_ddd_units(atc_code, *args, **kwargs))
-def av_from_text(*args, **kwargs):
+def av_from_text(text, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.av_from_text(*args, **kwargs))
+ return convert_to_python(amr_r.av_from_text(text, *args, **kwargs))
def av_name(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.av_name(x, *args, **kwargs))
@@ -354,45 +357,45 @@ def count_all(*args, **kwargs):
def n_sir(*args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.n_sir(*args, **kwargs))
-def count_df(*args, **kwargs):
+def count_df(data, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.count_df(*args, **kwargs))
+ return convert_to_python(amr_r.count_df(data, *args, **kwargs))
def custom_eucast_rules(*args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.custom_eucast_rules(*args, **kwargs))
-def eucast_rules(*args, **kwargs):
+def eucast_rules(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.eucast_rules(*args, **kwargs))
+ return convert_to_python(amr_r.eucast_rules(x, *args, **kwargs))
def eucast_dosage(ab, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.eucast_dosage(ab, *args, **kwargs))
-def export_ncbi_biosample(*args, **kwargs):
+def export_ncbi_biosample(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.export_ncbi_biosample(*args, **kwargs))
-def first_isolate(*args, **kwargs):
+ return convert_to_python(amr_r.export_ncbi_biosample(x, *args, **kwargs))
+def first_isolate(x = None, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.first_isolate(*args, **kwargs))
-def filter_first_isolate(*args, **kwargs):
+ return convert_to_python(amr_r.first_isolate(x = None, *args, **kwargs))
+def filter_first_isolate(x = None, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.filter_first_isolate(*args, **kwargs))
+ return convert_to_python(amr_r.filter_first_isolate(x = None, *args, **kwargs))
def g_test(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.g_test(x, *args, **kwargs))
def is_new_episode(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.is_new_episode(x, *args, **kwargs))
-def ggplot_pca(*args, **kwargs):
+def ggplot_pca(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.ggplot_pca(*args, **kwargs))
-def ggplot_sir(*args, **kwargs):
+ return convert_to_python(amr_r.ggplot_pca(x, *args, **kwargs))
+def ggplot_sir(data, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.ggplot_sir(*args, **kwargs))
-def geom_sir(*args, **kwargs):
+ return convert_to_python(amr_r.ggplot_sir(data, *args, **kwargs))
+def geom_sir(position = None, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.geom_sir(*args, **kwargs))
-def guess_ab_col(*args, **kwargs):
+ return convert_to_python(amr_r.geom_sir(position = None, *args, **kwargs))
+def guess_ab_col(x = None, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.guess_ab_col(*args, **kwargs))
+ return convert_to_python(amr_r.guess_ab_col(x = None, *args, **kwargs))
def italicise_taxonomy(string, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.italicise_taxonomy(string, *args, **kwargs))
@@ -417,24 +420,24 @@ def semi_join_microorganisms(x, *args, **kwargs):
def anti_join_microorganisms(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.anti_join_microorganisms(x, *args, **kwargs))
-def key_antimicrobials(*args, **kwargs):
+def key_antimicrobials(x = None, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.key_antimicrobials(*args, **kwargs))
+ return convert_to_python(amr_r.key_antimicrobials(x = None, *args, **kwargs))
def all_antimicrobials(x = None, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.all_antimicrobials(x = None, *args, **kwargs))
-def antimicrobials_equal(*args, **kwargs):
+def antimicrobials_equal(y, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.antimicrobials_equal(*args, **kwargs))
+ return convert_to_python(amr_r.antimicrobials_equal(y, *args, **kwargs))
def kurtosis(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.kurtosis(x, *args, **kwargs))
def like(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.like(x, *args, **kwargs))
-def mdro(*args, **kwargs):
+def mdro(x = None, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.mdro(*args, **kwargs))
+ return convert_to_python(amr_r.mdro(x = None, *args, **kwargs))
def custom_mdro_guideline(*args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.custom_mdro_guideline(*args, **kwargs))
@@ -450,9 +453,9 @@ def mdr_tb(x = None, *args, **kwargs):
def mdr_cmi2012(x = None, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.mdr_cmi2012(x = None, *args, **kwargs))
-def eucast_exceptional_phenotypes(*args, **kwargs):
+def eucast_exceptional_phenotypes(x = None, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.eucast_exceptional_phenotypes(*args, **kwargs))
+ return convert_to_python(amr_r.eucast_exceptional_phenotypes(x = None, *args, **kwargs))
def mean_amr_distance(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.mean_amr_distance(x, *args, **kwargs))
@@ -462,126 +465,126 @@ def amr_distance_from_row(amr_distance, *args, **kwargs):
def mo_matching_score(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.mo_matching_score(x, *args, **kwargs))
-def mo_name(*args, **kwargs):
+def mo_name(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.mo_name(*args, **kwargs))
-def mo_fullname(*args, **kwargs):
+ return convert_to_python(amr_r.mo_name(x, *args, **kwargs))
+def mo_fullname(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.mo_fullname(*args, **kwargs))
-def mo_shortname(*args, **kwargs):
+ return convert_to_python(amr_r.mo_fullname(x, *args, **kwargs))
+def mo_shortname(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.mo_shortname(*args, **kwargs))
-def mo_subspecies(*args, **kwargs):
+ return convert_to_python(amr_r.mo_shortname(x, *args, **kwargs))
+def mo_subspecies(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.mo_subspecies(*args, **kwargs))
-def mo_species(*args, **kwargs):
+ return convert_to_python(amr_r.mo_subspecies(x, *args, **kwargs))
+def mo_species(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.mo_species(*args, **kwargs))
-def mo_genus(*args, **kwargs):
+ return convert_to_python(amr_r.mo_species(x, *args, **kwargs))
+def mo_genus(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.mo_genus(*args, **kwargs))
-def mo_family(*args, **kwargs):
+ return convert_to_python(amr_r.mo_genus(x, *args, **kwargs))
+def mo_family(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.mo_family(*args, **kwargs))
-def mo_order(*args, **kwargs):
+ return convert_to_python(amr_r.mo_family(x, *args, **kwargs))
+def mo_order(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.mo_order(*args, **kwargs))
-def mo_class(*args, **kwargs):
+ return convert_to_python(amr_r.mo_order(x, *args, **kwargs))
+def mo_class(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.mo_class(*args, **kwargs))
-def mo_phylum(*args, **kwargs):
+ return convert_to_python(amr_r.mo_class(x, *args, **kwargs))
+def mo_phylum(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.mo_phylum(*args, **kwargs))
-def mo_kingdom(*args, **kwargs):
+ return convert_to_python(amr_r.mo_phylum(x, *args, **kwargs))
+def mo_kingdom(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.mo_kingdom(*args, **kwargs))
-def mo_domain(*args, **kwargs):
+ return convert_to_python(amr_r.mo_kingdom(x, *args, **kwargs))
+def mo_domain(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.mo_domain(*args, **kwargs))
-def mo_type(*args, **kwargs):
+ return convert_to_python(amr_r.mo_domain(x, *args, **kwargs))
+def mo_type(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.mo_type(*args, **kwargs))
-def mo_status(*args, **kwargs):
+ return convert_to_python(amr_r.mo_type(x, *args, **kwargs))
+def mo_status(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.mo_status(*args, **kwargs))
-def mo_pathogenicity(*args, **kwargs):
+ return convert_to_python(amr_r.mo_status(x, *args, **kwargs))
+def mo_pathogenicity(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.mo_pathogenicity(*args, **kwargs))
-def mo_gramstain(*args, **kwargs):
+ return convert_to_python(amr_r.mo_pathogenicity(x, *args, **kwargs))
+def mo_gramstain(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.mo_gramstain(*args, **kwargs))
-def mo_is_gram_negative(*args, **kwargs):
+ return convert_to_python(amr_r.mo_gramstain(x, *args, **kwargs))
+def mo_is_gram_negative(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.mo_is_gram_negative(*args, **kwargs))
-def mo_is_gram_positive(*args, **kwargs):
+ return convert_to_python(amr_r.mo_is_gram_negative(x, *args, **kwargs))
+def mo_is_gram_positive(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.mo_is_gram_positive(*args, **kwargs))
-def mo_is_yeast(*args, **kwargs):
+ return convert_to_python(amr_r.mo_is_gram_positive(x, *args, **kwargs))
+def mo_is_yeast(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.mo_is_yeast(*args, **kwargs))
-def mo_is_intrinsic_resistant(*args, **kwargs):
+ return convert_to_python(amr_r.mo_is_yeast(x, *args, **kwargs))
+def mo_is_intrinsic_resistant(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.mo_is_intrinsic_resistant(*args, **kwargs))
-def mo_oxygen_tolerance(*args, **kwargs):
+ return convert_to_python(amr_r.mo_is_intrinsic_resistant(x, *args, **kwargs))
+def mo_oxygen_tolerance(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.mo_oxygen_tolerance(*args, **kwargs))
-def mo_is_anaerobic(*args, **kwargs):
+ return convert_to_python(amr_r.mo_oxygen_tolerance(x, *args, **kwargs))
+def mo_is_anaerobic(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.mo_is_anaerobic(*args, **kwargs))
-def mo_snomed(*args, **kwargs):
+ return convert_to_python(amr_r.mo_is_anaerobic(x, *args, **kwargs))
+def mo_snomed(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.mo_snomed(*args, **kwargs))
-def mo_ref(*args, **kwargs):
+ return convert_to_python(amr_r.mo_snomed(x, *args, **kwargs))
+def mo_ref(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.mo_ref(*args, **kwargs))
-def mo_authors(*args, **kwargs):
+ return convert_to_python(amr_r.mo_ref(x, *args, **kwargs))
+def mo_authors(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.mo_authors(*args, **kwargs))
-def mo_year(*args, **kwargs):
+ return convert_to_python(amr_r.mo_authors(x, *args, **kwargs))
+def mo_year(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.mo_year(*args, **kwargs))
-def mo_lpsn(*args, **kwargs):
+ return convert_to_python(amr_r.mo_year(x, *args, **kwargs))
+def mo_lpsn(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.mo_lpsn(*args, **kwargs))
-def mo_mycobank(*args, **kwargs):
+ return convert_to_python(amr_r.mo_lpsn(x, *args, **kwargs))
+def mo_mycobank(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.mo_mycobank(*args, **kwargs))
-def mo_gbif(*args, **kwargs):
+ return convert_to_python(amr_r.mo_mycobank(x, *args, **kwargs))
+def mo_gbif(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.mo_gbif(*args, **kwargs))
-def mo_rank(*args, **kwargs):
+ return convert_to_python(amr_r.mo_gbif(x, *args, **kwargs))
+def mo_rank(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.mo_rank(*args, **kwargs))
-def mo_taxonomy(*args, **kwargs):
+ return convert_to_python(amr_r.mo_rank(x, *args, **kwargs))
+def mo_taxonomy(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.mo_taxonomy(*args, **kwargs))
-def mo_synonyms(*args, **kwargs):
+ return convert_to_python(amr_r.mo_taxonomy(x, *args, **kwargs))
+def mo_synonyms(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.mo_synonyms(*args, **kwargs))
+ return convert_to_python(amr_r.mo_synonyms(x, *args, **kwargs))
def mo_current(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.mo_current(x, *args, **kwargs))
-def mo_group_members(*args, **kwargs):
+def mo_group_members(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.mo_group_members(*args, **kwargs))
-def mo_info(*args, **kwargs):
+ return convert_to_python(amr_r.mo_group_members(x, *args, **kwargs))
+def mo_info(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.mo_info(*args, **kwargs))
-def mo_url(*args, **kwargs):
+ return convert_to_python(amr_r.mo_info(x, *args, **kwargs))
+def mo_url(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.mo_url(*args, **kwargs))
-def mo_property(*args, **kwargs):
+ return convert_to_python(amr_r.mo_url(x, *args, **kwargs))
+def mo_property(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.mo_property(*args, **kwargs))
-def pca(*args, **kwargs):
+ return convert_to_python(amr_r.mo_property(x, *args, **kwargs))
+def pca(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.pca(*args, **kwargs))
+ return convert_to_python(amr_r.pca(x, *args, **kwargs))
def theme_sir(*args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.theme_sir(*args, **kwargs))
-def labels_sir_count(*args, **kwargs):
+def labels_sir_count(position = None, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.labels_sir_count(*args, **kwargs))
+ return convert_to_python(amr_r.labels_sir_count(position = None, *args, **kwargs))
def resistance(*args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.resistance(*args, **kwargs))
@@ -606,12 +609,12 @@ def proportion_SI(*args, **kwargs):
def proportion_S(*args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.proportion_S(*args, **kwargs))
-def proportion_df(*args, **kwargs):
+def proportion_df(data, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.proportion_df(*args, **kwargs))
-def sir_df(*args, **kwargs):
+ return convert_to_python(amr_r.proportion_df(data, *args, **kwargs))
+def sir_df(data, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.sir_df(*args, **kwargs))
+ return convert_to_python(amr_r.sir_df(data, *args, **kwargs))
def random_mic(size = None, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.random_mic(size = None, *args, **kwargs))
@@ -621,18 +624,21 @@ def random_disk(size = None, *args, **kwargs):
def random_sir(size = None, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.random_sir(size = None, *args, **kwargs))
-def resistance_predict(*args, **kwargs):
+def resistance_predict(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.resistance_predict(*args, **kwargs))
-def sir_predict(*args, **kwargs):
+ return convert_to_python(amr_r.resistance_predict(x, *args, **kwargs))
+def sir_predict(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.sir_predict(*args, **kwargs))
-def ggplot_sir_predict(*args, **kwargs):
+ return convert_to_python(amr_r.sir_predict(x, *args, **kwargs))
+def ggplot_sir_predict(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
- return convert_to_python(amr_r.ggplot_sir_predict(*args, **kwargs))
+ return convert_to_python(amr_r.ggplot_sir_predict(x, *args, **kwargs))
def skewness(x, *args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.skewness(x, *args, **kwargs))
+def top_n_microorganisms(x, *args, **kwargs):
+ """See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
+ return convert_to_python(amr_r.top_n_microorganisms(x, *args, **kwargs))
def reset_AMR_locale(*args, **kwargs):
"""See our website of the R package for the manual: https://msberends.github.io/AMR/index.html"""
return convert_to_python(amr_r.reset_AMR_locale(*args, **kwargs))
diff --git a/PythonPackage/AMR/dist/AMR-2.1.1.9125-py3-none-any.whl b/PythonPackage/AMR/dist/AMR-2.1.1.9125-py3-none-any.whl
deleted file mode 100644
index d2fe81313..000000000
Binary files a/PythonPackage/AMR/dist/AMR-2.1.1.9125-py3-none-any.whl and /dev/null differ
diff --git a/PythonPackage/AMR/dist/AMR-2.1.1.9126-py3-none-any.whl b/PythonPackage/AMR/dist/AMR-2.1.1.9126-py3-none-any.whl
new file mode 100644
index 000000000..90ab360cc
Binary files /dev/null and b/PythonPackage/AMR/dist/AMR-2.1.1.9126-py3-none-any.whl differ
diff --git a/PythonPackage/AMR/dist/amr-2.1.1.9125.tar.gz b/PythonPackage/AMR/dist/amr-2.1.1.9125.tar.gz
deleted file mode 100644
index b8bbf0218..000000000
Binary files a/PythonPackage/AMR/dist/amr-2.1.1.9125.tar.gz and /dev/null differ
diff --git a/PythonPackage/AMR/dist/amr-2.1.1.9126.tar.gz b/PythonPackage/AMR/dist/amr-2.1.1.9126.tar.gz
new file mode 100644
index 000000000..9a3ee31d6
Binary files /dev/null and b/PythonPackage/AMR/dist/amr-2.1.1.9126.tar.gz differ
diff --git a/PythonPackage/AMR/setup.py b/PythonPackage/AMR/setup.py
index cdea4ad54..e1ceb8d41 100644
--- a/PythonPackage/AMR/setup.py
+++ b/PythonPackage/AMR/setup.py
@@ -2,7 +2,7 @@
setup(
name='AMR',
- version='2.1.1.9125',
+ version='2.1.1.9126',
packages=find_packages(),
install_requires=[
'rpy2',
diff --git a/R/antibiogram.R b/R/antibiogram.R
index 817dda70a..6115a5db4 100755
--- a/R/antibiogram.R
+++ b/R/antibiogram.R
@@ -29,21 +29,28 @@
#' Generate Traditional, Combination, Syndromic, or WISCA Antibiograms
#'
-#' Create detailed antibiograms with options for traditional, combination, syndromic, and Bayesian WISCA methods. Based on the approaches of Klinker *et al.*, Barbieri *et al.*, and the Bayesian WISCA model (Weighted-Incidence Syndromic Combination Antibiogram) by Bielicki *et al.*, this function provides flexible output formats including plots and tables, ideal for integration with R Markdown and Quarto reports.
-#' @param x a [data.frame] containing at least a column with microorganisms and columns with antibiotic results (class 'sir', see [as.sir()])
-#' @param antibiotics vector of any antibiotic name or code (will be evaluated with [as.ab()], column name of `x`, or (any combinations of) [antimicrobial selectors][antimicrobial_class_selectors] such as [aminoglycosides()] or [carbapenems()]. For combination antibiograms, this can also be set to values separated with `"+"`, such as "TZP+TOB" or "cipro + genta", given that columns resembling such antibiotics exist in `x`. See *Examples*.
+#' @description
+#' Create detailed antibiograms with options for traditional, combination, syndromic, and Bayesian WISCA methods.
+#'
+#' Adhering to previously described approaches (see *Source*) and especially the Bayesian WISCA model (Weighted-Incidence Syndromic Combination Antibiogram) by Bielicki *et al.*, these functions provides flexible output formats including plots and tables, ideal for integration with R Markdown and Quarto reports.
+#' @param x a [data.frame] containing at least a column with microorganisms and columns with antimicrobial results (class 'sir', see [as.sir()])
+#' @param antibiotics vector of any antimicrobial name or code (will be evaluated with [as.ab()], column name of `x`, or (any combinations of) [antimicrobial selectors][antimicrobial_class_selectors] such as [aminoglycosides()] or [carbapenems()]. For combination antibiograms, this can also be set to values separated with `"+"`, such as "TZP+TOB" or "cipro + genta", given that columns resembling such antimicrobials exist in `x`. See *Examples*.
#' @param mo_transform a character to transform microorganism input - must be `"name"`, `"shortname"` (default), `"gramstain"`, or one of the column names of the [microorganisms] data set: `r vector_or(colnames(microorganisms), sort = FALSE, quotes = TRUE)`. Can also be `NULL` to not transform the input.
-#' @param ab_transform a character to transform antibiotic input - must be one of the column names of the [antibiotics] data set (defaults to `"name"`): `r vector_or(colnames(antibiotics), sort = FALSE, quotes = TRUE)`. Can also be `NULL` to not transform the input.
+#' @param ab_transform a character to transform antimicrobial input - must be one of the column names of the [antibiotics] data set (defaults to `"name"`): `r vector_or(colnames(antibiotics), sort = FALSE, quotes = TRUE)`. Can also be `NULL` to not transform the input.
#' @param syndromic_group a column name of `x`, or values calculated to split rows of `x`, e.g. by using [ifelse()] or [`case_when()`][dplyr::case_when()]. See *Examples*.
-#' @param add_total_n a [logical] to indicate whether total available numbers per pathogen should be added to the table (default is `TRUE`). This will add the lowest and highest number of available isolate per antibiotic (e.g, if for *E. coli* 200 isolates are available for ciprofloxacin and 150 for amoxicillin, the returned number will be "150-200").
-#' @param only_all_tested (for combination antibiograms): a [logical] to indicate that isolates must be tested for all antibiotics, see *Details*
+#' @param add_total_n a [logical] to indicate whether total available numbers per pathogen should be added to the table (default is `TRUE`). This will add the lowest and highest number of available isolates per antimicrobial (e.g, if for *E. coli* 200 isolates are available for ciprofloxacin and 150 for amoxicillin, the returned number will be "150-200").
+#' @param only_all_tested (for combination antibiograms): a [logical] to indicate that isolates must be tested for all antimicrobials, see *Details*
#' @param digits number of digits to use for rounding the susceptibility percentage
-#' @param formatting_type numeric value (1–12) indicating how the 'cells' of the antibiogram table should be formatted. See *Details* > *Formatting Type* for a list of options.
+#' @param 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 *Details* > *Formatting Type* for a list of options.
#' @param col_mo column name of the names or codes of the microorganisms (see [as.mo()]) - the default is the first column of class [`mo`]. Values will be coerced using [as.mo()].
#' @param language language to translate text, which defaults to the system language (see [get_AMR_locale()])
#' @param minimum the minimum allowed number of available (tested) isolates. Any isolate count lower than `minimum` will return `NA` with a warning. The default number of `30` isolates is advised by the Clinical and Laboratory Standards Institute (CLSI) as best practice, see *Source*.
#' @param combine_SI a [logical] to indicate whether all susceptibility should be determined by results of either S, SDD, or I, instead of only S (default is `TRUE`)
-#' @param sep a separating character for antibiotic columns in combination antibiograms
+#' @param sep a separating character for antimicrobial columns in combination antibiograms
+#' @param wisca a [logical] to indicate whether a Weighted-Incidence Syndromic Combination Antibiogram (WISCA) must be generated (default is `FALSE`). This will use a Bayesian hierarchical model to estimate regimen coverage probabilities using Montecarlo simulations. Set `simulations` to adjust.
+#' @param simulations (for WISCA) a numerical value to set the number of Montecarlo simulations
+#' @param conf_interval (for WISCA) a numerical value to set confidence interval (default is `0.95`)
+#' @param interval_side (for WISCA) the side of the confidence interval, either `"two-tailed"` (default), `"left"` or `"right"`
#' @param info a [logical] to indicate info should be printed - the default is `TRUE` only in interactive mode
#' @param object an [antibiogram()] object
#' @param ... when used in [R Markdown or Quarto][knitr::kable()]: arguments passed on to [knitr::kable()] (otherwise, has no use)
@@ -51,9 +58,13 @@
#'
#' **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 [first_isolate()] to determine them in your data set with one of the four available algorithms.
#'
+#' For estimating antimicrobial coverage, especially when creating a WISCA, the outcome might become more reliable by only including the top *n* species encountered in the data. You can filter on this top *n* using [top_n_microorganisms()]. For example, use `top_n_microorganisms(your_data, n = 10)` as a pre-processing step to only include the top 10 species in the data.
+#'
+#' Using [get_long_numeric_format()], the antibiogram is converted to a long format containing numeric values. This is ideal for e.g. advanced plotting.
+#'
#' ### Formatting Type
#'
-#' The formatting of the 'cells' of the table can be set with the argument `formatting_type`. In these examples, `5` is the susceptibility percentage, `15` the numerator, and `300` the denominator:
+#' The formatting of the 'cells' of the table can be set with the argument `formatting_type`. In these examples, `5` is the susceptibility percentage (for WISCA: `4-6` indicates the confidence level), `15` the numerator, and `300` the denominator:
#'
#' 1. 5
#' 2. 15
@@ -64,19 +75,31 @@
#' 7. 5 (N=300)
#' 8. 5% (N=300)
#' 9. 5 (15/300)
-#' 10. 5% (15/300)
+#' 10. 5% (15/300) - **default for non-WISCA**
#' 11. 5 (N=15/300)
#' 12. 5% (N=15/300)
+#'
+#' Additional options for WISCA (using `antibiogram(..., wisca = TRUE)` or `wisca()`):
+#' 13. 5 (4-6)
+#' 14. 5% (4-6%)
+#' 15. 5 (4-6,300)
+#' 16. 5% (4-6%,300)
+#' 17. 5 (4-6,N=300)
+#' 18. 5% (4-6%,N=300) - **default for WISCA**
+#' 19. 5 (4-6,15/300)
+#' 20. 5% (4-6%,15/300)
+#' 21. 5 (4-6,N=15/300)
+#' 22. 5% (4-6%,N=15/300)
#'
-#' The default is `10`, which can be set globally with the package option [`AMR_antibiogram_formatting_type`][AMR-options], e.g. `options(AMR_antibiogram_formatting_type = 5)`.
+#' The default is `18` for WISCA and `10` for non-WISCA, which can be set globally with the package option [`AMR_antibiogram_formatting_type`][AMR-options], e.g. `options(AMR_antibiogram_formatting_type = 5)`.
#'
-#' Set `digits` (defaults to `0`) to alter the rounding of the susceptibility percentage.
+#' Set `digits` (defaults to `0`) to alter the rounding of the susceptibility percentages.
#'
#' ### Antibiogram Types
#'
-#' There are four antibiogram types, as summarised by Klinker *et al.* (2021, \doi{10.1177/20499361211011373}), and they are all supported by [antibiogram()]. Use WISCA whenever possible, since it provides precise coverage estimates by accounting for pathogen incidence and antimicrobial susceptibility. See the section *Why Use WISCA?* on this page.
+#' There are various antibiogram types, as summarised by Klinker *et al.* (2021, \doi{10.1177/20499361211011373}), and they are all supported by [antibiogram()].
#'
-#' The four antibiogram types:
+#' **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 *et al.* (2020, \doi{10.1001.jamanetworkopen.2019.21124}). See the section *Why Use WISCA?* on this page.
#'
#' 1. **Traditional Antibiogram**
#'
@@ -114,28 +137,35 @@
#'
#' 4. **Weighted-Incidence Syndromic Combination Antibiogram (WISCA)**
#'
-#' WISCA enhances empirical antibiotic selection by weighting the incidence of pathogens in specific clinical syndromes and combining them with their susceptibility data. It provides an estimation of regimen coverage by aggregating pathogen incidences and susceptibilities across potential causative organisms. See also the section *Why Use WISCA?* on this page.
-#'
-#' Case example: Susceptibility of *Pseudomonas aeruginosa* to TZP among respiratory specimens (obtained among ICU patients only) for male patients age >=65 years with heart failure
+#' WISCA can be applied to any antibiogram, see the section *Why Use WISCA?* on this page for more information.
#'
#' Code example:
#'
#' ```r
-#' library(dplyr)
-#' your_data %>%
-#' filter(ward == "ICU" & specimen_type == "Respiratory") %>%
-#' antibiogram(antibiotics = c("TZP", "TZP+TOB", "TZP+GEN"),
-#' syndromic_group = ifelse(.$age >= 65 &
-#' .$gender == "Male" &
-#' .$condition == "Heart Disease",
-#' "Study Group", "Control Group"))
+#' antibiogram(your_data,
+#' antibiotics = c("TZP", "TZP+TOB", "TZP+GEN"),
+#' wisca = TRUE)
+#'
+#' # this is equal to:
+#' wisca(your_data,
+#' antibiotics = c("TZP", "TZP+TOB", "TZP+GEN"))
#' ```
#'
#' WISCA uses a sophisticated Bayesian decision model to combine both local and pooled antimicrobial resistance data. This approach not only evaluates local patterns but can also draw on multi-centre datasets to improve regimen accuracy, even in low-incidence infections like paediatric bloodstream infections (BSIs).
+#'
+#' Grouped [tibbles][tibble::tibble] can also be used to calculate susceptibilities over various groups.
+#'
+#' Code example:
+#'
+#' ```r
+#' your_data %>%
+#' group_by(has_sepsis, is_neonate, sex) %>%
+#' wisca(antibiotics = c("TZP", "TZP+TOB", "TZP+GEN"))
+#' ```
#'
#' ### Inclusion in Combination Antibiogram and Syndromic Antibiogram
#'
-#' Note that for types 2 and 3 (Combination Antibiogram and Syndromic Antibiogram), it is important to realise that susceptibility can be calculated in two ways, which can be set with the `only_all_tested` argument (default is `FALSE`). See this example for two antibiotics, Drug A and Drug B, about how [antibiogram()] works to calculate the %SI:
+#' Note that for types 2 and 3 (Combination Antibiogram and Syndromic Antibiogram), it is important to realise that susceptibility can be calculated in two ways, which can be set with the `only_all_tested` argument (default is `FALSE`). See this example for two antimicrobials, Drug A and Drug B, about how [antibiogram()] works to calculate the %SI:
#'
#' ```
#' --------------------------------------------------------------------
@@ -165,18 +195,57 @@
#' You can also use functions from specific 'table reporting' packages to transform the output of [antibiogram()] to your needs, e.g. with `flextable::as_flextable()` or `gt::gt()`.
#'
#' @section Why Use WISCA?:
-#' WISCA is a powerful tool for guiding empirical antibiotic therapy because it provides precise coverage estimates by accounting for pathogen incidence and antimicrobial susceptibility. This is particularly important in empirical treatment, where the causative pathogen is often unknown at the outset. Traditional antibiograms do not reflect the weighted likelihood of specific pathogens based on clinical syndromes, which can lead to suboptimal treatment choices.
-#'
-#' The Bayesian WISCA, as described by Bielicki *et al.* (2016), improves on earlier methods by handling uncertainties common in smaller datasets, such as low-incidence infections. This method offers a significant advantage by:
+#' WISCA, as outlined by Barbieri *et al.* (\doi{10.1186/s13756-021-00939-2}), stands for
+#' Weighted-Incidence Syndromic Combination Antibiogram, which estimates the probability
+#' of adequate empirical antimicrobial regimen coverage for specific infection syndromes.
+#' This method leverages a Bayesian hierarchical logistic regression framework with random
+#' effects for pathogens and regimens, enabling robust estimates in the presence of sparse
+#' data.
+#'
+#' The Bayesian model assumes conjugate priors for parameter estimation. For example, the
+#' coverage probability \ifelse{latex}{\deqn{$theta$}}{$theta$} for a given antimicrobial regimen
+#' is modeled using a Beta distribution as a prior:
+#'
+#' \ifelse{latex}{\deqn{$theta$ \sim \text{Beta}($alpha$_0, $beta$_0)}}{
+#' \ifelse{html}{\figure{beta_prior.png}{options: width="300" alt="Beta prior"}}{$theta$ ~ Beta($alpha$_0, $beta$_0)}}
+#'
+#' where \eqn{$alpha$_0} and \eqn{$beta$_0} represent prior successes and failures, respectively,
+#' informed by expert knowledge or weakly informative priors (e.g., \eqn{$alpha$_0 = 1, $beta$_0 = 1}).
#'
-#' 1. Pooling Data from Multiple Sources:\cr WISCA uses pooled data from multiple hospitals or surveillance sources to overcome limitations of small sample sizes at individual institutions, allowing for more confident selection of narrow-spectrum antibiotics or combinations.
-#' 2. Bayesian Framework:\cr The Bayesian decision tree model accounts for both local data and prior knowledge (such as inherent resistance patterns) to estimate regimen coverage. It allows for a more precise estimation of coverage, even in cases where susceptibility data is missing or incomplete.
-#' 3. Incorporating Pathogen and Regimen Uncertainty:\cr WISCA allows clinicians to see the likelihood that an empirical regimen will be effective against all relevant pathogens, taking into account uncertainties related to both pathogen prevalence and antimicrobial resistance. This leads to better-informed, data-driven clinical decisions.
-#' 4. Scenarios for Optimising Treatment:\cr For hospitals or settings with low-incidence infections, WISCA helps determine whether local data is sufficient or if pooling with external data is necessary. It also identifies statistically significant differences or similarities between antibiotic regimens, enabling clinicians to choose optimal therapies with greater confidence.
+#' The likelihood function is constructed based on observed data, where the number of covered
+#' cases for a regimen follows a binomial distribution:
+#'
+#' \ifelse{latex}{\deqn{y \sim \text{Binomial}(n, $theta$)}}{
+#' \ifelse{html}{\figure{binomial_likelihood.png}{options: width="300" alt="Binomial likelihood"}}{y ~ Binomial(n, $theta$)}}
+#'
+#' Posterior parameter estimates are obtained by combining the prior and likelihood using
+#' Bayes' theorem. The posterior distribution of \eqn{$theta$} is also a Beta distribution:
+#'
+#' \ifelse{latex}{\deqn{$theta$ | y \sim \text{Beta}($alpha$_0 + y, $beta$_0 + n - y)}}{
+#' \ifelse{html}{\figure{posterior_beta.png}{options: width="300" alt="Beta posterior"}}{$theta$ | y ~ Beta($alpha$_0 + y, $beta$_0 + n - y)}}
+#'
+#' For hierarchical modeling, pathogen-level effects (e.g., differences in resistance
+#' patterns) and regimen-level effects are modelled using Gaussian priors on log-odds.
+#' This hierarchical structure ensures partial pooling of estimates across groups,
+#' improving stability in strata with small sample sizes. The model is implemented using
+#' Hamiltonian Monte Carlo (HMC) sampling.
+#'
+#' Stratified results are provided based on covariates such as age, sex, and clinical
+#' complexity (e.g., prior antimicrobial treatments or renal/urological comorbidities).
+#' For example, posterior odds ratios (ORs) are derived to quantify the effect of these
+#' covariates on coverage probabilities:
+#'
+#' \ifelse{latex}{\deqn{\text{OR}_{\text{covariate}} = \frac{\exp($beta$_{\text{covariate}})}{\exp($beta$_0)}}}{
+#' \ifelse{html}{\figure{odds_ratio.png}{options: width="300" alt="Odds ratio formula"}}{OR_covariate = exp(beta_covariate) / exp(beta_0)}}
+#'
+#' By combining empirical data with prior knowledge, WISCA overcomes the limitations
+#' of traditional combination antibiograms, offering disease-specific, patient-stratified
+#' estimates with robust uncertainty quantification. This tool is invaluable for antimicrobial
+#' stewardship programs and empirical treatment guideline refinement.
#'
-#' WISCA is essential in optimising empirical treatment by shifting away from broad-spectrum antibiotics, which are often overused in empirical settings. By offering precise estimates based on syndromic patterns and pooled data, WISCA supports antimicrobial stewardship by guiding more targeted therapy, reducing unnecessary broad-spectrum use, and combating the rise of antimicrobial resistance.
#' @source
#' * 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** *Journal of Antimicrobial Chemotherapy* 71(3); \doi{10.1093/jac/dkv397}
+#' * Bielicki JA *et al.* (2020). **Evaluation of the coverage of 3 antibiotic regimens for neonatal sepsis in the hospital setting across Asian countries** *JAMA Netw Open.* 3(2):e1921124; \doi{10.1001.jamanetworkopen.2019.21124}
#' * Klinker KP *et al.* (2021). **Antimicrobial stewardship and antibiograms: importance of moving beyond traditional antibiograms**. *Therapeutic Advances in Infectious Disease*, May 5;8:20499361211011373; \doi{10.1177/20499361211011373}
#' * Barbieri E *et al.* (2021). **Development of a Weighted-Incidence Syndromic Combination Antibiogram (WISCA) to guide the choice of the empiric antibiotic treatment for urinary tract infection in paediatric patients: a Bayesian approach** *Antimicrobial Resistance & Infection Control* May 1;10(1):74; \doi{10.1186/s13756-021-00939-2}
#' * **M39 Analysis and Presentation of Cumulative Antimicrobial Susceptibility Test Data, 5th Edition**, 2022, *Clinical and Laboratory Standards Institute (CLSI)*. .
@@ -246,19 +315,15 @@
#' ),
#' language = "es"
#' )
+#'
+#'
+#' # WISCA antibiogram ----------------------------------------------------
#'
-#'
-#' # Weighted-incidence syndromic combination antibiogram (WISCA) ---------
-#'
-#' # the data set could contain a filter for e.g. respiratory specimens/ICU
+#' # can be used for any of the above types - just add `wisca = TRUE`
#' antibiogram(example_isolates,
-#' antibiotics = c("AMC", "AMC+CIP", "TZP", "TZP+TOB"),
+#' antibiotics = c("TZP", "TZP+TOB", "TZP+GEN"),
#' mo_transform = "gramstain",
-#' minimum = 10, # this should be >=30, but now just as example
-#' syndromic_group = ifelse(example_isolates$age >= 65 &
-#' example_isolates$gender == "M",
-#' "WISCA Group 1", "WISCA Group 2"
-#' )
+#' wisca = TRUE
#' )
#'
#'
@@ -306,29 +371,65 @@ antibiogram <- function(x,
add_total_n = FALSE,
only_all_tested = FALSE,
digits = 0,
- formatting_type = getOption("AMR_antibiogram_formatting_type", 10),
+ formatting_type = getOption("AMR_antibiogram_formatting_type", ifelse(wisca, 18, 10)),
col_mo = NULL,
language = get_AMR_locale(),
minimum = 30,
combine_SI = TRUE,
sep = " + ",
+ wisca = FALSE,
+ simulations = 1000,
+ conf_interval = 0.95,
+ interval_side = "two-tailed",
info = interactive()) {
+ UseMethod("antibiogram")
+}
+
+#' @method antibiogram default
+#' @export
+antibiogram.default <- function(x,
+ antibiotics = where(is.sir),
+ mo_transform = "shortname",
+ ab_transform = "name",
+ syndromic_group = NULL,
+ add_total_n = FALSE,
+ only_all_tested = FALSE,
+ digits = 0,
+ formatting_type = getOption("AMR_antibiogram_formatting_type", ifelse(wisca, 18, 10)),
+ col_mo = NULL,
+ language = get_AMR_locale(),
+ minimum = 30,
+ combine_SI = TRUE,
+ sep = " + ",
+ wisca = FALSE,
+ simulations = 1000,
+ conf_interval = 0.95,
+ interval_side = "two-tailed",
+ info = interactive()) {
meet_criteria(x, allow_class = "data.frame")
x <- ascertain_sir_classes(x, "x")
- meet_criteria(mo_transform, allow_class = "character", has_length = 1, is_in = c("name", "shortname", "gramstain", colnames(AMR::microorganisms)), allow_NULL = TRUE)
- meet_criteria(ab_transform, allow_class = "character", has_length = 1, is_in = colnames(AMR::antibiotics), allow_NULL = TRUE)
+ if (!is.function(mo_transform)) {
+ meet_criteria(mo_transform, allow_class = "character", has_length = 1, is_in = c("name", "shortname", "gramstain", colnames(AMR::microorganisms)), allow_NULL = TRUE)
+ }
+ if (!is.function(ab_transform)) {
+ meet_criteria(ab_transform, allow_class = "character", has_length = 1, is_in = colnames(AMR::antibiotics), allow_NULL = TRUE)
+ }
meet_criteria(syndromic_group, allow_class = "character", allow_NULL = TRUE, allow_NA = TRUE)
meet_criteria(add_total_n, allow_class = "logical", has_length = 1)
meet_criteria(only_all_tested, allow_class = "logical", has_length = 1)
meet_criteria(digits, allow_class = c("numeric", "integer"), has_length = 1, is_finite = TRUE)
- meet_criteria(formatting_type, allow_class = c("numeric", "integer"), has_length = 1, is_in = c(1:12))
+ meet_criteria(wisca, allow_class = "logical", has_length = 1)
+ meet_criteria(formatting_type, allow_class = c("numeric", "integer"), has_length = 1, is_in = if (wisca == TRUE) c(1:22) else c(1:12))
meet_criteria(col_mo, allow_class = "character", has_length = 1, allow_NULL = TRUE, is_in = colnames(x))
language <- validate_language(language)
meet_criteria(minimum, allow_class = c("numeric", "integer"), has_length = 1, is_positive_or_zero = TRUE, is_finite = TRUE)
meet_criteria(combine_SI, allow_class = "logical", has_length = 1)
meet_criteria(sep, allow_class = "character", has_length = 1)
+ meet_criteria(simulations, allow_class = c("numeric", "integer"), has_length = 1, is_finite = TRUE, is_positive = TRUE)
+ meet_criteria(conf_interval, allow_class = c("numeric", "integer"), has_length = 1, is_finite = TRUE, is_positive = TRUE)
+ meet_criteria(interval_side, allow_class = "character", has_length = 1, is_in = c("two-tailed", "left", "right"))
meet_criteria(info, allow_class = "logical", has_length = 1)
-
+
# try to find columns based on type
if (is.null(col_mo)) {
col_mo <- search_type_in_df(x = x, type = "mo", info = interactive())
@@ -338,6 +439,8 @@ antibiogram <- function(x,
x$`.mo` <- x[, col_mo, drop = TRUE]
if (is.null(mo_transform)) {
# leave as is
+ } else if (is.function(mo_transform)) {
+ x$`.mo` <- mo_transform(x$`.mo`)
} else if (mo_transform == "gramstain") {
x$`.mo` <- mo_gramstain(x$`.mo`, language = language)
} else if (mo_transform == "shortname") {
@@ -348,7 +451,7 @@ antibiogram <- function(x,
x$`.mo` <- mo_property(x$`.mo`, property = mo_transform, language = language)
}
x$`.mo`[is.na(x$`.mo`)] <- "(??)"
-
+
# get syndromic groups
if (!is.null(syndromic_group)) {
if (length(syndromic_group) == 1 && syndromic_group %in% colnames(x)) {
@@ -361,9 +464,11 @@ antibiogram <- function(x,
} else {
has_syndromic_group <- FALSE
}
-
+
# get antibiotics
- if (tryCatch(is.character(antibiotics), error = function(e) FALSE)) {
+ ab_trycatch <- tryCatch(colnames(suppressWarnings(x[, antibiotics, drop = FALSE])), error = function(e) NULL)
+ if (is.null(ab_trycatch)) {
+ stop_ifnot(is.character(suppressMessages(antibiotics)), "`antibiotics` must be an antimicrobial selector, or a character vector.")
antibiotics.bak <- antibiotics
# split antibiotics on separator and make it a list
antibiotics <- strsplit(gsub(" ", "", antibiotics), "+", fixed = TRUE)
@@ -379,11 +484,11 @@ antibiogram <- function(x,
out[!is.na(out)]
})
user_ab <- user_ab[unlist(lapply(user_ab, length)) > 0]
-
+
if (length(non_existing) > 0) {
warning_("The following antibiotics were not available and ignored: ", vector_and(ab_name(non_existing, language = NULL, tolower = TRUE), quotes = FALSE))
}
-
+
# make list unique
antibiotics <- unique(user_ab)
# go through list to set AMR in combinations
@@ -418,9 +523,9 @@ antibiogram <- function(x,
}
antibiotics <- unlist(antibiotics)
} else {
- antibiotics <- colnames(suppressWarnings(x[, antibiotics, drop = FALSE]))
+ antibiotics <- ab_trycatch
}
-
+
if (isTRUE(has_syndromic_group)) {
out <- x %pm>%
pm_select(.syndromic_group, .mo, antibiotics) %pm>%
@@ -429,29 +534,107 @@ antibiogram <- function(x,
out <- x %pm>%
pm_select(.mo, antibiotics)
}
-
+
+
# get numbers of S, I, R (per group)
out <- out %pm>%
bug_drug_combinations(
col_mo = ".mo",
- FUN = function(x) x
+ FUN = function(x) x,
+ include_n_rows = TRUE
)
counts <- out
-
+
+
+ if (wisca == TRUE) {
+ # WISCA ----
+
+ # set up progress bar
+ progress <- progress_ticker(n = NROW(out[which(out$total > 0), , drop = FALSE]),
+ n_min = 10,
+ print = info,
+ title = "Calculating beta/gamma parameters for WISCA")
+ on.exit(close(progress))
+
+ out$percentage = NA_real_
+ out$lower = NA_real_
+ out$upper = NA_real_
+
+ for (i in seq_len(NROW(out))) {
+ if (out$total[i] == 0) {
+ next
+ }
+ progress$tick()
+ out_current <- out[i, , drop = FALSE]
+ priors <- calculate_priors(out_current, combine_SI = combine_SI)
+
+ # Monte Carlo simulation
+ coverage_simulations <- replicate(simulations, {
+ # simulate pathogen incidence
+ # = Dirichlet (Gamma) parameters
+ simulated_incidence <- stats::rgamma(
+ n = length(priors$gamma_posterior),
+ shape = priors$gamma_posterior,
+ rate = 1 # Scale = 1 for gamma
+ )
+ # normalise
+ simulated_incidence <- simulated_incidence / sum(simulated_incidence)
+
+ # simulate susceptibility
+ # = Beta parameters
+ simulated_susceptibility <- stats::rbeta(
+ n = length(priors$beta_posterior_1),
+ shape1 = priors$beta_posterior_1,
+ shape2 = priors$beta_posterior_2
+ )
+ sum(simulated_incidence * simulated_susceptibility)
+ })
+
+ # calculate coverage statistics
+ coverage_mean <- mean(coverage_simulations)
+ if (interval_side == "two-tailed") {
+ probs <- c((1 - conf_interval) / 2, 1 - (1 - conf_interval) / 2)
+ } else if (interval_side == "left") {
+ probs <- c(0, conf_interval)
+ } else if (interval_side == "right") {
+ probs <- c(1 - conf_interval, 1)
+ }
+ coverage_ci <- unname(stats::quantile(coverage_simulations, probs = probs))
+
+ out$percentage[i] <- coverage_mean
+ out$lower[i] <- coverage_ci[1]
+ out$upper[i] <- coverage_ci[2]
+ }
+ # remove progress bar from console
+ close(progress)
+ }
+
if (isTRUE(combine_SI)) {
out$numerator <- out$S + out$I + out$SDD
} else {
out$numerator <- out$S
}
- if (all(out$total < minimum, na.rm = TRUE)) {
+ if (all(out$total < minimum, na.rm = TRUE) && wisca == FALSE) {
warning_("All combinations had less than `minimum = ", minimum, "` results, returning an empty antibiogram")
return(as_original_data_class(data.frame(), class(out), extra_class = "antibiogram"))
} else if (any(out$total < minimum, na.rm = TRUE)) {
- if (isTRUE(info)) {
- message_("NOTE: ", sum(out$total < minimum, na.rm = TRUE), " combinations had less than `minimum = ", minimum, "` results and were ignored", add_fn = font_red)
- }
out <- out %pm>%
- subset(total >= minimum)
+ # also for WISCA, refrain from anything below 15 isolates:
+ subset(total > 15)
+ mins <- sum(out$total < minimum, na.rm = TRUE)
+ if (wisca == FALSE) {
+ out <- out %pm>%
+ subset(total >= minimum)
+ if (isTRUE(info) && mins > 0) {
+ message_("NOTE: ", mins, " combinations had less than `minimum = ", minimum, "` results and were ignored", add_fn = font_red)
+ }
+ } else if (isTRUE(info)) {
+ warning_("Number of tested isolates per regimen should exceed ", minimum, ". Coverage estimates will be inaccurate for ", mins, " regimen", ifelse(mins == 1, "", "s"), ".", call = FALSE)
+ }
+ }
+
+ if (NROW(out) == 0) {
+ return(as_original_data_class(data.frame(), class(out), extra_class = "antibiogram"))
}
# regroup for summarising
@@ -464,6 +647,21 @@ antibiogram <- function(x,
pm_group_by(mo, ab)
}
+ if (wisca == TRUE) {
+ out_numeric <- out %pm>%
+ pm_summarise(percentage = percentage,
+ lower = lower,
+ upper = upper,
+ numerator = numerator,
+ total = total)
+ } else {
+ out_numeric <- out %pm>%
+ pm_summarise(percentage = numerator / total,
+ numerator = numerator,
+ total = total)
+ }
+
+ out$digits <- digits # since pm_sumarise() cannot work with an object outside the current frame
# formatting type:
# 1. 5
# 2. 15
@@ -477,11 +675,16 @@ antibiogram <- function(x,
# 10. 5% (15/300)
# 11. 5 (N=15/300)
# 12. 5% (N=15/300)
- out_numeric <- out %pm>%
- pm_summarise(percentage = numerator / total,
- numerator = numerator,
- total = total)
- out$digits <- digits # since pm_sumarise() cannot work with an object outside the current frame
+ # 13. 5 (4-6)
+ # 14. 5% (4-6%)
+ # 15. 5 (4-6,300)
+ # 16. 5% (4-6%,300)
+ # 17. 5 (4-6,N=300)
+ # 18. 5% (4-6%,N=300)
+ # 19. 5 (4-6,15/300)
+ # 20. 5% (4-6%,15/300)
+ # 21. 5 (4-6,N=15/300)
+ # 22. 5% (4-6%,N=15/300)
if (formatting_type == 1) out <- out %pm>% pm_summarise(out_value = round((numerator / total) * 100, digits = digits))
if (formatting_type == 2) out <- out %pm>% pm_summarise(out_value = numerator)
if (formatting_type == 3) out <- out %pm>% pm_summarise(out_value = total)
@@ -494,6 +697,12 @@ antibiogram <- function(x,
if (formatting_type == 10) out <- out %pm>% pm_summarise(out_value = paste0(round((numerator / total) * 100, digits = digits), "% (", numerator, "/", total, ")"))
if (formatting_type == 11) out <- out %pm>% pm_summarise(out_value = paste0(round((numerator / total) * 100, digits = digits), " (N=", numerator, "/", total, ")"))
if (formatting_type == 12) out <- out %pm>% pm_summarise(out_value = paste0(round((numerator / total) * 100, digits = digits), "% (N=", numerator, "/", total, ")"))
+ if (formatting_type == 13) out <- out %pm>% pm_summarise(out_value = paste0(round(percentage * 100, digits = digits), " (", round(lower * 100, digits = digits), "-", round(upper * 100, digits = digits), ")"))
+ if (formatting_type == 14) out <- out %pm>% pm_summarise(out_value = paste0(round(percentage * 100, digits = digits), "% (", round(lower * 100, digits = digits), "-", round(upper * 100, digits = digits), "%)"))
+ if (formatting_type == 15) out <- out %pm>% pm_summarise(out_value = paste0(round(percentage * 100, digits = digits), " (", round(lower * 100, digits = digits), "-", round(upper * 100, digits = digits), ",", total, ")"))
+ if (formatting_type == 16) out <- out %pm>% pm_summarise(out_value = paste0(round(percentage * 100, digits = digits), "% (", round(lower * 100, digits = digits), "-", round(upper * 100, digits = digits), "%,", total, ")"))
+ if (formatting_type == 17) out <- out %pm>% pm_summarise(out_value = paste0(round(percentage * 100, digits = digits), " (", round(lower * 100, digits = digits), "-", round(upper * 100, digits = digits), ",N=", total, ")"))
+ if (formatting_type == 18) out <- out %pm>% pm_summarise(out_value = paste0(round(percentage * 100, digits = digits), "% (", round(lower * 100, digits = digits), "-", round(upper * 100, digits = digits), "%,N=", total, ")"))
# transform names of antibiotics
ab_naming_function <- function(x, t, l, s) {
@@ -503,6 +712,8 @@ antibiogram <- function(x,
a <- x[[i]]
if (is.null(t)) {
# leave as is
+ } else if (is.function(t)) {
+ a <- t(a)
} else if (t == "atc") {
a <- ab_atc(a, only_first = TRUE, language = l)
} else {
@@ -527,12 +738,12 @@ antibiogram <- function(x,
colnames(object) <- gsub("^out_value?[.]", "", colnames(object))
return(object)
}
-
+
# ungroup for long -> wide transformation
attr(out, "pm_groups") <- NULL
attr(out, "groups") <- NULL
class(out) <- class(out)[!class(out) %in% c("grouped_df", "grouped_data")]
-
+
if (isTRUE(has_syndromic_group)) {
grps <- unique(out$syndromic_group)
for (i in seq_len(length(grps))) {
@@ -559,7 +770,7 @@ antibiogram <- function(x,
new_df <- new_df[, c("mo", sort(colnames(new_df)[colnames(new_df) != "mo"])), drop = FALSE]
colnames(new_df)[1] <- translate_AMR("Pathogen", language = language)
}
-
+
# add total N if indicated
if (isTRUE(add_total_n)) {
if (isTRUE(has_syndromic_group)) {
@@ -587,20 +798,200 @@ antibiogram <- function(x,
colnames(new_df)[edit_col] <- paste(colnames(new_df)[edit_col], "(N min-max)")
}
}
-
+
out <- as_original_data_class(new_df, class(x), extra_class = "antibiogram")
rownames(out) <- NULL
+ rownames(out_numeric) <- NULL
+
structure(out,
- has_syndromic_group = has_syndromic_group,
- out_numeric = out_numeric,
- combine_SI = combine_SI
+ has_syndromic_group = has_syndromic_group,
+ combine_SI = combine_SI,
+ wisca = wisca,
+ conf_interval = conf_interval,
+ out_numeric = as_original_data_class(out_numeric, class(out))
+ )
+}
+
+#' @method antibiogram grouped_df
+#' @export
+antibiogram.grouped_df <- function(x,
+ antibiotics = where(is.sir),
+ mo_transform = function (...) "no_mo",
+ ab_transform = "name",
+ syndromic_group = NULL,
+ add_total_n = FALSE,
+ only_all_tested = FALSE,
+ digits = 0,
+ formatting_type = getOption("AMR_antibiogram_formatting_type", ifelse(wisca, 18, 10)),
+ col_mo = NULL,
+ language = get_AMR_locale(),
+ minimum = 30,
+ combine_SI = TRUE,
+ sep = " + ",
+ wisca = FALSE,
+ simulations = 1000,
+ conf_interval = 0.95,
+ interval_side = "two-tailed",
+ info = interactive()) {
+ stop_ifnot(is.null(syndromic_group), "`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 `syndromic_groups` redundant.", call = FALSE)
+ groups <- attributes(x)$groups
+ n_groups <- NROW(groups)
+ progress <- progress_ticker(n = n_groups,
+ n_min = 5,
+ print = info,
+ title = paste("Calculating AMR for", n_groups, "groups"))
+ on.exit(close(progress))
+
+ for (i in seq_len(n_groups)) {
+ if (i > 1) progress$tick()
+ rows <- unlist(groups[i, ]$.rows)
+ if (length(rows) == 0) {
+ next
+ }
+
+ new_out <- antibiogram(as.data.frame(x)[rows, , drop = FALSE],
+ antibiotics = antibiotics,
+ mo_transform = function(x) "no_mo",
+ 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,
+ wisca = wisca,
+ simulations = simulations,
+ conf_interval = conf_interval,
+ interval_side = interval_side,
+ info = i == 1 && info == TRUE)
+ new_out_numeric <- attributes(new_out)$out_numeric
+
+ if (i == 1) progress$tick()
+
+ if (NROW(new_out) == 0) {
+ next
+ }
+
+ # remove first column 'Pathogen' (in whatever language)
+ new_out <- new_out[, -1, drop = FALSE]
+ new_out_numeric <- new_out_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
+ new_out_numeric[, col_name] <- col_value
+ new_out_numeric <- new_out_numeric[, c(col_name, setdiff(names(new_out_numeric), col_name))] # set place to 1st col
+ }
+
+ if (i == 1) {
+ # the first go
+ out <- new_out
+ out_numeric <- new_out_numeric
+ } else {
+ out <- rbind_AMR(out, new_out)
+ out_numeric <- rbind_AMR(out_numeric, new_out_numeric)
+ }
+ }
+
+ close(progress)
+
+ out <- structure(as_original_data_class(out, class(x), extra_class = "antibiogram"),
+ has_syndromic_group = FALSE,
+ combine_SI = isTRUE(combine_SI),
+ wisca = isTRUE(wisca),
+ conf_interval = conf_interval,
+ out_numeric = as_original_data_class(out_numeric, class(x)))
+}
+
+#' @export
+#' @rdname antibiogram
+wisca <- function(x,
+ antibiotics = where(is.sir),
+ mo_transform = "shortname",
+ ab_transform = "name",
+ syndromic_group = NULL,
+ add_total_n = FALSE,
+ only_all_tested = FALSE,
+ digits = 0,
+ formatting_type = getOption("AMR_antibiogram_formatting_type", 18),
+ col_mo = NULL,
+ language = get_AMR_locale(),
+ minimum = 30,
+ combine_SI = TRUE,
+ sep = " + ",
+ simulations = 1000,
+ info = interactive()) {
+ antibiogram(x = x,
+ antibiotics = antibiotics,
+ mo_transform = mo_transform,
+ ab_transform = ab_transform,
+ syndromic_group = syndromic_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,
+ wisca = TRUE,
+ simulations = simulations,
+ info = info)
+}
+
+#' @export
+#' @param antibiogram the outcome of [antibiogram()] or [wisca()]
+#' @rdname antibiogram
+get_long_numeric_format <- function(antibiogram) {
+ stop_ifnot(inherits(antibiogram, "antibiogram"), "This function only works for the output of `antibiogram()` and `wisca()`.", call = FALSE)
+ attributes(antibiogram)$out_numeric
+}
+
+calculate_priors <- function(data, combine_SI = TRUE) {
+ # Ensure data has required columns
+ stopifnot(all(c("mo", "total_rows", "total", "S") %in% colnames(data)))
+ if (combine_SI == TRUE && "I" %in% colnames(data)) {
+ data$S <- data$S + data$I
+ }
+ if (combine_SI == TRUE && "SDD" %in% colnames(data)) {
+ data$S <- data$S + data$SDD
+ }
+
+ # Pathogen incidence (Dirichlet distribution)
+ gamma_prior <- rep(1, length(unique(data$mo))) # Dirichlet prior
+ gamma_posterior <- gamma_prior + data$total_rows # Posterior parameters
+
+ # Regimen susceptibility (Beta distribution)
+ beta_prior <- rep(1, length(unique(data$mo))) # Beta prior
+ r <- data$S # Number of pathogens tested susceptible
+ n <- data$total # Total tested
+ beta_posterior_1 <- beta_prior + r # Posterior alpha
+ beta_posterior_2 <- beta_prior + (n - r) # Posterior beta
+
+ # Return parameters as a list
+ list(
+ gamma_posterior = gamma_posterior,
+ beta_posterior_1 = beta_posterior_1,
+ beta_posterior_2 = beta_posterior_2
)
}
# will be exported in R/zzz.R
tbl_sum.antibiogram <- function(x, ...) {
dims <- paste(format(NROW(x), big.mark = ","), AMR_env$cross_icon, format(NCOL(x), big.mark = ","))
- names(dims) <- "An Antibiogram"
+ if (isTRUE(attributes(x)$wisca)) {
+ names(dims) <- paste0("An Antibiogram (WISCA / ", attributes(x)$conf_interval * 100, "% CI)")
+ } else {
+ names(dims) <- "An Antibiogram (non-WISCA)"
+ }
dims
}
@@ -619,6 +1010,9 @@ tbl_format_footer.antibiogram <- function(x, ...) {
#' @rdname antibiogram
plot.antibiogram <- function(x, ...) {
df <- attributes(x)$out_numeric
+ if (!"mo" %in% colnames(df)) {
+ stop_("Plotting antibiograms using plot() is only possible if they were not created using dplyr groups. Consider using `get_long_numeric_format()` to retrieve raw antibiogram values.")
+ }
if ("syndromic_group" %in% colnames(df)) {
# barplot in base R does not support facets - paste columns together
df$mo <- paste(df$mo, "-", df$syndromic_group)
@@ -629,11 +1023,12 @@ plot.antibiogram <- function(x, ...) {
mfrow_old <- graphics::par()$mfrow
sqrt_levels <- sqrt(length(mo_levels))
graphics::par(mfrow = c(ceiling(sqrt_levels), floor(sqrt_levels)))
+
for (i in seq_along(mo_levels)) {
mo <- mo_levels[i]
df_sub <- df[df$mo == mo, , drop = FALSE]
-
- barplot(
+
+ bp <- barplot(
height = df_sub$percentage * 100,
xlab = NULL,
ylab = ifelse(isTRUE(attributes(x)$combine_SI), "%SI", "%S"),
@@ -643,7 +1038,18 @@ plot.antibiogram <- function(x, ...) {
main = mo,
legend = NULL
)
+
+ if (isTRUE(attributes(x)$wisca)) {
+ lower <- df_sub$lower * 100
+ upper <- df_sub$upper * 100
+ arrows(
+ x0 = bp, y0 = lower, # Start of error bar (lower bound)
+ x1 = bp, y1 = upper, # End of error bar (upper bound)
+ angle = 90, code = 3, length = 0.05, col = "black"
+ )
+ }
}
+
graphics::par(mfrow = mfrow_old)
}
@@ -658,19 +1064,20 @@ barplot.antibiogram <- function(height, ...) {
# will be exported using s3_register() in R/zzz.R
autoplot.antibiogram <- function(object, ...) {
df <- attributes(object)$out_numeric
- ggplot2::ggplot(df) +
- ggplot2::geom_col(
- ggplot2::aes(
- x = ab,
- y = percentage * 100,
- fill = if ("syndromic_group" %in% colnames(df)) {
- syndromic_group
- } else {
- NULL
- }
- ),
- position = ggplot2::position_dodge2(preserve = "single")
- ) +
+ if (!"mo" %in% colnames(df)) {
+ stop_("Plotting antibiograms using plot() is only possible if they were not created using dplyr groups. Consider using `get_long_numeric_format()` to retrieve raw antibiogram values.")
+ }
+ out <- ggplot2::ggplot(df,
+ mapping = ggplot2::aes(
+ x = ab,
+ y = percentage * 100,
+ fill = if ("syndromic_group" %in% colnames(df)) {
+ syndromic_group
+ } else {
+ NULL
+ }
+ )) +
+ ggplot2::geom_col(position = ggplot2::position_dodge2(preserve = "single")) +
ggplot2::facet_wrap("mo") +
ggplot2::labs(
y = ifelse(isTRUE(attributes(object)$combine_SI), "%SI", "%S"),
@@ -681,6 +1088,13 @@ autoplot.antibiogram <- function(object, ...) {
NULL
}
)
+ if (isTRUE(attributes(object)$wisca)) {
+ out <- out +
+ ggplot2::geom_errorbar(mapping = ggplot2::aes(ymin = lower * 100, ymax = upper * 100),
+ position = ggplot2::position_dodge2(preserve = "single"),
+ width = 0.5)
+ }
+ out
}
# will be exported in zzz.R
@@ -692,17 +1106,17 @@ knit_print.antibiogram <- function(x, italicise = TRUE, na = getOption("knitr.ka
stop_ifnot_installed("knitr")
meet_criteria(italicise, allow_class = "logical", has_length = 1)
meet_criteria(na, allow_class = "character", has_length = 1, allow_NA = TRUE)
-
- if (isTRUE(italicise)) {
+
+ if (isTRUE(italicise) && "mo" %in% colnames(attributes(x)$out_numeric)) {
# make all microorganism names italic, according to nomenclature
names_col <- ifelse(isTRUE(attributes(x)$has_syndromic_group), 2, 1)
x[[names_col]] <- italicise_taxonomy(x[[names_col]], type = "markdown")
}
-
+
old_option <- getOption("knitr.kable.NA")
options(knitr.kable.NA = na)
on.exit(options(knitr.kable.NA = old_option))
-
+
out <- paste(c("", "", knitr::kable(x, ..., output = FALSE)), collapse = "\n")
knitr::asis_output(out)
}
diff --git a/R/bug_drug_combinations.R b/R/bug_drug_combinations.R
index abb4a4c01..17e933d7e 100755
--- a/R/bug_drug_combinations.R
+++ b/R/bug_drug_combinations.R
@@ -70,6 +70,7 @@
bug_drug_combinations <- function(x,
col_mo = NULL,
FUN = mo_shortname,
+ include_n_rows = FALSE,
...) {
meet_criteria(x, allow_class = "data.frame")
x <- ascertain_sir_classes(x, "x")
@@ -110,6 +111,7 @@ bug_drug_combinations <- function(x,
I = integer(0),
R = integer(0),
total = integer(0),
+ total_rows = integer(0),
stringsAsFactors = FALSE
)
if (data_has_groups) {
@@ -123,8 +125,14 @@ bug_drug_combinations <- function(x,
x_mo_filter <- x[which(x[, col_mo, drop = TRUE] == unique_mo[i]), names(which(vapply(FUN.VALUE = logical(1), x, is.sir))), drop = FALSE]
# turn and merge everything
pivot <- lapply(x_mo_filter, function(x) {
- m <- as.matrix(table(as.sir(x)))
- data.frame(S = m["S", ], SDD = m["SDD", ], I = m["I", ], R = m["R", ], NI = m["NI", ], stringsAsFactors = FALSE)
+ m <- as.matrix(table(as.sir(x), useNA = "always"))
+ data.frame(S = m["S", ],
+ SDD = m["SDD", ],
+ I = m["I", ],
+ R = m["R", ],
+ NI = m["NI", ],
+ na = m[which(is.na(rownames(m))), ],
+ stringsAsFactors = FALSE)
})
merged <- do.call(rbind_AMR, pivot)
out_group <- data.frame(
@@ -136,6 +144,7 @@ bug_drug_combinations <- function(x,
R = merged$R,
NI = merged$NI,
total = merged$S + merged$SDD + merged$I + merged$R + merged$NI,
+ total_rows = merged$S + merged$SDD + merged$I + merged$R + merged$NI + merged$na,
stringsAsFactors = FALSE
)
if (data_has_groups) {
@@ -162,16 +171,21 @@ bug_drug_combinations <- function(x,
}
res
}
-
+
+ if (include_n_rows == FALSE) {
+ out <- out[, colnames(out)[colnames(out) != "total_rows"], drop = FALSE]
+ }
+
if (data_has_groups) {
out <- apply_group(x, "run_it", groups)
} else {
out <- run_it(x)
}
+
out <- out %pm>% pm_arrange(mo, ab)
out <- as_original_data_class(out, class(x.bak)) # will remove tibble groups
rownames(out) <- NULL
- structure(out, class = c("bug_drug_combinations", ifelse(data_has_groups, "grouped", character(0)), class(out)))
+ structure(out, class = c("bug_drug_combinations", if(data_has_groups) "grouped" else NULL, class(out)))
}
#' @method format bug_drug_combinations
diff --git a/R/first_isolate.R b/R/first_isolate.R
index 41df81d50..e5a52ff2e 100644
--- a/R/first_isolate.R
+++ b/R/first_isolate.R
@@ -51,6 +51,8 @@
#' @param include_untested_sir a [logical] to indicate whether also rows without antibiotic results are still eligible for becoming a first isolate. Use `include_untested_sir = FALSE` to always return `FALSE` for such rows. This checks the data set for columns of class `sir` and consequently requires transforming columns with antibiotic results using [as.sir()] first.
#' @param ... arguments passed on to [first_isolate()] when using [filter_first_isolate()], otherwise arguments passed on to [key_antimicrobials()] (such as `universal`, `gram_negative`, `gram_positive`)
#' @details
+#' The methodology implemented in these functions is based on the research overview by Hindler *et al.* (2007, \doi{10.1086/511864}) and the recommendations outlined in the [CLSI Guideline M39](https://clsi.org/standards/products/microbiology/documents/m39).
+
#' To conduct epidemiological analyses on antimicrobial resistance data, only so-called first isolates should be included to prevent overestimation and underestimation of antimicrobial resistance. Different methods can be used to do so, see below.
#'
#' These functions are context-aware. This means that the `x` argument can be left blank if used inside a [data.frame] call, see *Examples*.
@@ -61,7 +63,7 @@
#'
#' ### Different methods
#'
-#' According to Hindler *et al.* (2007, \doi{10.1086/511864}), there are different methods (algorithms) to select first isolates with increasing reliability: isolate-based, patient-based, episode-based and phenotype-based. All methods select on a combination of the taxonomic genus and species (not subspecies).
+#' According to previously-mentioned sources, there are different methods (algorithms) to select first isolates with increasing reliability: isolate-based, patient-based, episode-based and phenotype-based. All methods select on a combination of the taxonomic genus and species (not subspecies).
#'
#' All mentioned methods are covered in the [first_isolate()] function:
#'
@@ -93,11 +95,11 @@
#'
#' ### Patient-based
#'
-#' To include every genus-species combination per patient once, set the `episode_days` to `Inf`. Although often inappropriate, this method makes sure that no duplicate isolates are selected from the same patient. In a large longitudinal data set, this could mean that isolates are *excluded* that were found years after the initial isolate.
+#' To include every genus-species combination per patient once, set the `episode_days` to `Inf`. This method makes sure that no duplicate isolates are selected from the same patient. This method is preferred to e.g. identify the first MRSA finding of each patient to determine the incidence. Conversely, in a large longitudinal data set, this could mean that isolates are *excluded* that were found years after the initial isolate.
#'
#' ### Episode-based
#'
-#' To include every genus-species combination per patient episode once, set the `episode_days` to a sensible number of days. Depending on the type of analysis, this could be 14, 30, 60 or 365. Short episodes are common for analysing specific hospital or ward data, long episodes are common for analysing regional and national data.
+#' To include every genus-species combination per patient episode once, set the `episode_days` to a sensible number of days. Depending on the type of analysis, this could be 14, 30, 60 or 365. Short episodes are common for analysing specific hospital or ward data or ICU cases, long episodes are common for analysing regional and national data.
#'
#' This is the most common method to correct for duplicate isolates. Patients are categorised into episodes based on their ID and dates (e.g., the date of specimen receipt or laboratory result). While this is a common method, it does not take into account antimicrobial test results. This means that e.g. a methicillin-resistant *Staphylococcus aureus* (MRSA) isolate cannot be differentiated from a wildtype *Staphylococcus aureus* isolate.
#'
diff --git a/R/top_n_microorganisms.R b/R/top_n_microorganisms.R
new file mode 100755
index 000000000..5c4193cca
--- /dev/null
+++ b/R/top_n_microorganisms.R
@@ -0,0 +1,97 @@
+# ==================================================================== #
+# TITLE: #
+# AMR: An R Package for Working with Antimicrobial Resistance Data #
+# #
+# SOURCE CODE: #
+# https://github.com/msberends/AMR #
+# #
+# PLEASE CITE THIS SOFTWARE AS: #
+# Berends MS, Luz CF, Friedrich AW, et al. (2022). #
+# AMR: An R Package for Working with Antimicrobial Resistance Data. #
+# Journal of Statistical Software, 104(3), 1-31. #
+# https://doi.org/10.18637/jss.v104.i03 #
+# #
+# Developed at the University of Groningen and the University Medical #
+# Center Groningen in The Netherlands, in collaboration with many #
+# colleagues from around the world, see our website. #
+# #
+# This R package is free software; you can freely use and distribute #
+# it for both personal and commercial purposes under the terms of the #
+# GNU General Public License version 2.0 (GNU GPL-2), as published by #
+# the Free Software Foundation. #
+# We created this package for both routine data analysis and academic #
+# research and it was publicly released in the hope that it will be #
+# useful, but it comes WITHOUT ANY WARRANTY OR LIABILITY. #
+# #
+# Visit our website for the full manual and a complete tutorial about #
+# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
+# ==================================================================== #
+
+#' Filter Top *n* Microorganisms
+#'
+#' This function filters a data set to include only the top *n* microorganisms based on a specified property, such as taxonomic family or genus. For example, it can filter a data set to the top 3 species, or to any species in the top 5 genera, or to the top 3 species in each of the top 5 genera.
+#' @param x a data frame containing microbial data
+#' @param n an integer specifying the maximum number of unique values of the `property` to include in the output
+#' @param property a character string indicating the microorganism property to use for filtering. Must be one of the column names of the [microorganisms] data set: `r vector_or(colnames(microorganisms), sort = FALSE, quotes = TRUE)`. If `NULL`, the raw values from `col_mo` will be used without transformation.
+#' @param n_for_each an optional integer specifying the maximum number of rows to retain for each value of the selected property. If `NULL`, all rows within the top *n* groups will be included.
+#' @param col_mo A character string indicating the column in `x` that contains microorganism names or codes. Defaults to the first column of class [`mo`]. Values will be coerced using [as.mo()].
+#' @param ... Additional arguments passed on to [mo_property()] when `property` is not `NULL`.
+#' @details This function is useful for preprocessing data before creating [antibiograms][antibiograms()] or other analyses that require focused subsets of microbial data. For example, it can filter a data set to only include isolates from the top 10 species.
+#' @export
+#' @seealso [mo_property()], [as.mo()], [antibiogram()]
+#' @examples
+#' # filter to the top 3 species:
+#' top_n_microorganisms(example_isolates,
+#' n = 3)
+#'
+#' # filter to any species in the top 5 genera:
+#' top_n_microorganisms(example_isolates,
+#' n = 5, property = "genus")
+#'
+#' # filter to the top 3 species in each of the top 5 genera:
+#' top_n_microorganisms(example_isolates,
+#' n = 5, property = "genus", n_for_each = 3)
+top_n_microorganisms <- function(x, n, property = "fullname", n_for_each = NULL, col_mo = NULL, ...) {
+ meet_criteria(x, allow_class = "data.frame") # also checks dimensions to be >0
+ meet_criteria(n, allow_class = c("numeric", "integer"), has_length = 1, is_finite = TRUE, is_positive = TRUE)
+ meet_criteria(property, allow_class = "character", has_length = 1, is_in = colnames(AMR::microorganisms))
+ meet_criteria(n_for_each, allow_class = c("numeric", "integer"), has_length = 1, is_finite = TRUE, is_positive = TRUE, allow_NULL = TRUE)
+ meet_criteria(col_mo, allow_class = "character", has_length = 1, allow_NULL = TRUE, is_in = colnames(x))
+ if (is.null(col_mo)) {
+ col_mo <- search_type_in_df(x = x, type = "mo", info = TRUE)
+ stop_if(is.null(col_mo), "`col_mo` must be set")
+ }
+
+ x.bak <- x
+
+ x[, col_mo] <- as.mo(x[, col_mo, drop = TRUE], keep_synonyms = TRUE)
+
+ if (is.null(property)) {
+ x$prop_val <- x[[col_mo]]
+ } else {
+ x$prop_val <- mo_property(x[[col_mo]], property = property, ...)
+ }
+ counts <- sort(table(x$prop_val), decreasing = TRUE)
+
+ n <- as.integer(n)
+ if (length(counts) < n) {
+ n <- length(counts)
+ }
+ count_values <- names(counts)[seq_len(n)]
+ filtered_rows <- which(x$prop_val %in% count_values)
+
+ if (!is.null(n_for_each)) {
+ n_for_each <- as.integer(n_for_each)
+ filtered_x <- x[filtered_rows, , drop = FALSE]
+ filtered_rows <- do.call(
+ c,
+ lapply(split(filtered_x, filtered_x$prop_val), function(group) {
+ top_values <- names(sort(table(group[[col_mo]]), decreasing = TRUE)[seq_len(n_for_each)])
+ top_values <- top_values[!is.na(top_values)]
+ which(x[[col_mo]] %in% top_values)
+ })
+ )
+ }
+
+ x.bak[filtered_rows, , drop = FALSE]
+}
diff --git a/_pkgdown.yml b/_pkgdown.yml
index f8343ef2b..64a267a82 100644
--- a/_pkgdown.yml
+++ b/_pkgdown.yml
@@ -267,10 +267,10 @@ reference:
- "`kurtosis`"
- "`skewness`"
- # - title: "Other: deprecated functions"
- # desc: >
- # These functions are deprecated, meaning that they will still
- # work but show a warning with every use and will be removed
- # in a future version.
- # contents:
- # - "`AMR-deprecated`"
+ - title: "Other: deprecated functions"
+ desc: >
+ These functions are deprecated, meaning that they will still
+ work but show a warning that they will be removed
+ in a future version.
+ contents:
+ - "`AMR-deprecated`"
diff --git a/data-raw/_generate_python_wrapper.sh b/data-raw/_generate_python_wrapper.sh
index 609547c7e..841d57b6e 100644
--- a/data-raw/_generate_python_wrapper.sh
+++ b/data-raw/_generate_python_wrapper.sh
@@ -47,6 +47,7 @@ GREEN = '\033[32m'
RESET = '\033[0m'
import os
+import sys
from rpy2 import robjects
from rpy2.robjects import pandas2ri
from rpy2.robjects.packages import importr, isinstalled
@@ -54,7 +55,7 @@ import pandas as pd
import importlib.metadata as metadata
# Get the path to the virtual environment
-venv_path = os.getenv('VIRTUAL_ENV') # Path to the active virtual environment
+venv_path = sys.prefix
# Define R library path within the venv
r_lib_path = os.path.join(venv_path, "R_libs")
@@ -63,10 +64,12 @@ os.makedirs(r_lib_path, exist_ok=True)
# Set the R library path in .libPaths
base = importr('base')
base._libPaths(r_lib_path)
+r_amr_lib_path = base._libPaths()[0]
# Check if the AMR package is installed in R
-if not isinstalled('AMR'):
+if not isinstalled('AMR', lib_loc = r_amr_lib_path):
utils = importr('utils')
+ print(f"{BLUE}AMR:{RESET} Installing AMR package to {BLUE}{r_amr_lib_path}/{RESET}...", flush=True)
utils.install_packages('AMR', repos='https://msberends.r-universe.dev', quiet=True)
# Python package version of AMR
@@ -81,7 +84,7 @@ r_amr_version = robjects.r(f'as.character(packageVersion("AMR", lib.loc = "{r_li
# Compare R and Python package versions
if r_amr_version != python_amr_version:
try:
- print(f"{BLUE}AMR:{RESET} Updating package version{RESET}", flush=True)
+ print(f"{BLUE}AMR:{RESET} Updating AMR package in {BLUE}{r_amr_lib_path}/{RESET}...", flush=True)
utils = importr('utils')
utils.install_packages('AMR', repos='https://msberends.r-universe.dev', quiet=True)
except Exception as e:
diff --git a/data-raw/gpt_training_text_v2.1.1.9125.txt b/data-raw/gpt_training_text_v2.1.1.9126.txt
similarity index 95%
rename from data-raw/gpt_training_text_v2.1.1.9125.txt
rename to data-raw/gpt_training_text_v2.1.1.9126.txt
index b42f62da2..f16964c22 100644
--- a/data-raw/gpt_training_text_v2.1.1.9125.txt
+++ b/data-raw/gpt_training_text_v2.1.1.9126.txt
@@ -1,5 +1,5 @@
This files contains all context you must know about the AMR package for R.
-First and foremost, you are trained on version 2.1.1.9125. Remember this whenever someone asks which AMR package version you’re at.
+First and foremost, you are trained on version 2.1.1.9126. Remember this whenever someone asks which AMR package version you’re at.
--------------------------------
THE PART HEREAFTER CONTAINS CONTENTS FROM FILE 'NAMESPACE':
@@ -39,6 +39,8 @@ S3method(Ops,mic)
S3method(Summary,mic)
S3method(all,amr_selector)
S3method(all,amr_selector_any_all)
+S3method(antibiogram,default)
+S3method(antibiogram,grouped_df)
S3method(any,amr_selector)
S3method(any,amr_selector_any_all)
S3method(as.data.frame,ab)
@@ -226,6 +228,7 @@ export(g.test)
export(geom_sir)
export(get_AMR_locale)
export(get_episode)
+export(get_long_numeric_format)
export(get_mo_source)
export(ggplot_pca)
export(ggplot_sir)
@@ -342,9 +345,11 @@ export(streptogramins)
export(susceptibility)
export(tetracyclines)
export(theme_sir)
+export(top_n_microorganisms)
export(translate_AMR)
export(trimethoprims)
export(ureidopenicillins)
+export(wisca)
importFrom(graphics,arrows)
importFrom(graphics,axis)
importFrom(graphics,barplot)
@@ -962,15 +967,9 @@ THE PART HEREAFTER CONTAINS CONTENTS FROM FILE 'man/ab_from_text.Rd':
\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}
@@ -1111,13 +1110,8 @@ 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()}}}
@@ -1614,6 +1608,8 @@ THE PART HEREAFTER CONTAINS CONTENTS FROM FILE 'man/antibiogram.Rd':
% Please edit documentation in R/antibiogram.R
\name{antibiogram}
\alias{antibiogram}
+\alias{wisca}
+\alias{get_long_numeric_format}
\alias{plot.antibiogram}
\alias{autoplot.antibiogram}
\alias{knit_print.antibiogram}
@@ -1621,59 +1617,57 @@ THE PART HEREAFTER CONTAINS CONTENTS FROM FILE 'man/antibiogram.Rd':
\source{
\itemize{
\item Bielicki JA \emph{et al.} (2016). \strong{Selecting appropriate empirical antibiotic regimens for paediatric bloodstream infections: application of a Bayesian decision model to local and pooled antimicrobial resistance surveillance data} \emph{Journal of Antimicrobial Chemotherapy} 71(3); \doi{10.1093/jac/dkv397}
+\item Bielicki JA \emph{et al.} (2020). \strong{Evaluation of the coverage of 3 antibiotic regimens for neonatal sepsis in the hospital setting across Asian countries} \emph{JAMA Netw Open.} 3(2):e1921124; \doi{10.1001.jamanetworkopen.2019.21124}
\item Klinker KP \emph{et al.} (2021). \strong{Antimicrobial stewardship and antibiograms: importance of moving beyond traditional antibiograms}. \emph{Therapeutic Advances in Infectious Disease}, May 5;8:20499361211011373; \doi{10.1177/20499361211011373}
\item Barbieri E \emph{et al.} (2021). \strong{Development of a Weighted-Incidence Syndromic Combination Antibiogram (WISCA) to guide the choice of the empiric antibiotic treatment for urinary tract infection in paediatric patients: a Bayesian approach} \emph{Antimicrobial Resistance & Infection Control} May 1;10(1):74; \doi{10.1186/s13756-021-00939-2}
\item \strong{M39 Analysis and Presentation of Cumulative Antimicrobial Susceptibility Test Data, 5th Edition}, 2022, \emph{Clinical and Laboratory Standards Institute (CLSI)}. \url{https://clsi.org/standards/products/microbiology/documents/m39/}.
}
}
\usage{
-antibiogram(
- x,
- antibiotics = where(is.sir),
- mo_transform = "shortname",
- ab_transform = "name",
- syndromic_group = NULL,
- add_total_n = FALSE,
- only_all_tested = FALSE,
- digits = 0,
- formatting_type = getOption("AMR_antibiogram_formatting_type", 10),
- col_mo = NULL,
- language = get_AMR_locale(),
- minimum = 30,
- combine_SI = TRUE,
- sep = " + ",
- info = interactive()
-)
+antibiogram(x, antibiotics = where(is.sir), mo_transform = "shortname",
+ ab_transform = "name", syndromic_group = NULL, add_total_n = FALSE,
+ only_all_tested = FALSE, digits = 0,
+ formatting_type = getOption("AMR_antibiogram_formatting_type",
+ ifelse(wisca, 18, 10)), col_mo = NULL, language = get_AMR_locale(),
+ minimum = 30, combine_SI = TRUE, sep = " + ", wisca = FALSE,
+ simulations = 1000, conf_interval = 0.95, interval_side = "two-tailed",
+ info = interactive())
+
+wisca(x, antibiotics = where(is.sir), mo_transform = "shortname",
+ ab_transform = "name", syndromic_group = NULL, add_total_n = FALSE,
+ only_all_tested = FALSE, digits = 0,
+ formatting_type = getOption("AMR_antibiogram_formatting_type", 18),
+ col_mo = NULL, language = get_AMR_locale(), minimum = 30,
+ combine_SI = TRUE, sep = " + ", simulations = 1000,
+ info = interactive())
+
+get_long_numeric_format(antibiogram)
\method{plot}{antibiogram}(x, ...)
\method{autoplot}{antibiogram}(object, ...)
-\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 antibiotic results (class 'sir', see \code{\link[=as.sir]{as.sir()}})}
+\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{antibiotics}{vector of any antibiotic name or code (will be evaluated with \code{\link[=as.ab]{as.ab()}}, column name of \code{x}, or (any combinations of) \link[=antimicrobial_class_selectors]{antimicrobial selectors} such as \code{\link[=aminoglycosides]{aminoglycosides()}} or \code{\link[=carbapenems]{carbapenems()}}. For combination antibiograms, this can also be set to values separated with \code{"+"}, such as "TZP+TOB" or "cipro + genta", given that columns resembling such antibiotics exist in \code{x}. See \emph{Examples}.}
+\item{antibiotics}{vector of any antimicrobial name or code (will be evaluated with \code{\link[=as.ab]{as.ab()}}, column name of \code{x}, or (any combinations of) \link[=antimicrobial_class_selectors]{antimicrobial selectors} such as \code{\link[=aminoglycosides]{aminoglycosides()}} or \code{\link[=carbapenems]{carbapenems()}}. For combination antibiograms, this can also be set to values separated with \code{"+"}, such as "TZP+TOB" or "cipro + genta", given that columns resembling such antimicrobials exist in \code{x}. See \emph{Examples}.}
\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: "mo", "fullname", "status", "kingdom", "phylum", "class", "order", "family", "genus", "species", "subspecies", "rank", "ref", "oxygen_tolerance", "source", "lpsn", "lpsn_parent", "lpsn_renamed_to", "mycobank", "mycobank_parent", "mycobank_renamed_to", "gbif", "gbif_parent", "gbif_renamed_to", "prevalence", or "snomed". Can also be \code{NULL} to not transform the input.}
-\item{ab_transform}{a character to transform antibiotic input - must be one of the column names of the \link{antibiotics} data set (defaults to \code{"name"}): "ab", "cid", "name", "group", "atc", "atc_group1", "atc_group2", "abbreviations", "synonyms", "oral_ddd", "oral_units", "iv_ddd", "iv_units", or "loinc". Can also be \code{NULL} to not transform the input.}
+\item{ab_transform}{a character to transform antimicrobial input - must be one of the column names of the \link{antibiotics} data set (defaults to \code{"name"}): "ab", "cid", "name", "group", "atc", "atc_group1", "atc_group2", "abbreviations", "synonyms", "oral_ddd", "oral_units", "iv_ddd", "iv_units", or "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_when]{case_when()}}. See \emph{Examples}.}
-\item{add_total_n}{a \link{logical} to indicate whether total available numbers per pathogen should be added to the table (default is \code{TRUE}). This will add the lowest and highest number of available isolate per antibiotic (e.g, if for \emph{E. coli} 200 isolates are available for ciprofloxacin and 150 for amoxicillin, the returned number will be "150-200").}
+\item{add_total_n}{a \link{logical} to indicate whether total 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").}
-\item{only_all_tested}{(for combination antibiograms): a \link{logical} to indicate that isolates must be tested for all antibiotics, see \emph{Details}}
+\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 susceptibility percentage}
-\item{formatting_type}{numeric value (1–12) indicating how the 'cells' of the antibiogram table should be formatted. See \emph{Details} > \emph{Formatting Type} for a list of options.}
+\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()}}.}
@@ -1683,10 +1677,20 @@ antibiogram(
\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 antibiotic columns in combination antibiograms}
+\item{sep}{a separating character for antimicrobial columns in combination antibiograms}
+
+\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 hierarchical model to estimate regimen coverage probabilities using Montecarlo simulations. Set \code{simulations} to adjust.}
+
+\item{simulations}{(for WISCA) a numerical value to set the number of Montecarlo simulations}
+
+\item{conf_interval}{(for WISCA) a numerical value to set confidence interval (default is \code{0.95})}
+
+\item{interval_side}{(for WISCA) 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{antibiogram}{the outcome of \code{\link[=antibiogram]{antibiogram()}} or \code{\link[=wisca]{wisca()}}}
+
\item{...}{when used in \link[knitr:kable]{R Markdown or Quarto}: arguments passed on to \code{\link[knitr:kable]{knitr::kable()}} (otherwise, has no use)}
\item{object}{an \code{\link[=antibiogram]{antibiogram()}} object}
@@ -1696,15 +1700,21 @@ antibiogram(
\item{na}{character to use for showing \code{NA} values}
}
\description{
-Create detailed antibiograms with options for traditional, combination, syndromic, and Bayesian WISCA methods. Based on the approaches of Klinker \emph{et al.}, Barbieri \emph{et al.}, and the Bayesian WISCA model (Weighted-Incidence Syndromic Combination Antibiogram) by Bielicki \emph{et al.}, this function provides flexible output formats including plots and tables, ideal for integration with R Markdown and Quarto reports.
+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 provides flexible output formats including plots and tables, ideal for integration with R Markdown and Quarto reports.
}
\details{
This function returns 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 in your data set with one of the four available algorithms.
+
+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.
+
+Using \code{\link[=get_long_numeric_format]{get_long_numeric_format()}}, the antibiogram is converted to a long format containing numeric values. 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} is the susceptibility percentage, \code{15} the numerator, and \code{300} the denominator:
+The formatting of the 'cells' of the table can be set with the argument \code{formatting_type}. In these examples, \code{5} is the susceptibility percentage (for WISCA: \code{4-6} indicates the confidence level), \code{15} the numerator, and \code{300} the denominator:
\enumerate{
\item 5
\item 15
@@ -1715,21 +1725,33 @@ The formatting of the 'cells' of the table can be set with the argument \code{fo
\item 5 (N=300)
\item 5\% (N=300)
\item 5 (15/300)
-\item 5\% (15/300)
+\item 5\% (15/300) - \strong{default for non-WISCA}
\item 5 (N=15/300)
\item 5\% (N=15/300)
+
+Additional options for WISCA (using \code{antibiogram(..., wisca = TRUE)} or \code{wisca()}):
+\item 5 (4-6)
+\item 5\% (4-6\%)
+\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 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 is \code{10}, which 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)}.
+The default is \code{18} for WISCA and \code{10} for non-WISCA, which 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)}.
-Set \code{digits} (defaults to \code{0}) to alter the rounding of the susceptibility percentage.
+Set \code{digits} (defaults to \code{0}) to alter the rounding of the susceptibility percentages.
}
\subsection{Antibiogram Types}{
-There are four antibiogram types, as summarised by Klinker \emph{et al.} (2021, \doi{10.1177/20499361211011373}), and they are all supported by \code{\link[=antibiogram]{antibiogram()}}. Use WISCA whenever possible, since it provides precise coverage estimates by accounting for pathogen incidence and antimicrobial susceptibility. See the section \emph{Why Use WISCA?} on this page.
+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()}}.
-The four antibiogram types:
+\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{Why Use WISCA?} on this page.
\enumerate{
\item \strong{Traditional Antibiogram}
@@ -1761,29 +1783,35 @@ Code example:
}\if{html}{\out{}}
\item \strong{Weighted-Incidence Syndromic Combination Antibiogram (WISCA)}
-WISCA enhances empirical antibiotic selection by weighting the incidence of pathogens in specific clinical syndromes and combining them with their susceptibility data. It provides an estimation of regimen coverage by aggregating pathogen incidences and susceptibilities across potential causative organisms. See also the section \emph{Why Use WISCA?} on this page.
-
-Case example: Susceptibility of \emph{Pseudomonas aeruginosa} to TZP among respiratory specimens (obtained among ICU patients only) for male patients age >=65 years with heart failure
+WISCA can be applied to any antibiogram, see the section \emph{Why Use WISCA?} on this page for more information.
Code example:
-\if{html}{\out{
}}\preformatted{library(dplyr)
-your_data \%>\%
- filter(ward == "ICU" & specimen_type == "Respiratory") \%>\%
- antibiogram(antibiotics = c("TZP", "TZP+TOB", "TZP+GEN"),
- syndromic_group = ifelse(.$age >= 65 &
- .$gender == "Male" &
- .$condition == "Heart Disease",
- "Study Group", "Control Group"))
+\if{html}{\out{
}}\preformatted{antibiogram(your_data,
+ antibiotics = c("TZP", "TZP+TOB", "TZP+GEN"),
+ wisca = TRUE)
+
+# this is equal to:
+wisca(your_data,
+ antibiotics = c("TZP", "TZP+TOB", "TZP+GEN"))
}\if{html}{\out{
}}
WISCA uses a sophisticated Bayesian decision model to combine both local and pooled antimicrobial resistance data. This approach not only evaluates local patterns but can also draw on multi-centre datasets to improve regimen accuracy, even in low-incidence infections like paediatric bloodstream infections (BSIs).
}
+
+Grouped \link[tibble:tibble]{tibbles} can also be used to calculate susceptibilities over various groups.
+
+Code example:
+
+\if{html}{\out{
}}\preformatted{your_data \%>\%
+ group_by(has_sepsis, is_neonate, sex) \%>\%
+ wisca(antibiotics = c("TZP", "TZP+TOB", "TZP+GEN"))
+}\if{html}{\out{
}}
}
\subsection{Inclusion in Combination Antibiogram and Syndromic Antibiogram}{
-Note that for types 2 and 3 (Combination Antibiogram and Syndromic Antibiogram), it is important to realise that susceptibility can be calculated in two ways, which can be set with the \code{only_all_tested} argument (default is \code{FALSE}). See this example for two antibiotics, Drug A and Drug B, about how \code{\link[=antibiogram]{antibiogram()}} works to calculate the \%SI:
+Note that for types 2 and 3 (Combination Antibiogram and Syndromic Antibiogram), it is important to realise that susceptibility can be calculated in two ways, which can be set with the \code{only_all_tested} argument (default is \code{FALSE}). See this example for two antimicrobials, Drug A and Drug B, about how \code{\link[=antibiogram]{antibiogram()}} works to calculate the \%SI:
\if{html}{\out{
}}\preformatted{--------------------------------------------------------------------
only_all_tested = FALSE only_all_tested = TRUE
@@ -1815,17 +1843,53 @@ You can also use functions from specific 'table reporting' packages to transform
}
\section{Why Use WISCA?}{
-WISCA is a powerful tool for guiding empirical antibiotic therapy because it provides precise coverage estimates by accounting for pathogen incidence and antimicrobial susceptibility. This is particularly important in empirical treatment, where the causative pathogen is often unknown at the outset. Traditional antibiograms do not reflect the weighted likelihood of specific pathogens based on clinical syndromes, which can lead to suboptimal treatment choices.
+WISCA, as outlined by Barbieri \emph{et al.} (\doi{10.1186/s13756-021-00939-2}), stands for
+Weighted-Incidence Syndromic Combination Antibiogram, which estimates the probability
+of adequate empirical antimicrobial regimen coverage for specific infection syndromes.
+This method leverages a Bayesian hierarchical logistic regression framework with random
+effects for pathogens and regimens, enabling robust estimates in the presence of sparse
+data.
-The Bayesian WISCA, as described by Bielicki \emph{et al.} (2016), improves on earlier methods by handling uncertainties common in smaller datasets, such as low-incidence infections. This method offers a significant advantage by:
-\enumerate{
-\item Pooling Data from Multiple Sources:\cr WISCA uses pooled data from multiple hospitals or surveillance sources to overcome limitations of small sample sizes at individual institutions, allowing for more confident selection of narrow-spectrum antibiotics or combinations.
-\item Bayesian Framework:\cr The Bayesian decision tree model accounts for both local data and prior knowledge (such as inherent resistance patterns) to estimate regimen coverage. It allows for a more precise estimation of coverage, even in cases where susceptibility data is missing or incomplete.
-\item Incorporating Pathogen and Regimen Uncertainty:\cr WISCA allows clinicians to see the likelihood that an empirical regimen will be effective against all relevant pathogens, taking into account uncertainties related to both pathogen prevalence and antimicrobial resistance. This leads to better-informed, data-driven clinical decisions.
-\item Scenarios for Optimising Treatment:\cr For hospitals or settings with low-incidence infections, WISCA helps determine whether local data is sufficient or if pooling with external data is necessary. It also identifies statistically significant differences or similarities between antibiotic regimens, enabling clinicians to choose optimal therapies with greater confidence.
-}
+The Bayesian model assumes conjugate priors for parameter estimation. For example, the
+coverage probability \ifelse{latex}{\deqn{$theta$}}{$theta$} for a given antimicrobial regimen
+is modeled using a Beta distribution as a prior:
+
+\ifelse{latex}{\deqn{$theta$ \sim \text{Beta}($alpha$_0, $beta$_0)}}{
+\ifelse{html}{\figure{beta_prior.png}{options: width="300" alt="Beta prior"}}{$theta$ ~ Beta($alpha$_0, $beta$_0)}}
+
+where \eqn{$alpha$_0} and \eqn{$beta$_0} represent prior successes and failures, respectively,
+informed by expert knowledge or weakly informative priors (e.g., \eqn{$alpha$_0 = 1, $beta$_0 = 1}).
+
+The likelihood function is constructed based on observed data, where the number of covered
+cases for a regimen follows a binomial distribution:
+
+\ifelse{latex}{\deqn{y \sim \text{Binomial}(n, $theta$)}}{
+\ifelse{html}{\figure{binomial_likelihood.png}{options: width="300" alt="Binomial likelihood"}}{y ~ Binomial(n, $theta$)}}
-WISCA is essential in optimising empirical treatment by shifting away from broad-spectrum antibiotics, which are often overused in empirical settings. By offering precise estimates based on syndromic patterns and pooled data, WISCA supports antimicrobial stewardship by guiding more targeted therapy, reducing unnecessary broad-spectrum use, and combating the rise of antimicrobial resistance.
+Posterior parameter estimates are obtained by combining the prior and likelihood using
+Bayes' theorem. The posterior distribution of \eqn{$theta$} is also a Beta distribution:
+
+\ifelse{latex}{\deqn{$theta$ | y \sim \text{Beta}($alpha$_0 + y, $beta$_0 + n - y)}}{
+\ifelse{html}{\figure{posterior_beta.png}{options: width="300" alt="Beta posterior"}}{$theta$ | y ~ Beta($alpha$_0 + y, $beta$_0 + n - y)}}
+
+For hierarchical modeling, pathogen-level effects (e.g., differences in resistance
+patterns) and regimen-level effects are modelled using Gaussian priors on log-odds.
+This hierarchical structure ensures partial pooling of estimates across groups,
+improving stability in strata with small sample sizes. The model is implemented using
+Hamiltonian Monte Carlo (HMC) sampling.
+
+Stratified results are provided based on covariates such as age, sex, and clinical
+complexity (e.g., prior antimicrobial treatments or renal/urological comorbidities).
+For example, posterior odds ratios (ORs) are derived to quantify the effect of these
+covariates on coverage probabilities:
+
+\ifelse{latex}{\deqn{\text{OR}_{\text{covariate}} = \frac{\exp($beta$_{\text{covariate}})}{\exp($beta$_0)}}}{
+\ifelse{html}{\figure{odds_ratio.png}{options: width="300" alt="Odds ratio formula"}}{OR_covariate = exp(beta_covariate) / exp(beta_0)}}
+
+By combining empirical data with prior knowledge, WISCA overcomes the limitations
+of traditional combination antibiograms, offering disease-specific, patient-stratified
+estimates with robust uncertainty quantification. This tool is invaluable for antimicrobial
+stewardship programs and empirical treatment guideline refinement.
}
\examples{
@@ -1893,17 +1957,13 @@ antibiogram(ex1,
)
-# Weighted-incidence syndromic combination antibiogram (WISCA) ---------
+# WISCA antibiogram ----------------------------------------------------
-# the data set could contain a filter for e.g. respiratory specimens/ICU
+# can be used for any of the above types - just add `wisca = TRUE`
antibiogram(example_isolates,
- antibiotics = c("AMC", "AMC+CIP", "TZP", "TZP+TOB"),
+ antibiotics = c("TZP", "TZP+TOB", "TZP+GEN"),
mo_transform = "gramstain",
- minimum = 10, # this should be >=30, but now just as example
- syndromic_group = ifelse(example_isolates$age >= 65 &
- example_isolates$gender == "M",
- "WISCA Group 1", "WISCA Group 2"
- )
+ wisca = TRUE
)
@@ -2084,28 +2144,14 @@ THE PART HEREAFTER CONTAINS CONTENTS FROM FILE 'man/antimicrobial_class_selector
\alias{not_intrinsic_resistant}
\title{Antimicrobial Selectors}
\usage{
-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, ...)
-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, ...)
@@ -2113,21 +2159,14 @@ 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, return_all = TRUE, ...)
@@ -2145,12 +2184,8 @@ fluoroquinolones(only_sir_columns = FALSE, return_all = TRUE, ...)
glycopeptides(only_sir_columns = FALSE, 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, ...)
@@ -2164,12 +2199,8 @@ penicillins(only_sir_columns = FALSE, return_all = TRUE, ...)
phenicols(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, return_all = TRUE, ...)
@@ -2187,12 +2218,8 @@ 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_expertrules = 3.3,
- ...
-)
+not_intrinsic_resistant(only_sir_columns = FALSE, col_mo = NULL,
+ version_expertrules = 3.3, ...)
}
\arguments{
\item{amr_class}{an antimicrobial class or a part of it, such as \code{"carba"} and \code{"carbapenems"}. The columns \code{group}, \code{atc_group1} and \code{atc_group2} of the \link{antibiotics} data set will be searched (case-insensitive) for this value.}
@@ -2895,20 +2922,14 @@ THE PART HEREAFTER CONTAINS CONTENTS FROM FILE 'man/as.mo.Rd':
\alias{mo_cleaning_regex}
\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)
@@ -3189,64 +3210,35 @@ is.sir(x)
is_sir_eligible(x, threshold = 0.05)
-\method{as.sir}{default}(
- x,
- S = "^(S|U)+$",
- I = "^(I)+$",
- R = "^(R)+$",
- NI = "^(N|NI|V)+$",
- SDD = "^(SDD|D|H)+$",
- ...
-)
+\method{as.sir}{default}(x, S = "^(S|U)+$", I = "^(I)+$", R = "^(R)+$",
+ NI = "^(N|NI|V)+$", SDD = "^(SDD|D|H)+$", ...)
-\method{as.sir}{mic}(
- x,
- mo = NULL,
- ab = deparse(substitute(x)),
- guideline = getOption("AMR_guideline", "EUCAST"),
- uti = NULL,
- conserve_capped_values = FALSE,
- add_intrinsic_resistance = FALSE,
+\method{as.sir}{mic}(x, mo = NULL, ab = deparse(substitute(x)),
+ guideline = getOption("AMR_guideline", "EUCAST"), uti = NULL,
+ conserve_capped_values = FALSE, add_intrinsic_resistance = FALSE,
reference_data = AMR::clinical_breakpoints,
include_screening = getOption("AMR_include_screening", FALSE),
include_PKPD = getOption("AMR_include_PKPD", TRUE),
- breakpoint_type = getOption("AMR_breakpoint_type", "human"),
- host = NULL,
- verbose = FALSE,
- ...
-)
+ breakpoint_type = getOption("AMR_breakpoint_type", "human"), host = NULL,
+ verbose = FALSE, ...)
-\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,
add_intrinsic_resistance = FALSE,
reference_data = AMR::clinical_breakpoints,
include_screening = getOption("AMR_include_screening", FALSE),
include_PKPD = getOption("AMR_include_PKPD", TRUE),
- breakpoint_type = getOption("AMR_breakpoint_type", "human"),
- host = NULL,
- verbose = FALSE,
- ...
-)
+ breakpoint_type = getOption("AMR_breakpoint_type", "human"), host = NULL,
+ verbose = FALSE, ...)
-\method{as.sir}{data.frame}(
- x,
- ...,
- col_mo = NULL,
- guideline = getOption("AMR_guideline", "EUCAST"),
- uti = NULL,
- conserve_capped_values = FALSE,
- add_intrinsic_resistance = FALSE,
+\method{as.sir}{data.frame}(x, ..., col_mo = NULL,
+ guideline = getOption("AMR_guideline", "EUCAST"), uti = NULL,
+ conserve_capped_values = FALSE, add_intrinsic_resistance = FALSE,
reference_data = AMR::clinical_breakpoints,
include_screening = getOption("AMR_include_screening", FALSE),
include_PKPD = getOption("AMR_include_PKPD", TRUE),
- breakpoint_type = getOption("AMR_breakpoint_type", "human"),
- host = NULL,
- verbose = FALSE
-)
+ breakpoint_type = getOption("AMR_breakpoint_type", "human"), host = NULL,
+ verbose = FALSE)
sir_interpretation_history(clean = FALSE)
}
@@ -3590,13 +3582,9 @@ THE PART HEREAFTER CONTAINS CONTENTS FROM FILE 'man/atc_online.Rd':
\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, ...)
@@ -3675,15 +3663,9 @@ THE PART HEREAFTER CONTAINS CONTENTS FROM FILE 'man/av_from_text.Rd':
\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}
@@ -3907,20 +3889,14 @@ THE PART HEREAFTER CONTAINS CONTENTS FROM FILE 'man/bug_drug_combinations.Rd':
\alias{format.bug_drug_combinations}
\title{Determine Bug-Drug Combinations}
\usage{
-bug_drug_combinations(x, col_mo = NULL, FUN = mo_shortname, ...)
+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 antibiotic columns, such as \code{amox}, \code{AMX} and \code{AMC}}
@@ -4102,12 +4078,8 @@ 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.}
@@ -4489,19 +4461,11 @@ Leclercq et al. \strong{EUCAST expert rules in antimicrobial susceptibility test
}
}
\usage{
-eucast_rules(
- x,
- col_mo = NULL,
- info = interactive(),
+eucast_rules(x, col_mo = NULL, info = interactive(),
rules = getOption("AMR_eucastrules", default = c("breakpoints", "expert")),
- verbose = FALSE,
- version_breakpoints = 12,
- version_expertrules = 3.3,
- ampc_cephalosporin_resistance = NA,
- only_sir_columns = FALSE,
- custom_rules = NULL,
- ...
-)
+ verbose = FALSE, version_breakpoints = 12, version_expertrules = 3.3,
+ ampc_cephalosporin_resistance = NA, only_sir_columns = FALSE,
+ custom_rules = NULL, ...)
eucast_dosage(ab, administration = "iv", version_breakpoints = 12)
}
@@ -4708,13 +4672,9 @@ THE PART HEREAFTER CONTAINS CONTENTS FROM FILE 'man/export_ncbi_biosample.Rd':
\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}
@@ -4747,38 +4707,18 @@ Methodology of this function is strictly based on:
}
}
\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,
- ...
-)
-
-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"),
- ...
-)
+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"), ...)
}
\arguments{
\item{x}{a \link{data.frame} containing isolates. Can be left blank for automatic determination, see \emph{Examples}.}
@@ -4828,6 +4768,7 @@ A \link{logical} vector
Determine first isolates of all microorganisms of every patient per episode and (if needed) per specimen type. These functions support all four methods as summarised by Hindler \emph{et al.} in 2007 (\doi{10.1086/511864}). To determine patient episodes not necessarily based on microorganisms, use \code{\link[=is_new_episode]{is_new_episode()}} that also supports grouping with the \code{dplyr} package.
}
\details{
+The methodology implemented in these functions is based on the research overview by Hindler \emph{et al.} (2007, \doi{10.1086/511864}) and the recommendations outlined in the \href{https://clsi.org/standards/products/microbiology/documents/m39}{CLSI Guideline M39}.
To conduct epidemiological analyses on antimicrobial resistance data, only so-called first isolates should be included to prevent overestimation and underestimation of antimicrobial resistance. Different methods can be used to do so, see below.
These functions are context-aware. This means that the \code{x} argument can be left blank if used inside a \link{data.frame} call, see \emph{Examples}.
@@ -4837,7 +4778,7 @@ The \code{\link[=first_isolate]{first_isolate()}} function is a wrapper around t
All isolates with a microbial ID of \code{NA} will be excluded as first isolate.
\subsection{Different methods}{
-According to Hindler \emph{et al.} (2007, \doi{10.1086/511864}), there are different methods (algorithms) to select first isolates with increasing reliability: isolate-based, patient-based, episode-based and phenotype-based. All methods select on a combination of the taxonomic genus and species (not subspecies).
+According to previously-mentioned sources, there are different methods (algorithms) to select first isolates with increasing reliability: isolate-based, patient-based, episode-based and phenotype-based. All methods select on a combination of the taxonomic genus and species (not subspecies).
All mentioned methods are covered in the \code{\link[=first_isolate]{first_isolate()}} function:\tabular{ll}{
\strong{Method} \tab \strong{Function to apply} \cr
@@ -4870,12 +4811,12 @@ This method does not require any selection, as all isolates should be included.
\subsection{Patient-based}{
-To include every genus-species combination per patient once, set the \code{episode_days} to \code{Inf}. Although often inappropriate, this method makes sure that no duplicate isolates are selected from the same patient. In a large longitudinal data set, this could mean that isolates are \emph{excluded} that were found years after the initial isolate.
+To include every genus-species combination per patient once, set the \code{episode_days} to \code{Inf}. This method makes sure that no duplicate isolates are selected from the same patient. This method is preferred to e.g. identify the first MRSA finding of each patient to determine the incidence. Conversely, in a large longitudinal data set, this could mean that isolates are \emph{excluded} that were found years after the initial isolate.
}
\subsection{Episode-based}{
-To include every genus-species combination per patient episode once, set the \code{episode_days} to a sensible number of days. Depending on the type of analysis, this could be 14, 30, 60 or 365. Short episodes are common for analysing specific hospital or ward data, long episodes are common for analysing regional and national data.
+To include every genus-species combination per patient episode once, set the \code{episode_days} to a sensible number of days. Depending on the type of analysis, this could be 14, 30, 60 or 365. Short episodes are common for analysing specific hospital or ward data or ICU cases, long episodes are common for analysing regional and national data.
This is the most common method to correct for duplicate isolates. Patients are categorised into episodes based on their ID and dates (e.g., the date of specimen receipt or laboratory result). While this is a common method, it does not take into account antimicrobial test results. This means that e.g. a methicillin-resistant \emph{Staphylococcus aureus} (MRSA) isolate cannot be differentiated from a wildtype \emph{Staphylococcus aureus} isolate.
}
@@ -5301,30 +5242,13 @@ 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()}}}
@@ -5443,42 +5367,18 @@ THE PART HEREAFTER CONTAINS CONTENTS FROM FILE 'man/ggplot_sir.Rd':
\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", 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,
- ...
-)
+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", 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, ...)
}
\arguments{
\item{data}{a \link{data.frame} with column(s) of class \code{\link{sir}} (see \code{\link[=as.sir]{as.sir()}})}
@@ -5652,12 +5552,8 @@ THE PART HEREAFTER CONTAINS CONTENTS FROM FILE 'man/guess_ab_col.Rd':
\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}}
@@ -5868,31 +5764,19 @@ THE PART HEREAFTER CONTAINS CONTENTS FROM FILE 'man/key_antimicrobials.Rd':
\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 = FALSE,
- ...
-)
+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 = FALSE, ...)
all_antimicrobials(x = NULL, only_sir_columns = FALSE, ...)
-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 antibiotics columns, like \code{AMX} or \code{amox}. Can be left blank to determine automatically}
@@ -6156,23 +6040,10 @@ THE PART HEREAFTER CONTAINS CONTENTS FROM FILE 'man/mdro.Rd':
See the supported guidelines above for the \link{list} of publications used for this function.
}
\usage{
-mdro(
- x = NULL,
- guideline = "CMI2012",
- 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 = FALSE,
- ...
-)
+mdro(x = NULL, guideline = "CMI2012", 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 = FALSE, ...)
custom_mdro_guideline(..., as_factor = TRUE)
@@ -6184,12 +6055,8 @@ mdr_tb(x = NULL, only_sir_columns = FALSE, verbose = FALSE, ...)
mdr_cmi2012(x = NULL, only_sir_columns = FALSE, verbose = FALSE, ...)
-eucast_exceptional_phenotypes(
- x = NULL,
- only_sir_columns = FALSE,
- verbose = FALSE,
- ...
-)
+eucast_exceptional_phenotypes(x = NULL, only_sir_columns = FALSE,
+ verbose = FALSE, ...)
}
\arguments{
\item{x}{a \link{data.frame} with antibiotics columns, like \code{AMX} or \code{amox}. Can be left blank for automatic determination.}
@@ -6806,262 +6673,115 @@ THE PART HEREAFTER CONTAINS CONTENTS FROM FILE 'man/mo_property.Rd':
\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_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_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_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_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_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_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_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_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_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_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_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_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_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_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_pathogenicity(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),
- ...
-)
+mo_gramstain(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_is_gram_negative(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_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_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_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_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_is_anaerobic(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_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_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_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_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_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_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_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_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_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_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}.}
@@ -7285,10 +7005,8 @@ THE PART HEREAFTER CONTAINS CONTENTS FROM FILE 'man/mo_source.Rd':
\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"))
}
@@ -7398,15 +7116,8 @@ THE PART HEREAFTER CONTAINS CONTENTS FROM FILE 'man/pca.Rd':
\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}
@@ -7518,128 +7229,83 @@ THE PART HEREAFTER CONTAINS CONTENTS FROM FILE 'man/plot.Rd':
\alias{labels_sir_count}
\title{Plotting Helpers for AMR Data Analysis}
\usage{
-scale_x_mic(keep_operators = "edges", mic_range = NULL, drop = FALSE, ...)
+scale_x_mic(keep_operators = "edges", mic_range = NULL, drop = FALSE,
+ ...)
-scale_y_mic(keep_operators = "edges", mic_range = NULL, drop = FALSE, ...)
+scale_y_mic(keep_operators = "edges", mic_range = NULL, drop = FALSE,
+ ...)
-scale_colour_mic(keep_operators = "edges", mic_range = NULL, drop = FALSE, ...)
+scale_colour_mic(keep_operators = "edges", mic_range = NULL,
+ drop = FALSE, ...)
-scale_fill_mic(keep_operators = "edges", mic_range = NULL, drop = FALSE, ...)
+scale_fill_mic(keep_operators = "edges", mic_range = NULL, drop = FALSE,
+ ...)
-\method{plot}{mic}(
- x,
- mo = NULL,
- ab = NULL,
- 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("#3CAEA3", "#F6D55C", "#ED553B"),
- language = get_AMR_locale(),
- expand = TRUE,
+\method{plot}{mic}(x, mo = NULL, ab = NULL, 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("#3CAEA3", "#F6D55C", "#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,
- guideline = "EUCAST",
- title = deparse(substitute(object)),
+\method{autoplot}{mic}(object, mo = NULL, ab = NULL,
+ 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("#3CAEA3", "#F6D55C", "#ED553B"),
- language = get_AMR_locale(),
- expand = TRUE,
+ xlab = translate_AMR("Minimum Inhibitory Concentration (mg/L)", language =
+ language), colours_SIR = c("#3CAEA3", "#F6D55C", "#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{fortify}{mic}(object, ...)
-\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 = "EUCAST",
+ mo = NULL, ab = NULL, guideline = "EUCAST",
colours_SIR = c("#3CAEA3", "#F6D55C", "#ED553B"),
- language = get_AMR_locale(),
- expand = TRUE,
+ 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 = "EUCAST",
- colours_SIR = c("#3CAEA3", "#F6D55C", "#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 = "EUCAST", colours_SIR = c("#3CAEA3",
+ "#F6D55C", "#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{fortify}{disk}(object, ...)
-\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{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{autoplot}{sir}(object, title = deparse(substitute(object)),
xlab = translate_AMR("Antimicrobial Interpretation", language = language),
ylab = translate_AMR("Frequency", language = language),
colours_SIR = c("#3CAEA3", "#F6D55C", "#ED553B"),
- language = get_AMR_locale(),
- ...
-)
+ language = get_AMR_locale(), ...)
\method{fortify}{sir}(object, ...)
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 = "fill",
- colours_SIR = c("#3CAEA3", "#F6D55C", "#ED553B")
-)
+scale_sir_colours(..., aesthetics = "fill", colours_SIR = c("#3CAEA3",
+ "#F6D55C", "#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.}
@@ -7824,50 +7490,38 @@ THE PART HEREAFTER CONTAINS CONTENTS FROM FILE 'man/proportion.Rd':
\strong{M39 Analysis and Presentation of Cumulative Antimicrobial Susceptibility Test Data, 5th Edition}, 2022, \emph{Clinical and Laboratory Standards Institute (CLSI)}. \url{https://clsi.org/standards/products/microbiology/documents/m39/}.
}
\usage{
-resistance(..., minimum = 30, as_percent = FALSE, only_all_tested = FALSE)
-
-susceptibility(..., minimum = 30, as_percent = FALSE, only_all_tested = FALSE)
-
-sir_confidence_interval(
- ...,
- ab_result = "R",
- minimum = 30,
- as_percent = FALSE,
- only_all_tested = FALSE,
- confidence_level = 0.95,
- side = "both",
- collapse = FALSE
-)
+resistance(..., minimum = 30, as_percent = FALSE,
+ only_all_tested = FALSE)
-proportion_R(..., minimum = 30, as_percent = FALSE, only_all_tested = FALSE)
+susceptibility(..., minimum = 30, as_percent = FALSE,
+ only_all_tested = FALSE)
-proportion_IR(..., minimum = 30, as_percent = FALSE, only_all_tested = 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_I(..., minimum = 30, as_percent = FALSE, only_all_tested = FALSE)
+proportion_R(..., minimum = 30, as_percent = FALSE,
+ only_all_tested = FALSE)
-proportion_SI(..., minimum = 30, as_percent = FALSE, only_all_tested = FALSE)
+proportion_IR(..., minimum = 30, as_percent = FALSE,
+ only_all_tested = FALSE)
-proportion_S(..., minimum = 30, as_percent = FALSE, only_all_tested = FALSE)
+proportion_I(..., 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_SI(..., minimum = 30, as_percent = FALSE,
+ only_all_tested = FALSE)
-sir_df(
- data,
- translate_ab = "name",
- language = get_AMR_locale(),
- minimum = 30,
- as_percent = FALSE,
- combine_SI = TRUE,
- confidence_level = 0.95
-)
+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)
+
+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}.}
@@ -8170,51 +7824,22 @@ THE PART HEREAFTER CONTAINS CONTENTS FROM FILE 'man/resistance_predict.Rd':
\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}.}
@@ -8378,6 +8003,56 @@ skewness(runif(1000))
+THE PART HEREAFTER CONTAINS CONTENTS FROM FILE 'man/top_n_microorganisms.Rd':
+
+
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/top_n_microorganisms.R
+\name{top_n_microorganisms}
+\alias{top_n_microorganisms}
+\title{Filter Top \emph{n} Microorganisms}
+\usage{
+top_n_microorganisms(x, n, property = "fullname", n_for_each = NULL,
+ col_mo = NULL, ...)
+}
+\arguments{
+\item{x}{a data frame containing microbial data}
+
+\item{n}{an integer specifying the maximum number of unique values of the \code{property} to include in the output}
+
+\item{property}{a character string indicating the microorganism property to use for filtering. Must be one of the column names of the \link{microorganisms} data set: "mo", "fullname", "status", "kingdom", "phylum", "class", "order", "family", "genus", "species", "subspecies", "rank", "ref", "oxygen_tolerance", "source", "lpsn", "lpsn_parent", "lpsn_renamed_to", "mycobank", "mycobank_parent", "mycobank_renamed_to", "gbif", "gbif_parent", "gbif_renamed_to", "prevalence", or "snomed". If \code{NULL}, the raw values from \code{col_mo} will be used without transformation.}
+
+\item{n_for_each}{an optional integer specifying the maximum number of rows to retain for each value of the selected property. If \code{NULL}, all rows within the top \emph{n} groups will be included.}
+
+\item{col_mo}{A character string indicating the column in \code{x} that contains microorganism names or codes. Defaults to the first column of class \code{\link{mo}}. Values will be coerced using \code{\link[=as.mo]{as.mo()}}.}
+
+\item{...}{Additional arguments passed on to \code{\link[=mo_property]{mo_property()}} when \code{property} is not \code{NULL}.}
+}
+\description{
+This function filters a data set to include only the top \emph{n} microorganisms based on a specified property, such as taxonomic family or genus. For example, it can filter a data set to the top 3 species, or to any species in the top 5 genera, or to the top 3 species in each of the top 5 genera.
+}
+\details{
+This function is useful for preprocessing data before creating \link[=antibiograms]{antibiograms} or other analyses that require focused subsets of microbial data. For example, it can filter a data set to only include isolates from the top 10 species.
+}
+\examples{
+# filter to the top 3 species:
+top_n_microorganisms(example_isolates,
+ n = 3)
+
+# filter to any species in the top 5 genera:
+top_n_microorganisms(example_isolates,
+ n = 5, property = "genus")
+
+# filter to the top 3 species in each of the top 5 genera:
+top_n_microorganisms(example_isolates,
+ n = 5, property = "genus", n_for_each = 3)
+}
+\seealso{
+\code{\link[=mo_property]{mo_property()}}, \code{\link[=as.mo]{as.mo()}}, \code{\link[=antibiogram]{antibiogram()}}
+}
+
+
+
THE PART HEREAFTER CONTAINS CONTENTS FROM FILE 'man/translate.Rd':
diff --git a/inst/tinytest/test-antibiogram.R b/inst/tinytest/test-antibiogram.R
index 886f0ea29..6614a902e 100644
--- a/inst/tinytest/test-antibiogram.R
+++ b/inst/tinytest/test-antibiogram.R
@@ -99,17 +99,22 @@ expect_equal(colnames(ab7), c("Syndroomgroep", "Pathogeen (N min-max)", "Amikaci
# Weighted-incidence syndromic combination antibiogram (WISCA) ---------
# the data set could contain a filter for e.g. respiratory specimens
-ab8 <- antibiogram(example_isolates,
- antibiotics = c("AMC", "AMC+CIP", "TZP", "TZP+TOB"),
- mo_transform = "gramstain",
- minimum = 10, # this should be >= 30, but now just as example
- syndromic_group = ifelse(example_isolates$age >= 65 &
- example_isolates$gender == "M",
- "WISCA Group 1", "WISCA Group 2"),
- ab_transform = NULL)
+ab8 <- suppressWarnings(antibiogram(example_isolates,
+ antibiotics = c("TZP", "TZP+TOB", "TZP+GEN"),
+ wisca = TRUE))
expect_inherits(ab8, "antibiogram")
-expect_equal(colnames(ab8), c("Syndromic Group", "Pathogen", "AMC", "AMC + CIP", "TZP", "TZP + TOB"))
+expect_equal(colnames(ab8), c("Pathogen", "Piperacillin/tazobactam", "Piperacillin/tazobactam + Gentamicin", "Piperacillin/tazobactam + Tobramycin"))
+
+# grouped tibbles
+
+if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0", also_load = TRUE)) {
+ ab9 <- example_isolates %>%
+ group_by(ward, gender) %>%
+ wisca(antibiotics = c("TZP", "TZP+TOB", "TZP+GEN"))
+ expect_equal(colnames(ab9), c("ward", "gender", "Piperacillin/tazobactam", "Piperacillin/tazobactam + Gentamicin", "Piperacillin/tazobactam + Tobramycin"))
+}
+
# Generate plots with ggplot2 or base R --------------------------------
@@ -123,6 +128,9 @@ expect_silent(plot(ab5))
expect_silent(plot(ab6))
expect_silent(plot(ab7))
expect_silent(plot(ab8))
+if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0", also_load = TRUE)) {
+ expect_silent(plot(ab9))
+}
if (AMR:::pkg_is_available("ggplot2")) {
expect_inherits(ggplot2::autoplot(ab1), "gg")
@@ -133,4 +141,7 @@ if (AMR:::pkg_is_available("ggplot2")) {
expect_inherits(ggplot2::autoplot(ab6), "gg")
expect_inherits(ggplot2::autoplot(ab7), "gg")
expect_inherits(ggplot2::autoplot(ab8), "gg")
+ if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0", also_load = TRUE)) {
+ expect_inherits(ggplot2::autoplot(ab9), "gg")
+ }
}
diff --git a/inst/tinytest/test-top_n_microorganisms.R b/inst/tinytest/test-top_n_microorganisms.R
new file mode 100644
index 000000000..af43a1892
--- /dev/null
+++ b/inst/tinytest/test-top_n_microorganisms.R
@@ -0,0 +1,43 @@
+# ==================================================================== #
+# TITLE: #
+# AMR: An R Package for Working with Antimicrobial Resistance Data #
+# #
+# SOURCE CODE: #
+# https://github.com/msberends/AMR #
+# #
+# PLEASE CITE THIS SOFTWARE AS: #
+# Berends MS, Luz CF, Friedrich AW, et al. (2022). #
+# AMR: An R Package for Working with Antimicrobial Resistance Data. #
+# Journal of Statistical Software, 104(3), 1-31. #
+# https://doi.org/10.18637/jss.v104.i03 #
+# #
+# Developed at the University of Groningen and the University Medical #
+# Center Groningen in The Netherlands, in collaboration with many #
+# colleagues from around the world, see our website. #
+# #
+# This R package is free software; you can freely use and distribute #
+# it for both personal and commercial purposes under the terms of the #
+# GNU General Public License version 2.0 (GNU GPL-2), as published by #
+# the Free Software Foundation. #
+# We created this package for both routine data analysis and academic #
+# research and it was publicly released in the hope that it will be #
+# useful, but it comes WITHOUT ANY WARRANTY OR LIABILITY. #
+# #
+# Visit our website for the full manual and a complete tutorial about #
+# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
+# ==================================================================== #
+
+out1 <- top_n_microorganisms(example_isolates, n = 3)
+out2 <- top_n_microorganisms(example_isolates, n = 5, property = "genus")
+out3 <- top_n_microorganisms(example_isolates, n = 5, property = "genus", n_for_each = 3)
+
+expect_equal(NROW(out1), 1015, tolerance = 0.5)
+expect_equal(NROW(out2), 1742, tolerance = 0.5)
+expect_equal(NROW(out3), 1497, tolerance = 0.5)
+
+expect_equal(length(table(out1$mo)), 3, tolerance = 0.5)
+expect_equal(length(table(out2$mo)), 39, tolerance = 0.5)
+expect_equal(length(table(out3$mo)), 13, tolerance = 0.5)
+
+expect_equal(length(unique(mo_genus(out2$mo))), 5, tolerance = 0.5)
+expect_equal(length(unique(mo_genus(out3$mo))), 5, tolerance = 0.5)
diff --git a/man/ab_from_text.Rd b/man/ab_from_text.Rd
index c182210d5..218db37a8 100644
--- a/man/ab_from_text.Rd
+++ b/man/ab_from_text.Rd
@@ -4,15 +4,9 @@
\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}
diff --git a/man/ab_property.Rd b/man/ab_property.Rd
index ccfe3030b..1b438c155 100644
--- a/man/ab_property.Rd
+++ b/man/ab_property.Rd
@@ -47,13 +47,8 @@ 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()}}}
diff --git a/man/antibiogram.Rd b/man/antibiogram.Rd
index 5a62a2ff7..bc63ccfd2 100644
--- a/man/antibiogram.Rd
+++ b/man/antibiogram.Rd
@@ -2,6 +2,8 @@
% Please edit documentation in R/antibiogram.R
\name{antibiogram}
\alias{antibiogram}
+\alias{wisca}
+\alias{get_long_numeric_format}
\alias{plot.antibiogram}
\alias{autoplot.antibiogram}
\alias{knit_print.antibiogram}
@@ -9,59 +11,57 @@
\source{
\itemize{
\item Bielicki JA \emph{et al.} (2016). \strong{Selecting appropriate empirical antibiotic regimens for paediatric bloodstream infections: application of a Bayesian decision model to local and pooled antimicrobial resistance surveillance data} \emph{Journal of Antimicrobial Chemotherapy} 71(3); \doi{10.1093/jac/dkv397}
+\item Bielicki JA \emph{et al.} (2020). \strong{Evaluation of the coverage of 3 antibiotic regimens for neonatal sepsis in the hospital setting across Asian countries} \emph{JAMA Netw Open.} 3(2):e1921124; \doi{10.1001.jamanetworkopen.2019.21124}
\item Klinker KP \emph{et al.} (2021). \strong{Antimicrobial stewardship and antibiograms: importance of moving beyond traditional antibiograms}. \emph{Therapeutic Advances in Infectious Disease}, May 5;8:20499361211011373; \doi{10.1177/20499361211011373}
\item Barbieri E \emph{et al.} (2021). \strong{Development of a Weighted-Incidence Syndromic Combination Antibiogram (WISCA) to guide the choice of the empiric antibiotic treatment for urinary tract infection in paediatric patients: a Bayesian approach} \emph{Antimicrobial Resistance & Infection Control} May 1;10(1):74; \doi{10.1186/s13756-021-00939-2}
\item \strong{M39 Analysis and Presentation of Cumulative Antimicrobial Susceptibility Test Data, 5th Edition}, 2022, \emph{Clinical and Laboratory Standards Institute (CLSI)}. \url{https://clsi.org/standards/products/microbiology/documents/m39/}.
}
}
\usage{
-antibiogram(
- x,
- antibiotics = where(is.sir),
- mo_transform = "shortname",
- ab_transform = "name",
- syndromic_group = NULL,
- add_total_n = FALSE,
- only_all_tested = FALSE,
- digits = 0,
- formatting_type = getOption("AMR_antibiogram_formatting_type", 10),
- col_mo = NULL,
- language = get_AMR_locale(),
- minimum = 30,
- combine_SI = TRUE,
- sep = " + ",
- info = interactive()
-)
+antibiogram(x, antibiotics = where(is.sir), mo_transform = "shortname",
+ ab_transform = "name", syndromic_group = NULL, add_total_n = FALSE,
+ only_all_tested = FALSE, digits = 0,
+ formatting_type = getOption("AMR_antibiogram_formatting_type",
+ ifelse(wisca, 18, 10)), col_mo = NULL, language = get_AMR_locale(),
+ minimum = 30, combine_SI = TRUE, sep = " + ", wisca = FALSE,
+ simulations = 1000, conf_interval = 0.95, interval_side = "two-tailed",
+ info = interactive())
+
+wisca(x, antibiotics = where(is.sir), mo_transform = "shortname",
+ ab_transform = "name", syndromic_group = NULL, add_total_n = FALSE,
+ only_all_tested = FALSE, digits = 0,
+ formatting_type = getOption("AMR_antibiogram_formatting_type", 18),
+ col_mo = NULL, language = get_AMR_locale(), minimum = 30,
+ combine_SI = TRUE, sep = " + ", simulations = 1000,
+ info = interactive())
+
+get_long_numeric_format(antibiogram)
\method{plot}{antibiogram}(x, ...)
\method{autoplot}{antibiogram}(object, ...)
-\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 antibiotic results (class 'sir', see \code{\link[=as.sir]{as.sir()}})}
+\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{antibiotics}{vector of any antibiotic name or code (will be evaluated with \code{\link[=as.ab]{as.ab()}}, column name of \code{x}, or (any combinations of) \link[=antimicrobial_class_selectors]{antimicrobial selectors} such as \code{\link[=aminoglycosides]{aminoglycosides()}} or \code{\link[=carbapenems]{carbapenems()}}. For combination antibiograms, this can also be set to values separated with \code{"+"}, such as "TZP+TOB" or "cipro + genta", given that columns resembling such antibiotics exist in \code{x}. See \emph{Examples}.}
+\item{antibiotics}{vector of any antimicrobial name or code (will be evaluated with \code{\link[=as.ab]{as.ab()}}, column name of \code{x}, or (any combinations of) \link[=antimicrobial_class_selectors]{antimicrobial selectors} such as \code{\link[=aminoglycosides]{aminoglycosides()}} or \code{\link[=carbapenems]{carbapenems()}}. For combination antibiograms, this can also be set to values separated with \code{"+"}, such as "TZP+TOB" or "cipro + genta", given that columns resembling such antimicrobials exist in \code{x}. See \emph{Examples}.}
\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: "mo", "fullname", "status", "kingdom", "phylum", "class", "order", "family", "genus", "species", "subspecies", "rank", "ref", "oxygen_tolerance", "source", "lpsn", "lpsn_parent", "lpsn_renamed_to", "mycobank", "mycobank_parent", "mycobank_renamed_to", "gbif", "gbif_parent", "gbif_renamed_to", "prevalence", or "snomed". Can also be \code{NULL} to not transform the input.}
-\item{ab_transform}{a character to transform antibiotic input - must be one of the column names of the \link{antibiotics} data set (defaults to \code{"name"}): "ab", "cid", "name", "group", "atc", "atc_group1", "atc_group2", "abbreviations", "synonyms", "oral_ddd", "oral_units", "iv_ddd", "iv_units", or "loinc". Can also be \code{NULL} to not transform the input.}
+\item{ab_transform}{a character to transform antimicrobial input - must be one of the column names of the \link{antibiotics} data set (defaults to \code{"name"}): "ab", "cid", "name", "group", "atc", "atc_group1", "atc_group2", "abbreviations", "synonyms", "oral_ddd", "oral_units", "iv_ddd", "iv_units", or "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_when]{case_when()}}. See \emph{Examples}.}
-\item{add_total_n}{a \link{logical} to indicate whether total available numbers per pathogen should be added to the table (default is \code{TRUE}). This will add the lowest and highest number of available isolate per antibiotic (e.g, if for \emph{E. coli} 200 isolates are available for ciprofloxacin and 150 for amoxicillin, the returned number will be "150-200").}
+\item{add_total_n}{a \link{logical} to indicate whether total 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").}
-\item{only_all_tested}{(for combination antibiograms): a \link{logical} to indicate that isolates must be tested for all antibiotics, see \emph{Details}}
+\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 susceptibility percentage}
-\item{formatting_type}{numeric value (1–12) indicating how the 'cells' of the antibiogram table should be formatted. See \emph{Details} > \emph{Formatting Type} for a list of options.}
+\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()}}.}
@@ -71,10 +71,20 @@ antibiogram(
\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 antibiotic columns in combination antibiograms}
+\item{sep}{a separating character for antimicrobial columns in combination antibiograms}
+
+\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 hierarchical model to estimate regimen coverage probabilities using Montecarlo simulations. Set \code{simulations} to adjust.}
+
+\item{simulations}{(for WISCA) a numerical value to set the number of Montecarlo simulations}
+
+\item{conf_interval}{(for WISCA) a numerical value to set confidence interval (default is \code{0.95})}
+
+\item{interval_side}{(for WISCA) 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{antibiogram}{the outcome of \code{\link[=antibiogram]{antibiogram()}} or \code{\link[=wisca]{wisca()}}}
+
\item{...}{when used in \link[knitr:kable]{R Markdown or Quarto}: arguments passed on to \code{\link[knitr:kable]{knitr::kable()}} (otherwise, has no use)}
\item{object}{an \code{\link[=antibiogram]{antibiogram()}} object}
@@ -84,15 +94,21 @@ antibiogram(
\item{na}{character to use for showing \code{NA} values}
}
\description{
-Create detailed antibiograms with options for traditional, combination, syndromic, and Bayesian WISCA methods. Based on the approaches of Klinker \emph{et al.}, Barbieri \emph{et al.}, and the Bayesian WISCA model (Weighted-Incidence Syndromic Combination Antibiogram) by Bielicki \emph{et al.}, this function provides flexible output formats including plots and tables, ideal for integration with R Markdown and Quarto reports.
+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 provides flexible output formats including plots and tables, ideal for integration with R Markdown and Quarto reports.
}
\details{
This function returns 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 in your data set with one of the four available algorithms.
+
+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.
+
+Using \code{\link[=get_long_numeric_format]{get_long_numeric_format()}}, the antibiogram is converted to a long format containing numeric values. 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} is the susceptibility percentage, \code{15} the numerator, and \code{300} the denominator:
+The formatting of the 'cells' of the table can be set with the argument \code{formatting_type}. In these examples, \code{5} is the susceptibility percentage (for WISCA: \code{4-6} indicates the confidence level), \code{15} the numerator, and \code{300} the denominator:
\enumerate{
\item 5
\item 15
@@ -103,21 +119,33 @@ The formatting of the 'cells' of the table can be set with the argument \code{fo
\item 5 (N=300)
\item 5\% (N=300)
\item 5 (15/300)
-\item 5\% (15/300)
+\item 5\% (15/300) - \strong{default for non-WISCA}
\item 5 (N=15/300)
\item 5\% (N=15/300)
+
+Additional options for WISCA (using \code{antibiogram(..., wisca = TRUE)} or \code{wisca()}):
+\item 5 (4-6)
+\item 5\% (4-6\%)
+\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 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 is \code{10}, which 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)}.
+The default is \code{18} for WISCA and \code{10} for non-WISCA, which 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)}.
-Set \code{digits} (defaults to \code{0}) to alter the rounding of the susceptibility percentage.
+Set \code{digits} (defaults to \code{0}) to alter the rounding of the susceptibility percentages.
}
\subsection{Antibiogram Types}{
-There are four antibiogram types, as summarised by Klinker \emph{et al.} (2021, \doi{10.1177/20499361211011373}), and they are all supported by \code{\link[=antibiogram]{antibiogram()}}. Use WISCA whenever possible, since it provides precise coverage estimates by accounting for pathogen incidence and antimicrobial susceptibility. See the section \emph{Why Use WISCA?} on this page.
+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()}}.
-The four antibiogram types:
+\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{Why Use WISCA?} on this page.
\enumerate{
\item \strong{Traditional Antibiogram}
@@ -149,29 +177,35 @@ Code example:
}\if{html}{\out{
}}
\item \strong{Weighted-Incidence Syndromic Combination Antibiogram (WISCA)}
-WISCA enhances empirical antibiotic selection by weighting the incidence of pathogens in specific clinical syndromes and combining them with their susceptibility data. It provides an estimation of regimen coverage by aggregating pathogen incidences and susceptibilities across potential causative organisms. See also the section \emph{Why Use WISCA?} on this page.
-
-Case example: Susceptibility of \emph{Pseudomonas aeruginosa} to TZP among respiratory specimens (obtained among ICU patients only) for male patients age >=65 years with heart failure
+WISCA can be applied to any antibiogram, see the section \emph{Why Use WISCA?} on this page for more information.
Code example:
-\if{html}{\out{
}}\preformatted{library(dplyr)
-your_data \%>\%
- filter(ward == "ICU" & specimen_type == "Respiratory") \%>\%
- antibiogram(antibiotics = c("TZP", "TZP+TOB", "TZP+GEN"),
- syndromic_group = ifelse(.$age >= 65 &
- .$gender == "Male" &
- .$condition == "Heart Disease",
- "Study Group", "Control Group"))
+\if{html}{\out{
}}\preformatted{antibiogram(your_data,
+ antibiotics = c("TZP", "TZP+TOB", "TZP+GEN"),
+ wisca = TRUE)
+
+# this is equal to:
+wisca(your_data,
+ antibiotics = c("TZP", "TZP+TOB", "TZP+GEN"))
}\if{html}{\out{
}}
WISCA uses a sophisticated Bayesian decision model to combine both local and pooled antimicrobial resistance data. This approach not only evaluates local patterns but can also draw on multi-centre datasets to improve regimen accuracy, even in low-incidence infections like paediatric bloodstream infections (BSIs).
}
+
+Grouped \link[tibble:tibble]{tibbles} can also be used to calculate susceptibilities over various groups.
+
+Code example:
+
+\if{html}{\out{
}}\preformatted{your_data \%>\%
+ group_by(has_sepsis, is_neonate, sex) \%>\%
+ wisca(antibiotics = c("TZP", "TZP+TOB", "TZP+GEN"))
+}\if{html}{\out{
}}
}
\subsection{Inclusion in Combination Antibiogram and Syndromic Antibiogram}{
-Note that for types 2 and 3 (Combination Antibiogram and Syndromic Antibiogram), it is important to realise that susceptibility can be calculated in two ways, which can be set with the \code{only_all_tested} argument (default is \code{FALSE}). See this example for two antibiotics, Drug A and Drug B, about how \code{\link[=antibiogram]{antibiogram()}} works to calculate the \%SI:
+Note that for types 2 and 3 (Combination Antibiogram and Syndromic Antibiogram), it is important to realise that susceptibility can be calculated in two ways, which can be set with the \code{only_all_tested} argument (default is \code{FALSE}). See this example for two antimicrobials, Drug A and Drug B, about how \code{\link[=antibiogram]{antibiogram()}} works to calculate the \%SI:
\if{html}{\out{
}}\preformatted{--------------------------------------------------------------------
only_all_tested = FALSE only_all_tested = TRUE
@@ -203,17 +237,53 @@ You can also use functions from specific 'table reporting' packages to transform
}
\section{Why Use WISCA?}{
-WISCA is a powerful tool for guiding empirical antibiotic therapy because it provides precise coverage estimates by accounting for pathogen incidence and antimicrobial susceptibility. This is particularly important in empirical treatment, where the causative pathogen is often unknown at the outset. Traditional antibiograms do not reflect the weighted likelihood of specific pathogens based on clinical syndromes, which can lead to suboptimal treatment choices.
+WISCA, as outlined by Barbieri \emph{et al.} (\doi{10.1186/s13756-021-00939-2}), stands for
+Weighted-Incidence Syndromic Combination Antibiogram, which estimates the probability
+of adequate empirical antimicrobial regimen coverage for specific infection syndromes.
+This method leverages a Bayesian hierarchical logistic regression framework with random
+effects for pathogens and regimens, enabling robust estimates in the presence of sparse
+data.
-The Bayesian WISCA, as described by Bielicki \emph{et al.} (2016), improves on earlier methods by handling uncertainties common in smaller datasets, such as low-incidence infections. This method offers a significant advantage by:
-\enumerate{
-\item Pooling Data from Multiple Sources:\cr WISCA uses pooled data from multiple hospitals or surveillance sources to overcome limitations of small sample sizes at individual institutions, allowing for more confident selection of narrow-spectrum antibiotics or combinations.
-\item Bayesian Framework:\cr The Bayesian decision tree model accounts for both local data and prior knowledge (such as inherent resistance patterns) to estimate regimen coverage. It allows for a more precise estimation of coverage, even in cases where susceptibility data is missing or incomplete.
-\item Incorporating Pathogen and Regimen Uncertainty:\cr WISCA allows clinicians to see the likelihood that an empirical regimen will be effective against all relevant pathogens, taking into account uncertainties related to both pathogen prevalence and antimicrobial resistance. This leads to better-informed, data-driven clinical decisions.
-\item Scenarios for Optimising Treatment:\cr For hospitals or settings with low-incidence infections, WISCA helps determine whether local data is sufficient or if pooling with external data is necessary. It also identifies statistically significant differences or similarities between antibiotic regimens, enabling clinicians to choose optimal therapies with greater confidence.
-}
+The Bayesian model assumes conjugate priors for parameter estimation. For example, the
+coverage probability \ifelse{latex}{\deqn{$theta$}}{$theta$} for a given antimicrobial regimen
+is modeled using a Beta distribution as a prior:
+
+\ifelse{latex}{\deqn{$theta$ \sim \text{Beta}($alpha$_0, $beta$_0)}}{
+\ifelse{html}{\figure{beta_prior.png}{options: width="300" alt="Beta prior"}}{$theta$ ~ Beta($alpha$_0, $beta$_0)}}
+
+where \eqn{$alpha$_0} and \eqn{$beta$_0} represent prior successes and failures, respectively,
+informed by expert knowledge or weakly informative priors (e.g., \eqn{$alpha$_0 = 1, $beta$_0 = 1}).
+
+The likelihood function is constructed based on observed data, where the number of covered
+cases for a regimen follows a binomial distribution:
-WISCA is essential in optimising empirical treatment by shifting away from broad-spectrum antibiotics, which are often overused in empirical settings. By offering precise estimates based on syndromic patterns and pooled data, WISCA supports antimicrobial stewardship by guiding more targeted therapy, reducing unnecessary broad-spectrum use, and combating the rise of antimicrobial resistance.
+\ifelse{latex}{\deqn{y \sim \text{Binomial}(n, $theta$)}}{
+\ifelse{html}{\figure{binomial_likelihood.png}{options: width="300" alt="Binomial likelihood"}}{y ~ Binomial(n, $theta$)}}
+
+Posterior parameter estimates are obtained by combining the prior and likelihood using
+Bayes' theorem. The posterior distribution of \eqn{$theta$} is also a Beta distribution:
+
+\ifelse{latex}{\deqn{$theta$ | y \sim \text{Beta}($alpha$_0 + y, $beta$_0 + n - y)}}{
+\ifelse{html}{\figure{posterior_beta.png}{options: width="300" alt="Beta posterior"}}{$theta$ | y ~ Beta($alpha$_0 + y, $beta$_0 + n - y)}}
+
+For hierarchical modeling, pathogen-level effects (e.g., differences in resistance
+patterns) and regimen-level effects are modelled using Gaussian priors on log-odds.
+This hierarchical structure ensures partial pooling of estimates across groups,
+improving stability in strata with small sample sizes. The model is implemented using
+Hamiltonian Monte Carlo (HMC) sampling.
+
+Stratified results are provided based on covariates such as age, sex, and clinical
+complexity (e.g., prior antimicrobial treatments or renal/urological comorbidities).
+For example, posterior odds ratios (ORs) are derived to quantify the effect of these
+covariates on coverage probabilities:
+
+\ifelse{latex}{\deqn{\text{OR}_{\text{covariate}} = \frac{\exp($beta$_{\text{covariate}})}{\exp($beta$_0)}}}{
+\ifelse{html}{\figure{odds_ratio.png}{options: width="300" alt="Odds ratio formula"}}{OR_covariate = exp(beta_covariate) / exp(beta_0)}}
+
+By combining empirical data with prior knowledge, WISCA overcomes the limitations
+of traditional combination antibiograms, offering disease-specific, patient-stratified
+estimates with robust uncertainty quantification. This tool is invaluable for antimicrobial
+stewardship programs and empirical treatment guideline refinement.
}
\examples{
@@ -281,17 +351,13 @@ antibiogram(ex1,
)
-# Weighted-incidence syndromic combination antibiogram (WISCA) ---------
+# WISCA antibiogram ----------------------------------------------------
-# the data set could contain a filter for e.g. respiratory specimens/ICU
+# can be used for any of the above types - just add `wisca = TRUE`
antibiogram(example_isolates,
- antibiotics = c("AMC", "AMC+CIP", "TZP", "TZP+TOB"),
+ antibiotics = c("TZP", "TZP+TOB", "TZP+GEN"),
mo_transform = "gramstain",
- minimum = 10, # this should be >=30, but now just as example
- syndromic_group = ifelse(example_isolates$age >= 65 &
- example_isolates$gender == "M",
- "WISCA Group 1", "WISCA Group 2"
- )
+ wisca = TRUE
)
diff --git a/man/antimicrobial_class_selectors.Rd b/man/antimicrobial_class_selectors.Rd
index 6bb978998..23709cbdb 100644
--- a/man/antimicrobial_class_selectors.Rd
+++ b/man/antimicrobial_class_selectors.Rd
@@ -38,28 +38,14 @@
\alias{not_intrinsic_resistant}
\title{Antimicrobial Selectors}
\usage{
-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,
- ...
-)
-
-aminoglycosides(
- 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, ...)
+
+aminoglycosides(only_sir_columns = FALSE, only_treatable = TRUE,
+ return_all = TRUE, ...)
aminopenicillins(only_sir_columns = FALSE, return_all = TRUE, ...)
@@ -67,21 +53,14 @@ 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, return_all = TRUE, ...)
@@ -99,12 +78,8 @@ fluoroquinolones(only_sir_columns = FALSE, return_all = TRUE, ...)
glycopeptides(only_sir_columns = FALSE, 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, ...)
@@ -118,12 +93,8 @@ penicillins(only_sir_columns = FALSE, return_all = TRUE, ...)
phenicols(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, return_all = TRUE, ...)
@@ -141,12 +112,8 @@ 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_expertrules = 3.3,
- ...
-)
+not_intrinsic_resistant(only_sir_columns = FALSE, col_mo = NULL,
+ version_expertrules = 3.3, ...)
}
\arguments{
\item{amr_class}{an antimicrobial class or a part of it, such as \code{"carba"} and \code{"carbapenems"}. The columns \code{group}, \code{atc_group1} and \code{atc_group2} of the \link{antibiotics} data set will be searched (case-insensitive) for this value.}
diff --git a/man/as.mo.Rd b/man/as.mo.Rd
index bfa5de0e0..a705d820f 100644
--- a/man/as.mo.Rd
+++ b/man/as.mo.Rd
@@ -11,20 +11,14 @@
\alias{mo_cleaning_regex}
\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)
diff --git a/man/as.sir.Rd b/man/as.sir.Rd
index 53c01fe53..72942576c 100644
--- a/man/as.sir.Rd
+++ b/man/as.sir.Rd
@@ -33,64 +33,35 @@ is.sir(x)
is_sir_eligible(x, threshold = 0.05)
-\method{as.sir}{default}(
- x,
- S = "^(S|U)+$",
- I = "^(I)+$",
- R = "^(R)+$",
- NI = "^(N|NI|V)+$",
- SDD = "^(SDD|D|H)+$",
- ...
-)
+\method{as.sir}{default}(x, S = "^(S|U)+$", I = "^(I)+$", R = "^(R)+$",
+ NI = "^(N|NI|V)+$", SDD = "^(SDD|D|H)+$", ...)
-\method{as.sir}{mic}(
- x,
- mo = NULL,
- ab = deparse(substitute(x)),
- guideline = getOption("AMR_guideline", "EUCAST"),
- uti = NULL,
- conserve_capped_values = FALSE,
- add_intrinsic_resistance = FALSE,
+\method{as.sir}{mic}(x, mo = NULL, ab = deparse(substitute(x)),
+ guideline = getOption("AMR_guideline", "EUCAST"), uti = NULL,
+ conserve_capped_values = FALSE, add_intrinsic_resistance = FALSE,
reference_data = AMR::clinical_breakpoints,
include_screening = getOption("AMR_include_screening", FALSE),
include_PKPD = getOption("AMR_include_PKPD", TRUE),
- breakpoint_type = getOption("AMR_breakpoint_type", "human"),
- host = NULL,
- verbose = FALSE,
- ...
-)
+ breakpoint_type = getOption("AMR_breakpoint_type", "human"), host = NULL,
+ verbose = FALSE, ...)
-\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,
add_intrinsic_resistance = FALSE,
reference_data = AMR::clinical_breakpoints,
include_screening = getOption("AMR_include_screening", FALSE),
include_PKPD = getOption("AMR_include_PKPD", TRUE),
- breakpoint_type = getOption("AMR_breakpoint_type", "human"),
- host = NULL,
- verbose = FALSE,
- ...
-)
+ breakpoint_type = getOption("AMR_breakpoint_type", "human"), host = NULL,
+ verbose = FALSE, ...)
-\method{as.sir}{data.frame}(
- x,
- ...,
- col_mo = NULL,
- guideline = getOption("AMR_guideline", "EUCAST"),
- uti = NULL,
- conserve_capped_values = FALSE,
- add_intrinsic_resistance = FALSE,
+\method{as.sir}{data.frame}(x, ..., col_mo = NULL,
+ guideline = getOption("AMR_guideline", "EUCAST"), uti = NULL,
+ conserve_capped_values = FALSE, add_intrinsic_resistance = FALSE,
reference_data = AMR::clinical_breakpoints,
include_screening = getOption("AMR_include_screening", FALSE),
include_PKPD = getOption("AMR_include_PKPD", TRUE),
- breakpoint_type = getOption("AMR_breakpoint_type", "human"),
- host = NULL,
- verbose = FALSE
-)
+ breakpoint_type = getOption("AMR_breakpoint_type", "human"), host = NULL,
+ verbose = FALSE)
sir_interpretation_history(clean = FALSE)
}
diff --git a/man/atc_online.Rd b/man/atc_online.Rd
index 0d34f971b..7336ca760 100644
--- a/man/atc_online.Rd
+++ b/man/atc_online.Rd
@@ -10,13 +10,9 @@
\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, ...)
diff --git a/man/av_from_text.Rd b/man/av_from_text.Rd
index e19d01f1b..e486f04aa 100644
--- a/man/av_from_text.Rd
+++ b/man/av_from_text.Rd
@@ -4,15 +4,9 @@
\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}
diff --git a/man/bug_drug_combinations.Rd b/man/bug_drug_combinations.Rd
index 3e7f8831f..3544563ed 100644
--- a/man/bug_drug_combinations.Rd
+++ b/man/bug_drug_combinations.Rd
@@ -5,20 +5,14 @@
\alias{format.bug_drug_combinations}
\title{Determine Bug-Drug Combinations}
\usage{
-bug_drug_combinations(x, col_mo = NULL, FUN = mo_shortname, ...)
+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 antibiotic columns, such as \code{amox}, \code{AMX} and \code{AMC}}
diff --git a/man/count.Rd b/man/count.Rd
index 93c8e4c68..a667da7ff 100644
--- a/man/count.Rd
+++ b/man/count.Rd
@@ -32,12 +32,8 @@ 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.}
diff --git a/man/eucast_rules.Rd b/man/eucast_rules.Rd
index 79305c4ce..3a9608764 100644
--- a/man/eucast_rules.Rd
+++ b/man/eucast_rules.Rd
@@ -19,19 +19,11 @@ Leclercq et al. \strong{EUCAST expert rules in antimicrobial susceptibility test
}
}
\usage{
-eucast_rules(
- x,
- col_mo = NULL,
- info = interactive(),
+eucast_rules(x, col_mo = NULL, info = interactive(),
rules = getOption("AMR_eucastrules", default = c("breakpoints", "expert")),
- verbose = FALSE,
- version_breakpoints = 12,
- version_expertrules = 3.3,
- ampc_cephalosporin_resistance = NA,
- only_sir_columns = FALSE,
- custom_rules = NULL,
- ...
-)
+ verbose = FALSE, version_breakpoints = 12, version_expertrules = 3.3,
+ ampc_cephalosporin_resistance = NA, only_sir_columns = FALSE,
+ custom_rules = NULL, ...)
eucast_dosage(ab, administration = "iv", version_breakpoints = 12)
}
diff --git a/man/export_ncbi_biosample.Rd b/man/export_ncbi_biosample.Rd
index 3da78df3c..c3977618c 100644
--- a/man/export_ncbi_biosample.Rd
+++ b/man/export_ncbi_biosample.Rd
@@ -4,13 +4,9 @@
\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}
diff --git a/man/first_isolate.Rd b/man/first_isolate.Rd
index 4ec269fb8..4876b7efc 100644
--- a/man/first_isolate.Rd
+++ b/man/first_isolate.Rd
@@ -12,38 +12,18 @@ Methodology of this function is strictly based on:
}
}
\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,
- ...
-)
-
-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"),
- ...
-)
+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"), ...)
}
\arguments{
\item{x}{a \link{data.frame} containing isolates. Can be left blank for automatic determination, see \emph{Examples}.}
@@ -93,6 +73,7 @@ A \link{logical} vector
Determine first isolates of all microorganisms of every patient per episode and (if needed) per specimen type. These functions support all four methods as summarised by Hindler \emph{et al.} in 2007 (\doi{10.1086/511864}). To determine patient episodes not necessarily based on microorganisms, use \code{\link[=is_new_episode]{is_new_episode()}} that also supports grouping with the \code{dplyr} package.
}
\details{
+The methodology implemented in these functions is based on the research overview by Hindler \emph{et al.} (2007, \doi{10.1086/511864}) and the recommendations outlined in the \href{https://clsi.org/standards/products/microbiology/documents/m39}{CLSI Guideline M39}.
To conduct epidemiological analyses on antimicrobial resistance data, only so-called first isolates should be included to prevent overestimation and underestimation of antimicrobial resistance. Different methods can be used to do so, see below.
These functions are context-aware. This means that the \code{x} argument can be left blank if used inside a \link{data.frame} call, see \emph{Examples}.
@@ -102,7 +83,7 @@ The \code{\link[=first_isolate]{first_isolate()}} function is a wrapper around t
All isolates with a microbial ID of \code{NA} will be excluded as first isolate.
\subsection{Different methods}{
-According to Hindler \emph{et al.} (2007, \doi{10.1086/511864}), there are different methods (algorithms) to select first isolates with increasing reliability: isolate-based, patient-based, episode-based and phenotype-based. All methods select on a combination of the taxonomic genus and species (not subspecies).
+According to previously-mentioned sources, there are different methods (algorithms) to select first isolates with increasing reliability: isolate-based, patient-based, episode-based and phenotype-based. All methods select on a combination of the taxonomic genus and species (not subspecies).
All mentioned methods are covered in the \code{\link[=first_isolate]{first_isolate()}} function:\tabular{ll}{
\strong{Method} \tab \strong{Function to apply} \cr
@@ -135,12 +116,12 @@ This method does not require any selection, as all isolates should be included.
\subsection{Patient-based}{
-To include every genus-species combination per patient once, set the \code{episode_days} to \code{Inf}. Although often inappropriate, this method makes sure that no duplicate isolates are selected from the same patient. In a large longitudinal data set, this could mean that isolates are \emph{excluded} that were found years after the initial isolate.
+To include every genus-species combination per patient once, set the \code{episode_days} to \code{Inf}. This method makes sure that no duplicate isolates are selected from the same patient. This method is preferred to e.g. identify the first MRSA finding of each patient to determine the incidence. Conversely, in a large longitudinal data set, this could mean that isolates are \emph{excluded} that were found years after the initial isolate.
}
\subsection{Episode-based}{
-To include every genus-species combination per patient episode once, set the \code{episode_days} to a sensible number of days. Depending on the type of analysis, this could be 14, 30, 60 or 365. Short episodes are common for analysing specific hospital or ward data, long episodes are common for analysing regional and national data.
+To include every genus-species combination per patient episode once, set the \code{episode_days} to a sensible number of days. Depending on the type of analysis, this could be 14, 30, 60 or 365. Short episodes are common for analysing specific hospital or ward data or ICU cases, long episodes are common for analysing regional and national data.
This is the most common method to correct for duplicate isolates. Patients are categorised into episodes based on their ID and dates (e.g., the date of specimen receipt or laboratory result). While this is a common method, it does not take into account antimicrobial test results. This means that e.g. a methicillin-resistant \emph{Staphylococcus aureus} (MRSA) isolate cannot be differentiated from a wildtype \emph{Staphylococcus aureus} isolate.
}
diff --git a/man/ggplot_pca.Rd b/man/ggplot_pca.Rd
index 1482b5d0e..bec3c36a6 100644
--- a/man/ggplot_pca.Rd
+++ b/man/ggplot_pca.Rd
@@ -17,30 +17,13 @@ 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()}}}
diff --git a/man/ggplot_sir.Rd b/man/ggplot_sir.Rd
index 058033dfc..5e62fabe9 100644
--- a/man/ggplot_sir.Rd
+++ b/man/ggplot_sir.Rd
@@ -5,42 +5,18 @@
\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", 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,
- ...
-)
+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", 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, ...)
}
\arguments{
\item{data}{a \link{data.frame} with column(s) of class \code{\link{sir}} (see \code{\link[=as.sir]{as.sir()}})}
diff --git a/man/guess_ab_col.Rd b/man/guess_ab_col.Rd
index d81709eca..03c50b9b1 100644
--- a/man/guess_ab_col.Rd
+++ b/man/guess_ab_col.Rd
@@ -4,12 +4,8 @@
\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}}
diff --git a/man/key_antimicrobials.Rd b/man/key_antimicrobials.Rd
index 40f1439dc..5bd2484bb 100644
--- a/man/key_antimicrobials.Rd
+++ b/man/key_antimicrobials.Rd
@@ -6,31 +6,19 @@
\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 = FALSE,
- ...
-)
+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 = FALSE, ...)
all_antimicrobials(x = NULL, only_sir_columns = FALSE, ...)
-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 antibiotics columns, like \code{AMX} or \code{amox}. Can be left blank to determine automatically}
diff --git a/man/mdro.Rd b/man/mdro.Rd
index 5e1126475..1cd635939 100644
--- a/man/mdro.Rd
+++ b/man/mdro.Rd
@@ -19,23 +19,10 @@
See the supported guidelines above for the \link{list} of publications used for this function.
}
\usage{
-mdro(
- x = NULL,
- guideline = "CMI2012",
- 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 = FALSE,
- ...
-)
+mdro(x = NULL, guideline = "CMI2012", 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 = FALSE, ...)
custom_mdro_guideline(..., as_factor = TRUE)
@@ -47,12 +34,8 @@ mdr_tb(x = NULL, only_sir_columns = FALSE, verbose = FALSE, ...)
mdr_cmi2012(x = NULL, only_sir_columns = FALSE, verbose = FALSE, ...)
-eucast_exceptional_phenotypes(
- x = NULL,
- only_sir_columns = FALSE,
- verbose = FALSE,
- ...
-)
+eucast_exceptional_phenotypes(x = NULL, only_sir_columns = FALSE,
+ verbose = FALSE, ...)
}
\arguments{
\item{x}{a \link{data.frame} with antibiotics columns, like \code{AMX} or \code{amox}. Can be left blank for automatic determination.}
diff --git a/man/mo_property.Rd b/man/mo_property.Rd
index 8bddd4c9b..c3905eebf 100644
--- a/man/mo_property.Rd
+++ b/man/mo_property.Rd
@@ -40,262 +40,115 @@
\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(),
- keep_synonyms = getOption("AMR_keep_synonyms", FALSE),
- ...
-)
-
-mo_is_gram_negative(
- 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_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_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(),
+ keep_synonyms = getOption("AMR_keep_synonyms", FALSE), ...)
+
+mo_is_gram_negative(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_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_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_property(
- x,
- property = "fullname",
- 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_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), ...)
}
\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}.}
diff --git a/man/mo_source.Rd b/man/mo_source.Rd
index 80687aa31..caec7b19f 100644
--- a/man/mo_source.Rd
+++ b/man/mo_source.Rd
@@ -6,10 +6,8 @@
\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"))
}
diff --git a/man/pca.Rd b/man/pca.Rd
index 9d463053e..a2ae6c1ef 100644
--- a/man/pca.Rd
+++ b/man/pca.Rd
@@ -4,15 +4,8 @@
\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}
diff --git a/man/plot.Rd b/man/plot.Rd
index 4e09485e6..55f2c90ff 100644
--- a/man/plot.Rd
+++ b/man/plot.Rd
@@ -22,128 +22,83 @@
\alias{labels_sir_count}
\title{Plotting Helpers for AMR Data Analysis}
\usage{
-scale_x_mic(keep_operators = "edges", mic_range = NULL, drop = FALSE, ...)
+scale_x_mic(keep_operators = "edges", mic_range = NULL, drop = FALSE,
+ ...)
-scale_y_mic(keep_operators = "edges", mic_range = NULL, drop = FALSE, ...)
+scale_y_mic(keep_operators = "edges", mic_range = NULL, drop = FALSE,
+ ...)
-scale_colour_mic(keep_operators = "edges", mic_range = NULL, drop = FALSE, ...)
+scale_colour_mic(keep_operators = "edges", mic_range = NULL,
+ drop = FALSE, ...)
-scale_fill_mic(keep_operators = "edges", mic_range = NULL, drop = FALSE, ...)
+scale_fill_mic(keep_operators = "edges", mic_range = NULL, drop = FALSE,
+ ...)
-\method{plot}{mic}(
- x,
- mo = NULL,
- ab = NULL,
- 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("#3CAEA3", "#F6D55C", "#ED553B"),
- language = get_AMR_locale(),
- expand = TRUE,
+\method{plot}{mic}(x, mo = NULL, ab = NULL, 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("#3CAEA3", "#F6D55C", "#ED553B"),
+ language = get_AMR_locale(), expand = TRUE,
include_PKPD = getOption("AMR_include_PKPD", TRUE),
- breakpoint_type = getOption("AMR_breakpoint_type", "human"),
- ...
-)
-
-\method{autoplot}{mic}(
- object,
- mo = NULL,
- ab = NULL,
- guideline = "EUCAST",
- title = deparse(substitute(object)),
+ breakpoint_type = getOption("AMR_breakpoint_type", "human"), ...)
+
+\method{autoplot}{mic}(object, mo = NULL, ab = NULL,
+ 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("#3CAEA3", "#F6D55C", "#ED553B"),
- language = get_AMR_locale(),
- expand = TRUE,
+ xlab = translate_AMR("Minimum Inhibitory Concentration (mg/L)", language =
+ language), colours_SIR = c("#3CAEA3", "#F6D55C", "#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{fortify}{mic}(object, ...)
-\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 = "EUCAST",
+ mo = NULL, ab = NULL, guideline = "EUCAST",
colours_SIR = c("#3CAEA3", "#F6D55C", "#ED553B"),
- language = get_AMR_locale(),
- expand = TRUE,
+ language = get_AMR_locale(), expand = TRUE,
include_PKPD = getOption("AMR_include_PKPD", TRUE),
- 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 = "EUCAST",
- colours_SIR = c("#3CAEA3", "#F6D55C", "#ED553B"),
- language = get_AMR_locale(),
- expand = TRUE,
+ 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 = "EUCAST", colours_SIR = c("#3CAEA3",
+ "#F6D55C", "#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{fortify}{disk}(object, ...)
-\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), 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("#3CAEA3", "#F6D55C", "#ED553B"),
- language = get_AMR_locale(),
- ...
-)
+ language = get_AMR_locale(), ...)
\method{fortify}{sir}(object, ...)
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 = "fill",
- colours_SIR = c("#3CAEA3", "#F6D55C", "#ED553B")
-)
+scale_sir_colours(..., aesthetics = "fill", colours_SIR = c("#3CAEA3",
+ "#F6D55C", "#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.}
diff --git a/man/proportion.Rd b/man/proportion.Rd
index b6894f996..9428cc7dd 100644
--- a/man/proportion.Rd
+++ b/man/proportion.Rd
@@ -18,50 +18,38 @@
\strong{M39 Analysis and Presentation of Cumulative Antimicrobial Susceptibility Test Data, 5th Edition}, 2022, \emph{Clinical and Laboratory Standards Institute (CLSI)}. \url{https://clsi.org/standards/products/microbiology/documents/m39/}.
}
\usage{
-resistance(..., minimum = 30, as_percent = FALSE, only_all_tested = FALSE)
-
-susceptibility(..., minimum = 30, as_percent = FALSE, only_all_tested = FALSE)
-
-sir_confidence_interval(
- ...,
- ab_result = "R",
- minimum = 30,
- as_percent = FALSE,
- only_all_tested = FALSE,
- confidence_level = 0.95,
- side = "both",
- collapse = FALSE
-)
+resistance(..., minimum = 30, as_percent = FALSE,
+ only_all_tested = FALSE)
-proportion_R(..., minimum = 30, as_percent = FALSE, only_all_tested = FALSE)
+susceptibility(..., minimum = 30, as_percent = FALSE,
+ only_all_tested = FALSE)
-proportion_IR(..., minimum = 30, as_percent = FALSE, only_all_tested = 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_I(..., minimum = 30, as_percent = FALSE, only_all_tested = FALSE)
+proportion_R(..., minimum = 30, as_percent = FALSE,
+ only_all_tested = FALSE)
-proportion_SI(..., minimum = 30, as_percent = FALSE, only_all_tested = FALSE)
+proportion_IR(..., minimum = 30, as_percent = FALSE,
+ only_all_tested = FALSE)
-proportion_S(..., minimum = 30, as_percent = FALSE, only_all_tested = FALSE)
+proportion_I(..., 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_SI(..., minimum = 30, as_percent = FALSE,
+ only_all_tested = FALSE)
-sir_df(
- data,
- translate_ab = "name",
- language = get_AMR_locale(),
- minimum = 30,
- as_percent = FALSE,
- combine_SI = TRUE,
- confidence_level = 0.95
-)
+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)
+
+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}.}
diff --git a/man/resistance_predict.Rd b/man/resistance_predict.Rd
index 1e574d326..e67a8afcc 100644
--- a/man/resistance_predict.Rd
+++ b/man/resistance_predict.Rd
@@ -8,51 +8,22 @@
\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}.}
diff --git a/man/top_n_microorganisms.Rd b/man/top_n_microorganisms.Rd
new file mode 100644
index 000000000..876ea2bff
--- /dev/null
+++ b/man/top_n_microorganisms.Rd
@@ -0,0 +1,44 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/top_n_microorganisms.R
+\name{top_n_microorganisms}
+\alias{top_n_microorganisms}
+\title{Filter Top \emph{n} Microorganisms}
+\usage{
+top_n_microorganisms(x, n, property = "fullname", n_for_each = NULL,
+ col_mo = NULL, ...)
+}
+\arguments{
+\item{x}{a data frame containing microbial data}
+
+\item{n}{an integer specifying the maximum number of unique values of the \code{property} to include in the output}
+
+\item{property}{a character string indicating the microorganism property to use for filtering. Must be one of the column names of the \link{microorganisms} data set: "mo", "fullname", "status", "kingdom", "phylum", "class", "order", "family", "genus", "species", "subspecies", "rank", "ref", "oxygen_tolerance", "source", "lpsn", "lpsn_parent", "lpsn_renamed_to", "mycobank", "mycobank_parent", "mycobank_renamed_to", "gbif", "gbif_parent", "gbif_renamed_to", "prevalence", or "snomed". If \code{NULL}, the raw values from \code{col_mo} will be used without transformation.}
+
+\item{n_for_each}{an optional integer specifying the maximum number of rows to retain for each value of the selected property. If \code{NULL}, all rows within the top \emph{n} groups will be included.}
+
+\item{col_mo}{A character string indicating the column in \code{x} that contains microorganism names or codes. Defaults to the first column of class \code{\link{mo}}. Values will be coerced using \code{\link[=as.mo]{as.mo()}}.}
+
+\item{...}{Additional arguments passed on to \code{\link[=mo_property]{mo_property()}} when \code{property} is not \code{NULL}.}
+}
+\description{
+This function filters a data set to include only the top \emph{n} microorganisms based on a specified property, such as taxonomic family or genus. For example, it can filter a data set to the top 3 species, or to any species in the top 5 genera, or to the top 3 species in each of the top 5 genera.
+}
+\details{
+This function is useful for preprocessing data before creating \link[=antibiograms]{antibiograms} or other analyses that require focused subsets of microbial data. For example, it can filter a data set to only include isolates from the top 10 species.
+}
+\examples{
+# filter to the top 3 species:
+top_n_microorganisms(example_isolates,
+ n = 3)
+
+# filter to any species in the top 5 genera:
+top_n_microorganisms(example_isolates,
+ n = 5, property = "genus")
+
+# filter to the top 3 species in each of the top 5 genera:
+top_n_microorganisms(example_isolates,
+ n = 5, property = "genus", n_for_each = 3)
+}
+\seealso{
+\code{\link[=mo_property]{mo_property()}}, \code{\link[=as.mo]{as.mo()}}, \code{\link[=antibiogram]{antibiogram()}}
+}