mirror of
https://github.com/msberends/AMR.git
synced 2025-09-30 12:09:04 +02:00
Compare commits
1 Commits
v3.0.1
...
sir-s3-upd
Author | SHA1 | Date | |
---|---|---|---|
d232666e49 |
@@ -40,4 +40,3 @@
|
||||
^CRAN-SUBMISSION$
|
||||
^PythonPackage$
|
||||
^README\.Rmd$
|
||||
\.no_include$
|
||||
|
10
.github/prehooks/pre-commit
vendored
10
.github/prehooks/pre-commit
vendored
@@ -48,6 +48,7 @@ echo "Running prehook..."
|
||||
if command -v Rscript > /dev/null; then
|
||||
if [ "$(Rscript -e 'cat(all(c('"'pkgload'"', '"'devtools'"', '"'dplyr'"') %in% rownames(installed.packages())))')" = "TRUE" ]; then
|
||||
Rscript -e "source('data-raw/_pre_commit_checks.R')"
|
||||
currentpkg=$(Rscript -e "cat(pkgload::pkg_name())")
|
||||
echo "- Adding changed files in ./data-raw and ./man to this commit"
|
||||
git add data-raw/*
|
||||
git add data/*
|
||||
@@ -56,9 +57,11 @@ if command -v Rscript > /dev/null; then
|
||||
git add NAMESPACE
|
||||
else
|
||||
echo "- R package 'pkgload', 'devtools', or 'dplyr' not installed!"
|
||||
currentpkg="your"
|
||||
fi
|
||||
else
|
||||
echo "- R is not available on your system!"
|
||||
currentpkg="your"
|
||||
fi
|
||||
echo ""
|
||||
|
||||
@@ -89,7 +92,7 @@ else
|
||||
|
||||
# Combine tag and commit number
|
||||
currentversion="$currenttag.$((currentcommit + 9001))"
|
||||
echo "- AMR pkg version set to ${currentversion}"
|
||||
echo "- ${currentpkg} pkg version set to ${currentversion}"
|
||||
|
||||
# Update version number and date in DESCRIPTION
|
||||
sed -i -- "s/^Version: .*/Version: ${currentversion}/" DESCRIPTION
|
||||
@@ -100,7 +103,10 @@ else
|
||||
|
||||
# Update version number in NEWS.md
|
||||
if [ -e "NEWS.md" ]; then
|
||||
sed -i -- "1s/.*/# AMR ${currentversion}/" NEWS.md
|
||||
if [ "$currentpkg" = "your" ]; then
|
||||
currentpkg=""
|
||||
fi
|
||||
sed -i -- "1s/.*/# ${currentpkg} ${currentversion}/" NEWS.md
|
||||
echo "- Updated version number in ./NEWS.md"
|
||||
rm -f NEWS.md--
|
||||
git add NEWS.md
|
||||
|
19
.github/workflows/check-old-tinytest.yaml
vendored
19
.github/workflows/check-old-tinytest.yaml
vendored
@@ -50,11 +50,11 @@ jobs:
|
||||
# For these old versions, dependencies and vignettes will not be checked.
|
||||
# For recent R versions, see check-recent.yaml (r-lib and tidyverse support the latest 5 major R releases).
|
||||
- {os: ubuntu-latest, r: '3.6', allowfail: false}
|
||||
# - {os: windows-latest, r: '3.5', allowfail: false} # always fails, horrible with UTF-8
|
||||
# - {os: ubuntu-latest, r: '3.4', allowfail: false} # 3.1-3.4 now always fails with Error in grep(warn_re, lines, invert = TRUE, value = TRUE) attempt to set index 46/46 in SET_STRING_ELT
|
||||
# - {os: ubuntu-latest, r: '3.3', allowfail: false}
|
||||
# - {os: ubuntu-latest, r: '3.2', allowfail: false}
|
||||
# - {os: ubuntu-latest, r: '3.1', allowfail: false}
|
||||
# - {os: windows-latest, r: '3.5', allowfail: true} # always fails, horrible with UTF-8
|
||||
- {os: ubuntu-latest, r: '3.4', allowfail: false}
|
||||
- {os: ubuntu-latest, r: '3.3', allowfail: false}
|
||||
- {os: ubuntu-latest, r: '3.2', allowfail: false}
|
||||
- {os: ubuntu-latest, r: '3.1', allowfail: false}
|
||||
- {os: ubuntu-latest, r: '3.0', allowfail: false}
|
||||
|
||||
env:
|
||||
@@ -76,14 +76,9 @@ jobs:
|
||||
|
||||
- uses: r-lib/actions/setup-pandoc@v2
|
||||
|
||||
- name: Install suggested pkgs (and tinytest) from CRAN
|
||||
- name: Install tinytest from CRAN
|
||||
run: |
|
||||
desc_lines <- readLines('DESCRIPTION')
|
||||
suggests <- readLines('DESCRIPTION')[grepl("^(Suggests:| )", readLines('DESCRIPTION'))]
|
||||
suggests <- suggests[(which(grepl("^Suggests", suggests)) + 1):length(suggests)]
|
||||
suggests <- gsub("[ ,]", "", suggests)
|
||||
pkgs <- unique(c(suggests, "tinytest"))
|
||||
for (p in pkgs) try(install.packages(p, repos = "https://cran.r-project.org"), silent = TRUE)
|
||||
install.packages("tinytest", repos = "https://cran.r-project.org")
|
||||
shell: Rscript {0}
|
||||
|
||||
- name: Show session info
|
||||
|
@@ -18,7 +18,7 @@
|
||||
# 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. #
|
||||
# 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. #
|
||||
@@ -28,37 +28,18 @@
|
||||
# ==================================================================== #
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
# run in each PR in this repo
|
||||
branches: '**'
|
||||
push:
|
||||
branches: '**'
|
||||
schedule:
|
||||
# also run a schedule everyday at 1 AM.
|
||||
# this is to check that all dependencies are still available (see R/zzz.R)
|
||||
- cron: '0 1 * * *'
|
||||
pull_request:
|
||||
branches: '**'
|
||||
|
||||
name: check-recent-dev-pkgs
|
||||
name: lintr
|
||||
|
||||
jobs:
|
||||
R-code-check:
|
||||
runs-on: ${{ matrix.config.os }}
|
||||
|
||||
continue-on-error: ${{ matrix.config.allowfail }}
|
||||
|
||||
name: ${{ matrix.config.os }} (dev-pkgs)
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
config:
|
||||
# current 'release' version on Ubuntu
|
||||
- {os: ubuntu-latest, r: 'release', allowfail: false}
|
||||
|
||||
lintr:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
|
||||
R_KEEP_PKG_SOURCE: yes
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
@@ -66,21 +47,39 @@ jobs:
|
||||
|
||||
- uses: r-lib/actions/setup-r@v2
|
||||
with:
|
||||
r-version: ${{ matrix.config.r }}
|
||||
use-public-rspm: false
|
||||
extra-repositories: >
|
||||
https://tidyverse.r-universe.dev
|
||||
https://r-lib.r-universe.dev
|
||||
https://tidymodels.r-universe.dev
|
||||
https://yihui.r-universe.dev
|
||||
r-version: release
|
||||
# use RStudio Package Manager to quickly install packages
|
||||
use-public-rspm: true
|
||||
|
||||
- uses: r-lib/actions/setup-r-dependencies@v2
|
||||
with:
|
||||
extra-packages: any::rcmdcheck
|
||||
needs: check
|
||||
upgrade: 'TRUE'
|
||||
|
||||
- uses: r-lib/actions/check-r-package@v2
|
||||
with:
|
||||
upload-snapshots: true
|
||||
build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")'
|
||||
extra-packages: |
|
||||
any::lintr
|
||||
any::cyclocomp
|
||||
any::roxygen2
|
||||
any::devtools
|
||||
any::usethis
|
||||
|
||||
- name: Remove unneeded folders
|
||||
run: |
|
||||
# do not check these folders
|
||||
rm -rf data-raw
|
||||
rm -rf tests
|
||||
rm -rf vignettes
|
||||
|
||||
- name: Lint
|
||||
run: |
|
||||
# get ALL linters, not just default ones
|
||||
linters <- getNamespaceExports(asNamespace("lintr"))
|
||||
linters <- sort(linters[grepl("_linter$", linters)])
|
||||
# lose deprecated
|
||||
linters <- linters[!grepl("^(closed_curly|open_curly|paren_brace|semicolon_terminator|consecutive_stopifnot|no_tab|single_quotes|unnecessary_nested_if|unneeded_concatenation)_linter$", linters)]
|
||||
linters <- linters[linters != "linter"]
|
||||
# and the ones we find unnnecessary
|
||||
linters <- linters[!grepl("^(commented_code|extraction_operator|implicit_integer|indentation|line_length|namespace|nonportable_path|object_length|object_name|object_usage|is)_linter$", linters)]
|
||||
# put the functions in a list
|
||||
linters_list <- lapply(linters, function(l) eval(parse(text = paste0("lintr::", l, "()")), envir = asNamespace("lintr")))
|
||||
names(linters_list) <- linters
|
||||
# run them all!
|
||||
lintr::lint_package(linters = linters_list, exclusions = list("R/aa_helper_pm_functions.R"))
|
||||
shell: Rscript {0}
|
7
.github/workflows/publish-to-pypi.yml
vendored
7
.github/workflows/publish-to-pypi.yml
vendored
@@ -39,7 +39,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
env:
|
||||
GH_REPO_SCOPE: ${{ secrets.GH_REPO_SCOPE }}
|
||||
PYPI_PAT: ${{ secrets.PYPI_PAT }}
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
@@ -78,7 +78,6 @@ jobs:
|
||||
cd PythonPackage/AMR
|
||||
python -m twine upload --repository-url https://test.pypi.org/legacy/ dist/*
|
||||
|
||||
# TODO - Support Miniconda and Anaconda too
|
||||
# - name: Set up Miniconda
|
||||
# continue-on-error: true
|
||||
# uses: conda-incubator/setup-miniconda@v2
|
||||
@@ -118,7 +117,7 @@ jobs:
|
||||
rm -rf PythonPackage
|
||||
|
||||
git init
|
||||
git remote add origin https://$GH_REPO_SCOPE@github.com/msberends/AMR
|
||||
git remote add origin https://$PYPI_PAT@github.com/msberends/AMR
|
||||
git checkout --orphan python-wrapper
|
||||
git config user.name "github-actions[bot]"
|
||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||
@@ -126,4 +125,4 @@ jobs:
|
||||
git rm -rf . || true
|
||||
git add .
|
||||
git commit -m "Python wrapper update"
|
||||
git push https://$GH_REPO_SCOPE@github.com/msberends/AMR.git python-wrapper --force
|
||||
git push https://$PYPI_PAT@github.com/msberends/AMR.git python-wrapper --force
|
||||
|
@@ -39,7 +39,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
env:
|
||||
GH_REPO_SCOPE: ${{ secrets.GH_REPO_SCOPE }}
|
||||
PYPI_PAT: ${{ secrets.PYPI_PAT }}
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
@@ -63,4 +63,4 @@ jobs:
|
||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||
git add latest_training_data.txt
|
||||
git commit -m "GPT training data update"
|
||||
git push https://$GH_REPO_SCOPE@github.com/msberends/amr-for-r-assistant.git main --force
|
||||
git push https://$PYPI_PAT@github.com/msberends/amr-for-r-assistant.git main --force
|
||||
|
80
.github/workflows/todo-tracker.yml
vendored
80
.github/workflows/todo-tracker.yml
vendored
@@ -1,80 +0,0 @@
|
||||
# ==================================================================== #
|
||||
# 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://amr-for-r.org #
|
||||
# ==================================================================== #
|
||||
|
||||
on:
|
||||
push:
|
||||
# only on main
|
||||
branches: "main"
|
||||
|
||||
name: Update TODO Tracker
|
||||
|
||||
jobs:
|
||||
update-todo:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Generate TODO list from R/
|
||||
run: |
|
||||
echo "## \`TODO\` Report" > todo.md
|
||||
echo "" >> todo.md
|
||||
echo "_This overview is automatically updated on each push to \`main\`. It provides an automated overview of all mentions of the text \`TODO\`._" >> todo.md
|
||||
echo "" >> todo.md
|
||||
todos=$(grep -rn --include=\*.{R,Rmd,yaml,yml,md,css,js} --exclude={todo-tracker.yml,todo.md} "TODO" . || true)
|
||||
if [ -z "$todos" ]; then
|
||||
echo "✅ No TODOs found." >> todo.md
|
||||
else
|
||||
echo "$todos" | awk -F: -v repo="https://github.com/msberends/AMR/blob/main/" '
|
||||
{
|
||||
file = $1
|
||||
gsub("^\\./", "", file) # remove leading ./ if present
|
||||
line = $2
|
||||
text = substr($0, index($0,$3))
|
||||
if (file != last_file) {
|
||||
if (last_file != "") print "```"
|
||||
print ""
|
||||
print "### [`" file "`](" repo file ")"
|
||||
print "```r"
|
||||
last_file = file
|
||||
}
|
||||
printf "L%s: %s\n", line, text
|
||||
}
|
||||
' >> todo.md
|
||||
echo "\`\`\`" >> todo.md
|
||||
fi
|
||||
|
||||
- name: Update GitHub issue
|
||||
uses: peter-evans/create-or-update-comment@v4
|
||||
with:
|
||||
token: ${{ secrets.GH_REPO_SCOPE }}
|
||||
issue-number: 231
|
||||
comment-id: 3253439219
|
||||
body-file: todo.md
|
||||
edit-mode: replace
|
9
.github/workflows/website.yaml
vendored
9
.github/workflows/website.yaml
vendored
@@ -42,15 +42,16 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
||||
- name: checkout
|
||||
uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
# this is to keep timestamps, the default fetch-depth: 1 gets the timestamps of the moment of cloning
|
||||
# we need this for the download page on our website - dates must be of the files, not of the latest git push
|
||||
fetch-depth: 0
|
||||
|
||||
- name: restore timestamps
|
||||
uses: chetan/git-restore-mtime-action@v2
|
||||
- name: Preserve timestamps
|
||||
run: |
|
||||
sudo apt install git-restore-mtime
|
||||
git restore-mtime
|
||||
|
||||
- uses: r-lib/actions/setup-pandoc@v2
|
||||
|
||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,6 +1,5 @@
|
||||
Meta
|
||||
doc
|
||||
docs
|
||||
.Renviron
|
||||
.Rproj.user
|
||||
.Rhistory
|
||||
|
@@ -1,3 +1,3 @@
|
||||
Version: 3.0.1
|
||||
Date: 2025-09-20 10:56:46 UTC
|
||||
SHA: 33fb1849eb5aa6d33828e643c8f5047dd93447e3
|
||||
Version: 3.0.0
|
||||
Date: 2025-06-01 16:52:53 UTC
|
||||
SHA: 79038fed2169a25a7fc067c80bb25d9d78be21d9
|
||||
|
@@ -1,6 +1,6 @@
|
||||
Package: AMR
|
||||
Version: 3.0.1
|
||||
Date: 2025-09-20
|
||||
Version: 3.0.0.9017
|
||||
Date: 2025-07-28
|
||||
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
|
||||
@@ -70,5 +70,5 @@ BugReports: https://github.com/msberends/AMR/issues
|
||||
License: GPL-2 | file LICENSE
|
||||
Encoding: UTF-8
|
||||
LazyData: true
|
||||
RoxygenNote: 7.3.3
|
||||
RoxygenNote: 7.3.2
|
||||
Roxygen: list(markdown = TRUE, old_usage = TRUE)
|
||||
|
20
NAMESPACE
20
NAMESPACE
@@ -12,6 +12,7 @@ S3method("[",deprecated_amr_dataset)
|
||||
S3method("[",disk)
|
||||
S3method("[",mic)
|
||||
S3method("[",mo)
|
||||
S3method("[",sir)
|
||||
S3method("[<-",ab)
|
||||
S3method("[<-",av)
|
||||
S3method("[<-",disk)
|
||||
@@ -24,6 +25,7 @@ S3method("[[",deprecated_amr_dataset)
|
||||
S3method("[[",disk)
|
||||
S3method("[[",mic)
|
||||
S3method("[[",mo)
|
||||
S3method("[[",sir)
|
||||
S3method("[[<-",ab)
|
||||
S3method("[[<-",av)
|
||||
S3method("[[<-",disk)
|
||||
@@ -99,6 +101,7 @@ S3method(print,custom_eucast_rules)
|
||||
S3method(print,custom_mdro_guideline)
|
||||
S3method(print,deprecated_amr_dataset)
|
||||
S3method(print,disk)
|
||||
S3method(print,interpreted_sir)
|
||||
S3method(print,mic)
|
||||
S3method(print,mo)
|
||||
S3method(print,mo_renamed)
|
||||
@@ -106,6 +109,8 @@ S3method(print,mo_uncertainties)
|
||||
S3method(print,pca)
|
||||
S3method(print,sir)
|
||||
S3method(print,sir_log)
|
||||
S3method(print,step_mic_log2)
|
||||
S3method(print,step_sir_numeric)
|
||||
S3method(quantile,mic)
|
||||
S3method(rep,ab)
|
||||
S3method(rep,av)
|
||||
@@ -159,6 +164,10 @@ export(administrable_per_os)
|
||||
export(age)
|
||||
export(age_groups)
|
||||
export(all_antimicrobials)
|
||||
export(all_mic)
|
||||
export(all_mic_predictors)
|
||||
export(all_sir)
|
||||
export(all_sir_predictors)
|
||||
export(aminoglycosides)
|
||||
export(aminopenicillins)
|
||||
export(amr_class)
|
||||
@@ -352,6 +361,8 @@ export(sir_df)
|
||||
export(sir_interpretation_history)
|
||||
export(sir_predict)
|
||||
export(skewness)
|
||||
export(step_mic_log2)
|
||||
export(step_sir_numeric)
|
||||
export(streptogramins)
|
||||
export(sulfonamides)
|
||||
export(susceptibility)
|
||||
@@ -373,8 +384,6 @@ if(getRversion() >= "3.0.0") S3method(ggplot2::fortify, disk)
|
||||
if(getRversion() >= "3.0.0") S3method(ggplot2::fortify, mic)
|
||||
if(getRversion() >= "3.0.0") S3method(ggplot2::fortify, resistance_predict)
|
||||
if(getRversion() >= "3.0.0") S3method(ggplot2::fortify, sir)
|
||||
if(getRversion() >= "3.0.0") S3method(ggplot2::scale_type, mic)
|
||||
if(getRversion() >= "3.0.0") S3method(ggplot2::scale_type, sir)
|
||||
if(getRversion() >= "3.0.0") S3method(knitr::knit_print, antibiogram)
|
||||
if(getRversion() >= "3.0.0") S3method(knitr::knit_print, formatted_bug_drug_combinations)
|
||||
if(getRversion() >= "3.0.0") S3method(pillar::pillar_shaft, ab)
|
||||
@@ -390,7 +399,12 @@ if(getRversion() >= "3.0.0") S3method(pillar::type_sum, av)
|
||||
if(getRversion() >= "3.0.0") S3method(pillar::type_sum, mic)
|
||||
if(getRversion() >= "3.0.0") S3method(pillar::type_sum, mo)
|
||||
if(getRversion() >= "3.0.0") S3method(pillar::type_sum, sir)
|
||||
if(getRversion() >= "3.0.0") S3method(skimr::get_skimmers, ab)
|
||||
if(getRversion() >= "3.0.0") S3method(recipes::bake, step_mic_log2)
|
||||
if(getRversion() >= "3.0.0") S3method(recipes::bake, step_sir_numeric)
|
||||
if(getRversion() >= "3.0.0") S3method(recipes::prep, step_mic_log2)
|
||||
if(getRversion() >= "3.0.0") S3method(recipes::prep, step_sir_numeric)
|
||||
if(getRversion() >= "3.0.0") S3method(recipes::tidy, step_mic_log2)
|
||||
if(getRversion() >= "3.0.0") S3method(recipes::tidy, step_sir_numeric)
|
||||
if(getRversion() >= "3.0.0") S3method(skimr::get_skimmers, disk)
|
||||
if(getRversion() >= "3.0.0") S3method(skimr::get_skimmers, mic)
|
||||
if(getRversion() >= "3.0.0") S3method(skimr::get_skimmers, mo)
|
||||
|
21
NEWS.md
21
NEWS.md
@@ -1,11 +1,13 @@
|
||||
# AMR 3.0.1
|
||||
# AMR 3.0.0.9017
|
||||
|
||||
This is a bugfix release following the release of v3.0.0 in June 2025.
|
||||
This is primarily a bugfix release, though we added one nice feature too.
|
||||
|
||||
### New
|
||||
* Integration with the **tidymodels** framework to allow seamless use of MIC and SIR data in modelling pipelines via `recipes`
|
||||
- `step_mic_log2()` to transform `<mic>` columns with log2, and `step_sir_numeric()` to convert `<sir>` columns to numeric
|
||||
- New `tidyselect` helpers: `all_mic()`, `all_mic_predictors()`, `all_sir()`, `all_sir_predictors()`
|
||||
|
||||
### Changed
|
||||
* Fixed bugs introduced by `ggplot2` v4.0.0 (#236)
|
||||
* MIC scale functions (such as `scale_y_mic()`) will now be applied automatically when plotting values of class `mic`
|
||||
* SIR scale functions (such as `scale_x_sir()`) will now be applied automatically when plotting values of class `sir`
|
||||
* Fixed a bug in `antibiogram()` for when no antimicrobials are set
|
||||
* Fixed a bug in `antibiogram()` to allow column names containing the `+` character (#222)
|
||||
* Fixed a bug in `as.ab()` for antimicrobial codes with a number in it if they are preceded by a space
|
||||
@@ -13,19 +15,10 @@ This is a bugfix release following the release of v3.0.0 in June 2025.
|
||||
* Fixed a bug in `as.sir()` to allow any tidyselect language (#220)
|
||||
* Fixed a bug in `as.sir()` to pick right breakpoint when `uti = FALSE` (#216)
|
||||
* Fixed a bug in `ggplot_sir()` when using `combine_SI = FALSE` (#213)
|
||||
* Fixed a bug in `mdro()` to make sure all genes specified in arguments are acknowledged
|
||||
* Fixed a bug the `antimicrobials` data set to remove statins (#229)
|
||||
* Fixed a bug the `microorganisms` data set for MycoBank IDs and synonyms (#233)
|
||||
* Fixed ATC J01CR05 to map to piperacillin/tazobactam rather than piperacillin/sulbactam (#230)
|
||||
* Fixed skimmers (`skimr` package) of class `ab`, `sir`, and `disk` (#234)
|
||||
* Fixed all plotting to contain a separate colour for SDD (susceptible dose-dependent) (#223)
|
||||
* Fixed some specific Dutch translations for antimicrobials
|
||||
* Added a warning to `as.ab()` if input resembles antiviral codes or names (#232)
|
||||
* Added all reasons in verbose output of `mdro()` (#227)
|
||||
* Added `names` to `age_groups()` so that custom names can be given (#215)
|
||||
* Added note to `as.sir()` to make it explicit when higher-level taxonomic breakpoints are used (#218)
|
||||
* Added antibiotic codes from the Comprehensive Antibiotic Resistance Database (CARD) to the `antimicrobials` data set (#225)
|
||||
* Updated Fosfomycin to be of antibiotic class Phosphonics (#225)
|
||||
* Updated `random_mic()` and `random_disk()` to set skewedness of the distribution and allow multiple microorganisms
|
||||
|
||||
|
||||
|
@@ -233,7 +233,6 @@ globalVariables(c(
|
||||
"uti_index",
|
||||
"value",
|
||||
"varname",
|
||||
"where",
|
||||
"x",
|
||||
"xvar",
|
||||
"y",
|
||||
|
@@ -485,7 +485,11 @@ word_wrap <- function(...,
|
||||
}
|
||||
|
||||
# format backticks
|
||||
if (pkg_is_available("cli") && in_rstudio() &&
|
||||
if (pkg_is_available("cli") &&
|
||||
tryCatch(isTRUE(getExportedValue("ansi_has_hyperlink_support", ns = asNamespace("cli"))()), error = function(e) FALSE) &&
|
||||
tryCatch(getExportedValue("isAvailable", ns = asNamespace("rstudioapi"))(), error = function(e) {
|
||||
return(FALSE)
|
||||
}) &&
|
||||
tryCatch(getExportedValue("versionInfo", ns = asNamespace("rstudioapi"))()$version > "2023.6.0.0", error = function(e) {
|
||||
return(FALSE)
|
||||
})) {
|
||||
@@ -1184,13 +1188,6 @@ reset_all_thrown_messages <- function() {
|
||||
)
|
||||
}
|
||||
|
||||
in_rstudio <- function() {
|
||||
identical(Sys.getenv("RSTUDIO"), "1")
|
||||
}
|
||||
in_positron <- function() {
|
||||
identical(Sys.getenv("POSITRON"), "1")
|
||||
}
|
||||
|
||||
has_colour <- function() {
|
||||
if (is.null(AMR_env$supports_colour)) {
|
||||
if (Sys.getenv("EMACS") != "" || Sys.getenv("INSIDE_EMACS") != "") {
|
||||
@@ -1225,7 +1222,7 @@ is_dark <- function() {
|
||||
AMR_env$current_theme <- tryCatch(getExportedValue("getThemeInfo", ns = asNamespace("rstudioapi"))()$editor, error = function(e) NULL)
|
||||
if (!identical(AMR_env$current_theme, AMR_env$former_theme) || is.null(AMR_env$is_dark_theme)) {
|
||||
AMR_env$former_theme <- AMR_env$current_theme
|
||||
AMR_env$is_dark_theme <- !has_colour() || tryCatch(isTRUE(getExportedValue("getThemeInfo", ns = asNamespace("rstudioapi"))()$dark), error = function(e) TRUE)
|
||||
AMR_env$is_dark_theme <- !has_colour() || tryCatch(isTRUE(getExportedValue("getThemeInfo", ns = asNamespace("rstudioapi"))()$dark), error = function(e) FALSE)
|
||||
}
|
||||
isTRUE(AMR_env$is_dark_theme)
|
||||
}
|
||||
|
21
R/ab.R
21
R/ab.R
@@ -202,9 +202,6 @@ as.ab <- function(x, flag_multiple_results = TRUE, language = get_AMR_locale(),
|
||||
if (sum(already_known) < length(x)) {
|
||||
progress <- progress_ticker(n = sum(!already_known), n_min = 25, print = info) # start if n >= 25
|
||||
on.exit(close(progress))
|
||||
if (any(x_new[!already_known & !is.na(x_new)] %in% unlist(AMR_env$AV_lookup$generalised_all, use.names = FALSE), na.rm = TRUE)) {
|
||||
warning_("in `as.ab()`: some input seems to resemble antiviral drugs - use `as.av()` or e.g. `av_name()` for these, not `as.ab()` or e.g. `ab_name()`.")
|
||||
}
|
||||
}
|
||||
|
||||
for (i in which(!already_known)) {
|
||||
@@ -451,7 +448,7 @@ as.ab <- function(x, flag_multiple_results = TRUE, language = get_AMR_locale(),
|
||||
x_unknown <- x_unknown[!x_unknown %in% c("", NA)]
|
||||
if (length(x_unknown) > 0 && fast_mode == FALSE) {
|
||||
warning_(
|
||||
"in `as.ab()`: ", ifelse(length(unique(x_unknown)) == 1, "this value", "these values"), " could not be coerced to a valid antimicrobial ID: ",
|
||||
"in `as.ab()`: these values could not be coerced to a valid antimicrobial ID: ",
|
||||
vector_and(x_unknown), "."
|
||||
)
|
||||
}
|
||||
@@ -514,7 +511,7 @@ pillar_shaft.ab <- function(x, ...) {
|
||||
out[is.na(x)] <- font_na(NA)
|
||||
|
||||
# add the names to the drugs as mouse-over!
|
||||
if (in_rstudio()) {
|
||||
if (tryCatch(isTRUE(getExportedValue("ansi_has_hyperlink_support", ns = asNamespace("cli"))()), error = function(e) FALSE)) {
|
||||
out[!is.na(x)] <- font_url(
|
||||
url = paste0(x[!is.na(x)], ": ", ab_name(x[!is.na(x)])),
|
||||
txt = out[!is.na(x)]
|
||||
@@ -630,20 +627,6 @@ rep.ab <- function(x, ...) {
|
||||
out
|
||||
}
|
||||
|
||||
# this prevents the requirement for putting the dependency in Imports:
|
||||
#' @rawNamespace if(getRversion() >= "3.0.0") S3method(skimr::get_skimmers, ab)
|
||||
get_skimmers.ab <- function(column) {
|
||||
ab <- as.ab(column, info = FALSE)
|
||||
ab <- ab[!is.na(ab)]
|
||||
skimr::sfl(
|
||||
skim_type = "ab",
|
||||
n_unique = ~ length(unique(ab)),
|
||||
top_ab = ~ names(sort(-table(ab)))[1L],
|
||||
top_ab_name = ~ names(sort(-table(ab_name(ab, info = FALSE))))[1L],
|
||||
top_group = ~ names(sort(-table(ab_group(ab, info = FALSE))))[1L]
|
||||
)
|
||||
}
|
||||
|
||||
generalise_antibiotic_name <- function(x) {
|
||||
x <- toupper(x)
|
||||
# remove suffices
|
||||
|
22
R/data.R
22
R/data.R
@@ -362,14 +362,14 @@
|
||||
#' dosage
|
||||
"dosage"
|
||||
|
||||
# TODO #' Data Set with `r format(nrow(esbl_isolates), big.mark = " ")` ESBL Isolates
|
||||
# TODO #'
|
||||
# TODO #' A data set containing `r format(nrow(esbl_isolates), big.mark = " ")` microbial isolates with MIC values of common antibiotics and a binary `esbl` column for extended-spectrum beta-lactamase (ESBL) production. This data set contains randomised fictitious data but reflects reality and can be used to practise AMR-related machine learning, e.g., classification modelling with [tidymodels](https://amr-for-r.org/articles/AMR_with_tidymodels.html).
|
||||
# TODO #' @format A [tibble][tibble::tibble] with `r format(nrow(esbl_isolates), big.mark = " ")` observations and `r ncol(esbl_isolates)` variables:
|
||||
# TODO #' - `esbl`\cr Logical indicator if the isolate is ESBL-producing
|
||||
# TODO #' - `genus`\cr Genus of the microorganism
|
||||
# TODO #' - `AMC:COL`\cr MIC values for 17 antimicrobial agents, transformed to class [`mic`] (see [as.mic()])
|
||||
# TODO #' @details See our [tidymodels integration][amr-tidymodels] for an example using this data set.
|
||||
# TODO #' @examples
|
||||
# TODO #' esbl_isolates
|
||||
# TODO "esbl_isolates"
|
||||
#' Data Set with `r format(nrow(esbl_isolates), big.mark = " ")` ESBL Isolates
|
||||
#'
|
||||
#' A data set containing `r format(nrow(esbl_isolates), big.mark = " ")` microbial isolates with MIC values of common antibiotics and a binary `esbl` column for extended-spectrum beta-lactamase (ESBL) production. This data set contains randomised fictitious data but reflects reality and can be used to practise AMR-related machine learning, e.g., classification modelling with [tidymodels](https://amr-for-r.org/articles/AMR_with_tidymodels.html).
|
||||
#' @format A [tibble][tibble::tibble] with `r format(nrow(esbl_isolates), big.mark = " ")` observations and `r ncol(esbl_isolates)` variables:
|
||||
#' - `esbl`\cr Logical indicator if the isolate is ESBL-producing
|
||||
#' - `genus`\cr Genus of the microorganism
|
||||
#' - `AMC:COL`\cr MIC values for 17 antimicrobial agents, transformed to class [`mic`] (see [as.mic()])
|
||||
#' @details See our [tidymodels integration][amr-tidymodels] for an example using this data set.
|
||||
#' @examples
|
||||
#' esbl_isolates
|
||||
"esbl_isolates"
|
||||
|
12
R/disk.R
12
R/disk.R
@@ -236,14 +236,12 @@ rep.disk <- function(x, ...) {
|
||||
# this prevents the requirement for putting the dependency in Imports:
|
||||
#' @rawNamespace if(getRversion() >= "3.0.0") S3method(skimr::get_skimmers, disk)
|
||||
get_skimmers.disk <- function(column) {
|
||||
column <- as.integer(column)
|
||||
skimr::sfl(
|
||||
skim_type = "disk",
|
||||
p0 = ~ stats::quantile(column, probs = 0, na.rm = TRUE, names = FALSE),
|
||||
p25 = ~ stats::quantile(column, probs = 0.25, na.rm = TRUE, names = FALSE),
|
||||
p50 = ~ stats::quantile(column, probs = 0.5, na.rm = TRUE, names = FALSE),
|
||||
p75 = ~ stats::quantile(column, probs = 0.75, na.rm = TRUE, names = FALSE),
|
||||
p100 = ~ stats::quantile(column, probs = 1, na.rm = TRUE, names = FALSE),
|
||||
hist = ~ skimr::inline_hist(stats::na.omit(column), 10)
|
||||
min = ~ min(as.double(.), na.rm = TRUE),
|
||||
max = ~ max(as.double(.), na.rm = TRUE),
|
||||
median = ~ stats::median(as.double(.), na.rm = TRUE),
|
||||
n_unique = ~ length(unique(stats::na.omit(.))),
|
||||
hist = ~ skimr::inline_hist(stats::na.omit(as.double(.)))
|
||||
)
|
||||
}
|
||||
|
@@ -61,7 +61,7 @@
|
||||
#'
|
||||
#' All isolates with a microbial ID of `NA` will be excluded as first isolate.
|
||||
#'
|
||||
#' ## Different methods
|
||||
#' ### Different methods
|
||||
#'
|
||||
#' 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).
|
||||
#'
|
||||
@@ -89,29 +89,21 @@
|
||||
#' | - Major difference in any antimicrobial result | - `first_isolate(x, type = "points")` |
|
||||
#' | - Any difference in key antimicrobial results | - `first_isolate(x, type = "keyantimicrobials")` |
|
||||
#'
|
||||
#' **Isolate-based**
|
||||
#'
|
||||
#' _Minimum variables required: Microorganism identifier_
|
||||
#' ### Isolate-based
|
||||
#'
|
||||
#' This method does not require any selection, as all isolates should be included. It does, however, respect all arguments set in the [first_isolate()] function. For example, the default setting for `include_unknown` (`FALSE`) will omit selection of rows without a microbial ID.
|
||||
#'
|
||||
#' **Patient-based**
|
||||
#' ### Patient-based
|
||||
#'
|
||||
#' _Minimum variables required: Microorganism identifier, Patient identifier_
|
||||
#' 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.
|
||||
#'
|
||||
#' This method includes every genus-species combination per patient once. 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
|
||||
#'
|
||||
#' **Episode-based**
|
||||
#'
|
||||
#' _Minimum variables required: Microorganism identifier, Patient identifier, Date_
|
||||
#'
|
||||
#' 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 e.g., 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.
|
||||
#' 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.
|
||||
#'
|
||||
#' **Phenotype-based**
|
||||
#'
|
||||
#' _Minimum variables required: Microorganism identifier, Patient identifier, Date, Antimicrobial test results_
|
||||
#' ### Phenotype-based
|
||||
#'
|
||||
#' This is a more reliable method, since it also *weighs* the antibiogram (antimicrobial test results) yielding so-called 'first weighted isolates'. There are two different methods to weigh the antibiogram:
|
||||
#'
|
||||
|
85
R/mdro.R
85
R/mdro.R
@@ -41,7 +41,7 @@
|
||||
#' @inheritParams eucast_rules
|
||||
#' @param pct_required_classes Minimal required percentage of antimicrobial classes that must be available per isolate, rounded down. For example, with the default guideline, 17 antimicrobial classes must be available for *S. aureus*. Setting this `pct_required_classes` argument to `0.5` (default) means that for every *S. aureus* isolate at least 8 different classes must be available. Any lower number of available classes will return `NA` for that isolate.
|
||||
#' @param combine_SI A [logical] to indicate whether all values of S and I must be merged into one, so resistance is only considered when isolates are R, not I. As this is the default behaviour of the [mdro()] function, it follows the redefinition by EUCAST about the interpretation of I (increased exposure) in 2019, see section 'Interpretation of S, I and R' below. When using `combine_SI = FALSE`, resistance is considered when isolates are R or I.
|
||||
#' @param verbose A [logical] to turn Verbose mode on and off (default is off). In Verbose mode, the function returns a data set with the MDRO results in logbook form with extensive info about which isolates would be MDRO-positive, or why they are not.
|
||||
#' @param verbose A [logical] to turn Verbose mode on and off (default is off). In Verbose mode, the function does not return the MDRO results, but instead returns a data set in logbook form with extensive info about which isolates would be MDRO-positive, or why they are not.
|
||||
#' @details
|
||||
#' These functions are context-aware. This means that the `x` argument can be left blank if used inside a [data.frame] call, see *Examples*.
|
||||
#'
|
||||
@@ -174,23 +174,48 @@ mdro <- function(x = NULL,
|
||||
}
|
||||
|
||||
# get gene values as TRUE/FALSE
|
||||
resolve_gene_var <- function(x, gene, varname) {
|
||||
if (is.character(gene)) {
|
||||
meet_criteria(gene, is_in = colnames(x), allow_NA = FALSE, has_length = 1)
|
||||
gene <- x[[gene]]
|
||||
meet_criteria(gene, allow_class = "logical", allow_NA = TRUE)
|
||||
} else if (length(gene) == 1) {
|
||||
gene <- rep(gene, NROW(x))
|
||||
}
|
||||
x[[varname]] <- gene
|
||||
x
|
||||
if (is.character(esbl)) {
|
||||
meet_criteria(esbl, is_in = colnames(x), allow_NA = FALSE, has_length = 1)
|
||||
esbl <- x[[esbl]]
|
||||
meet_criteria(esbl, allow_class = "logical", allow_NA = TRUE)
|
||||
} else if (length(esbl) == 1) {
|
||||
esbl <- rep(esbl, NROW(x))
|
||||
}
|
||||
if (is.character(carbapenemase)) {
|
||||
meet_criteria(carbapenemase, is_in = colnames(x), allow_NA = FALSE, has_length = 1)
|
||||
carbapenemase <- x[[carbapenemase]]
|
||||
meet_criteria(carbapenemase, allow_class = "logical", allow_NA = TRUE)
|
||||
} else if (length(carbapenemase) == 1) {
|
||||
carbapenemase <- rep(carbapenemase, NROW(x))
|
||||
}
|
||||
if (is.character(mecA)) {
|
||||
meet_criteria(mecA, is_in = colnames(x), allow_NA = FALSE, has_length = 1)
|
||||
mecA <- x[[mecA]]
|
||||
meet_criteria(mecA, allow_class = "logical", allow_NA = TRUE)
|
||||
} else if (length(mecA) == 1) {
|
||||
mecA <- rep(mecA, NROW(x))
|
||||
}
|
||||
if (is.character(mecC)) {
|
||||
meet_criteria(mecC, is_in = colnames(x), allow_NA = FALSE, has_length = 1)
|
||||
mecC <- x[[mecC]]
|
||||
meet_criteria(mecC, allow_class = "logical", allow_NA = TRUE)
|
||||
} else if (length(mecC) == 1) {
|
||||
mecC <- rep(mecC, NROW(x))
|
||||
}
|
||||
if (is.character(vanA)) {
|
||||
meet_criteria(vanA, is_in = colnames(x), allow_NA = FALSE, has_length = 1)
|
||||
vanA <- x[[vanA]]
|
||||
meet_criteria(vanA, allow_class = "logical", allow_NA = TRUE)
|
||||
} else if (length(vanA) == 1) {
|
||||
vanA <- rep(vanA, NROW(x))
|
||||
}
|
||||
if (is.character(vanB)) {
|
||||
meet_criteria(vanB, is_in = colnames(x), allow_NA = FALSE, has_length = 1)
|
||||
vanB <- x[[vanB]]
|
||||
meet_criteria(vanB, allow_class = "logical", allow_NA = TRUE)
|
||||
} else if (length(vanB) == 1) {
|
||||
vanB <- rep(vanB, NROW(x))
|
||||
}
|
||||
x <- resolve_gene_var(x, esbl, "esbl")
|
||||
x <- resolve_gene_var(x, carbapenemase, "carbapenemase")
|
||||
x <- resolve_gene_var(x, mecA, "mecA")
|
||||
x <- resolve_gene_var(x, mecC, "mecC")
|
||||
x <- resolve_gene_var(x, vanA, "vanA")
|
||||
x <- resolve_gene_var(x, vanB, "vanB")
|
||||
|
||||
info.bak <- info
|
||||
# don't throw info's more than once per call
|
||||
@@ -747,7 +772,7 @@ mdro <- function(x = NULL,
|
||||
)
|
||||
}
|
||||
x[rows_to_change, "MDRO"] <<- to
|
||||
x[rows_to_change, "reason"] <<- paste0(x[rows_to_change, "reason", drop = TRUE], "; ", reason)
|
||||
x[rows_to_change, "reason"] <<- reason
|
||||
x[rows_not_to_change, "reason"] <<- "guideline criteria not met"
|
||||
}
|
||||
}
|
||||
@@ -829,7 +854,7 @@ mdro <- function(x = NULL,
|
||||
x <- left_join_microorganisms(x, by = col_mo)
|
||||
x$MDRO <- ifelse(!is.na(x$genus), 1, NA_integer_)
|
||||
x$row_number <- seq_len(nrow(x))
|
||||
x$reason <- ""
|
||||
x$reason <- NA_character_
|
||||
x$all_nonsusceptible_columns <- ""
|
||||
|
||||
if (guideline$code == "cmi2012") {
|
||||
@@ -1473,7 +1498,7 @@ mdro <- function(x = NULL,
|
||||
}
|
||||
trans_tbl(
|
||||
3, # positive
|
||||
rows = which(x$order == "Enterobacterales" & x$esbl == TRUE),
|
||||
rows = which(x$order == "Enterobacterales" & esbl == TRUE),
|
||||
cols = "any",
|
||||
any_all = "any",
|
||||
reason = "Enterobacterales: ESBL"
|
||||
@@ -1494,18 +1519,17 @@ mdro <- function(x = NULL,
|
||||
)
|
||||
trans_tbl(
|
||||
3,
|
||||
rows = which(x$order == "Enterobacterales" & x$carbapenemase == TRUE),
|
||||
rows = which(x$order == "Enterobacterales" & carbapenemase == TRUE),
|
||||
cols = "any",
|
||||
any_all = "any",
|
||||
reason = "Enterobacterales: carbapenemase"
|
||||
)
|
||||
c.freundii_complex <- AMR::microorganisms.groups$mo_name[AMR::microorganisms.groups$mo_group_name == "Citrobacter freundii complex"]
|
||||
trans_tbl(
|
||||
3,
|
||||
rows = which(col_values(x, SXT) == "R" &
|
||||
(col_values(x, GEN) == "R" | col_values(x, TOB) == "R" | col_values(x, AMK) == "R") &
|
||||
(col_values(x, CIP) == "R" | col_values(x, NOR) == "R" | col_values(x, LVX) == "R") &
|
||||
(x$genus %in% c("Enterobacter", "Providencia") | paste(x$genus, x$species) %in% c(c.freundii_complex, "Klebsiella aerogenes", "Hafnia alvei", "Morganella morganii"))),
|
||||
(x$genus %in% c("Enterobacter", "Providencia") | paste(x$genus, x$species) %in% c("Citrobacter freundii", "Klebsiella aerogenes", "Hafnia alvei", "Morganella morganii"))),
|
||||
cols = c(SXT, aminoglycosides, fluoroquinolones),
|
||||
any_all = "any",
|
||||
reason = "Enterobacterales group II: aminoglycoside + fluoroquinolone + cotrimoxazol"
|
||||
@@ -1533,14 +1557,14 @@ mdro <- function(x = NULL,
|
||||
)
|
||||
trans_tbl(
|
||||
2, # unconfirmed
|
||||
rows = which(x[[col_mo]] %in% AMR::microorganisms.groups$mo[AMR::microorganisms.groups$mo_group_name == "Acinetobacter baumannii complex"] & is.na(x$carbapenemase)),
|
||||
rows = which(x[[col_mo]] %in% AMR::microorganisms.groups$mo[AMR::microorganisms.groups$mo_group_name == "Acinetobacter baumannii complex"] & is.na(carbapenemase)),
|
||||
cols = carbapenems,
|
||||
any_all = "any",
|
||||
reason = "A. baumannii-calcoaceticus complex: potential carbapenemase"
|
||||
)
|
||||
trans_tbl(
|
||||
3,
|
||||
rows = which(x[[col_mo]] %in% AMR::microorganisms.groups$mo[AMR::microorganisms.groups$mo_group_name == "Acinetobacter baumannii complex"] & x$carbapenemase == TRUE),
|
||||
rows = which(x[[col_mo]] %in% AMR::microorganisms.groups$mo[AMR::microorganisms.groups$mo_group_name == "Acinetobacter baumannii complex"] & carbapenemase == TRUE),
|
||||
cols = carbapenems,
|
||||
any_all = "any",
|
||||
reason = "A. baumannii-calcoaceticus complex: carbapenemase"
|
||||
@@ -1550,7 +1574,6 @@ mdro <- function(x = NULL,
|
||||
x$psae <- 0
|
||||
x$psae <- x$psae + ifelse(NA_as_FALSE(col_values(x, TOB) == "R") | NA_as_FALSE(col_values(x, AMK) == "R"), 1, 0)
|
||||
x$psae <- x$psae + ifelse(NA_as_FALSE(col_values(x, IPM) == "R") | NA_as_FALSE(col_values(x, MEM) == "R"), 1, 0)
|
||||
x$psae <- x$psae + ifelse(NA_as_FALSE(x$carbapenemase), 1, 0)
|
||||
x$psae <- x$psae + ifelse(NA_as_FALSE(col_values(x, PIP) == "R") | NA_as_FALSE(col_values(x, TZP) == "R"), 1, 0)
|
||||
x$psae <- x$psae + ifelse(NA_as_FALSE(col_values(x, CAZ) == "R") | NA_as_FALSE(col_values(x, CZA) == "R"), 1, 0)
|
||||
x$psae <- x$psae + ifelse(NA_as_FALSE(col_values(x, CIP) == "R") | NA_as_FALSE(col_values(x, NOR) == "R") | NA_as_FALSE(col_values(x, LVX) == "R"), 1, 0)
|
||||
@@ -1579,7 +1602,7 @@ mdro <- function(x = NULL,
|
||||
)
|
||||
trans_tbl(
|
||||
3,
|
||||
rows = which(x$genus == "Enterococcus" & x$species == "faecium" & (x$vanA == TRUE | x$vanB == TRUE)),
|
||||
rows = which(x$genus == "Enterococcus" & x$species == "faecium" & (vanA == TRUE | vanB == TRUE)),
|
||||
cols = c(PEN, AMX, AMP, VAN),
|
||||
any_all = "any",
|
||||
reason = "E. faecium: vanA/vanB gene + penicillin group"
|
||||
@@ -1588,14 +1611,14 @@ mdro <- function(x = NULL,
|
||||
# Staphylococcus aureus complex (= aureus, argenteus or schweitzeri)
|
||||
trans_tbl(
|
||||
2,
|
||||
rows = which(x$genus == "Staphylococcus" & x$species %in% c("aureus", "argenteus", "schweitzeri") & (is.na(x$mecA) | is.na(x$mecC))),
|
||||
rows = which(x$genus == "Staphylococcus" & x$species %in% c("aureus", "argenteus", "schweitzeri") & (is.na(mecA) | is.na(mecC))),
|
||||
cols = c(AMC, TZP, FLC, OXA, FOX, FOX1),
|
||||
any_all = "any",
|
||||
reason = "S. aureus complex: potential MRSA"
|
||||
)
|
||||
trans_tbl(
|
||||
3,
|
||||
rows = which(x$genus == "Staphylococcus" & x$species %in% c("aureus", "argenteus", "schweitzeri") & (x$mecA == TRUE | x$mecC == TRUE)),
|
||||
rows = which(x$genus == "Staphylococcus" & x$species %in% c("aureus", "argenteus", "schweitzeri") & (mecA == TRUE | mecC == TRUE)),
|
||||
cols = "any",
|
||||
any_all = "any",
|
||||
reason = "S. aureus complex: mecA/mecC gene"
|
||||
@@ -1876,10 +1899,6 @@ mdro <- function(x = NULL,
|
||||
# fill in empty reasons
|
||||
x$reason[is.na(x$reason)] <- "not covered by guideline"
|
||||
x[rows_empty, "reason"] <- paste(x[rows_empty, "reason"], "(note: no available test results)")
|
||||
# starting semicolons must be removed
|
||||
x$reason <- trimws(gsub("^;", "", x$reason))
|
||||
# if criteria were not met initially, but later they were, then they have a following semicolon; remove the initial lack of meeting criteria
|
||||
x$reason <- trimws(gsub("guideline criteria not met;", "", x$reason, fixed = TRUE))
|
||||
# format data set
|
||||
colnames(x)[colnames(x) == col_mo] <- "microorganism"
|
||||
x$microorganism <- mo_name(x$microorganism, language = NULL)
|
||||
|
12
R/mic.R
12
R/mic.R
@@ -596,12 +596,12 @@ get_skimmers.mic <- function(column) {
|
||||
column <- as.mic(column) # make sure that currently implemented MIC levels are used
|
||||
skimr::sfl(
|
||||
skim_type = "mic",
|
||||
p0 = ~ stats::quantile(column, probs = 0, na.rm = TRUE, names = FALSE),
|
||||
p25 = ~ stats::quantile(column, probs = 0.25, na.rm = TRUE, names = FALSE),
|
||||
p50 = ~ stats::quantile(column, probs = 0.5, na.rm = TRUE, names = FALSE),
|
||||
p75 = ~ stats::quantile(column, probs = 0.75, na.rm = TRUE, names = FALSE),
|
||||
p100 = ~ stats::quantile(column, probs = 1, na.rm = TRUE, names = FALSE),
|
||||
hist = ~ skimr::inline_hist(log2(stats::na.omit(column)), 10)
|
||||
p0 = ~ stats::quantile(., probs = 0, na.rm = TRUE, names = FALSE),
|
||||
p25 = ~ stats::quantile(., probs = 0.25, na.rm = TRUE, names = FALSE),
|
||||
p50 = ~ stats::quantile(., probs = 0.5, na.rm = TRUE, names = FALSE),
|
||||
p75 = ~ stats::quantile(., probs = 0.75, na.rm = TRUE, names = FALSE),
|
||||
p100 = ~ stats::quantile(., probs = 1, na.rm = TRUE, names = FALSE),
|
||||
hist = ~ skimr::inline_hist(log2(stats::na.omit(.)), 5)
|
||||
)
|
||||
}
|
||||
|
||||
|
16
R/mo.R
16
R/mo.R
@@ -675,7 +675,7 @@ pillar_shaft.mo <- function(x, ...) {
|
||||
}
|
||||
|
||||
# add the names to the bugs as mouse-over!
|
||||
if (in_rstudio()) {
|
||||
if (tryCatch(isTRUE(getExportedValue("ansi_has_hyperlink_support", ns = asNamespace("cli"))()), error = function(e) FALSE)) {
|
||||
out[!x %in% c("UNKNOWN", NA)] <- font_url(
|
||||
url = paste0(
|
||||
x[!x %in% c("UNKNOWN", NA)], ": ",
|
||||
@@ -747,17 +747,13 @@ freq.mo <- function(x, ...) {
|
||||
# this prevents the requirement for putting the dependency in Imports:
|
||||
#' @rawNamespace if(getRversion() >= "3.0.0") S3method(skimr::get_skimmers, mo)
|
||||
get_skimmers.mo <- function(column) {
|
||||
mo <- as.mo(column, keep_synonyms = TRUE, language = NULL, info = FALSE)
|
||||
mo <- mo[!is.na(mo)]
|
||||
spp <- mo[mo_species(mo, keep_synonyms = TRUE, language = NULL, info = FALSE) != ""]
|
||||
skimr::sfl(
|
||||
skim_type = "mo",
|
||||
n_unique = ~ length(unique(mo)),
|
||||
gram_negative = ~ sum(mo_is_gram_negative(mo, keep_synonyms = TRUE, language = NULL, info = FALSE), na.rm = TRUE),
|
||||
gram_positive = ~ sum(mo_is_gram_positive(mo, keep_synonyms = TRUE, language = NULL, info = FALSE), na.rm = TRUE),
|
||||
yeast = ~ sum(mo_is_yeast(mo, keep_synonyms = TRUE, language = NULL, info = FALSE), na.rm = TRUE),
|
||||
top_genus = ~ names(sort(-table(mo_genus(mo, keep_synonyms = TRUE, language = NULL, info = FALSE))))[1L],
|
||||
top_species = ~ names(sort(-table(mo_name(spp, keep_synonyms = TRUE, language = NULL, info = FALSE))))[1L],
|
||||
unique_total = ~ length(unique(stats::na.omit(.))),
|
||||
gram_negative = ~ sum(mo_is_gram_negative(.), na.rm = TRUE),
|
||||
gram_positive = ~ sum(mo_is_gram_positive(.), na.rm = TRUE),
|
||||
top_genus = ~ names(sort(-table(mo_genus(stats::na.omit(.), language = NULL))))[1L],
|
||||
top_species = ~ names(sort(-table(mo_name(stats::na.omit(.), language = NULL))))[1L]
|
||||
)
|
||||
}
|
||||
|
||||
|
74
R/plotting.R
74
R/plotting.R
@@ -52,19 +52,11 @@
|
||||
#' @details
|
||||
#' ### The `scale_*_mic()` Functions
|
||||
#'
|
||||
#' The functions [scale_x_mic()], [scale_y_mic()], [scale_colour_mic()], and [scale_fill_mic()] functions allow to plot the [mic][as.mic()] class (MIC values) on a continuous, logarithmic scale.
|
||||
#'
|
||||
#' There is normally no need to add these scale functions to your plot, as they are applied automatically when plotting values of class [mic][as.mic()].
|
||||
#'
|
||||
#' When manually added though, they allow to rescale the MIC range with an 'inside' or 'outside' range if required, and provide the option to retain the operators in MIC values (such as `>=`). Missing intermediate log2 levels will always be plotted too.
|
||||
#' The functions [scale_x_mic()], [scale_y_mic()], [scale_colour_mic()], and [scale_fill_mic()] functions allow to plot the [mic][as.mic()] class (MIC values) on a continuous, logarithmic scale. They also allow to rescale the MIC range with an 'inside' or 'outside' range if required, and retain the operators in MIC values (such as `>=`) if desired. Missing intermediate log2 levels will be plotted too.
|
||||
#'
|
||||
#' ### The `scale_*_sir()` Functions
|
||||
#'
|
||||
#' The functions [scale_x_sir()], [scale_colour_sir()], and [scale_fill_sir()] functions allow to plot the [sir][as.sir()] class in the right order (`r paste(levels(NA_sir_), collapse = " < ")`).
|
||||
#'
|
||||
#' There is normally no need to add these scale functions to your plot, as they are applied automatically when plotting values of class [sir][as.sir()].
|
||||
#'
|
||||
#' At default, they translate the S/I/R values to an interpretative text ("Susceptible", "Resistant", etc.) in any of the `r length(AMR:::LANGUAGES_SUPPORTED)` supported languages (use `language = NULL` to keep S/I/R). Also, except for [scale_x_sir()], they set colour-blind friendly colours to the `colour` and `fill` aesthetics.
|
||||
#' The functions [scale_x_sir()], [scale_colour_sir()], and [scale_fill_sir()] functions allow to plot the [sir][as.sir()] class in the right order (`r paste(levels(NA_sir_), collapse = " < ")`). At default, they translate the S/I/R values to an interpretative text ("Susceptible", "Resistant", etc.) in any of the `r length(AMR:::LANGUAGES_SUPPORTED)` supported languages (use `language = NULL` to keep S/I/R). Also, except for [scale_x_sir()], they set colour-blind friendly colours to the `colour` and `fill` aesthetics.
|
||||
#'
|
||||
#' ### Additional `ggplot2` Functions
|
||||
#'
|
||||
@@ -122,12 +114,17 @@
|
||||
#' ) +
|
||||
#' geom_col()
|
||||
#' mic_plot +
|
||||
#' labs(title = "scale_x_mic() automatically applied")
|
||||
#' labs(title = "without scale_x_mic()")
|
||||
#' }
|
||||
#' if (require("ggplot2")) {
|
||||
#' mic_plot +
|
||||
#' scale_x_mic(keep_operators = "none") +
|
||||
#' labs(title = "with scale_x_mic() keeping no operators")
|
||||
#' scale_x_mic() +
|
||||
#' labs(title = "with scale_x_mic()")
|
||||
#' }
|
||||
#' if (require("ggplot2")) {
|
||||
#' mic_plot +
|
||||
#' scale_x_mic(keep_operators = "all") +
|
||||
#' labs(title = "with scale_x_mic() keeping all operators")
|
||||
#' }
|
||||
#' if (require("ggplot2")) {
|
||||
#' mic_plot +
|
||||
@@ -154,7 +151,7 @@
|
||||
#' ) +
|
||||
#' geom_boxplot() +
|
||||
#' geom_violin(linetype = 2, colour = "grey30", fill = NA) +
|
||||
#' labs(title = "scale_y_mic() automatically applied")
|
||||
#' scale_y_mic()
|
||||
#' }
|
||||
#' if (require("ggplot2")) {
|
||||
#' ggplot(
|
||||
@@ -186,7 +183,7 @@
|
||||
#'
|
||||
#' # Plotting using scale_y_mic() and scale_colour_sir() ------------------
|
||||
#' if (require("ggplot2")) {
|
||||
#' mic_sir_plot <- ggplot(
|
||||
#' plain <- ggplot(
|
||||
#' data.frame(
|
||||
#' mic = some_mic_values,
|
||||
#' group = some_groups,
|
||||
@@ -200,16 +197,21 @@
|
||||
#' theme_minimal() +
|
||||
#' geom_boxplot(fill = NA, colour = "grey30") +
|
||||
#' geom_jitter(width = 0.25)
|
||||
#' labs(title = "scale_y_mic()/scale_colour_sir() automatically applied")
|
||||
#'
|
||||
#' mic_sir_plot
|
||||
#'
|
||||
#' plain
|
||||
#' }
|
||||
#' if (require("ggplot2")) {
|
||||
#' mic_sir_plot +
|
||||
#' # and now with our MIC and SIR scale functions:
|
||||
#' plain +
|
||||
#' scale_y_mic() +
|
||||
#' scale_colour_sir()
|
||||
#' }
|
||||
#' if (require("ggplot2")) {
|
||||
#' plain +
|
||||
#' scale_y_mic(mic_range = c(0.005, 32), name = "Our MICs!") +
|
||||
#' scale_colour_sir(
|
||||
#' language = "pt", # Portuguese
|
||||
#' name = "Support in 28 languages"
|
||||
#' language = "pt",
|
||||
#' name = "Support in 27 languages"
|
||||
#' )
|
||||
#' }
|
||||
#' }
|
||||
@@ -227,9 +229,6 @@
|
||||
#' plot(some_sir_values)
|
||||
NULL
|
||||
|
||||
#' @rawNamespace if(getRversion() >= "3.0.0") S3method(ggplot2::scale_type, mic)
|
||||
scale_type.mic <- function(x) c("mic", "discrete")
|
||||
|
||||
create_scale_mic <- function(aest, keep_operators, mic_range = NULL, ...) {
|
||||
ggplot_fn <- getExportedValue(paste0("scale_", aest, "_continuous"),
|
||||
ns = asNamespace("ggplot2")
|
||||
@@ -248,7 +247,6 @@ create_scale_mic <- function(aest, keep_operators, mic_range = NULL, ...) {
|
||||
as.double(rescale_mic(x = as.double(as.mic(x)), keep_operators = keep_operators, mic_range = mic_range, as.mic = TRUE))
|
||||
}
|
||||
scale$transform_df <- function(self, df) {
|
||||
out <- list()
|
||||
if (!aest %in% colnames(df)) {
|
||||
# support for geom_hline(), geom_vline(), etc
|
||||
other_x <- c("xintercept", "xmin", "xmax", "xend", "width")
|
||||
@@ -260,11 +258,11 @@ create_scale_mic <- function(aest, keep_operators, mic_range = NULL, ...) {
|
||||
} else {
|
||||
stop_("No support for plotting df with `scale_", aest, "_mic()` with columns ", vector_and(colnames(df), sort = FALSE))
|
||||
}
|
||||
mics <- rescale_mic(x = as.double(as.mic(df[[aest_val]])), keep_operators = "none", mic_range = NULL, as.mic = TRUE)
|
||||
if (!is.null(self$mic_values_rescaled) && any(mics < min(self$mic_values_rescaled, na.rm = TRUE) | mics > max(self$mic_values_rescaled, na.rm = TRUE), na.rm = TRUE)) {
|
||||
out <- rescale_mic(x = as.double(as.mic(df[[aest_val]])), keep_operators = "none", mic_range = NULL, as.mic = TRUE)
|
||||
if (!is.null(self$mic_values_rescaled) && any(out < min(self$mic_values_rescaled, na.rm = TRUE) | out > max(self$mic_values_rescaled, na.rm = TRUE), na.rm = TRUE)) {
|
||||
warning_("The value for `", aest_val, "` is outside the plotted MIC range, consider using/updating the `mic_range` argument in `scale_", aest, "_mic()`.")
|
||||
}
|
||||
out[[aest_val]] <- log2(as.double(mics))
|
||||
df[[aest_val]] <- log2(as.double(out))
|
||||
} else {
|
||||
self$mic_values_rescaled <- rescale_mic(x = as.double(as.mic(df[[aest]])), keep_operators = keep_operators, mic_range = mic_range, as.mic = TRUE)
|
||||
# create new breaks and labels here
|
||||
@@ -285,18 +283,14 @@ create_scale_mic <- function(aest, keep_operators, mic_range = NULL, ...) {
|
||||
self$mic_values_levels[1] <- paste0("<=", self$mic_values_levels[1])
|
||||
self$mic_values_levels[length(self$mic_values_levels)] <- paste0(">=", self$mic_values_levels[length(self$mic_values_levels)])
|
||||
}
|
||||
self$mic_values_log <- log2(as.double(self$mic_values_rescaled))
|
||||
|
||||
if (aest == "y" && "group" %in% colnames(df)) {
|
||||
if (!"x" %in% colnames(df) || all(is.na(df$x))) {
|
||||
out$group <- 1
|
||||
} else {
|
||||
out$group <- as.integer(factor(df$x))
|
||||
}
|
||||
self$mic_values_log <- log2(as.double(self$mic_values_rescaled))
|
||||
if (aest == "y" && "group" %in% colnames(df) && "x" %in% colnames(df)) {
|
||||
df$group <- as.integer(factor(df$x))
|
||||
}
|
||||
out[[aest]] <- self$mic_values_log
|
||||
df[[aest]] <- self$mic_values_log
|
||||
}
|
||||
out
|
||||
df
|
||||
}
|
||||
|
||||
scale$breaks <- function(..., self) {
|
||||
@@ -323,6 +317,7 @@ create_scale_mic <- function(aest, keep_operators, mic_range = NULL, ...) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
scale$limits <- function(x, ..., self) {
|
||||
if (!is.null(self$mic_limits_set)) {
|
||||
if (is.function(self$mic_limits_set)) {
|
||||
@@ -334,7 +329,7 @@ create_scale_mic <- function(aest, keep_operators, mic_range = NULL, ...) {
|
||||
rng <- range(log2(as.mic(self$mic_values_levels)))
|
||||
# add 0.5 extra space
|
||||
rng <- c(rng[1] - 0.5, rng[2] + 0.5)
|
||||
if (!is.null(x) && !is.na(x[1]) && x[1] == 0) {
|
||||
if (!is.na(x[1]) && x[1] == 0) {
|
||||
# scale that start at 0 must remain so, e.g. in case of geom_col()
|
||||
rng[1] <- 0
|
||||
}
|
||||
@@ -382,9 +377,6 @@ scale_fill_mic <- function(keep_operators = "edges", mic_range = NULL, ...) {
|
||||
create_scale_mic("fill", keep_operators = keep_operators, mic_range = mic_range, ...)
|
||||
}
|
||||
|
||||
#' @rawNamespace if(getRversion() >= "3.0.0") S3method(ggplot2::scale_type, sir)
|
||||
scale_type.sir <- function(x) c("sir", "discrete")
|
||||
|
||||
create_scale_sir <- function(aesthetics, colours_SIR, language, eucast_I, ...) {
|
||||
args <- list(...)
|
||||
args[c("value", "labels", "limits")] <- NULL
|
||||
|
280
R/sir.R
280
R/sir.R
@@ -385,26 +385,15 @@ as.sir <- function(x, ...) {
|
||||
UseMethod("as.sir")
|
||||
}
|
||||
|
||||
as_sir_structure <- function(x,
|
||||
guideline = NULL,
|
||||
mo = NULL,
|
||||
ab = NULL,
|
||||
method = NULL,
|
||||
ref_tbl = NULL,
|
||||
ref_breakpoints = NULL) {
|
||||
as_sir_structure <- function(x) {
|
||||
int <- attr(x, "interpretation_details")
|
||||
structure(
|
||||
factor(as.character(unlist(unname(x))),
|
||||
levels = c("S", "SDD", "I", "R", "NI"),
|
||||
ordered = TRUE
|
||||
),
|
||||
# TODO for #170
|
||||
# guideline = guideline,
|
||||
# mo = mo,
|
||||
# ab = ab,
|
||||
# method = method,
|
||||
# ref_tbl = ref_tbl,
|
||||
# ref_breakpoints = ref_breakpoints,
|
||||
class = c("sir", "ordered", "factor")
|
||||
interpretation_details = int,
|
||||
class = c(if (!is.null(int)) "interpreted_sir" else NULL, "sir", "ordered", "factor")
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1649,9 +1638,11 @@ as_sir_method <- function(method_short,
|
||||
breakpoint_S_R = vectorise_log_entry(NA_character_, length(rows)),
|
||||
stringsAsFactors = FALSE
|
||||
)
|
||||
attr(new_sir, "interpretation_details") <- out
|
||||
out <- subset(out, !is.na(input_given))
|
||||
AMR_env$sir_interpretation_history <- rbind_AMR(AMR_env$sir_interpretation_history, out)
|
||||
notes <- c(notes, notes_current)
|
||||
df[rows, "result"] <- new_sir
|
||||
next
|
||||
}
|
||||
|
||||
@@ -1827,6 +1818,7 @@ as_sir_method <- function(method_short,
|
||||
breakpoint_S_R = vectorise_log_entry(paste0(breakpoints_current[, "breakpoint_S", drop = TRUE], "-", breakpoints_current[, "breakpoint_R", drop = TRUE]), length(rows)),
|
||||
stringsAsFactors = FALSE
|
||||
)
|
||||
attr(new_sir, "interpretation_details") <- out
|
||||
out <- subset(out, !is.na(input_given))
|
||||
AMR_env$sir_interpretation_history <- rbind_AMR(AMR_env$sir_interpretation_history, out)
|
||||
}
|
||||
@@ -1871,20 +1863,33 @@ as_sir_method <- function(method_short,
|
||||
new_part <- new_part[order(new_part$index), , drop = FALSE]
|
||||
AMR_env$sir_interpretation_history <- rbind_AMR(old_part, new_part)
|
||||
|
||||
df$result
|
||||
as_sir_structure(df$result)
|
||||
}
|
||||
|
||||
#' @rdname as.sir
|
||||
#' @param sir_values SIR values that were interpreted from MIC or disk diffusion values using [as.sir()].
|
||||
#' @param clean A [logical] to indicate whether previously stored results should be forgotten after returning the 'logbook' with results.
|
||||
#' @export
|
||||
sir_interpretation_history <- function(clean = FALSE) {
|
||||
sir_interpretation_history <- function(sir_values = NULL, clean = FALSE) {
|
||||
# for AMR v3.0.0 and lower, the first argument was `clean`, so allow `sir_interpretation_history(TRUE)` to keep working
|
||||
if (is.logical(sir_values) && missing(clean)) {
|
||||
clean <- sir_values
|
||||
sir_values <- NULL
|
||||
warning_("For `sir_interpretation_history()`, the `clean` argument is no longer the first argument, please update your code to explicitly state 'clean': `sir_interpretation_history(clean = ", clean, ")`.")
|
||||
}
|
||||
meet_criteria(sir_values, allow_class = "sir", allow_NULL = TRUE)
|
||||
meet_criteria(clean, allow_class = "logical", has_length = 1)
|
||||
out <- AMR_env$sir_interpretation_history
|
||||
out <- out[which(!is.na(out$datetime)), , drop = FALSE]
|
||||
out$outcome <- as.sir(out$outcome)
|
||||
out$site <- as.character(out$site)
|
||||
if (isTRUE(clean)) {
|
||||
AMR_env$sir_interpretation_history <- AMR_env$sir_interpretation_history[0, , drop = FALSE]
|
||||
|
||||
if (!is.null(sir_values)) {
|
||||
out <- attr(sir_values, "interpretation_details")
|
||||
} else {
|
||||
out <- AMR_env$sir_interpretation_history
|
||||
out <- out[which(!is.na(out$datetime)), , drop = FALSE]
|
||||
out$outcome <- as.sir(out$outcome)
|
||||
out$site <- as.character(out$site)
|
||||
if (isTRUE(clean)) {
|
||||
AMR_env$sir_interpretation_history <- AMR_env$sir_interpretation_history[0, , drop = FALSE]
|
||||
}
|
||||
}
|
||||
if (pkg_is_available("tibble")) {
|
||||
out <- import_fn("as_tibble", "tibble")(out)
|
||||
@@ -1974,18 +1979,33 @@ freq.sir <- function(x, ...) {
|
||||
# this prevents the requirement for putting the dependency in Imports:
|
||||
#' @rawNamespace if(getRversion() >= "3.0.0") S3method(skimr::get_skimmers, sir)
|
||||
get_skimmers.sir <- function(column) {
|
||||
# TODO add here in AMR 3.1.0 details about guideline
|
||||
# get the variable name 'skim_variable'
|
||||
name_call <- function(.data) {
|
||||
calls <- sys.calls()
|
||||
frms <- sys.frames()
|
||||
calls_txt <- vapply(calls, function(x) paste(deparse(x), collapse = ""), FUN.VALUE = character(1))
|
||||
if (any(calls_txt %like% "skim_variable", na.rm = TRUE)) {
|
||||
ind <- which(calls_txt %like% "skim_variable")[1L]
|
||||
vars <- tryCatch(eval(parse(text = ".data$skim_variable$sir"), envir = frms[[ind]]),
|
||||
error = function(e) NULL
|
||||
)
|
||||
tryCatch(ab_name(as.character(calls[[length(calls)]][[2]]), language = NULL, info = FALSE),
|
||||
error = function(e) NA_character_
|
||||
)
|
||||
} else {
|
||||
NA_character_
|
||||
}
|
||||
}
|
||||
|
||||
skimr::sfl(
|
||||
skim_type = "sir",
|
||||
# guideline = function(x) "EUCAST 2025", # or "Multiple"
|
||||
# origin = function(x) "MIC", # or "Multiple"
|
||||
count_S = count_S,
|
||||
count_I = count_I,
|
||||
ab_name = name_call,
|
||||
count_R = count_R,
|
||||
prop_S = ~ round(proportion_S(., minimum = 0) * 100, 1),
|
||||
prop_I = ~ round(proportion_I(., minimum = 0) * 100, 1),
|
||||
prop_R = ~ round(proportion_R(., minimum = 0) * 100, 1),
|
||||
hist = ~ skimr::inline_hist(as.double(stats::na.omit(.)), 3)
|
||||
count_S = count_susceptible,
|
||||
count_I = count_I,
|
||||
prop_R = ~ proportion_R(., minimum = 0),
|
||||
prop_S = ~ susceptibility(., minimum = 0),
|
||||
prop_I = ~ proportion_I(., minimum = 0)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1993,21 +2013,60 @@ get_skimmers.sir <- function(column) {
|
||||
#' @export
|
||||
#' @noRd
|
||||
print.sir <- function(x, ...) {
|
||||
x_name <- deparse(substitute(x))
|
||||
cat("Class 'sir'\n")
|
||||
# TODO for #170
|
||||
# if (!is.null(attributes(x)$guideline) && !all(is.na(attributes(x)$guideline))) {
|
||||
# cat(font_blue(word_wrap("These values were interpreted using ",
|
||||
# font_bold(vector_and(attributes(x)$guideline, quotes = FALSE)),
|
||||
# " based on ",
|
||||
# vector_and(attributes(x)$method, quotes = FALSE),
|
||||
# " values. ",
|
||||
# "Use `sir_interpretation_history(", x_name, ")` to return a full logbook.")))
|
||||
# cat("\n")
|
||||
# }
|
||||
print(as.character(x), quote = FALSE)
|
||||
}
|
||||
|
||||
#' @method print interpreted_sir
|
||||
#' @export
|
||||
#' @noRd
|
||||
print.interpreted_sir <- function(x, ...) {
|
||||
cat("Class 'sir'\n")
|
||||
print(as.character(x), quote = FALSE)
|
||||
|
||||
if (length(x) == 0) {
|
||||
return(invisible())
|
||||
}
|
||||
|
||||
int <- attr(x, "interpretation_details")
|
||||
if (NROW(int) == 0) {
|
||||
if (length(x) == 1) {
|
||||
cat(font_blue(word_wrap("Source data were lost for this interpreted value.")))
|
||||
} else {
|
||||
cat(font_blue(word_wrap("Source data were lost for these interpreted values.")))
|
||||
}
|
||||
} else {
|
||||
relevant_cols <- int[, c("guideline", "method", "ab", "mo"), drop = FALSE]
|
||||
relevant_cols <- unique(relevant_cols)
|
||||
vals1_plural <- ifelse(length(x) == 1, "This value was", "These values were")
|
||||
vals2_plural <- ifelse(length(x) == 1, "value", "values")
|
||||
method_fn <- ifelse(relevant_cols$method == "MIC", "MIC", "disk diffusion")
|
||||
if (NROW(relevant_cols) == 1) {
|
||||
in_host <- ifelse(relevant_cols$host == "human", "", paste0(" in ", relevant_cols$host))
|
||||
cat(font_blue(word_wrap(
|
||||
vals1_plural, " interpreted using ",
|
||||
relevant_cols$guideline,
|
||||
" based on the ",
|
||||
method_fn,
|
||||
" ", vals2_plural, " for ",
|
||||
ab_name(relevant_cols$ab, language = NULL, info = FALSE, tolower = TRUE), " in ",
|
||||
italicise_taxonomy(mo_name(relevant_cols$mo, language = NULL, info = FALSE), type = "ansi"),
|
||||
in_host,
|
||||
"."
|
||||
)))
|
||||
} else {
|
||||
cat(font_blue(word_wrap(
|
||||
vals1_plural, " interpreted using ",
|
||||
vector_and(relevant_cols$guideline, quotes = FALSE),
|
||||
" based on ",
|
||||
vector_and(method_fn, quotes = FALSE),
|
||||
" ", vals2_plural, "."
|
||||
)))
|
||||
}
|
||||
cat(font_blue(word_wrap("\nUse `sir_interpretation_history()` on this object to return a full logbook.\n")))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#' @method as.double sir
|
||||
#' @export
|
||||
@@ -2063,51 +2122,132 @@ summary.sir <- function(object, ...) {
|
||||
value
|
||||
}
|
||||
|
||||
#' @method [ sir
|
||||
#' @export
|
||||
#' @noRd
|
||||
"[.sir" <- function(x, ...) {
|
||||
y <- NextMethod()
|
||||
det <- attr(x, "interpretation_details")
|
||||
if (!is.null(det)) {
|
||||
subset_idx <- seq_along(x)[...]
|
||||
# safer than relying on implicit eval inside NextMethod()
|
||||
attr(y, "interpretation_details") <- det[subset_idx, , drop = FALSE]
|
||||
}
|
||||
y
|
||||
}
|
||||
#' @method [[ sir
|
||||
#' @export
|
||||
#' @noRd
|
||||
"[[.sir" <- function(x, i, ...) {
|
||||
if (length(i) != 1L) {
|
||||
stop("attempt to select more than one element with [[.", call. = FALSE)
|
||||
}
|
||||
x[i] # calls `[.sir`, ensures attr alignment
|
||||
}
|
||||
|
||||
#' @method [<- sir
|
||||
#' @export
|
||||
#' @noRd
|
||||
"[<-.sir" <- function(i, j, ..., value) {
|
||||
value <- as.sir(value)
|
||||
y <- NextMethod()
|
||||
attributes(y) <- attributes(i)
|
||||
|
||||
old_det <- attr(i, "interpretation_details")
|
||||
new_det <- attr(value, "interpretation_details")
|
||||
|
||||
len_y <- length(y)
|
||||
|
||||
# Neither i nor value have details -> do nothing
|
||||
if (is.null(old_det) && is.null(new_det)) {
|
||||
return(y)
|
||||
}
|
||||
|
||||
# Start building full_det as copy of old_det or empty
|
||||
full_det <- if (!is.null(old_det)) old_det else data.frame(row = seq_along(i))
|
||||
|
||||
# Ensure full_det has correct row count and order
|
||||
if (nrow(full_det) != length(i)) {
|
||||
attr(y, "interpretation_details") <- NULL
|
||||
return(y)
|
||||
}
|
||||
|
||||
# Which rows are being assigned?
|
||||
assign_idx <- if (missing(j)) seq_along(i) else j
|
||||
assign_idx <- as.integer(assign_idx)
|
||||
|
||||
# If new_det is missing or too short, fill it
|
||||
if (is.null(new_det)) {
|
||||
new_det <- data.frame(row = assign_idx)
|
||||
} else if (nrow(new_det) != length(value)) {
|
||||
new_det <- data.frame(row = assign_idx)
|
||||
}
|
||||
|
||||
# Add temporary .row to track positions
|
||||
full_det$.row <- seq_len(nrow(full_det))
|
||||
new_det$.row <- assign_idx
|
||||
|
||||
# Replace old rows with new rows
|
||||
full_det <- rbind(
|
||||
subset(full_det, !.row %in% assign_idx),
|
||||
new_det
|
||||
)
|
||||
full_det <- full_det[order(full_det$.row), , drop = FALSE]
|
||||
full_det$.row <- NULL
|
||||
|
||||
# Clean up: ensure right number of rows
|
||||
if (nrow(full_det) == len_y) {
|
||||
attr(y, "interpretation_details") <- full_det
|
||||
} else {
|
||||
attr(y, "interpretation_details") <- NULL
|
||||
}
|
||||
|
||||
y
|
||||
}
|
||||
#' @method [[<- sir
|
||||
#' @export
|
||||
#' @noRd
|
||||
"[[<-.sir" <- function(i, j, ..., value) {
|
||||
value <- as.sir(value)
|
||||
y <- NextMethod()
|
||||
attributes(y) <- attributes(i)
|
||||
y
|
||||
if (!is.null(det) && length(i) == 1 && nrow(det) >= i) {
|
||||
i[j] <- value
|
||||
i
|
||||
} else {
|
||||
NextMethod()
|
||||
}
|
||||
}
|
||||
#' @method c sir
|
||||
#' @export
|
||||
#' @noRd
|
||||
c.sir <- function(...) {
|
||||
lst <- list(...)
|
||||
c.sir <- function(..., recursive = FALSE) {
|
||||
lst <- lapply(
|
||||
list(...),
|
||||
function(x) {
|
||||
list(
|
||||
values = as.character(x),
|
||||
interpretation_details = attr(x, "interpretation_details")
|
||||
)
|
||||
}
|
||||
)
|
||||
x <- unlist(lapply(lst, `[[`, "values"), use.names = FALSE)
|
||||
details <- lapply(lst, `[[`, "interpretation_details")
|
||||
has_details <- vapply(details, is.data.frame, logical(1))
|
||||
if (!any(has_details)) {
|
||||
return(as_sir_structure(x))
|
||||
}
|
||||
|
||||
# TODO for #170
|
||||
# guideline <- vapply(FUN.VALUE = character(1), lst, function(x) attributes(x)$guideline %or% NA_character_)
|
||||
# mo <- vapply(FUN.VALUE = character(1), lst, function(x) attributes(x)$mo %or% NA_character_)
|
||||
# ab <- vapply(FUN.VALUE = character(1), lst, function(x) attributes(x)$ab %or% NA_character_)
|
||||
# method <- vapply(FUN.VALUE = character(1), lst, function(x) attributes(x)$method %or% NA_character_)
|
||||
# ref_tbl <- vapply(FUN.VALUE = character(1), lst, function(x) attributes(x)$ref_tbl %or% NA_character_)
|
||||
# ref_breakpoints <- vapply(FUN.VALUE = character(1), lst, function(x) attributes(x)$ref_breakpoints %or% NA_character_)
|
||||
# Pre-allocate details (no Map, no matrix allocation)
|
||||
combined_details <- do.call(rbind, lapply(seq_along(details), function(i) {
|
||||
d <- details[[i]]
|
||||
if (is.null(d)) {
|
||||
# generate NA rows of correct length, but fast
|
||||
n <- length(details[[i]])
|
||||
as.data.frame(matrix(NA, nrow = n, ncol = 0))
|
||||
} else {
|
||||
d
|
||||
}
|
||||
}))
|
||||
|
||||
out <- as.sir(unlist(lapply(list(...), as.character)))
|
||||
|
||||
# TODO for #170
|
||||
# if (!all(is.na(guideline))) {
|
||||
# attributes(out)$guideline <- guideline
|
||||
# attributes(out)$mo <- mo
|
||||
# attributes(out)$ab <- ab
|
||||
# attributes(out)$method <- method
|
||||
# attributes(out)$ref_tbl <- ref_tbl
|
||||
# attributes(out)$ref_breakpoints <- ref_breakpoints
|
||||
# }
|
||||
|
||||
out
|
||||
attr(x, "interpretation_details") <- combined_details
|
||||
as_sir_structure(x)
|
||||
}
|
||||
|
||||
#' @method unique sir
|
||||
|
BIN
R/sysdata.rda
BIN
R/sysdata.rda
Binary file not shown.
@@ -49,11 +49,8 @@ To install the latest 'beta' version:
|
||||
|
||||
```{r, eval = FALSE}
|
||||
install.packages("AMR", repos = "beta.amr-for-r.org")
|
||||
```
|
||||
|
||||
If this does not work, try to install directly from GitHub using the `remotes` package:
|
||||
|
||||
```{r, eval = FALSE}
|
||||
# if this does not work, try to install directly from GitHub using the 'remotes' package:
|
||||
remotes::install_github("msberends/AMR")
|
||||
```
|
||||
|
||||
|
@@ -58,12 +58,8 @@ To install the latest ‘beta’ version:
|
||||
|
||||
``` r
|
||||
install.packages("AMR", repos = "beta.amr-for-r.org")
|
||||
```
|
||||
|
||||
If this does not work, try to install directly from GitHub using the
|
||||
`remotes` package:
|
||||
|
||||
``` r
|
||||
# if this does not work, try to install directly from GitHub using the 'remotes' package:
|
||||
remotes::install_github("msberends/AMR")
|
||||
```
|
||||
|
||||
|
@@ -234,7 +234,7 @@ reference:
|
||||
- "`antimicrobials`"
|
||||
- "`clinical_breakpoints`"
|
||||
- "`example_isolates`"
|
||||
# TODO - "`esbl_isolates`"
|
||||
- "`esbl_isolates`"
|
||||
- "`microorganisms.codes`"
|
||||
- "`microorganisms.groups`"
|
||||
- "`intrinsic_resistant`"
|
||||
|
@@ -1,5 +1,3 @@
|
||||
This version is a bugfix release (v3.0.1) following the release of v3.0.0 in June 2025.
|
||||
|
||||
As with all previous >20 releases, some CHECKs on `oldrel` may return a `NOTE` for narrowly exceeding the installation size limit. This has been reduced to a minimum in prior coordination with CRAN maintainers and currently returns only an `INFO` on `release` and `devel`.
|
||||
|
||||
We treat this as a high-impact package: it was published in the *Journal of Statistical Software* (2022), is listed in the CRAN Task View "Epidemiology", and (based on cranlogs download statistics) is used globally. If there is anything to address, we would appreciate being informed before archiving the current version. We conduct extensive automated unit testing and have no indication of unresolved issues.
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -1 +1 @@
|
||||
d12f1c78feaecbb4d1631f9c735ad49b
|
||||
228840b3941753c4adee2b781d901590
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -116,7 +116,7 @@
|
||||
"CSU" 68718 "Cefsumide" "Cephalosporins (unclassified gen.)" "NA" "NA" "cefsulmid,cefsumido,cefsumidum" "NA"
|
||||
"CPT" 56841980 "Ceftaroline" "Cephalosporins (5th gen.)" "J01DI02,QJ01DI02" "ceftar,cfro" "ceftaroine,teflaro,zinforo" "73604-1,73605-8,73626-4,73627-2,73649-6,73650-4,74170-2"
|
||||
"CPA" "Ceftaroline/avibactam" "Cephalosporins (5th gen.)" "NA" "NA" "NA" "73604-1,73626-4,73649-6"
|
||||
"CAZ" 5481173 "Ceftazidime" "Cephalosporins (3rd gen.)" "J01DD02,QJ01DD02" "Other beta-lactam antibacterials" "Third-generation cephalosporins" "caz,cef,cefta,ceftaz,cfta,cftz,taz,tz,xtz" "ceftazimide,ceptaz,fortam,fortaz,fortum,glazidim,kefazim,modacin,pentacef,tazicef,tizime" 4 "g" "101481-0,101482-8,101483-6,132-1,133-9,134-7,135-4,18893-8,21151-6,3449-6,35774-9,35775-6,35776-4,42352-5,55648-0,55649-8,55650-6,55651-4,58705-5,6995-5,73603-3,73625-6,73648-8,80960-8,87734-0,90850-9"
|
||||
"CAZ" 5481173 "Ceftazidime" "Cephalosporins (3rd gen.)" "J01DD02,QJ01DD02" "Other beta-lactam antibacterials" "Third-generation cephalosporins" "caz,cefta,ceftaz,cfta,cftz,taz,tz,xtz" "ceftazimide,ceptaz,fortam,fortaz,fortum,glazidim,kefazim,modacin,pentacef,tazicef,tizime" 4 "g" "101481-0,101482-8,101483-6,132-1,133-9,134-7,135-4,18893-8,21151-6,3449-6,35774-9,35775-6,35776-4,42352-5,55648-0,55649-8,55650-6,55651-4,58705-5,6995-5,73603-3,73625-6,73648-8,80960-8,87734-0,90850-9"
|
||||
"CZA" 90643431 "Ceftazidime/avibactam" "Cephalosporins (3rd gen.)" "J01DD52,QJ01DD52" "cfav" "avycaz,zavicefta" 6 "g" "101483-6,73603-3,73625-6,73648-8,87734-0"
|
||||
"CCV" 9575352 "Ceftazidime/clavulanic acid" "Cephalosporins (3rd gen.)" "J01DD52,QJ01DD52" "Other beta-lactam antibacterials" "Third-generation cephalosporins" "czcl,tazcla,xtzl" "NA" 6 "g" "NA"
|
||||
"CEM" 6537431 "Cefteram" "Cephalosporins (3rd gen.)" "J01DD18,QJ01DD18" "cefter" "cefterame,cefteramum,ceftetrame" 0.4 "g" "100047-0,76144-5"
|
||||
@@ -162,7 +162,7 @@
|
||||
"CYC" 6234 "Cycloserine" "Oxazolidinones" "J04AB01,QJ04AB01" "Drugs for treatment of tuberculosis" "Antibiotics" "cycl,cyclos" "cicloserina,closina,cyclorin,cycloserin,cycloserinum,farmiserina,levcicloserina,levcycloserine,levcycloserinum,micoserina,miroserina,miroseryn,novoserin,oxamicina,oxamycin,seromycin,tebemicina,wasserina" 0.75 "g" "16702-3,18914-2,212-1,213-9,214-7,215-4,23608-3,25207-2,25208-0,25209-8,25251-0,3519-6,55667-0"
|
||||
"DAL" 23724878 "Dalbavancin" "Glycopeptides" "J01XA04,QJ01XA04" "Other antibacterials" "Glycopeptide antibacterials" "dalb,dalbav" "dalbavancina,dalvance,xydalba,zeven" 1.5 "g" "41688-3,41689-1,41690-9,41734-5"
|
||||
"DAN" 71335 "Danofloxacin" "Fluoroquinolones" "QJ01MA92" "danofl" "advocin,danofloxacine,danofloxacino,danofloxacinum" "73601-7,73623-1,73646-2"
|
||||
"DPS" 2955 "Dapsone" "Other antibacterials" "D10AX05,J04BA02,QD10AX05,QJ04BA02" "Drugs for treatment of lepra" "Drugs for treatment of lepra" "dao" "aczone,atrisone,avlosulfon,avlosulfone,avlosulphone,benzenamide,benzenamine,bissulfone,bissulphone,croysulfone,croysulphone,dapson,dapsona,dapsonum,daspone,diaphenylsulfon,diaphenylsulfone,diaphenylsulphon,diaphenylsulphone,diphenasone,diphone,disulfone,disulone,disulphone,dubronax,dumitone,eporal,medapsol,novophone,servidapson,sulfadione,sulfona,sulfonyldianiline,sulphadione,sulphonyldianiline,tarimyl,udolac,undolac" 50 "mg" "51698-9,9747-7"
|
||||
"DPS" 2955 "Dapsone" "Other antibacterials" "D10AX05,J04BA02,QD10AX05,QJ04BA02" "Drugs for treatment of lepra" "Drugs for treatment of lepra" "NA" "aczone,atrisone,avlosulfon,avlosulfone,avlosulphone,benzenamide,benzenamine,bissulfone,bissulphone,croysulfone,croysulphone,dapson,dapsona,dapsonum,daspone,diaphenylsulfon,diaphenylsulfone,diaphenylsulphon,diaphenylsulphone,diphenasone,diphone,disulfone,disulone,disulphone,dubronax,dumitone,eporal,medapsol,novophone,servidapson,sulfadione,sulfona,sulfonyldianiline,sulphadione,sulphonyldianiline,tarimyl,udolac,undolac" 50 "mg" "51698-9,9747-7"
|
||||
"DAP" 16134395 "Daptomycin" "Other antibacterials" "J01XX09,QJ01XX09" "Other antibacterials" "Other antibacterials" "dap,dapt,dapt25,dapt50,daptom" "cidecin,cubicin,dapcin,daptomicina,daptomycine,daptomycinum,deptomycin" 0.28 "g" "35787-1,35788-9,35789-7,41691-7"
|
||||
"DFX" 487101 "Delafloxacin" "Fluoroquinolones" "J01MA23,QJ01MA23" "NA" "baxdela,delafloxacinum,quofenix" 0.9 "g" 0.6 "g" "88885-9,90447-4,93790-4"
|
||||
"DLM" 6480466 "Delamanid" "Antimycobacterials" "J04AK06,QJ04AK06" "Drugs for treatment of tuberculosis" "Other drugs for treatment of tuberculosis" "dela" "deltyba" 0.2 "g" "93851-4,96109-4"
|
||||
@@ -184,7 +184,7 @@
|
||||
"ERV" 54726192 "Eravacycline" "Tetracyclines" "J01AA13,QJ01AA13" "Tetracyclines" "Tetracyclines" "erav" "xerava" 0.14 "g" "100049-6,85423-2,93767-2"
|
||||
"ETP" 150610 "Ertapenem" "Carbapenems" "J01DH03,QJ01DH03" "Other beta-lactam antibacterials" "Carbapenems" "erta,ertape,etp" "ertapenemsalt,invanz" 1 "g" "101486-9,35799-6,35800-2,35801-0,35802-8"
|
||||
"ERY" 12560 "Erythromycin" "Macrolides/lincosamides" "D10AF02,J01FA01,QD10AF02,QJ01FA01,QJ51FA01,QS01AA17,S01AA17" "Macrolides, lincosamides and streptogramins" "Macrolides" "e,em,ery,ery32,eryt,eryth" "abboticin,abomacetin,acneryne,acnesol,aknemycin,aknin,benzamycin,derimer,deripil,dotycin,dumotrycin,emgel,emuvin,emycin,endoeritrin,erecin,erisone,eritomicina,eritrocina,eritromicina,ermycin,eryacne,eryacnen,erycen,erycette,erycinum,eryderm,erydermer,erygel,eryhexal,erymax,erymed,erysafe,erytab,erythro,erythroderm,erythrogran,erythroguent,erythromast,erythromid,erythromycine,erythromycinum,erytop,erytrociclin,ilocaps,ilosone,iloticina,ilotycin,inderm,latotryd,lederpax,mephamycin,mercina,oftamolets,pantoderm,pantodrin,pantomicina,pharyngocin,primacine,propiocine,proterytrin,retcin,robimycin,sansac,spotex,staticin,stiemicyn,stiemycin,tiprocin,torlamicina,wemid" 2 "g" 1 "g" "100050-4,11576-6,12298-6,16829-4,16830-2,18919-1,18920-9,20380-2,232-9,233-7,234-5,235-2,236-0,23633-1,237-8,238-6,239-4,25224-7,25275-9,3597-2,7009-4"
|
||||
"ETH" 14052 "Ethambutol" "Antimycobacterials" "J04AK02,QJ04AK02" "Drugs for treatment of tuberculosis" "Other drugs for treatment of tuberculosis" "emb,etha,ethamb" "aethambutolum,dadibutol,diambutol,etambutol,etambutolo,ethambutolum,myambutol,purderal,servambutol,tibutol" 1.2 "g" 1.2 "g" "100051-2,16841-9,18921-7,20381-0,23625-7,240-2,241-0,242-8,243-6,25187-6,25194-2,25195-9,25230-4,25404-5,3607-9,42645-2,42646-0,55154-9,55674-6,56025-0,7010-2,89491-5"
|
||||
"ETH" 14052 "Ethambutol" "Antimycobacterials" "J04AK02,QJ04AK02" "Drugs for treatment of tuberculosis" "Other drugs for treatment of tuberculosis" "etha,ethamb" "aethambutolum,dadibutol,diambutol,etambutol,etambutolo,ethambutolum,myambutol,purderal,servambutol,tibutol" 1.2 "g" 1.2 "g" "100051-2,16841-9,18921-7,20381-0,23625-7,240-2,241-0,242-8,243-6,25187-6,25194-2,25195-9,25230-4,25404-5,3607-9,42645-2,42646-0,55154-9,55674-6,56025-0,7010-2,89491-5"
|
||||
"ETI" 456476 "Ethambutol/isoniazid" "Antimycobacterials" "J04AM03,QJ04AM03" "Drugs for treatment of tuberculosis" "Combinations of drugs for treatment of tuberculosis" "NA" "NA" "NA"
|
||||
"ETI1" 2761171 "Ethionamide" "Antimycobacterials" "J04AD03,QJ04AD03" "Drugs for treatment of tuberculosis" "Thiocarbamide derivatives" "ethi,ethion" "aethionamidum,aetina,aetiva,amidazin,amidazine,atina,ethimide,ethina,ethinamide,ethionamidum,ethioniamide,ethylisothiamide,ethyonomide,etimid,etiocidan,etionamid,etionamida,etionamide,etioniamid,etionid,etionizin,etionizina,etionizine,fatoliamid,iridocin,iridozin,isothin,isotiamida,itiocide,nicotion,nisotin,nizotin,rigenicid,sertinon,teberus,thianid,thianide,thioamide,thiodine,thiomid,thioniden,tianid,tiomid,trecator,trekator,trescatyl,trescazide,tubenamide,tubermin,tuberoid,tuberoson" 0.75 "g" "16099-4,16845-0,18922-5,20382-8,23617-4,25183-5,25196-7,25198-3,25231-2,41693-3,42647-8,42648-6,7011-0,96110-2"
|
||||
"ETO" 6034 "Ethopabate" "Other antibacterials" "QP51AX17" "NA" "ethopabat" "NA"
|
||||
@@ -202,7 +202,7 @@
|
||||
"FLM" 3374 "Flumequine" "Quinolones" "J01MB07,QJ01MB07" "Quinolone antibacterials" "Other quinolones" "flumeq" "apurone,fantacin,flumequina,flumequino,flumequinum,flumigal,flumiquil,flumisol,flumix,imequyl" 1.2 "g" "55675-3,55676-1,55677-9,55678-7"
|
||||
"FLR1" 71260 "Flurithromycin" "Macrolides/lincosamides" "J01FA14,QJ01FA14" "Macrolides, lincosamides and streptogramins" "Macrolides" "NA" "abbot,beritromicina,berythromycin,berythromycine,berythromycinum,flurithromycine,flurithromycinum,fluritromicina,fluritromycinum,flurizic,mizar" 0.75 "g" "NA"
|
||||
"FFL" 214356 "Fosfluconazole" "Antifungals/antimycotics" "NA" "NA" "fosfluconazol,procif,prodif" "NA"
|
||||
"FOS" 446987 "Fosfomycin" "Phosphonics" "J01XX01,QJ01XX01,QS02AA17,S02AA17" "Other antibacterials" "Other antibacterials" "ff,fm,fo,fof,fos,fosf,fosfom,fosmyc" "fosfocina,fosfomicin,fosfomicina,fosfomycine,fosfomycinum,fosfonomycin,infectophos,phosphonemycin,phosphonomycin,veramina" 3 "g" 8 "g" "25596-8,25653-7,35809-3,35810-1"
|
||||
"FOS" 446987 "Fosfomycin" "Other antibacterials" "J01XX01,QJ01XX01,QS02AA17,S02AA17" "Other antibacterials" "Other antibacterials" "ff,fm,fo,fof,fos,fosf,fosfom,fosmyc" "fosfocina,fosfomicin,fosfomicina,fosfomycine,fosfomycinum,fosfonomycin,infectophos,phosphonemycin,phosphonomycin,veramina" 3 "g" 8 "g" "25596-8,25653-7,35809-3,35810-1"
|
||||
"FMD" 572 "Fosmidomycin" "Other antibacterials" "NA" "NA" "fosmidomicina,fosmidomycina,fosmidomycine,fosmidomycinsalt,fosmidomycinum" "NA"
|
||||
"FRM" 8378 "Framycetin" "Aminoglycosides" "D09AA01,QD09AA01,QJ01GB91,QR01AX08,QS01AA07,R01AX08,S01AA07" "fram,framyc" "actilin,actiline,antibiotique,bycomycin,enterfram,fradiomycin,fradiomycinum,framicetina,framidal,framycetine,framycetinum,framycin,framygen,francetin,jernadex,myacyne,mycerin,mycifradin,neobrettin,neolate,neomas,neomcin,neomicina,neomin,neomycine,neomycinum,nivemycin,soframycin,soframycine" "18926-6,257-6,258-4,259-2,260-0,55679-5"
|
||||
"FUR" 6870646 "Furazidin" "Other antibacterials" "J01XE03,QJ01XE03" "Other antibacterials" "Nitrofuran derivatives" "NA" "akritoin,furagin,furaginum,furamag,furazidine,hydantoin" 0.3 "g" "NA"
|
||||
@@ -268,7 +268,7 @@
|
||||
"MET" 6087 "Meticillin" "Beta-lactams/penicillins" "J01CF03,QJ01CF03,QJ51CF03" "Beta-lactam antibacterials, penicillins" "Beta-lactamase resistant penicillins" "methic,meti" "belfacillin,celbenin,celpilline,cinopenil,dimocillin,estafcilina,flabelline,lucopenin,metacillin,methcillin,methicillin,methicillinanhydrous,methicillinhydrate,methicillinsalt,methicillinum,methycillin,meticilina,meticillina,meticilline,meticillinsalt,meticillinum,penaureus,penysol,staficyn,staphcillin,synticillin" 4 "g" "NA"
|
||||
"MTP" 68590 "Metioprim" "Other antibacterials" "NA" "NA" "methioprim,metioprima,metioprime,metioprimum" "NA"
|
||||
"MXT" 3047729 "Metioxate" "Fluoroquinolones" "NA" "NA" "metioxato,metioxatum" "NA"
|
||||
"MTR" 4173 "Metronidazole" "Other antibacterials" "A01AB17,D06BX01,G01AF01,J01XD01,P01AB01,QA01AB17,QD06BX01,QG01AF01,QJ01XD01,QP51CA01" "Other antibacterials" "Imidazole derivatives" "metr,metron,mnz,mtz" "acromona,anagiardil,arilin,atrivyl,bexon,clont,danizol,deflamon,donnan,efloran,elyzol,entizol,eumin,flagemona,flagesol,flagil,flagyl,flazol,flegyl,florazole,fossyol,giatricol,gineflavir,givagil,hydroxydimetridazole,hydroxymetronidazole,izoklion,klion,klont,mepagyl,meronidal,metric,metrolag,metrolyl,metromidol,metronidazolo,metronidazolum,metroplex,metrotop,mexibol,monagyl,monasin,nalox,nidagyl,noritate,novonidazol,nuvessa,orvagil,polibiotic,protostat,rathimed,rosaced,rosased,sanatrichom,satric,takimetol,trichazol,trichex,trichobrol,trichocide,trichomol,trichopal,trichopol,tricocet,tricom,trikacide,trikamon,trikhopol,trikojol,trikozol,trimeks,trivazol,vagilen,vagimid,vandazole,vertisal,wagitran,zadstat,zidoval" 2 "g" 1.5 "g" "10991-8,18946-4,326-9,327-7,328-5,329-3,7031-8"
|
||||
"MTR" 4173 "Metronidazole" "Other antibacterials" "A01AB17,D06BX01,G01AF01,J01XD01,P01AB01,QA01AB17,QD06BX01,QG01AF01,QJ01XD01,QP51CA01" "Other antibacterials" "Imidazole derivatives" "metr,metron,mnz" "acromona,anagiardil,arilin,atrivyl,bexon,clont,danizol,deflamon,donnan,efloran,elyzol,entizol,eumin,flagemona,flagesol,flagil,flagyl,flazol,flegyl,florazole,fossyol,giatricol,gineflavir,givagil,hydroxydimetridazole,hydroxymetronidazole,izoklion,klion,klont,mepagyl,meronidal,metric,metrolag,metrolyl,metromidol,metronidazolo,metronidazolum,metroplex,metrotop,mexibol,monagyl,monasin,nalox,nidagyl,noritate,novonidazol,nuvessa,orvagil,polibiotic,protostat,rathimed,rosaced,rosased,sanatrichom,satric,takimetol,trichazol,trichex,trichobrol,trichocide,trichomol,trichopal,trichopol,tricocet,tricom,trikacide,trikamon,trikhopol,trikojol,trikozol,trimeks,trivazol,vagilen,vagimid,vandazole,vertisal,wagitran,zadstat,zidoval" 2 "g" 1.5 "g" "10991-8,18946-4,326-9,327-7,328-5,329-3,7031-8"
|
||||
"MEZ" 656511 "Mezlocillin" "Beta-lactams/penicillins" "J01CA10,QJ01CA10" "Beta-lactam antibacterials, penicillins" "Penicillins with extended spectrum" "mez,mezl,mezlo,mz" "baycipen,baypen,mezlin,mezlocilina,mezlocilline,mezlocillinsalt,mezlocillinum,multocillin" 6 "g" "18947-2,330-1,331-9,332-7,333-5,3820-8,41702-2,54194-6,54195-3,54196-1"
|
||||
"MSU" "Mezlocillin/sulbactam" "Beta-lactams/penicillins" "NA" "mezsul" "NA" "54194-6,54195-3,54196-1"
|
||||
"MIF" 477468 "Micafungin" "Antifungals/antimycotics" "J02AX05,QJ02AX05" "Antimycotics for systemic use" "Other antimycotics for systemic use" "mica,micafu" "fungard,funguard,micafungina,micafunginsalt,mycamine" 0.1 "g" "53812-4,58418-5,65340-2,85048-7"
|
||||
@@ -339,7 +339,7 @@
|
||||
"PMR" 5284447 "Pimaricin" "Antifungals/antimycotics" "NA" "natamycin" "delvocid,delvolan,delvopos,mycophyt,myprozine,natacyn,natafucin,natajen,natamatrix,natamax,natamicina,natamycin,natamycine,natamycinum,pimafucin,pimaracin,pimaricine,pimarizin,synogil,tennecetin" "NA"
|
||||
"PPA" 4831 "Pipemidic acid" "Quinolones" "J01MB04,QJ01MB04" "Quinolone antibacterials" "Other quinolones" "pipaci,pipz,pizu" "deblaston,dolcol,filtrax,karunomazin,memento,nuril,palin,pipedac,pipemid,pipemidate,pipemidic,pipemidicacid,pipram,pipurin,tractur,uromidin,urosten,uroval" 0.8 "g" "NA"
|
||||
"PIP" 43672 "Piperacillin" "Beta-lactams/penicillins" "J01CA12,QJ01CA12" "Beta-lactam antibacterials, penicillins" "Penicillins with extended spectrum" "pi,pip,pipc,pipe,pipera,pp" "penmalin,pentcillin,peperacillin,peracin,piperacilina,piperacillina,piperacilline,piperacillinhydrate,piperacillinum,pipercillin,pipracil,tazocin" 14 "g" "101490-1,101491-9,18969-6,18970-4,25268-4,3972-7,407-7,408-5,409-3,410-1,411-9,412-7,413-5,414-3,54197-9,54198-7,54199-5,55704-1,7043-3,7044-1"
|
||||
"PIS" "Piperacillin/sulbactam" "Beta-lactams/penicillins" "NA" "NA" "NA" 14 "g" "54197-9,54198-7,54199-5,55704-1"
|
||||
"PIS" "Piperacillin/sulbactam" "Beta-lactams/penicillins" "J01CR05,QJ01CR05" "NA" "NA" 14 "g" "54197-9,54198-7,54199-5,55704-1"
|
||||
"TZP" 461573 "Piperacillin/tazobactam" "Beta-lactams/penicillins" "J01CR05,QJ01CR05" "Beta-lactam antibacterials, penicillins" "Combinations of penicillins, incl. beta-lactamase inhibitors" "p/t,piptaz,piptazo,pit,pita,pt,ptc,ptz,tzp" "piptazobactam,tazonam,zobactin,zosyn" 14 "g" "101491-9,18970-4,411-9,412-7,413-5,414-3,7044-1"
|
||||
"PRC" 71978 "Piridicillin" "Beta-lactams/penicillins" "NA" "NA" "NA" "NA"
|
||||
"PRL" 157385 "Pirlimycin" "Macrolides/lincosamides" "QJ51FF90" "pirlim" "pirlimycina,pirlimycine,pirlimycinum,pirsue" "35829-1,35830-9,35831-7"
|
||||
@@ -370,7 +370,7 @@
|
||||
"RBC" 44631912 "Ribociclib" "Antifungals/antimycotics" "L01EF02,QL01EF02" "Antimycotics for systemic use" "Triazole derivatives" "ribo" "kisqali" 0.45 "g" "NA"
|
||||
"RST" 33042 "Ribostamycin" "Aminoglycosides" "J01GB10,QJ01GB10" "Aminoglycoside antibacterials" "Other aminoglycosides" "NA" "exaluren,hetangmycin,ribastamin,ribostamicina,ribostamycine,ribostamycinum,vistamycin,xylostatin" 1 "g" "NA"
|
||||
"RID1" 16659285 "Ridinilazole" "Other antibacterials" "NA" "NA" "ridinilazol" "NA"
|
||||
"RIB" 135398743 "Rifabutin" "Antimycobacterials" "J04AB04,QJ04AB04" "Drugs for treatment of tuberculosis" "Antibiotics" "ansamy,rfb,rifb" "alfacid,ansamicin,ansamycins,ansatipin,ansatipine,assatipin,mycobutin,rifabutinum" 0.15 "g" "100699-8,16100-0,16386-5,16387-3,19149-4,20386-9,23630-7,24032-5,25199-1,25200-7,25201-5,42655-1,42656-9,54183-9,96113-6"
|
||||
"RIB" 135398743 "Rifabutin" "Antimycobacterials" "J04AB04,QJ04AB04" "Drugs for treatment of tuberculosis" "Antibiotics" "ansamy,rifb" "alfacid,ansamicin,ansamycins,ansatipin,ansatipine,assatipin,mycobutin,rifabutinum" 0.15 "g" "100699-8,16100-0,16386-5,16387-3,19149-4,20386-9,23630-7,24032-5,25199-1,25200-7,25201-5,42655-1,42656-9,54183-9,96113-6"
|
||||
"RIF" 135398735 "Rifampicin" "Antimycobacterials" "J04AB02,QJ04AB02,QJ54AB02" "Drugs for treatment of tuberculosis" "Antibiotics" "rifa,rifamp" "abrifam,archidyn,arficin,arzide,benemicin,doloresum,eremfat,famcin,fenampicin,rifadin,rifadine,rifagen,rifaldazin,rifaldazine,rifaldin,rifam,rifamor,rifampicina,rifampicine,rifampicinum,rifampin,rifamsolin,rifapiam,rifaprodin,rifcin,rifinah,rifobac,rifoldin,rifoldine,riforal,rimactan,rimactane,rimactazid,rimactizid,rimazid,sinerdol,tubocin" 0.6 "g" 0.6 "g" "NA"
|
||||
"REI" 135483893 "Rifampicin/ethambutol/isoniazid" "Antimycobacterials" "J04AM07,QJ04AM07" "Drugs for treatment of tuberculosis" "Combinations of drugs for treatment of tuberculosis" "NA" "isonarif,rifamate,rifamazid" "NA"
|
||||
"RFI" "Rifampicin/isoniazid" "Antimycobacterials" "J04AM02,QJ04AM02" "Drugs for treatment of tuberculosis" "Combinations of drugs for treatment of tuberculosis" "NA" "NA" "NA"
|
||||
@@ -391,6 +391,7 @@
|
||||
"SRC" 54681908 "Sarecycline" "Tetracyclines" "J01AA14,QJ01AA14" "Tetracyclines" "Tetracyclines" "NA" "sareciclina,seysara" 0.1 "g" "NA"
|
||||
"SRX" 9933415 "Sarmoxicillin" "Beta-lactams/penicillins" "NA" "NA" "sarmoxillina,sarmoxilline,sarmoxillinum" "NA"
|
||||
"SEC" 71815 "Secnidazole" "Other antibacterials" "P01AB07" "NA" "flagentyl,secnidal,secnidazolum,secnil,sindose,solosec" 2 "g" "NA"
|
||||
"SMF" "Simvastatin/fenofibrate" "Antimycobacterials" "C10BA04,QC10BA04" "Drugs for treatment of tuberculosis" "Other drugs for treatment of tuberculosis" "simv" "NA" "NA"
|
||||
"SIS" 36119 "Sisomicin" "Aminoglycosides" "J01GB08,QJ01GB08" "Aminoglycoside antibacterials" "Other aminoglycosides" "siso,sisomy" "rickamicin,salvamina,sisomicina,sisomicine,sisomicinum,sisomin,sisomycin,sissomicin,sizomycin" 0.24 "g" "18979-5,447-3,448-1,449-9,450-7,55714-0"
|
||||
"SIT" 461399 "Sitafloxacin" "Fluoroquinolones" "J01MA21,QJ01MA21" "sitafl" "gracevit" 0.1 "g" "NA"
|
||||
"SDA" 2724368 "Sodium aminosalicylate" "Antimycobacterials" "J04AA02,QJ04AA02" "Drugs for treatment of tuberculosis" "Aminosalicylic acid and derivatives" "NA" "bactylan,lepasen,monopas,tubersan" 14 "g" 14 "g" "NA"
|
||||
@@ -494,4 +495,4 @@
|
||||
"VOR" 71616 "Voriconazole" "Antifungals/antimycotics" "J02AC03,QJ02AC03" "Antimycotics for systemic use" "Triazole derivatives" "vori,vorico,vrc" "vfend,voriconazol,voriconazolum,voriconzole,vorikonazole" 0.4 "g" 0.4 "g" "32379-0,35862-2,35863-0,38370-3,41199-1,41200-7,53902-3,73676-9,80553-1,80651-3"
|
||||
"XBR" 72144 "Xibornol" "Other antibacterials" "J01XX02,QJ01XX02" "Other antibacterials" "Other antibacterials" "NA" "bactacine,bracen,nanbacine,xibornolo,xibornolum" "NA"
|
||||
"ZID" 77846445 "Zidebactam" "Other antibacterials" "NA" "NA" "zidebactamsalt" "NA"
|
||||
"ZFD" "Zoliflodacin" "NA" "zol" "NA" "NA"
|
||||
"ZFD" "Zoliflodacin" "NA" "NA" "NA" "NA"
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -1 +1 @@
|
||||
6dc4dded108052760bfb626df03435e2
|
||||
5908f9e6e7687dfb8301d27fb26d1790
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
125
man/amr-tidymodels.Rd
Normal file
125
man/amr-tidymodels.Rd
Normal file
@@ -0,0 +1,125 @@
|
||||
% Generated by roxygen2: do not edit by hand
|
||||
% Please edit documentation in R/tidymodels.R
|
||||
\name{amr-tidymodels}
|
||||
\alias{amr-tidymodels}
|
||||
\alias{all_mic}
|
||||
\alias{all_mic_predictors}
|
||||
\alias{all_sir}
|
||||
\alias{all_sir_predictors}
|
||||
\alias{step_mic_log2}
|
||||
\alias{step_sir_numeric}
|
||||
\title{AMR Extensions for Tidymodels}
|
||||
\usage{
|
||||
all_mic()
|
||||
|
||||
all_mic_predictors()
|
||||
|
||||
all_sir()
|
||||
|
||||
all_sir_predictors()
|
||||
|
||||
step_mic_log2(recipe, ..., role = NA, trained = FALSE, columns = NULL,
|
||||
skip = FALSE, id = recipes::rand_id("mic_log2"))
|
||||
|
||||
step_sir_numeric(recipe, ..., role = NA, trained = FALSE, columns = NULL,
|
||||
skip = FALSE, id = recipes::rand_id("sir_numeric"))
|
||||
}
|
||||
\arguments{
|
||||
\item{recipe}{A recipe object. The step will be added to the sequence of
|
||||
operations for this recipe.}
|
||||
|
||||
\item{...}{One or more selector functions to choose variables for this step.
|
||||
See \code{\link[recipes:selections]{selections()}} for more details.}
|
||||
|
||||
\item{role}{Not used by this step since no new variables are created.}
|
||||
|
||||
\item{trained}{A logical to indicate if the quantities for preprocessing have
|
||||
been estimated.}
|
||||
|
||||
\item{skip}{A logical. Should the step be skipped when the recipe is baked by
|
||||
\code{\link[recipes:bake]{bake()}}? While all operations are baked when \code{\link[recipes:prep]{prep()}} is run, some
|
||||
operations may not be able to be conducted on new data (e.g. processing the
|
||||
outcome variable(s)). Care should be taken when using \code{skip = TRUE} as it
|
||||
may affect the computations for subsequent operations.}
|
||||
|
||||
\item{id}{A character string that is unique to this step to identify it.}
|
||||
}
|
||||
\description{
|
||||
This family of functions allows using AMR-specific data types such as \verb{<mic>} and \verb{<sir>} inside \code{tidymodels} pipelines.
|
||||
}
|
||||
\details{
|
||||
You can read more in our online \href{https://amr-for-r.org/articles/AMR_with_tidymodels.html}{AMR with tidymodels introduction}.
|
||||
|
||||
Tidyselect helpers include:
|
||||
\itemize{
|
||||
\item \code{\link[=all_mic]{all_mic()}} and \code{\link[=all_mic_predictors]{all_mic_predictors()}} to select \verb{<mic>} columns
|
||||
\item \code{\link[=all_sir]{all_sir()}} and \code{\link[=all_sir_predictors]{all_sir_predictors()}} to select \verb{<sir>} columns
|
||||
}
|
||||
|
||||
Pre-processing pipeline steps include:
|
||||
\itemize{
|
||||
\item \code{\link[=step_mic_log2]{step_mic_log2()}} to convert MIC columns to numeric (via \code{as.numeric()}) and apply a log2 transform, to be used with \code{\link[=all_mic_predictors]{all_mic_predictors()}}
|
||||
\item \code{\link[=step_sir_numeric]{step_sir_numeric()}} to convert SIR columns to numeric (via \code{as.numeric()}), to be used with \code{\link[=all_sir_predictors]{all_sir_predictors()}}: \code{"S"} = 1, \code{"I"}/\code{"SDD"} = 2, \code{"R"} = 3. All other values are rendered \code{NA}. Keep this in mind for further processing, especially if the model does not allow for \code{NA} values.
|
||||
}
|
||||
|
||||
These steps integrate with \code{recipes::recipe()} and work like standard preprocessing steps. They are useful for preparing data for modelling, especially with classification models.
|
||||
}
|
||||
\examples{
|
||||
if (require("tidymodels")) {
|
||||
|
||||
# The below approach formed the basis for this paper: DOI 10.3389/fmicb.2025.1582703
|
||||
# Presence of ESBL genes was predicted based on raw MIC values.
|
||||
|
||||
|
||||
# example data set in the AMR package
|
||||
esbl_isolates
|
||||
|
||||
# Prepare a binary outcome and convert to ordered factor
|
||||
data <- esbl_isolates \%>\%
|
||||
mutate(esbl = factor(esbl, levels = c(FALSE, TRUE), ordered = TRUE))
|
||||
|
||||
# Split into training and testing sets
|
||||
split <- initial_split(data)
|
||||
training_data <- training(split)
|
||||
testing_data <- testing(split)
|
||||
|
||||
# Create and prep a recipe with MIC log2 transformation
|
||||
mic_recipe <- recipe(esbl ~ ., data = training_data) \%>\%
|
||||
|
||||
# Optionally remove non-predictive variables
|
||||
remove_role(genus, old_role = "predictor") \%>\%
|
||||
|
||||
# Apply the log2 transformation to all MIC predictors
|
||||
step_mic_log2(all_mic_predictors()) \%>\%
|
||||
|
||||
# And apply the preparation steps
|
||||
prep()
|
||||
|
||||
# View prepped recipe
|
||||
mic_recipe
|
||||
|
||||
# Apply the recipe to training and testing data
|
||||
out_training <- bake(mic_recipe, new_data = NULL)
|
||||
out_testing <- bake(mic_recipe, new_data = testing_data)
|
||||
|
||||
# Fit a logistic regression model
|
||||
fitted <- logistic_reg(mode = "classification") \%>\%
|
||||
set_engine("glm") \%>\%
|
||||
fit(esbl ~ ., data = out_training)
|
||||
|
||||
# Generate predictions on the test set
|
||||
predictions <- predict(fitted, out_testing) \%>\%
|
||||
bind_cols(out_testing)
|
||||
|
||||
# Evaluate predictions using standard classification metrics
|
||||
our_metrics <- metric_set(accuracy, kap, ppv, npv)
|
||||
metrics <- our_metrics(predictions, truth = esbl, estimate = .pred_class)
|
||||
|
||||
# Show performance
|
||||
metrics
|
||||
}
|
||||
}
|
||||
\seealso{
|
||||
\code{\link[recipes:recipe]{recipes::recipe()}}, \code{\link[=as.mic]{as.mic()}}, \code{\link[=as.sir]{as.sir()}}
|
||||
}
|
||||
\keyword{internal}
|
@@ -181,7 +181,7 @@ The \code{\link[=not_intrinsic_resistant]{not_intrinsic_resistant()}} function c
|
||||
\item \code{\link[=aminoglycosides]{aminoglycosides()}} can select: \cr amikacin (AMK), amikacin/fosfomycin (AKF), apramycin (APR), arbekacin (ARB), astromicin (AST), bekanamycin (BEK), dibekacin (DKB), framycetin (FRM), gentamicin (GEN), gentamicin-high (GEH), habekacin (HAB), hygromycin (HYG), isepamicin (ISE), kanamycin (KAN), kanamycin-high (KAH), kanamycin/cephalexin (KAC), micronomicin (MCR), neomycin (NEO), netilmicin (NET), pentisomicin (PIM), plazomicin (PLZ), propikacin (PKA), ribostamycin (RST), sisomicin (SIS), streptoduocin (STR), streptomycin (STR1), streptomycin-high (STH), tobramycin (TOB), and tobramycin-high (TOH)
|
||||
\item \code{\link[=aminopenicillins]{aminopenicillins()}} can select: \cr amoxicillin (AMX) and ampicillin (AMP)
|
||||
\item \code{\link[=antifungals]{antifungals()}} can select: \cr amorolfine (AMO), amphotericin B (AMB), amphotericin B-high (AMH), anidulafungin (ANI), butoconazole (BUT), caspofungin (CAS), ciclopirox (CIX), clotrimazole (CTR), econazole (ECO), fluconazole (FLU), flucytosine (FCT), fosfluconazole (FFL), griseofulvin (GRI), hachimycin (HCH), ibrexafungerp (IBX), isavuconazole (ISV), isoconazole (ISO), itraconazole (ITR), ketoconazole (KET), manogepix (MGX), micafungin (MIF), miconazole (MCZ), nystatin (NYS), oteseconazole (OTE), pimaricin (PMR), posaconazole (POS), rezafungin (RZF), ribociclib (RBC), sulconazole (SUC), terbinafine (TRB), terconazole (TRC), and voriconazole (VOR)
|
||||
\item \code{\link[=antimycobacterials]{antimycobacterials()}} can select: \cr 4-aminosalicylic acid (AMA), calcium aminosalicylate (CLA), capreomycin (CAP), clofazimine (CLF), delamanid (DLM), enviomycin (ENV), ethambutol (ETH), ethambutol/isoniazid (ETI), ethionamide (ETI1), isoniazid (INH), isoniazid/sulfamethoxazole/trimethoprim/pyridoxine (IST), morinamide (MRN), p-aminosalicylic acid (PAS), pretomanid (PMD), protionamide (PTH), pyrazinamide (PZA), rifabutin (RIB), rifampicin (RIF), rifampicin/ethambutol/isoniazid (REI), rifampicin/isoniazid (RFI), rifampicin/pyrazinamide/ethambutol/isoniazid (RPEI), rifampicin/pyrazinamide/isoniazid (RPI), rifamycin (RFM), rifapentine (RFP), sodium aminosalicylate (SDA), streptomycin/isoniazid (STI), terizidone (TRZ), thioacetazone (TAT), thioacetazone/isoniazid (THI1), tiocarlide (TCR), and viomycin (VIO)
|
||||
\item \code{\link[=antimycobacterials]{antimycobacterials()}} can select: \cr 4-aminosalicylic acid (AMA), calcium aminosalicylate (CLA), capreomycin (CAP), clofazimine (CLF), delamanid (DLM), enviomycin (ENV), ethambutol (ETH), ethambutol/isoniazid (ETI), ethionamide (ETI1), isoniazid (INH), isoniazid/sulfamethoxazole/trimethoprim/pyridoxine (IST), morinamide (MRN), p-aminosalicylic acid (PAS), pretomanid (PMD), protionamide (PTH), pyrazinamide (PZA), rifabutin (RIB), rifampicin (RIF), rifampicin/ethambutol/isoniazid (REI), rifampicin/isoniazid (RFI), rifampicin/pyrazinamide/ethambutol/isoniazid (RPEI), rifampicin/pyrazinamide/isoniazid (RPI), rifamycin (RFM), rifapentine (RFP), simvastatin/fenofibrate (SMF), sodium aminosalicylate (SDA), streptomycin/isoniazid (STI), terizidone (TRZ), thioacetazone (TAT), thioacetazone/isoniazid (THI1), tiocarlide (TCR), and viomycin (VIO)
|
||||
\item \code{\link[=betalactams]{betalactams()}} can select: \cr amoxicillin (AMX), amoxicillin/clavulanic acid (AMC), amoxicillin/sulbactam (AXS), ampicillin (AMP), ampicillin/sulbactam (SAM), apalcillin (APL), aspoxicillin (APX), azidocillin (AZD), azlocillin (AZL), aztreonam (ATM), aztreonam/avibactam (AZA), aztreonam/nacubactam (ANC), bacampicillin (BAM), benzathine benzylpenicillin (BNB), benzathine phenoxymethylpenicillin (BNP), benzylpenicillin (PEN), benzylpenicillin screening test (PEN-S), biapenem (BIA), carbenicillin (CRB), carindacillin (CRN), carumonam (CAR), cefacetrile (CAC), cefaclor (CEC), cefadroxil (CFR), cefalexin (LEX), cefaloridine (RID), cefalotin (CEP), cefamandole (MAN), cefapirin (HAP), cefatrizine (CTZ), cefazedone (CZD), cefazolin (CZO), cefcapene (CCP), cefcapene pivoxil (CCX), cefdinir (CDR), cefditoren (DIT), cefditoren pivoxil (DIX), cefepime (FEP), cefepime/amikacin (CFA), cefepime/clavulanic acid (CPC), cefepime/enmetazobactam (FPE), cefepime/nacubactam (FNC), cefepime/tazobactam (FPT), cefepime/zidebactam (FPZ), cefetamet (CAT), cefetamet pivoxil (CPI), cefetecol (CCL), cefetrizole (CZL), cefiderocol (FDC), cefixime (CFM), cefmenoxime (CMX), cefmetazole (CMZ), cefodizime (DIZ), cefonicid (CID), cefoperazone (CFP), cefoperazone/sulbactam (CSL), ceforanide (CND), cefoselis (CSE), cefotaxime (CTX), cefotaxime screening test (CTX-S), cefotaxime/clavulanic acid (CTC), cefotaxime/sulbactam (CTS), cefotetan (CTT), cefotiam (CTF), cefotiam hexetil (CHE), cefovecin (FOV), cefoxitin (FOX), cefoxitin screening test (FOX-S), cefozopran (ZOP), cefpimizole (CFZ), cefpiramide (CPM), cefpirome (CPO), cefpodoxime (CPD), cefpodoxime proxetil (CPX), cefpodoxime/clavulanic acid (CDC), cefprozil (CPR), cefquinome (CEQ), cefroxadine (CRD), cefsulodin (CFS), cefsumide (CSU), ceftaroline (CPT), ceftaroline/avibactam (CPA), ceftazidime (CAZ), ceftazidime/avibactam (CZA), ceftazidime/clavulanic acid (CCV), cefteram (CEM), cefteram pivoxil (CPL), ceftezole (CTL), ceftibuten (CTB), ceftiofur (TIO), ceftizoxime (CZX), ceftizoxime alapivoxil (CZP), ceftobiprole (BPR), ceftobiprole medocaril (CFM1), ceftolozane/tazobactam (CZT), ceftriaxone (CRO), ceftriaxone/beta-lactamase inhibitor (CEB), cefuroxime (CXM), cefuroxime axetil (CXA), cephradine (CED), ciclacillin (CIC), clometocillin (CLM), cloxacillin (CLO), dicloxacillin (DIC), doripenem (DOR), epicillin (EPC), ertapenem (ETP), flucloxacillin (FLC), hetacillin (HET), imipenem (IPM), imipenem/EDTA (IPE), imipenem/relebactam (IMR), latamoxef (LTM), lenampicillin (LEN), loracarbef (LOR), mecillinam (MEC), meropenem (MEM), meropenem/nacubactam (MNC), meropenem/vaborbactam (MEV), metampicillin (MTM), meticillin (MET), mezlocillin (MEZ), mezlocillin/sulbactam (MSU), nafcillin (NAF), oxacillin (OXA), oxacillin screening test (OXA-S), panipenem (PAN), penamecillin (PNM), penicillin/novobiocin (PNO), penicillin/sulbactam (PSU), pheneticillin (PHE), phenoxymethylpenicillin (PHN), piperacillin (PIP), piperacillin/sulbactam (PIS), piperacillin/tazobactam (TZP), piridicillin (PRC), pivampicillin (PVM), pivmecillinam (PME), procaine benzylpenicillin (PRB), propicillin (PRP), razupenem (RZM), ritipenem (RIT), ritipenem acoxil (RIA), sarmoxicillin (SRX), sulbenicillin (SBC), sultamicillin (SLT6), talampicillin (TAL), tebipenem (TBP), temocillin (TEM), ticarcillin (TIC), ticarcillin/clavulanic acid (TCC), and tigemonam (TMN)
|
||||
\item \code{\link[=betalactams_with_inhibitor]{betalactams_with_inhibitor()}} can select: \cr amoxicillin/clavulanic acid (AMC), amoxicillin/sulbactam (AXS), ampicillin/sulbactam (SAM), aztreonam/avibactam (AZA), aztreonam/nacubactam (ANC), cefepime/amikacin (CFA), cefepime/clavulanic acid (CPC), cefepime/enmetazobactam (FPE), cefepime/nacubactam (FNC), cefepime/tazobactam (FPT), cefepime/zidebactam (FPZ), cefoperazone/sulbactam (CSL), cefotaxime/clavulanic acid (CTC), cefotaxime/sulbactam (CTS), cefpodoxime/clavulanic acid (CDC), ceftaroline/avibactam (CPA), ceftazidime/avibactam (CZA), ceftazidime/clavulanic acid (CCV), ceftolozane/tazobactam (CZT), ceftriaxone/beta-lactamase inhibitor (CEB), imipenem/relebactam (IMR), meropenem/nacubactam (MNC), meropenem/vaborbactam (MEV), mezlocillin/sulbactam (MSU), penicillin/novobiocin (PNO), penicillin/sulbactam (PSU), piperacillin/sulbactam (PIS), piperacillin/tazobactam (TZP), and ticarcillin/clavulanic acid (TCC)
|
||||
\item \code{\link[=carbapenems]{carbapenems()}} can select: \cr biapenem (BIA), doripenem (DOR), ertapenem (ETP), imipenem (IPM), imipenem/EDTA (IPE), imipenem/relebactam (IMR), meropenem (MEM), meropenem/nacubactam (MNC), meropenem/vaborbactam (MEV), panipenem (PAN), razupenem (RZM), ritipenem (RIT), ritipenem acoxil (RIA), and tebipenem (TBP)
|
||||
|
@@ -5,9 +5,9 @@
|
||||
\alias{antimicrobials}
|
||||
\alias{antibiotics}
|
||||
\alias{antivirals}
|
||||
\title{Data Sets with 616 Antimicrobial Drugs}
|
||||
\title{Data Sets with 617 Antimicrobial Drugs}
|
||||
\format{
|
||||
\subsection{For the \link{antimicrobials} data set: a \link[tibble:tibble]{tibble} with 496 observations and 14 variables:}{
|
||||
\subsection{For the \link{antimicrobials} data set: a \link[tibble:tibble]{tibble} with 497 observations and 14 variables:}{
|
||||
\itemize{
|
||||
\item \code{ab}\cr antimicrobial ID as used in this package (such as \code{AMC}), using the official EARS-Net (European Antimicrobial Resistance Surveillance Network) codes where available. \emph{\strong{This is a unique identifier.}}
|
||||
\item \code{cid}\cr Compound ID as found in PubChem. \emph{\strong{This is a unique identifier.}}
|
||||
@@ -50,7 +50,7 @@ LOINC:
|
||||
}
|
||||
}
|
||||
|
||||
An object of class \code{deprecated_amr_dataset} (inherits from \code{tbl_df}, \code{tbl}, \code{data.frame}) with 496 rows and 14 columns.
|
||||
An object of class \code{deprecated_amr_dataset} (inherits from \code{tbl_df}, \code{tbl}, \code{data.frame}) with 497 rows and 14 columns.
|
||||
|
||||
An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 120 rows and 11 columns.
|
||||
}
|
||||
|
@@ -70,7 +70,7 @@ is_sir_eligible(x, threshold = 0.05)
|
||||
language = get_AMR_locale(), verbose = FALSE, info = interactive(),
|
||||
parallel = FALSE, max_cores = -1, conserve_capped_values = NULL)
|
||||
|
||||
sir_interpretation_history(clean = FALSE)
|
||||
sir_interpretation_history(sir_values = NULL, clean = FALSE)
|
||||
}
|
||||
\arguments{
|
||||
\item{x}{Vector of values (for class \code{\link{mic}}: MIC values in mg/L, for class \code{\link{disk}}: a disk diffusion radius in millimetres).}
|
||||
@@ -147,6 +147,8 @@ The default \code{"standard"} setting ensures cautious handling of uncertain val
|
||||
|
||||
\item{max_cores}{Maximum number of cores to use if \code{parallel = TRUE}. Use a negative value to subtract that number from the available number of cores, e.g. a value of \code{-2} on an 8-core machine means that at most 6 cores will be used. Defaults to \code{-1}. There will never be used more cores than variables to analyse. The available number of cores are detected using \code{\link[parallelly:availableCores]{parallelly::availableCores()}} if that package is installed, and base \R's \code{\link[parallel:detectCores]{parallel::detectCores()}} otherwise.}
|
||||
|
||||
\item{sir_values}{SIR values that were interpreted from MIC or disk diffusion values using \code{\link[=as.sir]{as.sir()}}.}
|
||||
|
||||
\item{clean}{A \link{logical} to indicate whether previously stored results should be forgotten after returning the 'logbook' with results.}
|
||||
}
|
||||
\value{
|
||||
|
@@ -103,7 +103,7 @@ These 35 antimicrobial groups are allowed in the rules (case-insensitive) and ca
|
||||
\item aminoglycosides\cr(amikacin, amikacin/fosfomycin, apramycin, arbekacin, astromicin, bekanamycin, dibekacin, framycetin, gentamicin, gentamicin-high, habekacin, hygromycin, isepamicin, kanamycin, kanamycin-high, kanamycin/cephalexin, micronomicin, neomycin, netilmicin, pentisomicin, plazomicin, propikacin, ribostamycin, sisomicin, streptoduocin, streptomycin, streptomycin-high, tobramycin, and tobramycin-high)
|
||||
\item aminopenicillins\cr(amoxicillin and ampicillin)
|
||||
\item antifungals\cr(amorolfine, amphotericin B, amphotericin B-high, anidulafungin, butoconazole, caspofungin, ciclopirox, clotrimazole, econazole, fluconazole, flucytosine, fosfluconazole, griseofulvin, hachimycin, ibrexafungerp, isavuconazole, isoconazole, itraconazole, ketoconazole, manogepix, micafungin, miconazole, nystatin, oteseconazole, pimaricin, posaconazole, rezafungin, ribociclib, sulconazole, terbinafine, terconazole, and voriconazole)
|
||||
\item antimycobacterials\cr(4-aminosalicylic acid, calcium aminosalicylate, capreomycin, clofazimine, delamanid, enviomycin, ethambutol, ethambutol/isoniazid, ethionamide, isoniazid, isoniazid/sulfamethoxazole/trimethoprim/pyridoxine, morinamide, p-aminosalicylic acid, pretomanid, protionamide, pyrazinamide, rifabutin, rifampicin, rifampicin/ethambutol/isoniazid, rifampicin/isoniazid, rifampicin/pyrazinamide/ethambutol/isoniazid, rifampicin/pyrazinamide/isoniazid, rifamycin, rifapentine, sodium aminosalicylate, streptomycin/isoniazid, terizidone, thioacetazone, thioacetazone/isoniazid, tiocarlide, and viomycin)
|
||||
\item antimycobacterials\cr(4-aminosalicylic acid, calcium aminosalicylate, capreomycin, clofazimine, delamanid, enviomycin, ethambutol, ethambutol/isoniazid, ethionamide, isoniazid, isoniazid/sulfamethoxazole/trimethoprim/pyridoxine, morinamide, p-aminosalicylic acid, pretomanid, protionamide, pyrazinamide, rifabutin, rifampicin, rifampicin/ethambutol/isoniazid, rifampicin/isoniazid, rifampicin/pyrazinamide/ethambutol/isoniazid, rifampicin/pyrazinamide/isoniazid, rifamycin, rifapentine, simvastatin/fenofibrate, sodium aminosalicylate, streptomycin/isoniazid, terizidone, thioacetazone, thioacetazone/isoniazid, tiocarlide, and viomycin)
|
||||
\item betalactams\cr(amoxicillin, amoxicillin/clavulanic acid, amoxicillin/sulbactam, ampicillin, ampicillin/sulbactam, apalcillin, aspoxicillin, azidocillin, azlocillin, aztreonam, aztreonam/avibactam, aztreonam/nacubactam, bacampicillin, benzathine benzylpenicillin, benzathine phenoxymethylpenicillin, benzylpenicillin, benzylpenicillin screening test, biapenem, carbenicillin, carindacillin, carumonam, cefacetrile, cefaclor, cefadroxil, cefalexin, cefaloridine, cefalotin, cefamandole, cefapirin, cefatrizine, cefazedone, cefazolin, cefcapene, cefcapene pivoxil, cefdinir, cefditoren, cefditoren pivoxil, cefepime, cefepime/amikacin, cefepime/clavulanic acid, cefepime/enmetazobactam, cefepime/nacubactam, cefepime/tazobactam, cefepime/zidebactam, cefetamet, cefetamet pivoxil, cefetecol, cefetrizole, cefiderocol, cefixime, cefmenoxime, cefmetazole, cefodizime, cefonicid, cefoperazone, cefoperazone/sulbactam, ceforanide, cefoselis, cefotaxime, cefotaxime screening test, cefotaxime/clavulanic acid, cefotaxime/sulbactam, cefotetan, cefotiam, cefotiam hexetil, cefovecin, cefoxitin, cefoxitin screening test, cefozopran, cefpimizole, cefpiramide, cefpirome, cefpodoxime, cefpodoxime proxetil, cefpodoxime/clavulanic acid, cefprozil, cefquinome, cefroxadine, cefsulodin, cefsumide, ceftaroline, ceftaroline/avibactam, ceftazidime, ceftazidime/avibactam, ceftazidime/clavulanic acid, cefteram, cefteram pivoxil, ceftezole, ceftibuten, ceftiofur, ceftizoxime, ceftizoxime alapivoxil, ceftobiprole, ceftobiprole medocaril, ceftolozane/tazobactam, ceftriaxone, ceftriaxone/beta-lactamase inhibitor, cefuroxime, cefuroxime axetil, cephradine, ciclacillin, clometocillin, cloxacillin, dicloxacillin, doripenem, epicillin, ertapenem, flucloxacillin, hetacillin, imipenem, imipenem/EDTA, imipenem/relebactam, latamoxef, lenampicillin, loracarbef, mecillinam, meropenem, meropenem/nacubactam, meropenem/vaborbactam, metampicillin, meticillin, mezlocillin, mezlocillin/sulbactam, nafcillin, oxacillin, oxacillin screening test, panipenem, penamecillin, penicillin/novobiocin, penicillin/sulbactam, pheneticillin, phenoxymethylpenicillin, piperacillin, piperacillin/sulbactam, piperacillin/tazobactam, piridicillin, pivampicillin, pivmecillinam, procaine benzylpenicillin, propicillin, razupenem, ritipenem, ritipenem acoxil, sarmoxicillin, sulbenicillin, sultamicillin, talampicillin, tebipenem, temocillin, ticarcillin, ticarcillin/clavulanic acid, and tigemonam)
|
||||
\item betalactams_with_inhibitor\cr(amoxicillin/clavulanic acid, amoxicillin/sulbactam, ampicillin/sulbactam, aztreonam/avibactam, aztreonam/nacubactam, cefepime/amikacin, cefepime/clavulanic acid, cefepime/enmetazobactam, cefepime/nacubactam, cefepime/tazobactam, cefepime/zidebactam, cefoperazone/sulbactam, cefotaxime/clavulanic acid, cefotaxime/sulbactam, cefpodoxime/clavulanic acid, ceftaroline/avibactam, ceftazidime/avibactam, ceftazidime/clavulanic acid, ceftolozane/tazobactam, ceftriaxone/beta-lactamase inhibitor, imipenem/relebactam, meropenem/nacubactam, meropenem/vaborbactam, mezlocillin/sulbactam, penicillin/novobiocin, penicillin/sulbactam, piperacillin/sulbactam, piperacillin/tazobactam, and ticarcillin/clavulanic acid)
|
||||
\item carbapenems\cr(biapenem, doripenem, ertapenem, imipenem, imipenem/EDTA, imipenem/relebactam, meropenem, meropenem/nacubactam, meropenem/vaborbactam, panipenem, razupenem, ritipenem, ritipenem acoxil, and tebipenem)
|
||||
|
@@ -99,7 +99,7 @@ All 35 antimicrobial selectors are supported for use in the rules:
|
||||
\item \code{\link[=aminoglycosides]{aminoglycosides()}} can select: \cr amikacin, amikacin/fosfomycin, apramycin, arbekacin, astromicin, bekanamycin, dibekacin, framycetin, gentamicin, gentamicin-high, habekacin, hygromycin, isepamicin, kanamycin, kanamycin-high, kanamycin/cephalexin, micronomicin, neomycin, netilmicin, pentisomicin, plazomicin, propikacin, ribostamycin, sisomicin, streptoduocin, streptomycin, streptomycin-high, tobramycin, and tobramycin-high
|
||||
\item \code{\link[=aminopenicillins]{aminopenicillins()}} can select: \cr amoxicillin and ampicillin
|
||||
\item \code{\link[=antifungals]{antifungals()}} can select: \cr amorolfine, amphotericin B, amphotericin B-high, anidulafungin, butoconazole, caspofungin, ciclopirox, clotrimazole, econazole, fluconazole, flucytosine, fosfluconazole, griseofulvin, hachimycin, ibrexafungerp, isavuconazole, isoconazole, itraconazole, ketoconazole, manogepix, micafungin, miconazole, nystatin, oteseconazole, pimaricin, posaconazole, rezafungin, ribociclib, sulconazole, terbinafine, terconazole, and voriconazole
|
||||
\item \code{\link[=antimycobacterials]{antimycobacterials()}} can select: \cr 4-aminosalicylic acid, calcium aminosalicylate, capreomycin, clofazimine, delamanid, enviomycin, ethambutol, ethambutol/isoniazid, ethionamide, isoniazid, isoniazid/sulfamethoxazole/trimethoprim/pyridoxine, morinamide, p-aminosalicylic acid, pretomanid, protionamide, pyrazinamide, rifabutin, rifampicin, rifampicin/ethambutol/isoniazid, rifampicin/isoniazid, rifampicin/pyrazinamide/ethambutol/isoniazid, rifampicin/pyrazinamide/isoniazid, rifamycin, rifapentine, sodium aminosalicylate, streptomycin/isoniazid, terizidone, thioacetazone, thioacetazone/isoniazid, tiocarlide, and viomycin
|
||||
\item \code{\link[=antimycobacterials]{antimycobacterials()}} can select: \cr 4-aminosalicylic acid, calcium aminosalicylate, capreomycin, clofazimine, delamanid, enviomycin, ethambutol, ethambutol/isoniazid, ethionamide, isoniazid, isoniazid/sulfamethoxazole/trimethoprim/pyridoxine, morinamide, p-aminosalicylic acid, pretomanid, protionamide, pyrazinamide, rifabutin, rifampicin, rifampicin/ethambutol/isoniazid, rifampicin/isoniazid, rifampicin/pyrazinamide/ethambutol/isoniazid, rifampicin/pyrazinamide/isoniazid, rifamycin, rifapentine, simvastatin/fenofibrate, sodium aminosalicylate, streptomycin/isoniazid, terizidone, thioacetazone, thioacetazone/isoniazid, tiocarlide, and viomycin
|
||||
\item \code{\link[=betalactams]{betalactams()}} can select: \cr amoxicillin, amoxicillin/clavulanic acid, amoxicillin/sulbactam, ampicillin, ampicillin/sulbactam, apalcillin, aspoxicillin, azidocillin, azlocillin, aztreonam, aztreonam/avibactam, aztreonam/nacubactam, bacampicillin, benzathine benzylpenicillin, benzathine phenoxymethylpenicillin, benzylpenicillin, benzylpenicillin screening test, biapenem, carbenicillin, carindacillin, carumonam, cefacetrile, cefaclor, cefadroxil, cefalexin, cefaloridine, cefalotin, cefamandole, cefapirin, cefatrizine, cefazedone, cefazolin, cefcapene, cefcapene pivoxil, cefdinir, cefditoren, cefditoren pivoxil, cefepime, cefepime/amikacin, cefepime/clavulanic acid, cefepime/enmetazobactam, cefepime/nacubactam, cefepime/tazobactam, cefepime/zidebactam, cefetamet, cefetamet pivoxil, cefetecol, cefetrizole, cefiderocol, cefixime, cefmenoxime, cefmetazole, cefodizime, cefonicid, cefoperazone, cefoperazone/sulbactam, ceforanide, cefoselis, cefotaxime, cefotaxime screening test, cefotaxime/clavulanic acid, cefotaxime/sulbactam, cefotetan, cefotiam, cefotiam hexetil, cefovecin, cefoxitin, cefoxitin screening test, cefozopran, cefpimizole, cefpiramide, cefpirome, cefpodoxime, cefpodoxime proxetil, cefpodoxime/clavulanic acid, cefprozil, cefquinome, cefroxadine, cefsulodin, cefsumide, ceftaroline, ceftaroline/avibactam, ceftazidime, ceftazidime/avibactam, ceftazidime/clavulanic acid, cefteram, cefteram pivoxil, ceftezole, ceftibuten, ceftiofur, ceftizoxime, ceftizoxime alapivoxil, ceftobiprole, ceftobiprole medocaril, ceftolozane/tazobactam, ceftriaxone, ceftriaxone/beta-lactamase inhibitor, cefuroxime, cefuroxime axetil, cephradine, ciclacillin, clometocillin, cloxacillin, dicloxacillin, doripenem, epicillin, ertapenem, flucloxacillin, hetacillin, imipenem, imipenem/EDTA, imipenem/relebactam, latamoxef, lenampicillin, loracarbef, mecillinam, meropenem, meropenem/nacubactam, meropenem/vaborbactam, metampicillin, meticillin, mezlocillin, mezlocillin/sulbactam, nafcillin, oxacillin, oxacillin screening test, panipenem, penamecillin, penicillin/novobiocin, penicillin/sulbactam, pheneticillin, phenoxymethylpenicillin, piperacillin, piperacillin/sulbactam, piperacillin/tazobactam, piridicillin, pivampicillin, pivmecillinam, procaine benzylpenicillin, propicillin, razupenem, ritipenem, ritipenem acoxil, sarmoxicillin, sulbenicillin, sultamicillin, talampicillin, tebipenem, temocillin, ticarcillin, ticarcillin/clavulanic acid, and tigemonam
|
||||
\item \code{\link[=betalactams_with_inhibitor]{betalactams_with_inhibitor()}} can select: \cr amoxicillin/clavulanic acid, amoxicillin/sulbactam, ampicillin/sulbactam, aztreonam/avibactam, aztreonam/nacubactam, cefepime/amikacin, cefepime/clavulanic acid, cefepime/enmetazobactam, cefepime/nacubactam, cefepime/tazobactam, cefepime/zidebactam, cefoperazone/sulbactam, cefotaxime/clavulanic acid, cefotaxime/sulbactam, cefpodoxime/clavulanic acid, ceftaroline/avibactam, ceftazidime/avibactam, ceftazidime/clavulanic acid, ceftolozane/tazobactam, ceftriaxone/beta-lactamase inhibitor, imipenem/relebactam, meropenem/nacubactam, meropenem/vaborbactam, mezlocillin/sulbactam, penicillin/novobiocin, penicillin/sulbactam, piperacillin/sulbactam, piperacillin/tazobactam, and ticarcillin/clavulanic acid
|
||||
\item \code{\link[=carbapenems]{carbapenems()}} can select: \cr biapenem, doripenem, ertapenem, imipenem, imipenem/EDTA, imipenem/relebactam, meropenem, meropenem/nacubactam, meropenem/vaborbactam, panipenem, razupenem, ritipenem, ritipenem acoxil, and tebipenem
|
||||
|
27
man/esbl_isolates.Rd
Normal file
27
man/esbl_isolates.Rd
Normal file
@@ -0,0 +1,27 @@
|
||||
% Generated by roxygen2: do not edit by hand
|
||||
% Please edit documentation in R/data.R
|
||||
\docType{data}
|
||||
\name{esbl_isolates}
|
||||
\alias{esbl_isolates}
|
||||
\title{Data Set with 500 ESBL Isolates}
|
||||
\format{
|
||||
A \link[tibble:tibble]{tibble} with 500 observations and 19 variables:
|
||||
\itemize{
|
||||
\item \code{esbl}\cr Logical indicator if the isolate is ESBL-producing
|
||||
\item \code{genus}\cr Genus of the microorganism
|
||||
\item \code{AMC:COL}\cr MIC values for 17 antimicrobial agents, transformed to class \code{\link{mic}} (see \code{\link[=as.mic]{as.mic()}})
|
||||
}
|
||||
}
|
||||
\usage{
|
||||
esbl_isolates
|
||||
}
|
||||
\description{
|
||||
A data set containing 500 microbial isolates with MIC values of common antibiotics and a binary \code{esbl} column for extended-spectrum beta-lactamase (ESBL) production. This data set contains randomised fictitious data but reflects reality and can be used to practise AMR-related machine learning, e.g., classification modelling with \href{https://amr-for-r.org/articles/AMR_with_tidymodels.html}{tidymodels}.
|
||||
}
|
||||
\details{
|
||||
See our \link[=amr-tidymodels]{tidymodels integration} for an example using this data set.
|
||||
}
|
||||
\examples{
|
||||
esbl_isolates
|
||||
}
|
||||
\keyword{datasets}
|
@@ -108,30 +108,26 @@ All mentioned methods are covered in the \code{\link[=first_isolate]{first_isola
|
||||
- Any difference in key antimicrobial results \tab - \code{first_isolate(x, type = "keyantimicrobials")} \cr
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
\strong{Isolate-based}
|
||||
|
||||
\emph{Minimum variables required: Microorganism identifier}
|
||||
\subsection{Isolate-based}{
|
||||
|
||||
This method does not require any selection, as all isolates should be included. It does, however, respect all arguments set in the \code{\link[=first_isolate]{first_isolate()}} function. For example, the default setting for \code{include_unknown} (\code{FALSE}) will omit selection of rows without a microbial ID.
|
||||
}
|
||||
|
||||
\strong{Patient-based}
|
||||
\subsection{Patient-based}{
|
||||
|
||||
\emph{Minimum variables required: Microorganism identifier, Patient identifier}
|
||||
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.
|
||||
}
|
||||
|
||||
This method includes every genus-species combination per patient once. 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}{
|
||||
|
||||
\strong{Episode-based}
|
||||
|
||||
\emph{Minimum variables required: Microorganism identifier, Patient identifier, Date}
|
||||
|
||||
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 e.g., 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.
|
||||
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.
|
||||
}
|
||||
|
||||
\strong{Phenotype-based}
|
||||
|
||||
\emph{Minimum variables required: Microorganism identifier, Patient identifier, Date, Antimicrobial test results}
|
||||
\subsection{Phenotype-based}{
|
||||
|
||||
This is a more reliable method, since it also \emph{weighs} the antibiogram (antimicrobial test results) yielding so-called 'first weighted isolates'. There are two different methods to weigh the antibiogram:
|
||||
\enumerate{
|
||||
|
@@ -57,7 +57,7 @@ eucast_exceptional_phenotypes(x = NULL, only_sir_columns = any(is.sir(x)),
|
||||
|
||||
\item{combine_SI}{A \link{logical} to indicate whether all values of S and I must be merged into one, so resistance is only considered when isolates are R, not I. As this is the default behaviour of the \code{\link[=mdro]{mdro()}} function, it follows the redefinition by EUCAST about the interpretation of I (increased exposure) in 2019, see section 'Interpretation of S, I and R' below. When using \code{combine_SI = FALSE}, resistance is considered when isolates are R or I.}
|
||||
|
||||
\item{verbose}{A \link{logical} to turn Verbose mode on and off (default is off). In Verbose mode, the function returns a data set with the MDRO results in logbook form with extensive info about which isolates would be MDRO-positive, or why they are not.}
|
||||
\item{verbose}{A \link{logical} to turn Verbose mode on and off (default is off). In Verbose mode, the function does not return the MDRO results, but instead returns a data set in logbook form with extensive info about which isolates would be MDRO-positive, or why they are not.}
|
||||
|
||||
\item{only_sir_columns}{A \link{logical} to indicate whether only antimicrobial columns must be included that were transformed to class \link[=as.sir]{sir} on beforehand. Defaults to \code{FALSE} if no columns of \code{x} have a class \link[=as.sir]{sir}.}
|
||||
|
||||
|
@@ -18,7 +18,7 @@ A \link[tibble:tibble]{tibble} with 78 679 observations and 26 variables:
|
||||
\item \code{lpsn}\cr Identifier ('Record number') of List of Prokaryotic names with Standing in Nomenclature (LPSN). This will be the first/highest LPSN identifier to keep one identifier per row. For example, \emph{Acetobacter ascendens} has LPSN Record number 7864 and 11011. Only the first is available in the \code{microorganisms} data set. \emph{\strong{This is a unique identifier}}, though available for only ~33 000 records.
|
||||
\item \code{lpsn_parent}\cr LPSN identifier of the parent taxon
|
||||
\item \code{lpsn_renamed_to}\cr LPSN identifier of the currently valid taxon
|
||||
\item \code{mycobank}\cr Identifier ('MycoBank #') of MycoBank. \emph{\strong{This is a unique identifier}}, though available for only ~19 000 records.
|
||||
\item \code{mycobank}\cr Identifier ('MycoBank #') of MycoBank. \emph{\strong{This is a unique identifier}}, though available for only ~18 000 records.
|
||||
\item \code{mycobank_parent}\cr MycoBank identifier of the parent taxon
|
||||
\item \code{mycobank_renamed_to}\cr MycoBank identifier of the currently valid taxon
|
||||
\item \code{gbif}\cr Identifier ('taxonID') of Global Biodiversity Information Facility (GBIF). \emph{\strong{This is a unique identifier}}, though available for only ~49 000 records.
|
||||
@@ -70,7 +70,7 @@ Included taxonomic data from \href{https://lpsn.dsmz.de}{LPSN}, \href{https://ww
|
||||
\item ~28 000 species from the kingdom of Fungi. The kingdom of Fungi is a very large taxon with almost 300,000 different (sub)species, of which most are not microbial (but rather macroscopic, like mushrooms). Because of this, not all fungi fit the scope of this package. Only relevant fungi are covered (such as all species of \emph{Aspergillus}, \emph{Candida}, \emph{Cryptococcus}, \emph{Histoplasma}, \emph{Pneumocystis}, \emph{Saccharomyces} and \emph{Trichophyton}).
|
||||
\item ~8 100 (sub)species from the kingdom of Protozoa
|
||||
\item ~1 600 (sub)species from 39 other relevant genera from the kingdom of Animalia (such as \emph{Strongyloides} and \emph{Taenia})
|
||||
\item All ~26 000 previously accepted names of all included (sub)species (these were taxonomically renamed)
|
||||
\item All ~22 000 previously accepted names of all included (sub)species (these were taxonomically renamed)
|
||||
\item The complete taxonomic tree of all included (sub)species: from kingdom to subspecies
|
||||
\item The identifier of the parent taxons
|
||||
\item The year and first author of the related scientific publication
|
||||
|
44
man/plot.Rd
44
man/plot.Rd
@@ -172,20 +172,12 @@ Especially the \verb{scale_*_mic()} functions are relevant wrappers to plot MIC
|
||||
\details{
|
||||
\subsection{The \verb{scale_*_mic()} Functions}{
|
||||
|
||||
The functions \code{\link[=scale_x_mic]{scale_x_mic()}}, \code{\link[=scale_y_mic]{scale_y_mic()}}, \code{\link[=scale_colour_mic]{scale_colour_mic()}}, and \code{\link[=scale_fill_mic]{scale_fill_mic()}} functions allow to plot the \link[=as.mic]{mic} class (MIC values) on a continuous, logarithmic scale.
|
||||
|
||||
There is normally no need to add these scale functions to your plot, as they are applied automatically when plotting values of class \link[=as.mic]{mic}.
|
||||
|
||||
When manually added though, they allow to rescale the MIC range with an 'inside' or 'outside' range if required, and provide the option to retain the operators in MIC values (such as \code{>=}). Missing intermediate log2 levels will always be plotted too.
|
||||
The functions \code{\link[=scale_x_mic]{scale_x_mic()}}, \code{\link[=scale_y_mic]{scale_y_mic()}}, \code{\link[=scale_colour_mic]{scale_colour_mic()}}, and \code{\link[=scale_fill_mic]{scale_fill_mic()}} functions allow to plot the \link[=as.mic]{mic} class (MIC values) on a continuous, logarithmic scale. They also allow to rescale the MIC range with an 'inside' or 'outside' range if required, and retain the operators in MIC values (such as \code{>=}) if desired. Missing intermediate log2 levels will be plotted too.
|
||||
}
|
||||
|
||||
\subsection{The \verb{scale_*_sir()} Functions}{
|
||||
|
||||
The functions \code{\link[=scale_x_sir]{scale_x_sir()}}, \code{\link[=scale_colour_sir]{scale_colour_sir()}}, and \code{\link[=scale_fill_sir]{scale_fill_sir()}} functions allow to plot the \link[=as.sir]{sir} class in the right order (S < SDD < I < R < NI).
|
||||
|
||||
There is normally no need to add these scale functions to your plot, as they are applied automatically when plotting values of class \link[=as.sir]{sir}.
|
||||
|
||||
At default, they translate the S/I/R values to an interpretative text ("Susceptible", "Resistant", etc.) in any of the 28 supported languages (use \code{language = NULL} to keep S/I/R). Also, except for \code{\link[=scale_x_sir]{scale_x_sir()}}, they set colour-blind friendly colours to the \code{colour} and \code{fill} aesthetics.
|
||||
The functions \code{\link[=scale_x_sir]{scale_x_sir()}}, \code{\link[=scale_colour_sir]{scale_colour_sir()}}, and \code{\link[=scale_fill_sir]{scale_fill_sir()}} functions allow to plot the \link[=as.sir]{sir} class in the right order (S < SDD < I < R < NI). At default, they translate the S/I/R values to an interpretative text ("Susceptible", "Resistant", etc.) in any of the 28 supported languages (use \code{language = NULL} to keep S/I/R). Also, except for \code{\link[=scale_x_sir]{scale_x_sir()}}, they set colour-blind friendly colours to the \code{colour} and \code{fill} aesthetics.
|
||||
}
|
||||
|
||||
\subsection{Additional \code{ggplot2} Functions}{
|
||||
@@ -243,12 +235,17 @@ if (require("ggplot2")) {
|
||||
) +
|
||||
geom_col()
|
||||
mic_plot +
|
||||
labs(title = "scale_x_mic() automatically applied")
|
||||
labs(title = "without scale_x_mic()")
|
||||
}
|
||||
if (require("ggplot2")) {
|
||||
mic_plot +
|
||||
scale_x_mic(keep_operators = "none") +
|
||||
labs(title = "with scale_x_mic() keeping no operators")
|
||||
scale_x_mic() +
|
||||
labs(title = "with scale_x_mic()")
|
||||
}
|
||||
if (require("ggplot2")) {
|
||||
mic_plot +
|
||||
scale_x_mic(keep_operators = "all") +
|
||||
labs(title = "with scale_x_mic() keeping all operators")
|
||||
}
|
||||
if (require("ggplot2")) {
|
||||
mic_plot +
|
||||
@@ -275,7 +272,7 @@ if (require("ggplot2")) {
|
||||
) +
|
||||
geom_boxplot() +
|
||||
geom_violin(linetype = 2, colour = "grey30", fill = NA) +
|
||||
labs(title = "scale_y_mic() automatically applied")
|
||||
scale_y_mic()
|
||||
}
|
||||
if (require("ggplot2")) {
|
||||
ggplot(
|
||||
@@ -307,7 +304,7 @@ if (require("ggplot2")) {
|
||||
|
||||
# Plotting using scale_y_mic() and scale_colour_sir() ------------------
|
||||
if (require("ggplot2")) {
|
||||
mic_sir_plot <- ggplot(
|
||||
plain <- ggplot(
|
||||
data.frame(
|
||||
mic = some_mic_values,
|
||||
group = some_groups,
|
||||
@@ -321,16 +318,21 @@ if (require("ggplot2")) {
|
||||
theme_minimal() +
|
||||
geom_boxplot(fill = NA, colour = "grey30") +
|
||||
geom_jitter(width = 0.25)
|
||||
labs(title = "scale_y_mic()/scale_colour_sir() automatically applied")
|
||||
|
||||
mic_sir_plot
|
||||
|
||||
plain
|
||||
}
|
||||
if (require("ggplot2")) {
|
||||
mic_sir_plot +
|
||||
# and now with our MIC and SIR scale functions:
|
||||
plain +
|
||||
scale_y_mic() +
|
||||
scale_colour_sir()
|
||||
}
|
||||
if (require("ggplot2")) {
|
||||
plain +
|
||||
scale_y_mic(mic_range = c(0.005, 32), name = "Our MICs!") +
|
||||
scale_colour_sir(
|
||||
language = "pt", # Portuguese
|
||||
name = "Support in 28 languages"
|
||||
language = "pt",
|
||||
name = "Support in 27 languages"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
3907
pkgdown/assets/logo_umcg.svg
Executable file → Normal file
3907
pkgdown/assets/logo_umcg.svg
Executable file → Normal file
File diff suppressed because it is too large
Load Diff
Before Width: | Height: | Size: 3.6 KiB After Width: | Height: | Size: 343 KiB |
@@ -70,14 +70,14 @@ test_that("test-misc.R", {
|
||||
}
|
||||
|
||||
df <- example_isolates[, check_df("x")]
|
||||
expect_true(is_right, info = "the environmental data cannot be found for base `x`")
|
||||
expect_true(is_right, info = "the environmental data cannot be found for base/x (1)")
|
||||
|
||||
# should work on R >=3.6.3 or so
|
||||
df <- example_isolates[c(1:3), check_df("x")]
|
||||
if (!is_right) {
|
||||
# otherwise, this is needed for older versions
|
||||
if (getRversion() < "4.0.0") {
|
||||
df <- example_isolates[c(1:3), check_df("xx")]
|
||||
expect_true(is_right, info = "the environmental data cannot be found for base `x` or `xx`")
|
||||
expect_true(is_right, info = "the environmental data cannot be found for base/xx")
|
||||
} else {
|
||||
df <- example_isolates[c(1:3), check_df("x")]
|
||||
expect_true(is_right, info = "the environmental data cannot be found for base/x (2)")
|
||||
}
|
||||
|
||||
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0", also_load = TRUE)) {
|
||||
|
@@ -96,14 +96,6 @@ test_that("test-ab.R", {
|
||||
rep("GEH", 8)
|
||||
)
|
||||
|
||||
# skimr
|
||||
if (AMR:::pkg_is_available("skimr", min_version = "2.0.0", also_load = TRUE)) {
|
||||
expect_named(
|
||||
skim(clinical_breakpoints$ab),
|
||||
c("skim_type", "skim_variable", "n_missing", "complete_rate", "ab.n_unique", "ab.top_ab", "ab.top_ab_name", "ab.top_group")
|
||||
)
|
||||
}
|
||||
|
||||
# assigning and subsetting
|
||||
x <- AMR::antimicrobials$ab
|
||||
expect_inherits(x[1], "ab")
|
||||
|
@@ -60,12 +60,4 @@ test_that("test-disk.R", {
|
||||
if (AMR:::pkg_is_available("tibble")) {
|
||||
expect_output(print(tibble::tibble(d = as.disk(12))))
|
||||
}
|
||||
|
||||
# skimr
|
||||
if (AMR:::pkg_is_available("skimr", min_version = "2.0.0", also_load = TRUE)) {
|
||||
expect_named(
|
||||
skim(random_disk(100)),
|
||||
c("skim_type", "skim_variable", "n_missing", "complete_rate", "disk.p0", "disk.p25", "disk.p50", "disk.p75", "disk.p100", "disk.hist")
|
||||
)
|
||||
}
|
||||
})
|
||||
|
@@ -81,14 +81,6 @@ test_that("test-mic.R", {
|
||||
expect_output(print(tibble::tibble(m = as.mic(2:4))))
|
||||
}
|
||||
|
||||
# skimr
|
||||
if (AMR:::pkg_is_available("skimr", min_version = "2.0.0", also_load = TRUE)) {
|
||||
expect_named(
|
||||
skim(random_mic(100)),
|
||||
c("skim_type", "skim_variable", "n_missing", "complete_rate", "mic.p0", "mic.p25", "mic.p50", "mic.p75", "mic.p100", "mic.hist")
|
||||
)
|
||||
}
|
||||
|
||||
# all mathematical operations
|
||||
x <- random_mic(50)
|
||||
x_double <- as.double(gsub("[<=>]+", "", as.character(x)))
|
||||
|
@@ -321,12 +321,4 @@ test_that("test-mo.R", {
|
||||
if (AMR:::pkg_is_available("cleaner")) {
|
||||
expect_inherits(cleaner::freq(example_isolates$mo), "freq")
|
||||
}
|
||||
|
||||
# skimr
|
||||
if (AMR:::pkg_is_available("skimr", min_version = "2.0.0", also_load = TRUE)) {
|
||||
expect_named(
|
||||
skim(example_isolates$mo),
|
||||
c("skim_type", "skim_variable", "n_missing", "complete_rate", "mo.n_unique", "mo.gram_negative", "mo.gram_positive", "mo.yeast", "mo.top_genus", "mo.top_species")
|
||||
)
|
||||
}
|
||||
})
|
||||
|
@@ -115,7 +115,7 @@ test_that("test-mo_property.R", {
|
||||
|
||||
expect_equal(
|
||||
as.character(table(mo_pathogenicity(example_isolates$mo))),
|
||||
c("1911", "66", "1", "22")
|
||||
c("1911", "72", "1", "16")
|
||||
)
|
||||
|
||||
expect_equal(mo_ref("Escherichia coli"), "Castellani et al., 1919")
|
||||
|
@@ -103,13 +103,22 @@ test_that("test-sir.R", {
|
||||
pull(MEM) %>%
|
||||
is.sir())
|
||||
}
|
||||
|
||||
# skimr
|
||||
if (AMR:::pkg_is_available("skimr", min_version = "2.0.0", also_load = TRUE)) {
|
||||
expect_named(
|
||||
skim(example_isolates$PEN),
|
||||
c("skim_type", "skim_variable", "n_missing", "complete_rate", "sir.count_S", "sir.count_I", "sir.count_R", "sir.prop_S", "sir.prop_I", "sir.prop_R", "sir.hist")
|
||||
expect_inherits(
|
||||
skim(example_isolates),
|
||||
"data.frame"
|
||||
)
|
||||
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0", also_load = TRUE)) {
|
||||
expect_inherits(
|
||||
example_isolates %>%
|
||||
mutate(
|
||||
m = as.mic(2),
|
||||
d = as.disk(20)
|
||||
) %>%
|
||||
skim(),
|
||||
"data.frame"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
expect_equal(as.sir(c("", "-", NA, "NULL")), c(NA_sir_, NA_sir_, NA_sir_, NA_sir_))
|
||||
|
@@ -221,16 +221,142 @@ In this second example, we demonstrate how to use `<mic>` columns directly in `t
|
||||
|
||||
This approach and idea formed the basis for the publication [DOI: 10.3389/fmicb.2025.1582703](https://doi.org/10.3389/fmicb.2025.1582703) to model the presence of extended-spectrum beta-lactamases (ESBL).
|
||||
|
||||
> NOTE: THIS EXAMPLE WILL BE AVAILABLE IN A NEXT VERSION (#TODO)
|
||||
>
|
||||
> The new AMR package version will contain new tidymodels selectors such as `step_mic_log2()`.
|
||||
### **Objective**
|
||||
|
||||
<!-- TODO for AMR v3.1.0: add info from here: https://github.com/msberends/AMR/blob/2461631bcefa78ebdb37bdfad359be74cdd9165a/vignettes/AMR_with_tidymodels.Rmd#L212-L291 -->
|
||||
Our goal is to:
|
||||
|
||||
1. Use raw MIC values to predict whether a bacterial isolate produces ESBL.
|
||||
2. Apply AMR-aware preprocessing in a `tidymodels` recipe.
|
||||
3. Train a classification model and evaluate its predictive performance.
|
||||
|
||||
### **Data Preparation**
|
||||
|
||||
We use the `esbl_isolates` dataset that comes with the AMR package.
|
||||
|
||||
```{r}
|
||||
# Load required libraries
|
||||
library(AMR)
|
||||
library(tidymodels)
|
||||
|
||||
# View the esbl_isolates data set
|
||||
esbl_isolates
|
||||
|
||||
# Prepare a binary outcome and convert to ordered factor
|
||||
data <- esbl_isolates %>%
|
||||
mutate(esbl = factor(esbl, levels = c(FALSE, TRUE), ordered = TRUE))
|
||||
```
|
||||
|
||||
**Explanation:**
|
||||
|
||||
- `esbl_isolates`: Contains MIC test results and ESBL status for each isolate.
|
||||
- `mutate(esbl = ...)`: Converts the target column to an ordered factor for classification.
|
||||
|
||||
### **Defining the Workflow**
|
||||
|
||||
#### 1. Preprocessing with a Recipe
|
||||
|
||||
We use our `step_mic_log2()` function to log2-transform MIC values, ensuring that MICs are numeric and properly scaled. All MIC predictors can easily and agnostically selected using the new `all_mic_predictors()`:
|
||||
|
||||
```{r}
|
||||
# Split into training and testing sets
|
||||
set.seed(123)
|
||||
split <- initial_split(data)
|
||||
training_data <- training(split)
|
||||
testing_data <- testing(split)
|
||||
|
||||
# Define the recipe
|
||||
mic_recipe <- recipe(esbl ~ ., data = training_data) %>%
|
||||
remove_role(genus, old_role = "predictor") %>% # Remove non-informative variable
|
||||
step_mic_log2(all_mic_predictors()) #%>% # Log2 transform all MIC predictors
|
||||
# prep()
|
||||
|
||||
mic_recipe
|
||||
```
|
||||
|
||||
**Explanation:**
|
||||
|
||||
- `remove_role()`: Removes irrelevant variables like genus.
|
||||
- `step_mic_log2()`: Applies `log2(as.numeric(...))` to all MIC predictors in one go.
|
||||
- `prep()`: Finalises the recipe based on training data.
|
||||
|
||||
#### 2. Specifying the Model
|
||||
|
||||
We use a simple logistic regression to model ESBL presence, though recent models such as xgboost ([link to `parsnip` manual](https://parsnip.tidymodels.org/reference/details_boost_tree_xgboost.html)) could be much more precise.
|
||||
|
||||
```{r}
|
||||
# Define the model
|
||||
model <- logistic_reg(mode = "classification") %>%
|
||||
set_engine("glm")
|
||||
|
||||
model
|
||||
```
|
||||
|
||||
**Explanation:**
|
||||
|
||||
- `logistic_reg()`: Specifies a binary classification model.
|
||||
- `set_engine("glm")`: Uses the base R GLM engine.
|
||||
|
||||
#### 3. Building the Workflow
|
||||
|
||||
```{r}
|
||||
# Create workflow
|
||||
workflow_model <- workflow() %>%
|
||||
add_recipe(mic_recipe) %>%
|
||||
add_model(model)
|
||||
|
||||
workflow_model
|
||||
```
|
||||
|
||||
### **Training and Evaluating the Model**
|
||||
|
||||
```{r}
|
||||
# Fit the model
|
||||
fitted <- fit(workflow_model, training_data)
|
||||
|
||||
# Generate predictions
|
||||
predictions <- predict(fitted, testing_data) %>%
|
||||
bind_cols(testing_data)
|
||||
|
||||
# Evaluate model performance
|
||||
our_metrics <- metric_set(accuracy, kap, ppv, npv)
|
||||
metrics <- our_metrics(predictions, truth = esbl, estimate = .pred_class)
|
||||
|
||||
metrics
|
||||
```
|
||||
|
||||
**Explanation:**
|
||||
|
||||
- `fit()`: Trains the model on the processed training data.
|
||||
- `predict()`: Produces predictions for unseen test data.
|
||||
- `metric_set()`: Allows evaluating multiple classification metrics.
|
||||
|
||||
It appears we can predict ESBL gene presence with a positive predictive value (PPV) of `r round(metrics$.estimate[3], 3) * 100`% and a negative predictive value (NPV) of `r round(metrics$.estimate[4], 3) * 100` using a simplistic logistic regression model.
|
||||
|
||||
### **Visualising Predictions**
|
||||
|
||||
We can visualise predictions by comparing predicted and actual ESBL status.
|
||||
|
||||
```{r}
|
||||
library(ggplot2)
|
||||
|
||||
ggplot(predictions, aes(x = esbl, fill = .pred_class)) +
|
||||
geom_bar(position = "stack") +
|
||||
labs(title = "Predicted vs Actual ESBL Status",
|
||||
x = "Actual ESBL",
|
||||
y = "Count") +
|
||||
theme_minimal()
|
||||
```
|
||||
|
||||
### **Conclusion**
|
||||
|
||||
In this example, we showcased how the new `AMR`-specific recipe steps simplify working with `<mic>` columns in `tidymodels`. The `step_mic_log2()` transformation converts ordered MICs to log2-transformed numerics, improving compatibility with classification models.
|
||||
|
||||
This pipeline enables realistic, reproducible, and interpretable modelling of antimicrobial resistance data.
|
||||
|
||||
---
|
||||
|
||||
|
||||
## Example 2: Predicting AMR Over Time
|
||||
## Example 3: Predicting AMR Over Time
|
||||
|
||||
In this third example, we aim to predict antimicrobial resistance (AMR) trends over time using `tidymodels`. We will model resistance to three antibiotics (amoxicillin `AMX`, amoxicillin-clavulanic acid `AMC`, and ciprofloxacin `CIP`), based on historical data grouped by year and hospital ward.
|
||||
|
||||
|
Reference in New Issue
Block a user