Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1fe0350d15 | ||
|
|
69dc8795ae | ||
|
|
8685119254 | ||
|
|
cdada2f940 | ||
|
|
2183549fea | ||
|
|
550fd47250 | ||
|
|
dee759ef9c | ||
|
|
259fe07455 | ||
|
|
d5f778add6 | ||
|
|
7d4de8eb35 | ||
|
|
e0b5911d41 | ||
|
|
39d838ee3d | ||
|
|
a15da467b3 | ||
|
|
7c0ad08c8a | ||
|
|
48896ee426 | ||
|
|
31fd5db33b | ||
|
|
62f3d29455 | ||
|
|
d6a21b332a | ||
|
|
769ace0b66 | ||
|
|
c43e91eaee | ||
|
|
f31bb7259e | ||
|
|
21650ffec3 | ||
|
|
93271b2c07 | ||
|
|
59c39dc5d1 | ||
|
|
9950851ea8 | ||
|
|
a7dcf5719c | ||
|
|
e289d2568d | ||
|
|
d18dc71c10 | ||
|
|
2b13d43a3f | ||
|
|
deed569722 | ||
|
|
805dcaf92e | ||
|
|
d37dc49b96 | ||
|
|
32eee46345 | ||
|
|
84a6877c99 | ||
|
|
6151d3f729 | ||
|
|
32bfbe9286 | ||
|
|
3feb675608 | ||
|
|
e96db55bc2 | ||
|
|
49cc52e916 | ||
|
|
e665f73c92 | ||
|
|
72f176330e | ||
|
|
8ae4799471 | ||
|
|
784ee0812f | ||
|
|
d3e437e13a | ||
|
|
ec8f871100 | ||
|
|
6a000be49b | ||
|
|
d81e09bddd | ||
|
|
2c1a204ab6 | ||
|
|
e731388cb5 | ||
|
|
b3effa8a4e | ||
|
|
e81f9bcf5e | ||
|
|
8cd53d7ba4 | ||
|
|
fe6945bfad | ||
|
|
c5a5383b7b | ||
|
|
29c310e535 | ||
|
|
d247365476 | ||
|
|
64384886d7 | ||
|
|
7b50c6e9f7 | ||
|
|
100f3d6fe0 | ||
|
|
4dff2dbe6b | ||
|
|
09ffdc91e6 | ||
|
|
d6a732817a | ||
|
|
a153eb2626 | ||
|
|
0bc2afafe9 | ||
|
|
8c6795ca53 | ||
|
|
a994768452 | ||
|
|
4b476d056c | ||
|
|
eb998f6989 | ||
|
|
bdc43910ae | ||
|
|
6fd5ff2a24 | ||
|
|
68a0b3f94a | ||
|
|
d31b599825 | ||
|
|
7fe29a8401 | ||
|
|
f74da6c86a | ||
|
|
863a83ee08 | ||
|
|
b248bcc62a | ||
|
|
40b8ed3a1a | ||
|
|
90b951a48a | ||
|
|
05ea686a1e | ||
|
|
ec6f7db383 | ||
|
|
0d936e8905 | ||
|
|
f988c3273a | ||
|
|
9a91fdfb99 | ||
|
|
8438e68df5 | ||
|
|
8211647fb0 | ||
|
|
560396124f | ||
|
|
b45431b86c | ||
|
|
9667f42d3b | ||
|
|
49a3324340 | ||
|
|
ca3fb70197 | ||
|
|
f137d1a9e0 | ||
|
|
e2e3fa9184 | ||
|
|
205bfb053c | ||
|
|
553d074b96 | ||
|
|
4cc1967eab | ||
|
|
491cd94189 | ||
|
|
976d5292c7 | ||
|
|
1a10d0f4ee | ||
|
|
a1d8ec7d4a | ||
|
|
4f02b97c70 | ||
|
|
fee4bb45b1 | ||
|
|
2d869c2796 | ||
|
|
d2ff8027d1 | ||
|
|
cfc4fd0c0c | ||
|
|
f3f4586286 | ||
|
|
3f99e4a668 | ||
|
|
97c789d01f | ||
|
|
ac481f348b | ||
|
|
50592d10f1 | ||
|
|
a62a35d91d | ||
|
|
44b99f8875 | ||
|
|
964b71aedb | ||
|
|
f08c645b0c | ||
|
|
bcd6e333f0 | ||
|
|
cb53936bd3 | ||
|
|
37f397b1f3 |
@@ -1,23 +0,0 @@
|
||||
^.*\.Rproj$
|
||||
^\.gitlab-ci\.R$
|
||||
^\.gitlab-ci\.yml$
|
||||
^\.Renviron$
|
||||
^\.Rprofile$
|
||||
^\.Rproj\.user$
|
||||
^\.travis\.yml$
|
||||
^\.zenodo\.json$
|
||||
^_noinclude$
|
||||
^_pkgdown\.yml$
|
||||
^appveyor\.yml$
|
||||
^codecov\.yml$
|
||||
^cran-comments\.md$
|
||||
^CRAN-RELEASE$
|
||||
^doc$
|
||||
^docs$
|
||||
^git_.*\.sh$
|
||||
^index\.md$
|
||||
^installed_deps$
|
||||
^Meta$
|
||||
^pkgdown$
|
||||
^public$
|
||||
^data-raw$
|
||||
@@ -1,23 +0,0 @@
|
||||
Meta
|
||||
doc
|
||||
.Renviron
|
||||
.Rproj.user
|
||||
.Rhistory
|
||||
.RData
|
||||
.Ruserdata
|
||||
AMR.Rproj
|
||||
tests/testthat/Rplots.pdf
|
||||
inst/doc
|
||||
/src/*.o
|
||||
/src/*.o-*
|
||||
/src/*.d
|
||||
/src/*.so
|
||||
_noinclude
|
||||
*.dll
|
||||
vignettes/*.R
|
||||
.DS_Store
|
||||
.Rprofile
|
||||
^CRAN-RELEASE$
|
||||
packrat/lib*/
|
||||
packrat/src/
|
||||
cran-comments.md
|
||||
@@ -1,49 +0,0 @@
|
||||
# ==================================================================== #
|
||||
# TITLE #
|
||||
# Antimicrobial Resistance (AMR) Analysis #
|
||||
# #
|
||||
# SOURCE #
|
||||
# https://gitlab.com/msberends/AMR #
|
||||
# #
|
||||
# LICENCE #
|
||||
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
|
||||
# #
|
||||
# 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. #
|
||||
# #
|
||||
# This R package was created for academic research and was publicly #
|
||||
# released in the hope that it will be useful, but it comes WITHOUT #
|
||||
# ANY WARRANTY OR LIABILITY. #
|
||||
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
||||
# ==================================================================== #
|
||||
|
||||
install_if_needed <- function(pkg, repos, quiet) {
|
||||
package_path <- find.package(pkg, quiet = quiet)
|
||||
if (length(package_path) == 0) {
|
||||
message("NOTE: pkg ", pkg, " missing, installing...")
|
||||
install.packages(pkg, repos = repos, quiet = quiet)
|
||||
}
|
||||
}
|
||||
|
||||
gl_update_pkg_all <- function(repos = "https://cran.rstudio.com",
|
||||
quiet = TRUE,
|
||||
install_pkgdown = FALSE) {
|
||||
# update existing
|
||||
update.packages(ask = FALSE, repos = repos, quiet = quiet)
|
||||
|
||||
install_if_needed(pkg = "devtools", repos = repos, quiet = quiet)
|
||||
if (install_pkgdown == TRUE) {
|
||||
install_if_needed(pkg = "pkgdown", repos = repos, quiet = quiet)
|
||||
}
|
||||
|
||||
devtools::install_dev_deps(repos = repos, quiet = quiet, upgrade = TRUE)
|
||||
|
||||
cat("INSTALLED:\n")
|
||||
instld <- as.data.frame(installed.packages())
|
||||
rownames(instld) <- NULL
|
||||
print(instld[, c("Package", "Version")])
|
||||
|
||||
return(invisible(TRUE))
|
||||
}
|
||||
@@ -1,141 +0,0 @@
|
||||
# ==================================================================== #
|
||||
# TITLE #
|
||||
# Antimicrobial Resistance (AMR) Analysis #
|
||||
# #
|
||||
# SOURCE #
|
||||
# https://gitlab.com/msberends/AMR #
|
||||
# #
|
||||
# LICENCE #
|
||||
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
|
||||
# #
|
||||
# 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. #
|
||||
# #
|
||||
# This R package was created for academic research and was publicly #
|
||||
# released in the hope that it will be useful, but it comes WITHOUT #
|
||||
# ANY WARRANTY OR LIABILITY. #
|
||||
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
||||
# ==================================================================== #
|
||||
|
||||
# to check with R-Hub:
|
||||
# rhub::check_for_cran(devtools::build(args = c('--no-build-vignettes')))
|
||||
|
||||
stages:
|
||||
- build
|
||||
- test
|
||||
- deploy
|
||||
|
||||
image: rocker/r-base
|
||||
|
||||
before_script:
|
||||
- apt-get update -qq
|
||||
# install dependencies for packages
|
||||
- apt-get install -y wget locales libxml2-dev libssl-dev libcurl4-openssl-dev zlib1g-dev > /dev/null
|
||||
# recent pandoc
|
||||
- wget --quiet https://github.com/jgm/pandoc/releases/download/2.7.2/pandoc-2.7.2-1-amd64.deb
|
||||
- dpkg -i pandoc*.deb
|
||||
- rm pandoc*.deb
|
||||
# set R system language
|
||||
- echo "LC_ALL=en_US.UTF-8" >> /etc/environment
|
||||
- echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
|
||||
- echo "LANG=en_US.UTF-8" > /etc/locale.conf
|
||||
- locale-gen
|
||||
# cache R packages
|
||||
- mkdir -p installed_deps
|
||||
- echo 'R_LIBS="installed_deps"' > .Renviron
|
||||
- echo 'R_LIBS_USER="installed_deps"' >> .Renviron
|
||||
- echo 'R_LIBS_SITE="installed_deps"' >> .Renviron
|
||||
# set language
|
||||
- echo 'LANGUAGE="en_US.utf8"' >> .Renviron
|
||||
- echo 'LANG="en_US.utf8"' >> .Renviron
|
||||
- echo 'LANGUAGE="en_US.utf8"' > ~/.Renviron
|
||||
|
||||
R-release:
|
||||
stage: build
|
||||
allow_failure: false
|
||||
script:
|
||||
- Rscript -e 'sessionInfo()'
|
||||
# install missing and outdated packages
|
||||
- Rscript -e 'source(".gitlab-ci.R"); gl_update_pkg_all(repos = "https://cran.rstudio.com", quiet = TRUE, install_pkgdown = TRUE)'
|
||||
# remove vignettes folder and get VignetteBuilder field out of DESCRIPTION file
|
||||
- rm -rf vignettes
|
||||
- Rscript -e 'd <- read.dcf("DESCRIPTION"); d[, colnames(d) == "VignetteBuilder"] <- NA; write.dcf(d, "DESCRIPTION")'
|
||||
# build package
|
||||
- R CMD build . --no-build-vignettes --no-manual
|
||||
- PKG_FILE_NAME=$(ls -1t *.tar.gz | head -n 1)
|
||||
- R CMD check "${PKG_FILE_NAME}" --no-build-vignettes --no-manual --as-cran
|
||||
artifacts:
|
||||
when: always
|
||||
paths:
|
||||
- '*.Rcheck/*'
|
||||
expire_in: '1 month'
|
||||
cache:
|
||||
key: r350
|
||||
paths:
|
||||
- installed_deps/
|
||||
|
||||
R-devel:
|
||||
stage: build
|
||||
image: rocker/r-devel
|
||||
allow_failure: true
|
||||
script:
|
||||
- Rscriptdevel -e 'sessionInfo()'
|
||||
# install missing and outdated packages
|
||||
- Rscriptdevel -e 'source(".gitlab-ci.R"); gl_update_pkg_all(repos = "https://cran.rstudio.com", quiet = TRUE, install_pkgdown = TRUE)'
|
||||
# remove vignettes folder and get VignetteBuilder field out of DESCRIPTION file
|
||||
- rm -rf vignettes
|
||||
- Rscriptdevel -e 'd <- read.dcf("DESCRIPTION"); d[, colnames(d) == "VignetteBuilder"] <- NA; write.dcf(d, "DESCRIPTION")'
|
||||
# build package
|
||||
- Rdevel CMD build . --no-build-vignettes --no-manual
|
||||
- PKG_FILE_NAME=$(ls -1t *.tar.gz | head -n 1)
|
||||
- Rdevel CMD check "${PKG_FILE_NAME}" --no-build-vignettes --no-manual --as-cran
|
||||
artifacts:
|
||||
when: always
|
||||
paths:
|
||||
- '*.Rcheck/*'
|
||||
expire_in: '1 month'
|
||||
cache:
|
||||
key: r360
|
||||
paths:
|
||||
- installed_deps/
|
||||
|
||||
coverage:
|
||||
stage: test
|
||||
allow_failure: true
|
||||
when: on_success
|
||||
cache:
|
||||
key: r350
|
||||
paths:
|
||||
- installed_deps/
|
||||
policy: pull # no uploading after run
|
||||
only:
|
||||
- premaster
|
||||
- master
|
||||
script:
|
||||
- apt-get install --yes git
|
||||
# install missing and outdated packages
|
||||
- Rscript -e 'source(".gitlab-ci.R"); gl_update_pkg_all(repos = "https://cran.rstudio.com", quiet = TRUE, install_pkgdown = TRUE)'
|
||||
# codecov token is set in https://gitlab.com/msberends/AMR/settings/ci_cd
|
||||
- Rscript -e "cc <- covr::package_coverage(); covr::codecov(coverage = cc, token = '$codecov', exclusions = c('R/atc_online.R', 'R/mo_source.R')); cat('Code coverage:', covr::percent_coverage(cc))"
|
||||
coverage: '/Code coverage: \d+\.\d+/'
|
||||
|
||||
pages:
|
||||
stage: deploy
|
||||
when: always
|
||||
#cache:
|
||||
# key: "$CI_COMMIT_REF_SLUG"
|
||||
# paths:
|
||||
# - installed_deps/
|
||||
only:
|
||||
- master
|
||||
script:
|
||||
- mv docs public
|
||||
# install missing and outdated packages
|
||||
#- Rscript -e 'source(".gitlab-ci.R"); gl_update_pkg_all(repos = "https://cran.rstudio.com", quiet = TRUE, install_pkgdown = TRUE)'
|
||||
#- Rscript -e "devtools::install(build = TRUE, upgrade = FALSE)"
|
||||
#- R -e "pkgdown::build_site(examples = FALSE, lazy = TRUE, override = list(destination = 'public'))"
|
||||
artifacts:
|
||||
paths:
|
||||
- public
|
||||
@@ -0,0 +1,199 @@
|
||||
<!DOCTYPE html>
|
||||
<!-- Generated by pkgdown: do not edit by hand --><html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<title>Page not found (404) • AMR (for R)</title>
|
||||
<!-- favicons --><link rel="icon" type="image/png" sizes="16x16" href="https://msberends.github.io/AMR/favicon-16x16.png">
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="https://msberends.github.io/AMR/favicon-32x32.png">
|
||||
<link rel="apple-touch-icon" type="image/png" sizes="180x180" href="https://msberends.github.io/AMR/apple-touch-icon.png">
|
||||
<link rel="apple-touch-icon" type="image/png" sizes="120x120" href="https://msberends.github.io/AMR/apple-touch-icon-120x120.png">
|
||||
<link rel="apple-touch-icon" type="image/png" sizes="76x76" href="https://msberends.github.io/AMR/apple-touch-icon-76x76.png">
|
||||
<link rel="apple-touch-icon" type="image/png" sizes="60x60" href="https://msberends.github.io/AMR/apple-touch-icon-60x60.png">
|
||||
<script src="https://msberends.github.io/AMR/deps/jquery-3.6.0/jquery-3.6.0.min.js"></script><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<link href="https://msberends.github.io/AMR/deps/bootstrap-5.2.2/bootstrap.min.css" rel="stylesheet">
|
||||
<script src="https://msberends.github.io/AMR/deps/bootstrap-5.2.2/bootstrap.bundle.min.js"></script><link href="https://msberends.github.io/AMR/deps/Fira_Code-0.4.5/font.css" rel="stylesheet">
|
||||
<!-- Font Awesome icons --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css" integrity="sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk=" crossorigin="anonymous">
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/v4-shims.min.css" integrity="sha256-wZjR52fzng1pJHwx4aV2AO3yyTOXrcDW7jBpJtTwVxw=" crossorigin="anonymous">
|
||||
<!-- bootstrap-toc --><script src="https://cdn.jsdelivr.net/gh/afeld/bootstrap-toc@v1.0.1/dist/bootstrap-toc.min.js" integrity="sha256-4veVQbu7//Lk5TSmc7YV48MxtMy98e26cf5MrgZYnwo=" crossorigin="anonymous"></script><!-- headroom.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/headroom.min.js" integrity="sha256-AsUX4SJE1+yuDu5+mAVzJbuYNPHj/WroHuZ8Ir/CkE0=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/jQuery.headroom.min.js" integrity="sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4=" crossorigin="anonymous"></script><!-- clipboard.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js" integrity="sha256-inc5kl9MA1hkeYUt+EC3BhlIgyp/2jDIyBLS6k3UxPI=" crossorigin="anonymous"></script><!-- search --><script src="https://cdnjs.cloudflare.com/ajax/libs/fuse.js/6.4.6/fuse.js" integrity="sha512-zv6Ywkjyktsohkbp9bb45V6tEMoWhzFzXis+LrMehmJZZSys19Yxf1dopHx7WzIKxr5tK2dVcYmaCk2uqdjF4A==" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/autocomplete.js/0.38.0/autocomplete.jquery.min.js" integrity="sha512-GU9ayf+66Xx2TmpxqJpliWbT5PiGYxpaG8rfnBEk1LL8l1KGkRShhngwdXK1UgqhAzWpZHSiYPc09/NwDQIGyg==" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mark.js/8.11.1/mark.min.js" integrity="sha512-5CYOlHXGh6QpOFA/TeTylKLWfB3ftPsde7AnmhuitiTX4K5SqCLBeKro6sPS8ilsz1Q4NRx3v8Ko2IBiszzdww==" crossorigin="anonymous"></script><!-- pkgdown --><script src="https://msberends.github.io/AMR/pkgdown.js"></script><link href="https://msberends.github.io/AMR/extra.css" rel="stylesheet">
|
||||
<script src="https://msberends.github.io/AMR/extra.js"></script><meta property="og:title" content="Page not found (404)">
|
||||
<meta property="og:image" content="https://msberends.github.io/AMR/logo.svg">
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
<meta name="twitter:creator" content="@msberends">
|
||||
<meta name="twitter:site" content="@msberends">
|
||||
<!-- mathjax --><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script><!--[if lt IE 9]>
|
||||
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
|
||||
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
|
||||
<![endif]-->
|
||||
</head>
|
||||
<body>
|
||||
<a href="https://msberends.github.io/AMR/#main" class="visually-hidden-focusable">Skip to contents</a>
|
||||
|
||||
|
||||
<nav class="navbar fixed-top navbar-dark navbar-expand-lg bg-primary"><div class="container">
|
||||
|
||||
<a class="navbar-brand me-2" href="https://msberends.github.io/AMR/index.html">AMR (for R)</a>
|
||||
|
||||
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">1.8.2.9139</small>
|
||||
|
||||
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<div id="navbar" class="collapse navbar-collapse ms-3">
|
||||
<ul class="navbar-nav me-auto">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="https://msberends.github.io/AMR/index.html">
|
||||
<span class="fa fa-home"></span>
|
||||
|
||||
Home
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item dropdown">
|
||||
<a href="https://msberends.github.io/AMR/#" class="nav-link dropdown-toggle" data-bs-toggle="dropdown" role="button" aria-expanded="false" aria-haspopup="true" id="dropdown--how-to">
|
||||
<span class="fa fa-question-circle"></span>
|
||||
|
||||
How to
|
||||
</a>
|
||||
<div class="dropdown-menu" aria-labelledby="dropdown--how-to">
|
||||
<a class="dropdown-item" href="https://msberends.github.io/AMR/reference/AMR-options.html">
|
||||
<span class="fa fa-gear"></span>
|
||||
|
||||
User- Or Team-specific Package Settings
|
||||
</a>
|
||||
<a class="dropdown-item" href="https://msberends.github.io/AMR/articles/AMR.html">
|
||||
<span class="fa fa-directions"></span>
|
||||
|
||||
Conduct AMR Analysis
|
||||
</a>
|
||||
<a class="dropdown-item" href="https://msberends.github.io/AMR/reference/antibiogram.html">
|
||||
<span class="fa fa-file-prescription"></span>
|
||||
|
||||
Generate Antibiogram (Trad./Syndromic/WISCA)
|
||||
</a>
|
||||
<a class="dropdown-item" href="https://msberends.github.io/AMR/articles/resistance_predict.html">
|
||||
<span class="fa fa-dice"></span>
|
||||
|
||||
Predict Antimicrobial Resistance
|
||||
</a>
|
||||
<a class="dropdown-item" href="https://msberends.github.io/AMR/articles/datasets.html">
|
||||
<span class="fa fa-database"></span>
|
||||
|
||||
Data Sets for Download / Own Use
|
||||
</a>
|
||||
<a class="dropdown-item" href="https://msberends.github.io/AMR/articles/PCA.html">
|
||||
<span class="fa fa-compress"></span>
|
||||
|
||||
Conduct Principal Component Analysis for AMR
|
||||
</a>
|
||||
<a class="dropdown-item" href="https://msberends.github.io/AMR/articles/MDR.html">
|
||||
<span class="fa fa-skull-crossbones"></span>
|
||||
|
||||
Determine Multi-Drug Resistance (MDR)
|
||||
</a>
|
||||
<a class="dropdown-item" href="https://msberends.github.io/AMR/articles/WHONET.html">
|
||||
<span class="fa fa-globe-americas"></span>
|
||||
|
||||
Work with WHONET Data
|
||||
</a>
|
||||
<a class="dropdown-item" href="https://msberends.github.io/AMR/articles/SPSS.html">
|
||||
<span class="fa fa-file-upload"></span>
|
||||
|
||||
Import Data From SPSS/SAS/Stata
|
||||
</a>
|
||||
<a class="dropdown-item" href="https://msberends.github.io/AMR/articles/EUCAST.html">
|
||||
<span class="fa fa-exchange-alt"></span>
|
||||
|
||||
Apply Eucast Rules
|
||||
</a>
|
||||
<a class="dropdown-item" href="https://msberends.github.io/AMR/reference/mo_property.html">
|
||||
<span class="fa fa-bug"></span>
|
||||
|
||||
Get Taxonomy of a Microorganism
|
||||
</a>
|
||||
<a class="dropdown-item" href="https://msberends.github.io/AMR/reference/ab_property.html">
|
||||
<span class="fa fa-capsules"></span>
|
||||
|
||||
Get Properties of an Antibiotic Drug
|
||||
</a>
|
||||
<a class="dropdown-item" href="https://msberends.github.io/AMR/reference/av_property.html">
|
||||
<span class="fa fa-capsules"></span>
|
||||
|
||||
Get Properties of an Antiviral Drug
|
||||
</a>
|
||||
</div>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="https://msberends.github.io/AMR/reference/index.html">
|
||||
<span class="fa fa-book-open"></span>
|
||||
|
||||
Manual
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="https://msberends.github.io/AMR/authors.html">
|
||||
<span class="fa fa-users"></span>
|
||||
|
||||
Authors
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="https://msberends.github.io/AMR/news/index.html">
|
||||
<span class="far fa far fa-newspaper"></span>
|
||||
|
||||
Changelog
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
<form class="form-inline my-2 my-lg-0" role="search">
|
||||
<input type="search" class="form-control me-sm-2" aria-label="Toggle navigation" name="search-input" data-search-index="search.json" id="search-input" placeholder="Search for" autocomplete="off">
|
||||
</form>
|
||||
|
||||
<ul class="navbar-nav">
|
||||
<li class="nav-item">
|
||||
<a class="external-link nav-link" href="https://github.com/msberends/AMR">
|
||||
<span class="fab fa fab fa-github"></span>
|
||||
|
||||
Source Code
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</nav><div class="container template-title-body">
|
||||
<div class="row">
|
||||
<main id="main" class="col-md-9"><div class="page-header">
|
||||
<img src="https://msberends.github.io/AMR/logo.svg" class="logo" alt=""><h1>Page not found (404)</h1>
|
||||
|
||||
</div>
|
||||
|
||||
Content not found. Please use links in the navbar.
|
||||
|
||||
</main>
|
||||
</div>
|
||||
|
||||
|
||||
<footer><div class="pkgdown-footer-left">
|
||||
<p></p>
|
||||
<p><code>AMR</code> (for R). Free and open-source, licenced under the <a target="_blank" href="https://github.com/msberends/AMR/blob/main/LICENSE" class="external-link">GNU General Public License version 2.0 (GPL-2)</a>.<br>Developed at the <a target="_blank" href="https://www.rug.nl" class="external-link">University of Groningen</a> and <a target="_blank" href="https://www.umcg.nl" class="external-link">University Medical Center Groningen</a> in The Netherlands.</p>
|
||||
</div>
|
||||
|
||||
<div class="pkgdown-footer-right">
|
||||
<p></p>
|
||||
<p><a target="_blank" href="https://www.rug.nl" class="external-link"><img src="https://github.com/msberends/AMR/raw/main/pkgdown/logos/logo_rug.svg" style="max-width: 150px;"></a><a target="_blank" href="https://www.umcg.nl" class="external-link"><img src="https://github.com/msberends/AMR/raw/main/pkgdown/logos/logo_umcg.svg" style="max-width: 150px;"></a></p>
|
||||
</div>
|
||||
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
After Width: | Height: | Size: 144 KiB |
|
After Width: | Height: | Size: 464 KiB |
@@ -1,73 +0,0 @@
|
||||
Package: AMR
|
||||
Version: 0.7.0
|
||||
Date: 2019-06-03
|
||||
Title: Antimicrobial Resistance Analysis
|
||||
Authors@R: c(
|
||||
person(
|
||||
given = c("Matthijs", "S."),
|
||||
family = "Berends",
|
||||
email = "m.s.berends@umcg.nl",
|
||||
role = c("aut", "cre"),
|
||||
comment = c(ORCID = "0000-0001-7620-1800")),
|
||||
person(
|
||||
given = c("Christian", "F."),
|
||||
family = "Luz",
|
||||
email = "c.f.luz@umcg.nl",
|
||||
role = "aut",
|
||||
comment = c(ORCID = "0000-0001-5809-5995")),
|
||||
person(
|
||||
given = c("Erwin", "E.", "A."),
|
||||
family = "Hassing",
|
||||
email = "e.hassing@certe.nl",
|
||||
role = "ctb"),
|
||||
person(
|
||||
given = "Corinna",
|
||||
family = "Glasner",
|
||||
email = "c.glasner@umcg.nl",
|
||||
role = c("aut", "ths"),
|
||||
comment = c(ORCID = "0000-0003-1241-1328")),
|
||||
person(
|
||||
given = c("Alex", "W."),
|
||||
family = "Friedrich",
|
||||
email = "alex.friedrich@umcg.nl",
|
||||
role = c("aut", "ths"),
|
||||
comment = c(ORCID = "0000-0003-4881-038X")),
|
||||
person(
|
||||
given = c("Bhanu", "N.", "M."),
|
||||
family = "Sinha",
|
||||
email = "b.sinha@umcg.nl",
|
||||
role = c("aut", "ths"),
|
||||
comment = c(ORCID = "0000-0003-1634-0010")))
|
||||
Description: Functions to simplify the analysis and prediction of Antimicrobial
|
||||
Resistance (AMR) and to work with microbial and antimicrobial properties by
|
||||
using evidence-based methods.
|
||||
Depends:
|
||||
R (>= 3.1.0)
|
||||
Imports:
|
||||
backports,
|
||||
crayon (>= 1.3.0),
|
||||
data.table (>= 1.9.0),
|
||||
dplyr (>= 0.7.0),
|
||||
ggplot2,
|
||||
hms,
|
||||
knitr (>= 1.0.0),
|
||||
microbenchmark,
|
||||
rlang (>= 0.3.1),
|
||||
scales,
|
||||
tidyr (>= 0.7.0)
|
||||
Suggests:
|
||||
covr (>= 3.0.1),
|
||||
curl,
|
||||
readxl,
|
||||
rmarkdown,
|
||||
rstudioapi,
|
||||
rvest (>= 0.3.2),
|
||||
testthat (>= 1.0.2),
|
||||
xml2 (>= 1.0.0)
|
||||
VignetteBuilder: knitr
|
||||
URL: https://msberends.gitlab.io/AMR, https://gitlab.com/msberends/AMR
|
||||
BugReports: https://gitlab.com/msberends/AMR/issues
|
||||
License: GPL-2 | file LICENSE
|
||||
Encoding: UTF-8
|
||||
LazyData: true
|
||||
RoxygenNote: 6.1.1
|
||||
@@ -1,339 +0,0 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc., <http://fsf.org/>
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
{description}
|
||||
Copyright (C) {year} {fullname}
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
{signature of Ty Coon}, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
||||
@@ -0,0 +1,412 @@
|
||||
<!DOCTYPE html>
|
||||
<!-- Generated by pkgdown: do not edit by hand --><html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"><title>License • AMR (for R)</title><!-- favicons --><link rel="icon" type="image/png" sizes="16x16" href="favicon-16x16.png"><link rel="icon" type="image/png" sizes="32x32" href="favicon-32x32.png"><link rel="apple-touch-icon" type="image/png" sizes="180x180" href="apple-touch-icon.png"><link rel="apple-touch-icon" type="image/png" sizes="120x120" href="apple-touch-icon-120x120.png"><link rel="apple-touch-icon" type="image/png" sizes="76x76" href="apple-touch-icon-76x76.png"><link rel="apple-touch-icon" type="image/png" sizes="60x60" href="apple-touch-icon-60x60.png"><script src="deps/jquery-3.6.0/jquery-3.6.0.min.js"></script><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"><link href="deps/bootstrap-5.2.2/bootstrap.min.css" rel="stylesheet"><script src="deps/bootstrap-5.2.2/bootstrap.bundle.min.js"></script><link href="deps/Fira_Code-0.4.5/font.css" rel="stylesheet"><!-- Font Awesome icons --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css" integrity="sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk=" crossorigin="anonymous"><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/v4-shims.min.css" integrity="sha256-wZjR52fzng1pJHwx4aV2AO3yyTOXrcDW7jBpJtTwVxw=" crossorigin="anonymous"><!-- bootstrap-toc --><script src="https://cdn.jsdelivr.net/gh/afeld/bootstrap-toc@v1.0.1/dist/bootstrap-toc.min.js" integrity="sha256-4veVQbu7//Lk5TSmc7YV48MxtMy98e26cf5MrgZYnwo=" crossorigin="anonymous"></script><!-- headroom.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/headroom.min.js" integrity="sha256-AsUX4SJE1+yuDu5+mAVzJbuYNPHj/WroHuZ8Ir/CkE0=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/jQuery.headroom.min.js" integrity="sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4=" crossorigin="anonymous"></script><!-- clipboard.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js" integrity="sha256-inc5kl9MA1hkeYUt+EC3BhlIgyp/2jDIyBLS6k3UxPI=" crossorigin="anonymous"></script><!-- search --><script src="https://cdnjs.cloudflare.com/ajax/libs/fuse.js/6.4.6/fuse.js" integrity="sha512-zv6Ywkjyktsohkbp9bb45V6tEMoWhzFzXis+LrMehmJZZSys19Yxf1dopHx7WzIKxr5tK2dVcYmaCk2uqdjF4A==" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/autocomplete.js/0.38.0/autocomplete.jquery.min.js" integrity="sha512-GU9ayf+66Xx2TmpxqJpliWbT5PiGYxpaG8rfnBEk1LL8l1KGkRShhngwdXK1UgqhAzWpZHSiYPc09/NwDQIGyg==" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mark.js/8.11.1/mark.min.js" integrity="sha512-5CYOlHXGh6QpOFA/TeTylKLWfB3ftPsde7AnmhuitiTX4K5SqCLBeKro6sPS8ilsz1Q4NRx3v8Ko2IBiszzdww==" crossorigin="anonymous"></script><!-- pkgdown --><script src="pkgdown.js"></script><link href="extra.css" rel="stylesheet"><script src="extra.js"></script><meta property="og:title" content="License"><meta property="og:image" content="https://msberends.github.io/AMR/logo.svg"><meta name="twitter:card" content="summary_large_image"><meta name="twitter:creator" content="@msberends"><meta name="twitter:site" content="@msberends"><!-- mathjax --><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script><!--[if lt IE 9]>
|
||||
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
|
||||
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
|
||||
<![endif]--></head><body>
|
||||
<a href="#main" class="visually-hidden-focusable">Skip to contents</a>
|
||||
|
||||
|
||||
<nav class="navbar fixed-top navbar-dark navbar-expand-lg bg-primary"><div class="container">
|
||||
|
||||
<a class="navbar-brand me-2" href="index.html">AMR (for R)</a>
|
||||
|
||||
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">1.8.2.9139</small>
|
||||
|
||||
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<div id="navbar" class="collapse navbar-collapse ms-3">
|
||||
<ul class="navbar-nav me-auto"><li class="nav-item">
|
||||
<a class="nav-link" href="index.html">
|
||||
<span class="fa fa-home"></span>
|
||||
|
||||
Home
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item dropdown">
|
||||
<a href="#" class="nav-link dropdown-toggle" data-bs-toggle="dropdown" role="button" aria-expanded="false" aria-haspopup="true" id="dropdown--how-to">
|
||||
<span class="fa fa-question-circle"></span>
|
||||
|
||||
How to
|
||||
</a>
|
||||
<div class="dropdown-menu" aria-labelledby="dropdown--how-to">
|
||||
<a class="dropdown-item" href="reference/AMR-options.html">
|
||||
<span class="fa fa-gear"></span>
|
||||
|
||||
User- Or Team-specific Package Settings
|
||||
</a>
|
||||
<a class="dropdown-item" href="articles/AMR.html">
|
||||
<span class="fa fa-directions"></span>
|
||||
|
||||
Conduct AMR Analysis
|
||||
</a>
|
||||
<a class="dropdown-item" href="reference/antibiogram.html">
|
||||
<span class="fa fa-file-prescription"></span>
|
||||
|
||||
Generate Antibiogram (Trad./Syndromic/WISCA)
|
||||
</a>
|
||||
<a class="dropdown-item" href="articles/resistance_predict.html">
|
||||
<span class="fa fa-dice"></span>
|
||||
|
||||
Predict Antimicrobial Resistance
|
||||
</a>
|
||||
<a class="dropdown-item" href="articles/datasets.html">
|
||||
<span class="fa fa-database"></span>
|
||||
|
||||
Data Sets for Download / Own Use
|
||||
</a>
|
||||
<a class="dropdown-item" href="articles/PCA.html">
|
||||
<span class="fa fa-compress"></span>
|
||||
|
||||
Conduct Principal Component Analysis for AMR
|
||||
</a>
|
||||
<a class="dropdown-item" href="articles/MDR.html">
|
||||
<span class="fa fa-skull-crossbones"></span>
|
||||
|
||||
Determine Multi-Drug Resistance (MDR)
|
||||
</a>
|
||||
<a class="dropdown-item" href="articles/WHONET.html">
|
||||
<span class="fa fa-globe-americas"></span>
|
||||
|
||||
Work with WHONET Data
|
||||
</a>
|
||||
<a class="dropdown-item" href="articles/SPSS.html">
|
||||
<span class="fa fa-file-upload"></span>
|
||||
|
||||
Import Data From SPSS/SAS/Stata
|
||||
</a>
|
||||
<a class="dropdown-item" href="articles/EUCAST.html">
|
||||
<span class="fa fa-exchange-alt"></span>
|
||||
|
||||
Apply Eucast Rules
|
||||
</a>
|
||||
<a class="dropdown-item" href="reference/mo_property.html">
|
||||
<span class="fa fa-bug"></span>
|
||||
|
||||
Get Taxonomy of a Microorganism
|
||||
</a>
|
||||
<a class="dropdown-item" href="reference/ab_property.html">
|
||||
<span class="fa fa-capsules"></span>
|
||||
|
||||
Get Properties of an Antibiotic Drug
|
||||
</a>
|
||||
<a class="dropdown-item" href="reference/av_property.html">
|
||||
<span class="fa fa-capsules"></span>
|
||||
|
||||
Get Properties of an Antiviral Drug
|
||||
</a>
|
||||
</div>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="reference/index.html">
|
||||
<span class="fa fa-book-open"></span>
|
||||
|
||||
Manual
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="authors.html">
|
||||
<span class="fa fa-users"></span>
|
||||
|
||||
Authors
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="news/index.html">
|
||||
<span class="far fa far fa-newspaper"></span>
|
||||
|
||||
Changelog
|
||||
</a>
|
||||
</li>
|
||||
</ul><form class="form-inline my-2 my-lg-0" role="search">
|
||||
<input type="search" class="form-control me-sm-2" aria-label="Toggle navigation" name="search-input" data-search-index="search.json" id="search-input" placeholder="Search for" autocomplete="off"></form>
|
||||
|
||||
<ul class="navbar-nav"><li class="nav-item">
|
||||
<a class="external-link nav-link" href="https://github.com/msberends/AMR">
|
||||
<span class="fab fa fab fa-github"></span>
|
||||
|
||||
Source Code
|
||||
</a>
|
||||
</li>
|
||||
</ul></div>
|
||||
|
||||
|
||||
</div>
|
||||
</nav><div class="container template-title-body">
|
||||
<div class="row">
|
||||
<main id="main" class="col-md-9"><div class="page-header">
|
||||
<img src="logo.svg" class="logo" alt=""><h1>License</h1>
|
||||
|
||||
</div>
|
||||
|
||||
<pre>GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc., <http://fsf.org/>
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
A SUMMARY OF THIS LICENSE BY THE ORIGINAL AUTHORS OF THE AMR R PACKAGE
|
||||
|
||||
This R package, with package name 'AMR':
|
||||
- May be used for commercial purposes
|
||||
- May be used for private purposes
|
||||
- May NOT be used for patent purposes
|
||||
- May be modified, although:
|
||||
- Modifications MUST be released under the same license when distributing the package
|
||||
- Changes made to the code MUST be documented
|
||||
- May be distributed, although:
|
||||
- Source code MUST be made available when the package is distributed
|
||||
- A copy of the license and copyright notice MUST be included with the package.
|
||||
- Comes with a LIMITATION of liability
|
||||
- Comes with NO warranty
|
||||
|
||||
END OF THE SUMMARY
|
||||
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
</pre>
|
||||
|
||||
</main></div>
|
||||
|
||||
|
||||
<footer><div class="pkgdown-footer-left">
|
||||
<p></p><p><code>AMR</code> (for R). Free and open-source, licenced under the <a target="_blank" href="https://github.com/msberends/AMR/blob/main/LICENSE" class="external-link">GNU General Public License version 2.0 (GPL-2)</a>.<br>Developed at the <a target="_blank" href="https://www.rug.nl" class="external-link">University of Groningen</a> and <a target="_blank" href="https://www.umcg.nl" class="external-link">University Medical Center Groningen</a> in The Netherlands.</p>
|
||||
</div>
|
||||
|
||||
<div class="pkgdown-footer-right">
|
||||
<p></p><p><a target="_blank" href="https://www.rug.nl" class="external-link"><img src="https://github.com/msberends/AMR/raw/main/pkgdown/logos/logo_rug.svg" style="max-width: 150px;"></a><a target="_blank" href="https://www.umcg.nl" class="external-link"><img src="https://github.com/msberends/AMR/raw/main/pkgdown/logos/logo_umcg.svg" style="max-width: 150px;"></a></p>
|
||||
</div>
|
||||
|
||||
</footer></div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</body></html>
|
||||
|
||||
@@ -1,315 +0,0 @@
|
||||
# Generated by roxygen2: do not edit by hand
|
||||
|
||||
S3method(as.data.frame,ab)
|
||||
S3method(as.data.frame,atc)
|
||||
S3method(as.data.frame,freq)
|
||||
S3method(as.data.frame,mo)
|
||||
S3method(as.double,mic)
|
||||
S3method(as.integer,mic)
|
||||
S3method(as.numeric,mic)
|
||||
S3method(as.rsi,data.frame)
|
||||
S3method(as.rsi,default)
|
||||
S3method(as.rsi,disk)
|
||||
S3method(as.rsi,mic)
|
||||
S3method(as.vector,freq)
|
||||
S3method(as_tibble,freq)
|
||||
S3method(barplot,mic)
|
||||
S3method(barplot,rsi)
|
||||
S3method(boxplot,freq)
|
||||
S3method(diff,freq)
|
||||
S3method(droplevels,mic)
|
||||
S3method(droplevels,rsi)
|
||||
S3method(format,freq)
|
||||
S3method(hist,freq)
|
||||
S3method(kurtosis,data.frame)
|
||||
S3method(kurtosis,default)
|
||||
S3method(kurtosis,matrix)
|
||||
S3method(plot,freq)
|
||||
S3method(plot,mic)
|
||||
S3method(plot,resistance_predict)
|
||||
S3method(plot,rsi)
|
||||
S3method(print,ab)
|
||||
S3method(print,atc)
|
||||
S3method(print,catalogue_of_life_version)
|
||||
S3method(print,disk)
|
||||
S3method(print,freq)
|
||||
S3method(print,frequency_tbl)
|
||||
S3method(print,mic)
|
||||
S3method(print,mo)
|
||||
S3method(print,mo_renamed)
|
||||
S3method(print,mo_uncertainties)
|
||||
S3method(print,rsi)
|
||||
S3method(pull,ab)
|
||||
S3method(pull,atc)
|
||||
S3method(pull,mo)
|
||||
S3method(select,freq)
|
||||
S3method(skewness,data.frame)
|
||||
S3method(skewness,default)
|
||||
S3method(skewness,matrix)
|
||||
S3method(summary,mic)
|
||||
S3method(summary,mo)
|
||||
S3method(summary,rsi)
|
||||
export("%like%")
|
||||
export(ab_atc)
|
||||
export(ab_atc_group1)
|
||||
export(ab_atc_group2)
|
||||
export(ab_cid)
|
||||
export(ab_ddd)
|
||||
export(ab_group)
|
||||
export(ab_info)
|
||||
export(ab_name)
|
||||
export(ab_official)
|
||||
export(ab_property)
|
||||
export(ab_synonyms)
|
||||
export(ab_tradenames)
|
||||
export(abname)
|
||||
export(age)
|
||||
export(age_groups)
|
||||
export(anti_join_microorganisms)
|
||||
export(as.ab)
|
||||
export(as.atc)
|
||||
export(as.disk)
|
||||
export(as.mic)
|
||||
export(as.mo)
|
||||
export(as.rsi)
|
||||
export(atc_name)
|
||||
export(atc_official)
|
||||
export(atc_online_ddd)
|
||||
export(atc_online_groups)
|
||||
export(atc_online_property)
|
||||
export(atc_property)
|
||||
export(atc_tradenames)
|
||||
export(atc_trivial_nl)
|
||||
export(availability)
|
||||
export(brmo)
|
||||
export(catalogue_of_life_version)
|
||||
export(count_I)
|
||||
export(count_IR)
|
||||
export(count_R)
|
||||
export(count_S)
|
||||
export(count_SI)
|
||||
export(count_all)
|
||||
export(count_df)
|
||||
export(eucast_exceptional_phenotypes)
|
||||
export(eucast_rules)
|
||||
export(facet_rsi)
|
||||
export(filter_1st_cephalosporins)
|
||||
export(filter_2nd_cephalosporins)
|
||||
export(filter_3rd_cephalosporins)
|
||||
export(filter_4th_cephalosporins)
|
||||
export(filter_ab_class)
|
||||
export(filter_aminoglycosides)
|
||||
export(filter_carbapenems)
|
||||
export(filter_cephalosporins)
|
||||
export(filter_first_isolate)
|
||||
export(filter_first_weighted_isolate)
|
||||
export(filter_fluoroquinolones)
|
||||
export(filter_glycopeptides)
|
||||
export(filter_macrolides)
|
||||
export(filter_tetracyclines)
|
||||
export(first_isolate)
|
||||
export(freq)
|
||||
export(frequency_tbl)
|
||||
export(full_join_microorganisms)
|
||||
export(g.test)
|
||||
export(geom_rsi)
|
||||
export(get_locale)
|
||||
export(get_mo_source)
|
||||
export(ggplot_rsi)
|
||||
export(ggplot_rsi_predict)
|
||||
export(guess_ab_col)
|
||||
export(header)
|
||||
export(inner_join_microorganisms)
|
||||
export(is.ab)
|
||||
export(is.atc)
|
||||
export(is.disk)
|
||||
export(is.mic)
|
||||
export(is.mo)
|
||||
export(is.rsi)
|
||||
export(is.rsi.eligible)
|
||||
export(key_antibiotics)
|
||||
export(key_antibiotics_equal)
|
||||
export(kurtosis)
|
||||
export(labels_rsi_count)
|
||||
export(left_join_microorganisms)
|
||||
export(like)
|
||||
export(mdr_tb)
|
||||
export(mdro)
|
||||
export(mo_authors)
|
||||
export(mo_class)
|
||||
export(mo_failures)
|
||||
export(mo_family)
|
||||
export(mo_fullname)
|
||||
export(mo_genus)
|
||||
export(mo_gramstain)
|
||||
export(mo_kingdom)
|
||||
export(mo_name)
|
||||
export(mo_order)
|
||||
export(mo_phylum)
|
||||
export(mo_property)
|
||||
export(mo_rank)
|
||||
export(mo_ref)
|
||||
export(mo_renamed)
|
||||
export(mo_shortname)
|
||||
export(mo_species)
|
||||
export(mo_subspecies)
|
||||
export(mo_taxonomy)
|
||||
export(mo_type)
|
||||
export(mo_uncertainties)
|
||||
export(mo_url)
|
||||
export(mo_year)
|
||||
export(mrgn)
|
||||
export(n_rsi)
|
||||
export(p.symbol)
|
||||
export(portion_I)
|
||||
export(portion_IR)
|
||||
export(portion_R)
|
||||
export(portion_S)
|
||||
export(portion_SI)
|
||||
export(portion_df)
|
||||
export(ratio)
|
||||
export(read.4D)
|
||||
export(resistance_predict)
|
||||
export(right_join_microorganisms)
|
||||
export(rsi_predict)
|
||||
export(scale_rsi_colours)
|
||||
export(scale_y_percent)
|
||||
export(semi_join_microorganisms)
|
||||
export(set_mo_source)
|
||||
export(skewness)
|
||||
export(theme_rsi)
|
||||
export(top_freq)
|
||||
exportMethods(as.data.frame.ab)
|
||||
exportMethods(as.data.frame.atc)
|
||||
exportMethods(as.data.frame.freq)
|
||||
exportMethods(as.data.frame.mo)
|
||||
exportMethods(as.double.mic)
|
||||
exportMethods(as.integer.mic)
|
||||
exportMethods(as.numeric.mic)
|
||||
exportMethods(as.vector.freq)
|
||||
exportMethods(as_tibble.freq)
|
||||
exportMethods(barplot.mic)
|
||||
exportMethods(barplot.rsi)
|
||||
exportMethods(boxplot.freq)
|
||||
exportMethods(diff.freq)
|
||||
exportMethods(droplevels.mic)
|
||||
exportMethods(droplevels.rsi)
|
||||
exportMethods(format.freq)
|
||||
exportMethods(hist.freq)
|
||||
exportMethods(kurtosis)
|
||||
exportMethods(kurtosis.data.frame)
|
||||
exportMethods(kurtosis.default)
|
||||
exportMethods(kurtosis.matrix)
|
||||
exportMethods(plot.freq)
|
||||
exportMethods(plot.mic)
|
||||
exportMethods(plot.rsi)
|
||||
exportMethods(print.ab)
|
||||
exportMethods(print.atc)
|
||||
exportMethods(print.catalogue_of_life_version)
|
||||
exportMethods(print.disk)
|
||||
exportMethods(print.freq)
|
||||
exportMethods(print.frequency_tbl)
|
||||
exportMethods(print.mic)
|
||||
exportMethods(print.mo)
|
||||
exportMethods(print.mo_renamed)
|
||||
exportMethods(print.mo_uncertainties)
|
||||
exportMethods(print.rsi)
|
||||
exportMethods(pull.ab)
|
||||
exportMethods(pull.atc)
|
||||
exportMethods(pull.mo)
|
||||
exportMethods(select.freq)
|
||||
exportMethods(skewness)
|
||||
exportMethods(skewness.data.frame)
|
||||
exportMethods(skewness.default)
|
||||
exportMethods(skewness.matrix)
|
||||
exportMethods(summary.mic)
|
||||
exportMethods(summary.mo)
|
||||
exportMethods(summary.rsi)
|
||||
importFrom(crayon,bgGreen)
|
||||
importFrom(crayon,bgRed)
|
||||
importFrom(crayon,bgYellow)
|
||||
importFrom(crayon,black)
|
||||
importFrom(crayon,blue)
|
||||
importFrom(crayon,bold)
|
||||
importFrom(crayon,green)
|
||||
importFrom(crayon,has_color)
|
||||
importFrom(crayon,italic)
|
||||
importFrom(crayon,magenta)
|
||||
importFrom(crayon,red)
|
||||
importFrom(crayon,silver)
|
||||
importFrom(crayon,strip_style)
|
||||
importFrom(crayon,underline)
|
||||
importFrom(crayon,white)
|
||||
importFrom(crayon,yellow)
|
||||
importFrom(data.table,as.data.table)
|
||||
importFrom(data.table,data.table)
|
||||
importFrom(data.table,setkey)
|
||||
importFrom(dplyr,"%>%")
|
||||
importFrom(dplyr,all_vars)
|
||||
importFrom(dplyr,any_vars)
|
||||
importFrom(dplyr,arrange)
|
||||
importFrom(dplyr,arrange_at)
|
||||
importFrom(dplyr,as_tibble)
|
||||
importFrom(dplyr,between)
|
||||
importFrom(dplyr,bind_cols)
|
||||
importFrom(dplyr,bind_rows)
|
||||
importFrom(dplyr,case_when)
|
||||
importFrom(dplyr,desc)
|
||||
importFrom(dplyr,distinct)
|
||||
importFrom(dplyr,everything)
|
||||
importFrom(dplyr,filter)
|
||||
importFrom(dplyr,filter_all)
|
||||
importFrom(dplyr,filter_at)
|
||||
importFrom(dplyr,full_join)
|
||||
importFrom(dplyr,funs)
|
||||
importFrom(dplyr,group_by)
|
||||
importFrom(dplyr,group_by_at)
|
||||
importFrom(dplyr,group_vars)
|
||||
importFrom(dplyr,if_else)
|
||||
importFrom(dplyr,lag)
|
||||
importFrom(dplyr,left_join)
|
||||
importFrom(dplyr,mutate)
|
||||
importFrom(dplyr,mutate_all)
|
||||
importFrom(dplyr,mutate_at)
|
||||
importFrom(dplyr,n)
|
||||
importFrom(dplyr,n_distinct)
|
||||
importFrom(dplyr,n_groups)
|
||||
importFrom(dplyr,progress_estimated)
|
||||
importFrom(dplyr,pull)
|
||||
importFrom(dplyr,row_number)
|
||||
importFrom(dplyr,select)
|
||||
importFrom(dplyr,select_if)
|
||||
importFrom(dplyr,slice)
|
||||
importFrom(dplyr,summarise)
|
||||
importFrom(dplyr,summarise_if)
|
||||
importFrom(dplyr,tibble)
|
||||
importFrom(dplyr,top_n)
|
||||
importFrom(dplyr,transmute)
|
||||
importFrom(dplyr,ungroup)
|
||||
importFrom(dplyr,vars)
|
||||
importFrom(grDevices,boxplot.stats)
|
||||
importFrom(graphics,arrows)
|
||||
importFrom(graphics,axis)
|
||||
importFrom(graphics,barplot)
|
||||
importFrom(graphics,boxplot)
|
||||
importFrom(graphics,hist)
|
||||
importFrom(graphics,plot)
|
||||
importFrom(graphics,points)
|
||||
importFrom(graphics,text)
|
||||
importFrom(hms,is.hms)
|
||||
importFrom(knitr,kable)
|
||||
importFrom(microbenchmark,microbenchmark)
|
||||
importFrom(rlang,as_label)
|
||||
importFrom(rlang,enquos)
|
||||
importFrom(rlang,eval_tidy)
|
||||
importFrom(stats,complete.cases)
|
||||
importFrom(stats,fivenum)
|
||||
importFrom(stats,glm)
|
||||
importFrom(stats,lm)
|
||||
importFrom(stats,mad)
|
||||
importFrom(stats,pchisq)
|
||||
importFrom(stats,predict)
|
||||
importFrom(stats,sd)
|
||||
importFrom(utils,browseURL)
|
||||
importFrom(utils,browseVignettes)
|
||||
importFrom(utils,installed.packages)
|
||||
@@ -1,571 +0,0 @@
|
||||
# AMR 0.7.0
|
||||
|
||||
#### New
|
||||
* Support for translation of disk diffusion and MIC values to RSI values (i.e. antimicrobial interpretations). Supported guidelines are EUCAST (2011 to 2019) and CLSI (2011 to 2019). Use `as.rsi()` on an MIC value (created with `as.mic()`), a disk diffusion value (created with the new `as.disk()`) or on a complete date set containing columns with MIC or disk diffusion values.
|
||||
* Function `mo_name()` as alias of `mo_fullname()`
|
||||
* Added guidelines of the WHO to determine multi-drug resistance (MDR) for TB (`mdr_tb()`) and added a new vignette about MDR. Read this tutorial [here on our website](https://msberends.gitlab.io/AMR/articles/MDR.html).
|
||||
|
||||
#### Changed
|
||||
* Fixed a critical bug in `first_isolate()` where missing species would lead to incorrect FALSEs. This bug was not present in AMR v0.5.0, but was in v0.6.0 and v0.6.1.
|
||||
* Fixedd a bug in `eucast_rules()` where antibiotics from WHONET software would not be recognised
|
||||
* Completely reworked the `antibiotics` data set:
|
||||
* All entries now have 3 different identifiers:
|
||||
* Column `ab` contains a human readable EARS-Net code, used by ECDC and WHO/WHONET - this is the primary identifier used in this package
|
||||
* Column `atc` contains the ATC code, used by WHO/WHOCC
|
||||
* Column `cid` contains the CID code (Compound ID), used by PubChem
|
||||
* Based on the Compound ID, almost 5,000 official brand names have been added from many different countries
|
||||
* All references to antibiotics in our package now use EARS-Net codes, like `AMX` for amoxicillin
|
||||
* Functions `atc_certe`, `ab_umcg` and `atc_trivial_nl` have been removed
|
||||
* All `atc_*` functions are superceded by `ab_*` functions
|
||||
* All output will be translated by using an included translation file which [can be viewed here](https://gitlab.com/msberends/AMR/blob/master/data-raw/translations.tsv).
|
||||
|
||||
Please [create an issue in one of our repositories](https://gitlab.com/msberends/AMR/issues/new?issue[title]=Translation%20suggestion) if you want additions in this file.
|
||||
* Improvements to plotting AMR results with `ggplot_rsi()`:
|
||||
* New parameter `colours` to set the bar colours
|
||||
* New parameters `title`, `subtitle`, `caption`, `x.title` and `y.title` to set titles and axis descriptions
|
||||
* Improved intelligence of looking up antibiotic columns in a data set using `guess_ab_col()`
|
||||
* Added ~5,000 more old taxonomic names to the `microorganisms.old` data set, which leads to better results finding when using the `as.mo()` function
|
||||
* This package now honours the new EUCAST insight (2019) that S and I are but classified as susceptible, where I is defined as 'increased exposure' and not 'intermediate' anymore. For functions like `portion_df()` and `count_df()` this means that their new parameter `combine_SI` is TRUE at default. Our plotting function `ggplot_rsi()` also reflects this change since it uses `count_df()` internally.
|
||||
* The `age()` function gained a new parameter `exact` to determine ages with decimals
|
||||
* Removed deprecated functions `guess_mo()`, `guess_atc()`, `EUCAST_rules()`, `interpretive_reading()`, `rsi()`
|
||||
* Frequency tables (`freq()`):
|
||||
* speed improvement for microbial IDs
|
||||
* fixed factor level names for R Markdown
|
||||
* when all values are unique it now shows a message instead of a warning
|
||||
* support for boxplots:
|
||||
```r
|
||||
septic_patients %>%
|
||||
freq(age) %>%
|
||||
boxplot()
|
||||
# grouped boxplots:
|
||||
septic_patients %>%
|
||||
group_by(hospital_id) %>%
|
||||
freq(age) %>%
|
||||
boxplot()
|
||||
```
|
||||
* Removed all hardcoded EUCAST rules and replaced them with a new reference file which [can be viewed here](https://gitlab.com/msberends/AMR/blob/master/data-raw/eucast_rules.tsv).
|
||||
|
||||
Please [create an issue in one of our repositories](https://gitlab.com/msberends/AMR/issues/new?issue[title]=EUCAST%20edit) if you want changes in this file.
|
||||
* Added ceftazidim intrinsic resistance to *Streptococci*
|
||||
* Changed default settings for `age_groups()`, to let groups of fives and tens end with 100+ instead of 120+
|
||||
* Fix for `freq()` for when all values are `NA`
|
||||
* Fix for `first_isolate()` for when dates are missing
|
||||
* Improved speed of `guess_ab_col()`
|
||||
* Function `as.mo()` now gently interprets any number of whitespace characters (like tabs) as one space
|
||||
* Function `as.mo()` now returns `UNKNOWN` for `"con"` (WHONET ID of 'contamination') and returns `NA` for `"xxx"`(WHONET ID of 'no growth')
|
||||
* Small algorithm fix for `as.mo()`
|
||||
* Removed viruses from data set `microorganisms.codes` and cleaned it up
|
||||
* Fix for `mo_shortname()` where species would not be determined correctly
|
||||
|
||||
#### Other
|
||||
* Support for R 3.6.0 and later by providing support for [staged install](https://developer.r-project.org/Blog/public/2019/02/14/staged-install/index.html)
|
||||
|
||||
# AMR 0.6.1
|
||||
|
||||
#### Changed
|
||||
* Fixed a critical bug when using `eucast_rules()` with `verbose = TRUE`
|
||||
* Coercion of microbial IDs are now written to the package namespace instead of the user's home folder, to comply with the CRAN policy
|
||||
|
||||
# AMR 0.6.0
|
||||
|
||||
**New website!**
|
||||
|
||||
We've got a new website: [https://msberends.gitlab.io/AMR](https://msberends.gitlab.io/AMR/) (built with the great [`pkgdown`](https://pkgdown.r-lib.org/))
|
||||
|
||||
* Contains the complete manual of this package and all of its functions with an explanation of their parameters
|
||||
* Contains a comprehensive tutorial about how to conduct antimicrobial resistance analysis, import data from WHONET or SPSS and many more.
|
||||
|
||||
#### New
|
||||
* **BREAKING**: removed deprecated functions, parameters and references to 'bactid'. Use `as.mo()` to identify an MO code.
|
||||
* Catalogue of Life as a new taxonomic source for data about microorganisms, which also contains all ITIS data we used previously. The `microorganisms` data set now contains:
|
||||
* All ~55,000 (sub)species from the kingdoms of Archaea, Bacteria and Protozoa
|
||||
* All ~3,000 (sub)species from these orders of the kingdom of Fungi: Eurotiales, Onygenales, Pneumocystales, Saccharomycetales and Schizosaccharomycetales (covering at least like all species of *Aspergillus*, *Candida*, *Pneumocystis*, *Saccharomyces* and *Trichophyton*)
|
||||
* All ~2,000 (sub)species from ~100 other relevant genera, from the kingdoms of Animalia and Plantae (like *Strongyloides* and *Taenia*)
|
||||
* All ~15,000 previously accepted names of included (sub)species that have been taxonomically renamed
|
||||
* The responsible author(s) and year of scientific publication
|
||||
|
||||
This data is updated annually - check the included version with the new function `catalogue_of_life_version()`.
|
||||
* Due to this change, some `mo` codes changed (e.g. *Streptococcus* changed from `B_STRPTC` to `B_STRPT`). A translation table is used internally to support older microorganism IDs, so users will not notice this difference.
|
||||
* New function `mo_rank()` for the taxonomic rank (genus, species, infraspecies, etc.)
|
||||
* New function `mo_url()` to get the direct URL of a species from the Catalogue of Life
|
||||
* Support for data from [WHONET](https://whonet.org/) and [EARS-Net](https://ecdc.europa.eu/en/about-us/partnerships-and-networks/disease-and-laboratory-networks/ears-net) (European Antimicrobial Resistance Surveillance Network):
|
||||
* Exported files from WHONET can be read and used in this package. For functions like `first_isolate()` and `eucast_rules()`, all parameters will be filled in automatically.
|
||||
* This package now knows all antibiotic abbrevations by EARS-Net (which are also being used by WHONET) - the `antibiotics` data set now contains a column `ears_net`.
|
||||
* The function `as.mo()` now knows all WHONET species abbreviations too, because almost 2,000 microbial abbreviations were added to the `microorganisms.codes` data set.
|
||||
* New filters for antimicrobial classes. Use these functions to filter isolates on results in one of more antibiotics from a specific class:
|
||||
```r
|
||||
filter_aminoglycosides()
|
||||
filter_carbapenems()
|
||||
filter_cephalosporins()
|
||||
filter_1st_cephalosporins()
|
||||
filter_2nd_cephalosporins()
|
||||
filter_3rd_cephalosporins()
|
||||
filter_4th_cephalosporins()
|
||||
filter_fluoroquinolones()
|
||||
filter_glycopeptides()
|
||||
filter_macrolides()
|
||||
filter_tetracyclines()
|
||||
```
|
||||
The `antibiotics` data set will be searched, after which the input data will be checked for column names with a value in any abbreviations, codes or official names found in the `antibiotics` data set.
|
||||
For example:
|
||||
```r
|
||||
septic_patients %>% filter_glycopeptides(result = "R")
|
||||
# Filtering on glycopeptide antibacterials: any of `vanc` or `teic` is R
|
||||
septic_patients %>% filter_glycopeptides(result = "R", scope = "all")
|
||||
# Filtering on glycopeptide antibacterials: all of `vanc` and `teic` is R
|
||||
```
|
||||
* All `ab_*` functions are deprecated and replaced by `atc_*` functions:
|
||||
```r
|
||||
ab_property -> atc_property()
|
||||
ab_name -> atc_name()
|
||||
ab_official -> atc_official()
|
||||
ab_trivial_nl -> atc_trivial_nl()
|
||||
ab_certe -> atc_certe()
|
||||
ab_umcg -> atc_umcg()
|
||||
ab_tradenames -> atc_tradenames()
|
||||
```
|
||||
These functions use `as.atc()` internally. The old `atc_property` has been renamed `atc_online_property()`. This is done for two reasons: firstly, not all ATC codes are of antibiotics (ab) but can also be of antivirals or antifungals. Secondly, the input must have class `atc` or must be coerable to this class. Properties of these classes should start with the same class name, analogous to `as.mo()` and e.g. `mo_genus`.
|
||||
* New functions `set_mo_source()` and `get_mo_source()` to use your own predefined MO codes as input for `as.mo()` and consequently all `mo_*` functions
|
||||
* Support for the upcoming [`dplyr`](https://dplyr.tidyverse.org) version 0.8.0
|
||||
* New function `guess_ab_col()` to find an antibiotic column in a table
|
||||
* New function `mo_failures()` to review values that could not be coerced to a valid MO code, using `as.mo()`. This latter function will now only show a maximum of 10 uncoerced values and will refer to `mo_failures()`.
|
||||
* New function `mo_uncertainties()` to review values that could be coerced to a valid MO code using `as.mo()`, but with uncertainty.
|
||||
* New function `mo_renamed()` to get a list of all returned values from `as.mo()` that have had taxonomic renaming
|
||||
* New function `age()` to calculate the (patients) age in years
|
||||
* New function `age_groups()` to split ages into custom or predefined groups (like children or elderly). This allows for easier demographic antimicrobial resistance analysis per age group.
|
||||
* New function `ggplot_rsi_predict()` as well as the base R `plot()` function can now be used for resistance prediction calculated with `resistance_predict()`:
|
||||
```r
|
||||
x <- resistance_predict(septic_patients, col_ab = "amox")
|
||||
plot(x)
|
||||
ggplot_rsi_predict(x)
|
||||
```
|
||||
* Functions `filter_first_isolate()` and `filter_first_weighted_isolate()` to shorten and fasten filtering on data sets with antimicrobial results, e.g.:
|
||||
```r
|
||||
septic_patients %>% filter_first_isolate(...)
|
||||
# or
|
||||
filter_first_isolate(septic_patients, ...)
|
||||
```
|
||||
is equal to:
|
||||
```r
|
||||
septic_patients %>%
|
||||
mutate(only_firsts = first_isolate(septic_patients, ...)) %>%
|
||||
filter(only_firsts == TRUE) %>%
|
||||
select(-only_firsts)
|
||||
```
|
||||
* New function `availability()` to check the number of available (non-empty) results in a `data.frame`
|
||||
* New vignettes about how to conduct AMR analysis, predict antimicrobial resistance, use the *G*-test and more. These are also available (and even easier readable) on our website: https://msberends.gitlab.io/AMR.
|
||||
|
||||
#### Changed
|
||||
* Function `eucast_rules()`:
|
||||
* Updated EUCAST Clinical breakpoints to [version 9.0 of 1 January 2019](http://www.eucast.org/clinical_breakpoints/), the data set `septic_patients` now reflects these changes
|
||||
* Fixed a critical bug where some rules that depend on previous applied rules would not be applied adequately
|
||||
* Emphasised in manual that penicillin is meant as benzylpenicillin (ATC [J01CE01](https://www.whocc.no/atc_ddd_index/?code=J01CE01))
|
||||
* New info is returned when running this function, stating exactly what has been changed or added. Use `eucast_rules(..., verbose = TRUE)` to get a data set with all changed per bug and drug combination.
|
||||
* Removed data sets `microorganisms.oldDT`, `microorganisms.prevDT`, `microorganisms.unprevDT` and `microorganismsDT` since they were no longer needed and only contained info already available in the `microorganisms` data set
|
||||
* Added 65 antibiotics to the `antibiotics` data set, from the [Pharmaceuticals Community Register](http://ec.europa.eu/health/documents/community-register/html/atc.htm) of the European Commission
|
||||
* Removed columns `atc_group1_nl` and `atc_group2_nl` from the `antibiotics` data set
|
||||
* Functions `atc_ddd()` and `atc_groups()` have been renamed `atc_online_ddd()` and `atc_online_groups()`. The old functions are deprecated and will be removed in a future version.
|
||||
* Function `guess_mo()` is now deprecated in favour of `as.mo()` and will be removed in future versions
|
||||
* Function `guess_atc()` is now deprecated in favour of `as.atc()` and will be removed in future versions
|
||||
* Improvements for `as.mo()`:
|
||||
* Now handles incorrect spelling, like `i` instead of `y` and `f` instead of `ph`:
|
||||
```r
|
||||
# mo_fullname() uses as.mo() internally
|
||||
|
||||
mo_fullname("Sthafilokockus aaureuz")
|
||||
#> [1] "Staphylococcus aureus"
|
||||
|
||||
mo_fullname("S. klossi")
|
||||
#> [1] "Staphylococcus kloosii"
|
||||
```
|
||||
* Uncertainty of the algorithm is now divided into four levels, 0 to 3, where the default `allow_uncertain = TRUE` is equal to uncertainty level 2. Run `?as.mo` for more info about these levels.
|
||||
```r
|
||||
# equal:
|
||||
as.mo(..., allow_uncertain = TRUE)
|
||||
as.mo(..., allow_uncertain = 2)
|
||||
|
||||
# also equal:
|
||||
as.mo(..., allow_uncertain = FALSE)
|
||||
as.mo(..., allow_uncertain = 0)
|
||||
```
|
||||
Using `as.mo(..., allow_uncertain = 3)` could lead to very unreliable results.
|
||||
* Implemented the latest publication of Becker *et al.* (2019), for categorising coagulase-negative *Staphylococci*
|
||||
* All microbial IDs that found are now saved to a local file `~/.Rhistory_mo`. Use the new function `clean_mo_history()` to delete this file, which resets the algorithms.
|
||||
* Incoercible results will now be considered 'unknown', MO code `UNKNOWN`. On foreign systems, properties of these will be translated to all languages already previously supported: German, Dutch, French, Italian, Spanish and Portuguese:
|
||||
```r
|
||||
mo_genus("qwerty", language = "es")
|
||||
# Warning:
|
||||
# one unique value (^= 100.0%) could not be coerced and is considered 'unknown': "qwerty". Use mo_failures() to review it.
|
||||
#> [1] "(género desconocido)"
|
||||
```
|
||||
* Fix for vector containing only empty values
|
||||
* Finds better results when input is in other languages
|
||||
* Better handling for subspecies
|
||||
* Better handling for *Salmonellae*, especially the 'city like' serovars like *Salmonella London*
|
||||
* Understanding of highly virulent *E. coli* strains like EIEC, EPEC and STEC
|
||||
* There will be looked for uncertain results at default - these results will be returned with an informative warning
|
||||
* Manual (help page) now contains more info about the algorithms
|
||||
* Progress bar will be shown when it takes more than 3 seconds to get results
|
||||
* Support for formatted console text
|
||||
* Console will return the percentage of uncoercable input
|
||||
* Function `first_isolate()`:
|
||||
* Fixed a bug where distances between dates would not be calculated right - in the `septic_patients` data set this yielded a difference of 0.15% more isolates
|
||||
* Will now use a column named like "patid" for the patient ID (parameter `col_patientid`), when this parameter was left blank
|
||||
* Will now use a column named like "key(...)ab" or "key(...)antibiotics" for the key antibiotics (parameter `col_keyantibiotics()`), when this parameter was left blank
|
||||
* Removed parameter `output_logical`, the function will now always return a logical value
|
||||
* Renamed parameter `filter_specimen` to `specimen_group`, although using `filter_specimen` will still work
|
||||
* A note to the manual pages of the `portion` functions, that low counts can influence the outcome and that the `portion` functions may camouflage this, since they only return the portion (albeit being dependent on the `minimum` parameter)
|
||||
* Merged data sets `microorganisms.certe` and `microorganisms.umcg` into `microorganisms.codes`
|
||||
* Function `mo_taxonomy()` now contains the kingdom too
|
||||
* Reduce false positives for `is.rsi.eligible()` using the new `threshold` parameter
|
||||
* New colours for `scale_rsi_colours()`
|
||||
* Summaries of class `mo` will now return the top 3 and the unique count, e.g. using `summary(mo)`
|
||||
* Small text updates to summaries of class `rsi` and `mic`
|
||||
* Function `as.rsi()`:
|
||||
* Now gives a warning when inputting MIC values
|
||||
* Now accepts high and low resistance: `"HIGH S"` will return `S`
|
||||
* Frequency tables (`freq()` function):
|
||||
* Support for tidyverse quasiquotation! Now you can create frequency tables of function outcomes:
|
||||
```r
|
||||
# Determine genus of microorganisms (mo) in `septic_patients` data set:
|
||||
# OLD WAY
|
||||
septic_patients %>%
|
||||
mutate(genus = mo_genus(mo)) %>%
|
||||
freq(genus)
|
||||
# NEW WAY
|
||||
septic_patients %>%
|
||||
freq(mo_genus(mo))
|
||||
|
||||
# Even supports grouping variables:
|
||||
septic_patients %>%
|
||||
group_by(gender) %>%
|
||||
freq(mo_genus(mo))
|
||||
```
|
||||
* Header info is now available as a list, with the `header` function
|
||||
* The parameter `header` is now set to `TRUE` at default, even for markdown
|
||||
* Added header info for class `mo` to show unique count of families, genera and species
|
||||
* Now honours the `decimal.mark` setting, which just like `format` defaults to `getOption("OutDec")`
|
||||
* The new `big.mark` parameter will at default be `","` when `decimal.mark = "."` and `"."` otherwise
|
||||
* Fix for header text where all observations are `NA`
|
||||
* New parameter `droplevels` to exclude empty factor levels when input is a factor
|
||||
* Factor levels will be in header when present in input data (maximum of 5)
|
||||
* Fix for using `select()` on frequency tables
|
||||
* Function `scale_y_percent()` now contains the `limits` parameter
|
||||
* Automatic parameter filling for `mdro()`, `key_antibiotics()` and `eucast_rules()`
|
||||
* Updated examples for resistance prediction (`resistance_predict()` function)
|
||||
* Fix for `as.mic()` to support more values ending in (several) zeroes
|
||||
* if using different lengths of pattern and x in `%like%`, it will now return the call
|
||||
|
||||
#### Other
|
||||
* Updated licence text to emphasise GPL 2.0 and that this is an R package.
|
||||
|
||||
# AMR 0.5.0
|
||||
|
||||
#### New
|
||||
* Repository moved to GitLab: https://gitlab.com/msberends/AMR
|
||||
* Function `count_all` to get all available isolates (that like all `portion_*` and `count_*` functions also supports `summarise` and `group_by`), the old `n_rsi` is now an alias of `count_all`
|
||||
* Function `get_locale` to determine language for language-dependent output for some `mo_*` functions. This is now the default value for their `language` parameter, by which the system language will be used at default.
|
||||
* Data sets `microorganismsDT`, `microorganisms.prevDT`, `microorganisms.unprevDT` and `microorganisms.oldDT` to improve the speed of `as.mo`. They are for reference only, since they are primarily for internal use of `as.mo`.
|
||||
* Function `read.4D` to read from the 4D database of the MMB department of the UMCG
|
||||
* Functions `mo_authors` and `mo_year` to get specific values about the scientific reference of a taxonomic entry
|
||||
|
||||
#### Changed
|
||||
* Functions `MDRO`, `BRMO`, `MRGN` and `EUCAST_exceptional_phenotypes` were renamed to `mdro`, `brmo`, `mrgn` and `eucast_exceptional_phenotypes`
|
||||
* `EUCAST_rules` was renamed to `eucast_rules`, the old function still exists as a deprecated function
|
||||
* Big changes to the `eucast_rules` function:
|
||||
* Now also applies rules from the EUCAST 'Breakpoint tables for bacteria', version 8.1, 2018, http://www.eucast.org/clinical_breakpoints/ (see Source of the function)
|
||||
* New parameter `rules` to specify which rules should be applied (expert rules, breakpoints, others or all)
|
||||
* New parameter `verbose` which can be set to `TRUE` to get very specific messages about which columns and rows were affected
|
||||
* Better error handling when rules cannot be applied (i.e. new values could not be inserted)
|
||||
* The number of affected values will now only be measured once per row/column combination
|
||||
* Data set `septic_patients` now reflects these changes
|
||||
* Added parameter `pipe` for piperacillin (J01CA12), also to the `mdro` function
|
||||
* Small fixes to EUCAST clinical breakpoint rules
|
||||
* Added column `kingdom` to the microorganisms data set, and function `mo_kingdom` to look up values
|
||||
* Tremendous speed improvement for `as.mo` (and subsequently all `mo_*` functions), as empty values wil be ignored *a priori*
|
||||
* Fewer than 3 characters as input for `as.mo` will return NA
|
||||
* Function `as.mo` (and all `mo_*` wrappers) now supports genus abbreviations with "species" attached
|
||||
```r
|
||||
as.mo("E. species") # B_ESCHR
|
||||
mo_fullname("E. spp.") # "Escherichia species"
|
||||
as.mo("S. spp") # B_STPHY
|
||||
mo_fullname("S. species") # "Staphylococcus species"
|
||||
```
|
||||
* Added parameter `combine_IR` (TRUE/FALSE) to functions `portion_df` and `count_df`, to indicate that all values of I and R must be merged into one, so the output only consists of S vs. IR (susceptible vs. non-susceptible)
|
||||
* Fix for `portion_*(..., as_percent = TRUE)` when minimal number of isolates would not be met
|
||||
* Added parameter `also_single_tested` for `portion_*` and `count_*` functions to also include cases where not all antibiotics were tested but at least one of the tested antibiotics includes the target antimicribial interpretation, see `?portion`
|
||||
* Using `portion_*` functions now throws a warning when total available isolate is below parameter `minimum`
|
||||
* Functions `as.mo`, `as.rsi`, `as.mic`, `as.atc` and `freq` will not set package name as attribute anymore
|
||||
* Frequency tables - `freq()`:
|
||||
* Support for grouping variables, test with:
|
||||
```r
|
||||
septic_patients %>%
|
||||
group_by(hospital_id) %>%
|
||||
freq(gender)
|
||||
```
|
||||
* Support for (un)selecting columns:
|
||||
```r
|
||||
septic_patients %>%
|
||||
freq(hospital_id) %>%
|
||||
select(-count, -cum_count) # only get item, percent, cum_percent
|
||||
```
|
||||
* Check for `hms::is.hms`
|
||||
* Now prints in markdown at default in non-interactive sessions
|
||||
* No longer adds the factor level column and sorts factors on count again
|
||||
* Support for class `difftime`
|
||||
* New parameter `na`, to choose which character to print for empty values
|
||||
* New parameter `header` to turn the header info off (default when `markdown = TRUE`)
|
||||
* New parameter `title` to manually setbthe title of the frequency table
|
||||
* `first_isolate` now tries to find columns to use as input when parameters are left blank
|
||||
* Improvements for MDRO algorithm (function `mdro`)
|
||||
* Data set `septic_patients` is now a `data.frame`, not a tibble anymore
|
||||
* Removed diacritics from all authors (columns `microorganisms$ref` and `microorganisms.old$ref`) to comply with CRAN policy to only allow ASCII characters
|
||||
* Fix for `mo_property` not working properly
|
||||
* Fix for `eucast_rules` where some Streptococci would become ceftazidime R in EUCAST rule 4.5
|
||||
* Support for named vectors of class `mo`, useful for `top_freq()`
|
||||
* `ggplot_rsi` and `scale_y_percent` have `breaks` parameter
|
||||
* AI improvements for `as.mo`:
|
||||
* `"CRS"` -> *Stenotrophomonas maltophilia*
|
||||
* `"CRSM"` -> *Stenotrophomonas maltophilia*
|
||||
* `"MSSA"` -> *Staphylococcus aureus*
|
||||
* `"MSSE"` -> *Staphylococcus epidermidis*
|
||||
* Fix for `join` functions
|
||||
* Speed improvement for `is.rsi.eligible`, now 15-20 times faster
|
||||
* In `g.test`, when `sum(x)` is below 1000 or any of the expected values is below 5, Fisher's Exact Test will be suggested
|
||||
* `ab_name` will try to fall back on `as.atc` when no results are found
|
||||
* Removed the addin to view data sets
|
||||
* Percentages will now will rounded more logically (e.g. in `freq` function)
|
||||
|
||||
#### Other
|
||||
* New dependency on package `crayon`, to support formatted text in the console
|
||||
* Dependency `tidyr` is now mandatory (went to `Import` field) since `portion_df` and `count_df` rely on it
|
||||
* Updated vignettes to comply with README
|
||||
|
||||
|
||||
# AMR 0.4.0
|
||||
|
||||
#### New
|
||||
* The data set `microorganisms` now contains **all microbial taxonomic data from ITIS** (kingdoms Bacteria, Fungi and Protozoa), the Integrated Taxonomy Information System, available via https://itis.gov. The data set now contains more than 18,000 microorganisms with all known bacteria, fungi and protozoa according ITIS with genus, species, subspecies, family, order, class, phylum and subkingdom. The new data set `microorganisms.old` contains all previously known taxonomic names from those kingdoms.
|
||||
* New functions based on the existing function `mo_property`:
|
||||
* Taxonomic names: `mo_phylum`, `mo_class`, `mo_order`, `mo_family`, `mo_genus`, `mo_species`, `mo_subspecies`
|
||||
* Semantic names: `mo_fullname`, `mo_shortname`
|
||||
* Microbial properties: `mo_type`, `mo_gramstain`
|
||||
* Author and year: `mo_ref`
|
||||
|
||||
They also come with support for German, Dutch, French, Italian, Spanish and Portuguese:
|
||||
```r
|
||||
mo_gramstain("E. coli")
|
||||
# [1] "Gram negative"
|
||||
mo_gramstain("E. coli", language = "de") # German
|
||||
# [1] "Gramnegativ"
|
||||
mo_gramstain("E. coli", language = "es") # Spanish
|
||||
# [1] "Gram negativo"
|
||||
mo_fullname("S. group A", language = "pt") # Portuguese
|
||||
# [1] "Streptococcus grupo A"
|
||||
```
|
||||
|
||||
Furthermore, former taxonomic names will give a note about the current taxonomic name:
|
||||
```r
|
||||
mo_gramstain("Esc blattae")
|
||||
# Note: 'Escherichia blattae' (Burgess et al., 1973) was renamed 'Shimwellia blattae' (Priest and Barker, 2010)
|
||||
# [1] "Gram negative"
|
||||
```
|
||||
* Functions `count_R`, `count_IR`, `count_I`, `count_SI` and `count_S` to selectively count resistant or susceptible isolates
|
||||
* Extra function `count_df` (which works like `portion_df`) to get all counts of S, I and R of a data set with antibiotic columns, with support for grouped variables
|
||||
* Function `is.rsi.eligible` to check for columns that have valid antimicrobial results, but do not have the `rsi` class yet. Transform the columns of your raw data with: `data %>% mutate_if(is.rsi.eligible, as.rsi)`
|
||||
* Functions `as.mo` and `is.mo` as replacements for `as.bactid` and `is.bactid` (since the `microoganisms` data set not only contains bacteria). These last two functions are deprecated and will be removed in a future release. The `as.mo` function determines microbial IDs using intelligent rules:
|
||||
```r
|
||||
as.mo("E. coli")
|
||||
# [1] B_ESCHR_COL
|
||||
as.mo("MRSA")
|
||||
# [1] B_STPHY_AUR
|
||||
as.mo("S group A")
|
||||
# [1] B_STRPTC_GRA
|
||||
```
|
||||
And with great speed too - on a quite regular Linux server from 2007 it takes us less than 0.02 seconds to transform 25,000 items:
|
||||
```r
|
||||
thousands_of_E_colis <- rep("E. coli", 25000)
|
||||
microbenchmark::microbenchmark(as.mo(thousands_of_E_colis), unit = "s")
|
||||
# Unit: seconds
|
||||
# min median max neval
|
||||
# 0.01817717 0.01843957 0.03878077 100
|
||||
```
|
||||
* Added parameter `reference_df` for `as.mo`, so users can supply their own microbial IDs, name or codes as a reference table
|
||||
* Renamed all previous references to `bactid` to `mo`, like:
|
||||
* Column names inputs of `EUCAST_rules`, `first_isolate` and `key_antibiotics`
|
||||
* Column names of datasets `microorganisms` and `septic_patients`
|
||||
* All old syntaxes will still work with this version, but will throw warnings
|
||||
* Function `labels_rsi_count` to print datalabels on a RSI `ggplot2` model
|
||||
* Functions `as.atc` and `is.atc` to transform/look up antibiotic ATC codes as defined by the WHO. The existing function `guess_atc` is now an alias of `as.atc`.
|
||||
|
||||
* Function `ab_property` and its aliases: `ab_name`, `ab_tradenames`, `ab_certe`, `ab_umcg` and `ab_trivial_nl`
|
||||
* Introduction to AMR as a vignette
|
||||
* Removed clipboard functions as it violated the CRAN policy
|
||||
* Renamed `septic_patients$sex` to `septic_patients$gender`
|
||||
|
||||
#### Changed
|
||||
* Added three antimicrobial agents to the `antibiotics` data set: Terbinafine (D01BA02), Rifaximin (A07AA11) and Isoconazole (D01AC05)
|
||||
* Added 163 trade names to the `antibiotics` data set, it now contains 298 different trade names in total, e.g.:
|
||||
```r
|
||||
ab_official("Bactroban")
|
||||
# [1] "Mupirocin"
|
||||
ab_name(c("Bactroban", "Amoxil", "Zithromax", "Floxapen"))
|
||||
# [1] "Mupirocin" "Amoxicillin" "Azithromycin" "Flucloxacillin"
|
||||
ab_atc(c("Bactroban", "Amoxil", "Zithromax", "Floxapen"))
|
||||
# [1] "R01AX06" "J01CA04" "J01FA10" "J01CF05"
|
||||
```
|
||||
* For `first_isolate`, rows will be ignored when there's no species available
|
||||
* Function `ratio` is now deprecated and will be removed in a future release, as it is not really the scope of this package
|
||||
* Fix for `as.mic` for values ending in zeroes after a real number
|
||||
* Small fix where *B. fragilis* would not be found in the `microorganisms.umcg` data set
|
||||
* Added `prevalence` column to the `microorganisms` data set
|
||||
* Added parameters `minimum` and `as_percent` to `portion_df`
|
||||
* Support for quasiquotation in the functions series `count_*` and `portions_*`, and `n_rsi`. This allows to check for more than 2 vectors or columns.
|
||||
```r
|
||||
septic_patients %>% select(amox, cipr) %>% count_IR()
|
||||
# which is the same as:
|
||||
septic_patients %>% count_IR(amox, cipr)
|
||||
|
||||
septic_patients %>% portion_S(amcl)
|
||||
septic_patients %>% portion_S(amcl, gent)
|
||||
septic_patients %>% portion_S(amcl, gent, pita)
|
||||
```
|
||||
* Edited `ggplot_rsi` and `geom_rsi` so they can cope with `count_df`. The new `fun` parameter has value `portion_df` at default, but can be set to `count_df`.
|
||||
* Fix for `ggplot_rsi` when the `ggplot2` package was not loaded
|
||||
* Added datalabels function `labels_rsi_count` to `ggplot_rsi`
|
||||
* Added possibility to set any parameter to `geom_rsi` (and `ggplot_rsi`) so you can set your own preferences
|
||||
* Fix for joins, where predefined suffices would not be honoured
|
||||
* Added parameter `quote` to the `freq` function
|
||||
* Added generic function `diff` for frequency tables
|
||||
* Added longest en shortest character length in the frequency table (`freq`) header of class `character`
|
||||
* Support for types (classes) list and matrix for `freq`
|
||||
```r
|
||||
my_matrix = with(septic_patients, matrix(c(age, gender), ncol = 2))
|
||||
freq(my_matrix)
|
||||
```
|
||||
For lists, subsetting is possible:
|
||||
```r
|
||||
my_list = list(age = septic_patients$age, gender = septic_patients$gender)
|
||||
my_list %>% freq(age)
|
||||
my_list %>% freq(gender)
|
||||
```
|
||||
|
||||
#### Other
|
||||
* More unit tests to ensure better integrity of functions
|
||||
|
||||
# AMR 0.3.0
|
||||
|
||||
#### New
|
||||
* **BREAKING**: `rsi_df` was removed in favour of new functions `portion_R`, `portion_IR`, `portion_I`, `portion_SI` and `portion_S` to selectively calculate resistance or susceptibility. These functions are 20 to 30 times faster than the old `rsi` function. The old function still works, but is deprecated.
|
||||
* New function `portion_df` to get all portions of S, I and R of a data set with antibiotic columns, with support for grouped variables
|
||||
* **BREAKING**: the methodology for determining first weighted isolates was changed. The antibiotics that are compared between isolates (call *key antibiotics*) to include more first isolates (afterwards called first *weighted* isolates) are now as follows:
|
||||
* Universal: amoxicillin, amoxicillin/clavlanic acid, cefuroxime, piperacillin/tazobactam, ciprofloxacin, trimethoprim/sulfamethoxazole
|
||||
* Gram-positive: vancomycin, teicoplanin, tetracycline, erythromycin, oxacillin, rifampicin
|
||||
* Gram-negative: gentamicin, tobramycin, colistin, cefotaxime, ceftazidime, meropenem
|
||||
* Support for `ggplot2`
|
||||
* New functions `geom_rsi`, `facet_rsi`, `scale_y_percent`, `scale_rsi_colours` and `theme_rsi`
|
||||
* New wrapper function `ggplot_rsi` to apply all above functions on a data set:
|
||||
* `septic_patients %>% select(tobr, gent) %>% ggplot_rsi` will show portions of S, I and R immediately in a pretty plot
|
||||
* Support for grouped variables, see `?ggplot_rsi`
|
||||
* Determining bacterial ID:
|
||||
* New functions `as.bactid` and `is.bactid` to transform/ look up microbial ID's.
|
||||
* The existing function `guess_bactid` is now an alias of `as.bactid`
|
||||
* New Becker classification for *Staphylococcus* to categorise them into Coagulase Negative *Staphylococci* (CoNS) and Coagulase Positve *Staphylococci* (CoPS)
|
||||
* New Lancefield classification for *Streptococcus* to categorise them into Lancefield groups
|
||||
* For convience, new descriptive statistical functions `kurtosis` and `skewness` that are lacking in base R - they are generic functions and have support for vectors, data.frames and matrices
|
||||
* Function `g.test` to perform the Χ<sup>2</sup> distributed [*G*-test](https://en.wikipedia.org/wiki/G-test), which use is the same as `chisq.test`
|
||||
* ~~Function `ratio` to transform a vector of values to a preset ratio~~
|
||||
* ~~For example: `ratio(c(10, 500, 10), ratio = "1:2:1")` would return `130, 260, 130`~~
|
||||
* Support for Addins menu in RStudio to quickly insert `%in%` or `%like%` (and give them keyboard shortcuts), or to view the datasets that come with this package
|
||||
* Function `p.symbol` to transform p values to their related symbols: `0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1`
|
||||
* Functions `clipboard_import` and `clipboard_export` as helper functions to quickly copy and paste from/to software like Excel and SPSS. These functions use the `clipr` package, but are a little altered to also support headless Linux servers (so you can use it in RStudio Server)
|
||||
* New for frequency tables (function `freq`):
|
||||
* A vignette to explain its usage
|
||||
* Support for `rsi` (antimicrobial resistance) to use as input
|
||||
* Support for `table` to use as input: `freq(table(x, y))`
|
||||
* Support for existing functions `hist` and `plot` to use a frequency table as input: `hist(freq(df$age))`
|
||||
* Support for `as.vector`, `as.data.frame`, `as_tibble` and `format`
|
||||
* Support for quasiquotation: `freq(mydata, mycolumn)` is the same as `mydata %>% freq(mycolumn)`
|
||||
* Function `top_freq` function to return the top/below *n* items as vector
|
||||
* Header of frequency tables now also show Mean Absolute Deviaton (MAD) and Interquartile Range (IQR)
|
||||
* Possibility to globally set the default for the amount of items to print, with `options(max.print.freq = n)` where *n* is your preset value
|
||||
|
||||
#### Changed
|
||||
* Improvements for forecasting with `resistance_predict` and added more examples
|
||||
* More antibiotics added as parameters for EUCAST rules
|
||||
* Updated version of the `septic_patients` data set to better reflect the reality
|
||||
* Pretty printing for tibbles removed as it is not really the scope of this package
|
||||
* Printing of `mic` and `rsi` classes now returns all values - use `freq` to check distributions
|
||||
* Improved speed of key antibiotics comparison for determining first isolates
|
||||
* Column names for the `key_antibiotics` function are now generic: 6 for broadspectrum ABs, 6 for Gram-positive specific and 6 for Gram-negative specific ABs
|
||||
* Speed improvement for the `abname` function
|
||||
* `%like%` now supports multiple patterns
|
||||
* Frequency tables are now actual `data.frame`s with altered console printing to make it look like a frequency table. Because of this, the parameter `toConsole` is not longer needed.
|
||||
* Fix for `freq` where the class of an item would be lost
|
||||
* Small translational improvements to the `septic_patients` dataset and the column `bactid` now has the new class `"bactid"`
|
||||
* Small improvements to the `microorganisms` dataset (especially for *Salmonella*) and the column `bactid` now has the new class `"bactid"`
|
||||
* Combined MIC/RSI values will now be coerced by the `rsi` and `mic` functions:
|
||||
* `as.rsi("<=0.002; S")` will return `S`
|
||||
* `as.mic("<=0.002; S")` will return `<=0.002`
|
||||
* Now possible to coerce MIC values with a space between operator and value, i.e. `as.mic("<= 0.002")` now works
|
||||
* Classes `rsi` and `mic` do not add the attribute `package.version` anymore
|
||||
* Added `"groups"` option for `atc_property(..., property)`. It will return a vector of the ATC hierarchy as defined by the [WHO](https://www.whocc.no/atc/structure_and_principles/). The new function `atc_groups` is a convenient wrapper around this.
|
||||
* Build-in host check for `atc_property` as it requires the host set by `url` to be responsive
|
||||
* Improved `first_isolate` algorithm to exclude isolates where bacteria ID or genus is unavailable
|
||||
* Fix for warning *hybrid evaluation forced for row_number* ([`924b62`](https://github.com/tidyverse/dplyr/commit/924b62)) from the `dplyr` package v0.7.5 and above
|
||||
* Support for empty values and for 1 or 2 columns as input for `guess_bactid` (now called `as.bactid`)
|
||||
* So `yourdata %>% select(genus, species) %>% as.bactid()` now also works
|
||||
* Other small fixes
|
||||
|
||||
#### Other
|
||||
* Added integration tests (check if everything works as expected) for all releases of R 3.1 and higher
|
||||
* Linux and macOS: https://travis-ci.org/msberends/AMR
|
||||
* Windows: https://ci.appveyor.com/project/msberends/amr
|
||||
* Added thesis advisors to DESCRIPTION file
|
||||
|
||||
# AMR 0.2.0
|
||||
|
||||
#### New
|
||||
* Full support for Windows, Linux and macOS
|
||||
* Full support for old R versions, only R-3.0.0 (April 2013) or later is needed (needed packages may have other dependencies)
|
||||
* Function `n_rsi` to count cases where antibiotic test results were available, to be used in conjunction with `dplyr::summarise`, see ?rsi
|
||||
* Function `guess_bactid` to **determine the ID** of a microorganism based on genus/species or known abbreviations like MRSA
|
||||
* Function `guess_atc` to **determine the ATC** of an antibiotic based on name, trade name, or known abbreviations
|
||||
* Function `freq` to create **frequency tables**, with additional info in a header
|
||||
* Function `MDRO` to **determine Multi Drug Resistant Organisms (MDRO)** with support for country-specific guidelines.
|
||||
* [Exceptional resistances defined by EUCAST](http://www.eucast.org/expert_rules_and_intrinsic_resistance) are also supported instead of countries alone
|
||||
* Functions `BRMO` and `MRGN` are wrappers for Dutch and German guidelines, respectively
|
||||
* New algorithm to determine weighted isolates, can now be `"points"` or `"keyantibiotics"`, see `?first_isolate`
|
||||
* New print format for `tibble`s and `data.table`s
|
||||
|
||||
#### Changed
|
||||
* Fixed `rsi` class for vectors that contain only invalid antimicrobial interpretations
|
||||
* Renamed dataset `ablist` to `antibiotics`
|
||||
* Renamed dataset `bactlist` to `microorganisms`
|
||||
* Added common abbreviations and trade names to the `antibiotics` dataset
|
||||
* Added more microorganisms to the `microorganisms` dataset
|
||||
* Added analysis examples on help page of dataset `septic_patients`
|
||||
* Added support for character vector in `join` functions
|
||||
* Added warnings when a join results in more rows after than before the join
|
||||
* Altered `%like%` to make it case insensitive
|
||||
* For parameters of functions `first_isolate` and `EUCAST_rules` column names are now case-insensitive
|
||||
* Functions `as.rsi` and `as.mic` now add the package name and version as attributes
|
||||
|
||||
#### Other
|
||||
* Expanded `README.md` with more examples
|
||||
* Added [ORCID](https://orcid.org) of authors to DESCRIPTION file
|
||||
* Added unit testing with the `testthat` package
|
||||
* Added build tests for Linux and macOS using Travis CI (https://travis-ci.org/msberends/AMR)
|
||||
* Added line coverage checking using CodeCov (https://codecov.io/gh/msberends/AMR/tree/master/R)
|
||||
|
||||
# AMR 0.1.1
|
||||
|
||||
* `EUCAST_rules` applies for amoxicillin even if ampicillin is missing
|
||||
* Edited column names to comply with GLIMS, the laboratory information system
|
||||
* Added more valid MIC values
|
||||
* Renamed 'Daily Defined Dose' to 'Defined Daily Dose'
|
||||
* Added barplots for `rsi` and `mic` classes
|
||||
|
||||
# AMR 0.1.0
|
||||
|
||||
* First submission to CRAN.
|
||||
@@ -1,258 +0,0 @@
|
||||
# ==================================================================== #
|
||||
# TITLE #
|
||||
# Antimicrobial Resistance (AMR) Analysis #
|
||||
# #
|
||||
# SOURCE #
|
||||
# https://gitlab.com/msberends/AMR #
|
||||
# #
|
||||
# LICENCE #
|
||||
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
|
||||
# #
|
||||
# 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. #
|
||||
# #
|
||||
# This R package was created for academic research and was publicly #
|
||||
# released in the hope that it will be useful, but it comes WITHOUT #
|
||||
# ANY WARRANTY OR LIABILITY. #
|
||||
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
||||
# ==================================================================== #
|
||||
|
||||
#' Transform to antibiotic ID
|
||||
#'
|
||||
#' Use this function to determine the antibiotic code of one or more antibiotics. The data set \code{\link{antibiotics}} will be searched for abbreviations, official names and synonyms (brand names).
|
||||
#' @param x character vector to determine to antibiotic ID
|
||||
#' @rdname as.ab
|
||||
#' @keywords atc
|
||||
#' @inheritSection WHOCC WHOCC
|
||||
#' @export
|
||||
#' @importFrom dplyr %>% filter slice pull
|
||||
#' @details All entries in the \code{\link{antibiotics}} data set have three different identifiers: a human readable EARS-Net code (column \code{ab}, used by ECDC and WHONET), an ATC code (column \code{atc}, used by WHO), and a CID code (column \code{cid}, Compound ID, used by PubChem). The data set contains more than 5,000 official brand names from many different countries, as found in PubChem.
|
||||
#'
|
||||
#' Use the \code{\link{ab_property}} functions to get properties based on the returned antibiotic ID, see Examples.
|
||||
#' @section Source:
|
||||
#' World Health Organization (WHO) Collaborating Centre for Drug Statistics Methodology: \url{https://www.whocc.no/atc_ddd_index/}
|
||||
#'
|
||||
#' WHONET 2019 software: \url{http://www.whonet.org/software.html}
|
||||
#'
|
||||
#' European Commission Public Health PHARMACEUTICALS - COMMUNITY REGISTER: \url{http://ec.europa.eu/health/documents/community-register/html/atc.htm}
|
||||
#' @return Character (vector) with class \code{"ab"}. Unknown values will return \code{NA}.
|
||||
#' @seealso \code{\link{antibiotics}} for the dataframe that is being used to determine ATCs.
|
||||
#' @inheritSection AMR Read more on our website!
|
||||
#' @examples
|
||||
#' # These examples all return "ERY", the ID of Erythromycin:
|
||||
#' as.ab("J01FA01")
|
||||
#' as.ab("J 01 FA 01")
|
||||
#' as.ab("Erythromycin")
|
||||
#' as.ab("eryt")
|
||||
#' as.ab(" eryt 123")
|
||||
#' as.ab("ERYT")
|
||||
#' as.ab("ERY")
|
||||
#' as.ab("eritromicine") # spelled wrong, yet works
|
||||
#' as.ab("Erythrocin") # trade name
|
||||
#' as.ab("Romycin") # trade name
|
||||
#'
|
||||
#' # Use ab_* functions to get a specific properties (see ?ab_property);
|
||||
#' # they use as.ab() internally:
|
||||
#' ab_name("J01FA01") # "Erythromycin"
|
||||
#' ab_name("eryt") # "Erythromycin"
|
||||
as.ab <- function(x) {
|
||||
if (is.ab(x)) {
|
||||
return(x)
|
||||
}
|
||||
|
||||
if (all(toupper(x) %in% AMR::antibiotics$ab)) {
|
||||
# valid AB code, but not yet right class
|
||||
return(structure(.Data = toupper(x),
|
||||
class = "ab"))
|
||||
}
|
||||
|
||||
x_bak <- x
|
||||
# remove suffices
|
||||
x_bak_clean <- gsub("_(mic|rsi|disk|disc)$", "", x, ignore.case = TRUE)
|
||||
# remove disk concentrations, like LVX_NM -> LVX
|
||||
x_bak_clean <- gsub("_[A-Z]{2}[0-9_]{0,3}$", "", x_bak_clean, ignore.case = TRUE)
|
||||
# clean rest of it
|
||||
x_bak_clean <- gsub("[^A-Z0-9/-]", "", x_bak_clean, ignore.case = TRUE)
|
||||
# keep only a-z when it's not an ATC code or only numbers
|
||||
x_bak_clean[!x_bak_clean %like% "^([A-Z][0-9]{2}[A-Z]{2}[0-9]{2}|[0-9]+)$"] <- gsub("[^a-zA-Z]+",
|
||||
"",
|
||||
x_bak_clean[!x_bak_clean %like% "^([A-Z][0-9]{2}[A-Z]{2}[0-9]{2}|[0-9]+)$"])
|
||||
x <- unique(x_bak_clean)
|
||||
x_new <- rep(NA_character_, length(x))
|
||||
x_unknown <- character(0)
|
||||
|
||||
for (i in 1:length(x)) {
|
||||
if (is.na(x[i]) | is.null(x[i])) {
|
||||
next
|
||||
}
|
||||
if (identical(x[i], "")) {
|
||||
x_unknown <- c(x_unknown, x_bak[x[i] == x_bak_clean][1])
|
||||
next
|
||||
}
|
||||
|
||||
# exact AB code
|
||||
found <- AMR::antibiotics[which(AMR::antibiotics$ab == toupper(x[i])),]$ab
|
||||
if (length(found) > 0) {
|
||||
x_new[i] <- found[1L]
|
||||
next
|
||||
}
|
||||
|
||||
# exact ATC code
|
||||
found <- AMR::antibiotics[which(AMR::antibiotics$atc == toupper(x[i])),]$ab
|
||||
if (length(found) > 0) {
|
||||
x_new[i] <- found[1L]
|
||||
next
|
||||
}
|
||||
|
||||
# exact CID code
|
||||
found <- AMR::antibiotics[which(AMR::antibiotics$cid == x[i]),]$ab
|
||||
if (length(found) > 0) {
|
||||
x_new[i] <- found[1L]
|
||||
next
|
||||
}
|
||||
|
||||
# exact name
|
||||
found <- AMR::antibiotics[which(toupper(AMR::antibiotics$name) == toupper(x[i])),]$ab
|
||||
if (length(found) > 0) {
|
||||
x_new[i] <- found[1L]
|
||||
next
|
||||
}
|
||||
|
||||
# exact synonym
|
||||
synonym_found <- unlist(lapply(AMR::antibiotics$synonyms,
|
||||
function(s) if (toupper(x[i]) %in% toupper(s)) {
|
||||
TRUE
|
||||
} else {
|
||||
FALSE
|
||||
}))
|
||||
found <- AMR::antibiotics$ab[synonym_found == TRUE]
|
||||
if (length(found) > 0) {
|
||||
x_new[i] <- found[1L]
|
||||
next
|
||||
}
|
||||
|
||||
# exact abbreviation
|
||||
abbr_found <- unlist(lapply(AMR::antibiotics$abbreviations,
|
||||
function(a) if (toupper(x[i]) %in% toupper(a)) {
|
||||
TRUE
|
||||
} else {
|
||||
FALSE
|
||||
}))
|
||||
found <- AMR::antibiotics$ab[abbr_found == TRUE]
|
||||
if (length(found) > 0) {
|
||||
x_new[i] <- found[1L]
|
||||
next
|
||||
}
|
||||
|
||||
# first >=4 characters of name
|
||||
if (nchar(x[i]) >= 4) {
|
||||
found <- AMR::antibiotics[which(toupper(AMR::antibiotics$name) %like% paste0("^", x[i])),]$ab
|
||||
if (length(found) > 0) {
|
||||
x_new[i] <- found[1L]
|
||||
next
|
||||
}
|
||||
}
|
||||
|
||||
# allow characters that resemble others, but only continue when having more than 3 characters
|
||||
if (nchar(x[i]) <= 3) {
|
||||
x_unknown <- c(x_unknown, x_bak[x[i] == x_bak_clean][1])
|
||||
next
|
||||
}
|
||||
x_spelling <- tolower(x[i])
|
||||
x_spelling <- gsub("[iy]+", "[iy]+", x_spelling)
|
||||
x_spelling <- gsub("[sz]+", "[sz]+", x_spelling)
|
||||
x_spelling <- gsub("(c|k|q|qu)+", "(c|k|q|qu)+", x_spelling)
|
||||
x_spelling <- gsub("(ph|f|v)+", "(ph|f|v)+", x_spelling)
|
||||
x_spelling <- gsub("(th|t)+", "(th|t)+", x_spelling)
|
||||
x_spelling <- gsub("(x|ks)+", "(x|ks)+", x_spelling)
|
||||
x_spelling <- gsub("a+", "a+", x_spelling)
|
||||
x_spelling <- gsub("e+", "e+", x_spelling)
|
||||
x_spelling <- gsub("o+", "o+", x_spelling)
|
||||
# allow start with C/S/Z
|
||||
x_spelling <- gsub("^(\\(c\\|k\\|q\\|qu\\)|\\[sz\\])", "(c|k|q|qu|s|z)", x_spelling)
|
||||
x_spelling <- gsub("(c|k|q|qu)+[sz]", "(c|k|q|qu|s|x|z)", x_spelling, fixed = TRUE)
|
||||
# allow any ending of -in/-ine and -im/-ime
|
||||
x_spelling <- gsub("(\\[iy\\]\\+(n|m)|\\[iy\\]\\+(n|m)e\\+)$", "[iy]+(n|m)e*", x_spelling)
|
||||
# allow any ending of -ol/-ole
|
||||
x_spelling <- gsub("(o\\+l|o\\+le\\+)$", "o+le*", x_spelling)
|
||||
# allow any ending of -on/-one
|
||||
x_spelling <- gsub("(o\\+n|o\\+ne\\+)$", "o+ne*", x_spelling)
|
||||
# try if name starts with it
|
||||
found <- AMR::antibiotics[which(AMR::antibiotics$name %like% paste0("^", x_spelling)),]$ab
|
||||
if (length(found) > 0) {
|
||||
x_new[i] <- found[1L]
|
||||
next
|
||||
}
|
||||
# and try if any synonym starts with it
|
||||
synonym_found <- unlist(lapply(AMR::antibiotics$synonyms,
|
||||
function(s) if (any(s %like% paste0("^", x_spelling))) {
|
||||
TRUE
|
||||
} else {
|
||||
FALSE
|
||||
}))
|
||||
found <- AMR::antibiotics$ab[synonym_found == TRUE]
|
||||
if (length(found) > 0) {
|
||||
x_new[i] <- found[1L]
|
||||
next
|
||||
}
|
||||
|
||||
# not found
|
||||
x_unknown <- c(x_unknown, x_bak[x[i] == x_bak_clean][1])
|
||||
}
|
||||
|
||||
if (length(x_unknown) > 0) {
|
||||
warning("These values could not be coerced to a valid antibiotic ID: ",
|
||||
paste('"', sort(unique(x_unknown)), '"', sep = "", collapse = ', '),
|
||||
".",
|
||||
call. = FALSE)
|
||||
}
|
||||
|
||||
x_result <- data.frame(x = x_bak_clean, stringsAsFactors = FALSE) %>%
|
||||
left_join(data.frame(x = x, x_new = x_new, stringsAsFactors = FALSE), by = "x") %>%
|
||||
pull(x_new)
|
||||
|
||||
if (length(x_result) == 0) {
|
||||
x_result <- NA_character_
|
||||
}
|
||||
|
||||
structure(.Data = x_result,
|
||||
class = "ab")
|
||||
}
|
||||
|
||||
#' @rdname as.ab
|
||||
#' @export
|
||||
is.ab <- function(x) {
|
||||
identical(class(x), "ab")
|
||||
}
|
||||
|
||||
#' @exportMethod print.ab
|
||||
#' @export
|
||||
#' @noRd
|
||||
print.ab <- function(x, ...) {
|
||||
cat("Class 'ab'\n")
|
||||
print.default(as.character(x), quote = FALSE)
|
||||
}
|
||||
|
||||
#' @exportMethod as.data.frame.ab
|
||||
#' @export
|
||||
#' @noRd
|
||||
as.data.frame.ab <- function (x, ...) {
|
||||
# same as as.data.frame.character but with removed stringsAsFactors
|
||||
nm <- paste(deparse(substitute(x), width.cutoff = 500L),
|
||||
collapse = " ")
|
||||
if (!"nm" %in% names(list(...))) {
|
||||
as.data.frame.vector(x, ..., nm = nm)
|
||||
} else {
|
||||
as.data.frame.vector(x, ...)
|
||||
}
|
||||
}
|
||||
|
||||
#' @exportMethod pull.ab
|
||||
#' @export
|
||||
#' @importFrom dplyr pull
|
||||
#' @noRd
|
||||
pull.ab <- function(.data, ...) {
|
||||
pull(as.data.frame(.data), ...)
|
||||
}
|
||||
@@ -1,205 +0,0 @@
|
||||
# ==================================================================== #
|
||||
# TITLE #
|
||||
# Antimicrobial Resistance (AMR) Analysis #
|
||||
# #
|
||||
# SOURCE #
|
||||
# https://gitlab.com/msberends/AMR #
|
||||
# #
|
||||
# LICENCE #
|
||||
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
|
||||
# #
|
||||
# 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. #
|
||||
# #
|
||||
# This R package was created for academic research and was publicly #
|
||||
# released in the hope that it will be useful, but it comes WITHOUT #
|
||||
# ANY WARRANTY OR LIABILITY. #
|
||||
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
||||
# ==================================================================== #
|
||||
|
||||
#' Property of an antibiotic
|
||||
#'
|
||||
#' Use these functions to return a specific property of an antibiotic from the \code{\link{antibiotics}} data set. All input values will be evaluated internally with \code{\link{as.ab}}.
|
||||
#' @param x any (vector of) text that can be coerced to a valid microorganism code with \code{\link{as.ab}}
|
||||
#' @param tolower logical to indicate whether the first character of every output should be transformed to a lower case character. This will lead to e.g. "polymyxin B" and not "polymyxin b".
|
||||
#' @param property one of the column names of one of the \code{\link{antibiotics}} data set
|
||||
#' @param language language of the returned text, defaults to system language (see \code{\link{get_locale}}) and can also be set with \code{\link{getOption}("AMR_locale")}. Use \code{language = NULL} or \code{language = ""} to prevent translation.
|
||||
#' @param administration way of administration, either \code{"oral"} or \code{"iv"}
|
||||
#' @param units a logical to indicate whether the units instead of the DDDs itself must be returned, see Examples
|
||||
#' @param ... other parameters passed on to \code{\link{as.ab}}
|
||||
#' @details All output will be \link{translate}d where possible.
|
||||
#' @inheritSection as.ab Source
|
||||
#' @rdname ab_property
|
||||
#' @name ab_property
|
||||
#' @return \itemize{
|
||||
#' \item{An \code{integer} in case of \code{ab_cid}}
|
||||
#' \item{A named \code{list} in case of \code{ab_info} and multiple \code{ab_synonyms}/\code{ab_tradenames}}
|
||||
#' \item{A \code{double} in case of \code{ab_ddd}}
|
||||
#' \item{A \code{character} in all other cases}
|
||||
#' }
|
||||
#' @export
|
||||
#' @seealso \code{\link{antibiotics}}
|
||||
#' @inheritSection AMR Read more on our website!
|
||||
#' @examples
|
||||
#' # all properties:
|
||||
#' ab_name("AMX") # "Amoxicillin"
|
||||
#' ab_atc("AMX") # J01CA04 (ATC code from the WHO)
|
||||
#' ab_cid("AMX") # 33613 (Compound ID from PubChem)
|
||||
#'
|
||||
#' ab_synonyms("AMX") # a list with brand names of amoxicillin
|
||||
#' ab_tradenames("AMX") # same
|
||||
#'
|
||||
#' ab_group("AMX") # "Beta-lactams/penicillins"
|
||||
#' ab_atc_group1("AMX") # "Beta-lactam antibacterials, penicillins"
|
||||
#' ab_atc_group2("AMX") # "Penicillins with extended spectrum"
|
||||
#'
|
||||
#' ab_name(x = c("AMC", "PLB")) # "Amoxicillin/clavulanic acid" "Polymyxin B"
|
||||
#' ab_name(x = c("AMC", "PLB"),
|
||||
#' tolower = TRUE) # "amoxicillin/clavulanic acid" "polymyxin B"
|
||||
#'
|
||||
#' ab_ddd("AMX", "oral") # 1
|
||||
#' ab_ddd("AMX", "oral", units = TRUE) # "g"
|
||||
#' ab_ddd("AMX", "iv") # 1
|
||||
#' ab_ddd("AMX", "iv", units = TRUE) # "g"
|
||||
#'
|
||||
#' ab_info("AMX") # all properties as a list
|
||||
#'
|
||||
#' # all ab_* functions use as.ab() internally:
|
||||
#' ab_name("Fluclox") # "Flucloxacillin"
|
||||
#' ab_name("fluklox") # "Flucloxacillin"
|
||||
#' ab_name("floxapen") # "Flucloxacillin"
|
||||
#' ab_name(21319) # "Flucloxacillin" (using CID)
|
||||
#' ab_name("J01CF05") # "Flucloxacillin" (using ATC)
|
||||
ab_name <- function(x, language = get_locale(), tolower = FALSE, ...) {
|
||||
x <- ab_validate(x = x, property = "name", ...)
|
||||
res <- t(x, language = language)
|
||||
if (tolower == TRUE) {
|
||||
# use perl to only transform the first character
|
||||
# as we want "polymyxin B", not "polymyxin b"
|
||||
res <- gsub("^([A-Z])", "\\L\\1", res, perl = TRUE)
|
||||
}
|
||||
res
|
||||
}
|
||||
|
||||
#' @rdname ab_property
|
||||
#' @export
|
||||
ab_atc <- function(x, ...) {
|
||||
ab_validate(x = x, property = "atc", ...)
|
||||
}
|
||||
|
||||
#' @rdname ab_property
|
||||
#' @export
|
||||
ab_cid <- function(x, ...) {
|
||||
ab_validate(x = x, property = "cid", ...)
|
||||
}
|
||||
|
||||
#' @rdname ab_property
|
||||
#' @export
|
||||
ab_synonyms <- function(x, ...) {
|
||||
syns <- ab_validate(x = x, property = "synonyms", ...)
|
||||
names(syns) <- x
|
||||
if (length(syns) == 1) {
|
||||
unname(unlist(syns))
|
||||
} else {
|
||||
syns
|
||||
}
|
||||
}
|
||||
|
||||
#' @rdname ab_property
|
||||
#' @export
|
||||
ab_tradenames <- function(x, ...) {
|
||||
ab_synonyms(x, ...)
|
||||
}
|
||||
|
||||
#' @rdname ab_property
|
||||
#' @export
|
||||
ab_group <- function(x, language = get_locale(), ...) {
|
||||
t(ab_validate(x = x, property = "group", ...), language = language)
|
||||
}
|
||||
|
||||
#' @rdname ab_property
|
||||
#' @export
|
||||
ab_atc_group1 <- function(x, language = get_locale(), ...) {
|
||||
t(ab_validate(x = x, property = "atc_group1", ...), language = language)
|
||||
}
|
||||
|
||||
#' @rdname ab_property
|
||||
#' @export
|
||||
ab_atc_group2 <- function(x, language = get_locale(), ...) {
|
||||
t(ab_validate(x = x, property = "atc_group2", ...), language = language)
|
||||
}
|
||||
|
||||
#' @rdname ab_property
|
||||
#' @export
|
||||
ab_ddd <- function(x, administration = "oral", units = FALSE, ...) {
|
||||
if (!administration %in% c("oral", "iv")) {
|
||||
stop("`administration` must be 'oral' or 'iv'", call. = FALSE)
|
||||
}
|
||||
ddd_prop <- administration
|
||||
if (units == TRUE) {
|
||||
ddd_prop <- paste0(ddd_prop, "_units")
|
||||
} else {
|
||||
ddd_prop <- paste0(ddd_prop, "_ddd")
|
||||
}
|
||||
ab_validate(x = x, property = ddd_prop, ...)
|
||||
}
|
||||
|
||||
#' @rdname ab_property
|
||||
#' @export
|
||||
ab_info <- function(x, language = get_locale(), ...) {
|
||||
x <- AMR::as.ab(x, ...)
|
||||
base::list(ab = x,
|
||||
atc = ab_atc(x),
|
||||
cid = ab_cid(x),
|
||||
name = ab_name(x, language = language),
|
||||
group = ab_group(x, language = language),
|
||||
atc_group1 = ab_atc_group1(x, language = language),
|
||||
atc_group2 = ab_atc_group2(x, language = language),
|
||||
tradenames = ab_tradenames(x),
|
||||
ddd = list(oral = list(amount = ab_ddd(x, administration = "oral", units = FALSE),
|
||||
units = ab_ddd(x, administration = "oral", units = TRUE)),
|
||||
iv = list(amount = ab_ddd(x, administration = "iv", units = FALSE),
|
||||
units = ab_ddd(x, administration = "iv", units = TRUE))))
|
||||
}
|
||||
|
||||
#' @rdname ab_property
|
||||
#' @export
|
||||
ab_property <- function(x, property = 'name', language = get_locale(), ...) {
|
||||
if (length(property) != 1L) {
|
||||
stop("'property' must be of length 1.")
|
||||
}
|
||||
if (!property %in% colnames(AMR::antibiotics)) {
|
||||
stop("invalid property: '", property, "' - use a column name of the `antibiotics` data set")
|
||||
}
|
||||
|
||||
t(ab_validate(x = x, property = property, ...), language = language)
|
||||
}
|
||||
|
||||
ab_validate <- function(x, property, ...) {
|
||||
if (!"AMR" %in% base::.packages()) {
|
||||
library("AMR")
|
||||
# check onLoad() in R/zzz.R: data tables are created there.
|
||||
}
|
||||
|
||||
# try to catch an error when inputting an invalid parameter
|
||||
# so the 'call.' can be set to FALSE
|
||||
tryCatch(x[1L] %in% AMR::antibiotics[1, property],
|
||||
error = function(e) stop(e$message, call. = FALSE))
|
||||
|
||||
if (!all(x %in% AMR::antibiotics[, property])) {
|
||||
x <- data.frame(ab = AMR::as.ab(x), stringsAsFactors = FALSE) %>%
|
||||
left_join(AMR::antibiotics, by = "ab") %>%
|
||||
pull(property)
|
||||
}
|
||||
if (property %in% c("ab", "atc")) {
|
||||
return(structure(x, class = property))
|
||||
} else if (property == "cid") {
|
||||
return(as.integer(x))
|
||||
} else if (property %like% "ddd") {
|
||||
return(as.double(x))
|
||||
} else {
|
||||
return(x)
|
||||
}
|
||||
}
|
||||
@@ -1,179 +0,0 @@
|
||||
# ==================================================================== #
|
||||
# TITLE #
|
||||
# Antimicrobial Resistance (AMR) Analysis #
|
||||
# #
|
||||
# SOURCE #
|
||||
# https://gitlab.com/msberends/AMR #
|
||||
# #
|
||||
# LICENCE #
|
||||
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
|
||||
# #
|
||||
# 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. #
|
||||
# #
|
||||
# This R package was created for academic research and was publicly #
|
||||
# released in the hope that it will be useful, but it comes WITHOUT #
|
||||
# ANY WARRANTY OR LIABILITY. #
|
||||
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
||||
# ==================================================================== #
|
||||
|
||||
#' Age in years of individuals
|
||||
#'
|
||||
#' Calculates age in years based on a reference date, which is the sytem date at default.
|
||||
#' @param x date(s), will be coerced with \code{\link{as.POSIXlt}}
|
||||
#' @param reference reference date(s) (defaults to today), will be coerced with \code{\link{as.POSIXlt}} and cannot be lower than \code{x}
|
||||
#' @param exact a logical to indicate whether age calculation should be exact, i.e. with decimals. It divides the number of days of \href{https://en.wikipedia.org/wiki/Year-to-date}{year-to-date} (YTD) of \code{x} by the number of days in a year of \code{reference} (either 365 or 366).
|
||||
#' @return An integer (no decimals) if \code{exact = FALSE}, a double (with decimals) otherwise
|
||||
#' @seealso \code{\link{age_groups}} to split age into age groups
|
||||
#' @importFrom dplyr if_else
|
||||
#' @inheritSection AMR Read more on our website!
|
||||
#' @export
|
||||
#' @examples
|
||||
#' # 10 random birth dates
|
||||
#' df <- data.frame(birth_date = Sys.Date() - runif(10) * 25000)
|
||||
#' # add ages
|
||||
#' df$age <- age(df$birth_date)
|
||||
#' # add exact ages
|
||||
#' df$age_exact <- age(df$birth_date, exact = TRUE)
|
||||
#'
|
||||
#' df
|
||||
age <- function(x, reference = Sys.Date(), exact = FALSE) {
|
||||
if (length(x) != length(reference)) {
|
||||
if (length(reference) == 1) {
|
||||
reference <- rep(reference, length(x))
|
||||
} else {
|
||||
stop("`x` and `reference` must be of same length, or `reference` must be of length 1.")
|
||||
}
|
||||
}
|
||||
x <- as.POSIXlt(x)
|
||||
reference <- as.POSIXlt(reference)
|
||||
|
||||
# from https://stackoverflow.com/a/25450756/4575331
|
||||
years_gap <- reference$year - x$year
|
||||
ages <- if_else(reference$mon < x$mon | (reference$mon == x$mon & reference$mday < x$mday),
|
||||
as.integer(years_gap - 1),
|
||||
as.integer(years_gap))
|
||||
|
||||
# add decimals
|
||||
if (exact == TRUE) {
|
||||
# get dates of `x` when `x` would have the year of `reference`
|
||||
x_in_reference_year <- as.POSIXlt(paste0(format(reference, "%Y"), format(x, "-%m-%d")))
|
||||
# get differences in days
|
||||
n_days_x_rest <- as.double(difftime(reference, x_in_reference_year, units = "days"))
|
||||
# get numbers of days the years of `reference` has for a reliable denominator
|
||||
n_days_reference_year <- as.POSIXlt(paste0(format(reference, "%Y"), "-12-31"))$yday + 1
|
||||
# add decimal parts of year
|
||||
mod <- n_days_x_rest / n_days_reference_year
|
||||
# negative mods are cases where `x_in_reference_year` > `reference` - so 'add' a year
|
||||
mod[mod < 0] <- 1 + mod[mod < 0]
|
||||
# and finally add to ages
|
||||
ages <- ages + mod
|
||||
}
|
||||
|
||||
if (any(ages < 0, na.rm = TRUE)) {
|
||||
ages[ages < 0] <- NA
|
||||
warning("NAs introduced for ages below 0.")
|
||||
}
|
||||
if (any(ages > 120, na.rm = TRUE)) {
|
||||
warning("Some ages are above 120.")
|
||||
}
|
||||
|
||||
ages
|
||||
}
|
||||
|
||||
#' Split ages into age groups
|
||||
#'
|
||||
#' Split ages into age groups defined by the \code{split} parameter. This allows for easier demographic (antimicrobial resistance) analysis.
|
||||
#' @param x age, e.g. calculated with \code{\link{age}}
|
||||
#' @param split_at values to split \code{x} at, defaults to age groups 0-11, 12-24, 25-54, 55-74 and 75+. See Details.
|
||||
#' @details To split ages, the input can be:
|
||||
#' \itemize{
|
||||
#' \item{A numeric vector. A vector of e.g. \code{c(10, 20)} will split on 0-9, 10-19 and 20+. A value of only \code{50} will split on 0-49 and 50+.
|
||||
#' The default is to split on young children (0-11), youth (12-24), young adults (25-54), middle-aged adults (55-74) and elderly (75+).}
|
||||
#' \item{A character:}
|
||||
#' \itemize{
|
||||
#' \item{\code{"children"} or \code{"kids"}, equivalent of: \code{c(0, 1, 2, 4, 6, 13, 18)}. This will split on 0, 1, 2-3, 4-5, 6-12, 13-17 and 18+.}
|
||||
#' \item{\code{"elderly"} or \code{"seniors"}, equivalent of: \code{c(65, 75, 85)}. This will split on 0-64, 65-74, 75-84, 85+.}
|
||||
#' \item{\code{"fives"}, equivalent of: \code{1:20 * 5}. This will split on 0-4, 5-9, 10-14, ..., 90-94, 95-99, 100+.}
|
||||
#' \item{\code{"tens"}, equivalent of: \code{1:10 * 10}. This will split on 0-9, 10-19, 20-29, ... 80-89, 90-99, 100+.}
|
||||
#' }
|
||||
#' }
|
||||
#' @keywords age_group age
|
||||
#' @return Ordered \code{\link{factor}}
|
||||
#' @seealso \code{\link{age}} to determine ages based on one or more reference dates
|
||||
#' @export
|
||||
#' @inheritSection AMR Read more on our website!
|
||||
#' @examples
|
||||
#' ages <- c(3, 8, 16, 54, 31, 76, 101, 43, 21)
|
||||
#'
|
||||
#' # split into 0-49 and 50+
|
||||
#' age_groups(ages, 50)
|
||||
#'
|
||||
#' # split into 0-19, 20-49 and 50+
|
||||
#' age_groups(ages, c(20, 50))
|
||||
#'
|
||||
#' # split into groups of ten years
|
||||
#' age_groups(ages, 1:10 * 10)
|
||||
#' age_groups(ages, split_at = "tens")
|
||||
#'
|
||||
#' # split into groups of five years
|
||||
#' age_groups(ages, 1:20 * 5)
|
||||
#' age_groups(ages, split_at = "fives")
|
||||
#'
|
||||
#' # split specifically for children
|
||||
#' age_groups(ages, "children")
|
||||
#' # same:
|
||||
#' age_groups(ages, c(1, 2, 4, 6, 13, 17))
|
||||
#'
|
||||
#' # resistance of ciprofloxacine per age group
|
||||
#' library(dplyr)
|
||||
#' septic_patients %>%
|
||||
#' filter_first_isolate() %>%
|
||||
#' filter(mo == as.mo("E. coli")) %>%
|
||||
#' group_by(age_group = age_groups(age)) %>%
|
||||
#' select(age_group, CIP) %>%
|
||||
#' ggplot_rsi(x = "age_group")
|
||||
age_groups <- function(x, split_at = c(12, 25, 55, 75)) {
|
||||
if (is.character(split_at)) {
|
||||
split_at <- split_at[1L]
|
||||
if (split_at %like% "^(child|kid|junior)") {
|
||||
split_at <- c(0, 1, 2, 4, 6, 13, 18)
|
||||
} else if (split_at %like% "^(elder|senior)") {
|
||||
split_at <- c(65, 75, 85)
|
||||
} else if (split_at %like% "^five") {
|
||||
split_at <- 1:20 * 5
|
||||
} else if (split_at %like% "^ten") {
|
||||
split_at <- 1:10 * 10
|
||||
}
|
||||
}
|
||||
split_at <- as.integer(split_at)
|
||||
if (!is.numeric(x) | !is.numeric(split_at)) {
|
||||
stop("`x` and `split_at` must both be numeric.")
|
||||
}
|
||||
split_at <- sort(unique(split_at))
|
||||
if (!split_at[1] == 0) {
|
||||
# add base number 0
|
||||
split_at <- c(0, split_at)
|
||||
}
|
||||
split_at <- split_at[!is.na(split_at)]
|
||||
if (length(split_at) == 1) {
|
||||
# only 0 is available
|
||||
stop("invalid value for `split_at`.")
|
||||
}
|
||||
|
||||
# turn input values to 'split_at' indices
|
||||
y <- x
|
||||
labs <- split_at
|
||||
for (i in 1:length(split_at)) {
|
||||
y[x >= split_at[i]] <- i
|
||||
# create labels
|
||||
labs[i - 1] <- paste0(unique(c(split_at[i - 1], split_at[i] - 1)), collapse = "-")
|
||||
}
|
||||
|
||||
# last category
|
||||
labs[length(labs)] <- paste0(split_at[length(split_at)], "+")
|
||||
|
||||
factor(labs[y], levels = labs, ordered = TRUE)
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
# ==================================================================== #
|
||||
# TITLE #
|
||||
# Antimicrobial Resistance (AMR) Analysis #
|
||||
# #
|
||||
# SOURCE #
|
||||
# https://gitlab.com/msberends/AMR #
|
||||
# #
|
||||
# LICENCE #
|
||||
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
|
||||
# #
|
||||
# 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. #
|
||||
# #
|
||||
# This R package was created for academic research and was publicly #
|
||||
# released in the hope that it will be useful, but it comes WITHOUT #
|
||||
# ANY WARRANTY OR LIABILITY. #
|
||||
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
||||
# ==================================================================== #
|
||||
|
||||
#' The \code{AMR} Package
|
||||
#'
|
||||
#' Welcome to the \code{AMR} package.
|
||||
#' @details
|
||||
#' \code{AMR} is a free and open-source R package to simplify the analysis and prediction of Antimicrobial Resistance (AMR) and to work with microbial and antimicrobial properties by using evidence-based methods. It supports any table format, including WHONET/EARS-Net data.
|
||||
#'
|
||||
#' We created this package for both academic research and routine analysis at the Faculty of Medical Sciences of the University of Groningen and the Medical Microbiology & Infection Prevention (MMBI) department of the University Medical Center Groningen (UMCG). This R package is actively maintained and free software; you can freely use and distribute it for both personal and commercial (but not patent) purposes under the terms of the GNU General Public License version 2.0 (GPL-2), as published by the Free Software Foundation.
|
||||
#'
|
||||
#' This package can be used for:
|
||||
#' \itemize{
|
||||
#' \item{Reference for microorganisms, since it contains all microbial (sub)species from the Catalogue of Life}
|
||||
#' \item{Interpreting raw MIC and disk diffusion values, based on the latest CLSI or EUCAST guidelines}
|
||||
#' \item{Calculating antimicrobial resistance}
|
||||
#' \item{Determining multi-drug resistance (MDR) / multi-drug resistant organisms (MDRO)}
|
||||
#' \item{Calculating empirical susceptibility of both mono therapy and combination therapy}
|
||||
#' \item{Predicting future antimicrobial resistance using regression models}
|
||||
#' \item{Getting properties for any microorganism (like Gram stain, species, genus or family)}
|
||||
#' \item{Getting properties for any antibiotic (like name, ATC code, defined daily dose or trade name)}
|
||||
#' \item{Plotting antimicrobial resistance}
|
||||
#' \item{Determining first isolates to be used for AMR analysis}
|
||||
#' \item{Applying EUCAST expert rules}
|
||||
#' \item{Descriptive statistics: frequency tables, kurtosis and skewness}
|
||||
#' }
|
||||
#' @section Authors:
|
||||
#' Matthijs S. Berends[1,2] Christian F. Luz[1], Erwin E.A. Hassing[2], Corinna Glasner[1], Alex W. Friedrich[1], Bhanu N.M. Sinha[1] \cr
|
||||
#'
|
||||
#' [1] Department of Medical Microbiology, University of Groningen, University Medical Center Groningen, Groningen, the Netherlands - \url{https://www.rug.nl} \url{https://www.umcg.nl} \cr
|
||||
#' [2] Certe Medical Diagnostics & Advice, Groningen, the Netherlands - \url{https://www.certe.nl}
|
||||
|
||||
#' @section Read more on our website!:
|
||||
#' On our website \url{https://msberends.gitlab.io/AMR} you can find \href{https://msberends.gitlab.io/AMR/articles/AMR.html}{a tutorial} about how to conduct AMR analysis, the \href{https://msberends.gitlab.io/AMR/reference}{complete documentation of all functions} (which reads a lot easier than here in R) and \href{https://msberends.gitlab.io/AMR/articles/WHONET.html}{an example analysis using WHONET data}.
|
||||
|
||||
#' @section Contact us:
|
||||
#' For suggestions, comments or questions, please contact us at:
|
||||
#'
|
||||
#' Matthijs S. Berends \cr
|
||||
#' m.s.berends [at] umcg [dot] nl \cr
|
||||
#' Department of Medical Microbiology, University of Groningen \cr
|
||||
#' University Medical Center Groningen \cr
|
||||
#' Post Office Box 30001 \cr
|
||||
#' 9700 RB Groningen
|
||||
#'
|
||||
#' If you have found a bug, please file a new issue at: \cr
|
||||
#' \url{https://gitlab.com/msberends/AMR/issues}
|
||||
#' @name AMR
|
||||
#' @rdname AMR
|
||||
# # prevent NOTE on R >= 3.6
|
||||
#' @importFrom microbenchmark microbenchmark
|
||||
NULL
|
||||
@@ -1,85 +0,0 @@
|
||||
# ==================================================================== #
|
||||
# TITLE #
|
||||
# Antimicrobial Resistance (AMR) Analysis #
|
||||
# #
|
||||
# SOURCE #
|
||||
# https://gitlab.com/msberends/AMR #
|
||||
# #
|
||||
# LICENCE #
|
||||
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
|
||||
# #
|
||||
# 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. #
|
||||
# #
|
||||
# This R package was created for academic research and was publicly #
|
||||
# released in the hope that it will be useful, but it comes WITHOUT #
|
||||
# ANY WARRANTY OR LIABILITY. #
|
||||
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
||||
# ==================================================================== #
|
||||
|
||||
#' Transform to ATC code
|
||||
#'
|
||||
#' Use this function to determine the ATC code of one or more antibiotics. The data set \code{\link{antibiotics}} will be searched for abbreviations, official names and trade names.
|
||||
#' @param x character vector to determine \code{ATC} code
|
||||
#' @rdname as.atc
|
||||
#' @aliases atc
|
||||
#' @keywords atc
|
||||
#' @inheritSection WHOCC WHOCC
|
||||
#' @export
|
||||
#' @importFrom dplyr %>% filter slice pull
|
||||
#' @details Use the \code{\link{ab_property}} functions to get properties based on the returned ATC code, see Examples.
|
||||
#'
|
||||
#' In the ATC classification system, the active substances are classified in a hierarchy with five different levels. The system has fourteen main anatomical/pharmacological groups or 1st levels. Each ATC main group is divided into 2nd levels which could be either pharmacological or therapeutic groups. The 3rd and 4th levels are chemical, pharmacological or therapeutic subgroups and the 5th level is the chemical substance. The 2nd, 3rd and 4th levels are often used to identify pharmacological subgroups when that is considered more appropriate than therapeutic or chemical subgroups.
|
||||
#' Source: \url{https://www.whocc.no/atc/structure_and_principles/}
|
||||
#' @return Character (vector) with class \code{"atc"}. Unknown values will return \code{NA}.
|
||||
#' @seealso \code{\link{antibiotics}} for the dataframe that is being used to determine ATCs.
|
||||
#' @inheritSection AMR Read more on our website!
|
||||
#' @examples
|
||||
#' # These examples all return "J01FA01", the ATC code of Erythromycin:
|
||||
#' as.atc("J01FA01")
|
||||
#' as.atc("Erythromycin")
|
||||
#' as.atc("eryt")
|
||||
#' as.atc(" eryt 123")
|
||||
#' as.atc("ERYT")
|
||||
#' as.atc("ERY")
|
||||
as.atc <- function(x) {
|
||||
ab_atc(x)
|
||||
}
|
||||
|
||||
#' @rdname as.atc
|
||||
#' @export
|
||||
is.atc <- function(x) {
|
||||
identical(class(x), "atc")
|
||||
}
|
||||
|
||||
#' @exportMethod print.atc
|
||||
#' @export
|
||||
#' @noRd
|
||||
print.atc <- function(x, ...) {
|
||||
cat("Class 'atc'\n")
|
||||
print.default(as.character(x), quote = FALSE)
|
||||
}
|
||||
|
||||
#' @exportMethod as.data.frame.atc
|
||||
#' @export
|
||||
#' @noRd
|
||||
as.data.frame.atc <- function (x, ...) {
|
||||
# same as as.data.frame.character but with removed stringsAsFactors
|
||||
nm <- paste(deparse(substitute(x), width.cutoff = 500L),
|
||||
collapse = " ")
|
||||
if (!"nm" %in% names(list(...))) {
|
||||
as.data.frame.vector(x, ..., nm = nm)
|
||||
} else {
|
||||
as.data.frame.vector(x, ...)
|
||||
}
|
||||
}
|
||||
|
||||
#' @exportMethod pull.atc
|
||||
#' @export
|
||||
#' @importFrom dplyr pull
|
||||
#' @noRd
|
||||
pull.atc <- function(.data, ...) {
|
||||
pull(as.data.frame(.data), ...)
|
||||
}
|
||||
@@ -1,198 +0,0 @@
|
||||
# ==================================================================== #
|
||||
# TITLE #
|
||||
# Antimicrobial Resistance (AMR) Analysis #
|
||||
# #
|
||||
# SOURCE #
|
||||
# https://gitlab.com/msberends/AMR #
|
||||
# #
|
||||
# LICENCE #
|
||||
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
|
||||
# #
|
||||
# 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. #
|
||||
# #
|
||||
# This R package was created for academic research and was publicly #
|
||||
# released in the hope that it will be useful, but it comes WITHOUT #
|
||||
# ANY WARRANTY OR LIABILITY. #
|
||||
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
||||
# ==================================================================== #
|
||||
|
||||
#' Get ATC properties from WHOCC website
|
||||
#'
|
||||
#' Gets data from the WHO to determine properties of an ATC (e.g. an antibiotic) like name, defined daily dose (DDD) or standard unit. \cr \strong{This function requires an internet connection.}
|
||||
#' @param atc_code a character or character vector with ATC code(s) of antibiotic(s)
|
||||
#' @param property property of an ATC code. Valid values are \code{"ATC"}, \code{"Name"}, \code{"DDD"}, \code{"U"} (\code{"unit"}), \code{"Adm.R"}, \code{"Note"} and \code{groups}. For this last option, all hierarchical groups of an ATC code will be returned, see Examples.
|
||||
#' @param administration type of administration when using \code{property = "Adm.R"}, see Details
|
||||
#' @param url url of website of the WHO. The sign \code{\%s} can be used as a placeholder for ATC codes.
|
||||
#' @param ... parameters to pass on to \code{atc_property}
|
||||
#' @details
|
||||
#' Options for parameter \code{administration}:
|
||||
#' \itemize{
|
||||
#' \item{\code{"Implant"}}{ = Implant}
|
||||
#' \item{\code{"Inhal"}}{ = Inhalation}
|
||||
#' \item{\code{"Instill"}}{ = Instillation}
|
||||
#' \item{\code{"N"}}{ = nasal}
|
||||
#' \item{\code{"O"}}{ = oral}
|
||||
#' \item{\code{"P"}}{ = parenteral}
|
||||
#' \item{\code{"R"}}{ = rectal}
|
||||
#' \item{\code{"SL"}}{ = sublingual/buccal}
|
||||
#' \item{\code{"TD"}}{ = transdermal}
|
||||
#' \item{\code{"V"}}{ = vaginal}
|
||||
#' }
|
||||
#'
|
||||
#' Abbreviations of return values when using \code{property = "U"} (unit):
|
||||
#' \itemize{
|
||||
#' \item{\code{"g"}}{ = gram}
|
||||
#' \item{\code{"mg"}}{ = milligram}
|
||||
#' \item{\code{"mcg"}}{ = microgram}
|
||||
#' \item{\code{"U"}}{ = unit}
|
||||
#' \item{\code{"TU"}}{ = thousand units}
|
||||
#' \item{\code{"MU"}}{ = million units}
|
||||
#' \item{\code{"mmol"}}{ = millimole}
|
||||
#' \item{\code{"ml"}}{ = milliliter (e.g. eyedrops)}
|
||||
#' }
|
||||
#' @export
|
||||
#' @rdname atc_online
|
||||
#' @importFrom dplyr %>% progress_estimated
|
||||
#' @inheritSection AMR Read more on our website!
|
||||
#' @source \url{https://www.whocc.no/atc_ddd_alterations__cumulative/ddd_alterations/abbrevations/}
|
||||
#' @examples
|
||||
#' \donttest{
|
||||
#' # oral DDD (Defined Daily Dose) of amoxicillin
|
||||
#' atc_online_property("J01CA04", "DDD", "O")
|
||||
#' # parenteral DDD (Defined Daily Dose) of amoxicillin
|
||||
#' atc_online_property("J01CA04", "DDD", "P")
|
||||
#'
|
||||
#' atc_online_property("J01CA04", property = "groups") # search hierarchical groups of amoxicillin
|
||||
#' # [1] "ANTIINFECTIVES FOR SYSTEMIC USE"
|
||||
#' # [2] "ANTIBACTERIALS FOR SYSTEMIC USE"
|
||||
#' # [3] "BETA-LACTAM ANTIBACTERIALS, PENICILLINS"
|
||||
#' # [4] "Penicillins with extended spectrum"
|
||||
#' }
|
||||
atc_online_property <- function(atc_code,
|
||||
property,
|
||||
administration = 'O',
|
||||
url = 'https://www.whocc.no/atc_ddd_index/?code=%s&showdescription=no') {
|
||||
|
||||
if (!all(c("curl", "rvest", "xml2") %in% rownames(installed.packages()))) {
|
||||
stop("Packages 'xml2', 'rvest' and 'curl' are required for this function")
|
||||
}
|
||||
|
||||
if (!all(atc_code %in% AMR::antibiotics)) {
|
||||
atc_code <- as.character(as.atc(atc_code))
|
||||
}
|
||||
|
||||
if (!curl::has_internet()) {
|
||||
message("There appears to be no internet connection.")
|
||||
return(rep(NA, length(atc_code)))
|
||||
}
|
||||
|
||||
if (length(property) != 1L) {
|
||||
stop('`property` must be of length 1', call. = FALSE)
|
||||
}
|
||||
if (length(administration) != 1L) {
|
||||
stop('`administration` must be of length 1', call. = FALSE)
|
||||
}
|
||||
|
||||
# also allow unit as property
|
||||
if (property %like% 'unit') {
|
||||
property <- 'U'
|
||||
}
|
||||
|
||||
# validation of properties
|
||||
valid_properties <- c("ATC", "Name", "DDD", "U", "Adm.R", "Note", "groups")
|
||||
valid_properties.bak <- valid_properties
|
||||
|
||||
property <- tolower(property)
|
||||
valid_properties <- tolower(valid_properties)
|
||||
|
||||
if (!property %in% valid_properties) {
|
||||
stop('Invalid `property`, use one of ', paste(valid_properties.bak, collapse = ", "), '.')
|
||||
}
|
||||
|
||||
if (property == 'ddd') {
|
||||
returnvalue <- rep(NA_real_, length(atc_code))
|
||||
} else if (property == 'groups') {
|
||||
returnvalue <- list()
|
||||
} else {
|
||||
returnvalue <- rep(NA_character_, length(atc_code))
|
||||
}
|
||||
|
||||
progress <- progress_estimated(n = length(atc_code))
|
||||
|
||||
for (i in 1:length(atc_code)) {
|
||||
|
||||
progress$tick()$print()
|
||||
|
||||
atc_url <- sub('%s', atc_code[i], url, fixed = TRUE)
|
||||
|
||||
if (property == "groups") {
|
||||
tbl <- xml2::read_html(atc_url) %>%
|
||||
rvest::html_node("#content") %>%
|
||||
rvest::html_children() %>%
|
||||
rvest::html_node("a")
|
||||
|
||||
# get URLS of items
|
||||
hrefs <- tbl %>% rvest::html_attr("href")
|
||||
# get text of items
|
||||
texts <- tbl %>% rvest::html_text()
|
||||
# select only text items where URL like "code="
|
||||
texts <- texts[grepl("?code=", tolower(hrefs), fixed = TRUE)]
|
||||
# last one is antibiotics, skip it
|
||||
texts <- texts[1:length(texts) - 1]
|
||||
returnvalue <- c(list(texts), returnvalue)
|
||||
|
||||
} else {
|
||||
tbl <- xml2::read_html(atc_url) %>%
|
||||
rvest::html_nodes('table') %>%
|
||||
rvest::html_table(header = TRUE) %>%
|
||||
as.data.frame(stringsAsFactors = FALSE)
|
||||
|
||||
# case insensitive column names
|
||||
colnames(tbl) <- tolower(colnames(tbl)) %>% gsub('^atc.*', 'atc', .)
|
||||
|
||||
if (length(tbl) == 0) {
|
||||
warning('ATC not found: ', atc_code[i], '. Please check ', atc_url, '.', call. = FALSE)
|
||||
returnvalue[i] <- NA
|
||||
next
|
||||
}
|
||||
|
||||
if (property %in% c('atc', 'name')) {
|
||||
# ATC and name are only in first row
|
||||
returnvalue[i] <- tbl[1, property]
|
||||
} else {
|
||||
if (!'adm.r' %in% colnames(tbl) | is.na(tbl[1, 'adm.r'])) {
|
||||
returnvalue[i] <- NA
|
||||
next
|
||||
} else {
|
||||
for (j in 1:nrow(tbl)) {
|
||||
if (tbl[j, 'adm.r'] == administration) {
|
||||
returnvalue[i] <- tbl[j, property]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (property == "groups" & length(returnvalue) == 1) {
|
||||
returnvalue <- returnvalue[[1]]
|
||||
}
|
||||
|
||||
returnvalue
|
||||
}
|
||||
|
||||
#' @rdname atc_online
|
||||
#' @export
|
||||
atc_online_groups <- function(atc_code, ...) {
|
||||
atc_online_property(atc_code = atc_code, property = "groups", ...)
|
||||
}
|
||||
|
||||
#' @rdname atc_online
|
||||
#' @export
|
||||
atc_online_ddd <- function(atc_code, ...) {
|
||||
atc_online_property(atc_code = atc_code, property = "ddd", ...)
|
||||
}
|
||||
|
||||
@@ -1,88 +0,0 @@
|
||||
# ==================================================================== #
|
||||
# TITLE #
|
||||
# Antimicrobial Resistance (AMR) Analysis #
|
||||
# #
|
||||
# SOURCE #
|
||||
# https://gitlab.com/msberends/AMR #
|
||||
# #
|
||||
# LICENCE #
|
||||
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
|
||||
# #
|
||||
# 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. #
|
||||
# #
|
||||
# This R package was created for academic research and was publicly #
|
||||
# released in the hope that it will be useful, but it comes WITHOUT #
|
||||
# ANY WARRANTY OR LIABILITY. #
|
||||
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
||||
# ==================================================================== #
|
||||
|
||||
#' Check availability of columns
|
||||
#'
|
||||
#' Easy check for availability of columns in a data set. This makes it easy to get an idea of which antibiotic combination can be used for calculation with e.g. \code{\link{portion_IR}}.
|
||||
#' @param tbl a \code{data.frame} or \code{list}
|
||||
#' @param width number of characters to present the visual availability, defaults to filling the width of the console
|
||||
#' @return \code{data.frame} with column names of \code{tbl} as row names
|
||||
#' @inheritSection AMR Read more on our website!
|
||||
#' @export
|
||||
#' @examples
|
||||
#' availability(septic_patients)
|
||||
#'
|
||||
#' library(dplyr)
|
||||
#' septic_patients %>% availability()
|
||||
#'
|
||||
#' septic_patients %>%
|
||||
#' select_if(is.rsi) %>%
|
||||
#' availability()
|
||||
#'
|
||||
#' septic_patients %>%
|
||||
#' filter(mo == as.mo("E. coli")) %>%
|
||||
#' select_if(is.rsi) %>%
|
||||
#' availability()
|
||||
availability <- function(tbl, width = NULL) {
|
||||
x <- base::sapply(tbl, function(x) { 1 - base::sum(base::is.na(x)) / base::length(x) })
|
||||
n <- base::sapply(tbl, function(x) base::length(x[!base::is.na(x)]))
|
||||
IR <- base::sapply(tbl, function(x) base::ifelse(is.rsi(x), portion_IR(x, minimum = 0), NA))
|
||||
IR_print <- character(length(IR))
|
||||
IR_print[!is.na(IR)] <- percent(IR[!is.na(IR)], round = 1, force_zero = TRUE)
|
||||
IR_print[is.na(IR)] <- ""
|
||||
|
||||
if (is.null(width)) {
|
||||
width <- options()$width -
|
||||
(max(nchar(colnames(tbl))) +
|
||||
# count col
|
||||
8 +
|
||||
# available % column
|
||||
10 +
|
||||
# resistant % column
|
||||
10 +
|
||||
# extra margin
|
||||
5)
|
||||
width <- width / 2
|
||||
}
|
||||
|
||||
if (length(IR[is.na(IR)]) == ncol(tbl)) {
|
||||
width <- width * 2 + 10
|
||||
}
|
||||
|
||||
x_chars_IR <- strrep("#", round(width * IR, digits = 2))
|
||||
x_chars_S <- strrep("-", width - nchar(x_chars_IR))
|
||||
vis_resistance <- paste0("|", x_chars_IR, x_chars_S, "|")
|
||||
vis_resistance[is.na(IR)] <- ""
|
||||
|
||||
x_chars <- strrep("#", round(x, digits = 2) / (1 / width))
|
||||
x_chars_empty <- strrep("-", width - nchar(x_chars))
|
||||
|
||||
df <- data.frame(count = n,
|
||||
available = percent(x, round = 1, force_zero = TRUE),
|
||||
visual_availabilty = paste0("|", x_chars, x_chars_empty, "|"),
|
||||
resistant = IR_print,
|
||||
visual_resistance = vis_resistance)
|
||||
if (length(IR[is.na(IR)]) == ncol(tbl)) {
|
||||
df[,1:3]
|
||||
} else {
|
||||
df
|
||||
}
|
||||
}
|
||||
@@ -1,136 +0,0 @@
|
||||
# ==================================================================== #
|
||||
# TITLE #
|
||||
# Antimicrobial Resistance (AMR) Analysis #
|
||||
# #
|
||||
# SOURCE #
|
||||
# https://gitlab.com/msberends/AMR #
|
||||
# #
|
||||
# LICENCE #
|
||||
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
|
||||
# #
|
||||
# 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. #
|
||||
# #
|
||||
# This R package was created for academic research and was publicly #
|
||||
# released in the hope that it will be useful, but it comes WITHOUT #
|
||||
# ANY WARRANTY OR LIABILITY. #
|
||||
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
||||
# ==================================================================== #
|
||||
|
||||
#' The Catalogue of Life
|
||||
#'
|
||||
#' This package contains the complete taxonomic tree of almost all microorganisms from the authoritative and comprehensive Catalogue of Life.
|
||||
#' @section Catalogue of Life:
|
||||
#' \if{html}{\figure{logo_col.png}{options: height=40px style=margin-bottom:5px} \cr}
|
||||
#' This package contains the complete taxonomic tree of almost all microorganisms (~65,000 species) from the authoritative and comprehensive Catalogue of Life (\url{http://www.catalogueoflife.org}). The Catalogue of Life is the most comprehensive and authoritative global index of species currently available.
|
||||
#'
|
||||
#' \link[=catalogue_of_life]{Click here} for more information about the included taxa. The Catalogue of Life releases updates annually; check which version was included in this package with \code{\link{catalogue_of_life_version}()}.
|
||||
#' @section Included taxa:
|
||||
#' Included are:
|
||||
#' \itemize{
|
||||
#' \item{All ~55,000 (sub)species from the kingdoms of Archaea, Bacteria and Protozoa}
|
||||
#' \item{All ~3,500 (sub)species from these orders of the kingdom of Fungi: Eurotiales, Onygenales, Pneumocystales, Saccharomycetales, Schizosaccharomycetales and Tremellales. 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 and including everything would tremendously slow down our algorithms too. By only including the aforementioned taxonomic orders, the most relevant fungi are covered (like all species of \emph{Aspergillus}, \emph{Candida}, \emph{Cryptococcus}, \emph{Histplasma}, \emph{Pneumocystis}, \emph{Saccharomyces} and \emph{Trichophyton}).}
|
||||
#' \item{All ~2,000 (sub)species from ~100 other relevant genera, from the kingdoms of Animalia and Plantae (like \emph{Strongyloides} and \emph{Taenia})}
|
||||
#' \item{All ~21,000 previously accepted names of included (sub)species that have been taxonomically renamed}
|
||||
#' \item{The complete taxonomic tree of all included (sub)species: from kingdom to subspecies}
|
||||
#' \item{The responsible author(s) and year of scientific publication}
|
||||
#' }
|
||||
#'
|
||||
#' The Catalogue of Life (\url{http://www.catalogueoflife.org}) is the most comprehensive and authoritative global index of species currently available. It holds essential information on the names, relationships and distributions of over 1.6 million species. The Catalogue of Life is used to support the major biodiversity and conservation information services such as the Global Biodiversity Information Facility (GBIF), Encyclopedia of Life (EoL) and the International Union for Conservation of Nature Red List. It is recognised by the Convention on Biological Diversity as a significant component of the Global Taxonomy Initiative and a contribution to Target 1 of the Global Strategy for Plant Conservation.
|
||||
#'
|
||||
#' The syntax used to transform the original data to a cleansed R format, can be found here: \url{https://gitlab.com/msberends/AMR/blob/master/data-raw/reproduction_of_microorganisms.R}.
|
||||
#' @inheritSection AMR Read more on our website!
|
||||
#' @name catalogue_of_life
|
||||
#' @rdname catalogue_of_life
|
||||
#' @seealso Data set \code{\link{microorganisms}} for the actual data. \cr
|
||||
#' Function \code{\link{as.mo}()} to use the data for intelligent determination of microorganisms.
|
||||
#' @examples
|
||||
#' # Get version info of included data set
|
||||
#' catalogue_of_life_version()
|
||||
#'
|
||||
#'
|
||||
#' # Get a note when a species was renamed
|
||||
#' mo_shortname("Chlamydia psittaci")
|
||||
#' # Note: 'Chlamydia psittaci' (Page, 1968) was renamed
|
||||
#' # 'Chlamydophila psittaci' (Everett et al., 1999)
|
||||
#' # [1] "C. psittaci"
|
||||
#'
|
||||
#' # Get any property from the entire taxonomic tree for all included species
|
||||
#' mo_class("E. coli")
|
||||
#' # [1] "Gammaproteobacteria"
|
||||
#'
|
||||
#' mo_family("E. coli")
|
||||
#' # [1] "Enterobacteriaceae"
|
||||
#'
|
||||
#' mo_gramstain("E. coli") # based on kingdom and phylum, see ?mo_gramstain
|
||||
#' # [1] "Gram negative"
|
||||
#'
|
||||
#' mo_ref("E. coli")
|
||||
#' # [1] "Castellani et al., 1919"
|
||||
#'
|
||||
#' # Do not get mistaken - the package only includes microorganisms
|
||||
#' mo_phylum("C. elegans")
|
||||
#' # [1] "Cyanobacteria" # Bacteria?!
|
||||
#' mo_fullname("C. elegans")
|
||||
#' # [1] "Chroococcus limneticus elegans" # Because a microorganism was found
|
||||
NULL
|
||||
|
||||
#' Version info of included Catalogue of Life
|
||||
#'
|
||||
#' This function returns information about the included data from the Catalogue of Life. It also shows if the included version is their latest annual release. The Catalogue of Life releases their annual release in March each year.
|
||||
#' @seealso \code{\link{microorganisms}}
|
||||
#' @details The list item \code{...$catalogue_of_life$is_latest_annual_release} is based on the system date.
|
||||
#'
|
||||
#' For DSMZ, see \code{?microorganisms}.
|
||||
#' @return a \code{list}, which prints in pretty format
|
||||
#' @inheritSection catalogue_of_life Catalogue of Life
|
||||
#' @inheritSection AMR Read more on our website!
|
||||
#' @importFrom crayon bold underline
|
||||
#' @importFrom dplyr filter
|
||||
#' @export
|
||||
#' @examples
|
||||
#' library(dplyr)
|
||||
#' microorganisms %>% freq(kingdom)
|
||||
#' microorganisms %>% group_by(kingdom) %>% freq(phylum, nmax = NULL)
|
||||
catalogue_of_life_version <- function() {
|
||||
# see the `catalogue_of_life` list in R/data.R
|
||||
lst <- list(catalogue_of_life =
|
||||
list(version = gsub("{year}", catalogue_of_life$year, catalogue_of_life$version, fixed = TRUE),
|
||||
url = gsub("{year}", catalogue_of_life$year, catalogue_of_life$url_CoL, fixed = TRUE),
|
||||
# annual release always somewhere in May, so before June is TRUE, FALSE otherwise
|
||||
is_latest_annual_release = Sys.Date() < as.Date(paste0(catalogue_of_life$year + 1, "-06-01")),
|
||||
n = nrow(filter(AMR::microorganisms, source == "CoL"))),
|
||||
deutsche_sammlung_von_mikroorganismen_und_zellkulturen =
|
||||
list(version = "Prokaryotic Nomenclature Up-to-Date from DSMZ",
|
||||
url = catalogue_of_life$url_DSMZ,
|
||||
yearmonth = catalogue_of_life$yearmonth_DSMZ,
|
||||
n = nrow(filter(AMR::microorganisms, source == "DSMZ"))),
|
||||
total_included =
|
||||
list(
|
||||
n_total_species = nrow(AMR::microorganisms),
|
||||
n_total_synonyms = nrow(AMR::microorganisms.old)))
|
||||
|
||||
structure(.Data = lst,
|
||||
class = c("catalogue_of_life_version", "list"))
|
||||
}
|
||||
|
||||
#' @exportMethod print.catalogue_of_life_version
|
||||
#' @export
|
||||
#' @noRd
|
||||
print.catalogue_of_life_version <- function(x, ...) {
|
||||
lst <- x
|
||||
cat(paste0(bold("Included in this AMR package are:\n\n"),
|
||||
underline(lst$catalogue_of_life$version), "\n",
|
||||
" Available at: ", lst$catalogue_of_life$url, "\n",
|
||||
" Number of included species: ", format(lst$catalogue_of_life$n, big.mark = ","), "\n",
|
||||
" (based on your system time, this is most likely ", ifelse(lst$catalogue_of_life$is_latest_annual_release, "", "not "), "the latest annual release)\n\n",
|
||||
underline(paste0(lst$deutsche_sammlung_von_mikroorganismen_und_zellkulturen$version, " (",
|
||||
lst$deutsche_sammlung_von_mikroorganismen_und_zellkulturen$yearmonth, ")")), "\n",
|
||||
" Available at: ", lst$deutsche_sammlung_von_mikroorganismen_und_zellkulturen$url, "\n",
|
||||
" Number of included species: ", format(lst$deutsche_sammlung_von_mikroorganismen_und_zellkulturen$n, big.mark = ","), "\n\n",
|
||||
"=> Total number of species included: ", format(lst$total_included$n_total_species, big.mark = ","), "\n",
|
||||
"=> Total number of synonyms included: ", format(lst$total_included$n_total_synonyms, big.mark = ","), "\n\n",
|
||||
"See for more info ?microorganisms and ?catalogue_of_life.\n"))
|
||||
}
|
||||
@@ -1,188 +0,0 @@
|
||||
# ==================================================================== #
|
||||
# TITLE #
|
||||
# Antimicrobial Resistance (AMR) Analysis #
|
||||
# #
|
||||
# SOURCE #
|
||||
# https://gitlab.com/msberends/AMR #
|
||||
# #
|
||||
# LICENCE #
|
||||
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
|
||||
# #
|
||||
# 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. #
|
||||
# #
|
||||
# This R package was created for academic research and was publicly #
|
||||
# released in the hope that it will be useful, but it comes WITHOUT #
|
||||
# ANY WARRANTY OR LIABILITY. #
|
||||
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
||||
# ==================================================================== #
|
||||
|
||||
#' Count isolates
|
||||
#'
|
||||
#' @description These functions can be used to count resistant/susceptible microbial isolates. All functions support quasiquotation with pipes, can be used in \code{dplyr}s \code{\link[dplyr]{summarise}} and support grouped variables, see \emph{Examples}.
|
||||
#'
|
||||
#' \code{count_R} and \code{count_IR} can be used to count resistant isolates, \code{count_S} and \code{count_SI} can be used to count susceptible isolates.\cr
|
||||
#' @param ... one or more vectors (or columns) with antibiotic interpretations. They will be transformed internally with \code{\link{as.rsi}} if needed.
|
||||
#' @inheritParams portion
|
||||
#' @inheritSection as.rsi Interpretation of S, I and R
|
||||
#' @details These functions are meant to count isolates. Use the \code{\link{portion}_*} functions to calculate microbial resistance.
|
||||
#'
|
||||
#' \code{n_rsi} is an alias of \code{count_all}. They can be used to count all available isolates, i.e. where all input antibiotics have an available result (S, I or R). Their use is equal to \code{\link{n_distinct}}. Their function is equal to \code{count_S(...) + count_IR(...)}.
|
||||
#'
|
||||
#' \code{count_df} takes any variable from \code{data} that has an \code{"rsi"} class (created with \code{\link{as.rsi}}) and counts the amounts of R, I and S. The resulting \emph{tidy data} (see Source) \code{data.frame} will have three rows (S/I/R) and a column for each variable with class \code{"rsi"}.
|
||||
#' @source Wickham H. \strong{Tidy Data.} The Journal of Statistical Software, vol. 59, 2014. \url{http://vita.had.co.nz/papers/tidy-data.html}
|
||||
#' @seealso \code{\link{portion}_*} to calculate microbial resistance and susceptibility.
|
||||
#' @keywords resistance susceptibility rsi antibiotics isolate isolates
|
||||
#' @return Integer
|
||||
#' @rdname count
|
||||
#' @name count
|
||||
#' @export
|
||||
#' @inheritSection AMR Read more on our website!
|
||||
#' @examples
|
||||
#' # septic_patients is a data set available in the AMR package. It is true, genuine data.
|
||||
#' ?septic_patients
|
||||
#'
|
||||
#' # Count resistant isolates
|
||||
#' count_R(septic_patients$AMX)
|
||||
#' count_IR(septic_patients$AMX)
|
||||
#'
|
||||
#' # Or susceptible isolates
|
||||
#' count_S(septic_patients$AMX)
|
||||
#' count_SI(septic_patients$AMX)
|
||||
#'
|
||||
#' # Count all available isolates
|
||||
#' count_all(septic_patients$AMX)
|
||||
#' n_rsi(septic_patients$AMX)
|
||||
#'
|
||||
#' # Since n_rsi counts available isolates, you can
|
||||
#' # calculate back to count e.g. non-susceptible isolates.
|
||||
#' # This results in the same:
|
||||
#' count_IR(septic_patients$AMX)
|
||||
#' portion_IR(septic_patients$AMX) * n_rsi(septic_patients$AMX)
|
||||
#'
|
||||
#' library(dplyr)
|
||||
#' septic_patients %>%
|
||||
#' group_by(hospital_id) %>%
|
||||
#' summarise(R = count_R(CIP),
|
||||
#' I = count_I(CIP),
|
||||
#' S = count_S(CIP),
|
||||
#' n1 = count_all(CIP), # the actual total; sum of all three
|
||||
#' n2 = n_rsi(CIP), # same - analogous to n_distinct
|
||||
#' total = n()) # NOT the number of tested isolates!
|
||||
#'
|
||||
#' # Count co-resistance between amoxicillin/clav acid and gentamicin,
|
||||
#' # so we can see that combination therapy does a lot more than mono therapy.
|
||||
#' # Please mind that `portion_S` calculates percentages right away instead.
|
||||
#' count_S(septic_patients$AMC) # S = 1342 (71.4%)
|
||||
#' count_all(septic_patients$AMC) # n = 1879
|
||||
#'
|
||||
#' count_S(septic_patients$GEN) # S = 1372 (74.0%)
|
||||
#' count_all(septic_patients$GEN) # n = 1855
|
||||
#'
|
||||
#' with(septic_patients,
|
||||
#' count_S(AMC, GEN)) # S = 1660 (92.3%)
|
||||
#' with(septic_patients, # n = 1798
|
||||
#' n_rsi(AMC, GEN))
|
||||
#'
|
||||
#' # Get portions S/I/R immediately of all rsi columns
|
||||
#' septic_patients %>%
|
||||
#' select(AMX, CIP) %>%
|
||||
#' count_df(translate = FALSE)
|
||||
#'
|
||||
#' # It also supports grouping variables
|
||||
#' septic_patients %>%
|
||||
#' select(hospital_id, AMX, CIP) %>%
|
||||
#' group_by(hospital_id) %>%
|
||||
#' count_df(translate = FALSE)
|
||||
#'
|
||||
count_R <- function(..., also_single_tested = FALSE) {
|
||||
rsi_calc(...,
|
||||
type = "R",
|
||||
include_I = FALSE,
|
||||
minimum = 0,
|
||||
as_percent = FALSE,
|
||||
also_single_tested = FALSE,
|
||||
only_count = TRUE)
|
||||
}
|
||||
|
||||
#' @rdname count
|
||||
#' @export
|
||||
count_IR <- function(..., also_single_tested = FALSE) {
|
||||
rsi_calc(...,
|
||||
type = "R",
|
||||
include_I = TRUE,
|
||||
minimum = 0,
|
||||
as_percent = FALSE,
|
||||
also_single_tested = FALSE,
|
||||
only_count = TRUE)
|
||||
}
|
||||
|
||||
#' @rdname count
|
||||
#' @export
|
||||
count_I <- function(..., also_single_tested = FALSE) {
|
||||
rsi_calc(...,
|
||||
type = "I",
|
||||
include_I = FALSE,
|
||||
minimum = 0,
|
||||
as_percent = FALSE,
|
||||
also_single_tested = FALSE,
|
||||
only_count = TRUE)
|
||||
}
|
||||
|
||||
#' @rdname count
|
||||
#' @export
|
||||
count_SI <- function(..., also_single_tested = FALSE) {
|
||||
rsi_calc(...,
|
||||
type = "S",
|
||||
include_I = TRUE,
|
||||
minimum = 0,
|
||||
as_percent = FALSE,
|
||||
also_single_tested = FALSE,
|
||||
only_count = TRUE)
|
||||
}
|
||||
|
||||
#' @rdname count
|
||||
#' @export
|
||||
count_S <- function(..., also_single_tested = FALSE) {
|
||||
rsi_calc(...,
|
||||
type = "S",
|
||||
include_I = FALSE,
|
||||
minimum = 0,
|
||||
as_percent = FALSE,
|
||||
also_single_tested = FALSE,
|
||||
only_count = TRUE)
|
||||
}
|
||||
|
||||
#' @rdname count
|
||||
#' @export
|
||||
count_all <- function(...) {
|
||||
# only print warnings once, if needed
|
||||
count_S(...) + suppressWarnings(count_IR(...))
|
||||
}
|
||||
|
||||
#' @rdname count
|
||||
#' @export
|
||||
n_rsi <- function(...) {
|
||||
# only print warnings once, if needed
|
||||
count_S(...) + suppressWarnings(count_IR(...))
|
||||
}
|
||||
|
||||
#' @rdname count
|
||||
#' @importFrom dplyr %>% select_if bind_rows summarise_if mutate group_vars select everything
|
||||
#' @export
|
||||
count_df <- function(data,
|
||||
translate_ab = "name",
|
||||
language = get_locale(),
|
||||
combine_SI = TRUE,
|
||||
combine_IR = FALSE) {
|
||||
|
||||
rsi_calc_df(type = "count",
|
||||
data = data,
|
||||
translate_ab = translate_ab,
|
||||
language = language,
|
||||
combine_SI = combine_SI,
|
||||
combine_IR = combine_IR,
|
||||
combine_SI_missing = missing(combine_SI))
|
||||
}
|
||||
@@ -1,222 +0,0 @@
|
||||
# ==================================================================== #
|
||||
# TITLE #
|
||||
# Antimicrobial Resistance (AMR) Analysis #
|
||||
# #
|
||||
# SOURCE #
|
||||
# https://gitlab.com/msberends/AMR #
|
||||
# #
|
||||
# LICENCE #
|
||||
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
|
||||
# #
|
||||
# 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. #
|
||||
# #
|
||||
# This R package was created for academic research and was publicly #
|
||||
# released in the hope that it will be useful, but it comes WITHOUT #
|
||||
# ANY WARRANTY OR LIABILITY. #
|
||||
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
||||
# ==================================================================== #
|
||||
|
||||
#' Data set with ~450 antibiotics
|
||||
#'
|
||||
#' A data set containing all antibiotics. Use \code{\link{as.ab}} or one of the \code{\link{ab_property}} functions to retrieve values from this data set. Three identifiers are included in this data set: an antibiotic ID (\code{ab}, primarily used in this package) as defined by WHONET/EARS-Net, an ATC code (\code{atc}) as defined by the WHO, and a Compound ID (\code{cid}) as found in PubChem. Other properties in this data set are derived from one or more of these codes.
|
||||
#' @format A \code{\link{data.frame}} with 454 observations and 13 variables:
|
||||
#' \describe{
|
||||
#' \item{\code{ab}}{Antibiotic ID as used in this package (like \code{AMC}), using the official EARS-Net (European Antimicrobial Resistance Surveillance Network) codes where available}
|
||||
#' \item{\code{atc}}{ATC code (Anatomical Therapeutic Chemical) as defined by the WHOCC, like \code{J01CR02}}
|
||||
#' \item{\code{cid}}{Compound ID as found in PubChem}
|
||||
#' \item{\code{name}}{Official name as used by WHONET/EARS-Net or the WHO}
|
||||
#' \item{\code{group}}{A short and concise group name, based on WHONET and WHOCC definitions}
|
||||
#' \item{\code{atc_group1}}{Official pharmacological subgroup (3rd level ATC code) as defined by the WHOCC, like \code{"Macrolides, lincosamides and streptogramins"}}
|
||||
#' \item{\code{atc_group2}}{Official chemical subgroup (4th level ATC code) as defined by the WHOCC, like \code{"Macrolides"}}
|
||||
#' \item{\code{abbr}}{List of abbreviations as used in many countries, also for antibiotic susceptibility testing (AST)}
|
||||
#' \item{\code{synonyms}}{Synonyms (often trade names) of a drug, as found in PubChem based on their compound ID}
|
||||
#' \item{\code{oral_ddd}}{Defined Daily Dose (DDD), oral treatment}
|
||||
#' \item{\code{oral_units}}{Units of \code{ddd_units}}
|
||||
#' \item{\code{iv_ddd}}{Defined Daily Dose (DDD), parenteral treatment}
|
||||
#' \item{\code{iv_units}}{Units of \code{iv_ddd}}
|
||||
#' }
|
||||
#' @details Properties that are based on an ATC code are only available when an ATC is available. These properties are: \code{atc_group1}, \code{atc_group2}, \code{oral_ddd}, \code{oral_units}, \code{iv_ddd} and \code{iv_units}
|
||||
#'
|
||||
#' Synonyms (i.e. trade names) are derived from the Compound ID (\code{cid}) and consequently only available where a CID is available.
|
||||
#' @source World Health Organization (WHO) Collaborating Centre for Drug Statistics Methodology (WHOCC): \url{https://www.whocc.no/atc_ddd_index/}
|
||||
#'
|
||||
#' WHONET 2019 software: \url{http://www.whonet.org/software.html}
|
||||
#'
|
||||
#' European Commission Public Health PHARMACEUTICALS - COMMUNITY REGISTER: \url{http://ec.europa.eu/health/documents/community-register/html/atc.htm}
|
||||
#' @inheritSection WHOCC WHOCC
|
||||
#' @inheritSection AMR Read more on our website!
|
||||
#' @seealso \code{\link{microorganisms}}
|
||||
"antibiotics"
|
||||
|
||||
#' Data set with ~65,000 microorganisms
|
||||
#'
|
||||
#' A data set containing the microbial taxonomy of six kingdoms from the Catalogue of Life. MO codes can be looked up using \code{\link{as.mo}}.
|
||||
#' @inheritSection catalogue_of_life Catalogue of Life
|
||||
#' @format A \code{\link{data.frame}} with 67,903 observations and 16 variables:
|
||||
#' \describe{
|
||||
#' \item{\code{mo}}{ID of microorganism as used by this package}
|
||||
#' \item{\code{col_id}}{Catalogue of Life ID}
|
||||
#' \item{\code{fullname}}{Full name, like \code{"Escherichia coli"}}
|
||||
#' \item{\code{kingdom}, \code{phylum}, \code{class}, \code{order}, \code{family}, \code{genus}, \code{species}, \code{subspecies}}{Taxonomic rank of the microorganism}
|
||||
#' \item{\code{rank}}{Text of the taxonomic rank of the microorganism, like \code{"species"} or \code{"genus"}}
|
||||
#' \item{\code{ref}}{Author(s) and year of concerning scientific publication}
|
||||
#' \item{\code{species_id}}{ID of the species as used by the Catalogue of Life}
|
||||
#' \item{\code{source}}{Either \code{"CoL"}, \code{"DSMZ"} (see source) or "manually added"}
|
||||
#' \item{\code{prevalence}}{Prevalence of the microorganism, see \code{?as.mo}}
|
||||
#' }
|
||||
#' @details Manually added were:
|
||||
#' \itemize{
|
||||
#' \item{9 species of \emph{Streptococcus} (beta haemolytic groups A, B, C, D, F, G, H, K and unspecified)}
|
||||
#' \item{2 species of \emph{Staphylococcus} (coagulase-negative [CoNS] and coagulase-positive [CoPS])}
|
||||
#' \item{3 other undefined (unknown, unknown Gram negatives and unknown Gram positives)}
|
||||
#' \item{8,830 species from the DSMZ (Deutsche Sammlung von Mikroorganismen und Zellkulturen) that are not in the Catalogue of Life}
|
||||
#' }
|
||||
#' @section About the records from DSMZ (see source):
|
||||
#' Names of prokaryotes are defined as being validly published by the International Code of Nomenclature of Bacteria. Validly published are all names which are included in the Approved Lists of Bacterial Names and the names subsequently published in the International Journal of Systematic Bacteriology (IJSB) and, from January 2000, in the International Journal of Systematic and Evolutionary Microbiology (IJSEM) as original articles or in the validation lists.
|
||||
#'
|
||||
#' From: \url{https://www.dsmz.de/support/bacterial-nomenclature-up-to-date-downloads/readme.html}
|
||||
#' @source Catalogue of Life: Annual Checklist (public online taxonomic database), \url{http://www.catalogueoflife.org} (check included annual version with \code{\link{catalogue_of_life_version}()}).
|
||||
#'
|
||||
#' Leibniz Institute DSMZ-German Collection of Microorganisms and Cell Cultures, Germany, Prokaryotic Nomenclature Up-to-Date, \url{http://www.dsmz.de/bacterial-diversity/prokaryotic-nomenclature-up-to-date} (check included version with \code{\link{catalogue_of_life_version}()}).
|
||||
#' @inheritSection AMR Read more on our website!
|
||||
#' @seealso \code{\link{as.mo}}, \code{\link{mo_property}}, \code{\link{microorganisms.codes}}
|
||||
"microorganisms"
|
||||
|
||||
catalogue_of_life <- list(
|
||||
year = 2018,
|
||||
version = "Catalogue of Life: {year} Annual Checklist",
|
||||
url_CoL = "http://www.catalogueoflife.org/annual-checklist/{year}/",
|
||||
url_DSMZ = "https://www.dsmz.de/microorganisms/pnu/bacterial_nomenclature_info_mm.php",
|
||||
yearmonth_DSMZ = "February 2019"
|
||||
)
|
||||
|
||||
#' Data set with previously accepted taxonomic names
|
||||
#'
|
||||
#' A data set containing old (previously valid or accepted) taxonomic names according to the Catalogue of Life. This data set is used internally by \code{\link{as.mo}}.
|
||||
#' @inheritSection catalogue_of_life Catalogue of Life
|
||||
#' @format A \code{\link{data.frame}} with 21,342 observations and 4 variables:
|
||||
#' \describe{
|
||||
#' \item{\code{col_id}}{Catalogue of Life ID that was originally given}
|
||||
#' \item{\code{col_id_new}}{New Catalogue of Life ID that responds to an entry in the \code{\link{microorganisms}} data set}
|
||||
#' \item{\code{fullname}}{Old full taxonomic name of the microorganism}
|
||||
#' \item{\code{ref}}{Author(s) and year of concerning scientific publication}
|
||||
#' }
|
||||
#' @source Catalogue of Life: Annual Checklist (public online taxonomic database), \url{http://www.catalogueoflife.org} (check included annual version with \code{\link{catalogue_of_life_version}()}).
|
||||
#' @inheritSection AMR Read more on our website!
|
||||
#' @seealso \code{\link{as.mo}} \code{\link{mo_property}} \code{\link{microorganisms}}
|
||||
"microorganisms.old"
|
||||
|
||||
#' Translation table for microorganism codes
|
||||
#'
|
||||
#' A data set containing commonly used codes for microorganisms, from laboratory systems and WHONET. Define your own with \code{\link{set_mo_source}}.
|
||||
#' @format A \code{\link{data.frame}} with 4,969 observations and 2 variables:
|
||||
#' \describe{
|
||||
#' \item{\code{certe}}{Commonly used code of a microorganism}
|
||||
#' \item{\code{mo}}{ID of the microorganism in the \code{\link{microorganisms}} data set}
|
||||
#' }
|
||||
#' @inheritSection catalogue_of_life Catalogue of Life
|
||||
#' @inheritSection AMR Read more on our website!
|
||||
#' @seealso \code{\link{as.mo}} \code{\link{microorganisms}}
|
||||
"microorganisms.codes"
|
||||
|
||||
#' Data set with 2,000 blood culture isolates from septic patients
|
||||
#'
|
||||
#' An anonymised data set containing 2,000 microbial blood culture isolates with their full antibiograms found in septic patients in 4 different hospitals in the Netherlands, between 2001 and 2017. It is true, genuine data. This \code{data.frame} can be used to practice AMR analysis. For examples, please read \href{https://msberends.gitlab.io/AMR/articles/AMR.html}{the tutorial on our website}.
|
||||
#' @format A \code{\link{data.frame}} with 2,000 observations and 49 variables:
|
||||
#' \describe{
|
||||
#' \item{\code{date}}{date of receipt at the laboratory}
|
||||
#' \item{\code{hospital_id}}{ID of the hospital, from A to D}
|
||||
#' \item{\code{ward_icu}}{logical to determine if ward is an intensive care unit}
|
||||
#' \item{\code{ward_clinical}}{logical to determine if ward is a regular clinical ward}
|
||||
#' \item{\code{ward_outpatient}}{logical to determine if ward is an outpatient clinic}
|
||||
#' \item{\code{age}}{age of the patient}
|
||||
#' \item{\code{gender}}{gender of the patient}
|
||||
#' \item{\code{patient_id}}{ID of the patient, first 10 characters of an SHA hash containing irretrievable information}
|
||||
#' \item{\code{mo}}{ID of microorganism created with \code{\link{as.mo}}, see also \code{\link{microorganisms}}}
|
||||
#' \item{\code{peni:rifa}}{40 different antibiotics with class \code{rsi} (see \code{\link{as.rsi}}); these column names occur in \code{\link{antibiotics}} data set and can be translated with \code{\link{abname}}}
|
||||
#' }
|
||||
#' @inheritSection AMR Read more on our website!
|
||||
"septic_patients"
|
||||
|
||||
#' Data set with 500 isolates - WHONET example
|
||||
#'
|
||||
#' This example data set has the exact same structure as an export file from WHONET. Such files can be used with this package, as this example data set shows. The data itself was based on our \code{\link{septic_patients}} data set.
|
||||
#' @format A \code{\link{data.frame}} with 500 observations and 53 variables:
|
||||
#' \describe{
|
||||
#' \item{\code{Identification number}}{ID of the sample}
|
||||
#' \item{\code{Specimen number}}{ID of the specimen}
|
||||
#' \item{\code{Organism}}{Name of the microorganism. Before analysis, you should transform this to a valid microbial class, using \code{\link{as.mo}}.}
|
||||
#' \item{\code{Country}}{Country of origin}
|
||||
#' \item{\code{Laboratory}}{Name of laboratory}
|
||||
#' \item{\code{Last name}}{Last name of patient}
|
||||
#' \item{\code{First name}}{Initial of patient}
|
||||
#' \item{\code{Sex}}{Gender of patient}
|
||||
#' \item{\code{Age}}{Age of patient}
|
||||
#' \item{\code{Age category}}{Age group, can also be looked up using \code{\link{age_groups}}}
|
||||
#' \item{\code{Date of admission}}{Date of hospital admission}
|
||||
#' \item{\code{Specimen date}}{Date when specimen was received at laboratory}
|
||||
#' \item{\code{Specimen type}}{Specimen type or group}
|
||||
#' \item{\code{Specimen type (Numeric)}}{Translation of \code{"Specimen type"}}
|
||||
#' \item{\code{Reason}}{Reason of request with Differential Diagnosis}
|
||||
#' \item{\code{Isolate number}}{ID of isolate}
|
||||
#' \item{\code{Organism type}}{Type of microorganism, can also be looked up using \code{\link{mo_type}}}
|
||||
#' \item{\code{Serotype}}{Serotype of microorganism}
|
||||
#' \item{\code{Beta-lactamase}}{Microorganism produces beta-lactamase?}
|
||||
#' \item{\code{ESBL}}{Microorganism produces extended spectrum beta-lactamase?}
|
||||
#' \item{\code{Carbapenemase}}{Microorganism produces carbapenemase?}
|
||||
#' \item{\code{MRSA screening test}}{Microorganism is possible MRSA?}
|
||||
#' \item{\code{Inducible clindamycin resistance}}{Clindamycin can be induced?}
|
||||
#' \item{\code{Comment}}{Other comments}
|
||||
#' \item{\code{Date of data entry}}{Date this data was entered in WHONET}
|
||||
#' \item{\code{AMP_ND10:CIP_EE}}{27 different antibiotics. You can lookup the abbreviatons in the \code{\link{antibiotics}} data set, or use e.g. \code{\link{atc_name}("AMP")} to get the official name immediately. Before analysis, you should transform this to a valid antibiotic class, using \code{\link{as.rsi}}.}
|
||||
#' }
|
||||
#' @inheritSection AMR Read more on our website!
|
||||
"WHONET"
|
||||
|
||||
#' Data set for RSI interpretation
|
||||
#'
|
||||
#' Data set to interpret MIC and disk diffusion to RSI values. Included guidelines are CLSI (2011-2019) and EUCAST (2011-2019). Use \code{\link{as.rsi}} to transform MICs or disks measurements to RSI values.
|
||||
#' @format A \code{\link{data.frame}} with 11,559 observations and 9 variables:
|
||||
#' \describe{
|
||||
#' \item{\code{guideline}}{Name of the guideline}
|
||||
#' \item{\code{mo}}{Microbial ID, see \code{\link{as.mo}}}
|
||||
#' \item{\code{ab}}{Antibiotic ID, see \code{\link{as.ab}}}
|
||||
#' \item{\code{ref_tbl}}{Info about where the guideline rule can be found}
|
||||
#' \item{\code{S_mic}}{Lowest MIC value that leads to "S"}
|
||||
#' \item{\code{R_mic}}{Highest MIC value that leads to "R"}
|
||||
#' \item{\code{dose_disk}}{Dose of the used disk diffusion method}
|
||||
#' \item{\code{S_disk}}{Lowest number of millimeters that leads to "S"}
|
||||
#' \item{\code{R_disk}}{Highest number of millimeters that leads to "R"}
|
||||
#' }
|
||||
#' @inheritSection AMR Read more on our website!
|
||||
"rsi_translation"
|
||||
|
||||
# transforms data set to data.frame with only ASCII values, to comply with CRAN policies
|
||||
dataset_UTF8_to_ASCII <- function(df) {
|
||||
trans <- function(vect) {
|
||||
iconv(vect, from = "UTF-8", to = "ASCII//TRANSLIT")
|
||||
}
|
||||
df <- as.data.frame(df, stringsAsFactors = FALSE)
|
||||
for (i in 1:NCOL(df)) {
|
||||
col <- df[, i]
|
||||
if (is.list(col)) {
|
||||
for (j in 1:length(col)) {
|
||||
col[[j]] <- trans(col[[j]])
|
||||
}
|
||||
df[, i] <- list(col)
|
||||
} else {
|
||||
if (is.factor(col)) {
|
||||
levels(col) <- trans(levels(col))
|
||||
} else if (is.character(col)) {
|
||||
col <- trans(col)
|
||||
} else {
|
||||
col
|
||||
}
|
||||
df[, i] <- col
|
||||
}
|
||||
}
|
||||
df
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
# ==================================================================== #
|
||||
# TITLE #
|
||||
# Antimicrobial Resistance (AMR) Analysis #
|
||||
# #
|
||||
# SOURCE #
|
||||
# https://gitlab.com/msberends/AMR #
|
||||
# #
|
||||
# LICENCE #
|
||||
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
|
||||
# #
|
||||
# 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. #
|
||||
# #
|
||||
# This R package was created for academic research and was publicly #
|
||||
# released in the hope that it will be useful, but it comes WITHOUT #
|
||||
# ANY WARRANTY OR LIABILITY. #
|
||||
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
||||
# ==================================================================== #
|
||||
|
||||
#' Deprecated functions
|
||||
#'
|
||||
#' These functions are so-called '\link{Deprecated}'. They will be removed in a future release. Using the functions will give a warning with the name of the function it has been replaced by (if there is one).
|
||||
#' @inheritSection AMR Read more on our website!
|
||||
#' @export
|
||||
#' @keywords internal
|
||||
#' @name AMR-deprecated
|
||||
#' @rdname AMR-deprecated
|
||||
ratio <- function(x, ratio) {
|
||||
.Deprecated(package = "AMR")
|
||||
|
||||
if (!all(is.numeric(x))) {
|
||||
stop('`x` must be a vector of numeric values.')
|
||||
}
|
||||
if (length(ratio) == 1) {
|
||||
if (ratio %like% '^([0-9]+([.][0-9]+)?[-,:])+[0-9]+([.][0-9]+)?$') {
|
||||
# support for "1:2:1", "1-2-1", "1,2,1" and even "1.75:2:1.5"
|
||||
ratio <- ratio %>% strsplit("[-,:]") %>% unlist() %>% as.double()
|
||||
} else {
|
||||
stop('Invalid `ratio`: ', ratio, '.')
|
||||
}
|
||||
}
|
||||
if (length(x) != 1 & length(x) != length(ratio)) {
|
||||
stop('`x` and `ratio` must be of same size.')
|
||||
}
|
||||
sum(x, na.rm = TRUE) * (ratio / sum(ratio, na.rm = TRUE))
|
||||
}
|
||||
|
||||
#' @rdname AMR-deprecated
|
||||
#' @export
|
||||
abname <- function(...) {
|
||||
.Deprecated("ab_name", package = "AMR")
|
||||
ab_name(...)
|
||||
}
|
||||
|
||||
#' @rdname AMR-deprecated
|
||||
#' @export
|
||||
atc_property <- function(...) {
|
||||
.Deprecated("ab_property", package = "AMR")
|
||||
ab_property(...)
|
||||
}
|
||||
|
||||
#' @rdname AMR-deprecated
|
||||
#' @export
|
||||
atc_official <- function(...) {
|
||||
.Deprecated("ab_name", package = "AMR")
|
||||
ab_name(...)
|
||||
}
|
||||
|
||||
#' @rdname AMR-deprecated
|
||||
#' @export
|
||||
ab_official <- function(...) {
|
||||
.Deprecated("ab_name", package = "AMR")
|
||||
ab_name(...)
|
||||
}
|
||||
|
||||
#' @rdname AMR-deprecated
|
||||
#' @export
|
||||
atc_name <- function(...) {
|
||||
.Deprecated("ab_name", package = "AMR")
|
||||
ab_name(...)
|
||||
}
|
||||
|
||||
#' @rdname AMR-deprecated
|
||||
#' @export
|
||||
atc_trivial_nl <- function(...) {
|
||||
.Deprecated("ab_name", package = "AMR")
|
||||
ab_name(..., language = "nl")
|
||||
}
|
||||
|
||||
#' @rdname AMR-deprecated
|
||||
#' @export
|
||||
atc_tradenames <- function(...) {
|
||||
.Deprecated("ab_tradenames", package = "AMR")
|
||||
ab_tradenames(...)
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
# ==================================================================== #
|
||||
# TITLE #
|
||||
# Antimicrobial Resistance (AMR) Analysis #
|
||||
# #
|
||||
# SOURCE #
|
||||
# https://gitlab.com/msberends/AMR #
|
||||
# #
|
||||
# LICENCE #
|
||||
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
|
||||
# #
|
||||
# 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. #
|
||||
# #
|
||||
# This R package was created for academic research and was publicly #
|
||||
# released in the hope that it will be useful, but it comes WITHOUT #
|
||||
# ANY WARRANTY OR LIABILITY. #
|
||||
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
||||
# ==================================================================== #
|
||||
|
||||
#' Class 'disk'
|
||||
#'
|
||||
#' This transforms a vector to a new class \code{disk}, which is a growth zone size (around an antibiotic disk) in millimeters between 6 and 99.
|
||||
#' @rdname as.disk
|
||||
#' @param x vector
|
||||
#' @param na.rm a logical indicating whether missing values should be removed
|
||||
#' @details Interpret disk values as RSI values with \code{\link{as.rsi}}. It supports guidelines from EUCAST and CLSI.
|
||||
#' @return Ordered integer factor with new class \code{disk}
|
||||
#' @keywords disk
|
||||
#' @export
|
||||
#' @seealso \code{\link{as.rsi}}
|
||||
#' @inheritSection AMR Read more on our website!
|
||||
#' @examples
|
||||
#' # interpret disk values
|
||||
#' as.rsi(x = 12,
|
||||
#' mo = as.mo("S. pneumoniae"),
|
||||
#' ab = "AMX",
|
||||
#' guideline = "EUCAST")
|
||||
#' as.rsi(x = 12,
|
||||
#' mo = as.mo("S. pneumoniae"),
|
||||
#' ab = "AMX",
|
||||
#' guideline = "CLSI")
|
||||
as.disk <- function(x, na.rm = FALSE) {
|
||||
if (is.disk(x)) {
|
||||
x
|
||||
} else {
|
||||
x <- x %>% unlist()
|
||||
if (na.rm == TRUE) {
|
||||
x <- x[!is.na(x)]
|
||||
}
|
||||
x.bak <- x
|
||||
|
||||
na_before <- length(x[is.na(x)])
|
||||
|
||||
# force it to be integer
|
||||
x <- suppressWarnings(as.integer(x))
|
||||
|
||||
# disks can never be less than 9 mm (size of a disk) or more than 50 mm
|
||||
x[x < 6 | x > 99] <- NA_integer_
|
||||
na_after <- length(x[is.na(x)])
|
||||
|
||||
if (na_before != na_after) {
|
||||
list_missing <- x.bak[is.na(x) & !is.na(x.bak)] %>%
|
||||
unique() %>%
|
||||
sort()
|
||||
list_missing <- paste0('"', list_missing , '"', collapse = ", ")
|
||||
warning(na_after - na_before, ' results truncated (',
|
||||
round(((na_after - na_before) / length(x)) * 100),
|
||||
'%) that were invalid disk zones: ',
|
||||
list_missing, call. = FALSE)
|
||||
}
|
||||
|
||||
class(x) <- c('disk', 'integer')
|
||||
x
|
||||
}
|
||||
}
|
||||
|
||||
#' @rdname as.disk
|
||||
#' @export
|
||||
#' @importFrom dplyr %>%
|
||||
is.disk <- function(x) {
|
||||
class(x) %>% identical(c('disk', 'integer'))
|
||||
}
|
||||
|
||||
#' @exportMethod print.disk
|
||||
#' @export
|
||||
#' @noRd
|
||||
print.disk <- function(x, ...) {
|
||||
cat("Class 'disk'\n")
|
||||
print(as.integer(x), quote = FALSE)
|
||||
}
|
||||
@@ -1,750 +0,0 @@
|
||||
# ==================================================================== #
|
||||
# TITLE #
|
||||
# Antimicrobial Resistance (AMR) Analysis #
|
||||
# #
|
||||
# SOURCE #
|
||||
# https://gitlab.com/msberends/AMR #
|
||||
# #
|
||||
# LICENCE #
|
||||
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
|
||||
# #
|
||||
# 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. #
|
||||
# #
|
||||
# This R package was created for academic research and was publicly #
|
||||
# released in the hope that it will be useful, but it comes WITHOUT #
|
||||
# ANY WARRANTY OR LIABILITY. #
|
||||
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
||||
# ==================================================================== #
|
||||
|
||||
# global variables
|
||||
EUCAST_VERSION_BREAKPOINTS <- "9.0, 2019"
|
||||
EUCAST_VERSION_EXPERT_RULES <- "3.1, 2016"
|
||||
|
||||
#' EUCAST rules
|
||||
#'
|
||||
#' Apply susceptibility rules as defined by the European Committee on Antimicrobial Susceptibility Testing (EUCAST, \url{http://eucast.org}), see \emph{Source}. This includes (1) expert rules, (2) intrinsic resistance and (3) inferred resistance as defined in their breakpoint tables.
|
||||
#' @param x data with antibiotic columns, like e.g. \code{AMX} and \code{AMC}
|
||||
#' @param info print progress
|
||||
#' @param rules a character vector that specifies which rules should be applied - one or more of \code{c("breakpoints", "expert", "other", "all")}
|
||||
#' @param verbose a logical to indicate whether extensive info should be returned as a \code{data.frame} with info about which rows and columns are effected. It runs all EUCAST rules, but will not be applied to an output - only an informative \code{data.frame} with changes will be returned as output.
|
||||
#' @param ... column name of an antibiotic, see section Antibiotics
|
||||
#' @inheritParams first_isolate
|
||||
#' @details
|
||||
#' \strong{Note:} This function does not translate MIC values to RSI values. Use \code{\link{as.rsi}} for that. \cr
|
||||
#' \strong{Note:} When ampicillin (AMP, J01CA01) is not available but amoxicillin (AMX, J01CA04) is, the latter will be used for all rules where there is a dependency on ampicillin. These drugs are interchangeable when it comes to expression of antimicrobial resistance.
|
||||
#'
|
||||
#' The file containing all EUCAST rules is located here: \url{https://gitlab.com/msberends/AMR/blob/master/data-raw/eucast_rules.tsv}.
|
||||
#'
|
||||
#' @section Antibiotics:
|
||||
#' To define antibiotics column names, leave as it is to determine it automatically with \code{\link{guess_ab_col}} or input a text (case-insensitive), or use \code{NULL} to skip a column (e.g. \code{TIC = NULL} to skip ticarcillin). Manually defined but non-existing columns will be skipped with a warning.
|
||||
#'
|
||||
#' The following antibiotics are used for the functions \code{\link{eucast_rules}} and \code{\link{mdro}}. These are shown in the format '\strong{antimicrobial ID}: name (\emph{ATC code})', sorted by name:
|
||||
#'
|
||||
#' \strong{AMK}: amikacin (\href{https://www.whocc.no/atc_ddd_index/?code=J01GB06}{J01GB06}),
|
||||
#' \strong{AMX}: amoxicillin (\href{https://www.whocc.no/atc_ddd_index/?code=J01CA04}{J01CA04}),
|
||||
#' \strong{AMC}: amoxicillin/clavulanic acid (\href{https://www.whocc.no/atc_ddd_index/?code=J01CR02}{J01CR02}),
|
||||
#' \strong{AMP}: ampicillin (\href{https://www.whocc.no/atc_ddd_index/?code=J01CA01}{J01CA01}),
|
||||
#' \strong{AZM}: azithromycin (\href{https://www.whocc.no/atc_ddd_index/?code=J01FA10}{J01FA10}),
|
||||
#' \strong{AZL}: azlocillin (\href{https://www.whocc.no/atc_ddd_index/?code=J01CA09}{J01CA09}),
|
||||
#' \strong{ATM}: aztreonam (\href{https://www.whocc.no/atc_ddd_index/?code=J01DF01}{J01DF01}),
|
||||
#' \strong{CAP}: capreomycin (\href{https://www.whocc.no/atc_ddd_index/?code=J04AB30}{J04AB30}),
|
||||
#' \strong{RID}: cefaloridine (\href{https://www.whocc.no/atc_ddd_index/?code=J01DB02}{J01DB02}),
|
||||
#' \strong{CZO}: cefazolin (\href{https://www.whocc.no/atc_ddd_index/?code=J01DB04}{J01DB04}),
|
||||
#' \strong{FEP}: cefepime (\href{https://www.whocc.no/atc_ddd_index/?code=J01DE01}{J01DE01}),
|
||||
#' \strong{CTX}: cefotaxime (\href{https://www.whocc.no/atc_ddd_index/?code=J01DD01}{J01DD01}),
|
||||
#' \strong{FOX}: cefoxitin (\href{https://www.whocc.no/atc_ddd_index/?code=J01DC01}{J01DC01}),
|
||||
#' \strong{CED}: cefradine (\href{https://www.whocc.no/atc_ddd_index/?code=J01DB09}{J01DB09}),
|
||||
#' \strong{CAZ}: ceftazidime (\href{https://www.whocc.no/atc_ddd_index/?code=J01DD02}{J01DD02}),
|
||||
#' \strong{CRO}: ceftriaxone (\href{https://www.whocc.no/atc_ddd_index/?code=J01DD04}{J01DD04}),
|
||||
#' \strong{CXM}: cefuroxime (\href{https://www.whocc.no/atc_ddd_index/?code=J01DC02}{J01DC02}),
|
||||
#' \strong{CHL}: chloramphenicol (\href{https://www.whocc.no/atc_ddd_index/?code=J01BA01}{J01BA01}),
|
||||
#' \strong{CIP}: ciprofloxacin (\href{https://www.whocc.no/atc_ddd_index/?code=J01MA02}{J01MA02}),
|
||||
#' \strong{CLR}: clarithromycin (\href{https://www.whocc.no/atc_ddd_index/?code=J01FA09}{J01FA09}),
|
||||
#' \strong{CLI}: clindamycin (\href{https://www.whocc.no/atc_ddd_index/?code=J01FF01}{J01FF01}),
|
||||
#' \strong{COL}: colistin (\href{https://www.whocc.no/atc_ddd_index/?code=J01XB01}{J01XB01}),
|
||||
#' \strong{DAP}: daptomycin (\href{https://www.whocc.no/atc_ddd_index/?code=J01XX09}{J01XX09}),
|
||||
#' \strong{DOX}: doxycycline (\href{https://www.whocc.no/atc_ddd_index/?code=J01AA02}{J01AA02}),
|
||||
#' \strong{ETP}: ertapenem (\href{https://www.whocc.no/atc_ddd_index/?code=J01DH03}{J01DH03}),
|
||||
#' \strong{ERY}: erythromycin (\href{https://www.whocc.no/atc_ddd_index/?code=J01FA01}{J01FA01}),
|
||||
#' \strong{ETH}: ethambutol (\href{https://www.whocc.no/atc_ddd_index/?code=J04AK02}{J04AK02}),
|
||||
#' \strong{FLC}: flucloxacillin (\href{https://www.whocc.no/atc_ddd_index/?code=J01CF05}{J01CF05}),
|
||||
#' \strong{FOS}: fosfomycin (\href{https://www.whocc.no/atc_ddd_index/?code=J01XX01}{J01XX01}),
|
||||
#' \strong{FUS}: fusidic acid (\href{https://www.whocc.no/atc_ddd_index/?code=J01XC01}{J01XC01}),
|
||||
#' \strong{GAT}: gatifloxacin (\href{https://www.whocc.no/atc_ddd_index/?code=J01MA16}{J01MA16}),
|
||||
#' \strong{GEN}: gentamicin (\href{https://www.whocc.no/atc_ddd_index/?code=J01GB03}{J01GB03}),
|
||||
#' \strong{IPM}: imipenem (\href{https://www.whocc.no/atc_ddd_index/?code=J01DH51}{J01DH51}),
|
||||
#' \strong{INH}: isoniazid (\href{https://www.whocc.no/atc_ddd_index/?code=J04AC01}{J04AC01}),
|
||||
#' \strong{KAN}: kanamycin (\href{https://www.whocc.no/atc_ddd_index/?code=J01GB04}{J01GB04}),
|
||||
#' \strong{LVX}: levofloxacin (\href{https://www.whocc.no/atc_ddd_index/?code=J01MA12}{J01MA12}),
|
||||
#' \strong{LIN}: lincomycin (\href{https://www.whocc.no/atc_ddd_index/?code=J01FF02}{J01FF02}),
|
||||
#' \strong{LNZ}: linezolid (\href{https://www.whocc.no/atc_ddd_index/?code=J01XX08}{J01XX08}),
|
||||
#' \strong{MEM}: meropenem (\href{https://www.whocc.no/atc_ddd_index/?code=J01DH02}{J01DH02}),
|
||||
#' \strong{MTR}: metronidazole (\href{https://www.whocc.no/atc_ddd_index/?code=J01XD01}{J01XD01}),
|
||||
#' \strong{MEZ}: mezlocillin (\href{https://www.whocc.no/atc_ddd_index/?code=J01CA10}{J01CA10}),
|
||||
#' \strong{MNO}: minocycline (\href{https://www.whocc.no/atc_ddd_index/?code=J01AA08}{J01AA08}),
|
||||
#' \strong{MFX}: moxifloxacin (\href{https://www.whocc.no/atc_ddd_index/?code=J01MA14}{J01MA14}),
|
||||
#' \strong{NAL}: nalidixic acid (\href{https://www.whocc.no/atc_ddd_index/?code=J01MB02}{J01MB02}),
|
||||
#' \strong{NEO}: neomycin (\href{https://www.whocc.no/atc_ddd_index/?code=J01GB05}{J01GB05}),
|
||||
#' \strong{NET}: netilmicin (\href{https://www.whocc.no/atc_ddd_index/?code=J01GB07}{J01GB07}),
|
||||
#' \strong{NIT}: nitrofurantoin (\href{https://www.whocc.no/atc_ddd_index/?code=J01XE01}{J01XE01}),
|
||||
#' \strong{NOR}: norfloxacin (\href{https://www.whocc.no/atc_ddd_index/?code=J01MA06}{J01MA06}),
|
||||
#' \strong{NOV}: novobiocin (an ATCvet code: \href{https://www.whocc.no/atc_ddd_index/?code=QJ01XX95}{QJ01XX95}),
|
||||
#' \strong{OFX}: ofloxacin (\href{https://www.whocc.no/atc_ddd_index/?code=J01MA01}{J01MA01}),
|
||||
#' \strong{OXA}: oxacillin (\href{https://www.whocc.no/atc_ddd_index/?code=J01CF04}{J01CF04}),
|
||||
#' \strong{PEN}: penicillin G (\href{https://www.whocc.no/atc_ddd_index/?code=J01CE01}{J01CE01}),
|
||||
#' \strong{PIP}: piperacillin (\href{https://www.whocc.no/atc_ddd_index/?code=J01CA12}{J01CA12}),
|
||||
#' \strong{TZP}: piperacillin/tazobactam (\href{https://www.whocc.no/atc_ddd_index/?code=J01CR05}{J01CR05}),
|
||||
#' \strong{PLB}: polymyxin B (\href{https://www.whocc.no/atc_ddd_index/?code=J01XB02}{J01XB02}),
|
||||
#' \strong{PRI}: pristinamycin (\href{https://www.whocc.no/atc_ddd_index/?code=J01FG01}{J01FG01}),
|
||||
#' \strong{PZA}: pyrazinamide (\href{https://www.whocc.no/atc_ddd_index/?code=J04AK01}{J04AK01}),
|
||||
#' \strong{QDA}: quinupristin/dalfopristin (\href{https://www.whocc.no/atc_ddd_index/?code=J01FG02}{J01FG02}),
|
||||
#' \strong{RIB}: rifabutin (\href{https://www.whocc.no/atc_ddd_index/?code=J04AB04}{J04AB04}),
|
||||
#' \strong{RIF}: rifampicin (\href{https://www.whocc.no/atc_ddd_index/?code=J04AB02}{J04AB02}),
|
||||
#' \strong{RIF}: rifampin (\href{https://www.whocc.no/atc_ddd_index/?code=J04AB02}{J04AB02}),
|
||||
#' \strong{RFP}: rifapentine (\href{https://www.whocc.no/atc_ddd_index/?code=J04AB05}{J04AB05}),
|
||||
#' \strong{RXT}: roxithromycin (\href{https://www.whocc.no/atc_ddd_index/?code=J01FA06}{J01FA06}),
|
||||
#' \strong{SIS}: sisomicin (\href{https://www.whocc.no/atc_ddd_index/?code=J01GB08}{J01GB08}),
|
||||
#' \strong{TEC}: teicoplanin (\href{https://www.whocc.no/atc_ddd_index/?code=J01XA02}{J01XA02}),
|
||||
#' \strong{TCY}: tetracycline (\href{https://www.whocc.no/atc_ddd_index/?code=J01AA07}{J01AA07}),
|
||||
#' \strong{TIC}: ticarcillin (\href{https://www.whocc.no/atc_ddd_index/?code=J01CA13}{J01CA13}),
|
||||
#' \strong{TGC}: tigecycline (\href{https://www.whocc.no/atc_ddd_index/?code=J01AA12}{J01AA12}),
|
||||
#' \strong{TOB}: tobramycin (\href{https://www.whocc.no/atc_ddd_index/?code=J01GB01}{J01GB01}),
|
||||
#' \strong{TMP}: trimethoprim (\href{https://www.whocc.no/atc_ddd_index/?code=J01EA01}{J01EA01}),
|
||||
#' \strong{SXT}: trimethoprim/sulfamethoxazole (\href{https://www.whocc.no/atc_ddd_index/?code=J01EE01}{J01EE01}),
|
||||
#' \strong{VAN}: vancomycin (\href{https://www.whocc.no/atc_ddd_index/?code=J01XA01}{J01XA01}).
|
||||
#' @keywords interpretive eucast reading resistance
|
||||
#' @rdname eucast_rules
|
||||
#' @export
|
||||
#' @importFrom dplyr %>% select pull mutate_at vars group_by summarise n
|
||||
#' @importFrom crayon bold bgGreen bgYellow bgRed black green blue italic strip_style white
|
||||
#' @return The input of \code{x}, possibly with edited values of antibiotics. Or, if \code{verbose = TRUE}, a \code{data.frame} with all original and new values of the affected bug-drug combinations.
|
||||
#' @source
|
||||
#' \itemize{
|
||||
#' \item{
|
||||
#' EUCAST Expert Rules. Version 2.0, 2012. \cr
|
||||
#' Leclercq et al. \strong{EUCAST expert rules in antimicrobial susceptibility testing.} \emph{Clin Microbiol Infect.} 2013;19(2):141-60. \cr
|
||||
#' \url{https://doi.org/10.1111/j.1469-0691.2011.03703.x}
|
||||
#' }
|
||||
#' \item{
|
||||
#' EUCAST Expert Rules, Intrinsic Resistance and Exceptional Phenotypes Tables. Version 3.1, 2016. \cr
|
||||
#' \url{http://www.eucast.org/fileadmin/src/media/PDFs/EUCAST_files/Expert_Rules/Expert_rules_intrinsic_exceptional_V3.1.pdf}
|
||||
#' }
|
||||
#' \item{
|
||||
#' EUCAST Breakpoint tables for interpretation of MICs and zone diameters. Version 9.0, 2019. \cr
|
||||
#' \url{http://www.eucast.org/fileadmin/src/media/PDFs/EUCAST_files/Breakpoint_tables/v_9.0_Breakpoint_Tables.xlsx}
|
||||
#' }
|
||||
#' }
|
||||
#' @inheritSection AMR Read more on our website!
|
||||
#' @examples
|
||||
#' a <- eucast_rules(septic_patients)
|
||||
#'
|
||||
#' a <- data.frame(mo = c("Staphylococcus aureus",
|
||||
#' "Enterococcus faecalis",
|
||||
#' "Escherichia coli",
|
||||
#' "Klebsiella pneumoniae",
|
||||
#' "Pseudomonas aeruginosa"),
|
||||
#' VAN = "-", # Vancomycin
|
||||
#' AMX = "-", # Amoxicillin
|
||||
#' COL = "-", # Colistin
|
||||
#' CAZ = "-", # Ceftazidime
|
||||
#' CXM = "-", # Cefuroxime
|
||||
#' PEN = "S", # Penicillin G
|
||||
#' FOX = "S", # Cefoxitin
|
||||
#' stringsAsFactors = FALSE)
|
||||
#'
|
||||
#' a
|
||||
#' # mo VAN AMX COL CAZ CXM PEN FOX
|
||||
#' # 1 Staphylococcus aureus - - - - - S S
|
||||
#' # 2 Enterococcus faecalis - - - - - S S
|
||||
#' # 3 Escherichia coli - - - - - S S
|
||||
#' # 4 Klebsiella pneumoniae - - - - - S S
|
||||
#' # 5 Pseudomonas aeruginosa - - - - - S S
|
||||
#'
|
||||
#'
|
||||
#' # apply EUCAST rules: 18 results are forced as R or S
|
||||
#' b <- eucast_rules(a)
|
||||
#'
|
||||
#' b
|
||||
#' # mo VAN AMX COL CAZ CXM PEN FOX
|
||||
#' # 1 Staphylococcus aureus - S R R S S S
|
||||
#' # 2 Enterococcus faecalis - - R R R S R
|
||||
#' # 3 Escherichia coli R - - - - R S
|
||||
#' # 4 Klebsiella pneumoniae R R - - - R S
|
||||
#' # 5 Pseudomonas aeruginosa R R - - R R R
|
||||
#'
|
||||
#'
|
||||
#' # do not apply EUCAST rules, but rather get a a data.frame
|
||||
#' # with 18 rows, containing all details about the transformations:
|
||||
#' c <- eucast_rules(a, verbose = TRUE)
|
||||
eucast_rules <- function(x,
|
||||
col_mo = NULL,
|
||||
info = TRUE,
|
||||
rules = c("breakpoints", "expert", "other", "all"),
|
||||
verbose = FALSE,
|
||||
...) {
|
||||
|
||||
x <- x
|
||||
|
||||
if (!is.data.frame(x)) {
|
||||
stop("`x` must be a data frame.", call. = FALSE)
|
||||
}
|
||||
|
||||
# try to find columns based on type
|
||||
# -- mo
|
||||
if (is.null(col_mo)) {
|
||||
col_mo <- search_type_in_df(x = x, type = "mo")
|
||||
}
|
||||
if (is.null(col_mo)) {
|
||||
stop("`col_mo` must be set.", call. = FALSE)
|
||||
}
|
||||
|
||||
if (!all(rules %in% c("breakpoints", "expert", "other", "all"))) {
|
||||
stop("`rules` must be one or more of: 'breakpoints', 'expert', 'other', 'all'.")
|
||||
}
|
||||
|
||||
if (is.null(col_mo)) {
|
||||
stop("`col_mo` must be set")
|
||||
}
|
||||
|
||||
warned <- FALSE
|
||||
|
||||
txt_error <- function() { cat("", bgRed(white(" ERROR ")), "\n") }
|
||||
txt_warning <- function() { if (warned == FALSE) { cat("", bgYellow(black(" WARNING ")), "\n") }; warned <<- TRUE }
|
||||
txt_ok <- function(no_of_changes) {
|
||||
if (warned == FALSE) {
|
||||
if (no_of_changes > 0) {
|
||||
if (no_of_changes == 1) {
|
||||
cat(blue(" (1 new change)\n"))
|
||||
} else {
|
||||
cat(blue(paste0(" (", no_of_changes, " new changes)\n")))
|
||||
}
|
||||
} else {
|
||||
cat(green(" (no new changes)\n"))
|
||||
}
|
||||
warned <<- FALSE
|
||||
}
|
||||
}
|
||||
|
||||
cols_ab <- get_column_abx(x = x,
|
||||
soft_dependencies = c("AMC",
|
||||
"AMK",
|
||||
"AMX",
|
||||
"AMP",
|
||||
"AZM",
|
||||
"AZL",
|
||||
"ATM",
|
||||
"RID",
|
||||
"FEP",
|
||||
"CTX",
|
||||
"FOX",
|
||||
"CED",
|
||||
"CAZ",
|
||||
"CRO",
|
||||
"CXM",
|
||||
"CHL",
|
||||
"CIP",
|
||||
"CLR",
|
||||
"CLI",
|
||||
"FLC",
|
||||
"COL",
|
||||
"CZO",
|
||||
"DAP",
|
||||
"DOX",
|
||||
"ETP",
|
||||
"ERY",
|
||||
"FOS",
|
||||
"FUS",
|
||||
"GEN",
|
||||
"IPM",
|
||||
"KAN",
|
||||
"LVX",
|
||||
"LIN",
|
||||
"LNZ",
|
||||
"MEM",
|
||||
"MEZ",
|
||||
"MNO",
|
||||
"MFX",
|
||||
"NAL",
|
||||
"NEO",
|
||||
"NET",
|
||||
"NIT",
|
||||
"NOR",
|
||||
"NOV",
|
||||
"OFX",
|
||||
"OXA",
|
||||
"PEN",
|
||||
"PIP",
|
||||
"TZP",
|
||||
"PLB",
|
||||
"PRI",
|
||||
"QDA",
|
||||
"RIF",
|
||||
"RXT",
|
||||
"SIS",
|
||||
"TEC",
|
||||
"TCY",
|
||||
"TIC",
|
||||
"TGC",
|
||||
"TOB",
|
||||
"TMP",
|
||||
"SXT",
|
||||
"VAN"),
|
||||
hard_dependencies = NULL,
|
||||
verbose = verbose,
|
||||
...)
|
||||
|
||||
AMC <- cols_ab['AMC']
|
||||
AMK <- cols_ab['AMK']
|
||||
AMP <- cols_ab['AMP']
|
||||
AMX <- cols_ab['AMX']
|
||||
ATM <- cols_ab['ATM']
|
||||
AZL <- cols_ab['AZL']
|
||||
AZM <- cols_ab['AZM']
|
||||
CAZ <- cols_ab['CAZ']
|
||||
CED <- cols_ab['CED']
|
||||
CHL <- cols_ab['CHL']
|
||||
CIP <- cols_ab['CIP']
|
||||
CLI <- cols_ab['CLI']
|
||||
CLR <- cols_ab['CLR']
|
||||
COL <- cols_ab['COL']
|
||||
CRO <- cols_ab['CRO']
|
||||
CTX <- cols_ab['CTX']
|
||||
CXM <- cols_ab['CXM']
|
||||
CZO <- cols_ab['CZO']
|
||||
DAP <- cols_ab['DAP']
|
||||
DOX <- cols_ab['DOX']
|
||||
ERY <- cols_ab['ERY']
|
||||
ETP <- cols_ab['ETP']
|
||||
FEP <- cols_ab['FEP']
|
||||
FLC <- cols_ab['FLC']
|
||||
FOS <- cols_ab['FOS']
|
||||
FOX <- cols_ab['FOX']
|
||||
FUS <- cols_ab['FUS']
|
||||
GEN <- cols_ab['GEN']
|
||||
IPM <- cols_ab['IPM']
|
||||
KAN <- cols_ab['KAN']
|
||||
LIN <- cols_ab['LIN']
|
||||
LNZ <- cols_ab['LNZ']
|
||||
LVX <- cols_ab['LVX']
|
||||
MEM <- cols_ab['MEM']
|
||||
MEZ <- cols_ab['MEZ']
|
||||
MFX <- cols_ab['MFX']
|
||||
MNO <- cols_ab['MNO']
|
||||
NAL <- cols_ab['NAL']
|
||||
NEO <- cols_ab['NEO']
|
||||
NET <- cols_ab['NET']
|
||||
NIT <- cols_ab['NIT']
|
||||
NOR <- cols_ab['NOR']
|
||||
NOV <- cols_ab['NOV']
|
||||
OFX <- cols_ab['OFX']
|
||||
OXA <- cols_ab['OXA']
|
||||
PEN <- cols_ab['PEN']
|
||||
PIP <- cols_ab['PIP']
|
||||
PLB <- cols_ab['PLB']
|
||||
PRI <- cols_ab['PRI']
|
||||
QDA <- cols_ab['QDA']
|
||||
RID <- cols_ab['RID']
|
||||
RIF <- cols_ab['RIF']
|
||||
RXT <- cols_ab['RXT']
|
||||
SIS <- cols_ab['SIS']
|
||||
SXT <- cols_ab['SXT']
|
||||
TCY <- cols_ab['TCY']
|
||||
TEC <- cols_ab['TEC']
|
||||
TGC <- cols_ab['TGC']
|
||||
TIC <- cols_ab['TIC']
|
||||
TMP <- cols_ab['TMP']
|
||||
TOB <- cols_ab['TOB']
|
||||
TZP <- cols_ab['TZP']
|
||||
VAN <- cols_ab['VAN']
|
||||
|
||||
ab_missing <- function(ab) {
|
||||
all(ab %in% c(NULL, NA))
|
||||
}
|
||||
|
||||
verbose_info <- data.frame(row = integer(0),
|
||||
col = character(0),
|
||||
mo_fullname = character(0),
|
||||
old = character(0),
|
||||
new = character(0),
|
||||
rule = character(0),
|
||||
rule_group = character(0),
|
||||
rule_name = character(0),
|
||||
stringsAsFactors = FALSE)
|
||||
|
||||
# helper function for editing the table
|
||||
edit_rsi <- function(to, rule, rows, cols) {
|
||||
cols <- unique(cols[!is.na(cols) & !is.null(cols)])
|
||||
if (length(rows) > 0 & length(cols) > 0) {
|
||||
before_df <- x_original
|
||||
before <- as.character(unlist(as.list(x_original[rows, cols])))
|
||||
|
||||
tryCatch(
|
||||
# insert into original table
|
||||
x_original[rows, cols] <<- to,
|
||||
warning = function(w) {
|
||||
if (w$message %like% 'invalid factor level') {
|
||||
warning('Value "', to, '" could not be applied to column(s) `', paste(cols, collapse = '`, `'), '` because this value is not an existing factor level.', call. = FALSE)
|
||||
} else {
|
||||
warning(w$message, call. = FALSE)
|
||||
}
|
||||
txt_warning()
|
||||
},
|
||||
error = function(e) {
|
||||
txt_error()
|
||||
stop(e, call. = FALSE)
|
||||
}
|
||||
)
|
||||
|
||||
x[rows, cols] <<- x_original[rows, cols]
|
||||
|
||||
after <- as.character(unlist(as.list(x_original[rows, cols])))
|
||||
|
||||
# before_df might not be a data.frame, but a tibble of data.table instead
|
||||
old <- as.data.frame(before_df, stringsAsFactors = FALSE)[rows,]
|
||||
no_of_changes_this_run <- 0
|
||||
for (i in 1:length(cols)) {
|
||||
verbose_new <- data.frame(row = rows,
|
||||
col = cols[i],
|
||||
mo_fullname = x[rows, "fullname"],
|
||||
old = as.character(old[, cols[i]]),
|
||||
new = as.character(x[rows, cols[i]]),
|
||||
rule = strip_style(rule[1]),
|
||||
rule_group = strip_style(rule[2]),
|
||||
rule_name = strip_style(rule[3]),
|
||||
stringsAsFactors = FALSE)
|
||||
colnames(verbose_new) <- c("row", "col", "mo_fullname", "old", "new", "rule", "rule_group", "rule_name")
|
||||
verbose_new <- verbose_new %>% filter(old != new | is.na(old))
|
||||
verbose_info <<- rbind(verbose_info, verbose_new)
|
||||
no_of_changes_this_run <- no_of_changes_this_run + nrow(verbose_new)
|
||||
}
|
||||
# return number of (new) changes
|
||||
return(no_of_changes_this_run)
|
||||
}
|
||||
# return number of (new) changes: none.
|
||||
return(0)
|
||||
}
|
||||
|
||||
# save original table
|
||||
x_original <- x
|
||||
|
||||
# join to microorganisms data set
|
||||
suppressWarnings(
|
||||
x <- x %>%
|
||||
mutate_at(vars(col_mo), as.mo) %>%
|
||||
left_join_microorganisms(by = col_mo, suffix = c("_oldcols", "")) %>%
|
||||
mutate(gramstain = mo_gramstain(pull(., col_mo), language = "en"),
|
||||
genus_species = paste(genus, species)) %>%
|
||||
as.data.frame(stringsAsFactors = FALSE)
|
||||
)
|
||||
|
||||
if (info == TRUE) {
|
||||
cat(paste0(
|
||||
"\nRules by the ", bold("European Committee on Antimicrobial Susceptibility Testing (EUCAST)"),
|
||||
"\n", blue("http://eucast.org/"), "\n"))
|
||||
}
|
||||
|
||||
# since ampicillin ^= amoxicillin, get the first from the latter (not in original EUCAST table)
|
||||
if (!ab_missing(AMP) & !ab_missing(AMX)) {
|
||||
if (verbose == TRUE) {
|
||||
cat("\n VERBOSE: transforming",
|
||||
length(which(x[, AMX] == "S" & !x[, AMP] %in% c("S", "I", "R"))),
|
||||
"empty ampicillin fields to 'S' based on amoxicillin. ")
|
||||
cat("\n VERBOSE: transforming",
|
||||
length(which(x[, AMX] == "I" & !x[, AMP] %in% c("S", "I", "R"))),
|
||||
"empty ampicillin fields to 'I' based on amoxicillin. ")
|
||||
cat("\n VERBOSE: transforming",
|
||||
length(which(x[, AMX] == "R" & !x[, AMP] %in% c("S", "I", "R"))),
|
||||
"empty ampicillin fields to 'R' based on amoxicillin. \n")
|
||||
}
|
||||
x[which(x[, AMX] == "S" & !x[, AMP] %in% c("S", "I", "R")), AMP] <- "S"
|
||||
x[which(x[, AMX] == "I" & !x[, AMP] %in% c("S", "I", "R")), AMP] <- "I"
|
||||
x[which(x[, AMX] == "R" & !x[, AMP] %in% c("S", "I", "R")), AMP] <- "R"
|
||||
} else if (ab_missing(AMP) & !ab_missing(AMX)) {
|
||||
# ampicillin column is missing, but amoxicillin is available
|
||||
message(blue(paste0("NOTE: Using column `", bold(AMX), "` as input for ampicillin (J01CA01) since many EUCAST rules depend on it.")))
|
||||
AMP <- AMX
|
||||
}
|
||||
|
||||
# antibiotic classes
|
||||
aminoglycosides <- c(TOB, GEN, KAN, NEO, NET, SIS)
|
||||
tetracyclines <- c(DOX, MNO, TCY) # since EUCAST v3.1 tigecycline (TGC) is set apart
|
||||
polymyxins <- c(PLB, COL)
|
||||
macrolides <- c(ERY, AZM, RXT, CLR) # since EUCAST v3.1 clinda is set apart
|
||||
glycopeptides <- c(VAN, TEC)
|
||||
streptogramins <- c(QDA, PRI) # should officially also be quinupristin/dalfopristin
|
||||
aminopenicillins <- c(AMP, AMX)
|
||||
cephalosporins <- c(FEP, CTX, FOX, CED, CAZ, CRO, CXM, CZO)
|
||||
cephalosporins_without_CAZ <- cephalosporins[cephalosporins != ifelse(is.null(CAZ), "", CAZ)]
|
||||
carbapenems <- c(ETP, IPM, MEM)
|
||||
ureidopenicillins <- c(PIP, TZP, AZL, MEZ)
|
||||
all_betalactams <- c(aminopenicillins, cephalosporins, carbapenems, ureidopenicillins, AMC, OXA, FLC, PEN)
|
||||
fluoroquinolones <- c(OFX, CIP, NOR, LVX, MFX)
|
||||
|
||||
# Help function to get available antibiotic column names ------------------
|
||||
get_antibiotic_columns <- function(x, df) {
|
||||
x <- trimws(unlist(strsplit(x, ",", fixed = TRUE)))
|
||||
y <- character(0)
|
||||
for (i in 1:length(x)) {
|
||||
y <- c(y, tryCatch(get(x[i]), error = function(e) ""))
|
||||
}
|
||||
y[y != "" & y %in% colnames(df)]
|
||||
}
|
||||
|
||||
eucast_rules_df <- eucast_rules_file # internal data file
|
||||
no_of_changes <- 0
|
||||
for (i in 1:nrow(eucast_rules_df)) {
|
||||
|
||||
rule_previous <- eucast_rules_df[max(1, i - 1), "reference.rule"]
|
||||
rule_current <- eucast_rules_df[i, "reference.rule"]
|
||||
rule_next <- eucast_rules_df[min(nrow(eucast_rules_df), i + 1), "reference.rule"]
|
||||
rule_group_previous <- eucast_rules_df[max(1, i - 1), "reference.rule_group"]
|
||||
rule_group_current <- eucast_rules_df[i, "reference.rule_group"]
|
||||
rule_group_next <- eucast_rules_df[min(nrow(eucast_rules_df), i + 1), "reference.rule_group"]
|
||||
if (is.na(eucast_rules_df[i, 4])) {
|
||||
rule_text <- paste("always:", eucast_rules_df[i, 6], "=", eucast_rules_df[i, 7])
|
||||
} else {
|
||||
rule_text <- paste("if", eucast_rules_df[i, 4], "=", eucast_rules_df[i, 5],
|
||||
"then", eucast_rules_df[i, 6], "=", eucast_rules_df[i, 7])
|
||||
}
|
||||
if (i == 1) {
|
||||
rule_previous <- ""
|
||||
rule_group_previous <- ""
|
||||
}
|
||||
if (i == nrow(eucast_rules_df)) {
|
||||
rule_next <- ""
|
||||
rule_group_next <- ""
|
||||
}
|
||||
|
||||
# don't apply rules if user doesn't want to apply them
|
||||
if (rule_group_current %like% "breakpoint" & !any(c("all", "breakpoints") %in% rules)) {
|
||||
next
|
||||
}
|
||||
if (rule_group_current %like% "expert" & !any(c("all", "expert") %in% rules)) {
|
||||
next
|
||||
}
|
||||
if (rule_group_current %like% "other" & !any(c("all", "other") %in% rules)) {
|
||||
next
|
||||
}
|
||||
|
||||
|
||||
if (info == TRUE) {
|
||||
# Print rule (group) ------------------------------------------------------
|
||||
if (rule_group_current != rule_group_previous) {
|
||||
# is new rule group, one of Breakpoints, Expert Rules and Other
|
||||
cat(bold(
|
||||
case_when(
|
||||
rule_group_current %like% "breakpoint" ~
|
||||
paste0("\nEUCAST Clinical Breakpoints (v", EUCAST_VERSION_BREAKPOINTS, ")\n"),
|
||||
rule_group_current %like% "expert" ~
|
||||
paste0("\nEUCAST Expert Rules, Intrinsic Resistance and Exceptional Phenotypes (v", EUCAST_VERSION_EXPERT_RULES, ")\n"),
|
||||
TRUE ~
|
||||
"\nOther rules\n"
|
||||
)
|
||||
))
|
||||
}
|
||||
# Print rule -------------------------------------------------------------
|
||||
if (rule_current != rule_previous) {
|
||||
# is new rule within group, print its name
|
||||
if (rule_current %in% c(AMR::microorganisms$family,
|
||||
AMR::microorganisms$fullname)) {
|
||||
cat(italic(rule_current))
|
||||
} else {
|
||||
cat(rule_current)
|
||||
}
|
||||
warned <- FALSE
|
||||
}
|
||||
}
|
||||
|
||||
# Get rule from file ------------------------------------------------------
|
||||
col_mo_property <- eucast_rules_df[i, 1]
|
||||
like_is_one_of <- eucast_rules_df[i, 2]
|
||||
|
||||
# be sure to comprise all coagulase-negative/-positive Staphylococci when they are mentioned
|
||||
if (eucast_rules_df[i, 3] %like% "coagulase-") {
|
||||
suppressWarnings(
|
||||
all_staph <- AMR::microorganisms %>%
|
||||
filter(genus == "Staphylococcus") %>%
|
||||
mutate(CNS_CPS = mo_fullname(mo, Becker = "all"))
|
||||
)
|
||||
if (eucast_rules_df[i, 3] %like% "coagulase-") {
|
||||
eucast_rules_df[i, 3] <- paste0("^(",
|
||||
paste0(all_staph %>%
|
||||
filter(CNS_CPS %like% "coagulase-negative") %>%
|
||||
pull(fullname),
|
||||
collapse = "|"),
|
||||
")$")
|
||||
} else {
|
||||
eucast_rules_df[i, 3] <- paste0("^(",
|
||||
paste0(all_staph %>%
|
||||
filter(CNS_CPS %like% "coagulase-positive") %>%
|
||||
pull(fullname),
|
||||
collapse = "|"),
|
||||
")$")
|
||||
}
|
||||
like_is_one_of <- "like"
|
||||
}
|
||||
|
||||
if (like_is_one_of == "is") {
|
||||
mo_value <- paste0("^", eucast_rules_df[i, 3], "$")
|
||||
} else if (like_is_one_of == "one_of") {
|
||||
# "Clostridium, Actinomyces, ..." -> "^(Clostridium|Actinomyces|...)$"
|
||||
mo_value <- paste0("^(",
|
||||
paste(trimws(unlist(strsplit(eucast_rules_df[i, 3], ",", fixed = TRUE))),
|
||||
collapse = "|"),
|
||||
")$")
|
||||
} else if (like_is_one_of == "like") {
|
||||
mo_value <- eucast_rules_df[i, 3]
|
||||
} else {
|
||||
stop("invalid like_is_one_of", call. = FALSE)
|
||||
}
|
||||
|
||||
source_antibiotics <- eucast_rules_df[i, 4]
|
||||
source_value <- trimws(unlist(strsplit(eucast_rules_df[i, 5], ",", fixed = TRUE)))
|
||||
target_antibiotics <- eucast_rules_df[i, 6]
|
||||
target_value <- eucast_rules_df[i, 7]
|
||||
|
||||
if (is.na(source_antibiotics)) {
|
||||
rows <- tryCatch(which(x[, col_mo_property] %like% mo_value),
|
||||
error = function(e) integer(0))
|
||||
} else {
|
||||
source_antibiotics <- get_antibiotic_columns(source_antibiotics, x)
|
||||
if (length(source_value) == 1 & length(source_antibiotics) > 1) {
|
||||
source_value <- rep(source_value, length(source_antibiotics))
|
||||
}
|
||||
if (length(source_antibiotics) == 0) {
|
||||
rows <- integer(0)
|
||||
} else if (length(source_antibiotics) == 1) {
|
||||
rows <- tryCatch(which(x[, col_mo_property] %like% mo_value
|
||||
& x[, source_antibiotics[1L]] == source_value[1L]),
|
||||
error = function(e) integer(0))
|
||||
} else if (length(source_antibiotics) == 2) {
|
||||
rows <- tryCatch(which(x[, col_mo_property] %like% mo_value
|
||||
& x[, source_antibiotics[1L]] == source_value[1L]
|
||||
& x[, source_antibiotics[2L]] == source_value[2L]),
|
||||
error = function(e) integer(0))
|
||||
} else if (length(source_antibiotics) == 3) {
|
||||
rows <- tryCatch(which(x[, col_mo_property] %like% mo_value
|
||||
& x[, source_antibiotics[1L]] == source_value[1L]
|
||||
& x[, source_antibiotics[2L]] == source_value[2L]
|
||||
& x[, source_antibiotics[3L]] == source_value[3L]),
|
||||
error = function(e) integer(0))
|
||||
} else {
|
||||
stop("only 3 antibiotics supported for source_antibiotics ", call. = FALSE)
|
||||
}
|
||||
}
|
||||
|
||||
cols <- get_antibiotic_columns(target_antibiotics, x)
|
||||
|
||||
# Apply rule on data ------------------------------------------------------
|
||||
# this will return the unique number of changes
|
||||
no_of_changes <- no_of_changes + edit_rsi(to = target_value,
|
||||
rule = c(rule_text, rule_group_current, rule_current),
|
||||
rows = rows,
|
||||
cols = cols)
|
||||
|
||||
# Print number of new changes ---------------------------------------------
|
||||
if (info == TRUE & rule_next != rule_current) {
|
||||
# print only on last one of rules in this group
|
||||
txt_ok(no_of_changes = no_of_changes)
|
||||
no_of_changes <- 0
|
||||
}
|
||||
}
|
||||
|
||||
# Print overview ----------------------------------------------------------
|
||||
if (info == TRUE) {
|
||||
if (verbose == TRUE) {
|
||||
wouldve <- "would have "
|
||||
} else {
|
||||
wouldve <- ""
|
||||
}
|
||||
|
||||
verbose_info <- verbose_info %>%
|
||||
arrange(row, rule_group, rule_name, col)
|
||||
|
||||
decimal.mark <- getOption("OutDec")
|
||||
big.mark <- ifelse(decimal.mark != ",", ",", ".")
|
||||
formatnr <- function(x) {
|
||||
trimws(format(x, big.mark = big.mark, decimal.mark = decimal.mark))
|
||||
}
|
||||
|
||||
cat(paste0("\n", silver(strrep("-", options()$width - 1)), "\n"))
|
||||
cat(bold(paste('EUCAST rules', paste0(wouldve, 'affected'),
|
||||
formatnr(n_distinct(verbose_info$row)),
|
||||
'out of', formatnr(nrow(x_original)),
|
||||
'rows, making a total of', formatnr(nrow(verbose_info)), 'edits\n')))
|
||||
|
||||
n_added <- verbose_info %>% filter(is.na(old)) %>% nrow()
|
||||
n_changed <- verbose_info %>% filter(!is.na(old)) %>% nrow()
|
||||
|
||||
# print added values ----
|
||||
if (n_added == 0) {
|
||||
colour <- cat # is function
|
||||
} else {
|
||||
colour <- blue # is function
|
||||
}
|
||||
cat(colour(paste0("=> ", wouldve, "added ",
|
||||
bold(formatnr(verbose_info %>%
|
||||
filter(is.na(old)) %>%
|
||||
nrow()), "test results"),
|
||||
"\n")))
|
||||
if (n_added > 0) {
|
||||
verbose_info %>%
|
||||
filter(is.na(old)) %>%
|
||||
# sort it well: S < I < R
|
||||
mutate(new = as.rsi(new)) %>%
|
||||
group_by(new) %>%
|
||||
summarise(n = n()) %>%
|
||||
mutate(plural = ifelse(n > 1, "s", ""),
|
||||
txt = paste0(formatnr(n), " test result", plural, " added as ", new)) %>%
|
||||
pull(txt) %>%
|
||||
paste(" -", ., collapse = "\n") %>%
|
||||
cat()
|
||||
}
|
||||
|
||||
# print changed values ----
|
||||
if (n_changed == 0) {
|
||||
colour <- cat # is function
|
||||
} else {
|
||||
colour <- blue # is function
|
||||
}
|
||||
if (n_added + n_changed > 0) {
|
||||
cat("\n")
|
||||
}
|
||||
cat(colour(paste0("=> ", wouldve, "changed ",
|
||||
bold(formatnr(verbose_info %>%
|
||||
filter(!is.na(old)) %>%
|
||||
nrow()), "test results"),
|
||||
"\n")))
|
||||
if (n_changed > 0) {
|
||||
verbose_info %>%
|
||||
filter(!is.na(old)) %>%
|
||||
# sort it well: S < I < R
|
||||
mutate(old = as.rsi(old),
|
||||
new = as.rsi(new)) %>%
|
||||
group_by(old, new) %>%
|
||||
summarise(n = n()) %>%
|
||||
mutate(plural = ifelse(n > 1, "s", ""),
|
||||
txt = paste0(formatnr(n), " test result", plural, " changed from ", old, " to ", new)) %>%
|
||||
pull(txt) %>%
|
||||
paste(" -", ., collapse = "\n") %>%
|
||||
cat()
|
||||
cat("\n")
|
||||
}
|
||||
cat(paste0(silver(strrep("-", options()$width - 1)), "\n"))
|
||||
|
||||
if (verbose == FALSE & nrow(verbose_info) > 0) {
|
||||
cat(paste("\nUse", bold("verbose = TRUE"), "to get a data.frame with all specified edits instead.\n"))
|
||||
}
|
||||
}
|
||||
|
||||
# Return data set ---------------------------------------------------------
|
||||
if (verbose == TRUE) {
|
||||
verbose_info
|
||||
} else {
|
||||
x_original
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,299 +0,0 @@
|
||||
# ==================================================================== #
|
||||
# TITLE #
|
||||
# Antimicrobial Resistance (AMR) Analysis #
|
||||
# #
|
||||
# SOURCE #
|
||||
# https://gitlab.com/msberends/AMR #
|
||||
# #
|
||||
# LICENCE #
|
||||
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
|
||||
# #
|
||||
# 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. #
|
||||
# #
|
||||
# This R package was created for academic research and was publicly #
|
||||
# released in the hope that it will be useful, but it comes WITHOUT #
|
||||
# ANY WARRANTY OR LIABILITY. #
|
||||
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
||||
# ==================================================================== #
|
||||
|
||||
#' Filter isolates on result in antibiotic class
|
||||
#'
|
||||
#' Filter isolates on results in specific antibiotic variables based on their class (ATC groups). This makes it easy to get a list of isolates that were tested for e.g. any aminoglycoside.
|
||||
#' @param tbl a data set
|
||||
#' @param ab_class an antimicrobial class, like \code{"carbapenems"}. More specifically, this should be a text that can be found in a 4th level ATC group (chemical subgroup) or a 5th level ATC group (chemical substance), please see \href{https://www.whocc.no/atc/structure_and_principles/}{this explanation on the WHOCC website}.
|
||||
#' @param result an antibiotic result: S, I or R (or a combination of more of them)
|
||||
#' @param scope the scope to check which variables to check, can be \code{"any"} (default) or \code{"all"}
|
||||
#' @param ... parameters passed on to \code{\link[dplyr]{filter_at}}
|
||||
#' @details The \code{\link{antibiotics}} data set will be searched for \code{ab_class} in the columns \code{atc_group1} and \code{atc_group2} (case-insensitive). Next, \code{tbl} will be checked for column names with a value in any abbreviations, codes or official names found in the \code{antibiotics} data set.
|
||||
#' @rdname filter_ab_class
|
||||
#' @keywords filter fillter_class
|
||||
#' @importFrom dplyr filter_at %>% select vars any_vars all_vars
|
||||
#' @importFrom crayon bold blue
|
||||
#' @export
|
||||
#' @examples
|
||||
#' library(dplyr)
|
||||
#'
|
||||
#' # filter on isolates that have any result for any aminoglycoside
|
||||
#' septic_patients %>% filter_aminoglycosides()
|
||||
#'
|
||||
#' # this is essentially the same as (but without determination of column names):
|
||||
#' septic_patients %>%
|
||||
#' filter_at(.vars = vars(c("GEN", "TOB", "AMK", "KAN")),
|
||||
#' .vars_predicate = any_vars(. %in% c("S", "I", "R")))
|
||||
#'
|
||||
#'
|
||||
#' # filter on isolates that show resistance to ANY aminoglycoside
|
||||
#' septic_patients %>% filter_aminoglycosides("R")
|
||||
#'
|
||||
#' # filter on isolates that show resistance to ALL aminoglycosides
|
||||
#' septic_patients %>% filter_aminoglycosides("R", "all")
|
||||
#'
|
||||
#' # filter on isolates that show resistance to
|
||||
#' # any aminoglycoside and any fluoroquinolone
|
||||
#' septic_patients %>%
|
||||
#' filter_aminoglycosides("R") %>%
|
||||
#' filter_fluoroquinolones("R")
|
||||
#'
|
||||
#' # filter on isolates that show resistance to
|
||||
#' # all aminoglycosides and all fluoroquinolones
|
||||
#' septic_patients %>%
|
||||
#' filter_aminoglycosides("R", "all") %>%
|
||||
#' filter_fluoroquinolones("R", "all")
|
||||
filter_ab_class <- function(tbl,
|
||||
ab_class,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
...) {
|
||||
scope <- scope[1L]
|
||||
if (is.null(result)) {
|
||||
result <- c("S", "I", "R")
|
||||
}
|
||||
# make result = "IR" work too:
|
||||
result <- unlist(strsplit(result, ""))
|
||||
|
||||
if (!all(result %in% c("S", "I", "R"))) {
|
||||
stop("`result` must be one or more of: S, I, R", call. = FALSE)
|
||||
}
|
||||
if (!all(scope %in% c("any", "all"))) {
|
||||
stop("`scope` must be one of: any, all", call. = FALSE)
|
||||
}
|
||||
|
||||
vars_df <- colnames(tbl)[tolower(colnames(tbl)) %in% tolower(ab_class_vars(ab_class))]
|
||||
atc_groups <- ab_class_atcgroups(ab_class)
|
||||
|
||||
if (length(vars_df) > 0) {
|
||||
if (length(result) == 1) {
|
||||
operator <- " is "
|
||||
} else {
|
||||
operator <- " is one of "
|
||||
}
|
||||
if (scope == "any") {
|
||||
scope_txt <- " or "
|
||||
scope_fn <- any_vars
|
||||
} else {
|
||||
scope_txt <- " and "
|
||||
scope_fn <- all_vars
|
||||
if (length(vars_df) > 1) {
|
||||
operator <- gsub("is", "are", operator)
|
||||
}
|
||||
}
|
||||
if (length(vars_df) > 1) {
|
||||
scope <- paste(scope, "of ")
|
||||
} else {
|
||||
scope <- ""
|
||||
}
|
||||
message(blue(paste0("Filtering on ", atc_groups, ": ", scope,
|
||||
paste(bold(paste0("`", vars_df, "`")), collapse = scope_txt), operator, toString(result))))
|
||||
tbl %>%
|
||||
filter_at(vars(vars_df),
|
||||
scope_fn(. %in% result),
|
||||
...)
|
||||
} else {
|
||||
warning(paste0("no antibiotics of class ", atc_groups, " found, leaving data unchanged"), call. = FALSE)
|
||||
tbl
|
||||
}
|
||||
}
|
||||
|
||||
#' @rdname filter_ab_class
|
||||
#' @export
|
||||
filter_aminoglycosides <- function(tbl,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
...) {
|
||||
filter_ab_class(tbl = tbl,
|
||||
ab_class = "aminoglycoside",
|
||||
result = result,
|
||||
scope = scope,
|
||||
...)
|
||||
}
|
||||
|
||||
#' @rdname filter_ab_class
|
||||
#' @export
|
||||
filter_carbapenems <- function(tbl,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
...) {
|
||||
filter_ab_class(tbl = tbl,
|
||||
ab_class = "carbapenem",
|
||||
result = result,
|
||||
scope = scope,
|
||||
...)
|
||||
}
|
||||
|
||||
#' @rdname filter_ab_class
|
||||
#' @export
|
||||
filter_cephalosporins <- function(tbl,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
...) {
|
||||
filter_ab_class(tbl = tbl,
|
||||
ab_class = "cephalosporin",
|
||||
result = result,
|
||||
scope = scope,
|
||||
...)
|
||||
}
|
||||
|
||||
#' @rdname filter_ab_class
|
||||
#' @export
|
||||
filter_1st_cephalosporins <- function(tbl,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
...) {
|
||||
filter_ab_class(tbl = tbl,
|
||||
ab_class = "first-generation cephalosporin",
|
||||
result = result,
|
||||
scope = scope,
|
||||
...)
|
||||
}
|
||||
|
||||
#' @rdname filter_ab_class
|
||||
#' @export
|
||||
filter_2nd_cephalosporins <- function(tbl,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
...) {
|
||||
filter_ab_class(tbl = tbl,
|
||||
ab_class = "second-generation cephalosporin",
|
||||
result = result,
|
||||
scope = scope,
|
||||
...)
|
||||
}
|
||||
|
||||
#' @rdname filter_ab_class
|
||||
#' @export
|
||||
filter_3rd_cephalosporins <- function(tbl,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
...) {
|
||||
filter_ab_class(tbl = tbl,
|
||||
ab_class = "third-generation cephalosporin",
|
||||
result = result,
|
||||
scope = scope,
|
||||
...)
|
||||
}
|
||||
|
||||
#' @rdname filter_ab_class
|
||||
#' @export
|
||||
filter_4th_cephalosporins <- function(tbl,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
...) {
|
||||
filter_ab_class(tbl = tbl,
|
||||
ab_class = "fourth-generation cephalosporin",
|
||||
result = result,
|
||||
scope = scope,
|
||||
...)
|
||||
}
|
||||
|
||||
#' @rdname filter_ab_class
|
||||
#' @export
|
||||
filter_fluoroquinolones <- function(tbl,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
...) {
|
||||
filter_ab_class(tbl = tbl,
|
||||
ab_class = "fluoroquinolone",
|
||||
result = result,
|
||||
scope = scope,
|
||||
...)
|
||||
}
|
||||
|
||||
#' @rdname filter_ab_class
|
||||
#' @export
|
||||
filter_glycopeptides <- function(tbl,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
...) {
|
||||
filter_ab_class(tbl = tbl,
|
||||
ab_class = "glycopeptide",
|
||||
result = result,
|
||||
scope = scope,
|
||||
...)
|
||||
}
|
||||
|
||||
#' @rdname filter_ab_class
|
||||
#' @export
|
||||
filter_macrolides <- function(tbl,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
...) {
|
||||
filter_ab_class(tbl = tbl,
|
||||
ab_class = "macrolide",
|
||||
result = result,
|
||||
scope = scope,
|
||||
...)
|
||||
}
|
||||
|
||||
#' @rdname filter_ab_class
|
||||
#' @export
|
||||
filter_tetracyclines <- function(tbl,
|
||||
result = NULL,
|
||||
scope = "any",
|
||||
...) {
|
||||
filter_ab_class(tbl = tbl,
|
||||
ab_class = "tetracycline",
|
||||
result = result,
|
||||
scope = scope,
|
||||
...)
|
||||
}
|
||||
|
||||
#' @importFrom dplyr %>% filter_at vars any_vars select
|
||||
ab_class_vars <- function(ab_class) {
|
||||
ab_vars <- AMR::antibiotics %>%
|
||||
filter_at(vars(c("atc_group1", "atc_group2")), any_vars(. %like% ab_class)) %>%
|
||||
select(ab:name, abbreviations, synonyms) %>%
|
||||
unlist() %>%
|
||||
as.matrix() %>%
|
||||
as.character() %>%
|
||||
paste(collapse = "|") %>%
|
||||
strsplit("|", fixed = TRUE) %>%
|
||||
unlist() %>%
|
||||
unique()
|
||||
ab_vars[!is.na(ab_vars)]
|
||||
}
|
||||
|
||||
#' @importFrom dplyr %>% filter pull
|
||||
ab_class_atcgroups <- function(ab_class) {
|
||||
ifelse(ab_class %in% c("aminoglycoside",
|
||||
"carbapenem",
|
||||
"cephalosporin",
|
||||
"first-generation cephalosporin",
|
||||
"second-generation cephalosporin",
|
||||
"third-generation cephalosporin",
|
||||
"fourth-generation cephalosporin",
|
||||
"fluoroquinolone",
|
||||
"glycopeptide",
|
||||
"macrolide",
|
||||
"tetracycline"),
|
||||
paste0(ab_class, "s"),
|
||||
AMR::antibiotics %>%
|
||||
filter(ab %in% ab_class_vars(ab_class)) %>%
|
||||
pull("atc_group2") %>%
|
||||
unique() %>%
|
||||
tolower() %>%
|
||||
paste(collapse = "/")
|
||||
)
|
||||
}
|
||||
@@ -1,578 +0,0 @@
|
||||
# ==================================================================== #
|
||||
# TITLE #
|
||||
# Antimicrobial Resistance (AMR) Analysis #
|
||||
# #
|
||||
# SOURCE #
|
||||
# https://gitlab.com/msberends/AMR #
|
||||
# #
|
||||
# LICENCE #
|
||||
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
|
||||
# #
|
||||
# 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. #
|
||||
# #
|
||||
# This R package was created for academic research and was publicly #
|
||||
# released in the hope that it will be useful, but it comes WITHOUT #
|
||||
# ANY WARRANTY OR LIABILITY. #
|
||||
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
||||
# ==================================================================== #
|
||||
|
||||
#' Determine first (weighted) isolates
|
||||
#'
|
||||
#' Determine first (weighted) isolates of all microorganisms of every patient per episode and (if needed) per specimen type.
|
||||
#' @param x a \code{data.frame} containing isolates.
|
||||
#' @param col_date column name of the result date (or date that is was received on the lab), defaults to the first column of with a date class
|
||||
#' @param col_patient_id column name of the unique IDs of the patients, defaults to the first column that starts with 'patient' or 'patid' (case insensitive)
|
||||
#' @param col_mo column name of the unique IDs of the microorganisms (see \code{\link{mo}}), defaults to the first column of class \code{mo}. Values will be coerced using \code{\link{as.mo}}.
|
||||
#' @param col_testcode column name of the test codes. Use \code{col_testcode = NULL} to \strong{not} exclude certain test codes (like test codes for screening). In that case \code{testcodes_exclude} will be ignored.
|
||||
#' @param col_specimen column name of the specimen type or group
|
||||
#' @param col_icu column name of the logicals (\code{TRUE}/\code{FALSE}) whether a ward or department is an Intensive Care Unit (ICU)
|
||||
#' @param col_keyantibiotics column name of the key antibiotics to determine first \emph{weighted} isolates, see \code{\link{key_antibiotics}}. Defaults to the first column that starts with 'key' followed by 'ab' or 'antibiotics' (case insensitive). Use \code{col_keyantibiotics = FALSE} to prevent this.
|
||||
#' @param episode_days episode in days after which a genus/species combination will be determined as 'first isolate' again
|
||||
#' @param testcodes_exclude character vector with test codes that should be excluded (case-insensitive)
|
||||
#' @param icu_exclude logical whether ICU isolates should be excluded (rows with value \code{TRUE} in column \code{col_icu})
|
||||
#' @param specimen_group value in column \code{col_specimen} to filter on
|
||||
#' @param type type to determine weighed isolates; can be \code{"keyantibiotics"} or \code{"points"}, see Details
|
||||
#' @param ignore_I logical to determine whether antibiotic interpretations with \code{"I"} will be ignored when \code{type = "keyantibiotics"}, see Details
|
||||
#' @param points_threshold points until the comparison of key antibiotics will lead to inclusion of an isolate when \code{type = "points"}, see Details
|
||||
#' @param info print progress
|
||||
#' @param ... parameters passed on to the \code{first_isolate} function
|
||||
#' @details \strong{WHY THIS IS SO IMPORTANT} \cr
|
||||
#' To conduct an analysis of antimicrobial resistance, you should only include the first isolate of every patient per episode \href{https://www.ncbi.nlm.nih.gov/pubmed/17304462}{[1]}. If you would not do this, you could easily get an overestimate or underestimate of the resistance of an antibiotic. Imagine that a patient was admitted with an MRSA and that it was found in 5 different blood cultures the following week. The resistance percentage of oxacillin of all \emph{S. aureus} isolates would be overestimated, because you included this MRSA more than once. It would be \href{https://en.wikipedia.org/wiki/Selection_bias}{selection bias}.
|
||||
#'
|
||||
#' The functions \code{filter_first_isolate} and \code{filter_first_weighted_isolate} are helper functions to quickly filter on first isolates. The function \code{filter_first_isolate} is essentially equal to:
|
||||
#' \preformatted{
|
||||
#' x \%>\%
|
||||
#' mutate(only_firsts = first_isolate(x, ...)) \%>\%
|
||||
#' filter(only_firsts == TRUE) \%>\%
|
||||
#' select(-only_firsts)
|
||||
#' }
|
||||
#' The function \code{filter_first_weighted_isolate} is essentially equal to:
|
||||
#' \preformatted{
|
||||
#' x \%>\%
|
||||
#' mutate(keyab = key_antibiotics(.)) \%>\%
|
||||
#' mutate(only_weighted_firsts = first_isolate(x,
|
||||
#' col_keyantibiotics = "keyab", ...)) \%>\%
|
||||
#' filter(only_weighted_firsts == TRUE) \%>\%
|
||||
#' select(-only_weighted_firsts)
|
||||
#' }
|
||||
#' @section Key antibiotics:
|
||||
#' There are two ways to determine whether isolates can be included as first \emph{weighted} isolates which will give generally the same results: \cr
|
||||
#'
|
||||
#' \strong{1. Using} \code{type = "keyantibiotics"} \strong{and parameter} \code{ignore_I} \cr
|
||||
#' Any difference from S to R (or vice versa) will (re)select an isolate as a first weighted isolate. With \code{ignore_I = FALSE}, also differences from I to S|R (or vice versa) will lead to this. This is a reliable method and 30-35 times faster than method 2. Read more about this in the \code{\link{key_antibiotics}} function. \cr
|
||||
#'
|
||||
#' \strong{2. Using} \code{type = "points"} \strong{and parameter} \code{points_threshold} \cr
|
||||
#' A difference from I to S|R (or vice versa) means 0.5 points, a difference from S to R (or vice versa) means 1 point. When the sum of points exceeds \code{points_threshold}, which default to \code{2}, an isolate will be (re)selected as a first weighted isolate.
|
||||
#' @rdname first_isolate
|
||||
#' @keywords isolate isolates first
|
||||
#' @seealso \code{\link{key_antibiotics}}
|
||||
#' @export
|
||||
#' @importFrom dplyr arrange_at lag between row_number filter mutate arrange pull
|
||||
#' @importFrom crayon blue bold silver
|
||||
#' @return Logical vector
|
||||
#' @source Methodology of this function is based on: \strong{M39 Analysis and Presentation of Cumulative Antimicrobial Susceptibility Test Data, 4th Edition}, 2014, \emph{Clinical and Laboratory Standards Institute (CLSI)}. \url{https://clsi.org/standards/products/microbiology/documents/m39/}.
|
||||
#' @inheritSection AMR Read more on our website!
|
||||
#' @examples
|
||||
#' # septic_patients is a dataset available in the AMR package. It is true, genuine data.
|
||||
#' ?septic_patients
|
||||
#'
|
||||
#' library(dplyr)
|
||||
#' # Filter on first isolates:
|
||||
#' septic_patients %>%
|
||||
#' mutate(first_isolate = first_isolate(.,
|
||||
#' col_date = "date",
|
||||
#' col_patient_id = "patient_id",
|
||||
#' col_mo = "mo")) %>%
|
||||
#' filter(first_isolate == TRUE)
|
||||
#'
|
||||
#' # Which can be shortened to:
|
||||
#' septic_patients %>%
|
||||
#' filter_first_isolate()
|
||||
#' # or for first weighted isolates:
|
||||
#' septic_patients %>%
|
||||
#' filter_first_weighted_isolate()
|
||||
#'
|
||||
#' # Now let's see if first isolates matter:
|
||||
#' A <- septic_patients %>%
|
||||
#' group_by(hospital_id) %>%
|
||||
#' summarise(count = n_rsi(GEN), # gentamicin availability
|
||||
#' resistance = portion_IR(GEN)) # gentamicin resistance
|
||||
#'
|
||||
#' B <- septic_patients %>%
|
||||
#' filter_first_weighted_isolate() %>% # the 1st isolate filter
|
||||
#' group_by(hospital_id) %>%
|
||||
#' summarise(count = n_rsi(GEN), # gentamicin availability
|
||||
#' resistance = portion_IR(GEN)) # gentamicin resistance
|
||||
#'
|
||||
#' # Have a look at A and B.
|
||||
#' # B is more reliable because every isolate is only counted once.
|
||||
#' # Gentamicin resitance in hospital D appears to be 3.1% higher than
|
||||
#' # when you (erroneously) would have used all isolates for analysis.
|
||||
#'
|
||||
#'
|
||||
#' ## OTHER EXAMPLES:
|
||||
#'
|
||||
#' \dontrun{
|
||||
#'
|
||||
#' # set key antibiotics to a new variable
|
||||
#' x$keyab <- key_antibiotics(x)
|
||||
#'
|
||||
#' x$first_isolate <-
|
||||
#' first_isolate(x)
|
||||
#'
|
||||
#' x$first_isolate_weighed <-
|
||||
#' first_isolate(x,
|
||||
#' col_keyantibiotics = 'keyab')
|
||||
#'
|
||||
#' x$first_blood_isolate <-
|
||||
#' first_isolate(x,
|
||||
#' specimen_group = 'Blood')
|
||||
#'
|
||||
#' x$first_blood_isolate_weighed <-
|
||||
#' first_isolate(x,
|
||||
#' specimen_group = 'Blood',
|
||||
#' col_keyantibiotics = 'keyab')
|
||||
#'
|
||||
#' x$first_urine_isolate <-
|
||||
#' first_isolate(x,
|
||||
#' specimen_group = 'Urine')
|
||||
#'
|
||||
#' x$first_urine_isolate_weighed <-
|
||||
#' first_isolate(x,
|
||||
#' specimen_group = 'Urine',
|
||||
#' col_keyantibiotics = 'keyab')
|
||||
#'
|
||||
#' x$first_resp_isolate <-
|
||||
#' first_isolate(x,
|
||||
#' specimen_group = 'Respiratory')
|
||||
#'
|
||||
#' x$first_resp_isolate_weighed <-
|
||||
#' first_isolate(x,
|
||||
#' specimen_group = 'Respiratory',
|
||||
#' col_keyantibiotics = 'keyab')
|
||||
#' }
|
||||
first_isolate <- function(x,
|
||||
col_date = NULL,
|
||||
col_patient_id = NULL,
|
||||
col_mo = NULL,
|
||||
col_testcode = NULL,
|
||||
col_specimen = NULL,
|
||||
col_icu = NULL,
|
||||
col_keyantibiotics = NULL,
|
||||
episode_days = 365,
|
||||
testcodes_exclude = NULL,
|
||||
icu_exclude = FALSE,
|
||||
specimen_group = NULL,
|
||||
type = "keyantibiotics",
|
||||
ignore_I = TRUE,
|
||||
points_threshold = 2,
|
||||
info = TRUE,
|
||||
...) {
|
||||
|
||||
if (!is.data.frame(x)) {
|
||||
stop("`x` must be a data.frame.", call. = FALSE)
|
||||
}
|
||||
|
||||
dots <- unlist(list(...))
|
||||
if (length(dots) != 0) {
|
||||
# backwards compatibility with old parameters
|
||||
dots.names <- dots %>% names()
|
||||
if ('filter_specimen' %in% dots.names) {
|
||||
specimen_group <- dots[which(dots.names == 'filter_specimen')]
|
||||
}
|
||||
if ('tbl' %in% dots.names) {
|
||||
x <- dots[which(dots.names == 'tbl')]
|
||||
}
|
||||
}
|
||||
|
||||
# try to find columns based on type
|
||||
# -- mo
|
||||
if (is.null(col_mo)) {
|
||||
col_mo <- search_type_in_df(x = x, type = "mo")
|
||||
}
|
||||
if (is.null(col_mo)) {
|
||||
stop("`col_mo` must be set.", call. = FALSE)
|
||||
}
|
||||
|
||||
# -- date
|
||||
if (is.null(col_date)) {
|
||||
col_date <- search_type_in_df(x = x, type = "date")
|
||||
}
|
||||
if (is.null(col_date)) {
|
||||
stop("`col_date` must be set.", call. = FALSE)
|
||||
}
|
||||
# convert to Date (pipes/pull for supporting tibbles too)
|
||||
dates <- x %>% pull(col_date) %>% as.Date()
|
||||
dates[is.na(dates)] <- as.Date("1970-01-01")
|
||||
x[, col_date] <- dates
|
||||
|
||||
# -- patient id
|
||||
if (is.null(col_patient_id)) {
|
||||
if (all(c("First name", "Last name", "Sex", "Identification number") %in% colnames(x))) {
|
||||
# WHONET support
|
||||
x <- x %>% mutate(patient_id = paste(`First name`, `Last name`, Sex))
|
||||
col_patient_id <- "patient_id"
|
||||
message(blue(paste0("NOTE: Using combined columns ", bold("`First name`, `Last name` and `Sex`"), " as input for `col_patient_id`.")))
|
||||
} else {
|
||||
col_patient_id <- search_type_in_df(x = x, type = "patient_id")
|
||||
}
|
||||
}
|
||||
if (is.null(col_patient_id)) {
|
||||
stop("`col_patient_id` must be set.", call. = FALSE)
|
||||
}
|
||||
|
||||
# -- key antibiotics
|
||||
if (is.null(col_keyantibiotics)) {
|
||||
col_keyantibiotics <- search_type_in_df(x = x, type = "keyantibiotics")
|
||||
}
|
||||
if (isFALSE(col_keyantibiotics)) {
|
||||
col_keyantibiotics <- NULL
|
||||
}
|
||||
|
||||
# -- specimen
|
||||
if (is.null(col_specimen) & !is.null(specimen_group)) {
|
||||
col_specimen <- search_type_in_df(x = x, type = "specimen")
|
||||
}
|
||||
if (isFALSE(col_specimen)) {
|
||||
col_specimen <- NULL
|
||||
}
|
||||
|
||||
# check if columns exist
|
||||
check_columns_existance <- function(column, tblname = x) {
|
||||
if (NROW(tblname) <= 1 | NCOL(tblname) <= 1) {
|
||||
stop('Please check tbl for existance.')
|
||||
}
|
||||
|
||||
if (!is.null(column)) {
|
||||
if (!(column %in% colnames(tblname))) {
|
||||
stop('Column `', column, '` not found.')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
check_columns_existance(col_date)
|
||||
check_columns_existance(col_patient_id)
|
||||
check_columns_existance(col_mo)
|
||||
check_columns_existance(col_testcode)
|
||||
check_columns_existance(col_icu)
|
||||
check_columns_existance(col_keyantibiotics)
|
||||
|
||||
# join to microorganisms data set
|
||||
x <- x %>%
|
||||
mutate_at(vars(col_mo), as.mo) %>%
|
||||
left_join_microorganisms(by = col_mo) %>%
|
||||
# empty species will lead to first = FALSE, so put in text there if genus is available
|
||||
mutate(species = ifelse(!is.na(genus) & species == "", "species", species))
|
||||
col_genus <- "genus"
|
||||
col_species <- "species"
|
||||
|
||||
if (is.null(col_testcode)) {
|
||||
testcodes_exclude <- NULL
|
||||
}
|
||||
# remove testcodes
|
||||
if (!is.null(testcodes_exclude) & info == TRUE) {
|
||||
cat('[Criterion] Excluded test codes:\n', toString(testcodes_exclude), '\n')
|
||||
}
|
||||
|
||||
if (is.null(col_icu)) {
|
||||
icu_exclude <- FALSE
|
||||
} else {
|
||||
x <- x %>%
|
||||
mutate(col_icu = x %>% pull(col_icu) %>% as.logical())
|
||||
}
|
||||
|
||||
if (is.null(col_specimen)) {
|
||||
specimen_group <- NULL
|
||||
}
|
||||
|
||||
# filter on specimen group and keyantibiotics when they are filled in
|
||||
if (!is.null(specimen_group)) {
|
||||
check_columns_existance(col_specimen, x)
|
||||
if (info == TRUE) {
|
||||
cat('[Criterion] Excluded other than specimen group \'', specimen_group, '\'\n', sep = '')
|
||||
}
|
||||
}
|
||||
if (!is.null(col_keyantibiotics)) {
|
||||
x <- x %>% mutate(key_ab = x %>% pull(col_keyantibiotics))
|
||||
}
|
||||
|
||||
if (is.null(testcodes_exclude)) {
|
||||
testcodes_exclude <- ''
|
||||
}
|
||||
|
||||
# create new dataframe with original row index and right sorting
|
||||
x <- x %>%
|
||||
mutate(first_isolate_row_index = 1:nrow(x),
|
||||
date_lab = x %>% pull(col_date),
|
||||
patient_id = x %>% pull(col_patient_id),
|
||||
species = x %>% pull(col_species),
|
||||
genus = x %>% pull(col_genus)) %>%
|
||||
mutate(species = if_else(is.na(species) | species == "(no MO)", "", species),
|
||||
genus = if_else(is.na(genus) | genus == "(no MO)", "", genus))
|
||||
|
||||
if (is.null(specimen_group)) {
|
||||
# not filtering on specimen
|
||||
if (icu_exclude == FALSE) {
|
||||
if (info == TRUE & !is.null(col_icu)) {
|
||||
cat('[Criterion] Included isolates from ICU.\n')
|
||||
}
|
||||
x <- x %>%
|
||||
arrange_at(c(col_patient_id,
|
||||
col_genus,
|
||||
col_species,
|
||||
col_date))
|
||||
row.start <- 1
|
||||
row.end <- nrow(x)
|
||||
} else {
|
||||
if (info == TRUE) {
|
||||
cat('[Criterion] Excluded isolates from ICU.\n')
|
||||
}
|
||||
x <- x %>%
|
||||
arrange_at(c(col_icu,
|
||||
col_patient_id,
|
||||
col_genus,
|
||||
col_species,
|
||||
col_date))
|
||||
|
||||
suppressWarnings(
|
||||
row.start <- which(x %>% pull(col_icu) == FALSE) %>% min(na.rm = TRUE)
|
||||
)
|
||||
suppressWarnings(
|
||||
row.end <- which(x %>% pull(col_icu) == FALSE) %>% max(na.rm = TRUE)
|
||||
)
|
||||
}
|
||||
|
||||
} else {
|
||||
# filtering on specimen and only analyse these row to save time
|
||||
if (icu_exclude == FALSE) {
|
||||
if (info == TRUE & !is.null(col_icu)) {
|
||||
cat('[Criterion] Included isolates from ICU.\n')
|
||||
}
|
||||
x <- x %>%
|
||||
arrange_at(c(col_specimen,
|
||||
col_patient_id,
|
||||
col_genus,
|
||||
col_species,
|
||||
col_date))
|
||||
suppressWarnings(
|
||||
row.start <- which(x %>% pull(col_specimen) == specimen_group) %>% min(na.rm = TRUE)
|
||||
)
|
||||
suppressWarnings(
|
||||
row.end <- which(x %>% pull(col_specimen) == specimen_group) %>% max(na.rm = TRUE)
|
||||
)
|
||||
} else {
|
||||
if (info == TRUE) {
|
||||
cat('[Criterion] Excluded isolates from ICU.\n')
|
||||
}
|
||||
x <- x %>%
|
||||
arrange_at(c(col_icu,
|
||||
col_specimen,
|
||||
col_patient_id,
|
||||
col_genus,
|
||||
col_species,
|
||||
col_date))
|
||||
suppressWarnings(
|
||||
row.start <- which(x %>% pull(col_specimen) == specimen_group
|
||||
& x %>% pull(col_icu) == FALSE) %>% min(na.rm = TRUE)
|
||||
)
|
||||
suppressWarnings(
|
||||
row.end <- which(x %>% pull(col_specimen) == specimen_group
|
||||
& x %>% pull(col_icu) == FALSE) %>% max(na.rm = TRUE)
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (abs(row.start) == Inf | abs(row.end) == Inf) {
|
||||
if (info == TRUE) {
|
||||
message(paste("=> Found", bold("no isolates")))
|
||||
}
|
||||
# NAs where genus is unavailable
|
||||
return(x %>%
|
||||
mutate(real_first_isolate = if_else(genus == '', NA, FALSE)) %>%
|
||||
pull(real_first_isolate)
|
||||
)
|
||||
}
|
||||
|
||||
# suppress warnings because dplyr wants us to use library(dplyr) when using filter(row_number())
|
||||
suppressWarnings(
|
||||
scope.size <- x %>%
|
||||
filter(
|
||||
row_number() %>% between(row.start,
|
||||
row.end),
|
||||
genus != "",
|
||||
species != "") %>%
|
||||
nrow()
|
||||
)
|
||||
|
||||
identify_new_year = function(x, episode_days) {
|
||||
# I asked on StackOverflow:
|
||||
# https://stackoverflow.com/questions/42122245/filter-one-row-every-year
|
||||
if (length(x) == 1) {
|
||||
return(TRUE)
|
||||
}
|
||||
indices = integer(0)
|
||||
start = x[1]
|
||||
ind = 1
|
||||
indices[ind] = ind
|
||||
for (i in 2:length(x)) {
|
||||
if (as.numeric(x[i] - start >= episode_days)) {
|
||||
ind = ind + 1
|
||||
indices[ind] = i
|
||||
start = x[i]
|
||||
}
|
||||
}
|
||||
result <- rep(FALSE, length(x))
|
||||
result[indices] <- TRUE
|
||||
return(result)
|
||||
}
|
||||
|
||||
# Analysis of first isolate ----
|
||||
all_first <- x %>%
|
||||
mutate(other_pat_or_mo = if_else(patient_id == lag(patient_id)
|
||||
& genus == lag(genus)
|
||||
& species == lag(species),
|
||||
FALSE,
|
||||
TRUE)) %>%
|
||||
group_by_at(vars(patient_id,
|
||||
genus,
|
||||
species)) %>%
|
||||
mutate(more_than_episode_ago = identify_new_year(x = date_lab,
|
||||
episode_days = episode_days)) %>%
|
||||
ungroup()
|
||||
|
||||
weighted.notice <- ''
|
||||
if (!is.null(col_keyantibiotics)) {
|
||||
weighted.notice <- 'weighted '
|
||||
if (info == TRUE) {
|
||||
if (type == 'keyantibiotics') {
|
||||
cat('[Criterion] Inclusion based on key antibiotics, ')
|
||||
if (ignore_I == FALSE) {
|
||||
cat('not ')
|
||||
}
|
||||
cat('ignoring I.\n')
|
||||
}
|
||||
if (type == 'points') {
|
||||
cat(paste0('[Criterion] Inclusion based on key antibiotics, using points threshold of '
|
||||
, points_threshold, '.\n'))
|
||||
}
|
||||
}
|
||||
type_param <- type
|
||||
# suppress warnings because dplyr want us to use library(dplyr) when using filter(row_number())
|
||||
suppressWarnings(
|
||||
all_first <- all_first %>%
|
||||
mutate(key_ab_lag = lag(key_ab)) %>%
|
||||
mutate(key_ab_other = !key_antibiotics_equal(y = key_ab,
|
||||
z = key_ab_lag,
|
||||
type = type_param,
|
||||
ignore_I = ignore_I,
|
||||
points_threshold = points_threshold,
|
||||
info = info)) %>%
|
||||
mutate(
|
||||
real_first_isolate =
|
||||
if_else(
|
||||
between(row_number(), row.start, row.end)
|
||||
& genus != ""
|
||||
& species != ""
|
||||
& (other_pat_or_mo | more_than_episode_ago | key_ab_other),
|
||||
TRUE,
|
||||
FALSE))
|
||||
)
|
||||
} else {
|
||||
# no key antibiotics
|
||||
# suppress warnings because dplyr want us to use library(dplyr) when using filter(row_number())
|
||||
suppressWarnings(
|
||||
all_first <- all_first %>%
|
||||
mutate(
|
||||
real_first_isolate =
|
||||
if_else(
|
||||
between(row_number(), row.start, row.end)
|
||||
& genus != ""
|
||||
& species != ""
|
||||
& (other_pat_or_mo | more_than_episode_ago),
|
||||
TRUE,
|
||||
FALSE))
|
||||
)
|
||||
}
|
||||
|
||||
# first one as TRUE
|
||||
all_first[row.start, 'real_first_isolate'] <- TRUE
|
||||
# no tests that should be included, or ICU
|
||||
if (!is.null(col_testcode)) {
|
||||
all_first[which(all_first[, col_testcode] %in% tolower(testcodes_exclude)), 'real_first_isolate'] <- FALSE
|
||||
}
|
||||
if (icu_exclude == TRUE) {
|
||||
all_first[which(all_first[, col_icu] == TRUE), 'real_first_isolate'] <- FALSE
|
||||
}
|
||||
|
||||
# NAs where genus is unavailable
|
||||
all_first <- all_first %>%
|
||||
mutate(real_first_isolate = if_else(genus %in% c('', '(no MO)', NA), NA, real_first_isolate))
|
||||
|
||||
all_first <- all_first %>%
|
||||
arrange(first_isolate_row_index) %>%
|
||||
pull(real_first_isolate)
|
||||
|
||||
if (info == TRUE) {
|
||||
decimal.mark <- getOption("OutDec")
|
||||
big.mark <- ifelse(decimal.mark != ",", ",", ".")
|
||||
n_found <- base::sum(all_first, na.rm = TRUE)
|
||||
p_found_total <- percent(n_found / nrow(x), force_zero = TRUE)
|
||||
p_found_scope <- percent(n_found / scope.size, force_zero = TRUE)
|
||||
# mark up number of found
|
||||
n_found <- base::format(n_found, big.mark = big.mark, decimal.mark = decimal.mark)
|
||||
if (p_found_total != p_found_scope) {
|
||||
msg_txt <- paste0("=> Found ",
|
||||
bold(paste0(n_found, " first ", weighted.notice, "isolates")),
|
||||
" (", p_found_scope, " within scope and ", p_found_total, " of total)")
|
||||
} else {
|
||||
msg_txt <- paste0("=> Found ",
|
||||
bold(paste0(n_found, " first ", weighted.notice, "isolates")),
|
||||
" (", p_found_total, " of total)")
|
||||
}
|
||||
base::message(msg_txt)
|
||||
}
|
||||
|
||||
all_first
|
||||
|
||||
}
|
||||
|
||||
#' @rdname first_isolate
|
||||
#' @importFrom dplyr filter
|
||||
#' @export
|
||||
filter_first_isolate <- function(x,
|
||||
col_date = NULL,
|
||||
col_patient_id = NULL,
|
||||
col_mo = NULL,
|
||||
...) {
|
||||
filter(x, first_isolate(x = x,
|
||||
col_date = col_date,
|
||||
col_patient_id = col_patient_id,
|
||||
col_mo = col_mo,
|
||||
...))
|
||||
}
|
||||
|
||||
#' @rdname first_isolate
|
||||
#' @importFrom dplyr %>% mutate filter
|
||||
#' @export
|
||||
filter_first_weighted_isolate <- function(x,
|
||||
col_date = NULL,
|
||||
col_patient_id = NULL,
|
||||
col_mo = NULL,
|
||||
col_keyantibiotics = NULL,
|
||||
...) {
|
||||
tbl_keyab <- x %>%
|
||||
mutate(keyab = suppressMessages(key_antibiotics(.,
|
||||
col_mo = col_mo,
|
||||
...))) %>%
|
||||
mutate(firsts = first_isolate(.,
|
||||
col_date = col_date,
|
||||
col_patient_id = col_patient_id,
|
||||
col_mo = col_mo,
|
||||
col_keyantibiotics = "keyab",
|
||||
...))
|
||||
x[which(tbl_keyab$firsts == TRUE),]
|
||||
}
|
||||
@@ -1,234 +0,0 @@
|
||||
# ==================================================================== #
|
||||
# TITLE #
|
||||
# Antimicrobial Resistance (AMR) Analysis #
|
||||
# #
|
||||
# SOURCE #
|
||||
# https://gitlab.com/msberends/AMR #
|
||||
# #
|
||||
# LICENCE #
|
||||
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
|
||||
# #
|
||||
# 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. #
|
||||
# #
|
||||
# This R package was created for academic research and was publicly #
|
||||
# released in the hope that it will be useful, but it comes WITHOUT #
|
||||
# ANY WARRANTY OR LIABILITY. #
|
||||
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
||||
# ==================================================================== #
|
||||
|
||||
#' \emph{G}-test for Count Data
|
||||
#'
|
||||
#' \code{g.test} performs chi-squared contingency table tests and goodness-of-fit tests, just like \code{\link{chisq.test}} but is more reliable [1]. A \emph{G}-test can be used to see whether the number of observations in each category fits a theoretical expectation (called a \strong{\emph{G}-test of goodness-of-fit}), or to see whether the proportions of one variable are different for different values of the other variable (called a \strong{\emph{G}-test of independence}).
|
||||
#' @inherit stats::chisq.test params return
|
||||
#' @details If \code{x} is a matrix with one row or column, or if \code{x} is a vector and \code{y} is not given, then a \emph{goodness-of-fit test} is performed (\code{x} is treated as a one-dimensional contingency table). The entries of \code{x} must be non-negative integers. In this case, the hypothesis tested is whether the population probabilities equal those in \code{p}, or are all equal if \code{p} is not given.
|
||||
#'
|
||||
#' If \code{x} is a matrix with at least two rows and columns, it is taken as a two-dimensional contingency table: the entries of \code{x} must be non-negative integers. Otherwise, \code{x} and \code{y} must be vectors or factors of the same length; cases with missing values are removed, the objects are coerced to factors, and the contingency table is computed from these. Then Pearson's chi-squared test is performed of the null hypothesis that the joint distribution of the cell counts in a 2-dimensional contingency table is the product of the row and column marginals.
|
||||
#'
|
||||
#' The p-value is computed from the asymptotic chi-squared distribution of the test statistic.
|
||||
#'
|
||||
#' In the contingency table case simulation is done by random sampling from the set of all contingency tables with given marginals, and works only if the marginals are strictly positive. Note that this is not the usual sampling situation assumed for a chi-squared test (like the \emph{G}-test) but rather that for Fisher's exact test.
|
||||
#'
|
||||
#' In the goodness-of-fit case simulation is done by random sampling from the discrete distribution specified by \code{p}, each sample being of size \code{n = sum(x)}. This simulation is done in \R and may be slow.
|
||||
#' @section \emph{G}-test of goodness-of-fit (likelihood ratio test):
|
||||
#' Use the \emph{G}-test of goodness-of-fit when you have one nominal variable with two or more values (such as male and female, or red, pink and white flowers). You compare the observed counts of numbers of observations in each category with the expected counts, which you calculate using some kind of theoretical expectation (such as a 1:1 sex ratio or a 1:2:1 ratio in a genetic cross).
|
||||
#'
|
||||
#' If the expected number of observations in any category is too small, the \emph{G}-test may give inaccurate results, and you should use an exact test instead (\code{\link{fisher.test}}).
|
||||
#'
|
||||
#' The \emph{G}-test of goodness-of-fit is an alternative to the chi-square test of goodness-of-fit (\code{\link{chisq.test}}); each of these tests has some advantages and some disadvantages, and the results of the two tests are usually very similar.
|
||||
#'
|
||||
#' @section \emph{G}-test of independence:
|
||||
#' Use the \emph{G}-test of independence when you have two nominal variables, each with two or more possible values. You want to know whether the proportions for one variable are different among values of the other variable.
|
||||
#'
|
||||
#' It is also possible to do a \emph{G}-test of independence with more than two nominal variables. For example, Jackson et al. (2013) also had data for children under 3, so you could do an analysis of old vs. young, thigh vs. arm, and reaction vs. no reaction, all analyzed together.
|
||||
#'
|
||||
#' Fisher's exact test (\code{\link{fisher.test}}) is an \strong{exact} test, where the \emph{G}-test is still only an \strong{approximation}. For any 2x2 table, Fisher's Exact test may be slower but will still run in seconds, even if the sum of your observations is multiple millions.
|
||||
#'
|
||||
#' The \emph{G}-test of independence is an alternative to the chi-square test of independence (\code{\link{chisq.test}}), and they will give approximately the same results.
|
||||
#' @section How the test works:
|
||||
#' Unlike the exact test of goodness-of-fit (\code{\link{fisher.test}}), the \emph{G}-test does not directly calculate the probability of obtaining the observed results or something more extreme. Instead, like almost all statistical tests, the \emph{G}-test has an intermediate step; it uses the data to calculate a test statistic that measures how far the observed data are from the null expectation. You then use a mathematical relationship, in this case the chi-square distribution, to estimate the probability of obtaining that value of the test statistic.
|
||||
#'
|
||||
#' The \emph{G}-test uses the log of the ratio of two likelihoods as the test statistic, which is why it is also called a likelihood ratio test or log-likelihood ratio test. The formula to calculate a \emph{G}-statistic is:
|
||||
#'
|
||||
#' \code{G <- 2 * sum(x * log(x / E))}
|
||||
#'
|
||||
#' where \code{E} are the expected values. Since this is chi-square distributed, the p value can be calculated with:
|
||||
#'
|
||||
#' \code{p <- stats::pchisq(G, df, lower.tail = FALSE)}
|
||||
#'
|
||||
#' where \code{df} are the degrees of freedom.
|
||||
#'
|
||||
#' If there are more than two categories and you want to find out which ones are significantly different from their null expectation, you can use the same method of testing each category vs. the sum of all categories, with the Bonferroni correction. You use \emph{G}-tests for each category, of course.
|
||||
#' @keywords chi
|
||||
#' @seealso \code{\link{chisq.test}}
|
||||
#' @references [1] McDonald, J.H. 2014. \strong{Handbook of Biological Statistics (3rd ed.)}. Sparky House Publishing, Baltimore, Maryland. \url{http://www.biostathandbook.com/gtestgof.html}.
|
||||
#' @source This code is almost identical to \code{\link{chisq.test}}, except that:
|
||||
#' \itemize{
|
||||
#' \item{The calculation of the statistic was changed to \code{2 * sum(x * log(x / E))}}
|
||||
#' \item{Yates' continuity correction was removed as it does not apply to a \emph{G}-test}
|
||||
#' \item{The possibility to simulate p values with \code{simulate.p.value} was removed}
|
||||
#' }
|
||||
#' @export
|
||||
#' @importFrom stats pchisq complete.cases
|
||||
#' @inheritSection AMR Read more on our website!
|
||||
#' @examples
|
||||
#' # = EXAMPLE 1 =
|
||||
#' # Shivrain et al. (2006) crossed clearfield rice (which are resistant
|
||||
#' # to the herbicide imazethapyr) with red rice (which are susceptible to
|
||||
#' # imazethapyr). They then crossed the hybrid offspring and examined the
|
||||
#' # F2 generation, where they found 772 resistant plants, 1611 moderately
|
||||
#' # resistant plants, and 737 susceptible plants. If resistance is controlled
|
||||
#' # by a single gene with two co-dominant alleles, you would expect a 1:2:1
|
||||
#' # ratio.
|
||||
#'
|
||||
#' x <- c(772, 1611, 737)
|
||||
#' G <- g.test(x, p = c(1, 2, 1) / 4)
|
||||
#' # G$p.value = 0.12574.
|
||||
#'
|
||||
#' # There is no significant difference from a 1:2:1 ratio.
|
||||
#' # Meaning: resistance controlled by a single gene with two co-dominant
|
||||
#' # alleles, is plausible.
|
||||
#'
|
||||
#'
|
||||
#' # = EXAMPLE 2 =
|
||||
#' # Red crossbills (Loxia curvirostra) have the tip of the upper bill either
|
||||
#' # right or left of the lower bill, which helps them extract seeds from pine
|
||||
#' # cones. Some have hypothesized that frequency-dependent selection would
|
||||
#' # keep the number of right and left-billed birds at a 1:1 ratio. Groth (1992)
|
||||
#' # observed 1752 right-billed and 1895 left-billed crossbills.
|
||||
#'
|
||||
#' x <- c(1752, 1895)
|
||||
#' g.test(x)
|
||||
#' # p = 0.01787343
|
||||
#'
|
||||
#' # There is a significant difference from a 1:1 ratio.
|
||||
#' # Meaning: there are significantly more left-billed birds.
|
||||
#'
|
||||
g.test <- function(x,
|
||||
y = NULL,
|
||||
# correct = TRUE,
|
||||
p = rep(1/length(x), length(x)),
|
||||
rescale.p = FALSE) {
|
||||
DNAME <- deparse(substitute(x))
|
||||
if (is.data.frame(x))
|
||||
x <- as.matrix(x)
|
||||
if (is.matrix(x)) {
|
||||
if (min(dim(x)) == 1L)
|
||||
x <- as.vector(x)
|
||||
}
|
||||
if (!is.matrix(x) && !is.null(y)) {
|
||||
if (length(x) != length(y))
|
||||
stop("'x' and 'y' must have the same length")
|
||||
DNAME2 <- deparse(substitute(y))
|
||||
xname <- if (length(DNAME) > 1L || nchar(DNAME, "w") >
|
||||
30)
|
||||
""
|
||||
else DNAME
|
||||
yname <- if (length(DNAME2) > 1L || nchar(DNAME2, "w") >
|
||||
30)
|
||||
""
|
||||
else DNAME2
|
||||
OK <- complete.cases(x, y)
|
||||
x <- factor(x[OK])
|
||||
y <- factor(y[OK])
|
||||
if ((nlevels(x) < 2L) || (nlevels(y) < 2L))
|
||||
stop("'x' and 'y' must have at least 2 levels")
|
||||
x <- table(x, y)
|
||||
names(dimnames(x)) <- c(xname, yname)
|
||||
DNAME <- paste(paste(DNAME, collapse = "\n"), "and",
|
||||
paste(DNAME2, collapse = "\n"))
|
||||
}
|
||||
if (any(x < 0) || anyNA(x))
|
||||
stop("all entries of 'x' must be nonnegative and finite")
|
||||
if ((n <- sum(x)) == 0)
|
||||
stop("at least one entry of 'x' must be positive")
|
||||
# if (simulate.p.value) {
|
||||
# setMETH <- function() METHOD <<- paste(METHOD, "with simulated p-value\n\t (based on",
|
||||
# B, "replicates)")
|
||||
# almost.1 <- 1 - 64 * .Machine$double.eps
|
||||
# }
|
||||
if (is.matrix(x)) {
|
||||
METHOD <- "G-test of independence"
|
||||
nr <- as.integer(nrow(x))
|
||||
nc <- as.integer(ncol(x))
|
||||
if (is.na(nr) || is.na(nc) || is.na(nr * nc))
|
||||
stop("invalid nrow(x) or ncol(x)", domain = NA)
|
||||
# add fisher.test suggestion
|
||||
if (nr == 2 && nc == 2)
|
||||
warning("`fisher.test()` is always more reliable for 2x2 tables and although must slower, often only takes seconds.")
|
||||
sr <- rowSums(x)
|
||||
sc <- colSums(x)
|
||||
E <- outer(sr, sc, "*")/n
|
||||
v <- function(r, c, n) c * r * (n - r) * (n - c)/n^3
|
||||
V <- outer(sr, sc, v, n)
|
||||
dimnames(E) <- dimnames(x)
|
||||
# if (simulate.p.value && all(sr > 0) && all(sc > 0)) {
|
||||
# setMETH()
|
||||
# tmp <- .Call(chisq_sim, sr, sc, B, E, PACKAGE = "stats")
|
||||
# STATISTIC <- 2 * sum(x * log(x / E)) # sum(sort((x - E)^2/E, decreasing = TRUE)) for chisq.test
|
||||
# PARAMETER <- NA
|
||||
# PVAL <- (1 + sum(tmp >= almost.1 * STATISTIC))/(B +
|
||||
# 1)
|
||||
# }
|
||||
# else {
|
||||
# if (simulate.p.value)
|
||||
# warning("cannot compute simulated p-value with zero marginals")
|
||||
# if (correct && nrow(x) == 2L && ncol(x) == 2L) {
|
||||
# YATES <- min(0.5, abs(x - E))
|
||||
# if (YATES > 0)
|
||||
# METHOD <- paste(METHOD, "with Yates' continuity correction")
|
||||
# }
|
||||
# else YATES <- 0
|
||||
STATISTIC <- 2 * sum(x * log(x / E)) # sum((abs(x - E) - YATES)^2/E) for chisq.test
|
||||
PARAMETER <- (nr - 1L) * (nc - 1L)
|
||||
PVAL <- pchisq(STATISTIC, PARAMETER, lower.tail = FALSE)
|
||||
# }
|
||||
}
|
||||
else {
|
||||
if (length(dim(x)) > 2L)
|
||||
stop("invalid 'x'")
|
||||
if (length(x) == 1L)
|
||||
stop("'x' must at least have 2 elements")
|
||||
if (length(x) != length(p))
|
||||
stop("'x' and 'p' must have the same number of elements")
|
||||
if (any(p < 0))
|
||||
stop("probabilities must be non-negative.")
|
||||
if (abs(sum(p) - 1) > sqrt(.Machine$double.eps)) {
|
||||
if (rescale.p)
|
||||
p <- p/sum(p)
|
||||
else stop("probabilities must sum to 1.")
|
||||
}
|
||||
METHOD <- "G-test of goodness-of-fit (likelihood ratio test)"
|
||||
E <- n * p
|
||||
V <- n * p * (1 - p)
|
||||
STATISTIC <- 2 * sum(x * log(x / E)) # sum((x - E)^2/E) for chisq.test
|
||||
names(E) <- names(x)
|
||||
# if (simulate.p.value) {
|
||||
# setMETH()
|
||||
# nx <- length(x)
|
||||
# sm <- matrix(sample.int(nx, B * n, TRUE, prob = p),
|
||||
# nrow = n)
|
||||
# ss <- apply(sm, 2L, function(x, E, k) {
|
||||
# sum((table(factor(x, levels = 1L:k)) - E)^2/E)
|
||||
# }, E = E, k = nx)
|
||||
# PARAMETER <- NA
|
||||
# PVAL <- (1 + sum(ss >= almost.1 * STATISTIC))/(B +
|
||||
# 1)
|
||||
# }
|
||||
# else {
|
||||
PARAMETER <- length(x) - 1
|
||||
PVAL <- pchisq(STATISTIC, PARAMETER, lower.tail = FALSE)
|
||||
# }
|
||||
}
|
||||
names(STATISTIC) <- "X-squared"
|
||||
names(PARAMETER) <- "df"
|
||||
if (any(E < 5) && is.finite(PARAMETER))
|
||||
warning("G-statistic approximation may be incorrect due to E < 5")
|
||||
|
||||
structure(list(statistic = STATISTIC, parameter = PARAMETER,
|
||||
p.value = PVAL, method = METHOD, data.name = DNAME,
|
||||
observed = x, expected = E, residuals = (x - E)/sqrt(E),
|
||||
stdres = (x - E)/sqrt(V)), class = "htest")
|
||||
}
|
||||
@@ -1,90 +0,0 @@
|
||||
# ==================================================================== #
|
||||
# TITLE #
|
||||
# Antimicrobial Resistance (AMR) Analysis #
|
||||
# #
|
||||
# SOURCE #
|
||||
# https://gitlab.com/msberends/AMR #
|
||||
# #
|
||||
# LICENCE #
|
||||
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
|
||||
# #
|
||||
# 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. #
|
||||
# #
|
||||
# This R package was created for academic research and was publicly #
|
||||
# released in the hope that it will be useful, but it comes WITHOUT #
|
||||
# ANY WARRANTY OR LIABILITY. #
|
||||
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
||||
# ==================================================================== #
|
||||
|
||||
#' Translate strings from AMR package
|
||||
#'
|
||||
#' For language-dependent output of AMR functions, like \code{\link{mo_fullname}} and \code{\link{mo_type}}.
|
||||
#' @details Strings will be translated to foreign languages if they are defined in a local translation file. Additions to this file can be suggested at our repository. The file can be found here: \url{https://gitlab.com/msberends/AMR/blob/master/data-raw/translations.tsv}.
|
||||
#'
|
||||
#' Please suggest your own translations \href{https://gitlab.com/msberends/AMR/issues/new?issue[title]=Translation\%20suggestion}{by creating a new issue on our repository}.
|
||||
#'
|
||||
#' This file will be read by all functions where a translated output can be desired, like all \code{\link{mo_property}} functions (\code{\link{mo_fullname}}, \code{\link{mo_type}}, etc.).
|
||||
#'
|
||||
#' The system language will be used at default, if supported, using \code{\link{get_locale}}. The system language can be overwritten with \code{\link{getOption}("AMR_locale")}.
|
||||
#' @inheritSection AMR Read more on our website!
|
||||
#' @rdname translate
|
||||
#' @name translate
|
||||
#' @export
|
||||
#' @examples
|
||||
#' # The 'language' parameter of below functions
|
||||
#' # will be set automatically to your system language
|
||||
#' # with get_locale()
|
||||
#'
|
||||
#' # English
|
||||
#' mo_fullname("CoNS", language = "en")
|
||||
#' #> "Coagulase-negative Staphylococcus (CoNS)"
|
||||
#'
|
||||
#' # German
|
||||
#' mo_fullname("CoNS", language = "de")
|
||||
#' #> "Koagulase-negative Staphylococcus (KNS)"
|
||||
#'
|
||||
#' # Dutch
|
||||
#' mo_fullname("CoNS", language = "nl")
|
||||
#' #> "Coagulase-negatieve Staphylococcus (CNS)"
|
||||
#'
|
||||
#' # Spanish
|
||||
#' mo_fullname("CoNS", language = "es")
|
||||
#' #> "Staphylococcus coagulasa negativo (SCN)"
|
||||
#'
|
||||
#' # Italian
|
||||
#' mo_fullname("CoNS", language = "it")
|
||||
#' #> "Staphylococcus negativo coagulasi (CoNS)"
|
||||
#'
|
||||
#' # Portuguese
|
||||
#' mo_fullname("CoNS", language = "pt")
|
||||
#' #> "Staphylococcus coagulase negativo (CoNS)"
|
||||
get_locale <- function() {
|
||||
if (getOption("AMR_locale", "en") != "en") {
|
||||
return(getOption("AMR_locale"))
|
||||
}
|
||||
|
||||
lang <- Sys.getlocale("LC_COLLATE")
|
||||
# grepl with case = FALSE is faster than like
|
||||
if (grepl("^(English|en_|EN_)", lang, ignore.case = FALSE)) {
|
||||
# as first option to optimise speed
|
||||
"en"
|
||||
} else if (grepl("^(German|Deutsch|de_|DE_)", lang, ignore.case = FALSE)) {
|
||||
"de"
|
||||
} else if (grepl("^(Dutch|Nederlands|nl_|NL_)", lang, ignore.case = FALSE)) {
|
||||
"nl"
|
||||
} else if (grepl("^(Spanish|Espa.ol|es_|ES_)", lang, ignore.case = FALSE)) {
|
||||
"es"
|
||||
} else if (grepl("^(Italian|Italiano|it_|IT_)", lang, ignore.case = FALSE)) {
|
||||
"it"
|
||||
} else if (grepl("^(French|Fran.ais|fr_|FR_)", lang, ignore.case = FALSE)) {
|
||||
"fr"
|
||||
} else if (grepl("^(Portuguese|Portugu.s|pt_|PT_)", lang, ignore.case = FALSE)) {
|
||||
"pt"
|
||||
} else {
|
||||
# other language -> set to English
|
||||
"en"
|
||||
}
|
||||
}
|
||||
@@ -1,444 +0,0 @@
|
||||
# ==================================================================== #
|
||||
# TITLE #
|
||||
# Antimicrobial Resistance (AMR) Analysis #
|
||||
# #
|
||||
# SOURCE #
|
||||
# https://gitlab.com/msberends/AMR #
|
||||
# #
|
||||
# LICENCE #
|
||||
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
|
||||
# #
|
||||
# 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. #
|
||||
# #
|
||||
# This R package was created for academic research and was publicly #
|
||||
# released in the hope that it will be useful, but it comes WITHOUT #
|
||||
# ANY WARRANTY OR LIABILITY. #
|
||||
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
||||
# ==================================================================== #
|
||||
|
||||
#' AMR plots with \code{ggplot2}
|
||||
#'
|
||||
#' Use these functions to create bar plots for antimicrobial resistance analysis. All functions rely on internal \code{\link[ggplot2]{ggplot}2} functions.
|
||||
#' @param data a \code{data.frame} with column(s) of class \code{"rsi"} (see \code{\link{as.rsi}})
|
||||
#' @param position position adjustment of bars, either \code{"fill"} (default when \code{fun} is \code{\link{count_df}}), \code{"stack"} (default when \code{fun} is \code{\link{portion_df}}) or \code{"dodge"}
|
||||
#' @param x variable to show on x axis, either \code{"Antibiotic"} (default) or \code{"Interpretation"} or a grouping variable
|
||||
#' @param fill variable to categorise using the plots legend, either \code{"Antibiotic"} (default) or \code{"Interpretation"} or a grouping variable
|
||||
#' @param breaks numeric vector of positions
|
||||
#' @param limits numeric vector of length two providing limits of the scale, use \code{NA} to refer to the existing minimum or maximum
|
||||
#' @param facet variable to split plots by, either \code{"Interpretation"} (default) or \code{"Antibiotic"} or a grouping variable
|
||||
#' @param fun function to transform \code{data}, either \code{\link{count_df}} (default) or \code{\link{portion_df}}
|
||||
#' @inheritParams portion
|
||||
#' @param nrow (when using \code{facet}) number of rows
|
||||
#' @param colours a named vector with colours for the bars. The names must be one or more of: S, SI, I, IR, R or be \code{FALSE} to use default \code{ggplot2} colours.
|
||||
#' @param datalabels show datalabels using \code{labels_rsi_count}, will only be shown when \code{fun = count_df}
|
||||
#' @param datalabels.size size of the datalabels
|
||||
#' @param datalabels.colour colour of the datalabels
|
||||
#' @param title text to show as title of the plot
|
||||
#' @param subtitle text to show as subtitle of the plot
|
||||
#' @param caption text to show as caption of the plot
|
||||
#' @param x.title text to show as x axis description
|
||||
#' @param y.title text to show as y axis description
|
||||
#' @param ... other parameters passed on to \code{geom_rsi}
|
||||
#' @details At default, the names of antibiotics will be shown on the plots using \code{\link{ab_name}}. This can be set with the \code{translate_ab} parameter. See \code{\link{count_df}}.
|
||||
#'
|
||||
#' \strong{The functions}\cr
|
||||
#' \code{geom_rsi} will take any variable from the data that has an \code{rsi} class (created with \code{\link{as.rsi}}) using \code{fun} (\code{\link{count_df}} at default, can also be \code{\link{portion_df}}) and will plot bars with the percentage R, I and S. The default behaviour is to have the bars stacked and to have the different antibiotics on the x axis.
|
||||
#'
|
||||
#' \code{facet_rsi} creates 2d plots (at default based on S/I/R) using \code{\link[ggplot2]{facet_wrap}}.
|
||||
#'
|
||||
#' \code{scale_y_percent} transforms the y axis to a 0 to 100\% range using \code{\link[ggplot2]{scale_continuous}}.
|
||||
#'
|
||||
#' \code{scale_rsi_colours} sets colours to the bars: pastel blue for S, pastel turquoise for I and pastel red for R, using \code{\link[ggplot2]{scale_brewer}}.
|
||||
#'
|
||||
#' \code{theme_rsi} is a \code{ggplot \link[ggplot2]{theme}} with minimal distraction.
|
||||
#'
|
||||
#' \code{labels_rsi_count} print datalabels on the bars with percentage and amount of isolates using \code{\link[ggplot2]{geom_text}}
|
||||
#'
|
||||
#' \code{ggplot_rsi} is a wrapper around all above functions that uses data as first input. This makes it possible to use this function after a pipe (\code{\%>\%}). See Examples.
|
||||
#' @rdname ggplot_rsi
|
||||
#' @importFrom utils installed.packages
|
||||
#' @export
|
||||
#' @inheritSection AMR Read more on our website!
|
||||
#' @examples
|
||||
#' library(dplyr)
|
||||
#' library(ggplot2)
|
||||
#'
|
||||
#' # get antimicrobial results for drugs against a UTI:
|
||||
#' ggplot(septic_patients %>% select(AMX, NIT, FOS, TMP, CIP)) +
|
||||
#' geom_rsi()
|
||||
#'
|
||||
#' # prettify the plot using some additional functions:
|
||||
#' df <- septic_patients %>% select(AMX, NIT, FOS, TMP, CIP)
|
||||
#' ggplot(df) +
|
||||
#' geom_rsi() +
|
||||
#' scale_y_percent() +
|
||||
#' scale_rsi_colours() +
|
||||
#' labels_rsi_count() +
|
||||
#' theme_rsi()
|
||||
#'
|
||||
#' # or better yet, simplify this using the wrapper function - a single command:
|
||||
#' septic_patients %>%
|
||||
#' select(AMX, NIT, FOS, TMP, CIP) %>%
|
||||
#' ggplot_rsi()
|
||||
#'
|
||||
#' # get only portions and no counts:
|
||||
#' septic_patients %>%
|
||||
#' select(AMX, NIT, FOS, TMP, CIP) %>%
|
||||
#' ggplot_rsi(fun = portion_df)
|
||||
#'
|
||||
#' # add other ggplot2 parameters as you like:
|
||||
#' septic_patients %>%
|
||||
#' select(AMX, NIT, FOS, TMP, CIP) %>%
|
||||
#' ggplot_rsi(width = 0.5,
|
||||
#' colour = "black",
|
||||
#' size = 1,
|
||||
#' linetype = 2,
|
||||
#' alpha = 0.25)
|
||||
#'
|
||||
#' septic_patients %>%
|
||||
#' select(AMX) %>%
|
||||
#' ggplot_rsi(colours = c(SI = "yellow"))
|
||||
#'
|
||||
#' # resistance of ciprofloxacine per age group
|
||||
#' septic_patients %>%
|
||||
#' mutate(first_isolate = first_isolate(.)) %>%
|
||||
#' filter(first_isolate == TRUE,
|
||||
#' mo == as.mo("E. coli")) %>%
|
||||
#' # `age_group` is also a function of this package:
|
||||
#' group_by(age_group = age_groups(age)) %>%
|
||||
#' select(age_group,
|
||||
#' CIP) %>%
|
||||
#' ggplot_rsi(x = "age_group")
|
||||
#' \donttest{
|
||||
#'
|
||||
#' # for colourblind mode, use divergent colours from the viridis package:
|
||||
#' septic_patients %>%
|
||||
#' select(AMX, NIT, FOS, TMP, CIP) %>%
|
||||
#' ggplot_rsi() + scale_fill_viridis_d()
|
||||
#' # a shorter version which also adjusts data label colours:
|
||||
#' septic_patients %>%
|
||||
#' select(AMX, NIT, FOS, TMP, CIP) %>%
|
||||
#' ggplot_rsi(colours = FALSE)
|
||||
#'
|
||||
#'
|
||||
#' # it also supports groups (don't forget to use the group var on `x` or `facet`):
|
||||
#' septic_patients %>%
|
||||
#' select(hospital_id, AMX, NIT, FOS, TMP, CIP) %>%
|
||||
#' group_by(hospital_id) %>%
|
||||
#' ggplot_rsi(x = "hospital_id",
|
||||
#' facet = "Antibiotic",
|
||||
#' nrow = 1,
|
||||
#' title = "AMR of Anti-UTI Drugs Per Hospital",
|
||||
#' x.title = "Hospital",
|
||||
#' datalabels = FALSE)
|
||||
#'
|
||||
#' # genuine analysis: check 3 most prevalent microorganisms
|
||||
#' septic_patients %>%
|
||||
#' # create new bacterial ID's, with all CoNS under the same group (Becker et al.)
|
||||
#' mutate(mo = as.mo(mo, Becker = TRUE)) %>%
|
||||
#' # filter on top three bacterial ID's
|
||||
#' filter(mo %in% top_freq(freq(.$mo), 3)) %>%
|
||||
#' # filter on first isolates
|
||||
#' filter_first_isolate() %>%
|
||||
#' # get short MO names (like "E. coli")
|
||||
#' mutate(bug = mo_shortname(mo, Becker = TRUE)) %>%
|
||||
#' # select this short name and some antiseptic drugs
|
||||
#' select(bug, CXM, GEN, CIP) %>%
|
||||
#' # group by MO
|
||||
#' group_by(bug) %>%
|
||||
#' # plot the thing, putting MOs on the facet
|
||||
#' ggplot_rsi(x = "Antibiotic",
|
||||
#' facet = "bug",
|
||||
#' translate_ab = FALSE,
|
||||
#' nrow = 1,
|
||||
#' title = "AMR of Top Three Microorganisms In Blood Culture Isolates",
|
||||
#' subtitle = expression(paste("Only First Isolates, CoNS grouped according to Becker ",
|
||||
#' italic("et al."), " (2014)")),
|
||||
#' x.title = "Antibiotic (EARS-Net code)")
|
||||
#' }
|
||||
ggplot_rsi <- function(data,
|
||||
position = NULL,
|
||||
x = "Antibiotic",
|
||||
fill = "Interpretation",
|
||||
# params = list(),
|
||||
facet = NULL,
|
||||
breaks = seq(0, 1, 0.1),
|
||||
limits = NULL,
|
||||
translate_ab = "name",
|
||||
combine_SI = TRUE,
|
||||
combine_IR = FALSE,
|
||||
language = get_locale(),
|
||||
fun = count_df,
|
||||
nrow = NULL,
|
||||
colours = c(S = "#61a8ff",
|
||||
SI = "#61a8ff",
|
||||
I = "#61f7ff",
|
||||
IR = "#ff6961",
|
||||
R = "#ff6961"),
|
||||
datalabels = TRUE,
|
||||
datalabels.size = 2.5,
|
||||
datalabels.colour = "gray15",
|
||||
title = NULL,
|
||||
subtitle = NULL,
|
||||
caption = NULL,
|
||||
x.title = NULL,
|
||||
y.title = NULL,
|
||||
...) {
|
||||
|
||||
stopifnot_installed_package("ggplot2")
|
||||
|
||||
fun_name <- deparse(substitute(fun))
|
||||
if (!fun_name %in% c("portion_df", "count_df")) {
|
||||
stop("`fun` must be portion_df or count_df")
|
||||
}
|
||||
|
||||
x <- x[1]
|
||||
facet <- facet[1]
|
||||
|
||||
# we work with aes_string later on
|
||||
x_deparse <- deparse(substitute(x))
|
||||
if (x_deparse != "x") {
|
||||
x <- x_deparse
|
||||
}
|
||||
if (x %like% '".*"') {
|
||||
x <- substr(x, 2, nchar(x) - 1)
|
||||
}
|
||||
facet_deparse <- deparse(substitute(facet))
|
||||
if (facet_deparse != "facet") {
|
||||
facet <- facet_deparse
|
||||
}
|
||||
if (facet %like% '".*"') {
|
||||
facet <- substr(facet, 2, nchar(facet) - 1)
|
||||
}
|
||||
if (facet %in% c("NULL", "")) {
|
||||
facet <- NULL
|
||||
}
|
||||
|
||||
if (is.null(position)) {
|
||||
position <- "fill"
|
||||
}
|
||||
|
||||
p <- ggplot2::ggplot(data = data) +
|
||||
geom_rsi(position = position, x = x, fill = fill, translate_ab = translate_ab,
|
||||
fun = fun, combine_SI = combine_SI, combine_IR = combine_IR, ...) +
|
||||
theme_rsi()
|
||||
|
||||
if (fill == "Interpretation") {
|
||||
# set RSI colours
|
||||
if (isFALSE(colours) & missing(datalabels.colour)) {
|
||||
# set datalabel colour to middle gray
|
||||
datalabels.colour <- "gray50"
|
||||
}
|
||||
p <- p + scale_rsi_colours(colours = colours)
|
||||
}
|
||||
|
||||
if (fun_name == "portion_df"
|
||||
| (fun_name == "count_df" & identical(position, "fill"))) {
|
||||
# portions, so use y scale with percentage
|
||||
p <- p + scale_y_percent(breaks = breaks, limits = limits)
|
||||
}
|
||||
|
||||
if (fun_name == "count_df" & datalabels == TRUE) {
|
||||
p <- p + labels_rsi_count(position = position,
|
||||
x = x,
|
||||
translate_ab = translate_ab,
|
||||
combine_SI = combine_SI,
|
||||
combine_IR = combine_IR,
|
||||
datalabels.size = datalabels.size,
|
||||
datalabels.colour = datalabels.colour)
|
||||
}
|
||||
|
||||
if (!is.null(facet)) {
|
||||
p <- p + facet_rsi(facet = facet, nrow = nrow)
|
||||
}
|
||||
|
||||
p <- p + ggplot2::labs(title = title,
|
||||
subtitle = subtitle,
|
||||
caption = caption,
|
||||
x = x.title,
|
||||
y = y.title)
|
||||
|
||||
p
|
||||
}
|
||||
|
||||
#' @rdname ggplot_rsi
|
||||
#' @export
|
||||
geom_rsi <- function(position = NULL,
|
||||
x = c("Antibiotic", "Interpretation"),
|
||||
fill = "Interpretation",
|
||||
translate_ab = "name",
|
||||
language = get_locale(),
|
||||
combine_SI = TRUE,
|
||||
combine_IR = FALSE,
|
||||
fun = count_df,
|
||||
...) {
|
||||
|
||||
stopifnot_installed_package("ggplot2")
|
||||
|
||||
if (is.data.frame(position)) {
|
||||
stop("`position` is invalid. Did you accidentally use '%>%' instead of '+'?", call. = FALSE)
|
||||
}
|
||||
|
||||
fun_name <- deparse(substitute(fun))
|
||||
if (!fun_name %in% c("portion_df", "count_df", "fun")) {
|
||||
stop("`fun` must be portion_df or count_df")
|
||||
}
|
||||
y <- "Value"
|
||||
if (identical(fun, count_df)) {
|
||||
if (missing(position) | is.null(position)) {
|
||||
position <- "fill"
|
||||
}
|
||||
} else {
|
||||
if (missing(position) | is.null(position)) {
|
||||
position <- "stack"
|
||||
}
|
||||
}
|
||||
|
||||
if (identical(position, "fill")) {
|
||||
position <- ggplot2::position_fill(vjust = 0.5, reverse = TRUE)
|
||||
}
|
||||
|
||||
x <- x[1]
|
||||
|
||||
# we work with aes_string later on
|
||||
x_deparse <- deparse(substitute(x))
|
||||
if (x_deparse != "x") {
|
||||
x <- x_deparse
|
||||
}
|
||||
if (x %like% '".*"') {
|
||||
x <- substr(x, 2, nchar(x) - 1)
|
||||
}
|
||||
|
||||
if (tolower(x) %in% tolower(c('ab', 'antibiotic', 'abx', 'antibiotics'))) {
|
||||
x <- "Antibiotic"
|
||||
} else if (tolower(x) %in% tolower(c('SIR', 'RSI', 'interpretation', 'interpretations', 'result'))) {
|
||||
x <- "Interpretation"
|
||||
}
|
||||
|
||||
ggplot2::layer(geom = "bar", stat = "identity", position = position,
|
||||
mapping = ggplot2::aes_string(x = x, y = y, fill = fill),
|
||||
params = list(...), data = function(x) {
|
||||
fun(data = x,
|
||||
translate_ab = translate_ab,
|
||||
language = language,
|
||||
combine_SI = combine_SI,
|
||||
combine_IR = combine_IR)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
#' @rdname ggplot_rsi
|
||||
#' @export
|
||||
facet_rsi <- function(facet = c("Interpretation", "Antibiotic"), nrow = NULL) {
|
||||
|
||||
stopifnot_installed_package("ggplot2")
|
||||
|
||||
facet <- facet[1]
|
||||
|
||||
# we work with aes_string later on
|
||||
facet_deparse <- deparse(substitute(facet))
|
||||
if (facet_deparse != "facet") {
|
||||
facet <- facet_deparse
|
||||
}
|
||||
if (facet %like% '".*"') {
|
||||
facet <- substr(facet, 2, nchar(facet) - 1)
|
||||
}
|
||||
|
||||
if (tolower(facet) %in% tolower(c('SIR', 'RSI', 'interpretation', 'interpretations', 'result'))) {
|
||||
facet <- "Interpretation"
|
||||
} else if (tolower(facet) %in% tolower(c('ab', 'antibiotic', 'abx', 'antibiotics'))) {
|
||||
facet <- "Antibiotic"
|
||||
}
|
||||
|
||||
ggplot2::facet_wrap(facets = facet, scales = "free_x", nrow = nrow)
|
||||
}
|
||||
|
||||
#' @rdname ggplot_rsi
|
||||
#' @export
|
||||
scale_y_percent <- function(breaks = seq(0, 1, 0.1), limits = NULL) {
|
||||
stopifnot_installed_package("ggplot2")
|
||||
|
||||
if (all(breaks[breaks != 0] > 1)) {
|
||||
breaks <- breaks / 100
|
||||
}
|
||||
ggplot2::scale_y_continuous(breaks = breaks,
|
||||
labels = percent(breaks),
|
||||
limits = limits)
|
||||
}
|
||||
|
||||
#' @rdname ggplot_rsi
|
||||
#' @export
|
||||
scale_rsi_colours <- function(colours = c(S = "#61a8ff",
|
||||
SI = "#61a8ff",
|
||||
I = "#61f7ff",
|
||||
IR = "#ff6961",
|
||||
R = "#ff6961")) {
|
||||
stopifnot_installed_package("ggplot2")
|
||||
#ggplot2::scale_fill_brewer(palette = "RdYlGn")
|
||||
#ggplot2::scale_fill_manual(values = c("#b22222", "#ae9c20", "#7cfc00"))
|
||||
|
||||
if (!identical(colours, FALSE)) {
|
||||
original_cols <- c(S = "#61a8ff",
|
||||
SI = "#61a8ff",
|
||||
I = "#61f7ff",
|
||||
IR = "#ff6961",
|
||||
R = "#ff6961")
|
||||
colours <- replace(original_cols, names(colours), colours)
|
||||
ggplot2::scale_fill_manual(values = colours)
|
||||
}
|
||||
}
|
||||
|
||||
#' @rdname ggplot_rsi
|
||||
#' @export
|
||||
theme_rsi <- function() {
|
||||
stopifnot_installed_package("ggplot2")
|
||||
ggplot2::theme_minimal(base_size = 10) +
|
||||
ggplot2::theme(panel.grid.major.x = ggplot2::element_blank(),
|
||||
panel.grid.minor = ggplot2::element_blank(),
|
||||
panel.grid.major.y = ggplot2::element_line(colour = "grey75"),
|
||||
# center title and subtitle
|
||||
plot.title = ggplot2::element_text(hjust = 0.5),
|
||||
plot.subtitle = ggplot2::element_text(hjust = 0.5))
|
||||
}
|
||||
|
||||
#' @rdname ggplot_rsi
|
||||
#' @importFrom dplyr mutate %>% group_by_at
|
||||
#' @export
|
||||
labels_rsi_count <- function(position = NULL,
|
||||
x = "Antibiotic",
|
||||
translate_ab = "name",
|
||||
combine_SI = TRUE,
|
||||
combine_IR = FALSE,
|
||||
datalabels.size = 3,
|
||||
datalabels.colour = "gray15") {
|
||||
stopifnot_installed_package("ggplot2")
|
||||
if (is.null(position)) {
|
||||
position <- "fill"
|
||||
}
|
||||
if (identical(position, "fill")) {
|
||||
position <- ggplot2::position_fill(vjust = 0.5, reverse = TRUE)
|
||||
}
|
||||
x_name <- x
|
||||
ggplot2::geom_text(mapping = ggplot2::aes_string(label = "lbl",
|
||||
x = x,
|
||||
y = "Value"),
|
||||
position = position,
|
||||
inherit.aes = FALSE,
|
||||
size = datalabels.size,
|
||||
colour = datalabels.colour,
|
||||
lineheight = 0.75,
|
||||
data = function(x) {
|
||||
# labels are only shown when function is count_df,
|
||||
# so no need parameterise it here
|
||||
count_df(data = x,
|
||||
translate_ab = translate_ab,
|
||||
combine_SI = combine_SI,
|
||||
combine_IR = combine_IR) %>%
|
||||
group_by_at(x_name) %>%
|
||||
mutate(lbl = paste0(percent(Value / sum(Value, na.rm = TRUE), force_zero = TRUE),
|
||||
"\n(n=", Value, ")"))
|
||||
})
|
||||
}
|
||||
@@ -1,126 +0,0 @@
|
||||
# ==================================================================== #
|
||||
# TITLE #
|
||||
# Antimicrobial Resistance (AMR) Analysis #
|
||||
# #
|
||||
# SOURCE #
|
||||
# https://gitlab.com/msberends/AMR #
|
||||
# #
|
||||
# LICENCE #
|
||||
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
|
||||
# #
|
||||
# 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. #
|
||||
# #
|
||||
# This R package was created for academic research and was publicly #
|
||||
# released in the hope that it will be useful, but it comes WITHOUT #
|
||||
# ANY WARRANTY OR LIABILITY. #
|
||||
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
||||
# ==================================================================== #
|
||||
|
||||
globalVariables(c(".",
|
||||
"..property",
|
||||
"ab",
|
||||
"abbreviations",
|
||||
"mdr",
|
||||
"mono_count",
|
||||
"second",
|
||||
"xdr",
|
||||
"antibiotic",
|
||||
"Antibiotic",
|
||||
"antibiotics",
|
||||
"atc",
|
||||
"authors",
|
||||
"Becker",
|
||||
"CNS_CPS",
|
||||
"cnt",
|
||||
"col_id",
|
||||
"count",
|
||||
"count.x",
|
||||
"count.y",
|
||||
"cum_count",
|
||||
"cum_percent",
|
||||
"date_lab",
|
||||
"diff.percent",
|
||||
"fctlvl",
|
||||
"First name",
|
||||
"first_isolate_row_index",
|
||||
"Freq",
|
||||
"fullname",
|
||||
"fullname_lower",
|
||||
"genus",
|
||||
"gramstain",
|
||||
"index",
|
||||
"input",
|
||||
"Interpretation",
|
||||
"item",
|
||||
"key_ab",
|
||||
"key_ab_lag",
|
||||
"key_ab_other",
|
||||
"kingdom",
|
||||
"labs",
|
||||
"Lancefield",
|
||||
"lang",
|
||||
"Last name",
|
||||
"lbl",
|
||||
"lookup",
|
||||
"median",
|
||||
"mic",
|
||||
"microorganisms",
|
||||
"microorganisms.codes",
|
||||
"microorganisms.old",
|
||||
"microorganisms.oldDT",
|
||||
"microorganisms.prevDT",
|
||||
"microorganisms.unprevDT",
|
||||
"microorganismsDT",
|
||||
"mo",
|
||||
"mo.old",
|
||||
"more_than_episode_ago",
|
||||
"MPM",
|
||||
"n",
|
||||
"name",
|
||||
"new",
|
||||
"observations",
|
||||
"observed",
|
||||
"official",
|
||||
"old",
|
||||
"other_pat_or_mo",
|
||||
"package_v",
|
||||
"Pasted",
|
||||
"patient_id",
|
||||
"phylum",
|
||||
"plural",
|
||||
"prevalence",
|
||||
"prevalent",
|
||||
"property",
|
||||
"psae",
|
||||
"R",
|
||||
"real_first_isolate",
|
||||
"ref",
|
||||
"reference.rule",
|
||||
"reference.rule_group",
|
||||
"rsi",
|
||||
"rule_group",
|
||||
"rule_name",
|
||||
"S",
|
||||
"se_max",
|
||||
"se_min",
|
||||
"septic_patients",
|
||||
"Sex",
|
||||
"shortname",
|
||||
"species",
|
||||
"species_id",
|
||||
"subspecies",
|
||||
"synonyms",
|
||||
"trade_name",
|
||||
"trans",
|
||||
"transmute",
|
||||
"tsn",
|
||||
"tsn_new",
|
||||
"txt",
|
||||
"value",
|
||||
"Value",
|
||||
"x",
|
||||
"y",
|
||||
"year"))
|
||||
@@ -1,106 +0,0 @@
|
||||
# ==================================================================== #
|
||||
# TITLE #
|
||||
# Antimicrobial Resistance (AMR) Analysis #
|
||||
# #
|
||||
# SOURCE #
|
||||
# https://gitlab.com/msberends/AMR #
|
||||
# #
|
||||
# LICENCE #
|
||||
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
|
||||
# #
|
||||
# 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. #
|
||||
# #
|
||||
# This R package was created for academic research and was publicly #
|
||||
# released in the hope that it will be useful, but it comes WITHOUT #
|
||||
# ANY WARRANTY OR LIABILITY. #
|
||||
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
||||
# ==================================================================== #
|
||||
|
||||
#' Guess antibiotic column
|
||||
#'
|
||||
#' This tries to find a column name in a data set based on information from the \code{\link{antibiotics}} data set. Also supports WHONET abbreviations.
|
||||
#' @param x a \code{data.frame}
|
||||
#' @param search_string a text to search \code{x} for
|
||||
#' @param verbose a logical to indicate whether additional info should be printed
|
||||
#' @details You can look for an antibiotic (trade) name or abbreviation and it will search \code{x} and the \code{\link{antibiotics}} data set for any column containing a name or ATC code of that antibiotic. \strong{Longer columns names take precendence over shorter column names.}
|
||||
#' @importFrom dplyr %>% select filter_all any_vars
|
||||
#' @importFrom crayon blue
|
||||
#' @return A column name of \code{x}, or \code{NULL} when no result is found.
|
||||
#' @export
|
||||
#' @inheritSection AMR Read more on our website!
|
||||
#' @examples
|
||||
#' df <- data.frame(amox = "S",
|
||||
#' tetr = "R")
|
||||
#'
|
||||
#' guess_ab_col(df, "amoxicillin")
|
||||
#' # [1] "amox"
|
||||
#' guess_ab_col(df, "J01AA07") # ATC code of tetracycline
|
||||
#' # [1] "tetr"
|
||||
#'
|
||||
#' guess_ab_col(df, "J01AA07", verbose = TRUE)
|
||||
#' # Note: Using column `tetr` as input for "J01AA07".
|
||||
#' # [1] "tetr"
|
||||
#'
|
||||
#' # WHONET codes
|
||||
#' df <- data.frame(AMP_ND10 = "R",
|
||||
#' AMC_ED20 = "S")
|
||||
#' guess_ab_col(df, "ampicillin")
|
||||
#' # [1] "AMP_ND10"
|
||||
#' guess_ab_col(df, "J01CR02")
|
||||
#' # [1] "AMC_ED20"
|
||||
#' guess_ab_col(df, as.ab("augmentin"))
|
||||
#' # [1] "AMC_ED20"
|
||||
#'
|
||||
#' # Longer names take precendence:
|
||||
#' df <- data.frame(AMP_ED2 = "S",
|
||||
#' AMP_ED20 = "S")
|
||||
#' guess_ab_col(df, "ampicillin")
|
||||
#' # [1] "AMP_ED20"
|
||||
guess_ab_col <- function(x = NULL, search_string = NULL, verbose = FALSE) {
|
||||
if (is.null(x) & is.null(search_string)) {
|
||||
return(as.name("guess_ab_col"))
|
||||
}
|
||||
if (!is.data.frame(x)) {
|
||||
stop("`x` must be a data.frame")
|
||||
}
|
||||
|
||||
if (length(search_string) > 1) {
|
||||
warning("argument 'search_string' has length > 1 and only the first element will be used")
|
||||
search_string <- search_string[1]
|
||||
}
|
||||
search_string <- as.character(search_string)
|
||||
|
||||
if (search_string %in% colnames(x)) {
|
||||
ab_result <- search_string
|
||||
} else {
|
||||
search_string.ab <- suppressWarnings(as.ab(search_string))
|
||||
if (search_string.ab %in% colnames(x)) {
|
||||
ab_result <- colnames(x)[colnames(x) == search_string.ab][1L]
|
||||
} else {
|
||||
# sort colnames on length - longest first
|
||||
cols <- colnames(x[, x %>% colnames() %>% nchar() %>% order() %>% rev()])
|
||||
df_trans <- data.frame(cols = cols,
|
||||
abs = suppressWarnings(as.ab(cols)),
|
||||
stringsAsFactors = FALSE)
|
||||
ab_result <- df_trans[which(df_trans$abs == search_string.ab), "cols"]
|
||||
ab_result <- ab_result[!is.na(ab_result)][1L]
|
||||
}
|
||||
}
|
||||
|
||||
if (length(ab_result) == 0) {
|
||||
if (verbose == TRUE) {
|
||||
message(paste0("No column found as input for `", search_string,
|
||||
"` (", ab_name(search_string, language = "en", tolower = TRUE), ")."))
|
||||
}
|
||||
return(NULL)
|
||||
} else {
|
||||
if (verbose == TRUE) {
|
||||
message(blue(paste0("NOTE: Using column `", bold(ab_result), "` as input for `", search_string,
|
||||
"` (", ab_name(search_string, language = "en", tolower = TRUE), ").")))
|
||||
}
|
||||
return(ab_result)
|
||||
}
|
||||
}
|
||||
@@ -1,158 +0,0 @@
|
||||
# ==================================================================== #
|
||||
# TITLE #
|
||||
# Antimicrobial Resistance (AMR) Analysis #
|
||||
# #
|
||||
# SOURCE #
|
||||
# https://gitlab.com/msberends/AMR #
|
||||
# #
|
||||
# LICENCE #
|
||||
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
|
||||
# #
|
||||
# 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. #
|
||||
# #
|
||||
# This R package was created for academic research and was publicly #
|
||||
# released in the hope that it will be useful, but it comes WITHOUT #
|
||||
# ANY WARRANTY OR LIABILITY. #
|
||||
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
||||
# ==================================================================== #
|
||||
|
||||
#' Join a table with \code{microorganisms}
|
||||
#'
|
||||
#' Join the dataset \code{\link{microorganisms}} easily to an existing table or character vector.
|
||||
#' @rdname join
|
||||
#' @name join
|
||||
#' @aliases join inner_join
|
||||
#' @param x existing table to join, or character vector
|
||||
#' @param by a variable to join by - if left empty will search for a column with class \code{mo} (created with \code{\link{as.mo}}) or will be \code{"mo"} if that column name exists in \code{x}, could otherwise be a column name of \code{x} with values that exist in \code{microorganisms$mo} (like \code{by = "bacteria_id"}), or another column in \code{\link{microorganisms}} (but then it should be named, like \code{by = c("my_genus_species" = "fullname")})
|
||||
#' @param suffix if there are non-joined duplicate variables in \code{x} and \code{y}, these suffixes will be added to the output to disambiguate them. Should be a character vector of length 2.
|
||||
#' @param ... other parameters to pass on to \code{dplyr::\link[dplyr]{join}}.
|
||||
#' @details \strong{Note:} As opposed to the \code{\link[dplyr]{join}} functions of \code{dplyr}, characters vectors are supported and at default existing columns will get a suffix \code{"2"} and the newly joined columns will not get a suffix. See \code{\link[dplyr]{join}} for more information.
|
||||
#' @inheritSection AMR Read more on our website!
|
||||
#' @export
|
||||
#' @examples
|
||||
#' left_join_microorganisms(as.mo("K. pneumoniae"))
|
||||
#' left_join_microorganisms("B_KLBSL_PNE")
|
||||
#'
|
||||
#' library(dplyr)
|
||||
#' septic_patients %>% left_join_microorganisms()
|
||||
#'
|
||||
#' df <- data.frame(date = seq(from = as.Date("2018-01-01"),
|
||||
#' to = as.Date("2018-01-07"),
|
||||
#' by = 1),
|
||||
#' bacteria = as.mo(c("S. aureus", "MRSA", "MSSA", "STAAUR",
|
||||
#' "E. coli", "E. coli", "E. coli")),
|
||||
#' stringsAsFactors = FALSE)
|
||||
#' colnames(df)
|
||||
#' df_joined <- left_join_microorganisms(df, "bacteria")
|
||||
#' colnames(df_joined)
|
||||
inner_join_microorganisms <- function(x, by = NULL, suffix = c("2", ""), ...) {
|
||||
checked <- joins_check_df(x, by)
|
||||
x <- checked$x
|
||||
by <- checked$by
|
||||
join <- suppressWarnings(
|
||||
dplyr::inner_join(x = x, y = AMR::microorganisms, by = by, suffix = suffix, ...)
|
||||
)
|
||||
if (nrow(join) > nrow(x)) {
|
||||
warning('The newly joined tbl contains ', nrow(join) - nrow(x), ' rows more that its original.')
|
||||
}
|
||||
join
|
||||
}
|
||||
|
||||
#' @rdname join
|
||||
#' @export
|
||||
left_join_microorganisms <- function(x, by = NULL, suffix = c("2", ""), ...) {
|
||||
checked <- joins_check_df(x, by)
|
||||
x <- checked$x
|
||||
by <- checked$by
|
||||
join <- suppressWarnings(
|
||||
dplyr::left_join(x = x, y = AMR::microorganisms, by = by, suffix = suffix, ...)
|
||||
)
|
||||
if (nrow(join) > nrow(x)) {
|
||||
warning('The newly joined tbl contains ', nrow(join) - nrow(x), ' rows more that its original.')
|
||||
}
|
||||
join
|
||||
}
|
||||
|
||||
#' @rdname join
|
||||
#' @export
|
||||
right_join_microorganisms <- function(x, by = NULL, suffix = c("2", ""), ...) {
|
||||
checked <- joins_check_df(x, by)
|
||||
x <- checked$x
|
||||
by <- checked$by
|
||||
join <- suppressWarnings(
|
||||
dplyr::right_join(x = x, y = AMR::microorganisms, by = by, suffix = suffix, ...)
|
||||
)
|
||||
if (nrow(join) > nrow(x)) {
|
||||
warning('The newly joined tbl contains ', nrow(join) - nrow(x), ' rows more that its original.')
|
||||
}
|
||||
join
|
||||
}
|
||||
|
||||
#' @rdname join
|
||||
#' @export
|
||||
full_join_microorganisms <- function(x, by = NULL, suffix = c("2", ""), ...) {
|
||||
checked <- joins_check_df(x, by)
|
||||
x <- checked$x
|
||||
by <- checked$by
|
||||
join <- suppressWarnings(
|
||||
dplyr::full_join(x = x, y = AMR::microorganisms, by = by, suffix = suffix, ...)
|
||||
)
|
||||
if (nrow(join) > nrow(x)) {
|
||||
warning('The newly joined tbl contains ', nrow(join) - nrow(x), ' rows more that its original.')
|
||||
}
|
||||
join
|
||||
}
|
||||
|
||||
#' @rdname join
|
||||
#' @export
|
||||
semi_join_microorganisms <- function(x, by = NULL, ...) {
|
||||
checked <- joins_check_df(x, by)
|
||||
x <- checked$x
|
||||
by <- checked$by
|
||||
suppressWarnings(
|
||||
dplyr::semi_join(x = x, y = AMR::microorganisms, by = by, ...)
|
||||
)
|
||||
}
|
||||
|
||||
#' @rdname join
|
||||
#' @export
|
||||
anti_join_microorganisms <- function(x, by = NULL, ...) {
|
||||
checked <- joins_check_df(x, by)
|
||||
x <- checked$x
|
||||
by <- checked$by
|
||||
suppressWarnings(
|
||||
dplyr::anti_join(x = x, y = AMR::microorganisms, by = by, ...)
|
||||
)
|
||||
}
|
||||
|
||||
joins_check_df <- function(x, by) {
|
||||
if (!any(class(x) %in% c("data.frame", "matrix"))) {
|
||||
x <- data.frame(mo = as.character(x), stringsAsFactors = FALSE)
|
||||
if (is.null(by)) {
|
||||
by <- "mo"
|
||||
}
|
||||
}
|
||||
if (is.null(by)) {
|
||||
# search for column with class `mo` and return first one found
|
||||
by <- colnames(x)[lapply(x, is.mo) == TRUE][1]
|
||||
if (is.na(by)) {
|
||||
if ("mo" %in% colnames(x)) {
|
||||
by <- "mo"
|
||||
} else {
|
||||
stop("Cannot join - no column found with name or class `mo`.", call. = FALSE)
|
||||
}
|
||||
}
|
||||
message('Joining, by = "', by, '"') # message same as dplyr::join functions
|
||||
}
|
||||
if (is.null(names(by))) {
|
||||
joinby <- colnames(AMR::microorganisms)[1]
|
||||
names(joinby) <- by
|
||||
} else {
|
||||
joinby <- by
|
||||
}
|
||||
list(x = x,
|
||||
by = joinby)
|
||||
}
|
||||
@@ -1,306 +0,0 @@
|
||||
# ==================================================================== #
|
||||
# TITLE #
|
||||
# Antimicrobial Resistance (AMR) Analysis #
|
||||
# #
|
||||
# SOURCE #
|
||||
# https://gitlab.com/msberends/AMR #
|
||||
# #
|
||||
# LICENCE #
|
||||
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
|
||||
# #
|
||||
# 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. #
|
||||
# #
|
||||
# This R package was created for academic research and was publicly #
|
||||
# released in the hope that it will be useful, but it comes WITHOUT #
|
||||
# ANY WARRANTY OR LIABILITY. #
|
||||
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
||||
# ==================================================================== #
|
||||
|
||||
#' Key antibiotics for first \emph{weighted} isolates
|
||||
#'
|
||||
#' These function can be used to determine first isolates (see \code{\link{first_isolate}}). Using key antibiotics to determine first isolates is more reliable than without key antibiotics. These selected isolates will then be called first \emph{weighted} isolates.
|
||||
#' @param x table with antibiotics coloms, like \code{AMX} or \code{amox}
|
||||
#' @param y,z characters to compare
|
||||
#' @inheritParams first_isolate
|
||||
#' @param universal_1,universal_2,universal_3,universal_4,universal_5,universal_6 column names of \strong{broad-spectrum} antibiotics, case-insensitive. At default, the columns containing these antibiotics will be guessed with \code{\link{guess_ab_col}}.
|
||||
#' @param GramPos_1,GramPos_2,GramPos_3,GramPos_4,GramPos_5,GramPos_6 column names of antibiotics for \strong{Gram positives}, case-insensitive. At default, the columns containing these antibiotics will be guessed with \code{\link{guess_ab_col}}.
|
||||
#' @param GramNeg_1,GramNeg_2,GramNeg_3,GramNeg_4,GramNeg_5,GramNeg_6 column names of antibiotics for \strong{Gram negatives}, case-insensitive. At default, the columns containing these antibiotics will be guessed with \code{\link{guess_ab_col}}.
|
||||
#' @param warnings give warning about missing antibiotic columns, they will anyway be ignored
|
||||
#' @param ... other parameters passed on to function
|
||||
#' @details The function \code{key_antibiotics} returns a character vector with 12 antibiotic results for every isolate. These isolates can then be compared using \code{key_antibiotics_equal}, to check if two isolates have generally the same antibiogram. Missing and invalid values are replaced with a dot (\code{"."}). The \code{\link{first_isolate}} function only uses this function on the same microbial species from the same patient. Using this, an MRSA will be included after a susceptible \emph{S. aureus} (MSSA) found within the same episode (see \code{episode} parameter of \code{\link{first_isolate}}). Without key antibiotic comparison it would not.
|
||||
#'
|
||||
#' At default, the antibiotics that are used for \strong{Gram positive bacteria} are (colum names): \cr
|
||||
#' \code{"amox"}, \code{"amcl"}, \code{"cfur"}, \code{"pita"}, \code{"cipr"}, \code{"trsu"} (until here is universal), \code{"vanc"}, \code{"teic"}, \code{"tetr"}, \code{"eryt"}, \code{"oxac"}, \code{"rifa"}.
|
||||
#'
|
||||
#' At default, the antibiotics that are used for \strong{Gram negative bacteria} are (colum names): \cr
|
||||
#' \code{"amox"}, \code{"amcl"}, \code{"cfur"}, \code{"pita"}, \code{"cipr"}, \code{"trsu"} (until here is universal), \code{"gent"}, \code{"tobr"}, \code{"coli"}, \code{"cfot"}, \code{"cfta"}, \code{"mero"}.
|
||||
#'
|
||||
#'
|
||||
#' The function \code{key_antibiotics_equal} checks the characters returned by \code{key_antibiotics} for equality, and returns a logical vector.
|
||||
#' @inheritSection first_isolate Key antibiotics
|
||||
#' @rdname key_antibiotics
|
||||
#' @export
|
||||
#' @importFrom dplyr %>% mutate if_else pull
|
||||
#' @importFrom crayon blue bold
|
||||
#' @seealso \code{\link{first_isolate}}
|
||||
#' @inheritSection AMR Read more on our website!
|
||||
#' @examples
|
||||
#' # septic_patients is a dataset available in the AMR package
|
||||
#' ?septic_patients
|
||||
|
||||
#' library(dplyr)
|
||||
#' # set key antibiotics to a new variable
|
||||
#' my_patients <- septic_patients %>%
|
||||
#' mutate(keyab = key_antibiotics(.)) %>%
|
||||
#' mutate(
|
||||
#' # now calculate first isolates
|
||||
#' first_regular = first_isolate(., col_keyantibiotics = FALSE),
|
||||
#' # and first WEIGHTED isolates
|
||||
#' first_weighted = first_isolate(., col_keyantibiotics = "keyab")
|
||||
#' )
|
||||
#'
|
||||
#' # Check the difference, in this data set it results in 7% more isolates:
|
||||
#' sum(my_patients$first_regular, na.rm = TRUE)
|
||||
#' sum(my_patients$first_weighted, na.rm = TRUE)
|
||||
#'
|
||||
#'
|
||||
#' # output of the `key_antibiotics` function could be like this:
|
||||
#' strainA <- "SSSRR.S.R..S"
|
||||
#' strainB <- "SSSIRSSSRSSS"
|
||||
#'
|
||||
#' key_antibiotics_equal(strainA, strainB)
|
||||
#' # TRUE, because I is ignored (as well as missing values)
|
||||
#'
|
||||
#' key_antibiotics_equal(strainA, strainB, ignore_I = FALSE)
|
||||
#' # FALSE, because I is not ignored and so the 4th value differs
|
||||
key_antibiotics <- function(x,
|
||||
col_mo = NULL,
|
||||
universal_1 = guess_ab_col(x, "AMX"),
|
||||
universal_2 = guess_ab_col(x, "AMC"),
|
||||
universal_3 = guess_ab_col(x, "CXM"),
|
||||
universal_4 = guess_ab_col(x, "TZP"),
|
||||
universal_5 = guess_ab_col(x, "CIP"),
|
||||
universal_6 = guess_ab_col(x, "SXT"),
|
||||
GramPos_1 = guess_ab_col(x, "VAN"),
|
||||
GramPos_2 = guess_ab_col(x, "TEC"),
|
||||
GramPos_3 = guess_ab_col(x, "TCY"),
|
||||
GramPos_4 = guess_ab_col(x, "ERY"),
|
||||
GramPos_5 = guess_ab_col(x, "OXA"),
|
||||
GramPos_6 = guess_ab_col(x, "RIF"),
|
||||
GramNeg_1 = guess_ab_col(x, "GEN"),
|
||||
GramNeg_2 = guess_ab_col(x, "TOB"),
|
||||
GramNeg_3 = guess_ab_col(x, "COL"),
|
||||
GramNeg_4 = guess_ab_col(x, "CTX"),
|
||||
GramNeg_5 = guess_ab_col(x, "CAZ"),
|
||||
GramNeg_6 = guess_ab_col(x, "MEM"),
|
||||
warnings = TRUE,
|
||||
...) {
|
||||
|
||||
# try to find columns based on type
|
||||
# -- mo
|
||||
if (is.null(col_mo)) {
|
||||
col_mo <- search_type_in_df(x = x, type = "mo")
|
||||
}
|
||||
if (is.null(col_mo)) {
|
||||
stop("`col_mo` must be set.", call. = FALSE)
|
||||
}
|
||||
|
||||
# check columns
|
||||
col.list <- c(universal_1, universal_2, universal_3, universal_4, universal_5, universal_6,
|
||||
GramPos_1, GramPos_2, GramPos_3, GramPos_4, GramPos_5, GramPos_6,
|
||||
GramNeg_1, GramNeg_2, GramNeg_3, GramNeg_4, GramNeg_5, GramNeg_6)
|
||||
check_available_columns <- function(x, col.list, info = TRUE) {
|
||||
# check columns
|
||||
col.list <- col.list[!is.na(col.list) & !is.null(col.list)]
|
||||
names(col.list) <- col.list
|
||||
col.list.bak <- col.list
|
||||
# are they available as upper case or lower case then?
|
||||
for (i in 1:length(col.list)) {
|
||||
if (is.null(col.list[i]) | isTRUE(is.na(col.list[i]))) {
|
||||
col.list[i] <- NA
|
||||
} else if (toupper(col.list[i]) %in% colnames(x)) {
|
||||
col.list[i] <- toupper(col.list[i])
|
||||
} else if (tolower(col.list[i]) %in% colnames(x)) {
|
||||
col.list[i] <- tolower(col.list[i])
|
||||
} else if (!col.list[i] %in% colnames(x)) {
|
||||
col.list[i] <- NA
|
||||
}
|
||||
}
|
||||
if (!all(col.list %in% colnames(x))) {
|
||||
if (info == TRUE) {
|
||||
warning('Some columns do not exist and will be ignored: ',
|
||||
col.list.bak[!(col.list %in% colnames(x))] %>% toString(),
|
||||
'.\nTHIS MAY STRONGLY INFLUENCE THE OUTCOME.',
|
||||
immediate. = TRUE,
|
||||
call. = FALSE)
|
||||
}
|
||||
}
|
||||
col.list
|
||||
}
|
||||
|
||||
col.list <- check_available_columns(x = x, col.list = col.list, info = warnings)
|
||||
universal_1 <- col.list[universal_1]
|
||||
universal_2 <- col.list[universal_2]
|
||||
universal_3 <- col.list[universal_3]
|
||||
universal_4 <- col.list[universal_4]
|
||||
universal_5 <- col.list[universal_5]
|
||||
universal_6 <- col.list[universal_6]
|
||||
GramPos_1 <- col.list[GramPos_1]
|
||||
GramPos_2 <- col.list[GramPos_2]
|
||||
GramPos_3 <- col.list[GramPos_3]
|
||||
GramPos_4 <- col.list[GramPos_4]
|
||||
GramPos_5 <- col.list[GramPos_5]
|
||||
GramPos_6 <- col.list[GramPos_6]
|
||||
GramNeg_1 <- col.list[GramNeg_1]
|
||||
GramNeg_2 <- col.list[GramNeg_2]
|
||||
GramNeg_3 <- col.list[GramNeg_3]
|
||||
GramNeg_4 <- col.list[GramNeg_4]
|
||||
GramNeg_5 <- col.list[GramNeg_5]
|
||||
GramNeg_6 <- col.list[GramNeg_6]
|
||||
|
||||
universal <- c(universal_1, universal_2, universal_3,
|
||||
universal_4, universal_5, universal_6)
|
||||
|
||||
gram_positive = c(universal,
|
||||
GramPos_1, GramPos_2, GramPos_3,
|
||||
GramPos_4, GramPos_5, GramPos_6)
|
||||
gram_positive <- gram_positive[!is.null(gram_positive)]
|
||||
gram_positive <- gram_positive[!is.na(gram_positive)]
|
||||
if (length(gram_positive) < 12) {
|
||||
warning("only using ", length(gram_positive), " different antibiotics as key antibiotics for Gram positives. See ?key_antibiotics.", call. = FALSE)
|
||||
}
|
||||
|
||||
gram_negative = c(universal,
|
||||
GramNeg_1, GramNeg_2, GramNeg_3,
|
||||
GramNeg_4, GramNeg_5, GramNeg_6)
|
||||
gram_negative <- gram_negative[!is.null(gram_negative)]
|
||||
gram_negative <- gram_negative[!is.na(gram_negative)]
|
||||
if (length(gram_negative) < 12) {
|
||||
warning("only using ", length(gram_negative), " different antibiotics as key antibiotics for Gram negatives. See ?key_antibiotics.", call. = FALSE)
|
||||
}
|
||||
|
||||
# join to microorganisms data set
|
||||
x <- x %>%
|
||||
mutate_at(vars(col_mo), as.mo) %>%
|
||||
left_join_microorganisms(by = col_mo) %>%
|
||||
mutate(key_ab = NA_character_,
|
||||
gramstain = mo_gramstain(pull(., col_mo)))
|
||||
|
||||
# Gram +
|
||||
x <- x %>% mutate(key_ab =
|
||||
if_else(gramstain == "Gram positive",
|
||||
apply(X = x[, gram_positive],
|
||||
MARGIN = 1,
|
||||
FUN = function(x) paste(x, collapse = "")),
|
||||
key_ab))
|
||||
|
||||
# Gram -
|
||||
x <- x %>% mutate(key_ab =
|
||||
if_else(gramstain == "Gram negative",
|
||||
apply(X = x[, gram_negative],
|
||||
MARGIN = 1,
|
||||
FUN = function(x) paste(x, collapse = "")),
|
||||
key_ab))
|
||||
|
||||
# format
|
||||
key_abs <- x %>%
|
||||
pull(key_ab) %>%
|
||||
gsub('(NA|NULL)', '.', .) %>%
|
||||
gsub('[^SIR]', '.', ., ignore.case = TRUE)
|
||||
|
||||
key_abs
|
||||
|
||||
}
|
||||
|
||||
#' @importFrom dplyr progress_estimated %>%
|
||||
#' @rdname key_antibiotics
|
||||
#' @export
|
||||
key_antibiotics_equal <- function(y,
|
||||
z,
|
||||
type = c("keyantibiotics", "points"),
|
||||
ignore_I = TRUE,
|
||||
points_threshold = 2,
|
||||
info = FALSE) {
|
||||
# y is active row, z is lag
|
||||
x <- y
|
||||
y <- z
|
||||
|
||||
type <- type[1]
|
||||
|
||||
if (length(x) != length(y)) {
|
||||
stop('Length of `x` and `y` must be equal.')
|
||||
}
|
||||
|
||||
# only show progress bar on points or when at least 5000 isolates
|
||||
info_needed <- info == TRUE & (type == "points" | length(x) > 5000)
|
||||
|
||||
result <- logical(length(x))
|
||||
|
||||
if (info_needed == TRUE) {
|
||||
p <- dplyr::progress_estimated(length(x))
|
||||
}
|
||||
|
||||
for (i in 1:length(x)) {
|
||||
|
||||
if (info_needed == TRUE) {
|
||||
p$tick()$print()
|
||||
}
|
||||
|
||||
if (is.na(x[i])) {
|
||||
x[i] <- ''
|
||||
}
|
||||
if (is.na(y[i])) {
|
||||
y[i] <- ''
|
||||
}
|
||||
|
||||
if (x[i] == y[i]) {
|
||||
|
||||
result[i] <- TRUE
|
||||
|
||||
} else if (nchar(x[i]) != nchar(y[i])) {
|
||||
|
||||
result[i] <- FALSE
|
||||
|
||||
} else {
|
||||
|
||||
x_split <- strsplit(x[i], "")[[1]]
|
||||
y_split <- strsplit(y[i], "")[[1]]
|
||||
|
||||
if (type == 'keyantibiotics') {
|
||||
|
||||
if (ignore_I == TRUE) {
|
||||
x_split[x_split == "I"] <- "."
|
||||
y_split[y_split == "I"] <- "."
|
||||
}
|
||||
|
||||
y_split[x_split == "."] <- "."
|
||||
x_split[y_split == "."] <- "."
|
||||
|
||||
result[i] <- all(x_split == y_split)
|
||||
|
||||
} else if (type == 'points') {
|
||||
# count points for every single character:
|
||||
# - no change is 0 points
|
||||
# - I <-> S|R is 0.5 point
|
||||
# - S|R <-> R|S is 1 point
|
||||
# use the levels of as.rsi (S = 1, I = 2, R = 3)
|
||||
|
||||
suppressWarnings(x_split <- x_split %>% as.rsi() %>% as.double())
|
||||
suppressWarnings(y_split <- y_split %>% as.rsi() %>% as.double())
|
||||
|
||||
points <- (x_split - y_split) %>% abs() %>% sum(na.rm = TRUE) / 2
|
||||
result[i] <- points >= points_threshold
|
||||
|
||||
} else {
|
||||
stop('`', type, '` is not a valid value for type, must be "points" or "keyantibiotics". See ?first_isolate.')
|
||||
}
|
||||
}
|
||||
}
|
||||
if (info_needed == TRUE) {
|
||||
cat('\n')
|
||||
}
|
||||
result
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
# ==================================================================== #
|
||||
# TITLE #
|
||||
# Antimicrobial Resistance (AMR) Analysis #
|
||||
# #
|
||||
# SOURCE #
|
||||
# https://gitlab.com/msberends/AMR #
|
||||
# #
|
||||
# LICENCE #
|
||||
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
|
||||
# #
|
||||
# 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. #
|
||||
# #
|
||||
# This R package was created for academic research and was publicly #
|
||||
# released in the hope that it will be useful, but it comes WITHOUT #
|
||||
# ANY WARRANTY OR LIABILITY. #
|
||||
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
||||
# ==================================================================== #
|
||||
|
||||
#' Kurtosis of the sample
|
||||
#'
|
||||
#' @description Kurtosis is a measure of the "tailedness" of the probability distribution of a real-valued random variable.
|
||||
#'
|
||||
#' @param x a vector of values, a \code{matrix} or a \code{data frame}
|
||||
#' @param na.rm a logical value indicating whether \code{NA} values should be stripped before the computation proceeds.
|
||||
#' @exportMethod kurtosis
|
||||
#' @seealso \code{\link{skewness}}
|
||||
#' @rdname kurtosis
|
||||
#' @inheritSection AMR Read more on our website!
|
||||
#' @export
|
||||
kurtosis <- function(x, na.rm = FALSE) {
|
||||
UseMethod("kurtosis")
|
||||
}
|
||||
|
||||
#' @exportMethod kurtosis.default
|
||||
#' @rdname kurtosis
|
||||
#' @export
|
||||
kurtosis.default <- function (x, na.rm = FALSE) {
|
||||
x <- as.vector(x)
|
||||
if (na.rm == TRUE) {
|
||||
x <- x[!is.na(x)]
|
||||
}
|
||||
n <- length(x)
|
||||
n * base::sum((x - base::mean(x, na.rm = na.rm))^4, na.rm = na.rm) /
|
||||
(base::sum((x - base::mean(x, na.rm = na.rm))^2, na.rm = na.rm)^2)
|
||||
}
|
||||
|
||||
#' @exportMethod kurtosis.matrix
|
||||
#' @rdname kurtosis
|
||||
#' @export
|
||||
kurtosis.matrix <- function (x, na.rm = FALSE) {
|
||||
base::apply(x, 2, kurtosis.default, na.rm = na.rm)
|
||||
}
|
||||
|
||||
#' @exportMethod kurtosis.data.frame
|
||||
#' @rdname kurtosis
|
||||
#' @export
|
||||
kurtosis.data.frame <- function (x, na.rm = FALSE) {
|
||||
base::sapply(x, kurtosis.default, na.rm = na.rm)
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
# ==================================================================== #
|
||||
# TITLE #
|
||||
# Antimicrobial Resistance (AMR) Analysis #
|
||||
# #
|
||||
# SOURCE #
|
||||
# https://gitlab.com/msberends/AMR #
|
||||
# #
|
||||
# LICENCE #
|
||||
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
|
||||
# #
|
||||
# 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. #
|
||||
# #
|
||||
# This R package was created for academic research and was publicly #
|
||||
# released in the hope that it will be useful, but it comes WITHOUT #
|
||||
# ANY WARRANTY OR LIABILITY. #
|
||||
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
||||
# ==================================================================== #
|
||||
|
||||
#' Pattern Matching
|
||||
#'
|
||||
#' Convenient wrapper around \code{\link[base]{grep}} to match a pattern: \code{a \%like\% b}. It always returns a \code{logical} vector and is always case-insensitive. Also, \code{pattern} (\code{b}) can be as long as \code{x} (\code{a}) to compare items of each index in both vectors.
|
||||
#' @inheritParams base::grepl
|
||||
#' @return A \code{logical} vector
|
||||
#' @name like
|
||||
#' @rdname like
|
||||
#' @export
|
||||
#' @details Using RStudio? This function can also be inserted from the Addins menu and can have its own Keyboard Shortcut like Ctrl+Shift+L or Cmd+Shift+L (see Tools > Modify Keyboard Shortcuts...).
|
||||
#' @source Idea from the \href{https://github.com/Rdatatable/data.table/blob/master/R/like.R}{\code{like} function from the \code{data.table} package}, but made it case insensitive at default and let it support multiple patterns.
|
||||
#' @seealso \code{\link[base]{grep}}
|
||||
#' @inheritSection AMR Read more on our website!
|
||||
#' @examples
|
||||
#' # simple test
|
||||
#' a <- "This is a test"
|
||||
#' b <- "TEST"
|
||||
#' a %like% b
|
||||
#' #> TRUE
|
||||
#' b %like% a
|
||||
#' #> FALSE
|
||||
#'
|
||||
#' # also supports multiple patterns, length must be equal to x
|
||||
#' a <- c("Test case", "Something different", "Yet another thing")
|
||||
#' b <- c("case", "diff", "yet")
|
||||
#' a %like% b
|
||||
#' #> TRUE TRUE TRUE
|
||||
#'
|
||||
#' # get frequencies of bacteria whose name start with 'Ent' or 'ent'
|
||||
#' library(dplyr)
|
||||
#' septic_patients %>%
|
||||
#' left_join_microorganisms() %>%
|
||||
#' filter(genus %like% '^ent') %>%
|
||||
#' freq(genus, species)
|
||||
like <- function(x, pattern) {
|
||||
if (length(pattern) > 1) {
|
||||
if (length(x) != length(pattern)) {
|
||||
pattern <- pattern[1]
|
||||
warning('only the first element of argument `pattern` used for `%like%`', call. = TRUE)
|
||||
} else {
|
||||
# x and pattern are of same length, so items with each other
|
||||
res <- vector(length = length(pattern))
|
||||
for (i in 1:length(res)) {
|
||||
if (is.factor(x[i])) {
|
||||
res[i] <- as.integer(x[i]) %in% base::grep(pattern[i], levels(x[i]), ignore.case = TRUE)
|
||||
} else {
|
||||
res[i] <- base::grepl(pattern[i], x[i], ignore.case = TRUE)
|
||||
}
|
||||
}
|
||||
return(res)
|
||||
}
|
||||
}
|
||||
|
||||
# the regular way how grepl works; just one pattern against one or more x
|
||||
if (is.factor(x)) {
|
||||
as.integer(x) %in% base::grep(pattern, levels(x), ignore.case = TRUE)
|
||||
} else {
|
||||
base::grepl(pattern, x, ignore.case = TRUE)
|
||||
}
|
||||
}
|
||||
|
||||
#' @rdname like
|
||||
#' @export
|
||||
"%like%" <- like
|
||||
@@ -1,519 +0,0 @@
|
||||
# ==================================================================== #
|
||||
# TITLE #
|
||||
# Antimicrobial Resistance (AMR) Analysis #
|
||||
# #
|
||||
# SOURCE #
|
||||
# https://gitlab.com/msberends/AMR #
|
||||
# #
|
||||
# LICENCE #
|
||||
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
|
||||
# #
|
||||
# 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. #
|
||||
# #
|
||||
# This R package was created for academic research and was publicly #
|
||||
# released in the hope that it will be useful, but it comes WITHOUT #
|
||||
# ANY WARRANTY OR LIABILITY. #
|
||||
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
||||
# ==================================================================== #
|
||||
|
||||
#' Determine multidrug-resistant organisms (MDRO)
|
||||
#'
|
||||
#' Determine which isolates are multidrug-resistant organisms (MDRO) according to country-specific guidelines.
|
||||
#' @param x table with antibiotic columns, like e.g. \code{AMX} and \code{AMC}
|
||||
#' @param country country code to determine guidelines. Should be or a code from the \href{https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements}{list of ISO 3166-1 alpha-2 country codes}. Case-insensitive.
|
||||
#' @param guideline a specific guideline to mention. For some countries this will be determined automatically, see Details. EUCAST guidelines will be used when left empty, see Details.
|
||||
#' @param info print progress
|
||||
#' @inheritParams eucast_rules
|
||||
#' @param verbose print additional info: missing antibiotic columns per parameter
|
||||
#' @inheritSection eucast_rules Antibiotics
|
||||
#' @details When \code{country} is set, the parameter guideline will be ignored as these guidelines will be used:
|
||||
#'
|
||||
#' \itemize{
|
||||
#' \item{\code{country = "nl"}: Rijksinstituut voor Volksgezondheid en Milieu "WIP-richtlijn BRMO (Bijzonder Resistente Micro-Organismen) [ZKH]" (\href{https://www.rivm.nl/Documenten_en_publicaties/Professioneel_Praktisch/Richtlijnen/Infectieziekten/WIP_Richtlijnen/WIP_Richtlijnen/Ziekenhuizen/WIP_richtlijn_BRMO_Bijzonder_Resistente_Micro_Organismen_ZKH}{link})}
|
||||
#' }
|
||||
#'
|
||||
#' Please suggest your own country's specific guidelines by letting us know: \url{https://gitlab.com/msberends/AMR/issues/new}.
|
||||
#'
|
||||
#' Other currently supported guidelines are:
|
||||
#' \itemize{
|
||||
#' \item{\code{guideline = "eucast"}: EUCAST Expert Rules Version 3.1 "Intrinsic Resistance and Exceptional Phenotypes Tables" (\href{http://www.eucast.org/fileadmin/src/media/PDFs/EUCAST_files/Expert_Rules/Expert_rules_intrinsic_exceptional_V3.1.pdf}{link})}
|
||||
#' \item{\code{guideline = "tb"}: World Health Organization "Companion handbook to the WHO guidelines for the programmatic management of drug-resistant tuberculosis" (\href{https://www.who.int/tb/publications/pmdt_companionhandbook/en/}{link})}
|
||||
#' }
|
||||
#' @return Ordered factor with levels \code{Negative < Positive, unconfirmed < Positive}.
|
||||
#' @rdname mdro
|
||||
#' @importFrom dplyr %>%
|
||||
#' @importFrom crayon red blue bold
|
||||
#' @export
|
||||
#' @inheritSection AMR Read more on our website!
|
||||
#' @examples
|
||||
#' library(dplyr)
|
||||
#'
|
||||
#' septic_patients %>%
|
||||
#' mutate(EUCAST = mdro(.),
|
||||
#' BRMO = brmo(.))
|
||||
mdro <- function(x,
|
||||
country = NULL,
|
||||
guideline = NULL,
|
||||
col_mo = NULL,
|
||||
info = TRUE,
|
||||
verbose = FALSE,
|
||||
...) {
|
||||
|
||||
if (!is.data.frame(x)) {
|
||||
stop("`x` must be a data frame.", call. = FALSE)
|
||||
}
|
||||
|
||||
if (length(guideline) > 1) {
|
||||
stop("`guideline` must be a length one character string.", call. = FALSE)
|
||||
}
|
||||
if (length(country) > 1) {
|
||||
stop("`country` must be a length one character string.", call. = FALSE)
|
||||
}
|
||||
if (!is.null(country)) {
|
||||
guideline <- country
|
||||
}
|
||||
if (is.null(guideline)) {
|
||||
guideline <- "eucast"
|
||||
}
|
||||
if (!tolower(guideline) %in% c("nl", "de", "eucast", "tb")) {
|
||||
stop("invalid guideline: ", guideline, call. = FALSE)
|
||||
}
|
||||
guideline <- list(code = tolower(guideline))
|
||||
|
||||
# try to find columns based on type
|
||||
# -- mo
|
||||
if (is.null(col_mo)) {
|
||||
col_mo <- search_type_in_df(x = x, type = "mo")
|
||||
}
|
||||
if (is.null(col_mo) & guideline$code == "tb") {
|
||||
message(blue("NOTE: No column found as input for `col_mo`,",
|
||||
bold("assuming all records contain",
|
||||
italic("Mycobacterium tuberculosis.\n"))))
|
||||
x$mo <- AMR::as.mo("Mycobacterium tuberculosis")
|
||||
col_mo <- "mo"
|
||||
}
|
||||
if (is.null(col_mo)) {
|
||||
stop("`col_mo` must be set.", call. = FALSE)
|
||||
}
|
||||
|
||||
if (length(country) > 1) {
|
||||
stop("`country` must be a length one character string.", call. = FALSE)
|
||||
}
|
||||
|
||||
if (guideline$code == "eucast") {
|
||||
guideline$name <- "EUCAST Expert Rules, \"Intrinsic Resistance and Exceptional Phenotypes Tables\""
|
||||
guideline$author <- "EUCAST (European Committee on Antimicrobial Susceptibility Testing)"
|
||||
guideline$version <- "3.1"
|
||||
guideline$source <- "http://www.eucast.org/fileadmin/src/media/PDFs/EUCAST_files/Expert_Rules/Expert_rules_intrinsic_exceptional_V3.1.pdf"
|
||||
|
||||
} else if (guideline$code == "tb") {
|
||||
guideline$name <- "Companion handbook to the WHO guidelines for the programmatic management of drug-resistant tuberculosis"
|
||||
guideline$author <- "WHO (World Health Organization)"
|
||||
guideline$version <- "WHO/HTM/TB/2014.11"
|
||||
guideline$source <- "https://www.who.int/tb/publications/pmdt_companionhandbook/en/"
|
||||
|
||||
# support per country:
|
||||
} else if (guideline$code == "de") {
|
||||
guideline$name <- "Germany"
|
||||
guideline$name <- ""
|
||||
guideline$version <- ""
|
||||
guideline$source <- ""
|
||||
} else if (guideline$code == "nl") {
|
||||
guideline$name <- "WIP-Richtlijn Bijzonder Resistente Micro-organismen (BRMO)"
|
||||
guideline$author <- "RIVM (Rijksinstituut voor de Volksgezondheid)"
|
||||
guideline$version <- "Revision as of December 2017"
|
||||
guideline$source <- "https://www.rivm.nl/Documenten_en_publicaties/Professioneel_Praktisch/Richtlijnen/Infectieziekten/WIP_Richtlijnen/WIP_Richtlijnen/Ziekenhuizen/WIP_richtlijn_BRMO_Bijzonder_Resistente_Micro_Organismen_ZKH"
|
||||
# add here more countries like this:
|
||||
# } else if (country$code == "xx") {
|
||||
# country$name <- "country name"
|
||||
} else {
|
||||
stop("This guideline is currently unsupported: ", guideline$code, call. = FALSE)
|
||||
}
|
||||
|
||||
if (info == TRUE) {
|
||||
cat("Determining multidrug-resistant organisms (MDRO), according to:\n",
|
||||
"Guideline: ", red(guideline$name), "\n",
|
||||
"Version: ", red(guideline$version), "\n",
|
||||
"Author: ", red(guideline$author), "\n",
|
||||
"Source: ", blue(guideline$source), "\n",
|
||||
"\n", sep = "")
|
||||
}
|
||||
|
||||
if (guideline$code == "tb") {
|
||||
cols_ab <- get_column_abx(x = x,
|
||||
soft_dependencies = c("CAP",
|
||||
"ETH",
|
||||
"GAT",
|
||||
"INH",
|
||||
"PZA",
|
||||
"RIF",
|
||||
"RIB",
|
||||
"RFP"),
|
||||
verbose = verbose, ...)
|
||||
} else {
|
||||
cols_ab <- get_column_abx(x = x, verbose = verbose, ...)
|
||||
}
|
||||
|
||||
AMC <- cols_ab["AMC"]
|
||||
AMK <- cols_ab["AMK"]
|
||||
AMP <- cols_ab["AMP"]
|
||||
AMX <- cols_ab["AMX"]
|
||||
ATM <- cols_ab["ATM"]
|
||||
AZL <- cols_ab["AZL"]
|
||||
AZM <- cols_ab["AZM"]
|
||||
CAZ <- cols_ab["CAZ"]
|
||||
CED <- cols_ab["CED"]
|
||||
CHL <- cols_ab["CHL"]
|
||||
CIP <- cols_ab["CIP"]
|
||||
CLI <- cols_ab["CLI"]
|
||||
CLR <- cols_ab["CLR"]
|
||||
COL <- cols_ab["COL"]
|
||||
CRO <- cols_ab["CRO"]
|
||||
CTX <- cols_ab["CTX"]
|
||||
CXM <- cols_ab["CXM"]
|
||||
CZO <- cols_ab["CZO"]
|
||||
DAP <- cols_ab["DAP"]
|
||||
DOX <- cols_ab["DOX"]
|
||||
ERY <- cols_ab["ERY"]
|
||||
ETP <- cols_ab["ETP"]
|
||||
FEP <- cols_ab["FEP"]
|
||||
FLC <- cols_ab["FLC"]
|
||||
FOS <- cols_ab["FOS"]
|
||||
FOX <- cols_ab["FOX"]
|
||||
FUS <- cols_ab["FUS"]
|
||||
GEN <- cols_ab["GEN"]
|
||||
IPM <- cols_ab["IPM"]
|
||||
KAN <- cols_ab["KAN"]
|
||||
LIN <- cols_ab["LIN"]
|
||||
LNZ <- cols_ab["LNZ"]
|
||||
LVX <- cols_ab["LVX"]
|
||||
MEM <- cols_ab["MEM"]
|
||||
MEZ <- cols_ab["MEZ"]
|
||||
MTR <- cols_ab["MTR"]
|
||||
MFX <- cols_ab["MFX"]
|
||||
MNO <- cols_ab["MNO"]
|
||||
NAL <- cols_ab["NAL"]
|
||||
NEO <- cols_ab["NEO"]
|
||||
NET <- cols_ab["NET"]
|
||||
NIT <- cols_ab["NIT"]
|
||||
NOR <- cols_ab["NOR"]
|
||||
NOV <- cols_ab["NOV"]
|
||||
OFX <- cols_ab["OFX"]
|
||||
PEN <- cols_ab["PEN"]
|
||||
PIP <- cols_ab["PIP"]
|
||||
PLB <- cols_ab["PLB"]
|
||||
PRI <- cols_ab["PRI"]
|
||||
QDA <- cols_ab["QDA"]
|
||||
RID <- cols_ab["RID"]
|
||||
RIF <- cols_ab["RIF"]
|
||||
RXT <- cols_ab["RXT"]
|
||||
SIS <- cols_ab["SIS"]
|
||||
SXT <- cols_ab["SXT"]
|
||||
TCY <- cols_ab["TCY"]
|
||||
TEC <- cols_ab["TEC"]
|
||||
TGC <- cols_ab["TGC"]
|
||||
TIC <- cols_ab["TIC"]
|
||||
TMP <- cols_ab["TMP"]
|
||||
TOB <- cols_ab["TOB"]
|
||||
TZP <- cols_ab["TZP"]
|
||||
VAN <- cols_ab["VAN"]
|
||||
# additional for TB
|
||||
CAP <- cols_ab["CAP"]
|
||||
ETH <- cols_ab["ETH"]
|
||||
GAT <- cols_ab["GAT"]
|
||||
INH <- cols_ab["INH"]
|
||||
PZA <- cols_ab["PZA"]
|
||||
RIF <- cols_ab["RIF"]
|
||||
RIB <- cols_ab["RIB"]
|
||||
RFP <- cols_ab["RFP"]
|
||||
abx_tb <- c(CAP, ETH, GAT, INH, PZA, RIF, RIB, RFP)
|
||||
abx_tb <- abx_tb[!is.na(abx_tb)]
|
||||
if (guideline$code == "tb" & length(abx_tb) == 0) {
|
||||
stop("No antimycobacterials found in data set.", call. = FALSE)
|
||||
}
|
||||
|
||||
ab_missing <- function(ab) {
|
||||
isTRUE(ab %in% c(NULL, NA)) | length(ab) == 0
|
||||
}
|
||||
|
||||
# antibiotic classes
|
||||
aminoglycosides <- c(TOB, GEN)
|
||||
cephalosporins <- c(FEP, CTX, FOX, CED, CAZ, CRO, CXM, CZO)
|
||||
cephalosporins_3rd <- c(CTX, CRO, CAZ)
|
||||
carbapenems <- c(ETP, IPM, MEM)
|
||||
fluoroquinolones <- c(OFX, CIP, LVX, MFX)
|
||||
|
||||
# helper function for editing the table
|
||||
trans_tbl <- function(to, rows, cols, any_all) {
|
||||
cols <- cols[!ab_missing(cols)]
|
||||
cols <- cols[!is.na(cols)]
|
||||
if (length(rows) > 0 & length(cols) > 0) {
|
||||
if (any_all == "any") {
|
||||
row_filter <- which(x[, cols] == "R")
|
||||
} else if (any_all == "all") {
|
||||
row_filter <- x %>%
|
||||
mutate(index = 1:nrow(.)) %>%
|
||||
filter_at(vars(cols), all_vars(. == "R")) %>%
|
||||
pull((index))
|
||||
}
|
||||
rows <- rows[rows %in% row_filter]
|
||||
x[rows, "MDRO"] <<- to
|
||||
}
|
||||
}
|
||||
|
||||
x <- x %>%
|
||||
mutate_at(vars(col_mo), as.mo) %>%
|
||||
# join to microorganisms data set
|
||||
left_join_microorganisms(by = col_mo) %>%
|
||||
# add unconfirmed to where genus is available
|
||||
mutate(MDRO = ifelse(!is.na(genus), 1, NA_integer_))
|
||||
|
||||
if (guideline$code == "eucast") {
|
||||
# EUCAST ------------------------------------------------------------------
|
||||
# Table 5
|
||||
trans_tbl(3,
|
||||
which(x$family == "Enterobacteriaceae"
|
||||
| x$fullname %like% "^Pseudomonas aeruginosa"
|
||||
| x$genus == "Acinetobacter"),
|
||||
COL,
|
||||
"all")
|
||||
trans_tbl(3,
|
||||
which(x$fullname %like% "^Salmonella Typhi"),
|
||||
c(carbapenems, fluoroquinolones),
|
||||
"any")
|
||||
trans_tbl(3,
|
||||
which(x$fullname %like% "^Haemophilus influenzae"),
|
||||
c(cephalosporins_3rd, carbapenems, fluoroquinolones),
|
||||
"any")
|
||||
trans_tbl(3,
|
||||
which(x$fullname %like% "^Moraxella catarrhalis"),
|
||||
c(cephalosporins_3rd, fluoroquinolones),
|
||||
"any")
|
||||
trans_tbl(3,
|
||||
which(x$fullname %like% "^Neisseria meningitidis"),
|
||||
c(cephalosporins_3rd, fluoroquinolones),
|
||||
"any")
|
||||
trans_tbl(3,
|
||||
which(x$fullname %like% "^Neisseria gonorrhoeae"),
|
||||
AZM,
|
||||
"any")
|
||||
# Table 6
|
||||
trans_tbl(3,
|
||||
which(x$fullname %like% "^Staphylococcus (aureus|epidermidis|coagulase negatief|hominis|haemolyticus|intermedius|pseudointermedius)"),
|
||||
c(VAN, TEC, DAP, LNZ, QDA, TGC),
|
||||
"any")
|
||||
trans_tbl(3,
|
||||
which(x$genus == "Corynebacterium"),
|
||||
c(VAN, TEC, DAP, LNZ, QDA, TGC),
|
||||
"any")
|
||||
trans_tbl(3,
|
||||
which(x$fullname %like% "^Streptococcus pneumoniae"),
|
||||
c(carbapenems, VAN, TEC, DAP, LNZ, QDA, TGC, RIF),
|
||||
"any")
|
||||
trans_tbl(3, # Sr. groups A/B/C/G
|
||||
which(x$fullname %like% "^Streptococcus (pyogenes|agalactiae|equisimilis|equi|zooepidemicus|dysgalactiae|anginosus)"),
|
||||
c(PEN, cephalosporins, VAN, TEC, DAP, LNZ, QDA, TGC),
|
||||
"any")
|
||||
trans_tbl(3,
|
||||
which(x$genus == "Enterococcus"),
|
||||
c(DAP, LNZ, TGC, TEC),
|
||||
"any")
|
||||
trans_tbl(3,
|
||||
which(x$fullname %like% "^Enterococcus faecalis"),
|
||||
c(AMP, AMX),
|
||||
"any")
|
||||
# Table 7
|
||||
trans_tbl(3,
|
||||
which(x$genus == "Bacteroides"),
|
||||
MTR,
|
||||
"any")
|
||||
trans_tbl(3,
|
||||
which(x$fullname %like% "^Clostridium difficile"),
|
||||
c(MTR, VAN),
|
||||
"any")
|
||||
}
|
||||
|
||||
if (guideline$code == "de") {
|
||||
# Germany -----------------------------------------------------------------
|
||||
stop("We are still working on German guidelines in this beta version.", call. = FALSE)
|
||||
}
|
||||
|
||||
if (guideline$code == "nl") {
|
||||
# Netherlands -------------------------------------------------------------
|
||||
aminoglycosides <- aminoglycosides[!is.na(aminoglycosides)]
|
||||
fluoroquinolones <- fluoroquinolones[!is.na(fluoroquinolones)]
|
||||
carbapenems <- carbapenems[!is.na(carbapenems)]
|
||||
amino <- AMX %or% AMP
|
||||
third <- CAZ %or% CTX
|
||||
ESBLs <- c(amino, third)
|
||||
ESBLs <- ESBLs[!is.na(ESBLs)]
|
||||
if (length(ESBLs) != 2) {
|
||||
ESBLs <- character(0)
|
||||
}
|
||||
|
||||
# Table 1
|
||||
trans_tbl(3,
|
||||
which(x$family == "Enterobacteriaceae"),
|
||||
c(aminoglycosides, fluoroquinolones),
|
||||
"all")
|
||||
|
||||
trans_tbl(2,
|
||||
which(x$family == "Enterobacteriaceae"),
|
||||
carbapenems,
|
||||
"any")
|
||||
|
||||
trans_tbl(2,
|
||||
which(x$family == "Enterobacteriaceae"),
|
||||
ESBLs,
|
||||
"all")
|
||||
|
||||
# Table 2
|
||||
trans_tbl(2,
|
||||
which(x$genus == "Acinetobacter"),
|
||||
c(carbapenems),
|
||||
"any")
|
||||
trans_tbl(3,
|
||||
which(x$genus == "Acinetobacter"),
|
||||
c(aminoglycosides, fluoroquinolones),
|
||||
"all")
|
||||
|
||||
trans_tbl(3,
|
||||
which(x$fullname %like% "^Stenotrophomonas maltophilia"),
|
||||
SXT,
|
||||
"all")
|
||||
|
||||
if (!ab_missing(MEM) & !ab_missing(IPM)
|
||||
& !ab_missing(GEN) & !ab_missing(TOB)
|
||||
& !ab_missing(CIP)
|
||||
& !ab_missing(CAZ)
|
||||
& !ab_missing(TZP) ) {
|
||||
x$psae <- 0
|
||||
x[which(x[, MEM] == "R" | x[, IPM] == "R"), "psae"] <- 1 + x[which(x[, MEM] == "R" | x[, IPM] == "R"), "psae"]
|
||||
x[which(x[, GEN] == "R" & x[, TOB] == "R"), "psae"] <- 1 + x[which(x[, GEN] == "R" & x[, TOB] == "R"), "psae"]
|
||||
x[which(x[, CIP] == "R"), "psae"] <- 1 + x[which(x[, CIP] == "R"), "psae"]
|
||||
x[which(x[, CAZ] == "R"), "psae"] <- 1 + x[which(x[, CAZ] == "R"), "psae"]
|
||||
x[which(x[, TZP] == "R"), "psae"] <- 1 + x[which(x[, TZP] == "R"), "psae"]
|
||||
} else {
|
||||
x$psae <- 0
|
||||
}
|
||||
x[which(
|
||||
x$fullname %like% "Pseudomonas aeruginosa"
|
||||
& x$psae >= 3
|
||||
), "MDRO"] <- 3
|
||||
|
||||
# Table 3
|
||||
trans_tbl(3,
|
||||
which(x$fullname %like% "Streptococcus pneumoniae"),
|
||||
PEN,
|
||||
"all")
|
||||
trans_tbl(3,
|
||||
which(x$fullname %like% "Streptococcus pneumoniae"),
|
||||
VAN,
|
||||
"all")
|
||||
trans_tbl(3,
|
||||
which(x$fullname %like% "Enterococcus faecium"),
|
||||
c(PEN, VAN),
|
||||
"all")
|
||||
}
|
||||
|
||||
prepare_drug <- function(ab) {
|
||||
# returns vector values of drug
|
||||
# if `ab` is a column name, looks up the values in `x`
|
||||
if (length(ab) == 1 & is.character(ab)) {
|
||||
if (ab %in% colnames(x)) {
|
||||
ab <- as.data.frame(x)[, ab]
|
||||
}
|
||||
}
|
||||
ab <- as.character(as.rsi(ab))
|
||||
ab[is.na(ab)] <- ""
|
||||
ab
|
||||
}
|
||||
drug_is_R <- function(ab) {
|
||||
# returns logical vector
|
||||
ab <- prepare_drug(ab)
|
||||
if (length(ab) == 1) {
|
||||
rep(ab, NROW(x)) == "R"
|
||||
} else {
|
||||
ab == "R"
|
||||
}
|
||||
}
|
||||
drug_is_not_R <- function(ab) {
|
||||
# returns logical vector
|
||||
ab <- prepare_drug(ab)
|
||||
if (length(ab) == 1) {
|
||||
rep(ab, NROW(x)) != "R"
|
||||
} else {
|
||||
ab != "R"
|
||||
}
|
||||
}
|
||||
|
||||
if (guideline$code == "tb") {
|
||||
# Tuberculosis ------------------------------------------------------------
|
||||
x <- x %>%
|
||||
mutate(mono_count = 0,
|
||||
mono_count = ifelse(drug_is_R(INH), mono_count + 1, mono_count),
|
||||
mono_count = ifelse(drug_is_R(RIF), mono_count + 1, mono_count),
|
||||
mono_count = ifelse(drug_is_R(ETH), mono_count + 1, mono_count),
|
||||
mono_count = ifelse(drug_is_R(PZA), mono_count + 1, mono_count),
|
||||
mono_count = ifelse(drug_is_R(RIB), mono_count + 1, mono_count),
|
||||
mono_count = ifelse(drug_is_R(RFP), mono_count + 1, mono_count),
|
||||
# from here on logicals
|
||||
mono = mono_count > 0,
|
||||
poly = ifelse(mono_count > 1 & drug_is_not_R(RIF) & drug_is_not_R(INH),
|
||||
TRUE, FALSE),
|
||||
mdr = ifelse(drug_is_R(RIF) & drug_is_R(INH),
|
||||
TRUE, FALSE),
|
||||
xdr = ifelse(drug_is_R(LVX) | drug_is_R(MFX) | drug_is_R(GAT),
|
||||
TRUE, FALSE),
|
||||
second = ifelse(drug_is_R(CAP) | drug_is_R(KAN) | drug_is_R(AMK),
|
||||
TRUE, FALSE),
|
||||
xdr = ifelse(mdr & xdr & second, TRUE, FALSE)) %>%
|
||||
mutate(mdr_tb = case_when(xdr ~ 5,
|
||||
mdr ~ 4,
|
||||
poly ~ 3,
|
||||
mono ~ 2,
|
||||
TRUE ~ 1),
|
||||
# keep all real TB, make other species NA
|
||||
mdr_tb = ifelse(x$fullname == "Mycobacterium tuberculosis", mdr_tb, NA_real_))
|
||||
}
|
||||
|
||||
# return results
|
||||
if (guideline$code == "tb") {
|
||||
factor(x = x$mdr_tb,
|
||||
levels = 1:5,
|
||||
labels = c("Negative", "Mono-resistance", "Poly-resistance", "Multidrug resistance", "Extensive drug resistance"),
|
||||
ordered = TRUE)
|
||||
} else {
|
||||
factor(x = x$MDRO,
|
||||
levels = 1:3,
|
||||
labels = c("Negative", "Positive, unconfirmed", "Positive"),
|
||||
ordered = TRUE)
|
||||
}
|
||||
}
|
||||
|
||||
#' @rdname mdro
|
||||
#' @export
|
||||
brmo <- function(..., country = "nl") {
|
||||
mdro(..., country = "nl")
|
||||
}
|
||||
|
||||
#' @rdname mdro
|
||||
#' @export
|
||||
mrgn <- function(x, country = "de", ...) {
|
||||
mdro(x = x, country = "de", ...)
|
||||
}
|
||||
|
||||
#' @rdname mdro
|
||||
#' @export
|
||||
mdr_tb <- function(x, guideline = "TB", ...) {
|
||||
mdro(x = x, guideline = "TB", ...)
|
||||
}
|
||||
|
||||
#' @rdname mdro
|
||||
#' @export
|
||||
eucast_exceptional_phenotypes <- function(x, guideline = "EUCAST", ...) {
|
||||
mdro(x = x, guideline = "EUCAST", ...)
|
||||
}
|
||||
@@ -1,275 +0,0 @@
|
||||
# ==================================================================== #
|
||||
# TITLE #
|
||||
# Antimicrobial Resistance (AMR) Analysis #
|
||||
# #
|
||||
# SOURCE #
|
||||
# https://gitlab.com/msberends/AMR #
|
||||
# #
|
||||
# LICENCE #
|
||||
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
|
||||
# #
|
||||
# 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. #
|
||||
# #
|
||||
# This R package was created for academic research and was publicly #
|
||||
# released in the hope that it will be useful, but it comes WITHOUT #
|
||||
# ANY WARRANTY OR LIABILITY. #
|
||||
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
||||
# ==================================================================== #
|
||||
|
||||
#' Class 'mic'
|
||||
#'
|
||||
#' This transforms a vector to a new class \code{mic}, which is an ordered factor with valid MIC values as levels. Invalid MIC values will be translated as \code{NA} with a warning.
|
||||
#' @rdname as.mic
|
||||
#' @param x vector
|
||||
#' @param na.rm a logical indicating whether missing values should be removed
|
||||
#' @details Interpret MIC values as RSI values with \code{\link{as.rsi}}. It supports guidelines from EUCAST and CLSI.
|
||||
#' @return Ordered factor with new class \code{mic}
|
||||
#' @keywords mic
|
||||
#' @export
|
||||
#' @importFrom dplyr %>%
|
||||
#' @seealso \code{\link{as.rsi}}
|
||||
#' @inheritSection AMR Read more on our website!
|
||||
#' @examples
|
||||
#' mic_data <- as.mic(c(">=32", "1.0", "1", "1.00", 8, "<=0.128", "8", "16", "16"))
|
||||
#' is.mic(mic_data)
|
||||
#'
|
||||
#' # this can also coerce combined MIC/RSI values:
|
||||
#' as.mic("<=0.002; S") # will return <=0.002
|
||||
#'
|
||||
#' # interpret MIC values
|
||||
#' as.rsi(x = as.mic(2),
|
||||
#' mo = as.mo("S. pneumoniae"),
|
||||
#' ab = "AMX",
|
||||
#' guideline = "EUCAST")
|
||||
#' as.rsi(x = as.mic(4),
|
||||
#' mo = as.mo("S. pneumoniae"),
|
||||
#' ab = "AMX",
|
||||
#' guideline = "EUCAST")
|
||||
#'
|
||||
#' plot(mic_data)
|
||||
#' barplot(mic_data)
|
||||
#' freq(mic_data)
|
||||
as.mic <- function(x, na.rm = FALSE) {
|
||||
if (is.mic(x)) {
|
||||
x
|
||||
} else {
|
||||
x <- x %>% unlist()
|
||||
if (na.rm == TRUE) {
|
||||
x <- x[!is.na(x)]
|
||||
}
|
||||
x.bak <- x
|
||||
|
||||
# comma to period
|
||||
x <- gsub(',', '.', x, fixed = TRUE)
|
||||
# remove space between operator and number ("<= 0.002" -> "<=0.002")
|
||||
x <- gsub('(<|=|>) +', '\\1', x)
|
||||
# starting dots must start with 0
|
||||
x <- gsub('^[.]+', '0.', x)
|
||||
# <=0.2560.512 should be 0.512
|
||||
x <- gsub('.*[.].*[.]', '0.', x)
|
||||
# remove ending .0
|
||||
x <- gsub('[.]+0$', '', x)
|
||||
# remove all after last digit
|
||||
x <- gsub('[^0-9]+$', '', x)
|
||||
# remove last zeroes
|
||||
x <- gsub('([.].?)0+$', '\\1', x)
|
||||
x <- gsub('(.*[.])0+$', '\\10', x)
|
||||
# remove ending .0 again
|
||||
x <- gsub('[.]+0$', '', x)
|
||||
# force to be character
|
||||
x <- as.character(x)
|
||||
|
||||
## previously unempty values now empty - should return a warning later on
|
||||
x[x.bak != "" & x == ""] <- "invalid"
|
||||
|
||||
# these are allowed MIC values and will become factor levels
|
||||
lvls <- c("<0.001", "<=0.001", "0.001", ">=0.001", ">0.001",
|
||||
"<0.002", "<=0.002", "0.002", ">=0.002", ">0.002",
|
||||
"<0.003", "<=0.003", "0.003", ">=0.003", ">0.003",
|
||||
"<0.004", "<=0.004", "0.004", ">=0.004", ">0.004",
|
||||
"<0.006", "<=0.006", "0.006", ">=0.006", ">0.006",
|
||||
"<0.008", "<=0.008", "0.008", ">=0.008", ">0.008",
|
||||
"<0.012", "<=0.012", "0.012", ">=0.012", ">0.012",
|
||||
"<0.0125", "<=0.0125", "0.0125", ">=0.0125", ">0.0125",
|
||||
"<0.016", "<=0.016", "0.016", ">=0.016", ">0.016",
|
||||
"<0.023", "<=0.023", "0.023", ">=0.023", ">0.023",
|
||||
"<0.025", "<=0.025", "0.025", ">=0.025", ">0.025",
|
||||
"<0.03", "<=0.03", "0.03", ">=0.03", ">0.03",
|
||||
"<0.032", "<=0.032", "0.032", ">=0.032", ">0.032",
|
||||
"<0.047", "<=0.047", "0.047", ">=0.047", ">0.047",
|
||||
"<0.05", "<=0.05", "0.05", ">=0.05", ">0.05",
|
||||
"<0.054", "<=0.054", "0.054", ">=0.054", ">0.054",
|
||||
"<0.06", "<=0.06", "0.06", ">=0.06", ">0.06",
|
||||
"<0.0625", "<=0.0625", "0.0625", ">=0.0625", ">0.0625",
|
||||
"<0.063", "<=0.063", "0.063", ">=0.063", ">0.063",
|
||||
"<0.064", "<=0.064", "0.064", ">=0.064", ">0.064",
|
||||
"<0.09", "<=0.09", "0.09", ">=0.09", ">0.09",
|
||||
"<0.094", "<=0.094", "0.094", ">=0.094", ">0.094",
|
||||
"<0.12", "<=0.12", "0.12", ">=0.12", ">0.12",
|
||||
"<0.125", "<=0.125", "0.125", ">=0.125", ">0.125",
|
||||
"<0.128", "<=0.128", "0.128", ">=0.128", ">0.128",
|
||||
"<0.16", "<=0.16", "0.16", ">=0.16", ">0.16",
|
||||
"<0.19", "<=0.19", "0.19", ">=0.19", ">0.19",
|
||||
"<0.23", "<=0.23", "0.23", ">=0.23", ">0.23",
|
||||
"<0.25", "<=0.25", "0.25", ">=0.25", ">0.25",
|
||||
"<0.256", "<=0.256", "0.256", ">=0.256", ">0.256",
|
||||
"<0.28", "<=0.28", "0.28", ">=0.28", ">0.28",
|
||||
"<0.3", "<=0.3", "0.3", ">=0.3", ">0.3",
|
||||
"<0.32", "<=0.32", "0.32", ">=0.32", ">0.32",
|
||||
"<0.36", "<=0.36", "0.36", ">=0.36", ">0.36",
|
||||
"<0.38", "<=0.38", "0.38", ">=0.38", ">0.38",
|
||||
"<0.5", "<=0.5", "0.5", ">=0.5", ">0.5",
|
||||
"<0.512", "<=0.512", "0.512", ">=0.512", ">0.512",
|
||||
"<0.64", "<=0.64", "0.64", ">=0.64", ">0.64",
|
||||
"<0.75", "<=0.75", "0.75", ">=0.75", ">0.75",
|
||||
"<1", "<=1", "1", ">=1", ">1",
|
||||
"<1.5", "<=1.5", "1.5", ">=1.5", ">1.5",
|
||||
"<2", "<=2", "2", ">=2", ">2",
|
||||
"<3", "<=3", "3", ">=3", ">3",
|
||||
"<4", "<=4", "4", ">=4", ">4",
|
||||
"<5", "<=5", "5", ">=5", ">5",
|
||||
"<6", "<=6", "6", ">=6", ">6",
|
||||
"<7", "<=7", "7", ">=7", ">7",
|
||||
"<8", "<=8", "8", ">=8", ">8",
|
||||
"<10", "<=10", "10", ">=10", ">10",
|
||||
"<12", "<=12", "12", ">=12", ">12",
|
||||
"<16", "<=16", "16", ">=16", ">16",
|
||||
"<20", "<=20", "20", ">=20", ">20",
|
||||
"<24", "<=24", "24", ">=24", ">24",
|
||||
"<32", "<=32", "32", ">=32", ">32",
|
||||
"<40", "<=40", "40", ">=40", ">40",
|
||||
"<48", "<=48", "48", ">=48", ">48",
|
||||
"<64", "<=64", "64", ">=64", ">64",
|
||||
"<80", "<=80", "80", ">=80", ">80",
|
||||
"<96", "<=96", "96", ">=96", ">96",
|
||||
"<128", "<=128", "128", ">=128", ">128",
|
||||
"129",
|
||||
"<160", "<=160", "160", ">=160", ">160",
|
||||
"<256", "<=256", "256", ">=256", ">256",
|
||||
"257",
|
||||
"<320", "<=320", "320", ">=320", ">320",
|
||||
"<512", "<=512", "512", ">=512", ">512",
|
||||
"513",
|
||||
"<1024", "<=1024", "1024", ">=1024", ">1024",
|
||||
"1025")
|
||||
|
||||
na_before <- x[is.na(x) | x == ''] %>% length()
|
||||
x[!x %in% lvls] <- NA
|
||||
na_after <- x[is.na(x) | x == ''] %>% length()
|
||||
|
||||
if (na_before != na_after) {
|
||||
list_missing <- x.bak[is.na(x) & !is.na(x.bak) & x.bak != ''] %>%
|
||||
unique() %>%
|
||||
sort()
|
||||
list_missing <- paste0('"', list_missing , '"', collapse = ", ")
|
||||
warning(na_after - na_before, ' results truncated (',
|
||||
round(((na_after - na_before) / length(x)) * 100),
|
||||
'%) that were invalid MICs: ',
|
||||
list_missing, call. = FALSE)
|
||||
}
|
||||
|
||||
x <- factor(x, levels = lvls, ordered = TRUE)
|
||||
class(x) <- c('mic', 'ordered', 'factor')
|
||||
x
|
||||
}
|
||||
}
|
||||
|
||||
#' @rdname as.mic
|
||||
#' @export
|
||||
#' @importFrom dplyr %>%
|
||||
is.mic <- function(x) {
|
||||
class(x) %>% identical(c('mic', 'ordered', 'factor'))
|
||||
}
|
||||
|
||||
#' @exportMethod as.double.mic
|
||||
#' @export
|
||||
#' @noRd
|
||||
as.double.mic <- function(x, ...) {
|
||||
as.double(gsub('(<|=|>)+', '', as.character(x)))
|
||||
}
|
||||
|
||||
#' @exportMethod as.integer.mic
|
||||
#' @export
|
||||
#' @noRd
|
||||
as.integer.mic <- function(x, ...) {
|
||||
as.integer(gsub('(<|=|>)+', '', as.character(x)))
|
||||
}
|
||||
|
||||
#' @exportMethod as.numeric.mic
|
||||
#' @export
|
||||
#' @noRd
|
||||
as.numeric.mic <- function(x, ...) {
|
||||
as.numeric(gsub('(<|=|>)+', '', as.character(x)))
|
||||
}
|
||||
|
||||
#' @exportMethod droplevels.mic
|
||||
#' @export
|
||||
#' @noRd
|
||||
droplevels.mic <- function(x, exclude = if(anyNA(levels(x))) NULL else NA, ...) {
|
||||
x <- droplevels.factor(x, exclude = exclude, ...)
|
||||
class(x) <- c('mic', 'ordered', 'factor')
|
||||
x
|
||||
}
|
||||
|
||||
#' @exportMethod print.mic
|
||||
#' @export
|
||||
#' @importFrom dplyr %>% tibble group_by summarise pull
|
||||
#' @noRd
|
||||
print.mic <- function(x, ...) {
|
||||
cat("Class 'mic'\n")
|
||||
print(as.character(x), quote = FALSE)
|
||||
}
|
||||
|
||||
#' @exportMethod summary.mic
|
||||
#' @export
|
||||
#' @importFrom dplyr %>%
|
||||
#' @noRd
|
||||
summary.mic <- function(object, ...) {
|
||||
x <- object
|
||||
n_total <- x %>% length()
|
||||
x <- x[!is.na(x)]
|
||||
n <- x %>% length()
|
||||
c(
|
||||
"Class" = 'mic',
|
||||
"<NA>" = n_total - n,
|
||||
"Min." = sort(x)[1] %>% as.character(),
|
||||
"Max." = sort(x)[n] %>% as.character()
|
||||
)
|
||||
}
|
||||
|
||||
#' @exportMethod plot.mic
|
||||
#' @export
|
||||
#' @importFrom dplyr %>% group_by summarise
|
||||
#' @importFrom graphics plot text
|
||||
#' @noRd
|
||||
plot.mic <- function(x, ...) {
|
||||
x_name <- deparse(substitute(x))
|
||||
create_barplot_mic(x, x_name, ...)
|
||||
}
|
||||
|
||||
#' @exportMethod barplot.mic
|
||||
#' @export
|
||||
#' @importFrom graphics barplot axis
|
||||
#' @noRd
|
||||
barplot.mic <- function(height, ...) {
|
||||
x_name <- deparse(substitute(height))
|
||||
create_barplot_mic(height, x_name, ...)
|
||||
}
|
||||
|
||||
#' @importFrom graphics barplot axis
|
||||
#' @importFrom dplyr %>% group_by summarise
|
||||
create_barplot_mic <- function(x, x_name, ...) {
|
||||
data <- data.frame(mic = droplevels(x), cnt = 1) %>%
|
||||
group_by(mic) %>%
|
||||
summarise(cnt = sum(cnt))
|
||||
barplot(table(droplevels.factor(x)),
|
||||
ylab = 'Frequency',
|
||||
xlab = 'MIC value',
|
||||
main = paste('MIC values of', x_name),
|
||||
axes = FALSE,
|
||||
...)
|
||||
axis(2, seq(0, max(data$cnt)))
|
||||
}
|
||||
@@ -1,305 +0,0 @@
|
||||
# ==================================================================== #
|
||||
# TITLE #
|
||||
# Antimicrobial Resistance (AMR) Analysis #
|
||||
# #
|
||||
# SOURCE #
|
||||
# https://gitlab.com/msberends/AMR #
|
||||
# #
|
||||
# LICENCE #
|
||||
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
|
||||
# #
|
||||
# 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. #
|
||||
# #
|
||||
# This R package was created for academic research and was publicly #
|
||||
# released in the hope that it will be useful, but it comes WITHOUT #
|
||||
# ANY WARRANTY OR LIABILITY. #
|
||||
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
||||
# ==================================================================== #
|
||||
|
||||
# No export, no Rd
|
||||
addin_insert_in <- function() {
|
||||
rstudioapi::insertText(" %in% ")
|
||||
}
|
||||
|
||||
# No export, no Rd
|
||||
addin_insert_like <- function() {
|
||||
rstudioapi::insertText(" %like% ")
|
||||
}
|
||||
|
||||
# No export, no Rd
|
||||
# works exactly like round(), but rounds `round(44.55, 1)` as 44.6 instead of 44.5
|
||||
# and adds decimal zeroes until `digits` is reached when force_zero = TRUE
|
||||
round2 <- function(x, digits = 0, force_zero = TRUE) {
|
||||
# https://stackoverflow.com/a/12688836/4575331
|
||||
val <- (trunc((abs(x) * 10 ^ digits) + 0.5) / 10 ^ digits) * sign(x)
|
||||
if (digits > 0 & force_zero == TRUE) {
|
||||
val[val != as.integer(val)] <- paste0(val[val != as.integer(val)],
|
||||
strrep("0", max(0, digits - nchar(gsub(".*[.](.*)$", "\\1", val[val != as.integer(val)])))))
|
||||
}
|
||||
val
|
||||
}
|
||||
|
||||
# Coefficient of variation (CV)
|
||||
cv <- function(x, na.rm = TRUE) {
|
||||
stats::sd(x, na.rm = na.rm) / base::abs(base::mean(x, na.rm = na.rm))
|
||||
}
|
||||
|
||||
# Coefficient of dispersion, or coefficient of quartile variation (CQV).
|
||||
# (Bonett et al., 2006: Confidence interval for a coefficient of quartile variation).
|
||||
cqv <- function(x, na.rm = TRUE) {
|
||||
fives <- stats::fivenum(x, na.rm = na.rm)
|
||||
(fives[4] - fives[2]) / (fives[4] + fives[2])
|
||||
}
|
||||
|
||||
# show bytes as kB/MB/GB
|
||||
# size_humanreadable(123456) # 121 kB
|
||||
# size_humanreadable(12345678) # 11.8 MB
|
||||
size_humanreadable <- function(bytes, decimals = 1) {
|
||||
bytes <- bytes %>% as.double()
|
||||
# Adapted from:
|
||||
# http://jeffreysambells.com/2012/10/25/human-readable-filesize-php
|
||||
size <- c('B','kB','MB','GB','TB','PB','EB','ZB','YB')
|
||||
factor <- floor((nchar(bytes) - 1) / 3)
|
||||
# added slight improvement; no decimals for B and kB:
|
||||
decimals <- rep(decimals, length(bytes))
|
||||
decimals[size[factor + 1] %in% c('B', 'kB')] <- 0
|
||||
|
||||
out <- paste(sprintf(paste0("%.", decimals, "f"), bytes / (1024 ^ factor)), size[factor + 1])
|
||||
out
|
||||
}
|
||||
|
||||
percent_scales <- scales::percent
|
||||
# No export, no Rd
|
||||
# based on scales::percent
|
||||
percent <- function(x, round = 1, force_zero = FALSE, decimal.mark = getOption("OutDec"), ...) {
|
||||
x <- percent_scales(x = as.double(x),
|
||||
accuracy = 1 / 10 ^ round,
|
||||
decimal.mark = decimal.mark,
|
||||
...)
|
||||
if (force_zero == FALSE) {
|
||||
x <- gsub("([.]%|%%)", "%", paste0(gsub("0+%$", "", x), "%"))
|
||||
}
|
||||
x
|
||||
}
|
||||
|
||||
#' @importFrom crayon blue bold red
|
||||
#' @importFrom dplyr %>% pull
|
||||
search_type_in_df <- function(x, type) {
|
||||
# try to find columns based on type
|
||||
found <- NULL
|
||||
|
||||
colnames(x) <- trimws(colnames(x))
|
||||
|
||||
# -- mo
|
||||
if (type == "mo") {
|
||||
if ("mo" %in% lapply(x, class)) {
|
||||
found <- colnames(x)[lapply(x, class) == "mo"][1]
|
||||
} else if (any(colnames(x) %like% "^(mo|microorganism|organism|bacteria)s?$")) {
|
||||
found <- colnames(x)[colnames(x) %like% "^(mo|microorganism|organism|bacteria)s?$"][1]
|
||||
} else if (any(colnames(x) %like% "species")) {
|
||||
found <- colnames(x)[colnames(x) %like% "species"][1]
|
||||
}
|
||||
|
||||
}
|
||||
# -- key antibiotics
|
||||
if (type == "keyantibiotics") {
|
||||
if (any(colnames(x) %like% "^key.*(ab|antibiotics)")) {
|
||||
found <- colnames(x)[colnames(x) %like% "^key.*(ab|antibiotics)"][1]
|
||||
}
|
||||
}
|
||||
# -- date
|
||||
if (type == "date") {
|
||||
if (any(colnames(x) %like% "^(specimen date|specimen_date|spec_date)")) {
|
||||
# WHONET support
|
||||
found <- colnames(x)[colnames(x) %like% "^(specimen date|specimen_date|spec_date)"][1]
|
||||
if (!any(class(x %>% pull(found)) %in% c("Date", "POSIXct"))) {
|
||||
stop(red(paste0("ERROR: Found column `", bold(found), "` to be used as input for `col_", type,
|
||||
"`, but this column contains no valid dates. Transform its values to valid dates first.")),
|
||||
call. = FALSE)
|
||||
}
|
||||
} else {
|
||||
for (i in 1:ncol(x)) {
|
||||
if (any(class(x %>% pull(i)) %in% c("Date", "POSIXct"))) {
|
||||
found <- colnames(x)[i]
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
# -- patient id
|
||||
if (type == "patient_id") {
|
||||
if (any(colnames(x) %like% "^(identification |patient|patid)")) {
|
||||
found <- colnames(x)[colnames(x) %like% "^(identification |patient|patid)"][1]
|
||||
}
|
||||
}
|
||||
# -- specimen
|
||||
if (type == "specimen") {
|
||||
if (any(colnames(x) %like% "(specimen type|spec_type)")) {
|
||||
found <- colnames(x)[colnames(x) %like% "(specimen type|spec_type)"][1]
|
||||
} else if (any(colnames(x) %like% "^(specimen)")) {
|
||||
found <- colnames(x)[colnames(x) %like% "^(specimen)"][1]
|
||||
}
|
||||
}
|
||||
|
||||
if (!is.null(found)) {
|
||||
msg <- paste0("NOTE: Using column `", bold(found), "` as input for `col_", type, "`.")
|
||||
if (type %in% c("keyantibiotics", "specimen")) {
|
||||
msg <- paste(msg, "Use", bold(paste0("col_", type), "= FALSE"), "to prevent this.")
|
||||
}
|
||||
message(blue(msg))
|
||||
}
|
||||
found
|
||||
}
|
||||
|
||||
#' @importFrom crayon blue bold
|
||||
get_column_abx <- function(x,
|
||||
soft_dependencies = NULL,
|
||||
hard_dependencies = NULL,
|
||||
verbose = FALSE,
|
||||
...) {
|
||||
|
||||
# determine from given data set
|
||||
df_trans <- data.frame(colnames = colnames(x),
|
||||
abcode = suppressWarnings(as.ab(colnames(x))))
|
||||
df_trans <- df_trans[!is.na(df_trans$abcode),]
|
||||
x <- as.character(df_trans$colnames)
|
||||
names(x) <- df_trans$abcode
|
||||
|
||||
# add from self-defined dots (...):
|
||||
# get_column_abx(septic_patients %>% rename(thisone = AMX), amox = "thisone")
|
||||
dots <- list(...)
|
||||
if (length(dots) > 0) {
|
||||
dots <- unlist(dots)
|
||||
newnames <- suppressWarnings(as.ab(names(dots)))
|
||||
if (any(is.na(newnames))) {
|
||||
warning("Invalid antibiotic reference(s): ", toString(names(dots)[is.na(newnames)]),
|
||||
call. = FALSE, immediate. = TRUE)
|
||||
}
|
||||
names(dots) <- newnames
|
||||
dots <- dots[!is.na(names(dots))]
|
||||
# merge, but overwrite automatically determined ones by 'dots'
|
||||
x <- c(x[!x %in% dots & !names(x) %in% names(dots)], dots)
|
||||
}
|
||||
|
||||
# sort on name
|
||||
x <- x[sort(names(x))]
|
||||
duplies <- x[base::duplicated(x)]
|
||||
|
||||
if (verbose == TRUE) {
|
||||
for (i in 1:length(x)) {
|
||||
if (x[i] %in% duplies) {
|
||||
message(red(paste0("NOTE: Using column `", bold(x[i]), "` as input for `", names(x)[i],
|
||||
"` (", ab_name(names(x)[i], language = "en", tolower = TRUE), ") [DUPLICATED USE].")))
|
||||
} else {
|
||||
message(blue(paste0("NOTE: Using column `", bold(x[i]), "` as input for `", names(x)[i],
|
||||
"` (", ab_name(names(x)[i], language = "en", tolower = TRUE), ").")))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (n_distinct(x) != length(x)) {
|
||||
msg_txt <- paste("Column(s)", paste0("`", duplies, "`", collapse = " and "), "used for more than one antibiotic.")
|
||||
if (verbose == FALSE) {
|
||||
msg_txt <- paste(msg_txt, "Use verbose = TRUE to see which antibiotics are used by which columns.")
|
||||
}
|
||||
stop(msg_txt, call. = FALSE)
|
||||
}
|
||||
|
||||
if (!is.null(hard_dependencies)) {
|
||||
if (!all(hard_dependencies %in% names(x))) {
|
||||
# missing a hard dependency will return NA and consequently the data will not be analysed
|
||||
missing <- hard_dependencies[!hard_dependencies %in% names(x)]
|
||||
generate_warning_abs_missing(missing, any = FALSE)
|
||||
return(NA)
|
||||
}
|
||||
}
|
||||
if (!is.null(soft_dependencies)) {
|
||||
if (!all(soft_dependencies %in% names(x))) {
|
||||
# missing a soft dependency may lower the reliability
|
||||
missing <- soft_dependencies[!soft_dependencies %in% names(x)]
|
||||
missing <- paste0(bold(missing), " (", ab_name(missing, tolower = TRUE), ")")
|
||||
message(blue('NOTE: Reliability might be improved if these antimicrobial results would be available too:', paste(missing, collapse = ", ")))
|
||||
}
|
||||
}
|
||||
x
|
||||
}
|
||||
|
||||
generate_warning_abs_missing <- function(missing, any = FALSE) {
|
||||
missing <- paste0(missing, " (", ab_name(missing, tolower = TRUE), ")")
|
||||
if (any == TRUE) {
|
||||
any_txt <- c(" any of", "is")
|
||||
} else {
|
||||
any_txt <- c("", "are")
|
||||
}
|
||||
warning(paste0("Introducing NAs since", any_txt[1], " these antimicrobials ", any_txt[2], " required: ",
|
||||
paste(missing, collapse = ", ")),
|
||||
immediate. = TRUE,
|
||||
call. = FALSE)
|
||||
}
|
||||
|
||||
|
||||
stopifnot_installed_package <- function(package) {
|
||||
# no "utils::installed.packages()" since it requires non-staged install since R 3.6.0
|
||||
# https://developer.r-project.org/Blog/public/2019/02/14/staged-install/index.html
|
||||
get(".packageName", envir = asNamespace(package))
|
||||
return(invisible())
|
||||
}
|
||||
|
||||
# translate strings based on inst/translations.tsv
|
||||
#' @importFrom dplyr %>% filter
|
||||
t <- function(from, language = get_locale()) {
|
||||
# if (getOption("AMR_locale", "en") != language) {
|
||||
# language <- getOption("AMR_locale", "en")
|
||||
# }
|
||||
|
||||
if (is.null(language)) {
|
||||
return(from)
|
||||
}
|
||||
if (language %in% c("en", "")) {
|
||||
return(from)
|
||||
}
|
||||
|
||||
df_trans <- translations_file # internal data file
|
||||
|
||||
if (!language %in% df_trans$lang) {
|
||||
stop("Unsupported language: '", language, "' - use one of: ",
|
||||
paste0("'", sort(unique(df_trans$lang)), "'", collapse = ", "),
|
||||
call. = FALSE)
|
||||
}
|
||||
|
||||
df_trans <- df_trans %>% filter(lang == language)
|
||||
|
||||
# default case sensitive if value if 'ignore.case' is missing:
|
||||
df_trans$ignore.case[is.na(df_trans$ignore.case)] <- FALSE
|
||||
# default not using regular expressions (fixed = TRUE) if 'fixed' is missing:
|
||||
df_trans$fixed[is.na(df_trans$fixed)] <- TRUE
|
||||
|
||||
# check if text to look for is in one of the patterns
|
||||
any_form_in_patterns <- tryCatch(any(from %like% paste0("(", paste(df_trans$pattern, collapse = "|"), ")")),
|
||||
error = function(e) {
|
||||
warning("Translation not possible. Please open an issue on GitLab (https://gitlab.com/msberends/AMR/issues) or GitHub (https://github.com/msberends/AMR/issues).", call. = FALSE)
|
||||
return(FALSE)
|
||||
})
|
||||
if (NROW(df_trans) == 0 | !any_form_in_patterns) {
|
||||
return(from)
|
||||
}
|
||||
|
||||
for (i in 1:nrow(df_trans)) {
|
||||
from <- gsub(x = from,
|
||||
pattern = df_trans$pattern[i],
|
||||
replacement = df_trans$replacement[i],
|
||||
fixed = df_trans$fixed[i],
|
||||
ignore.case = df_trans$ignore.case[i])
|
||||
}
|
||||
|
||||
# force UTF-8 for diacritics
|
||||
base::enc2utf8(from)
|
||||
|
||||
}
|
||||
|
||||
"%or%" <- function(x, y) {
|
||||
ifelse(!is.na(x), x, ifelse(!is.na(y), y, NA))
|
||||
}
|
||||
@@ -1,134 +0,0 @@
|
||||
# ==================================================================== #
|
||||
# TITLE #
|
||||
# Antimicrobial Resistance (AMR) Analysis #
|
||||
# #
|
||||
# SOURCE #
|
||||
# https://gitlab.com/msberends/AMR #
|
||||
# #
|
||||
# LICENCE #
|
||||
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
|
||||
# #
|
||||
# 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. #
|
||||
# #
|
||||
# This R package was created for academic research and was publicly #
|
||||
# released in the hope that it will be useful, but it comes WITHOUT #
|
||||
# ANY WARRANTY OR LIABILITY. #
|
||||
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
||||
# ==================================================================== #
|
||||
|
||||
# print successful as.mo coercions to AMR environment
|
||||
#' @importFrom dplyr %>% distinct filter
|
||||
set_mo_history <- function(x, mo, uncertainty_level, force = FALSE) {
|
||||
# disable function for now
|
||||
return(base::invisible())
|
||||
|
||||
# if (base::interactive() | force == TRUE) {
|
||||
# mo_hist <- read_mo_history(uncertainty_level = uncertainty_level, force = force)
|
||||
# df <- data.frame(x, mo, stringsAsFactors = FALSE) %>%
|
||||
# distinct(x, .keep_all = TRUE) %>%
|
||||
# filter(!is.na(x) & !is.na(mo))
|
||||
# if (nrow(df) == 0) {
|
||||
# return(base::invisible())
|
||||
# }
|
||||
# x <- toupper(df$x)
|
||||
# mo <- df$mo
|
||||
# for (i in 1:length(x)) {
|
||||
# # save package version too, as both the as.mo() algorithm and the reference data set may change
|
||||
# if (NROW(mo_hist[base::which(mo_hist$x == x[i] &
|
||||
# mo_hist$uncertainty_level >= uncertainty_level &
|
||||
# mo_hist$package_v == utils::packageVersion("AMR")),]) == 0) {
|
||||
# tryCatch(
|
||||
# assign(x = "mo_history",
|
||||
# value = rbind(mo_hist,
|
||||
# data.frame(
|
||||
# x = x[i],
|
||||
# mo = mo[i],
|
||||
# uncertainty_level = uncertainty_level,
|
||||
# package_v = base::as.character(utils::packageVersion("AMR")),
|
||||
# stringsAsFactors = FALSE)),
|
||||
# envir = asNamespace("AMR")),
|
||||
# error = function(e) invisible())
|
||||
# }
|
||||
# }
|
||||
# }
|
||||
# return(base::invisible())
|
||||
}
|
||||
|
||||
get_mo_history <- function(x, uncertainty_level, force = FALSE) {
|
||||
# disable function for now
|
||||
return(NA)
|
||||
|
||||
# history <- read_mo_history(uncertainty_level = uncertainty_level, force = force)
|
||||
# if (base::is.null(history)) {
|
||||
# NA
|
||||
# } else {
|
||||
# data.frame(x = toupper(x), stringsAsFactors = FALSE) %>%
|
||||
# left_join(history, by = "x") %>%
|
||||
# pull(mo)
|
||||
# }
|
||||
}
|
||||
|
||||
#' @importFrom dplyr %>% filter distinct
|
||||
read_mo_history <- function(uncertainty_level = 2, force = FALSE, unfiltered = FALSE) {
|
||||
# disable function for now
|
||||
return(NULL)
|
||||
|
||||
# if ((!base::interactive() & force == FALSE)) {
|
||||
# return(NULL)
|
||||
# }
|
||||
# uncertainty_level_param <- uncertainty_level
|
||||
#
|
||||
# history <- tryCatch(get("mo_history", envir = asNamespace("AMR")),
|
||||
# error = function(e) NULL)
|
||||
# if (is.null(history)) {
|
||||
# return(NULL)
|
||||
# }
|
||||
# # Below: filter on current package version.
|
||||
# # Even current fullnames may be replaced by new taxonomic names, so new versions of
|
||||
# # the Catalogue of Life must not lead to data corruption.
|
||||
#
|
||||
# if (unfiltered == FALSE) {
|
||||
# history <- history %>%
|
||||
# filter(package_v == as.character(utils::packageVersion("AMR")),
|
||||
# # only take unknowns if uncertainty_level_param is higher
|
||||
# ((mo == "UNKNOWN" & uncertainty_level_param == uncertainty_level) |
|
||||
# (mo != "UNKNOWN" & uncertainty_level_param >= uncertainty_level))) %>%
|
||||
# arrange(desc(uncertainty_level)) %>%
|
||||
# distinct(x, mo, .keep_all = TRUE)
|
||||
# }
|
||||
#
|
||||
# if (nrow(history) == 0) {
|
||||
# NULL
|
||||
# } else {
|
||||
# history
|
||||
# }
|
||||
}
|
||||
|
||||
# @rdname as.mo
|
||||
# @importFrom crayon red
|
||||
# @importFrom utils menu
|
||||
# @export
|
||||
clean_mo_history <- function(...) {
|
||||
# if (!is.null(read_mo_history())) {
|
||||
# if (interactive() & !isTRUE(list(...)$force)) {
|
||||
# q <- menu(title = paste("This will remove all",
|
||||
# format(nrow(read_mo_history(999, unfiltered = TRUE)), big.mark = ","),
|
||||
# "microbial IDs determined previously in this session. Are you sure?"),
|
||||
# choices = c("Yes", "No"),
|
||||
# graphics = FALSE)
|
||||
# if (q != 1) {
|
||||
# return(invisible())
|
||||
# }
|
||||
# }
|
||||
# tryCatch(
|
||||
# assign(x = "mo_history",
|
||||
# value = NULL,
|
||||
# envir = asNamespace("AMR")),
|
||||
# error = function(e) invisible())
|
||||
# cat(red("History removed."))
|
||||
# }
|
||||
}
|
||||
|
||||
@@ -1,387 +0,0 @@
|
||||
# ==================================================================== #
|
||||
# TITLE #
|
||||
# Antimicrobial Resistance (AMR) Analysis #
|
||||
# #
|
||||
# SOURCE #
|
||||
# https://gitlab.com/msberends/AMR #
|
||||
# #
|
||||
# LICENCE #
|
||||
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
|
||||
# #
|
||||
# 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. #
|
||||
# #
|
||||
# This R package was created for academic research and was publicly #
|
||||
# released in the hope that it will be useful, but it comes WITHOUT #
|
||||
# ANY WARRANTY OR LIABILITY. #
|
||||
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
||||
# ==================================================================== #
|
||||
|
||||
#' Property of a microorganism
|
||||
#'
|
||||
#' Use these functions to return a specific property of a microorganism from the \code{\link{microorganisms}} data set. All input values will be evaluated internally with \code{\link{as.mo}}.
|
||||
#' @param x any (vector of) text that can be coerced to a valid microorganism code with \code{\link{as.mo}}
|
||||
#' @param property one of the column names of the \code{\link{microorganisms}} data set or \code{"shortname"}
|
||||
#' @param language language of the returned text, defaults to system language (see \code{\link{get_locale}}) and can also be set with \code{\link{getOption}("AMR_locale")}. Use \code{language = NULL} or \code{language = ""} to prevent translation.
|
||||
#' @param ... other parameters passed on to \code{\link{as.mo}}
|
||||
#' @param open browse the URL using \code{\link[utils]{browseURL}()}
|
||||
#' @details All functions will return the most recently known taxonomic property according to the Catalogue of Life, except for \code{mo_ref}, \code{mo_authors} and \code{mo_year}. This leads to the following results:
|
||||
#' \itemize{
|
||||
#' \item{\code{mo_name("Chlamydia psittaci")} will return \code{"Chlamydophila psittaci"} (with a warning about the renaming)}
|
||||
#' \item{\code{mo_ref("Chlamydia psittaci")} will return \code{"Page, 1968"} (with a warning about the renaming)}
|
||||
#' \item{\code{mo_ref("Chlamydophila psittaci")} will return \code{"Everett et al., 1999"} (without a warning)}
|
||||
#' }
|
||||
#'
|
||||
#' The Gram stain - \code{mo_gramstain()} - will be determined on the taxonomic kingdom and phylum. According to Cavalier-Smith (2002) who defined subkingdoms Negibacteria and Posibacteria, only these phyla are Posibacteria: Actinobacteria, Chloroflexi, Firmicutes and Tenericutes. These bacteria are considered Gram positive - all other bacteria are considered Gram negative. Species outside the kingdom of Bacteria will return a value \code{NA}.
|
||||
#'
|
||||
#' All output will be \link{translate}d where possible.
|
||||
#'
|
||||
#' The function \code{mo_url()} will return the direct URL to the online database entry, which also shows the scientific reference of the concerned species.
|
||||
#' @inheritSection catalogue_of_life Catalogue of Life
|
||||
#' @inheritSection as.mo Source
|
||||
#' @rdname mo_property
|
||||
#' @name mo_property
|
||||
#' @return \itemize{
|
||||
#' \item{An \code{integer} in case of \code{mo_year}}
|
||||
#' \item{A \code{list} in case of \code{mo_taxonomy}}
|
||||
#' \item{A named \code{character} in case of \code{mo_url}}
|
||||
#' \item{A \code{character} in all other cases}
|
||||
#' }
|
||||
#' @export
|
||||
#' @seealso \code{\link{microorganisms}}
|
||||
#' @inheritSection AMR Read more on our website!
|
||||
#' @examples
|
||||
#' ## taxonomic tree
|
||||
#' mo_kingdom("E. coli") # "Bacteria"
|
||||
#' mo_phylum("E. coli") # "Proteobacteria"
|
||||
#' mo_class("E. coli") # "Gammaproteobacteria"
|
||||
#' mo_order("E. coli") # "Enterobacteriales"
|
||||
#' mo_family("E. coli") # "Enterobacteriaceae"
|
||||
#' mo_genus("E. coli") # "Escherichia"
|
||||
#' mo_species("E. coli") # "coli"
|
||||
#' mo_subspecies("E. coli") # ""
|
||||
#'
|
||||
#' ## colloquial properties
|
||||
#' mo_name("E. coli") # "Escherichia coli"
|
||||
#' mo_fullname("E. coli") # "Escherichia coli", same as mo_name()
|
||||
#' mo_shortname("E. coli") # "E. coli"
|
||||
#'
|
||||
#' ## other properties
|
||||
#' mo_gramstain("E. coli") # "Gram negative"
|
||||
#' mo_type("E. coli") # "Bacteria" (equal to kingdom)
|
||||
#' mo_rank("E. coli") # "species"
|
||||
#' mo_url("E. coli") # get the direct url to the online database entry
|
||||
#'
|
||||
#' ## scientific reference
|
||||
#' mo_ref("E. coli") # "Castellani et al., 1919"
|
||||
#' mo_authors("E. coli") # "Castellani et al."
|
||||
#' mo_year("E. coli") # 1919
|
||||
#'
|
||||
#'
|
||||
#' # Abbreviations known in the field
|
||||
#' mo_genus("MRSA") # "Staphylococcus"
|
||||
#' mo_species("MRSA") # "aureus"
|
||||
#' mo_shortname("MRSA") # "S. aureus"
|
||||
#' mo_gramstain("MRSA") # "Gram positive"
|
||||
#'
|
||||
#' mo_genus("VISA") # "Staphylococcus"
|
||||
#' mo_species("VISA") # "aureus"
|
||||
#'
|
||||
#'
|
||||
#' # Known subspecies
|
||||
#' mo_name("doylei") # "Campylobacter jejuni doylei"
|
||||
#' mo_genus("doylei") # "Campylobacter"
|
||||
#' mo_species("doylei") # "jejuni"
|
||||
#' mo_subspecies("doylei") # "doylei"
|
||||
#'
|
||||
#' mo_fullname("K. pneu rh") # "Klebsiella pneumoniae rhinoscleromatis"
|
||||
#' mo_shortname("K. pneu rh") # "K. pneumoniae"
|
||||
#'
|
||||
#'
|
||||
#' # Becker classification, see ?as.mo
|
||||
#' mo_fullname("S. epi") # "Staphylococcus epidermidis"
|
||||
#' mo_fullname("S. epi", Becker = TRUE) # "Coagulase-negative Staphylococcus (CoNS)"
|
||||
#' mo_shortname("S. epi") # "S. epidermidis"
|
||||
#' mo_shortname("S. epi", Becker = TRUE) # "CoNS"
|
||||
#'
|
||||
#' # Lancefield classification, see ?as.mo
|
||||
#' mo_fullname("S. pyo") # "Streptococcus pyogenes"
|
||||
#' mo_fullname("S. pyo", Lancefield = TRUE) # "Streptococcus group A"
|
||||
#' mo_shortname("S. pyo") # "S. pyogenes"
|
||||
#' mo_shortname("S. pyo", Lancefield = TRUE) # "GAS" ('Group A streptococci')
|
||||
#'
|
||||
#'
|
||||
#' # language support for German, Dutch, Spanish, Portuguese, Italian and French
|
||||
#' mo_gramstain("E. coli", language = "de") # "Gramnegativ"
|
||||
#' mo_gramstain("E. coli", language = "nl") # "Gram-negatief"
|
||||
#' mo_gramstain("E. coli", language = "es") # "Gram negativo"
|
||||
#'
|
||||
#' # mo_type is equal to mo_kingdom, but mo_kingdom will remain official
|
||||
#' mo_kingdom("E. coli") # "Bacteria" on a German system
|
||||
#' mo_type("E. coli") # "Bakterien" on a German system
|
||||
#' mo_type("E. coli") # "Bacteria" on an English system
|
||||
#'
|
||||
#' mo_fullname("S. pyogenes",
|
||||
#' Lancefield = TRUE,
|
||||
#' language = "de") # "Streptococcus Gruppe A"
|
||||
#' mo_fullname("S. pyogenes",
|
||||
#' Lancefield = TRUE,
|
||||
#' language = "nl") # "Streptococcus groep A"
|
||||
#'
|
||||
#'
|
||||
#' # get a list with the complete taxonomy (from kingdom to subspecies)
|
||||
#' mo_taxonomy("E. coli")
|
||||
mo_name <- function(x, language = get_locale(), ...) {
|
||||
mo_fullname(x = x, language = language, ... = ...)
|
||||
}
|
||||
|
||||
#' @rdname mo_property
|
||||
#' @export
|
||||
mo_fullname <- function(x, language = get_locale(), ...) {
|
||||
t(mo_validate(x = x, property = "fullname", ...), language = language)
|
||||
}
|
||||
|
||||
#' @rdname mo_property
|
||||
#' @importFrom dplyr %>% mutate pull
|
||||
#' @export
|
||||
mo_shortname <- function(x, language = get_locale(), ...) {
|
||||
dots <- list(...)
|
||||
Becker <- dots$Becker
|
||||
if (is.null(Becker)) {
|
||||
Becker <- FALSE
|
||||
}
|
||||
Lancefield <- dots$Lancefield
|
||||
if (is.null(Lancefield)) {
|
||||
Lancefield <- FALSE
|
||||
}
|
||||
|
||||
# get result without transformations
|
||||
res1 <- AMR::as.mo(x, Becker = FALSE, Lancefield = FALSE, reference_df = dots$reference_df)
|
||||
# and result with transformations
|
||||
res2 <- suppressWarnings(AMR::as.mo(res1, ...))
|
||||
res2_fullname <- mo_fullname(res2, language = language)
|
||||
res2_fullname[res2_fullname %like% " \\(CoNS\\)"] <- "CoNS"
|
||||
res2_fullname[res2_fullname %like% " \\(CoPS\\)"] <- "CoPS"
|
||||
res2_fullname[res2_fullname %like% " \\(KNS\\)"] <- "KNS"
|
||||
res2_fullname[res2_fullname %like% " \\(KPS\\)"] <- "KPS"
|
||||
res2_fullname[res2_fullname %like% " \\(CNS\\)"] <- "CNS"
|
||||
res2_fullname[res2_fullname %like% " \\(CPS\\)"] <- "CPS"
|
||||
res2_fullname[res2_fullname %like% " \\(SCN\\)"] <- "SCN"
|
||||
res2_fullname <- gsub("Streptococcus (group|Gruppe|gruppe|groep|grupo|gruppo|groupe) (.)",
|
||||
"G\\2S",
|
||||
res2_fullname) # turn "Streptococcus group A" and "Streptococcus grupo A" to "GAS"
|
||||
res2_fullname_vector <- res2_fullname[res2_fullname == mo_fullname(res1)]
|
||||
res2_fullname[res2_fullname == mo_fullname(res1)] <- paste0(substr(mo_genus(res2_fullname_vector), 1, 1),
|
||||
". ",
|
||||
suppressWarnings(mo_species(res2_fullname_vector)))
|
||||
if (sum(res1 == res2, na.rm = TRUE) > 0) {
|
||||
res1[res1 == res2] <- paste0(substr(mo_genus(res1[res1 == res2]), 1, 1),
|
||||
". ",
|
||||
suppressWarnings(mo_species(res1[res1 == res2])))
|
||||
}
|
||||
res1[res1 != res2] <- res2_fullname
|
||||
result <- as.character(res1)
|
||||
|
||||
t(result, language = language)
|
||||
}
|
||||
|
||||
#' @rdname mo_property
|
||||
#' @export
|
||||
mo_subspecies <- function(x, language = get_locale(), ...) {
|
||||
t(mo_validate(x = x, property = "subspecies", ...), language = language)
|
||||
}
|
||||
|
||||
#' @rdname mo_property
|
||||
#' @export
|
||||
mo_species <- function(x, language = get_locale(), ...) {
|
||||
t(mo_validate(x = x, property = "species", ...), language = language)
|
||||
}
|
||||
|
||||
#' @rdname mo_property
|
||||
#' @export
|
||||
mo_genus <- function(x, language = get_locale(), ...) {
|
||||
t(mo_validate(x = x, property = "genus", ...), language = language)
|
||||
}
|
||||
|
||||
#' @rdname mo_property
|
||||
#' @export
|
||||
mo_family <- function(x, language = get_locale(), ...) {
|
||||
t(mo_validate(x = x, property = "family", ...), language = language)
|
||||
}
|
||||
|
||||
#' @rdname mo_property
|
||||
#' @export
|
||||
mo_order <- function(x, language = get_locale(), ...) {
|
||||
t(mo_validate(x = x, property = "order", ...), language = language)
|
||||
}
|
||||
|
||||
#' @rdname mo_property
|
||||
#' @export
|
||||
mo_class <- function(x, language = get_locale(), ...) {
|
||||
t(mo_validate(x = x, property = "class", ...), language = language)
|
||||
}
|
||||
|
||||
#' @rdname mo_property
|
||||
#' @export
|
||||
mo_phylum <- function(x, language = get_locale(), ...) {
|
||||
t(mo_validate(x = x, property = "phylum", ...), language = language)
|
||||
}
|
||||
|
||||
#' @rdname mo_property
|
||||
#' @export
|
||||
mo_kingdom <- function(x, language = get_locale(), ...) {
|
||||
if (all(x %in% AMR::microorganisms$kingdom)) {
|
||||
return(x)
|
||||
}
|
||||
x <- as.mo(x, ...)
|
||||
kngdm <- mo_validate(x = x, property = "kingdom", ...)
|
||||
if (language != "en") {
|
||||
kngdm[x == "UNKNOWN"] <- t(kngdm[x == "UNKNOWN"], language = language)
|
||||
}
|
||||
kngdm
|
||||
}
|
||||
|
||||
#' @rdname mo_property
|
||||
#' @export
|
||||
mo_type <- function(x, language = get_locale(), ...) {
|
||||
t(mo_validate(x = x, property = "kingdom", ...), language = language)
|
||||
}
|
||||
|
||||
#' @rdname mo_property
|
||||
#' @export
|
||||
mo_gramstain <- function(x, language = get_locale(), ...) {
|
||||
x.mo <- as.mo(x, ...)
|
||||
x.phylum <- mo_phylum(x.mo, language = "en")
|
||||
x[x.phylum %in% c("Actinobacteria",
|
||||
"Chloroflexi",
|
||||
"Firmicutes",
|
||||
"Tenericutes")] <- "Gram positive"
|
||||
x[x != "Gram positive"] <- "Gram negative"
|
||||
x[mo_kingdom(x.mo, language = "en") != "Bacteria"] <- NA_character_
|
||||
x[x.mo == "B_GRAMP"] <- "Gram positive"
|
||||
x[x.mo == "B_GRAMN"] <- "Gram negative"
|
||||
|
||||
t(x, language = language)
|
||||
}
|
||||
|
||||
#' @rdname mo_property
|
||||
#' @export
|
||||
mo_ref <- function(x, ...) {
|
||||
mo_validate(x = x, property = "ref", ...)
|
||||
}
|
||||
|
||||
#' @rdname mo_property
|
||||
#' @export
|
||||
mo_authors <- function(x, ...) {
|
||||
x <- mo_validate(x = x, property = "ref", ...)
|
||||
# remove last 4 digits and presumably the comma and space that preceeds them
|
||||
x[!is.na(x)] <- gsub(",? ?[0-9]{4}", "", x[!is.na(x)])
|
||||
suppressWarnings(x)
|
||||
}
|
||||
|
||||
#' @rdname mo_property
|
||||
#' @export
|
||||
mo_year <- function(x, ...) {
|
||||
x <- mo_validate(x = x, property = "ref", ...)
|
||||
# get last 4 digits
|
||||
x[!is.na(x)] <- gsub(".*([0-9]{4})$", "\\1", x[!is.na(x)])
|
||||
suppressWarnings(as.integer(x))
|
||||
}
|
||||
|
||||
#' @rdname mo_property
|
||||
#' @export
|
||||
mo_rank <- function(x, ...) {
|
||||
mo_validate(x = x, property = "rank", ...)
|
||||
}
|
||||
|
||||
#' @rdname mo_property
|
||||
#' @export
|
||||
mo_taxonomy <- function(x, language = get_locale(), ...) {
|
||||
x <- AMR::as.mo(x, ...)
|
||||
base::list(kingdom = mo_kingdom(x, language = language),
|
||||
phylum = mo_phylum(x, language = language),
|
||||
class = mo_class(x, language = language),
|
||||
order = mo_order(x, language = language),
|
||||
family = mo_family(x, language = language),
|
||||
genus = mo_genus(x, language = language),
|
||||
species = mo_species(x, language = language),
|
||||
subspecies = mo_subspecies(x, language = language))
|
||||
}
|
||||
|
||||
#' @rdname mo_property
|
||||
#' @importFrom utils browseURL
|
||||
#' @importFrom dplyr %>% left_join select mutate case_when
|
||||
#' @export
|
||||
mo_url <- function(x, open = FALSE, ...) {
|
||||
mo <- AMR::as.mo(x = x, ... = ...)
|
||||
df <- data.frame(mo, stringsAsFactors = FALSE) %>%
|
||||
left_join(select(AMR::microorganisms, mo, source, species_id), by = "mo") %>%
|
||||
mutate(url = case_when(source == "CoL" ~
|
||||
paste0(gsub("{year}", catalogue_of_life$year, catalogue_of_life$url_CoL, fixed = TRUE), "details/species/id/", species_id),
|
||||
source == "DSMZ" ~
|
||||
paste0(catalogue_of_life$url_DSMZ, "?bnu_no=", species_id, "#", species_id),
|
||||
TRUE ~
|
||||
NA_character_))
|
||||
|
||||
u <- df$url
|
||||
names(u) <- mo_fullname(mo)
|
||||
if (open == TRUE) {
|
||||
if (length(u) > 1) {
|
||||
warning("only the first URL will be opened, as `browseURL()` only suports one string.")
|
||||
}
|
||||
browseURL(u[1L])
|
||||
}
|
||||
u
|
||||
}
|
||||
|
||||
|
||||
#' @rdname mo_property
|
||||
#' @importFrom data.table data.table as.data.table setkey
|
||||
#' @export
|
||||
mo_property <- function(x, property = 'fullname', language = get_locale(), ...) {
|
||||
if (length(property) != 1L) {
|
||||
stop("'property' must be of length 1.")
|
||||
}
|
||||
if (!property %in% colnames(AMR::microorganisms)) {
|
||||
stop("invalid property: '", property, "' - use a column name of the `microorganisms` data set")
|
||||
}
|
||||
|
||||
t(mo_validate(x = x, property = property, ...), language = language)
|
||||
}
|
||||
|
||||
mo_validate <- function(x, property, ...) {
|
||||
|
||||
dots <- list(...)
|
||||
Becker <- dots$Becker
|
||||
if (is.null(Becker)) {
|
||||
Becker <- FALSE
|
||||
}
|
||||
Lancefield <- dots$Lancefield
|
||||
if (is.null(Lancefield)) {
|
||||
Lancefield <- FALSE
|
||||
}
|
||||
|
||||
if (!"AMR" %in% base::.packages()) {
|
||||
require("AMR")
|
||||
# check onLoad() in R/zzz.R: data tables are created there.
|
||||
}
|
||||
|
||||
# try to catch an error when inputting an invalid parameter
|
||||
# so the 'call.' can be set to FALSE
|
||||
tryCatch(x[1L] %in% AMR::microorganisms[1, property],
|
||||
error = function(e) stop(e$message, call. = FALSE))
|
||||
|
||||
if (!all(x %in% pull(AMR::microorganisms, property))
|
||||
| Becker %in% c(TRUE, "all")
|
||||
| Lancefield %in% c(TRUE, "all")) {
|
||||
exec_as.mo(x, property = property, ...)
|
||||
} else {
|
||||
if (property == "mo") {
|
||||
return(structure(x, class = "mo"))
|
||||
} else {
|
||||
return(x)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,221 +0,0 @@
|
||||
# ==================================================================== #
|
||||
# TITLE #
|
||||
# Antimicrobial Resistance (AMR) Analysis #
|
||||
# #
|
||||
# SOURCE #
|
||||
# https://gitlab.com/msberends/AMR #
|
||||
# #
|
||||
# LICENCE #
|
||||
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
|
||||
# #
|
||||
# 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. #
|
||||
# #
|
||||
# This R package was created for academic research and was publicly #
|
||||
# released in the hope that it will be useful, but it comes WITHOUT #
|
||||
# ANY WARRANTY OR LIABILITY. #
|
||||
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
||||
# ==================================================================== #
|
||||
|
||||
#' Use predefined reference data set
|
||||
#'
|
||||
#' @description These functions can be used to predefine your own reference to be used in \code{\link{as.mo}} and consequently all \code{mo_*} functions like \code{\link{mo_genus}} and \code{\link{mo_gramstain}}.
|
||||
#'
|
||||
#' This is \strong{the fastest way} to have your organisation (or analysis) specific codes picked up and translated by this package.
|
||||
#' @param path location of your reference file, see Details
|
||||
#' @rdname mo_source
|
||||
#' @name mo_source
|
||||
#' @aliases set_mo_source get_mo_source
|
||||
#' @details The reference file can be a text file seperated with commas (CSV) or tabs or pipes, an Excel file (either 'xls' or 'xlsx' format) or an R object file (extension '.rds'). To use an Excel file, you need to have the \code{readxl} package installed.
|
||||
#'
|
||||
#' \code{set_mo_source} will check the file for validity: it must be a \code{data.frame}, must have a column named \code{"mo"} which contains values from \code{microorganisms$mo} and must have a reference column with your own defined values. If all tests pass, \code{set_mo_source} will read the file into R and export it to \code{"~/.mo_source.rds"}. This compressed data file will then be used at default for MO determination (function \code{\link{as.mo}} and consequently all \code{mo_*} functions like \code{\link{mo_genus}} and \code{\link{mo_gramstain}}). The location of the original file will be saved as option with \code{\link{options}(mo_source = path)}. Its timestamp will be saved with \code{\link{options}(mo_source_datetime = ...)}.
|
||||
#'
|
||||
#' \code{get_mo_source} will return the data set by reading \code{"~/.mo_source.rds"} with \code{\link{readRDS}}. If the original file has changed (the file defined with \code{path}), it will call \code{set_mo_source} to update the data file automatically.
|
||||
#'
|
||||
#' Reading an Excel file (\code{.xlsx}) with only one row has a size of 8-9 kB. The compressed file used by this package will have a size of 0.1 kB and can be read by \code{get_mo_source} in only a couple of microseconds (a millionth of a second).
|
||||
#' @section How it works:
|
||||
#' Imagine this data on a sheet of an Excel file (mo codes were looked up in the `microorganisms` data set). The first column contains the organisation specific codes, the second column contains an MO code from this package:
|
||||
#' \preformatted{
|
||||
#' | A | B |
|
||||
#' --|--------------------|-------------|
|
||||
#' 1 | Organisation XYZ | mo |
|
||||
#' 2 | lab_mo_ecoli | B_ESCHR_COL |
|
||||
#' 3 | lab_mo_kpneumoniae | B_KLBSL_PNE |
|
||||
#' 4 | | |
|
||||
#' }
|
||||
#'
|
||||
#' We save it as \code{'home/me/ourcodes.xlsx'}. Now we have to set it as a source:
|
||||
#' \preformatted{
|
||||
#' set_mo_source("home/me/ourcodes.xlsx")
|
||||
#' # Created mo_source file '~/.mo_source.rds' from 'home/me/ourcodes.xlsx'.
|
||||
#' }
|
||||
#'
|
||||
#' It has now created a file "~/.mo_source.rds" with the contents of our Excel file, but only the first column with foreign values and the 'mo' column will be kept.
|
||||
#'
|
||||
#' And now we can use it in our functions:
|
||||
#' \preformatted{
|
||||
#' as.mo("lab_mo_ecoli")
|
||||
#' [1] B_ESCHR_COL
|
||||
#'
|
||||
#' mo_genus("lab_mo_kpneumoniae")
|
||||
#' [1] "Klebsiella"
|
||||
#'
|
||||
#' # other input values still work too
|
||||
#' as.mo(c("Escherichia coli", "E. coli", "lab_mo_ecoli"))
|
||||
#' [1] B_ESCHR_COL B_ESCHR_COL B_ESCHR_COL
|
||||
#' }
|
||||
#'
|
||||
#' If we edit the Excel file to, let's say, this:
|
||||
#' \preformatted{
|
||||
#' | A | B |
|
||||
#' --|--------------------|-------------|
|
||||
#' 1 | Organisation XYZ | mo |
|
||||
#' 2 | lab_mo_ecoli | B_ESCHR_COL |
|
||||
#' 3 | lab_mo_kpneumoniae | B_KLBSL_PNE |
|
||||
#' 4 | lab_Staph_aureus | B_STPHY_AUR |
|
||||
#' 5 | | |
|
||||
#' }
|
||||
#'
|
||||
#' ...any new usage of an MO function in this package will update your data:
|
||||
#' \preformatted{
|
||||
#' as.mo("lab_mo_ecoli")
|
||||
#' # Updated mo_source file '~/.mo_source.rds' from 'home/me/ourcodes.xlsx'.
|
||||
#' [1] B_ESCHR_COL
|
||||
#'
|
||||
#' mo_genus("lab_Staph_aureus")
|
||||
#' [1] "Staphylococcus"
|
||||
#' }
|
||||
#'
|
||||
#' To remove the reference completely, just use any of these:
|
||||
#' \preformatted{
|
||||
#' set_mo_source("")
|
||||
#' set_mo_source(NULL)
|
||||
#' # Removed mo_source file '~/.mo_source.rds'.
|
||||
#' }
|
||||
#' @importFrom dplyr select everything
|
||||
#' @export
|
||||
#' @inheritSection AMR Read more on our website!
|
||||
set_mo_source <- function(path) {
|
||||
|
||||
file_location <- path.expand('~/mo_source.rds')
|
||||
|
||||
if (!is.character(path) | length(path) > 1) {
|
||||
stop("`path` must be a character of length 1.")
|
||||
}
|
||||
|
||||
if (path %in% c(NULL, "")) {
|
||||
options(mo_source = NULL)
|
||||
options(mo_source_timestamp = NULL)
|
||||
if (file.exists(file_location)) {
|
||||
unlink(file_location)
|
||||
message("Removed mo_source file '", file_location, "'.")
|
||||
}
|
||||
return(invisible())
|
||||
}
|
||||
|
||||
if (!file.exists(path)) {
|
||||
stop("File not found: ", path)
|
||||
}
|
||||
|
||||
if (path %like% '[.]rds$') {
|
||||
df <- readRDS(path)
|
||||
|
||||
} else if (path %like% '[.]xlsx?$') {
|
||||
# is Excel file (old or new)
|
||||
if (!"readxl" %in% utils::installed.packages()) {
|
||||
stop("Install the 'readxl' package first.")
|
||||
}
|
||||
df <- readxl::read_excel(path)
|
||||
|
||||
} else if (path %like% '[.]tsv$') {
|
||||
df <- utils::read.table(header = TRUE, sep = "\t", stringsAsFactors = FALSE)
|
||||
|
||||
} else {
|
||||
# try comma first
|
||||
try(
|
||||
df <- utils::read.table(header = TRUE, sep = ",", stringsAsFactors = FALSE),
|
||||
silent = TRUE)
|
||||
if (!mo_source_isvalid(df)) {
|
||||
# try tab
|
||||
try(
|
||||
df <- utils::read.table(header = TRUE, sep = "\t", stringsAsFactors = FALSE),
|
||||
silent = TRUE)
|
||||
}
|
||||
if (!mo_source_isvalid(df)) {
|
||||
# try pipe
|
||||
try(
|
||||
df <- utils::read.table(header = TRUE, sep = "|", stringsAsFactors = FALSE),
|
||||
silent = TRUE)
|
||||
}
|
||||
}
|
||||
|
||||
if (!mo_source_isvalid(df)) {
|
||||
stop("File must contain a column with self-defined values and a reference column `mo` with valid values from the `microorganisms` data set.")
|
||||
}
|
||||
|
||||
df <- df %>% filter(!is.na(mo))
|
||||
|
||||
# keep only first two columns, second must be mo
|
||||
if (colnames(df)[1] == "mo") {
|
||||
df <- df[, c(2, 1)]
|
||||
} else {
|
||||
df <- df[, c(1, 2)]
|
||||
}
|
||||
|
||||
df <- as.data.frame(df, stringAsFactors = FALSE)
|
||||
|
||||
# success
|
||||
if (file.exists(file_location)) {
|
||||
action <- "Updated"
|
||||
} else {
|
||||
action <- "Created"
|
||||
}
|
||||
saveRDS(df, file_location)
|
||||
options(mo_source = path)
|
||||
options(mo_source_timestamp = as.character(file.info(path)$mtime))
|
||||
message(action, " mo_source file '", file_location, "' from '", path, "'.")
|
||||
}
|
||||
|
||||
#' @rdname mo_source
|
||||
#' @export
|
||||
get_mo_source <- function() {
|
||||
if (is.null(getOption("mo_source", NULL))) {
|
||||
NULL
|
||||
} else {
|
||||
old_time <- as.POSIXct(getOption("mo_source_timestamp"))
|
||||
new_time <- as.POSIXct(as.character(file.info(getOption("mo_source", ""))$mtime))
|
||||
|
||||
if (is.na(new_time)) {
|
||||
# source file was deleted, remove reference too
|
||||
set_mo_source("")
|
||||
return(NULL)
|
||||
}
|
||||
if (new_time != old_time) {
|
||||
# set updated source
|
||||
set_mo_source(getOption("mo_source"))
|
||||
}
|
||||
file_location <- path.expand('~/mo_source.rds')
|
||||
readRDS(file_location)
|
||||
}
|
||||
}
|
||||
|
||||
mo_source_isvalid <- function(x) {
|
||||
if (deparse(substitute(x)) == "get_mo_source()") {
|
||||
return(TRUE)
|
||||
}
|
||||
if (identical(x, get_mo_source())) {
|
||||
return(TRUE)
|
||||
}
|
||||
if (is.null(x)) {
|
||||
return(TRUE)
|
||||
}
|
||||
if (!is.data.frame(x)) {
|
||||
return(FALSE)
|
||||
}
|
||||
if (!"mo" %in% colnames(x)) {
|
||||
return(FALSE)
|
||||
}
|
||||
all(x$mo %in% c("", AMR::microorganisms$mo))
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
# ==================================================================== #
|
||||
# TITLE #
|
||||
# Antimicrobial Resistance (AMR) Analysis #
|
||||
# #
|
||||
# SOURCE #
|
||||
# https://gitlab.com/msberends/AMR #
|
||||
# #
|
||||
# LICENCE #
|
||||
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
|
||||
# #
|
||||
# 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. #
|
||||
# #
|
||||
# This R package was created for academic research and was publicly #
|
||||
# released in the hope that it will be useful, but it comes WITHOUT #
|
||||
# ANY WARRANTY OR LIABILITY. #
|
||||
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
||||
# ==================================================================== #
|
||||
|
||||
#' Symbol of a p value
|
||||
#'
|
||||
#' Return the symbol related to the p value: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1. Values above \code{p = 1} will return \code{NA}.
|
||||
#' @param p p value
|
||||
#' @param emptychar text to show when \code{p > 0.1}
|
||||
#' @return Text
|
||||
#' @inheritSection AMR Read more on our website!
|
||||
#' @export
|
||||
p.symbol <- function(p, emptychar = " ") {
|
||||
setting.bak <- options()$scipen
|
||||
options(scipen = 999)
|
||||
s <- vector(mode = "character", length = length(p))
|
||||
for (i in 1:length(p)) {
|
||||
if (is.na(p[i])) {
|
||||
s[i] <- NA_character_
|
||||
next
|
||||
}
|
||||
if (p[i] > 1) {
|
||||
s[i] <- NA_character_
|
||||
next
|
||||
} else {
|
||||
p_test <- p[i]
|
||||
}
|
||||
|
||||
if (p_test > 0.1) {
|
||||
s[i] <- emptychar
|
||||
} else if (p_test > 0.05) {
|
||||
s[i] <- '.'
|
||||
} else if (p_test > 0.01) {
|
||||
s[i] <- '*'
|
||||
} else if (p_test > 0.001) {
|
||||
s[i] <- '**'
|
||||
} else if (p_test >= 0) {
|
||||
s[i] <- '***'
|
||||
}
|
||||
}
|
||||
options(scipen = setting.bak)
|
||||
s
|
||||
}
|
||||
@@ -1,237 +0,0 @@
|
||||
# ==================================================================== #
|
||||
# TITLE #
|
||||
# Antimicrobial Resistance (AMR) Analysis #
|
||||
# #
|
||||
# SOURCE #
|
||||
# https://gitlab.com/msberends/AMR #
|
||||
# #
|
||||
# LICENCE #
|
||||
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
|
||||
# #
|
||||
# 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. #
|
||||
# #
|
||||
# This R package was created for academic research and was publicly #
|
||||
# released in the hope that it will be useful, but it comes WITHOUT #
|
||||
# ANY WARRANTY OR LIABILITY. #
|
||||
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
||||
# ==================================================================== #
|
||||
|
||||
#' Calculate resistance of isolates
|
||||
#'
|
||||
#' @description These functions can be used to calculate the (co-)resistance of microbial isolates (i.e. percentage of S, SI, I, IR or R). All functions support quasiquotation with pipes, can be used in \code{dplyr}s \code{\link[dplyr]{summarise}} and support grouped variables, see \emph{Examples}.
|
||||
#'
|
||||
#' \code{portion_R} and \code{portion_IR} can be used to calculate resistance, \code{portion_S} and \code{portion_SI} can be used to calculate susceptibility.\cr
|
||||
#' @param ... one or more vectors (or columns) with antibiotic interpretations. They will be transformed internally with \code{\link{as.rsi}} if needed. Use multiple columns to calculate (the lack of) co-resistance: the probability where one of two drugs have a resistant or susceptible result. See Examples.
|
||||
#' @param minimum the minimum allowed number of available (tested) isolates. Any isolate count lower than \code{minimum} will return \code{NA} with a warning. The default number of \code{30} isolates is advised by the Clinical and Laboratory Standards Institute (CLSI) as best practice, see Source.
|
||||
#' @param as_percent a logical to indicate whether the output must be returned as a hundred fold with \% sign (a character). A value of \code{0.123456} will then be returned as \code{"12.3\%"}.
|
||||
#' @param also_single_tested a logical to indicate whether (in combination therapies) also observations should be included where not all antibiotics were tested, but at least one of the tested antibiotics contains a target interpretation (e.g. S in case of \code{portion_S} and R in case of \code{portion_R}). \strong{This would lead to selection bias in almost all cases.}
|
||||
#' @param data a \code{data.frame} containing columns with class \code{rsi} (see \code{\link{as.rsi}})
|
||||
#' @param translate_ab a column name of the \code{\link{antibiotics}} data set to translate the antibiotic abbreviations to, using \code{\link{ab_property}}
|
||||
#' @inheritParams ab_property
|
||||
#' @param combine_SI a logical to indicate whether all values of S and I must be merged into one, so the output only consists of S+I vs. R (susceptible vs. resistant). This used to be the parameter \code{combine_IR}, but this now follows the redefinition by EUCAST about the interpretion of I (increased exposure) in 2019, see section 'Interpretation of S, I and R' below. Default is \code{TRUE}.
|
||||
#' @param combine_IR a logical to indicate whether all values of I and R must be merged into one, so the output only consists of S vs. I+R (susceptible vs. non-susceptible). This is outdated, see parameter \code{combine_SI}.
|
||||
#' @inheritSection as.rsi Interpretation of S, I and R
|
||||
#' @details \strong{Remember that you should filter your table to let it contain only first isolates!} Use \code{\link{first_isolate}} to determine them in your data set.
|
||||
#'
|
||||
#' These functions are not meant to count isolates, but to calculate the portion of resistance/susceptibility. Use the \code{\link[AMR]{count}} functions to count isolates. \emph{Low counts can infuence the outcome - these \code{portion} functions may camouflage this, since they only return the portion albeit being dependent on the \code{minimum} parameter.}
|
||||
#'
|
||||
#' \code{portion_df} takes any variable from \code{data} that has an \code{"rsi"} class (created with \code{\link{as.rsi}}) and calculates the portions R, I and S. The resulting \emph{tidy data} (see Source) \code{data.frame} will have three rows (S/I/R) and a column for each variable with class \code{"rsi"}.
|
||||
#' \if{html}{
|
||||
# (created with https://www.latex4technics.com/)
|
||||
#' \cr\cr
|
||||
#' To calculate the probability (\emph{p}) of susceptibility of one antibiotic, we use this formula:
|
||||
#' \out{<div style="text-align: center;">}\figure{combi_therapy_2.png}\out{</div>}
|
||||
#' To calculate the probability (\emph{p}) of susceptibility of more antibiotics (i.e. combination therapy), we need to check whether one of them has a susceptible result (as numerator) and count all cases where all antibiotics were tested (as denominator). \cr
|
||||
#' \cr
|
||||
#' For two antibiotics:
|
||||
#' \out{<div style="text-align: center;">}\figure{combi_therapy_2.png}\out{</div>}
|
||||
#' \cr
|
||||
#' For three antibiotics:
|
||||
#' \out{<div style="text-align: center;">}\figure{combi_therapy_2.png}\out{</div>}
|
||||
#' \cr
|
||||
#' And so on.
|
||||
#' }
|
||||
#'
|
||||
#' @source \strong{M39 Analysis and Presentation of Cumulative Antimicrobial Susceptibility Test Data, 4th Edition}, 2014, \emph{Clinical and Laboratory Standards Institute (CLSI)}. \url{https://clsi.org/standards/products/microbiology/documents/m39/}.
|
||||
#'
|
||||
#' Wickham H. \strong{Tidy Data.} The Journal of Statistical Software, vol. 59, 2014. \url{http://vita.had.co.nz/papers/tidy-data.html}
|
||||
#' @seealso \code{\link[AMR]{count}_*} to count resistant and susceptible isolates.
|
||||
#' @keywords resistance susceptibility rsi_df rsi antibiotics isolate isolates
|
||||
#' @return Double or, when \code{as_percent = TRUE}, a character.
|
||||
#' @rdname portion
|
||||
#' @name portion
|
||||
#' @export
|
||||
#' @inheritSection AMR Read more on our website!
|
||||
#' @examples
|
||||
#' # septic_patients is a data set available in the AMR package. It is true, genuine data.
|
||||
#' ?septic_patients
|
||||
#'
|
||||
#' # Calculate resistance
|
||||
#' portion_R(septic_patients$AMX)
|
||||
#' portion_IR(septic_patients$AMX)
|
||||
#'
|
||||
#' # Or susceptibility
|
||||
#' portion_S(septic_patients$AMX)
|
||||
#' portion_SI(septic_patients$AMX)
|
||||
#'
|
||||
|
||||
#' # Do the above with pipes:
|
||||
#' library(dplyr)
|
||||
#' septic_patients %>% portion_R(AMX)
|
||||
#' septic_patients %>% portion_IR(AMX)
|
||||
#' septic_patients %>% portion_S(AMX)
|
||||
#' septic_patients %>% portion_SI(AMX)
|
||||
#'
|
||||
#' septic_patients %>%
|
||||
#' group_by(hospital_id) %>%
|
||||
#' summarise(p = portion_S(CIP),
|
||||
#' n = n_rsi(CIP)) # n_rsi works like n_distinct in dplyr
|
||||
#'
|
||||
#' septic_patients %>%
|
||||
#' group_by(hospital_id) %>%
|
||||
#' summarise(R = portion_R(CIP, as_percent = TRUE),
|
||||
#' I = portion_I(CIP, as_percent = TRUE),
|
||||
#' S = portion_S(CIP, as_percent = TRUE),
|
||||
#' n1 = count_all(CIP), # the actual total; sum of all three
|
||||
#' n2 = n_rsi(CIP), # same - analogous to n_distinct
|
||||
#' total = n()) # NOT the number of tested isolates!
|
||||
#'
|
||||
#' # Calculate co-resistance between amoxicillin/clav acid and gentamicin,
|
||||
#' # so we can see that combination therapy does a lot more than mono therapy:
|
||||
#' septic_patients %>% portion_S(AMC) # S = 71.4%
|
||||
#' septic_patients %>% count_all(AMC) # n = 1879
|
||||
#'
|
||||
#' septic_patients %>% portion_S(GEN) # S = 74.0%
|
||||
#' septic_patients %>% count_all(GEN) # n = 1855
|
||||
#'
|
||||
#' septic_patients %>% portion_S(AMC, GEN) # S = 92.3%
|
||||
#' septic_patients %>% count_all(AMC, GEN) # n = 1798
|
||||
#'
|
||||
#'
|
||||
#' septic_patients %>%
|
||||
#' group_by(hospital_id) %>%
|
||||
#' summarise(cipro_p = portion_S(CIP, as_percent = TRUE),
|
||||
#' cipro_n = count_all(CIP),
|
||||
#' genta_p = portion_S(GEN, as_percent = TRUE),
|
||||
#' genta_n = count_all(GEN),
|
||||
#' combination_p = portion_S(CIP, GEN, as_percent = TRUE),
|
||||
#' combination_n = count_all(CIP, GEN))
|
||||
#'
|
||||
#' # Get portions S/I/R immediately of all rsi columns
|
||||
#' septic_patients %>%
|
||||
#' select(AMX, CIP) %>%
|
||||
#' portion_df(translate = FALSE)
|
||||
#'
|
||||
#' # It also supports grouping variables
|
||||
#' septic_patients %>%
|
||||
#' select(hospital_id, AMX, CIP) %>%
|
||||
#' group_by(hospital_id) %>%
|
||||
#' portion_df(translate = FALSE)
|
||||
#'
|
||||
#'
|
||||
#' \dontrun{
|
||||
#'
|
||||
#' # calculate current empiric combination therapy of Helicobacter gastritis:
|
||||
#' my_table %>%
|
||||
#' filter(first_isolate == TRUE,
|
||||
#' genus == "Helicobacter") %>%
|
||||
#' summarise(p = portion_S(AMX, MTR), # amoxicillin with metronidazole
|
||||
#' n = count_all(AMX, MTR))
|
||||
#' }
|
||||
portion_R <- function(...,
|
||||
minimum = 30,
|
||||
as_percent = FALSE,
|
||||
also_single_tested = FALSE) {
|
||||
rsi_calc(...,
|
||||
type = "R",
|
||||
include_I = FALSE,
|
||||
minimum = minimum,
|
||||
as_percent = as_percent,
|
||||
also_single_tested = also_single_tested,
|
||||
only_count = FALSE)
|
||||
}
|
||||
|
||||
#' @rdname portion
|
||||
#' @export
|
||||
portion_IR <- function(...,
|
||||
minimum = 30,
|
||||
as_percent = FALSE,
|
||||
also_single_tested = FALSE) {
|
||||
rsi_calc(...,
|
||||
type = "R",
|
||||
include_I = TRUE,
|
||||
minimum = minimum,
|
||||
as_percent = as_percent,
|
||||
also_single_tested = also_single_tested,
|
||||
only_count = FALSE)
|
||||
}
|
||||
|
||||
#' @rdname portion
|
||||
#' @export
|
||||
portion_I <- function(...,
|
||||
minimum = 30,
|
||||
as_percent = FALSE,
|
||||
also_single_tested = FALSE) {
|
||||
rsi_calc(...,
|
||||
type = "I",
|
||||
include_I = FALSE,
|
||||
minimum = minimum,
|
||||
as_percent = as_percent,
|
||||
also_single_tested = also_single_tested,
|
||||
only_count = FALSE)
|
||||
}
|
||||
|
||||
#' @rdname portion
|
||||
#' @export
|
||||
portion_SI <- function(...,
|
||||
minimum = 30,
|
||||
as_percent = FALSE,
|
||||
also_single_tested = FALSE) {
|
||||
rsi_calc(...,
|
||||
type = "S",
|
||||
include_I = TRUE,
|
||||
minimum = minimum,
|
||||
as_percent = as_percent,
|
||||
also_single_tested = also_single_tested,
|
||||
only_count = FALSE)
|
||||
}
|
||||
|
||||
#' @rdname portion
|
||||
#' @export
|
||||
portion_S <- function(...,
|
||||
minimum = 30,
|
||||
as_percent = FALSE,
|
||||
also_single_tested = FALSE) {
|
||||
rsi_calc(...,
|
||||
type = "S",
|
||||
include_I = FALSE,
|
||||
minimum = minimum,
|
||||
as_percent = as_percent,
|
||||
also_single_tested = also_single_tested,
|
||||
only_count = FALSE)
|
||||
}
|
||||
|
||||
#' @rdname portion
|
||||
#' @importFrom dplyr %>% select_if bind_rows summarise_if mutate group_vars select everything
|
||||
#' @export
|
||||
portion_df <- function(data,
|
||||
translate_ab = "name",
|
||||
language = get_locale(),
|
||||
minimum = 30,
|
||||
as_percent = FALSE,
|
||||
combine_SI = TRUE,
|
||||
combine_IR = FALSE) {
|
||||
|
||||
rsi_calc_df(type = "portion",
|
||||
data = data,
|
||||
translate_ab = translate_ab,
|
||||
language = language,
|
||||
minimum = minimum,
|
||||
as_percent = as_percent,
|
||||
combine_SI = combine_SI,
|
||||
combine_IR = combine_IR,
|
||||
combine_SI_missing = missing(combine_SI))
|
||||
}
|
||||
@@ -1,176 +0,0 @@
|
||||
# ==================================================================== #
|
||||
# TITLE #
|
||||
# Antimicrobial Resistance (AMR) Analysis #
|
||||
# #
|
||||
# SOURCE #
|
||||
# https://gitlab.com/msberends/AMR #
|
||||
# #
|
||||
# LICENCE #
|
||||
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
|
||||
# #
|
||||
# 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. #
|
||||
# #
|
||||
# This R package was created for academic research and was publicly #
|
||||
# released in the hope that it will be useful, but it comes WITHOUT #
|
||||
# ANY WARRANTY OR LIABILITY. #
|
||||
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
||||
# ==================================================================== #
|
||||
|
||||
#' Read data from 4D database
|
||||
#'
|
||||
#' This function is only useful for the MMB department of the UMCG. Use this function to \strong{import data by just defining the \code{file} parameter}. It will automatically transform birth dates and calculate patients age, translate the column names to English, transform the MO codes with \code{\link{as.mo}} and transform all antimicrobial columns with \code{\link{as.rsi}}.
|
||||
#' @inheritParams utils::read.table
|
||||
#' @param info a logical to indicate whether info about the import should be printed, defaults to \code{TRUE} in interactive sessions
|
||||
#' @details Column names will be transformed, but the original column names are set as a "label" attribute and can be seen in e.g. RStudio Viewer.
|
||||
#' @inheritSection AMR Read more on our website!
|
||||
#' @export
|
||||
read.4D <- function(file,
|
||||
info = interactive(),
|
||||
header = TRUE,
|
||||
row.names = NULL,
|
||||
sep = "\t",
|
||||
quote = "\"'",
|
||||
dec = ",",
|
||||
na.strings = c("NA", "", "."),
|
||||
skip = 2,
|
||||
check.names = TRUE,
|
||||
strip.white = TRUE,
|
||||
fill = TRUE,
|
||||
blank.lines.skip = TRUE,
|
||||
stringsAsFactors = FALSE,
|
||||
fileEncoding = "UTF-8",
|
||||
encoding = "UTF-8") {
|
||||
|
||||
if (info == TRUE) {
|
||||
message("Importing ", file, "... ", appendLF = FALSE)
|
||||
}
|
||||
data_4D <- utils::read.table(file = file,
|
||||
row.names = row.names,
|
||||
header = header,
|
||||
sep = sep,
|
||||
quote = quote,
|
||||
dec = dec,
|
||||
na.strings = na.strings,
|
||||
skip = skip,
|
||||
check.names = check.names,
|
||||
strip.white = strip.white,
|
||||
fill = fill,
|
||||
blank.lines.skip = blank.lines.skip,
|
||||
stringsAsFactors = stringsAsFactors,
|
||||
fileEncoding = fileEncoding,
|
||||
encoding = encoding)
|
||||
|
||||
# helper function for dates
|
||||
to_date_4D <- function(x) {
|
||||
date_regular <- as.Date(x, format = "%d-%m-%y")
|
||||
posixlt <- as.POSIXlt(date_regular)
|
||||
# born after today will be born 100 years ago
|
||||
# based on https://stackoverflow.com/a/3312971/4575331
|
||||
posixlt[date_regular > Sys.Date() & !is.na(posixlt)]$year <- posixlt[date_regular > Sys.Date() & !is.na(posixlt)]$year - 100
|
||||
as.Date(posixlt)
|
||||
}
|
||||
|
||||
if (info == TRUE) {
|
||||
message("OK\nTransforming column names... ", appendLF = FALSE)
|
||||
}
|
||||
if ("row.names" %in% colnames(data_4D) & all(is.na(data_4D[, ncol(data_4D)]))) {
|
||||
# remove first column name "row.names" and remove last empty column
|
||||
colnames(data_4D) <- c(colnames(data_4D)[2:ncol(data_4D)], "_skip_last")
|
||||
data_4D <- data_4D[, -ncol(data_4D)]
|
||||
}
|
||||
|
||||
colnames(data_4D) <- tolower(colnames(data_4D))
|
||||
if (all(c("afnamedat", "gebdatum") %in% colnames(data_4D))) {
|
||||
# add age
|
||||
data_4D$age <- NA_integer_
|
||||
}
|
||||
cols_wanted <- c("patientnr", "gebdatum", "age", "mv", "monsternr", "afnamedat", "bepaling",
|
||||
"afd.", "spec", "mat", "matbijz.", "mocode",
|
||||
"amfo", "amox", "anid", "azit", "casp", "cecl", "cefe", "cfcl",
|
||||
"cfot", "cfox", "cfta", "cftr", "cfur", "chlo", "cipr", "clin",
|
||||
"cocl", "ctta", "dapt", "doxy", "eryt", "fluo", "fluz", "fosf",
|
||||
"fusi", "gehi", "gent", "imip", "kana", "levo", "line", "mero",
|
||||
"metr", "mico", "mino", "moxi", "mupi", "nali", "nitr", "norf",
|
||||
"oxac", "peni", "pipe", "pita", "poly", "posa", "quda", "rifa",
|
||||
"spat", "teic", "tige", "tobr", "trim", "trsu", "vana", "vanb",
|
||||
"vanc", "vori")
|
||||
# this ones actually exist
|
||||
cols_wanted <- cols_wanted[cols_wanted %in% colnames(data_4D)]
|
||||
# order of columns
|
||||
data_4D <- data_4D[, cols_wanted]
|
||||
|
||||
# backup original column names
|
||||
colnames.bak <- toupper(colnames(data_4D))
|
||||
colnames.bak[colnames.bak == "AGE"] <- NA_character_
|
||||
|
||||
# rename of columns
|
||||
colnames(data_4D) <- gsub("patientnr", "patient_id", colnames(data_4D), fixed = TRUE)
|
||||
colnames(data_4D) <- gsub("gebdatum", "date_birth", colnames(data_4D), fixed = TRUE)
|
||||
colnames(data_4D) <- gsub("mv", "gender", colnames(data_4D), fixed = TRUE)
|
||||
colnames(data_4D) <- gsub("monsternr", "sample_id", colnames(data_4D), fixed = TRUE)
|
||||
colnames(data_4D) <- gsub("afnamedat", "date_received", colnames(data_4D), fixed = TRUE)
|
||||
colnames(data_4D) <- gsub("bepaling", "sample_test", colnames(data_4D), fixed = TRUE)
|
||||
colnames(data_4D) <- gsub("afd.", "department", colnames(data_4D), fixed = TRUE)
|
||||
colnames(data_4D) <- gsub("spec", "specialty", colnames(data_4D), fixed = TRUE)
|
||||
colnames(data_4D) <- gsub("matbijz.", "specimen_type", colnames(data_4D), fixed = TRUE)
|
||||
colnames(data_4D) <- gsub("mat", "specimen_group", colnames(data_4D), fixed = TRUE)
|
||||
colnames(data_4D) <- gsub("mocode", "mo", colnames(data_4D), fixed = TRUE)
|
||||
|
||||
if (info == TRUE) {
|
||||
message("OK\nTransforming dates and age... ", appendLF = FALSE)
|
||||
}
|
||||
if ("date_birth" %in% colnames(data_4D)) {
|
||||
data_4D$date_birth <- to_date_4D(data_4D$date_birth)
|
||||
}
|
||||
if ("date_received" %in% colnames(data_4D)) {
|
||||
data_4D$date_received <- to_date_4D(data_4D$date_received)
|
||||
}
|
||||
if ("age" %in% colnames(data_4D)) {
|
||||
data_4D$age <- age(data_4D$date_birth, data_4D$date_received)
|
||||
}
|
||||
if ("gender" %in% colnames(data_4D)) {
|
||||
data_4D$gender[data_4D$gender == "V"] <- "F"
|
||||
}
|
||||
|
||||
if (info == TRUE) {
|
||||
message("OK\nTransforming MO codes... ", appendLF = FALSE)
|
||||
}
|
||||
if ("mo" %in% colnames(data_4D)) {
|
||||
data_4D$mo <- as.mo(data_4D$mo)
|
||||
# column right of mo is:
|
||||
drug1 <- colnames(data_4D)[grep("^mo$", colnames(data_4D)) + 1]
|
||||
if (!is.na(drug1)) {
|
||||
# and last is:
|
||||
drug_last <- colnames(data_4D)[length(data_4D)]
|
||||
# transform those to rsi:
|
||||
data_4D <- suppressWarnings(mutate_at(data_4D, vars(drug1:drug_last), as.rsi))
|
||||
}
|
||||
}
|
||||
|
||||
# set original column names as label (can be seen in RStudio Viewer)
|
||||
if (info == TRUE) {
|
||||
message("OK\nSetting original column names as label... ", appendLF = FALSE)
|
||||
}
|
||||
for (i in 1:ncol(data_4D)) {
|
||||
if (!is.na(colnames.bak[i])) {
|
||||
attr(data_4D[, i], "label") <- colnames.bak[i]
|
||||
}
|
||||
}
|
||||
|
||||
if (info == TRUE) {
|
||||
message("OK\nSetting query as label to data.frame... ", appendLF = FALSE)
|
||||
}
|
||||
qry <- readLines(con <- file(file, open="r"))[1]
|
||||
close(con)
|
||||
attr(data_4D, "label") <- qry
|
||||
|
||||
if (info == TRUE) {
|
||||
message("OK")
|
||||
}
|
||||
|
||||
data_4D
|
||||
}
|
||||
|
||||
@@ -1,400 +0,0 @@
|
||||
# ==================================================================== #
|
||||
# TITLE #
|
||||
# Antimicrobial Resistance (AMR) Analysis #
|
||||
# #
|
||||
# SOURCE #
|
||||
# https://gitlab.com/msberends/AMR #
|
||||
# #
|
||||
# LICENCE #
|
||||
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
|
||||
# #
|
||||
# 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. #
|
||||
# #
|
||||
# This R package was created for academic research and was publicly #
|
||||
# released in the hope that it will be useful, but it comes WITHOUT #
|
||||
# ANY WARRANTY OR LIABILITY. #
|
||||
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
||||
# ==================================================================== #
|
||||
|
||||
#' Predict antimicrobial resistance
|
||||
#'
|
||||
#' Create a prediction model to predict antimicrobial resistance for the next years on statistical solid ground. Standard errors (SE) will be returned as columns \code{se_min} and \code{se_max}. See Examples for a real live example.
|
||||
#' @param col_ab column name of \code{x} with antimicrobial interpretations (\code{R}, \code{I} and \code{S})
|
||||
#' @param col_date column name of the date, will be used to calculate years if this column doesn't consist of years already, defaults to the first column of with a date class
|
||||
#' @param year_min lowest year to use in the prediction model, dafaults to the lowest year in \code{col_date}
|
||||
#' @param year_max highest year to use in the prediction model, defaults to 10 years after today
|
||||
#' @param year_every unit of sequence between lowest year found in the data and \code{year_max}
|
||||
#' @param minimum minimal amount of available isolates per year to include. Years containing less observations will be estimated by the model.
|
||||
#' @param model the statistical model of choice. Defaults to a generalised linear regression model with binomial distribution, assuming that a period of zero resistance was followed by a period of increasing resistance leading slowly to more and more resistance. See Details for valid options.
|
||||
#' @param I_as_S a logical to indicate whether values \code{I} should be treated as \code{S}
|
||||
#' @param preserve_measurements a logical to indicate whether predictions of years that are actually available in the data should be overwritten by the original data. The standard errors of those years will be \code{NA}.
|
||||
#' @param info a logical to indicate whether textual analysis should be printed with the name and \code{\link{summary}} of the statistical model.
|
||||
#' @param main title of the plot
|
||||
#' @param ribbon a logical to indicate whether a ribbon should be shown (default) or error bars
|
||||
#' @param ... parameters passed on to functions
|
||||
#' @inheritParams first_isolate
|
||||
#' @inheritParams graphics::plot
|
||||
#' @details Valid options for the statistical model are:
|
||||
#' \itemize{
|
||||
#' \item{\code{"binomial"} or \code{"binom"} or \code{"logit"}: a generalised linear regression model with binomial distribution}
|
||||
#' \item{\code{"loglin"} or \code{"poisson"}: a generalised log-linear regression model with poisson distribution}
|
||||
#' \item{\code{"lin"} or \code{"linear"}: a linear regression model}
|
||||
#' }
|
||||
#' @return \code{data.frame} with extra class \code{"resistance_predict"} with columns:
|
||||
#' \itemize{
|
||||
#' \item{\code{year}}
|
||||
#' \item{\code{value}, the same as \code{estimated} when \code{preserve_measurements = FALSE}, and a combination of \code{observed} and \code{estimated} otherwise}
|
||||
#' \item{\code{se_min}, the lower bound of the standard error with a minimum of \code{0} (so the standard error will never go below 0\%)}
|
||||
#' \item{\code{se_max} the upper bound of the standard error with a maximum of \code{1} (so the standard error will never go above 100\%)}
|
||||
#' \item{\code{observations}, the total number of available observations in that year, i.e. S + I + R}
|
||||
#' \item{\code{observed}, the original observed resistant percentages}
|
||||
#' \item{\code{estimated}, the estimated resistant percentages, calculated by the model}
|
||||
#' }
|
||||
#' Furthermore, the model itself is available as an attribute: \code{attributes(x)$model}, see Examples.
|
||||
#' @seealso The \code{\link{portion}} function to calculate resistance, \cr \code{\link{lm}} \code{\link{glm}}
|
||||
#' @rdname resistance_predict
|
||||
#' @export
|
||||
#' @importFrom stats predict glm lm
|
||||
#' @importFrom dplyr %>% pull mutate mutate_at n group_by_at summarise filter filter_at all_vars n_distinct arrange case_when n_groups transmute
|
||||
#' @inheritSection AMR Read more on our website!
|
||||
#' @examples
|
||||
#' x <- resistance_predict(septic_patients, col_ab = "AMX", year_min = 2010)
|
||||
#' plot(x)
|
||||
#' ggplot_rsi_predict(x)
|
||||
#'
|
||||
#' # use dplyr so you can actually read it:
|
||||
#' library(dplyr)
|
||||
#' x <- septic_patients %>%
|
||||
#' filter_first_isolate() %>%
|
||||
#' filter(mo_genus(mo) == "Staphylococcus") %>%
|
||||
#' resistance_predict("PEN")
|
||||
#' plot(x)
|
||||
#'
|
||||
#'
|
||||
#' # get the model from the object
|
||||
#' mymodel <- attributes(x)$model
|
||||
#' summary(mymodel)
|
||||
#'
|
||||
#'
|
||||
#' # create nice plots with ggplot2 yourself
|
||||
#' if (!require(ggplot2)) {
|
||||
#'
|
||||
#' data <- septic_patients %>%
|
||||
#' filter(mo == as.mo("E. coli")) %>%
|
||||
#' resistance_predict(col_ab = "AMX",
|
||||
#' col_date = "date",
|
||||
#' info = FALSE,
|
||||
#' minimum = 15)
|
||||
#'
|
||||
#' ggplot(data,
|
||||
#' aes(x = year)) +
|
||||
#' geom_col(aes(y = value),
|
||||
#' fill = "grey75") +
|
||||
#' geom_errorbar(aes(ymin = se_min,
|
||||
#' ymax = se_max),
|
||||
#' colour = "grey50") +
|
||||
#' scale_y_continuous(limits = c(0, 1),
|
||||
#' breaks = seq(0, 1, 0.1),
|
||||
#' labels = paste0(seq(0, 100, 10), "%")) +
|
||||
#' labs(title = expression(paste("Forecast of amoxicillin resistance in ",
|
||||
#' italic("E. coli"))),
|
||||
#' y = "%IR",
|
||||
#' x = "Year") +
|
||||
#' theme_minimal(base_size = 13)
|
||||
#' }
|
||||
resistance_predict <- function(x,
|
||||
col_ab,
|
||||
col_date = NULL,
|
||||
year_min = NULL,
|
||||
year_max = NULL,
|
||||
year_every = 1,
|
||||
minimum = 30,
|
||||
model = 'binomial',
|
||||
I_as_S = TRUE,
|
||||
preserve_measurements = TRUE,
|
||||
info = TRUE,
|
||||
...) {
|
||||
|
||||
if (nrow(x) == 0) {
|
||||
stop('This table does not contain any observations.')
|
||||
}
|
||||
|
||||
if (!col_ab %in% colnames(x)) {
|
||||
stop('Column ', col_ab, ' not found.')
|
||||
}
|
||||
|
||||
dots <- unlist(list(...))
|
||||
if (length(dots) != 0) {
|
||||
# backwards compatibility with old parameters
|
||||
dots.names <- dots %>% names()
|
||||
if ('tbl' %in% dots.names) {
|
||||
x <- dots[which(dots.names == 'tbl')]
|
||||
}
|
||||
if ('I_as_R' %in% dots.names) {
|
||||
warning("`I_as_R is deprecated - use I_as_S instead.", call. = FALSE)
|
||||
}
|
||||
}
|
||||
|
||||
# -- date
|
||||
if (is.null(col_date)) {
|
||||
col_date <- search_type_in_df(x = x, type = "date")
|
||||
}
|
||||
if (is.null(col_date)) {
|
||||
stop("`col_date` must be set.", call. = FALSE)
|
||||
}
|
||||
|
||||
if (!col_date %in% colnames(x)) {
|
||||
stop('Column ', col_date, ' not found.')
|
||||
}
|
||||
|
||||
if (n_groups(x) > 1) {
|
||||
# no grouped tibbles please, mutate will throw errors
|
||||
x <- base::as.data.frame(x, stringsAsFactors = FALSE)
|
||||
}
|
||||
|
||||
year <- function(x) {
|
||||
if (all(grepl('^[0-9]{4}$', x))) {
|
||||
x
|
||||
} else {
|
||||
as.integer(format(as.Date(x), '%Y'))
|
||||
}
|
||||
}
|
||||
|
||||
df <- x %>%
|
||||
mutate_at(col_ab, as.rsi) %>%
|
||||
mutate_at(col_ab, droplevels) %>%
|
||||
mutate_at(col_ab, funs(
|
||||
if (I_as_S == TRUE) {
|
||||
gsub("I", "S", .)
|
||||
} else {
|
||||
# then I as R
|
||||
gsub("I", "R", .)
|
||||
}
|
||||
)) %>%
|
||||
filter_at(col_ab, all_vars(!is.na(.))) %>%
|
||||
mutate(year = pull(., col_date) %>% year()) %>%
|
||||
group_by_at(c('year', col_ab)) %>%
|
||||
summarise(n())
|
||||
|
||||
if (df %>% pull(col_ab) %>% n_distinct(na.rm = TRUE) < 2) {
|
||||
stop("No variety in antimicrobial interpretations - all isolates are '",
|
||||
df %>% pull(col_ab) %>% unique(), "'.",
|
||||
call. = FALSE)
|
||||
}
|
||||
|
||||
colnames(df) <- c('year', 'antibiotic', 'observations')
|
||||
df <- df %>%
|
||||
filter(!is.na(antibiotic)) %>%
|
||||
tidyr::spread(antibiotic, observations, fill = 0) %>%
|
||||
filter((R + S) >= minimum)
|
||||
df_matrix <- df %>%
|
||||
ungroup() %>%
|
||||
select(R, S) %>%
|
||||
as.matrix()
|
||||
|
||||
if (NROW(df) == 0) {
|
||||
stop('There are no observations.')
|
||||
}
|
||||
|
||||
year_lowest <- min(df$year)
|
||||
if (is.null(year_min)) {
|
||||
year_min <- year_lowest
|
||||
} else {
|
||||
year_min <- max(year_min, year_lowest, na.rm = TRUE)
|
||||
}
|
||||
if (is.null(year_max)) {
|
||||
year_max <- year(Sys.Date()) + 10
|
||||
}
|
||||
|
||||
years <- list(year = seq(from = year_min, to = year_max, by = year_every))
|
||||
|
||||
if (model %in% c('binomial', 'binom', 'logit')) {
|
||||
model <- "binomial"
|
||||
model_lm <- with(df, glm(df_matrix ~ year, family = binomial))
|
||||
if (info == TRUE) {
|
||||
cat('\nLogistic regression model (logit) with binomial distribution')
|
||||
cat('\n------------------------------------------------------------\n')
|
||||
print(summary(model_lm))
|
||||
}
|
||||
|
||||
predictmodel <- predict(model_lm, newdata = years, type = "response", se.fit = TRUE)
|
||||
prediction <- predictmodel$fit
|
||||
se <- predictmodel$se.fit
|
||||
|
||||
} else if (model %in% c('loglin', 'poisson')) {
|
||||
model <- "poisson"
|
||||
model_lm <- with(df, glm(R ~ year, family = poisson))
|
||||
if (info == TRUE) {
|
||||
cat('\nLog-linear regression model (loglin) with poisson distribution')
|
||||
cat('\n--------------------------------------------------------------\n')
|
||||
print(summary(model_lm))
|
||||
}
|
||||
|
||||
predictmodel <- predict(model_lm, newdata = years, type = "response", se.fit = TRUE)
|
||||
prediction <- predictmodel$fit
|
||||
se <- predictmodel$se.fit
|
||||
|
||||
} else if (model %in% c('lin', 'linear')) {
|
||||
model <- "linear"
|
||||
model_lm <- with(df, lm((R / (R + S)) ~ year))
|
||||
if (info == TRUE) {
|
||||
cat('\nLinear regression model')
|
||||
cat('\n-----------------------\n')
|
||||
print(summary(model_lm))
|
||||
}
|
||||
|
||||
predictmodel <- predict(model_lm, newdata = years, se.fit = TRUE)
|
||||
prediction <- predictmodel$fit
|
||||
se <- predictmodel$se.fit
|
||||
|
||||
} else {
|
||||
stop('No valid model selected.')
|
||||
}
|
||||
|
||||
# prepare the output dataframe
|
||||
df_prediction <- data.frame(year = unlist(years),
|
||||
value = prediction,
|
||||
stringsAsFactors = FALSE) %>%
|
||||
|
||||
mutate(se_min = value - se,
|
||||
se_max = value + se)
|
||||
|
||||
if (model == 'poisson') {
|
||||
df_prediction <- df_prediction %>%
|
||||
mutate(value = value %>%
|
||||
format(scientific = FALSE) %>%
|
||||
as.integer(),
|
||||
se_min = as.integer(se_min),
|
||||
se_max = as.integer(se_max))
|
||||
} else {
|
||||
df_prediction <- df_prediction %>%
|
||||
# se_max not above 1
|
||||
mutate(se_max = ifelse(se_max > 1, 1, se_max))
|
||||
}
|
||||
df_prediction <- df_prediction %>%
|
||||
# se_min not below 0
|
||||
mutate(se_min = ifelse(se_min < 0, 0, se_min))
|
||||
|
||||
df_observations <- df %>%
|
||||
ungroup() %>%
|
||||
transmute(year,
|
||||
observations = R + S,
|
||||
observed = R / (R + S))
|
||||
df_prediction <- df_prediction %>%
|
||||
left_join(df_observations, by = "year") %>%
|
||||
mutate(estimated = value)
|
||||
|
||||
if (preserve_measurements == TRUE) {
|
||||
# replace estimated data by observed data
|
||||
df_prediction <- df_prediction %>%
|
||||
mutate(value = ifelse(!is.na(observed), observed, value),
|
||||
se_min = ifelse(!is.na(observed), NA, se_min),
|
||||
se_max = ifelse(!is.na(observed), NA, se_max))
|
||||
}
|
||||
|
||||
df_prediction <- df_prediction %>%
|
||||
mutate(value = case_when(value > 1 ~ 1,
|
||||
value < 0 ~ 0,
|
||||
TRUE ~ value)) %>%
|
||||
arrange(year)
|
||||
|
||||
structure(
|
||||
.Data = df_prediction,
|
||||
class = c("resistance_predict", "data.frame"),
|
||||
I_as_S = I_as_S,
|
||||
model_title = model,
|
||||
model = model_lm,
|
||||
ab = col_ab
|
||||
)
|
||||
}
|
||||
|
||||
#' @rdname resistance_predict
|
||||
#' @export
|
||||
rsi_predict <- resistance_predict
|
||||
|
||||
#' @exportMethod plot.mic
|
||||
#' @export
|
||||
#' @importFrom dplyr filter
|
||||
#' @importFrom graphics plot axis arrows points
|
||||
#' @rdname resistance_predict
|
||||
plot.resistance_predict <- function(x, main = paste("Resistance Prediction of", x_name), ...) {
|
||||
x_name <- paste0(ab_name(attributes(x)$ab), " (", attributes(x)$ab, ")")
|
||||
|
||||
if (attributes(x)$I_as_S == TRUE) {
|
||||
ylab <- "%R"
|
||||
} else {
|
||||
ylab <- "%IR"
|
||||
}
|
||||
plot(x = x$year,
|
||||
y = x$value,
|
||||
ylim = c(0, 1),
|
||||
yaxt = "n", # no y labels
|
||||
pch = 19, # closed dots
|
||||
ylab = paste0("Percentage (", ylab, ")"),
|
||||
xlab = "Year",
|
||||
main = main,
|
||||
sub = paste0("(n = ", sum(x$observations, na.rm = TRUE),
|
||||
", model: ", attributes(x)$model_title, ")"),
|
||||
cex.sub = 0.75)
|
||||
|
||||
|
||||
axis(side = 2, at = seq(0, 1, 0.1), labels = paste0(0:10 * 10, "%"))
|
||||
|
||||
# hack for error bars: https://stackoverflow.com/a/22037078/4575331
|
||||
arrows(x0 = x$year,
|
||||
y0 = x$se_min,
|
||||
x1 = x$year,
|
||||
y1 = x$se_max,
|
||||
length = 0.05, angle = 90, code = 3, lwd = 1.5)
|
||||
|
||||
# overlay grey points for prediction
|
||||
points(x = filter(x, is.na(observations))$year,
|
||||
y = filter(x, is.na(observations))$value,
|
||||
pch = 19,
|
||||
col = "grey40")
|
||||
}
|
||||
|
||||
#' @rdname resistance_predict
|
||||
#' @importFrom dplyr filter
|
||||
#' @export
|
||||
ggplot_rsi_predict <- function(x,
|
||||
main = paste("Resistance Prediction of", x_name),
|
||||
ribbon = TRUE,
|
||||
...) {
|
||||
if (!"resistance_predict" %in% class(x)) {
|
||||
stop("`x` must be a resistance prediction model created with resistance_predict().")
|
||||
}
|
||||
|
||||
x_name <- paste0(ab_name(attributes(x)$ab), " (", attributes(x)$ab, ")")
|
||||
|
||||
if (attributes(x)$I_as_S == TRUE) {
|
||||
ylab <- "%R"
|
||||
} else {
|
||||
ylab <- "%IR"
|
||||
}
|
||||
|
||||
p <- ggplot2::ggplot(x, ggplot2::aes(x = year, y = value)) +
|
||||
ggplot2::geom_point(data = filter(x, !is.na(observations)),
|
||||
size = 2) +
|
||||
scale_y_percent(limits = c(0, 1)) +
|
||||
ggplot2::labs(title = main,
|
||||
y = paste0("Percentage (", ylab, ")"),
|
||||
x = "Year",
|
||||
caption = paste0("(n = ", sum(x$observations, na.rm = TRUE),
|
||||
", model: ", attributes(x)$model_title, ")"))
|
||||
|
||||
if (ribbon == TRUE) {
|
||||
p <- p + ggplot2::geom_ribbon(ggplot2::aes(ymin = se_min, ymax = se_max), alpha = 0.25)
|
||||
} else {
|
||||
p <- p + ggplot2::geom_errorbar(ggplot2::aes(ymin = se_min, ymax = se_max), na.rm = TRUE, width = 0.5)
|
||||
}
|
||||
p <- p +
|
||||
# overlay grey points for prediction
|
||||
ggplot2::geom_point(data = filter(x, is.na(observations)),
|
||||
size = 2,
|
||||
colour = "grey40")
|
||||
p
|
||||
}
|
||||
@@ -1,462 +0,0 @@
|
||||
# ==================================================================== #
|
||||
# TITLE #
|
||||
# Antimicrobial Resistance (AMR) Analysis #
|
||||
# #
|
||||
# SOURCE #
|
||||
# https://gitlab.com/msberends/AMR #
|
||||
# #
|
||||
# LICENCE #
|
||||
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
|
||||
# #
|
||||
# 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. #
|
||||
# #
|
||||
# This R package was created for academic research and was publicly #
|
||||
# released in the hope that it will be useful, but it comes WITHOUT #
|
||||
# ANY WARRANTY OR LIABILITY. #
|
||||
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
||||
# ==================================================================== #
|
||||
|
||||
#' Class 'rsi'
|
||||
#'
|
||||
#' Interpret MIC values according to EUCAST or CLSI, or clean up existing RSI values. This transforms the input to a new class \code{rsi}, which is an ordered factor with levels \code{S < I < R}. Invalid antimicrobial interpretations will be translated as \code{NA} with a warning.
|
||||
#' @rdname as.rsi
|
||||
#' @param x vector of values (for class \code{mic}: an MIC value in mg/L, for class \code{disk}: a disk diffusion radius in millimeters)
|
||||
#' @param mo a microorganism code, generated with \code{\link{as.mo}}
|
||||
#' @param ab an antibiotic code, generated with \code{\link{as.ab}}
|
||||
#' @inheritParams first_isolate
|
||||
#' @param guideline defaults to the latest included EUCAST guideline, run \code{unique(AMR::rsi_translation$guideline)} for all options
|
||||
#' @param threshold maximum fraction of \code{x} that is allowed to fail transformation, see Examples
|
||||
#' @param ... parameters passed on to methods
|
||||
#' @details Run \code{unique(AMR::rsi_translation$guideline)} for a list of all supported guidelines.
|
||||
#'
|
||||
#' After using \code{as.rsi}, you can use \code{\link{eucast_rules}} to (1) apply inferred susceptibility and resistance based on results of other antibiotics and (2) apply intrinsic resistance based on taxonomic properties of a microorganism.
|
||||
#'
|
||||
#' The function \code{is.rsi.eligible} returns \code{TRUE} when a columns contains at most 5\% invalid antimicrobial interpretations (not S and/or I and/or R), and \code{FALSE} otherwise. The threshold of 5\% can be set with the \code{threshold} parameter.
|
||||
#' @section Interpretation of S, I and R:
|
||||
#' In 2019, EUCAST has decided to change the definitions of susceptibility testing categories S, I and R as shown below. Results of several consultations on the new definitions are available on the EUCAST website under "Consultations".
|
||||
#'
|
||||
#' \itemize{
|
||||
#' \item{\strong{S} - }{Susceptible, standard dosing regimen: A microorganism is categorised as "Susceptible, standard dosing regimen", when there is a high likelihood of therapeutic success using a standard dosing regimen of the agent.}
|
||||
#' \item{\strong{I} - }{Susceptible, increased exposure: A microorganism is categorised as "Susceptible, Increased exposure" when there is a high likelihood of therapeutic success because exposure to the agent is increased by adjusting the dosing regimen or by its concentration at the site of infection.}
|
||||
#' \item{\strong{R} - }{Resistant: A microorganism is categorised as "Resistant" when there is a high likelihood of therapeutic failure even when there is increased exposure.}
|
||||
#' }
|
||||
#'
|
||||
#' Exposure is a function of how the mode of administration, dose, dosing interval, infusion time, as well as distribution and excretion of the antimicrobial agent will influence the infecting organism at the site of infection.
|
||||
#'
|
||||
#' Source: \url{http://www.eucast.org/newsiandr/}.
|
||||
#'
|
||||
#' \strong{This AMR package honours this new insight.}
|
||||
#' @return Ordered factor with new class \code{rsi}
|
||||
#' @keywords rsi
|
||||
#' @export
|
||||
#' @importFrom dplyr %>%
|
||||
#' @seealso \code{\link{as.mic}}
|
||||
#' @inheritSection AMR Read more on our website!
|
||||
#' @examples
|
||||
#' rsi_data <- as.rsi(c(rep("S", 474), rep("I", 36), rep("R", 370)))
|
||||
#' rsi_data <- as.rsi(c(rep("S", 474), rep("I", 36), rep("R", 370), "A", "B", "C"))
|
||||
#' is.rsi(rsi_data)
|
||||
#'
|
||||
#' # this can also coerce combined MIC/RSI values:
|
||||
#' as.rsi("<= 0.002; S") # will return S
|
||||
#'
|
||||
#' # interpret MIC values
|
||||
#' as.rsi(x = as.mic(2),
|
||||
#' mo = as.mo("S. pneumoniae"),
|
||||
#' ab = "AMX",
|
||||
#' guideline = "EUCAST")
|
||||
#' as.rsi(x = as.mic(4),
|
||||
#' mo = as.mo("S. pneumoniae"),
|
||||
#' ab = "AMX",
|
||||
#' guideline = "EUCAST")
|
||||
#'
|
||||
#' plot(rsi_data) # for percentages
|
||||
#' barplot(rsi_data) # for frequencies
|
||||
#' freq(rsi_data) # frequency table with informative header
|
||||
#'
|
||||
#' # using dplyr's mutate
|
||||
#' library(dplyr)
|
||||
#' septic_patients %>%
|
||||
#' mutate_at(vars(PEN:RIF), as.rsi)
|
||||
#'
|
||||
#'
|
||||
#' # fastest way to transform all columns with already valid AB results to class `rsi`:
|
||||
#' septic_patients %>%
|
||||
#' mutate_if(is.rsi.eligible,
|
||||
#' as.rsi)
|
||||
#'
|
||||
#' # default threshold of `is.rsi.eligible` is 5%.
|
||||
#' is.rsi.eligible(WHONET$`First name`) # fails, >80% is invalid
|
||||
#' is.rsi.eligible(WHONET$`First name`, threshold = 0.99) # succeeds
|
||||
as.rsi <- function(x, ...) {
|
||||
UseMethod("as.rsi")
|
||||
}
|
||||
|
||||
#' @export
|
||||
as.rsi.default <- function(x, ...) {
|
||||
if (is.rsi(x)) {
|
||||
x
|
||||
} else if (identical(levels(x), c("S", "I", "R"))) {
|
||||
structure(x, class = c('rsi', 'ordered', 'factor'))
|
||||
} else {
|
||||
# if (input_resembles_mic(x) > 0.5) {
|
||||
# warning("`as.rsi` is intended to clean antimicrobial interpretations - not to interpret MIC values.", call. = FALSE)
|
||||
# }
|
||||
|
||||
x <- x %>% unlist()
|
||||
x.bak <- x
|
||||
|
||||
na_before <- x[is.na(x) | x == ''] %>% length()
|
||||
# remove all spaces
|
||||
x <- gsub(' +', '', x)
|
||||
# remove all MIC-like values: numbers, operators and periods
|
||||
x <- gsub('[0-9.,;:<=>]+', '', x)
|
||||
# remove everything between brackets, and 'high' and 'low'
|
||||
x <- gsub("([(].*[)])", "", x)
|
||||
x <- gsub("(high|low)", "", x, ignore.case = TRUE)
|
||||
# disallow more than 3 characters
|
||||
x[nchar(x) > 3] <- NA
|
||||
# set to capitals
|
||||
x <- toupper(x)
|
||||
# remove all invalid characters
|
||||
x <- gsub('[^RSI]+', '', x)
|
||||
# in cases of "S;S" keep S, but in case of "S;I" make it NA
|
||||
x <- gsub('^S+$', 'S', x)
|
||||
x <- gsub('^I+$', 'I', x)
|
||||
x <- gsub('^R+$', 'R', x)
|
||||
x[!x %in% c('S', 'I', 'R')] <- NA
|
||||
na_after <- x[is.na(x) | x == ''] %>% length()
|
||||
|
||||
if (na_before != na_after) {
|
||||
list_missing <- x.bak[is.na(x) & !is.na(x.bak) & x.bak != ''] %>%
|
||||
unique() %>%
|
||||
sort()
|
||||
list_missing <- paste0('"', list_missing , '"', collapse = ", ")
|
||||
warning(na_after - na_before, ' results truncated (',
|
||||
round(((na_after - na_before) / length(x)) * 100),
|
||||
'%) that were invalid antimicrobial interpretations: ',
|
||||
list_missing, call. = FALSE)
|
||||
}
|
||||
|
||||
structure(.Data = factor(x, levels = c("S", "I", "R"), ordered = TRUE),
|
||||
class = c('rsi', 'ordered', 'factor'))
|
||||
}
|
||||
}
|
||||
|
||||
input_resembles_mic <- function(x) {
|
||||
mic <- x %>%
|
||||
gsub("[^0-9.,]+", "", .) %>%
|
||||
unique()
|
||||
mic_valid <- suppressWarnings(as.mic(mic))
|
||||
result <- sum(!is.na(mic_valid)) / length(mic)
|
||||
if (is.na(result)) {
|
||||
0
|
||||
} else {
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
#' @rdname as.rsi
|
||||
#' @importFrom dplyr case_when
|
||||
#' @export
|
||||
as.rsi.mic <- function(x, mo, ab, guideline = "EUCAST", ...) {
|
||||
exec_as.rsi(method = "mic",
|
||||
x = x,
|
||||
mo = mo,
|
||||
ab = ab,
|
||||
guideline = guideline)
|
||||
}
|
||||
|
||||
#' @rdname as.rsi
|
||||
#' @export
|
||||
as.rsi.disk <- function(x, mo, ab, guideline = "EUCAST", ...) {
|
||||
exec_as.rsi(method = "disk",
|
||||
x = x,
|
||||
mo = mo,
|
||||
ab = ab,
|
||||
guideline = guideline)
|
||||
}
|
||||
|
||||
exec_as.rsi <- function(method, x, mo, ab, guideline) {
|
||||
if (method == "mic") {
|
||||
x <- as.mic(x) # when as.rsi.mic is called directly
|
||||
} else if (method == "disk") {
|
||||
x <- as.disk(x) # when as.rsi.disk is called directly
|
||||
}
|
||||
|
||||
mo <- as.mo(mo)
|
||||
ab <- as.ab(ab)
|
||||
|
||||
mo_genus <- as.mo(mo_genus(mo))
|
||||
mo_family <- as.mo(mo_family(mo))
|
||||
mo_order <- as.mo(mo_order(mo))
|
||||
mo_becker <- as.mo(mo, Becker = TRUE)
|
||||
mo_lancefield <- as.mo(mo, Lancefield = TRUE)
|
||||
|
||||
guideline_param <- toupper(guideline)
|
||||
if (guideline_param %in% c("CLSI", "EUCAST")) {
|
||||
guideline_param <- AMR::rsi_translation %>%
|
||||
filter(guideline %like% guideline_param) %>%
|
||||
pull(guideline) %>%
|
||||
sort() %>%
|
||||
rev() %>%
|
||||
.[1]
|
||||
}
|
||||
|
||||
if (!guideline_param %in% AMR::rsi_translation$guideline) {
|
||||
stop(paste0("invalid guideline: '", guideline,
|
||||
"'.\nValid guidelines are: ", paste0("'", rev(sort(unique(AMR::rsi_translation$guideline))), "'", collapse = ", ")),
|
||||
call. = FALSE)
|
||||
}
|
||||
|
||||
new_rsi <- rep(NA_character_, length(x))
|
||||
trans <- AMR::rsi_translation %>%
|
||||
filter(guideline == guideline_param) %>%
|
||||
mutate(lookup = paste(mo, ab))
|
||||
|
||||
lookup_mo <- paste(mo, ab)
|
||||
lookup_genus <- paste(mo_genus, ab)
|
||||
lookup_family <- paste(mo_family, ab)
|
||||
lookup_order <- paste(mo_order, ab)
|
||||
lookup_becker <- paste(mo_becker, ab)
|
||||
lookup_lancefield <- paste(mo_lancefield, ab)
|
||||
|
||||
for (i in 1:length(x)) {
|
||||
get_record <- trans %>%
|
||||
filter(lookup %in% c(lookup_mo[i],
|
||||
lookup_genus[i],
|
||||
lookup_family[i],
|
||||
lookup_order[i],
|
||||
lookup_becker[i],
|
||||
lookup_lancefield[i])) %>%
|
||||
# be as specific as possible (i.e. prefer species over genus):
|
||||
arrange(desc(nchar(mo))) %>%
|
||||
.[1L,]
|
||||
|
||||
if (NROW(get_record) > 0) {
|
||||
if (method == "mic") {
|
||||
new_rsi[i] <- case_when(isTRUE(x[i] <= get_record$S_mic) ~ "S",
|
||||
isTRUE(x[i] >= get_record$R_mic) ~ "R",
|
||||
!is.na(get_record$S_mic) & !is.na(get_record$R_mic) ~ "I",
|
||||
TRUE ~ NA_character_)
|
||||
} else if (method == "disk") {
|
||||
new_rsi[i] <- case_when(isTRUE(x[i] >= get_record$S_disk) ~ "S",
|
||||
isTRUE(x[i] <= get_record$R_disk) ~ "R",
|
||||
!is.na(get_record$S_disk) & !is.na(get_record$R_disk) ~ "I",
|
||||
TRUE ~ NA_character_)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
structure(.Data = factor(new_rsi, levels = c("S", "I", "R"), ordered = TRUE),
|
||||
class = c('rsi', 'ordered', 'factor'))
|
||||
}
|
||||
|
||||
#' @rdname as.rsi
|
||||
#' @importFrom crayon red blue
|
||||
#' @export
|
||||
as.rsi.data.frame <- function(x, col_mo = NULL, guideline = "EUCAST", ...) {
|
||||
x <- x
|
||||
|
||||
ab_cols <- colnames(x)[sapply(x, function(y) is.mic(y) | is.disk(y))]
|
||||
if (length(ab_cols) == 0) {
|
||||
stop("No columns with MIC values or disk zones found in this data set. Use as.mic or as.disk to transform antibiotic columns.", call. = FALSE)
|
||||
}
|
||||
|
||||
# try to find columns based on type
|
||||
# -- mo
|
||||
if (is.null(col_mo)) {
|
||||
col_mo <- search_type_in_df(x = x, type = "mo")
|
||||
}
|
||||
if (is.null(col_mo)) {
|
||||
stop("`col_mo` must be set.", call. = FALSE)
|
||||
}
|
||||
|
||||
# transform all MICs
|
||||
ab_cols <- colnames(x)[sapply(x, is.mic)]
|
||||
if (length(ab_cols) > 0) {
|
||||
for (i in 1:length(ab_cols)) {
|
||||
if (is.na(suppressWarnings(as.ab(ab_cols[i])))) {
|
||||
message(red(paste0("Unknown drug: `", bold(ab_cols[i]), "`. Rename this column to a drug name or code, and check the output with as.ab().")))
|
||||
next
|
||||
}
|
||||
message(blue(paste0("Interpreting column `", bold(ab_cols[i]), "` (", ab_name(ab_cols[i], tolower = TRUE), ")...")), appendLF = FALSE)
|
||||
x[, ab_cols[i]] <- exec_as.rsi(method = "mic",
|
||||
x = x %>% pull(ab_cols[i]),
|
||||
mo = x %>% pull(col_mo),
|
||||
ab = as.ab(ab_cols[i]),
|
||||
guideline = guideline)
|
||||
message(blue(" OK."))
|
||||
}
|
||||
}
|
||||
# transform all disks
|
||||
ab_cols <- colnames(x)[sapply(x, is.disk)]
|
||||
if (length(ab_cols) > 0) {
|
||||
for (i in 1:length(ab_cols)) {
|
||||
if (is.na(suppressWarnings(as.ab(ab_cols[i])))) {
|
||||
message(red(paste0("Unknown drug: `", bold(ab_cols[i]), "`. Rename this column to a drug name or code, and check the output with as.ab().")))
|
||||
next
|
||||
}
|
||||
message(blue(paste0("Interpreting column `", bold(ab_cols[i]), "` (", ab_name(ab_cols[i], tolower = TRUE), ")...")), appendLF = FALSE)
|
||||
x[, ab_cols[i]] <- exec_as.rsi(method = "disk",
|
||||
x = x %>% pull(ab_cols[i]),
|
||||
mo = x %>% pull(col_mo),
|
||||
ab = as.ab(ab_cols[i]),
|
||||
guideline = guideline)
|
||||
message(blue(" OK."))
|
||||
}
|
||||
}
|
||||
|
||||
x
|
||||
}
|
||||
|
||||
#' @rdname as.rsi
|
||||
#' @export
|
||||
is.rsi <- function(x) {
|
||||
identical(class(x),
|
||||
c('rsi', 'ordered', 'factor'))
|
||||
}
|
||||
|
||||
#' @rdname as.rsi
|
||||
#' @export
|
||||
is.rsi.eligible <- function(x, threshold = 0.05) {
|
||||
if (NCOL(x) > 1) {
|
||||
stop('`x` must be a one-dimensional vector.')
|
||||
}
|
||||
if (any(c("logical",
|
||||
"numeric",
|
||||
"integer",
|
||||
"mo",
|
||||
"Date",
|
||||
"POSIXct",
|
||||
"rsi",
|
||||
"raw",
|
||||
"hms")
|
||||
%in% class(x))) {
|
||||
# no transformation needed
|
||||
FALSE
|
||||
} else {
|
||||
x <- x[!is.na(x) & !is.null(x) & !identical(x, "")]
|
||||
if (length(x) == 0) {
|
||||
return(FALSE)
|
||||
}
|
||||
checked <- suppressWarnings(as.rsi(x))
|
||||
outcome <- sum(is.na(checked)) / length(x)
|
||||
outcome <= threshold
|
||||
}
|
||||
}
|
||||
|
||||
#' @exportMethod print.rsi
|
||||
#' @export
|
||||
#' @importFrom dplyr %>%
|
||||
#' @noRd
|
||||
print.rsi <- function(x, ...) {
|
||||
cat("Class 'rsi'\n")
|
||||
print(as.character(x), quote = FALSE)
|
||||
}
|
||||
|
||||
#' @exportMethod droplevels.rsi
|
||||
#' @export
|
||||
#' @noRd
|
||||
droplevels.rsi <- function(x, exclude = if(anyNA(levels(x))) NULL else NA, ...) {
|
||||
x <- droplevels.factor(x, exclude = exclude, ...)
|
||||
class(x) <- c('rsi', 'ordered', 'factor')
|
||||
x
|
||||
}
|
||||
|
||||
#' @exportMethod summary.rsi
|
||||
#' @export
|
||||
#' @noRd
|
||||
summary.rsi <- function(object, ...) {
|
||||
x <- object
|
||||
c(
|
||||
"Class" = 'rsi',
|
||||
"<NA>" = sum(is.na(x)),
|
||||
"Sum S" = sum(x == "S", na.rm = TRUE),
|
||||
"Sum IR" = sum(x %in% c("I", "R"), na.rm = TRUE),
|
||||
"-Sum R" = sum(x == "R", na.rm = TRUE),
|
||||
"-Sum I" = sum(x == "I", na.rm = TRUE)
|
||||
)
|
||||
}
|
||||
|
||||
#' @exportMethod plot.rsi
|
||||
#' @export
|
||||
#' @importFrom dplyr %>% group_by summarise filter mutate if_else n_distinct
|
||||
#' @importFrom graphics plot text
|
||||
#' @noRd
|
||||
plot.rsi <- function(x, ...) {
|
||||
x_name <- deparse(substitute(x))
|
||||
|
||||
suppressWarnings(
|
||||
data <- data.frame(x = x,
|
||||
y = 1,
|
||||
stringsAsFactors = TRUE) %>%
|
||||
group_by(x) %>%
|
||||
summarise(n = sum(y)) %>%
|
||||
filter(!is.na(x)) %>%
|
||||
mutate(s = round((n / sum(n)) * 100, 1))
|
||||
)
|
||||
if (!"S" %in% data$x) {
|
||||
data <- rbind(data, data.frame(x = "S", n = 0, s = 0))
|
||||
}
|
||||
if (!"I" %in% data$x) {
|
||||
data <- rbind(data, data.frame(x = "I", n = 0, s = 0))
|
||||
}
|
||||
if (!"R" %in% data$x) {
|
||||
data <- rbind(data, data.frame(x = "R", n = 0, s = 0))
|
||||
}
|
||||
|
||||
data$x <- factor(data$x, levels = c('S', 'I', 'R'), ordered = TRUE)
|
||||
|
||||
ymax <- if_else(max(data$s) > 95, 105, 100)
|
||||
|
||||
plot(x = data$x,
|
||||
y = data$s,
|
||||
lwd = 2,
|
||||
col = c('green', 'orange', 'red'),
|
||||
ylim = c(0, ymax),
|
||||
ylab = 'Percentage',
|
||||
xlab = 'Antimicrobial Interpretation',
|
||||
main = paste('Susceptibility Analysis of', x_name),
|
||||
axes = FALSE,
|
||||
...)
|
||||
# x axis
|
||||
axis(side = 1, at = 1:n_distinct(data$x), labels = levels(data$x), lwd = 0)
|
||||
# y axis, 0-100%
|
||||
axis(side = 2, at = seq(0, 100, 5))
|
||||
|
||||
text(x = data$x,
|
||||
y = data$s + 4,
|
||||
labels = paste0(data$s, '% (n = ', data$n, ')'))
|
||||
}
|
||||
|
||||
|
||||
#' @exportMethod barplot.rsi
|
||||
#' @export
|
||||
#' @importFrom dplyr %>% group_by summarise
|
||||
#' @importFrom graphics barplot axis
|
||||
#' @noRd
|
||||
barplot.rsi <- function(height, ...) {
|
||||
x <- height
|
||||
x_name <- deparse(substitute(height))
|
||||
|
||||
suppressWarnings(
|
||||
data <- data.frame(rsi = x, cnt = 1) %>%
|
||||
group_by(rsi) %>%
|
||||
summarise(cnt = sum(cnt)) %>%
|
||||
droplevels()
|
||||
)
|
||||
|
||||
barplot(table(x),
|
||||
col = c('green3', 'orange2', 'red3'),
|
||||
xlab = 'Antimicrobial Interpretation',
|
||||
main = paste('Susceptibility Analysis of', x_name),
|
||||
ylab = 'Frequency',
|
||||
axes = FALSE,
|
||||
...)
|
||||
# y axis, 0-100%
|
||||
axis(side = 2, at = seq(0, max(data$cnt) + max(data$cnt) * 1.1, by = 25))
|
||||
}
|
||||
@@ -1,237 +0,0 @@
|
||||
# ==================================================================== #
|
||||
# TITLE #
|
||||
# Antimicrobial Resistance (AMR) Analysis #
|
||||
# #
|
||||
# SOURCE #
|
||||
# https://gitlab.com/msberends/AMR #
|
||||
# #
|
||||
# LICENCE #
|
||||
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
|
||||
# #
|
||||
# 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. #
|
||||
# #
|
||||
# This R package was created for academic research and was publicly #
|
||||
# released in the hope that it will be useful, but it comes WITHOUT #
|
||||
# ANY WARRANTY OR LIABILITY. #
|
||||
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
||||
# ==================================================================== #
|
||||
|
||||
#' @importFrom dplyr %>% pull all_vars any_vars filter_all funs mutate_all
|
||||
rsi_calc <- function(...,
|
||||
type,
|
||||
include_I,
|
||||
minimum,
|
||||
as_percent,
|
||||
also_single_tested,
|
||||
only_count) {
|
||||
|
||||
if (!is.logical(include_I)) {
|
||||
stop('`include_I` must be logical', call. = FALSE)
|
||||
}
|
||||
if (!is.numeric(minimum)) {
|
||||
stop('`minimum` must be numeric', call. = FALSE)
|
||||
}
|
||||
if (!is.logical(as_percent)) {
|
||||
stop('`as_percent` must be logical', call. = FALSE)
|
||||
}
|
||||
if (!is.logical(also_single_tested)) {
|
||||
stop('`also_single_tested` must be logical', call. = FALSE)
|
||||
}
|
||||
|
||||
dots_df <- ...elt(1) # it needs this evaluation
|
||||
dots <- base::eval(base::substitute(base::alist(...)))
|
||||
ndots <- length(dots)
|
||||
|
||||
if ("data.frame" %in% class(dots_df)) {
|
||||
# data.frame passed with other columns, like:
|
||||
# septic_patients %>% portion_S(amcl, gent)
|
||||
dots <- as.character(dots)
|
||||
dots <- dots[dots != "."]
|
||||
if (length(dots) == 0 | all(dots == "df")) {
|
||||
# for complete data.frames, like septic_patients %>% select(amcl, gent) %>% portion_S()
|
||||
# and the old rsi function, that has "df" as name of the first parameter
|
||||
x <- dots_df
|
||||
} else {
|
||||
x <- dots_df[, dots]
|
||||
}
|
||||
} else if (ndots == 1) {
|
||||
# only 1 variable passed (can also be data.frame), like:
|
||||
# portion_S(septic_patients$amcl)
|
||||
# septic_patients$amcl %>% portion_S()
|
||||
x <- dots_df
|
||||
} else {
|
||||
# multiple variables passed without pipe, like:
|
||||
# portion_S(septic_patients$amcl, septic_patients$gent)
|
||||
x <- NULL
|
||||
try(x <- as.data.frame(dots), silent = TRUE)
|
||||
if (is.null(x)) {
|
||||
# support for: with(septic_patients, portion_S(amcl, gent))
|
||||
x <- as.data.frame(rlang::list2(...))
|
||||
}
|
||||
}
|
||||
|
||||
if (is.null(x)) {
|
||||
warning("argument is NULL (check if columns exist): returning NA", call. = FALSE)
|
||||
return(NA)
|
||||
}
|
||||
|
||||
print_warning <- FALSE
|
||||
|
||||
type_trans <- as.integer(as.rsi(type))
|
||||
type_others <- base::setdiff(1:3, type_trans)
|
||||
|
||||
if (is.data.frame(x)) {
|
||||
rsi_integrity_check <- character(0)
|
||||
for (i in 1:ncol(x)) {
|
||||
# check integrity of columns: force rsi class
|
||||
if (!is.rsi(x %>% pull(i))) {
|
||||
rsi_integrity_check <- c(rsi_integrity_check, x %>% pull(i) %>% as.character())
|
||||
x[, i] <- suppressWarnings(as.rsi(x[, i])) # warning will be given later
|
||||
print_warning <- TRUE
|
||||
}
|
||||
x[, i] <- x %>% pull(i) %>% as.integer()
|
||||
}
|
||||
if (length(rsi_integrity_check) > 0) {
|
||||
# this will give a warning for invalid results, of all input columns (so only 1 warning)
|
||||
rsi_integrity_check <- as.rsi(rsi_integrity_check)
|
||||
}
|
||||
|
||||
if (include_I == TRUE) {
|
||||
x <- x %>% mutate_all(funs(ifelse(. == 2, type_trans, .)))
|
||||
}
|
||||
|
||||
if (also_single_tested == TRUE) {
|
||||
# THE CHANCE THAT AT LEAST ONE RESULT IS type
|
||||
found <- x %>% filter_all(any_vars(. == type_trans)) %>% nrow()
|
||||
# THE CHANCE THAT AT LEAST ONE RESULT IS type OR ALL ARE TESTED
|
||||
total <- found + x %>% filter_all(all_vars(. %in% type_others)) %>% nrow()
|
||||
} else {
|
||||
x <- apply(X = x,
|
||||
MARGIN = 1,
|
||||
FUN = min)
|
||||
found <- sum(as.integer(x) == type_trans, na.rm = TRUE)
|
||||
total <- length(x) - sum(is.na(x))
|
||||
}
|
||||
} else {
|
||||
if (!is.rsi(x)) {
|
||||
x <- as.rsi(x)
|
||||
print_warning <- TRUE
|
||||
}
|
||||
x <- as.integer(x)
|
||||
if (include_I == TRUE) {
|
||||
x[x == 2] <- type_trans
|
||||
}
|
||||
found <- sum(x == type_trans, na.rm = TRUE)
|
||||
total <- length(x) - sum(is.na(x))
|
||||
}
|
||||
|
||||
if (print_warning == TRUE) {
|
||||
warning("Increase speed by transforming to class `rsi` on beforehand: df %>% mutate_if(is.rsi.eligible, as.rsi)",
|
||||
call. = FALSE)
|
||||
}
|
||||
|
||||
if (only_count == TRUE) {
|
||||
return(found)
|
||||
}
|
||||
|
||||
if (total < minimum) {
|
||||
warning("Introducing NA: only ", total, " results available (minimum set to ", minimum, ").", call. = FALSE)
|
||||
result <- NA
|
||||
} else {
|
||||
result <- found / total
|
||||
}
|
||||
|
||||
if (as_percent == TRUE) {
|
||||
percent(result, force_zero = TRUE)
|
||||
} else {
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
rsi_calc_df <- function(type, # "portion" or "count"
|
||||
data,
|
||||
translate_ab = "name",
|
||||
language = get_locale(),
|
||||
minimum = 30,
|
||||
as_percent = FALSE,
|
||||
combine_SI = TRUE,
|
||||
combine_IR = FALSE,
|
||||
combine_SI_missing = FALSE) {
|
||||
|
||||
if (!"data.frame" %in% class(data)) {
|
||||
stop(paste0("`", type, "_df` must be called on a data.frame"), call. = FALSE)
|
||||
}
|
||||
|
||||
if (isTRUE(combine_IR) & isTRUE(combine_SI_missing)) {
|
||||
combine_SI <- FALSE
|
||||
}
|
||||
if (isTRUE(combine_SI) & isTRUE(combine_IR)) {
|
||||
stop("either `combine_SI` or `combine_IR` can be TRUE", call. = FALSE)
|
||||
}
|
||||
|
||||
if (data %>% select_if(is.rsi) %>% ncol() == 0) {
|
||||
stop("No columns with class 'rsi' found. See ?as.rsi.", call. = FALSE)
|
||||
}
|
||||
|
||||
if (as.character(translate_ab) %in% c("TRUE", "official")) {
|
||||
translate_ab <- "name"
|
||||
}
|
||||
|
||||
get_summaryfunction <- function(int) {
|
||||
# look for portion_S, count_S, etc:
|
||||
int_fn <- get(paste0(type, "_", int), envir = asNamespace("AMR"))
|
||||
|
||||
if (type == "portion") {
|
||||
summ <- summarise_if(.tbl = data,
|
||||
.predicate = is.rsi,
|
||||
.funs = int_fn,
|
||||
minimum = minimum,
|
||||
as_percent = as_percent)
|
||||
} else if (type == "count") {
|
||||
summ <- summarise_if(.tbl = data,
|
||||
.predicate = is.rsi,
|
||||
.funs = int_fn)
|
||||
}
|
||||
summ %>%
|
||||
mutate(Interpretation = int) %>%
|
||||
select(Interpretation, everything())
|
||||
}
|
||||
|
||||
resS <- get_summaryfunction("S")
|
||||
resI <- get_summaryfunction("I")
|
||||
resR <- get_summaryfunction("R")
|
||||
resSI <- get_summaryfunction("SI")
|
||||
resIR <- get_summaryfunction("IR")
|
||||
data.groups <- group_vars(data)
|
||||
|
||||
if (isFALSE(combine_SI) & isFALSE(combine_IR)) {
|
||||
res <- bind_rows(resS, resI, resR) %>%
|
||||
mutate(Interpretation = factor(Interpretation,
|
||||
levels = c("S", "I", "R"),
|
||||
ordered = TRUE))
|
||||
|
||||
} else if (isTRUE(combine_IR)) {
|
||||
res <- bind_rows(resS, resIR) %>%
|
||||
mutate(Interpretation = factor(Interpretation,
|
||||
levels = c("S", "IR"),
|
||||
ordered = TRUE))
|
||||
|
||||
} else if (isTRUE(combine_SI)) {
|
||||
res <- bind_rows(resSI, resR) %>%
|
||||
mutate(Interpretation = factor(Interpretation,
|
||||
levels = c("SI", "R"),
|
||||
ordered = TRUE))
|
||||
}
|
||||
|
||||
res <- res %>%
|
||||
tidyr::gather(Antibiotic, Value, -Interpretation, -data.groups)
|
||||
|
||||
if (!translate_ab == FALSE) {
|
||||
res <- res %>% mutate(Antibiotic = ab_property(Antibiotic, property = translate_ab, language = language))
|
||||
}
|
||||
|
||||
res
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
# ==================================================================== #
|
||||
# TITLE #
|
||||
# Antimicrobial Resistance (AMR) Analysis #
|
||||
# #
|
||||
# SOURCE #
|
||||
# https://gitlab.com/msberends/AMR #
|
||||
# #
|
||||
# LICENCE #
|
||||
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
|
||||
# #
|
||||
# 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. #
|
||||
# #
|
||||
# This R package was created for academic research and was publicly #
|
||||
# released in the hope that it will be useful, but it comes WITHOUT #
|
||||
# ANY WARRANTY OR LIABILITY. #
|
||||
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
||||
# ==================================================================== #
|
||||
|
||||
#' Skewness of the sample
|
||||
#'
|
||||
#' @description Skewness is a measure of the asymmetry of the probability distribution of a real-valued random variable about its mean.
|
||||
#'
|
||||
#' When negative: the left tail is longer; the mass of the distribution is concentrated on the right of the figure. When positive: the right tail is longer; the mass of the distribution is concentrated on the left of the figure.
|
||||
#' @param x a vector of values, a \code{matrix} or a \code{data frame}
|
||||
#' @param na.rm a logical value indicating whether \code{NA} values should be stripped before the computation proceeds.
|
||||
#' @exportMethod skewness
|
||||
#' @seealso \code{\link{kurtosis}}
|
||||
#' @rdname skewness
|
||||
#' @inheritSection AMR Read more on our website!
|
||||
#' @export
|
||||
skewness <- function(x, na.rm = FALSE) {
|
||||
UseMethod("skewness")
|
||||
}
|
||||
|
||||
#' @exportMethod skewness.default
|
||||
#' @rdname skewness
|
||||
#' @export
|
||||
skewness.default <- function (x, na.rm = FALSE) {
|
||||
x <- as.vector(x)
|
||||
if (na.rm == TRUE) {
|
||||
x <- x[!is.na(x)]
|
||||
}
|
||||
n <- length(x)
|
||||
(base::sum((x - base::mean(x))^3) / n) / (base::sum((x - base::mean(x))^2) / n)^(3/2)
|
||||
}
|
||||
|
||||
#' @exportMethod skewness.matrix
|
||||
#' @rdname skewness
|
||||
#' @export
|
||||
skewness.matrix <- function (x, na.rm = FALSE) {
|
||||
base::apply(x, 2, skewness.default, na.rm = na.rm)
|
||||
}
|
||||
|
||||
#' @exportMethod skewness.data.frame
|
||||
#' @rdname skewness
|
||||
#' @export
|
||||
skewness.data.frame <- function (x, na.rm = FALSE) {
|
||||
base::sapply(x, skewness.default, na.rm = na.rm)
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
# ==================================================================== #
|
||||
# TITLE #
|
||||
# Antimicrobial Resistance (AMR) Analysis #
|
||||
# #
|
||||
# SOURCE #
|
||||
# https://gitlab.com/msberends/AMR #
|
||||
# #
|
||||
# LICENCE #
|
||||
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
|
||||
# #
|
||||
# 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. #
|
||||
# #
|
||||
# This R package was created for academic research and was publicly #
|
||||
# released in the hope that it will be useful, but it comes WITHOUT #
|
||||
# ANY WARRANTY OR LIABILITY. #
|
||||
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
||||
# ==================================================================== #
|
||||
|
||||
#' WHOCC: WHO Collaborating Centre for Drug Statistics Methodology
|
||||
#'
|
||||
#' All antimicrobial drugs and their official names, ATC codes, ATC groups and defined daily dose (DDD) are included in this package, using the WHO Collaborating Centre for Drug Statistics Methodology.
|
||||
#' @section WHOCC:
|
||||
#' \if{html}{\figure{logo_who.png}{options: height=60px style=margin-bottom:5px} \cr}
|
||||
#' This package contains \strong{all ~450 antimicrobial drugs} and their Anatomical Therapeutic Chemical (ATC) codes, ATC groups and Defined Daily Dose (DDD) from the World Health Organization Collaborating Centre for Drug Statistics Methodology (WHOCC, \url{https://www.whocc.no}) and the Pharmaceuticals Community Register of the European Commission (\url{http://ec.europa.eu/health/documents/community-register/html/atc.htm}).
|
||||
#'
|
||||
#' These have become the gold standard for international drug utilisation monitoring and research.
|
||||
#'
|
||||
#' The WHOCC is located in Oslo at the Norwegian Institute of Public Health and funded by the Norwegian government. The European Commission is the executive of the European Union and promotes its general interest.
|
||||
#' @inheritSection AMR Read more on our website!
|
||||
#' @name WHOCC
|
||||
#' @rdname WHOCC
|
||||
#' @examples
|
||||
#' as.ab("meropenem")
|
||||
#' ab_name("J01DH02")
|
||||
#'
|
||||
#' ab_tradenames("flucloxacillin")
|
||||
NULL
|
||||
@@ -1,261 +0,0 @@
|
||||
# ==================================================================== #
|
||||
# TITLE #
|
||||
# Antimicrobial Resistance (AMR) Analysis #
|
||||
# #
|
||||
# SOURCE #
|
||||
# https://gitlab.com/msberends/AMR #
|
||||
# #
|
||||
# LICENCE #
|
||||
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
|
||||
# #
|
||||
# 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. #
|
||||
# #
|
||||
# This R package was created for academic research and was publicly #
|
||||
# released in the hope that it will be useful, but it comes WITHOUT #
|
||||
# ANY WARRANTY OR LIABILITY. #
|
||||
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
||||
# ==================================================================== #
|
||||
|
||||
#' @importFrom data.table as.data.table setkey
|
||||
.onLoad <- function(libname, pkgname) {
|
||||
# get new functions not available in older versions of R
|
||||
backports::import(pkgname)
|
||||
|
||||
# register data
|
||||
microorganisms.oldDT <- as.data.table(AMR::microorganisms.old)
|
||||
microorganisms.oldDT$fullname_lower <- tolower(microorganisms.oldDT$fullname)
|
||||
setkey(microorganisms.oldDT, col_id, fullname)
|
||||
|
||||
assign(x = "microorganismsDT",
|
||||
value = make_DT(),
|
||||
envir = asNamespace("AMR"))
|
||||
|
||||
assign(x = "microorganisms.oldDT",
|
||||
value = microorganisms.oldDT,
|
||||
envir = asNamespace("AMR"))
|
||||
|
||||
assign(x = "mo_codes_v0.5.0",
|
||||
value = make_trans_tbl(),
|
||||
envir = asNamespace("AMR"))
|
||||
|
||||
# assign(x = "mo_history",
|
||||
# value = data.frame(x = character(0),
|
||||
# mo = character(0),
|
||||
# uncertainty_level = integer(0),
|
||||
# package_v = character(0),
|
||||
# stringsAsFactors = FALSE),
|
||||
# envir = asNamespace("AMR"))
|
||||
|
||||
}
|
||||
|
||||
#' @importFrom data.table as.data.table setkey
|
||||
make_DT <- function() {
|
||||
microorganismsDT <- as.data.table(AMR::microorganisms)
|
||||
microorganismsDT$fullname_lower <- tolower(microorganismsDT$fullname)
|
||||
setkey(microorganismsDT,
|
||||
prevalence,
|
||||
kingdom,
|
||||
fullname)
|
||||
microorganismsDT
|
||||
}
|
||||
|
||||
make_trans_tbl <- function() {
|
||||
# conversion of old MO codes from v0.5.0 (ITIS) to later versions (Catalogue of Life)
|
||||
c(B_ACHRMB = "B_ACHRM", B_ANNMA = "B_ACTNS", B_ACLLS = "B_ALCYC",
|
||||
B_AHNGM = "B_ARCHN", B_ARMTM = "B_ARMTMN", B_ARTHR = "B_ARTHRB", B_ARTHRS = "B_ARTHR",
|
||||
B_APHLS = "B_AZRHZP", B_BRCHA = "B_BRCHY", B_BCTRM = "B_BRVBCT",
|
||||
B_CLRBCT = "B_CLRBC", B_CTRDM = "B_CLSTR", B_CPRMM = "B_CYLND",
|
||||
B_DLCLN = "B_DPLCL", B_DMCLM = "B_DSLFT", B_DSLFVB = "B_DSLFV",
|
||||
B_FCTRM = "B_FSBCT", B_GNRLA = "B_GRDNR", B_HNRBM = "B_HLNRB",
|
||||
B_HPHGA = "B_HNPHGA", B_HCCCS = "B_HYDRC", B_MCRCLS = "B_MCRCL",
|
||||
B_MTHYLS = "B_MLSMA", B_MARCLS = "B_MRCLS", B_MGCLS = "B_MSTGC",
|
||||
B_MCLLA = "B_MTHYLC", B_MYCPLS = "B_MYCPL", B_NBCTR = "B_NTRBC",
|
||||
B_OCLLS = "B_OCNBC", B_PTHRX = "B_PLNKT", B_PCCCS = "B_PRCHL",
|
||||
B_PSPHN = "B_PRPHY", B_PDMNS = "B_PSDMN", B_SCCHRP = "B_SCCHR",
|
||||
B_SRBCTR = "B_SHRBCTR", B_STRPTC = "B_STRPT", B_SHMNS = "B_SYNTR",
|
||||
B_TRBCTR = "B_THRMN", P_ALBMN = "C_ABMNA", F_ACHLY = "C_ACHLY",
|
||||
P_ACINT = "C_ACINT", P_ARTCL = "C_ACLNA", P_ACRVL = "C_ACRVL",
|
||||
P_ADRCT = "C_ADRCT", P_AMPHS = "C_AHSRS", F_ALBUG = "C_ALBUG",
|
||||
P_ALCNT = "C_ALCNT", P_ALFRD = "C_ALFRD", P_ALLGR = "C_ALLGR",
|
||||
P_AMPHL = "C_ALPTS", F_ALTHR = "C_ALTHR", P_AMLLA = "C_AMLLA",
|
||||
P_ANMLN = "C_AMLNA", P_AMMBC = "C_AMMBC", P_AMMDS = "C_AMMDS",
|
||||
P_AMMLG = "C_AMMLG", P_AMMMR = "C_AMMMR", P_AMMMS = "C_AMMMS",
|
||||
P_AMMON = "C_AMMON", P_AMMSC = "C_AMMSC", P_AMMSP = "C_AMMSP",
|
||||
P_AMMST = "C_AMMST", P_AMMTM = "C_AMMTM", F_AMYCS = "C_AMYCS",
|
||||
P_ANARM = "C_ANARM", P_ANGLD = "C_ANGLD", P_ANGLG = "C_ANGLG",
|
||||
P_ANNLC = "C_ANNLC", F_ANSLP = "C_ANSLP", F_APDCH = "C_APDCH",
|
||||
F_APHND = "C_APHND", F_APLNC = "C_APLNC", F_AQLND = "C_AQLND",
|
||||
P_ARCHS = "C_ARCHAS", P_ASTRN = "C_ARNNN", P_ARNPR = "C_ARNPR",
|
||||
F_ARSPR = "C_ARSPR", P_ARTST = "C_ARTSTR", P_AMPHC = "C_ARYNA",
|
||||
P_ASCHM = "C_ASCHM", P_ASPDS = "C_ASPDS", P_ASTCL = "C_ASTCL",
|
||||
P_ASTRG = "C_ASTRGR", P_ASTRM = "C_ASTRMM", P_ASTRR = "C_ASTRR",
|
||||
P_ASTRT = "C_ASTRTR", F_ATKNS = "C_ATKNS", F_AYLLA = "C_AYLLA",
|
||||
P_BAGGN = "C_BAGGN", P_BCCLL = "C_BCCLL", P_BDLLD = "C_BDLLD",
|
||||
P_BGNRN = "C_BGNRN", P_BLCLN = "C_BLCLN", P_BLMND = "C_BLMND",
|
||||
P_BLMNL = "C_BLMNL", P_BLPHR = "C_BLPHR", P_BLVNT = "C_BLVNT",
|
||||
P_BOLVN = "C_BOLVN", P_BORLS = "C_BORLS", P_BRNNM = "C_BRNNM",
|
||||
P_BRSLN = "C_BRSLN", P_BRSRD = "C_BRSRD", F_BRVLG = "C_BRVLG",
|
||||
F_BNLLA = "C_BRVLGN", P_BSCCM = "C_BSCCM", F_BSDPH = "C_BSDPH",
|
||||
P_BTHYS = "C_BTHYS", P_BTLLN = "C_BTLLN", P_BULMN = "C_BULMN",
|
||||
P_CCLDM = "C_CCLDM", P_CDNLL = "C_CDNLL", P_CLPSS = "C_CDNLLP",
|
||||
P_CHLDN = "C_CHLDNL", P_CHLST = "C_CHLST", P_CHNLM = "C_CHNLM",
|
||||
P_CHRYS = "C_CHRYSL", P_CHTSP = "C_CHTSP", P_CBCDS = "C_CIBCDS",
|
||||
P_CLCRN = "C_CLCRN", P_CLMNA = "C_CLMNA", P_CLPDM = "C_CLPDM",
|
||||
P_CLPHR = "C_CLPHRY", P_CLVLN = "C_CLVLN", P_CMPNL = "C_CMPNL",
|
||||
P_CNCRS = "C_CNCRS", P_CNTCH = "C_CNTCH", F_CNTRM = "C_CNTRMY",
|
||||
P_COLPD = "C_COLPD", P_COLPS = "C_COLPS", P_CPRDS = "C_CPRDS",
|
||||
P_CRNSP = "C_CPRMA", P_CRBNL = "C_CRBNL", P_CRBRB = "C_CRBRB",
|
||||
P_CRBRG = "C_CRBRG", P_CRBRS = "C_CRBRS", P_CRCHS = "C_CRCHS",
|
||||
P_CRCLC = "C_CRCLC", P_CRNLC = "C_CRNLC", P_CRNTH = "C_CRNTH",
|
||||
P_CRPNT = "C_CRPNT", P_CRSTG = "C_CRSTG", P_CRTHN = "C_CRTHN",
|
||||
P_CRTRN = "C_CRTRN", P_CYMBL = "C_CRTTA", P_CRYPT = "C_CRYPT",
|
||||
P_CSHMN = "C_CSHMNL", P_CSSDL = "C_CSSDL", P_CLNDS = "C_CSSDLN",
|
||||
P_CHRNA = "C_CTHRN", P_CTPSS = "C_CTPSS", P_CUNLN = "C_CUNLN",
|
||||
P_CYLND = "C_CVLNA", P_CYCLC = "C_CYCLCB", P_CDNTA = "C_CYCLD",
|
||||
P_CYCLG = "C_CYCLG", P_CYCLM = "C_CYCLM", P_CYRTL = "C_CYRTL",
|
||||
P_CYSTM = "C_CYSTM", P_DCHLM = "C_DCHLM", P_DCRBS = "C_DCRBS",
|
||||
P_DCTYC = "C_DCTYC", P_DIDNM = "C_DIDNM", P_DLPTS = "C_DLPTS",
|
||||
P_DNTLN = "C_DNTLN", P_DNTST = "C_DNTST", P_DORTH = "C_DORTH",
|
||||
P_DCTYP = "C_DPHMS", F_DPLCY = "C_DPLCY", P_DNDRT = "C_DRTNA",
|
||||
P_DSCMM = "C_DSCMM", P_DSCRB = "C_DSCRB", P_DSCRN = "C_DSCRN",
|
||||
P_DSCSP = "C_DSCSP", P_DSNBR = "C_DSNBR", P_DYCBC = "C_DYCBC",
|
||||
F_DCTYC = "C_DYCHS", F_ECTRG = "C_ECTRG", B_EDWRD = "C_EDWRD",
|
||||
P_EGGRL = "C_EGGRL", P_EHLYS = "C_EHLYS", P_EHRNB = "C_EHRNB",
|
||||
P_ELPHD = "C_ELPHD", P_ENCHL = "C_ELYDM", P_EPHDM = "C_EPHDM",
|
||||
P_EPLTS = "C_EPLTS", P_EPLXL = "C_EPLXL", P_EPNDL = "C_EPNDL",
|
||||
P_EPNDS = "C_EPNDS", P_ENLLA = "C_EPSTM", P_EPSTY = "C_EPSTY",
|
||||
F_ERYCH = "C_ERYCH", F_ESMDM = "C_ESMDM", P_ESSYR = "C_ESSYR",
|
||||
P_FSCHR = "C_FHRNA", P_FLRLS = "C_FLRLS", P_FLNTN = "C_FNTNA",
|
||||
P_FRNDC = "C_FRNDC", P_FRNTN = "C_FRNTN", P_FRSNK = "C_FRSNK",
|
||||
P_FNLLA = "C_FSCHRN", P_FSSRN = "C_FSSRN", P_FVCSS = "C_FVCSS",
|
||||
P_GDRYN = "C_GDRYN", F_GELGN = "C_GELGN", P_GERDA = "C_GERDA",
|
||||
P_GLACM = "C_GLACM", P_GLBBL = "C_GLBBL", P_GLBGR = "C_GLBGR",
|
||||
P_GLBLN = "C_GLBLN", P_GRTLA = "C_GLBRT", P_GLBTX = "C_GLBTX",
|
||||
P_GLLNA = "C_GLLNA", P_GLMSP = "C_GLMSP", P_GLNDL = "C_GLNDL",
|
||||
F_GNMCH = "C_GNMCH", P_GOSLL = "C_GOSLL", P_GRNDS = "C_GRNDS",
|
||||
P_GRNTA = "C_GRNTA", P_GLBRT = "C_GTLLA", P_GTTLN = "C_GTTLN",
|
||||
P_GVLNP = "C_GVLNP", P_GYPSN = "C_GYPSN", P_GYRDN = "C_GYRDN",
|
||||
P_HALTR = "C_HALTR", P_HANZW = "C_HANZW", P_HAURN = "C_HAURN",
|
||||
P_HELNN = "C_HELNN", P_HLPHR = "C_HHRYA", P_HLNTA = "C_HLNTA",
|
||||
F_HLPHT = "C_HLPHT", P_HLSTC = "C_HLSTC", P_HMSPH = "C_HMSPH",
|
||||
P_HMTRM = "C_HMTRM", P_HPKNS = "C_HPKNS", P_HPLPH = "C_HPLPH",
|
||||
P_HPPCR = "C_HPPCR", P_HNLLA = "C_HPPCRP", P_HRMSN = "C_HRMSN",
|
||||
P_HRNLL = "C_HRNLL", F_HRPCH = "C_HRPCH", P_HSTGR = "C_HSTGR",
|
||||
P_HSTTL = "C_HSTTL", P_HTRST = "C_HTGNA", P_HTRLL = "C_HTRLL",
|
||||
P_HTRPH = "C_HTRPH", F_HYPHC = "C_HYPHC", P_HYPRM = "C_HYPRM",
|
||||
P_INTRN = "C_INTRN", P_IRIDI = "C_IRIDI", P_ISLND = "C_ISLND",
|
||||
P_JCLLL = "C_JCLLL", P_KHLLL = "C_KHLLL", P_KRNPS = "C_KRNPS",
|
||||
P_KRRRL = "C_KRRRL", P_LABOE = "C_LABOE", P_LAGEN = "C_LAGEN",
|
||||
P_LBSLL = "C_LBSLL", F_LTHLA = "C_LBYRN", P_LCRYM = "C_LCRYM",
|
||||
P_LEMBS = "C_LEMBS", F_LGNDM = "C_LGNDM", P_LGNMM = "C_LGNMM",
|
||||
P_LGNPH = "C_LGNPHR", F_LGNSM = "C_LGNSM", P_LGYNP = "C_LGYNP",
|
||||
P_LITTB = "C_LITTB", P_LITUL = "C_LITUL", P_LMBDN = "C_LMBDN",
|
||||
P_LMRCK = "C_LMRCK", F_LBYRN = "C_LMYXA", P_LNGLN = "C_LNGLN",
|
||||
P_LNTCL = "C_LNTCL", P_LOXDS = "C_LOXDS", F_LPTLG = "C_LPTLG",
|
||||
F_LNLLA = "C_LPTLGN", F_LPTMT = "C_LPTMT", P_LRYNG = "C_LRYNG",
|
||||
P_LTCRN = "C_LTCRN", P_LTHPL = "C_LTHPL", P_LTNTS = "C_LTNTS",
|
||||
F_LTRST = "C_LTRST", P_LXPHY = "C_LXPHY", P_MCRTH = "C_MCRTH",
|
||||
P_MELNS = "C_MELNS", P_MSDNM = "C_MESDNM", P_METPS = "C_METPS",
|
||||
P_MIMSN = "C_MIMSN", P_MINCN = "C_MINCN", P_MLLNL = "C_MLLNL",
|
||||
P_MLMMN = "C_MLMMN", F_MNDNL = "C_MNDNL", P_MNLYS = "C_MNLYS",
|
||||
P_MNPSS = "C_MNPSS", P_MRGNL = "C_MRGNL", P_MRGNP = "C_MRGNP",
|
||||
P_MRSPL = "C_MRSPL", P_MRTNT = "C_MRTNT", P_MSSLN = "C_MSSLN",
|
||||
P_MSSSS = "C_MSSSS", P_MTCNT = "C_MTCNT", P_MYCHS = "C_MYCHS",
|
||||
P_MYSCH = "C_MYSCH", F_MYZCY = "C_MYZCY", P_NASSL = "C_NASSL",
|
||||
P_NBCLN = "C_NBCLN", P_NBCLR = "C_NBCLR", P_NCNRB = "C_NCNRB",
|
||||
P_NDBCL = "C_NDBCL", P_NRLLA = "C_NDBCLR", P_NMMLC = "C_NMMLC",
|
||||
F_NMTPH = "C_NMTPH", P_NNNLL = "C_NNNLL", P_NODSR = "C_NODSR",
|
||||
P_NONIN = "C_NONIN", P_NOURI = "C_NOURI", P_OCLNA = "C_OCLNA",
|
||||
P_OGLNA = "C_OGLNA", P_OPHTH = "C_OLMDM", F_OLPDP = "C_OLPDP",
|
||||
P_ONYCH = "C_OMPSS", P_OOLIN = "C_OOLIN", P_OPRCL = "C_OPRCL",
|
||||
P_ORBLN = "C_ORBLN", F_ORCAD = "C_ORCAD", P_ORDRS = "C_ORDRS",
|
||||
P_OPHRY = "C_ORYDM", P_OSNGL = "C_OSNGL", P_OXYTR = "C_OXYTR",
|
||||
P_PARRN = "C_PARRN", P_PATRS = "C_PATRS", P_PAVNN = "C_PAVNN",
|
||||
P_PTYCH = "C_PCYLS", P_PDPHR = "C_PDPHR", P_PELSN = "C_PELSN",
|
||||
F_PHGMY = "C_PHGMY", F_PSDSP = "C_PHRTA", P_PHRYG = "C_PHRYG",
|
||||
P_PHYSL = "C_PHYSL", F_PHYTP = "C_PHYTP", P_PLACS = "C_PLACS",
|
||||
P_PLCPS = "C_PLCPS", P_PLCPSL = "C_PLCPSL", P_PLCTN = "C_PLCTN",
|
||||
P_PLGPH = "C_PLGPH", B_PLGTH = "C_PLGTH", P_PLMRN = "C_PLMRN",
|
||||
P_PLNCT = "C_PLNCT", P_PLNDSC = "C_PLNDSC", P_PLNGY = "C_PLNGY",
|
||||
P_PLNRBL = "C_PLNLLA", P_PLNLN = "C_PLNLN", P_PLNLR = "C_PLNLR",
|
||||
P_PLNRB = "C_PLNRB", P_PLNSP = "C_PLNSPR", P_PLRNM = "C_PLRNM",
|
||||
P_PLRST = "C_PLRST", P_PLRTR = "C_PLRTR", F_PLSMD = "C_PLSMD",
|
||||
P_PLTYC = "C_PLTYC", P_PSDBL = "C_PLVNA", P_PLYMR = "C_PLYMR",
|
||||
P_PLTYN = "C_PNMTM", P_PNRPL = "C_PNRPL", F_PNTSM = "C_PNTSM",
|
||||
P_PRCNT = "C_PRCNT", P_PRFSS = "C_PRFSS", P_PRMCM = "C_PRMCUM",
|
||||
F_PRNSP = "C_PRNSP", P_PRPND = "C_PRPND", P_PRPYX = "C_PRPYX",
|
||||
P_PRRDN = "C_PRRDN", P_PSDDF = "C_PSDDF", P_PSDMC = "C_PSDMC",
|
||||
P_PSDND = "C_PSDND", P_PSDNN = "C_PSDNN", P_PSDPL = "C_PSDPLY",
|
||||
P_PSMMS = "C_PSMMS", P_PTLLN = "C_PTLLN", P_PTLLND = "C_PTLLND",
|
||||
F_PTRSN = "C_PTRSN", P_PULLN = "C_PULLN", P_PUTLN = "C_PUTLN",
|
||||
P_PRTTR = "C_PYMNA", P_PYRGL = "C_PYRGL", P_PYRGO = "C_PYRGO",
|
||||
P_PYRLN = "C_PYRLN", F_PYTHM = "C_PYTHIM", F_PYTHL = "C_PYTHL",
|
||||
P_PYXCL = "C_PYXCL", P_QNQLC = "C_QNQLC", P_RAMLN = "C_RAMLN",
|
||||
P_RBRTN = "C_RBRTN", P_RCRVD = "C_RCRVD", P_RCTBL = "C_RCTBL",
|
||||
P_RCTCB = "C_RCTCB", P_RCTGL = "C_RCTGL", P_RCTVG = "C_RCTVG",
|
||||
P_RDGDR = "C_RDGDR", P_REMNC = "C_REMNC", P_REPHX = "C_REPHX",
|
||||
P_RHBDM = "C_RHBDMM", F_RHBDS = "C_RHBDSP", P_RHPDD = "C_RHPDD",
|
||||
F_RHPDM = "C_RHPDM", F_RHZDMY = "C_RHZDM", P_RHZMM = "C_RHZMM",
|
||||
P_RIVRN = "C_RIVRN", P_ROSLN = "C_ROSLN", P_ROTAL = "C_ROTAL",
|
||||
P_RPHDP = "C_RPHDP", P_RPRTN = "C_RPRTN", P_RSSLL = "C_RSSLL",
|
||||
P_RTLMM = "C_RTLMM", P_RTYLA = "C_RTYLA", P_RUGID = "C_RUGID",
|
||||
F_RZLLP = "C_RZLLP", P_SAGRN = "C_SAGRN", P_SCCMM = "C_SCCMM",
|
||||
P_SCCRH = "C_SCCRH", P_SCHLM = "C_SCHLM", F_SCLRS = "C_SCLRS",
|
||||
P_SCTLR = "C_SCTLR", P_SEBRK = "C_SEBRK", P_SGMLN = "C_SGMLN",
|
||||
P_SGMLP = "C_SGMLP", P_SGMMR = "C_SGMMR", P_SGMVR = "C_SGMVR",
|
||||
F_SMMRS = "C_SMMRS", P_SNNDS = "C_SNNDS", P_SORTS = "C_SORTS",
|
||||
P_SPHGN = "C_SPHGN", P_SPHNN = "C_SPHNN", P_SNLLA = "C_SPHNNL",
|
||||
P_SPHTR = "C_SPHTR", P_SPHTX = "C_SPHTX", P_SPHVG = "C_SPHVG",
|
||||
P_SPRDT = "C_SPRDT", P_SPRLC = "C_SPRLC", F_SPRLG = "C_SPRLG",
|
||||
P_SPRLL = "C_SPRLL", F_SPRMY = "C_SPRMY", P_SPRPL = "C_SPRPL",
|
||||
P_SPRSG = "C_SPRSG", P_SPRST = "C_SPRST", P_SPHNP = "C_SPRTA",
|
||||
P_SPRZN = "C_SPRZN", P_SPHRG = "C_SPSNA", P_STHDM = "C_SPTHD",
|
||||
P_SRCNR = "C_SRCNR", F_SRLPD = "C_SRLPD", F_SPNGS = "C_SSPRA",
|
||||
F_STEIN = "C_STEIN", P_SPTHD = "C_STHDDS", P_STHRP = "C_STHRP",
|
||||
P_STNFR = "C_STNFR", P_STNSM = "C_STNSM", P_STNTR = "C_STNTR",
|
||||
P_STRBL = "C_STRBL", P_STRMB = "C_STRMB", P_STTSN = "C_STTSN",
|
||||
P_STYLN = "C_SYCHA", F_SCHZC = "C_SYTRM", P_TBNLL = "C_TBNLL",
|
||||
P_TRCHL = "C_TCHLS", P_TCHNT = "C_TCHNT", P_THRCL = "C_THRCL",
|
||||
P_THRMM = "C_THRMM", P_TIARN = "C_TIARN", P_TKPHR = "C_TKPHR",
|
||||
P_TLNMA = "C_TLNMA", P_TLYPM = "C_TLYPM", P_TMNDS = "C_TMNDS",
|
||||
P_TMNTA = "C_TMNTA", P_TNTNN = "C_TNNDM", P_TTNNS = "C_TNTNN",
|
||||
P_TNPSS = "C_TNTNNP", P_TONTN = "C_TONTN", P_TOSAI = "C_TOSAI",
|
||||
P_TPHTR = "C_TPHTR", P_TRCHH = "C_TRCHH", P_TRPHS = "C_TRCHLR",
|
||||
P_TMMNA = "C_TRCHM", P_TRCHS = "C_TRCHSP", P_TRFRN = "C_TRFRN",
|
||||
P_TRLCL = "C_TRLCL", P_TRTXL = "C_TRTXL", P_TRTXS = "C_TRTXS",
|
||||
P_TTRHY = "C_TTRHY", F_TTRMY = "C_TTRMY", P_TXTLR = "C_TXTLR",
|
||||
F_THRST = "C_TYTRM", P_URLPT = "C_ULPTS", P_UNGLT = "C_UNGLT",
|
||||
P_URCNT = "C_URCNT", P_URONM = "C_URONM", P_UROSM = "C_UROSM",
|
||||
P_URTRC = "C_URTRC", P_URSTY = "C_UTYLA", P_UVGRN = "C_UVGRN",
|
||||
P_VLVLN = "C_VALVLN", P_VGNLN = "C_VGNLN", P_VGNLNP = "C_VGNLNP",
|
||||
P_VLNRA = "C_VLVLN", P_VGNCL = "C_VNCLA", P_VRGLN = "C_VRGLN",
|
||||
P_VRGLNP = "C_VRGLNP", P_VRTCL = "C_VRTCL", P_WBBNL = "C_WBBNL",
|
||||
P_WEBBN = "C_WEBBN", P_WSNRL = "C_WSNRL", P_ZTHMN = "C_ZHMNM",
|
||||
B_ZOOGL = "C_ZOOGL", F_DDSCS = "F_DPDSC", F_SCCHR = "F_SMYCS",
|
||||
P_AMTRN = "P_ACNTH", F_AMBDM = "P_AMBDM", F_ARCYR = "P_ARCYR",
|
||||
F_BADHM = "P_BADHM", F_BDHMP = "P_BDHMP", F_BRBYL = "P_BRBYL",
|
||||
F_BRFLD = "P_BRFLD", F_CLMYX = "P_CLMYX", F_CLSTD = "P_CLSTD",
|
||||
F_CMTRC = "P_CMTRC", F_CRBRR = "P_CRBRR", F_CRTMY = "P_CRTMY",
|
||||
F_CRTRM = "P_CRTRM", F_DCTYD = "P_DCTYD", F_DDYMM = "P_DDYMM",
|
||||
F_DIACH = "P_DIACH", F_DIANM = "P_DIANM", F_DIDRM = "P_DIDRM",
|
||||
F_ELMYX = "P_ELMYX", F_ESTLM = "P_ESTLM", F_FULIG = "P_FULIG",
|
||||
F_HMTRC = "P_HMTRC", F_LCRPS = "P_LCRPS", F_LICEA = "P_LICEA",
|
||||
F_LMPRD = "P_LMPRD", F_LPTDR = "P_LPTDR", F_LSTRL = "P_LSTRL",
|
||||
F_LYCGL = "P_LYCGL", F_MCBRD = "P_MCBRD", F_MNKTL = "P_MNKTL",
|
||||
F_MTTRC = "P_MTTRC", F_MUCLG = "P_MUCLG", F_PHYSR = "P_PHYSR",
|
||||
F_PRCHN = "P_PRCHN", F_PRMBD = "P_PRMBD", F_PRTPH = "P_PRTPH",
|
||||
F_PSRNA = "P_PSRNA", F_PYSRM = "P_PYSRM", F_RTCLR = "P_RTCLR",
|
||||
F_STMNT = "P_STMNT", F_SYMPH = "P_SYMPH", F_TRBRK = "P_TRBRK",
|
||||
F_TRICH = "P_TRICH", F_TUBFR = "P_TUBFR",
|
||||
B_GRDNR = "B_GRLLA", B_SGMNS = "B_SNGMNS", B_TCLLS = "B_THBCL",
|
||||
F_CCCCS = "F_CRYPT",
|
||||
# renamings of old genus + species
|
||||
F_CANDD_GLB = "F_CANDD_GLA", F_CANDD_KRU = "F_ISSTC_ORI",
|
||||
F_CANDD_GUI = "F_MYRZY_GUI",
|
||||
F_CANDD_LUS = "F_CLVSP_LUS", B_STRPT_TUS = "B_STRPT",
|
||||
B_PRVTL_OLA = "B_PRVTL_OULO", B_FSBCT_RUM = "B_FSBCT",
|
||||
B_CRYNB_EYI = "B_CRYNB_FRE", B_OLGLL_LIS = "B_OLGLL_URE")
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
% AMR (for R)
|
||||
|
||||
# `AMR` (for R)
|
||||
<img src="man/figures/logo.png" align="right" height="120px" />
|
||||
|
||||
### Not a developer? Then please visit our website [https://msberends.gitlab.io/AMR](https://msberends.gitlab.io/AMR) to read about this package.
|
||||
**It contains documentation about all of the included functions and also a comprehensive tutorial about how to conduct AMR analysis.**
|
||||
|
||||
## Development source
|
||||
|
||||
*NOTE: the original source code is on GitLab (https://gitlab.com/msberends/AMR), so you can report a bug at https://gitlab.com/msberends/AMR/issues. There is a mirror repository on GitHub (https://github.com/msberends/AMR). As the mirror process is automated by GitLab, both repositories always contain the latest changes.*
|
||||
|
||||
This is the **development source** of `AMR`, a free and open-source [R package](https://www.r-project.org) to simplify the analysis and prediction of Antimicrobial Resistance (AMR) and to work with microbial and antimicrobial properties by using evidence-based methods.
|
||||
|
||||
## Authors
|
||||
Matthijs S. Berends <a href="https://orcid.org/0000-0001-7620-1800"><img src="https://cran.rstudio.com/web/orcid.svg" height="16px"></a> <sup>1,2,a</sup>,
|
||||
Christian F. Luz <a href="https://orcid.org/0000-0001-5809-5995"><img src="https://cran.rstudio.com/web/orcid.svg" height="16px"></a> <sup>1,a</sup>,
|
||||
Erwin E.A. Hassing<sup>2</sup>,
|
||||
Corinna Glasner <a href="https://orcid.org/0000-0003-1241-1328"><img src="https://cran.rstudio.com/web/orcid.svg" height="16px"></a> <sup>1,b</sup>,
|
||||
Alex W. Friedrich <a href="https://orcid.org/0000-0003-4881-038X"><img src="https://cran.rstudio.com/web/orcid.svg" height="16px"></a> <sup>1,b</sup>,
|
||||
Bhanu N.M. Sinha <a href="https://orcid.org/0000-0003-1634-0010"><img src="https://cran.rstudio.com/web/orcid.svg" height="16px"></a> <sup>1,b</sup>
|
||||
|
||||
<sup>1</sup> Department of Medical Microbiology, University of Groningen, University Medical Center Groningen, Groningen, the Netherlands - [rug.nl](http://www.rug.nl) [umcg.nl](http://www.umcg.nl)<br>
|
||||
<sup>2</sup> Certe Medical Diagnostics & Advice, Groningen, the Netherlands - [certe.nl](http://www.certe.nl)<br>
|
||||
<sup>a</sup> Thesis dissertant<br>
|
||||
<sup>b</sup> Thesis advisor
|
||||
|
||||
<a href="https://www.rug.nl"><img src="man/figures/logo_rug.png" height="60px"></a>
|
||||
<a href="https://www.umcg.nl"><img src="man/figures/logo_umcg.png" height="60px"></a>
|
||||
<a href="https://www.certe.nl"><img src="man/figures/logo_certe.png" height="60px"></a>
|
||||
<a href="http://www.eurhealth-1health.eu"><img src="man/figures/logo_eh1h.png" height="60px"></a>
|
||||
<a href="http://www.eurhealth-1health.eu"><img src="man/figures/logo_interreg.png" height="60px"></a>
|
||||
|
||||
## How to get this package
|
||||
All stable versions of this package [are published on CRAN](https://CRAN.R-project.org/package=AMR), the official R network with a peer-reviewed submission process.
|
||||
|
||||
### Install from CRAN
|
||||
[](https://CRAN.R-project.org/package=AMR) [](https://CRAN.R-project.org/package=AMR)
|
||||
|
||||
(Note: Downloads measured only by cran.rstudio.com, this excludes e.g. the official [cran.r-project.org](https://cran.r-project.org/package=AMR))
|
||||
|
||||
- <img src="http://www.rstudio.com/favicon.ico" alt="RStudio favicon" height="20px"> Install using [RStudio](http://www.rstudio.com) (recommended):
|
||||
- Click on `Tools` and then `Install Packages...`
|
||||
- Type in `AMR` and press <kbd>Install</kbd>
|
||||
|
||||
- <img src="https://cran.r-project.org/favicon.ico" alt="R favicon" height="20px"> Install in R directly:
|
||||
- `install.packages("AMR")`
|
||||
|
||||
### Install from Zenodo
|
||||
[](https://doi.org/10.5281/zenodo.1305355)
|
||||
|
||||
This package was also published on Zenodo (stable releases only): https://doi.org/10.5281/zenodo.1305355
|
||||
|
||||
### Install from GitLab
|
||||
|
||||
This is the latest **development version**. Although it may contain bugfixes and even new functions compared to the latest released version on CRAN, it is also subject to change and may be unstable or behave unexpectedly. Always consider this a beta version. All below 'badges' should be green:
|
||||
|
||||
Development Test | Result | Reference
|
||||
--- | :---: | ---
|
||||
All functions checked on Linux | [](https://gitlab.com/msberends/AMR/commits/master) | GitLab CI [[ref 1]](https://gitlab.com/msberends/AMR)
|
||||
All functions checked on Windows | [](https://ci.appveyor.com/project/msberends/amr-svxon) | Appveyor Systems Inc. [[ref 2]](https://ci.appveyor.com/project/msberends/amr-svxon)
|
||||
Percentage of syntax lines checked | [](https://codecov.io/gl/msberends/AMR) [](https://codecov.io/gl/msberends/AMR) | Codecov LLC [[ref 3]](https://codecov.io/gl/msberends/AMR)
|
||||
|
||||
If so, try it with:
|
||||
```r
|
||||
install.packages("devtools")
|
||||
devtools::install_gitlab("msberends/AMR")
|
||||
```
|
||||
|
||||
## Copyright
|
||||
|
||||
This R package is licensed under the [GNU General Public License (GPL) v2.0](https://gitlab.com/msberends/AMR/blob/master/LICENSE). In a nutshell, this means that this package:
|
||||
|
||||
- May be used for commercial purposes
|
||||
|
||||
- May be used for private purposes
|
||||
|
||||
- May **not** be used for patent purposes
|
||||
|
||||
- May be modified, although:
|
||||
|
||||
- Modifications **must** be released under the same license when distributing the package
|
||||
- Changes made to the code **must** be documented
|
||||
|
||||
- May be distributed, although:
|
||||
|
||||
- Source code **must** be made available when the package is distributed
|
||||
- A copy of the license and copyright notice **must** be included with the package.
|
||||
|
||||
- Comes with a LIMITATION of liability
|
||||
|
||||
- Comes with NO warranty
|
||||
@@ -1,189 +0,0 @@
|
||||
# ==================================================================== #
|
||||
# TITLE #
|
||||
# Antimicrobial Resistance (AMR) Analysis #
|
||||
# #
|
||||
# SOURCE #
|
||||
# https://gitlab.com/msberends/AMR #
|
||||
# #
|
||||
# LICENCE #
|
||||
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
|
||||
# #
|
||||
# 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. #
|
||||
# #
|
||||
# This R package was created for academic research and was publicly #
|
||||
# released in the hope that it will be useful, but it comes WITHOUT #
|
||||
# ANY WARRANTY OR LIABILITY. #
|
||||
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
||||
# ==================================================================== #
|
||||
|
||||
title: 'AMR (for R)'
|
||||
url: 'https://msberends.gitlab.io/AMR'
|
||||
development:
|
||||
mode: release # improves indexing by search engines
|
||||
news:
|
||||
one_page: true
|
||||
|
||||
navbar:
|
||||
title: 'AMR (for R)'
|
||||
left:
|
||||
- text: 'Home'
|
||||
icon: 'fa-home'
|
||||
href: 'index.html'
|
||||
- text: 'How to'
|
||||
icon: 'fa-question-circle'
|
||||
menu:
|
||||
- text: 'Conduct AMR analysis'
|
||||
icon: 'fa-directions'
|
||||
href: 'articles/AMR.html'
|
||||
- text: 'Predict antimicrobial resistance'
|
||||
icon: 'fa-dice'
|
||||
href: 'articles/resistance_predict.html'
|
||||
- text: 'Determine multi-drug resistance (MDR)'
|
||||
icon: 'fa-skull-crossbones'
|
||||
href: 'articles/MDR.html'
|
||||
- text: 'Work with WHONET data'
|
||||
icon: 'fa-globe-americas'
|
||||
href: 'articles/WHONET.html'
|
||||
- text: 'Import data from SPSS/SAS/Stata'
|
||||
icon: 'fa-file-upload'
|
||||
href: 'articles/SPSS.html'
|
||||
- text: 'Apply EUCAST rules'
|
||||
icon: 'fa-exchange-alt'
|
||||
href: 'articles/EUCAST.html'
|
||||
- text: 'Get properties of a microorganism'
|
||||
icon: 'fa-bug'
|
||||
href: 'reference/mo_property.html' # reference instead of article
|
||||
- text: 'Get properties of an antibiotic'
|
||||
icon: 'fa-capsules'
|
||||
href: 'reference/ab_property.html' # reference instead of article
|
||||
- text: 'Create frequency tables'
|
||||
icon: 'fa-sort-amount-down'
|
||||
href: 'articles/freq.html'
|
||||
- text: 'Use the G-test'
|
||||
icon: 'fa-clipboard-check'
|
||||
href: 'reference/g.test.html' # reference instead of article
|
||||
- text: 'Other: benchmarks'
|
||||
icon: 'fa-shipping-fast'
|
||||
href: 'articles/benchmarks.html'
|
||||
- text: 'Manual'
|
||||
icon: 'fa-book-open'
|
||||
href: 'reference/'
|
||||
- text: 'Authors'
|
||||
icon: 'fa-users'
|
||||
href: 'authors.html'
|
||||
- text: 'Changelog'
|
||||
icon: 'far fa-newspaper'
|
||||
href: 'news/'
|
||||
right:
|
||||
- text: 'Source Code'
|
||||
icon: 'fab fa-gitlab'
|
||||
href: 'https://gitlab.com/msberends/AMR'
|
||||
- text: 'Licence'
|
||||
icon: 'fa-book'
|
||||
href: 'LICENSE-text.html'
|
||||
|
||||
reference:
|
||||
- title: 'Background information'
|
||||
desc: >
|
||||
Some pages about our package and its external sources. Be sure to read our [How To's](./../articles/index.html)
|
||||
for more information about how to work with functions in this package.
|
||||
contents:
|
||||
- '`AMR`'
|
||||
- '`catalogue_of_life`'
|
||||
- '`catalogue_of_life_version`'
|
||||
- '`WHOCC`'
|
||||
- title: 'Cleaning your data'
|
||||
desc: >
|
||||
Functions for cleaning and optimising your data, to be able to add
|
||||
variables later on (like taxonomic properties) or to fix and extend
|
||||
antibiotic interpretations by applying [EUCAST rules](http://www.eucast.org/expert_rules_and_intrinsic_resistance/).
|
||||
contents:
|
||||
- starts_with("as.")
|
||||
- '`mo_source`'
|
||||
- '`eucast_rules`'
|
||||
- '`rsi_translation`'
|
||||
- '`guess_ab_col`'
|
||||
- '`read.4D`'
|
||||
- title: 'Adding variables to your data'
|
||||
desc: >
|
||||
Functions to add new data to existing data, like the determination
|
||||
of first isolates, multi-drug resistant microorganisms (MDRO), getting
|
||||
properties of microorganisms or antibiotics and determining the age of
|
||||
patients or divide ages into age groups.
|
||||
contents:
|
||||
- '`first_isolate`'
|
||||
- '`mdro`'
|
||||
- '`key_antibiotics`'
|
||||
- '`mo_property`'
|
||||
- '`ab_property`'
|
||||
- '`age`'
|
||||
- '`age_groups`'
|
||||
- '`p.symbol`'
|
||||
- '`join`'
|
||||
- '`atc_online_property`'
|
||||
- title: 'Analysing your data'
|
||||
desc: >
|
||||
Functions for conducting AMR analysis, like counting isolates, calculating
|
||||
resistance or susceptibility, creating frequency tables or make plots.
|
||||
contents:
|
||||
- '`availability`'
|
||||
- '`count`'
|
||||
- '`portion`'
|
||||
- '`filter_ab_class`'
|
||||
- '`freq`'
|
||||
- '`g.test`'
|
||||
- '`ggplot_rsi`'
|
||||
- '`kurtosis`'
|
||||
- '`resistance_predict`'
|
||||
- '`skewness`'
|
||||
- title: 'Included data sets'
|
||||
desc: >
|
||||
References for microorganisms and antibiotics, and even a
|
||||
genuine data set with isolates from septic patients.
|
||||
contents:
|
||||
- '`antibiotics`'
|
||||
- '`microorganisms`'
|
||||
- '`septic_patients`'
|
||||
- '`WHONET`'
|
||||
- '`microorganisms.codes`'
|
||||
- '`microorganisms.old`'
|
||||
- title: Other functions
|
||||
desc: >
|
||||
These functions are mostly for internal use, but some of
|
||||
them may also be suitable for your analysis. Especially the
|
||||
'like' function can be useful: `if (x %like% y) {...}`.
|
||||
contents:
|
||||
- '`get_locale`'
|
||||
- '`like`'
|
||||
- title: Deprecated functions
|
||||
desc: >
|
||||
These functions are deprecated, meaning that they still
|
||||
work but show a warning with every use and will be removed
|
||||
in a future version.
|
||||
contents:
|
||||
- '`AMR-deprecated`'
|
||||
|
||||
authors:
|
||||
Matthijs S. Berends:
|
||||
href: https://www.rug.nl/staff/m.s.berends/
|
||||
Christian F. Luz:
|
||||
href: https://www.rug.nl/staff/c.f.luz/
|
||||
Corinna Glasner:
|
||||
href: https://www.rug.nl/staff/c.glasner/
|
||||
Alex W. Friedrich:
|
||||
href: https://www.rug.nl/staff/a.w.friedrich/
|
||||
Bhanu N. M. Sinha:
|
||||
href: https://www.rug.nl/staff/b.sinha/
|
||||
|
||||
template:
|
||||
assets: pkgdown/logos # use logos in this folder
|
||||
params:
|
||||
noindex: false
|
||||
bootswatch: flatly
|
||||
docsearch:
|
||||
# using algolia.com
|
||||
api_key: 'f737050abfd4d726c63938e18f8c496e'
|
||||
index_name: 'amr'
|
||||
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 56 KiB |
|
After Width: | Height: | Size: 6.2 KiB |
|
After Width: | Height: | Size: 8.0 KiB |
|
After Width: | Height: | Size: 9.7 KiB |
|
After Width: | Height: | Size: 2.9 KiB |
|
After Width: | Height: | Size: 3.6 KiB |
|
After Width: | Height: | Size: 9.7 KiB |
@@ -1,75 +0,0 @@
|
||||
# ==================================================================== #
|
||||
# TITLE #
|
||||
# Antimicrobial Resistance (AMR) Analysis #
|
||||
# #
|
||||
# SOURCE #
|
||||
# https://gitlab.com/msberends/AMR #
|
||||
# #
|
||||
# LICENCE #
|
||||
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
|
||||
# #
|
||||
# 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. #
|
||||
# #
|
||||
# This R package was created for academic research and was publicly #
|
||||
# released in the hope that it will be useful, but it comes WITHOUT #
|
||||
# ANY WARRANTY OR LIABILITY. #
|
||||
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
||||
# ==================================================================== #
|
||||
|
||||
# Download script file from GitHub
|
||||
init:
|
||||
ps: |
|
||||
$ErrorActionPreference = "Stop"
|
||||
Invoke-WebRequest https://raw.githubusercontent.com/krlmlr/r-appveyor/master/scripts/appveyor-tool.ps1 -OutFile "..\appveyor-tool.ps1"
|
||||
Import-Module '..\appveyor-tool.ps1'
|
||||
|
||||
install:
|
||||
ps: Bootstrap
|
||||
|
||||
cache:
|
||||
- C:\RLibrary
|
||||
|
||||
# Adapt as necessary starting from here
|
||||
|
||||
environment:
|
||||
R_ARCH: x64
|
||||
GCC_PATH: mingw_64
|
||||
WARNINGS_ARE_ERRORS: 1
|
||||
PKGTYPE: win.binary
|
||||
# USE_RTOOLS: true
|
||||
|
||||
matrix:
|
||||
- R_VERSION: release
|
||||
- R_VERSION: devel
|
||||
|
||||
build_script:
|
||||
- travis-tool.sh install_deps
|
||||
|
||||
test_script:
|
||||
- travis-tool.sh run_tests
|
||||
|
||||
on_failure:
|
||||
- 7z a failure.zip *.Rcheck\*
|
||||
- appveyor PushArtifact failure.zip
|
||||
|
||||
artifacts:
|
||||
- path: '*.Rcheck\**\*.log'
|
||||
name: Logs
|
||||
|
||||
- path: '*.Rcheck\**\*.out'
|
||||
name: Logs
|
||||
|
||||
- path: '*.Rcheck\**\*.fail'
|
||||
name: Logs
|
||||
|
||||
- path: '*.Rcheck\**\*.Rout'
|
||||
name: Logs
|
||||
|
||||
- path: '\*_*.tar.gz'
|
||||
name: Bits
|
||||
|
||||
- path: '\*_*.zip'
|
||||
name: Bits
|
||||
|
After Width: | Height: | Size: 38 KiB |
|
After Width: | Height: | Size: 55 KiB |
|
After Width: | Height: | Size: 27 KiB |
|
After Width: | Height: | Size: 37 KiB |
|
After Width: | Height: | Size: 38 KiB |
|
After Width: | Height: | Size: 48 KiB |
|
After Width: | Height: | Size: 41 KiB |
|
After Width: | Height: | Size: 28 KiB |
|
After Width: | Height: | Size: 76 KiB |
|
After Width: | Height: | Size: 49 KiB |
@@ -0,0 +1,435 @@
|
||||
<!DOCTYPE html>
|
||||
<!-- Generated by pkgdown: do not edit by hand --><html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<meta name="description" content="AMR">
|
||||
<title>How to apply EUCAST rules • AMR (for R)</title>
|
||||
<!-- favicons --><link rel="icon" type="image/png" sizes="16x16" href="../favicon-16x16.png">
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="../favicon-32x32.png">
|
||||
<link rel="apple-touch-icon" type="image/png" sizes="180x180" href="../apple-touch-icon.png">
|
||||
<link rel="apple-touch-icon" type="image/png" sizes="120x120" href="../apple-touch-icon-120x120.png">
|
||||
<link rel="apple-touch-icon" type="image/png" sizes="76x76" href="../apple-touch-icon-76x76.png">
|
||||
<link rel="apple-touch-icon" type="image/png" sizes="60x60" href="../apple-touch-icon-60x60.png">
|
||||
<script src="../deps/jquery-3.6.0/jquery-3.6.0.min.js"></script><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<link href="../deps/bootstrap-5.2.2/bootstrap.min.css" rel="stylesheet">
|
||||
<script src="../deps/bootstrap-5.2.2/bootstrap.bundle.min.js"></script><link href="../deps/Fira_Code-0.4.5/font.css" rel="stylesheet">
|
||||
<!-- Font Awesome icons --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css" integrity="sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk=" crossorigin="anonymous">
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/v4-shims.min.css" integrity="sha256-wZjR52fzng1pJHwx4aV2AO3yyTOXrcDW7jBpJtTwVxw=" crossorigin="anonymous">
|
||||
<!-- bootstrap-toc --><script src="https://cdn.jsdelivr.net/gh/afeld/bootstrap-toc@v1.0.1/dist/bootstrap-toc.min.js" integrity="sha256-4veVQbu7//Lk5TSmc7YV48MxtMy98e26cf5MrgZYnwo=" crossorigin="anonymous"></script><!-- headroom.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/headroom.min.js" integrity="sha256-AsUX4SJE1+yuDu5+mAVzJbuYNPHj/WroHuZ8Ir/CkE0=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/jQuery.headroom.min.js" integrity="sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4=" crossorigin="anonymous"></script><!-- clipboard.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js" integrity="sha256-inc5kl9MA1hkeYUt+EC3BhlIgyp/2jDIyBLS6k3UxPI=" crossorigin="anonymous"></script><!-- search --><script src="https://cdnjs.cloudflare.com/ajax/libs/fuse.js/6.4.6/fuse.js" integrity="sha512-zv6Ywkjyktsohkbp9bb45V6tEMoWhzFzXis+LrMehmJZZSys19Yxf1dopHx7WzIKxr5tK2dVcYmaCk2uqdjF4A==" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/autocomplete.js/0.38.0/autocomplete.jquery.min.js" integrity="sha512-GU9ayf+66Xx2TmpxqJpliWbT5PiGYxpaG8rfnBEk1LL8l1KGkRShhngwdXK1UgqhAzWpZHSiYPc09/NwDQIGyg==" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mark.js/8.11.1/mark.min.js" integrity="sha512-5CYOlHXGh6QpOFA/TeTylKLWfB3ftPsde7AnmhuitiTX4K5SqCLBeKro6sPS8ilsz1Q4NRx3v8Ko2IBiszzdww==" crossorigin="anonymous"></script><!-- pkgdown --><script src="../pkgdown.js"></script><link href="../extra.css" rel="stylesheet">
|
||||
<script src="../extra.js"></script><meta property="og:title" content="How to apply EUCAST rules">
|
||||
<meta property="og:description" content="AMR">
|
||||
<meta property="og:image" content="https://msberends.github.io/AMR/logo.svg">
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
<meta name="twitter:creator" content="@msberends">
|
||||
<meta name="twitter:site" content="@msberends">
|
||||
<!-- mathjax --><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script><!--[if lt IE 9]>
|
||||
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
|
||||
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
|
||||
<![endif]-->
|
||||
</head>
|
||||
<body>
|
||||
<a href="#main" class="visually-hidden-focusable">Skip to contents</a>
|
||||
|
||||
|
||||
<nav class="navbar fixed-top navbar-dark navbar-expand-lg bg-primary"><div class="container">
|
||||
|
||||
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
|
||||
|
||||
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">1.8.2.9139</small>
|
||||
|
||||
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<div id="navbar" class="collapse navbar-collapse ms-3">
|
||||
<ul class="navbar-nav me-auto">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="../index.html">
|
||||
<span class="fa fa-home"></span>
|
||||
|
||||
Home
|
||||
</a>
|
||||
</li>
|
||||
<li class="active nav-item dropdown">
|
||||
<a href="#" class="nav-link dropdown-toggle" data-bs-toggle="dropdown" role="button" aria-expanded="false" aria-haspopup="true" id="dropdown--how-to">
|
||||
<span class="fa fa-question-circle"></span>
|
||||
|
||||
How to
|
||||
</a>
|
||||
<div class="dropdown-menu" aria-labelledby="dropdown--how-to">
|
||||
<a class="dropdown-item" href="../reference/AMR-options.html">
|
||||
<span class="fa fa-gear"></span>
|
||||
|
||||
User- Or Team-specific Package Settings
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/AMR.html">
|
||||
<span class="fa fa-directions"></span>
|
||||
|
||||
Conduct AMR Analysis
|
||||
</a>
|
||||
<a class="dropdown-item" href="../reference/antibiogram.html">
|
||||
<span class="fa fa-file-prescription"></span>
|
||||
|
||||
Generate Antibiogram (Trad./Syndromic/WISCA)
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/resistance_predict.html">
|
||||
<span class="fa fa-dice"></span>
|
||||
|
||||
Predict Antimicrobial Resistance
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/datasets.html">
|
||||
<span class="fa fa-database"></span>
|
||||
|
||||
Data Sets for Download / Own Use
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/PCA.html">
|
||||
<span class="fa fa-compress"></span>
|
||||
|
||||
Conduct Principal Component Analysis for AMR
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/MDR.html">
|
||||
<span class="fa fa-skull-crossbones"></span>
|
||||
|
||||
Determine Multi-Drug Resistance (MDR)
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/WHONET.html">
|
||||
<span class="fa fa-globe-americas"></span>
|
||||
|
||||
Work with WHONET Data
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/SPSS.html">
|
||||
<span class="fa fa-file-upload"></span>
|
||||
|
||||
Import Data From SPSS/SAS/Stata
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/EUCAST.html">
|
||||
<span class="fa fa-exchange-alt"></span>
|
||||
|
||||
Apply Eucast Rules
|
||||
</a>
|
||||
<a class="dropdown-item" href="../reference/mo_property.html">
|
||||
<span class="fa fa-bug"></span>
|
||||
|
||||
Get Taxonomy of a Microorganism
|
||||
</a>
|
||||
<a class="dropdown-item" href="../reference/ab_property.html">
|
||||
<span class="fa fa-capsules"></span>
|
||||
|
||||
Get Properties of an Antibiotic Drug
|
||||
</a>
|
||||
<a class="dropdown-item" href="../reference/av_property.html">
|
||||
<span class="fa fa-capsules"></span>
|
||||
|
||||
Get Properties of an Antiviral Drug
|
||||
</a>
|
||||
</div>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="../reference/index.html">
|
||||
<span class="fa fa-book-open"></span>
|
||||
|
||||
Manual
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="../authors.html">
|
||||
<span class="fa fa-users"></span>
|
||||
|
||||
Authors
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="../news/index.html">
|
||||
<span class="far fa far fa-newspaper"></span>
|
||||
|
||||
Changelog
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
<form class="form-inline my-2 my-lg-0" role="search">
|
||||
<input type="search" class="form-control me-sm-2" aria-label="Toggle navigation" name="search-input" data-search-index="../search.json" id="search-input" placeholder="Search for" autocomplete="off">
|
||||
</form>
|
||||
|
||||
<ul class="navbar-nav">
|
||||
<li class="nav-item">
|
||||
<a class="external-link nav-link" href="https://github.com/msberends/AMR">
|
||||
<span class="fab fa fab fa-github"></span>
|
||||
|
||||
Source Code
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</nav><div class="container template-article">
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="row">
|
||||
<main id="main" class="col-md-9"><div class="page-header">
|
||||
<img src="../logo.svg" class="logo" alt=""><h1>How to apply EUCAST rules</h1>
|
||||
|
||||
|
||||
<small class="dont-index">Source: <a href="https://github.com/msberends/AMR/blob/HEAD/vignettes/EUCAST.Rmd" class="external-link"><code>vignettes/EUCAST.Rmd</code></a></small>
|
||||
<div class="d-none name"><code>EUCAST.Rmd</code></div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div class="section level2">
|
||||
<h2 id="introduction">Introduction<a class="anchor" aria-label="anchor" href="#introduction"></a>
|
||||
</h2>
|
||||
<p>What are EUCAST rules? The European Committee on Antimicrobial
|
||||
Susceptibility Testing (EUCAST) states <a href="https://www.eucast.org/expert_rules_and_intrinsic_resistance/" class="external-link">on
|
||||
their website</a>:</p>
|
||||
<blockquote>
|
||||
<p><em>EUCAST expert rules are a tabulated collection of expert
|
||||
knowledge on intrinsic resistances, exceptional resistance phenotypes
|
||||
and interpretive rules that may be applied to antimicrobial
|
||||
susceptibility testing in order to reduce errors and make appropriate
|
||||
recommendations for reporting particular resistances.</em></p>
|
||||
</blockquote>
|
||||
<p>In Europe, a lot of medical microbiological laboratories already
|
||||
apply these rules (<a href="https://www.eurosurveillance.org/content/10.2807/1560-7917.ES2015.20.2.21008" class="external-link">Brown
|
||||
<em>et al.</em>, 2015</a>). Our package features their latest insights
|
||||
on intrinsic resistance and unusual phenotypes (v3.3, 2021).</p>
|
||||
<p>Moreover, the <code><a href="../reference/eucast_rules.html">eucast_rules()</a></code> function we use for this
|
||||
purpose can also apply additional rules, like forcing
|
||||
<help title="ATC: J01CA01">ampicillin</help> = R in isolates when
|
||||
<help title="ATC: J01CR02">amoxicillin/clavulanic acid</help> = R.</p>
|
||||
</div>
|
||||
<div class="section level2">
|
||||
<h2 id="examples">Examples<a class="anchor" aria-label="anchor" href="#examples"></a>
|
||||
</h2>
|
||||
<p>These rules can be used to discard impossible bug-drug combinations
|
||||
in your data. For example, <em>Klebsiella</em> produces beta-lactamase
|
||||
that prevents ampicillin (or amoxicillin) from working against it. In
|
||||
other words, practically every strain of <em>Klebsiella</em> is
|
||||
resistant to ampicillin.</p>
|
||||
<p>Sometimes, laboratory data can still contain such strains with
|
||||
ampicillin being susceptible to ampicillin. This could be because an
|
||||
antibiogram is available before an identification is available, and the
|
||||
antibiogram is then not re-interpreted based on the identification
|
||||
(namely, <em>Klebsiella</em>). EUCAST expert rules solve this, that can
|
||||
be applied using <code><a href="../reference/eucast_rules.html">eucast_rules()</a></code>:</p>
|
||||
<div class="sourceCode" id="cb1"><pre class="downlit sourceCode r">
|
||||
<code class="sourceCode R"><span><span class="va">oops</span> <span class="op"><-</span> <span class="fu"><a href="https://rdrr.io/r/base/data.frame.html" class="external-link">data.frame</a></span><span class="op">(</span></span>
|
||||
<span> mo <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span></span>
|
||||
<span> <span class="st">"Klebsiella"</span>,</span>
|
||||
<span> <span class="st">"Escherichia"</span></span>
|
||||
<span> <span class="op">)</span>,</span>
|
||||
<span> ampicillin <span class="op">=</span> <span class="st">"S"</span></span>
|
||||
<span><span class="op">)</span></span>
|
||||
<span><span class="va">oops</span></span>
|
||||
<span><span class="co">#> mo ampicillin</span></span>
|
||||
<span><span class="co">#> 1 Klebsiella S</span></span>
|
||||
<span><span class="co">#> 2 Escherichia S</span></span>
|
||||
<span></span>
|
||||
<span><span class="fu"><a href="../reference/eucast_rules.html">eucast_rules</a></span><span class="op">(</span><span class="va">oops</span>, info <span class="op">=</span> <span class="cn">FALSE</span><span class="op">)</span></span>
|
||||
<span><span class="co">#> mo ampicillin</span></span>
|
||||
<span><span class="co">#> 1 Klebsiella R</span></span>
|
||||
<span><span class="co">#> 2 Escherichia S</span></span></code></pre></div>
|
||||
<p>A more convenient function is
|
||||
<code><a href="../reference/mo_property.html">mo_is_intrinsic_resistant()</a></code> that uses the same guideline,
|
||||
but allows to check for one or more specific microorganisms or
|
||||
antibiotics:</p>
|
||||
<div class="sourceCode" id="cb2"><pre class="downlit sourceCode r">
|
||||
<code class="sourceCode R"><span><span class="fu"><a href="../reference/mo_property.html">mo_is_intrinsic_resistant</a></span><span class="op">(</span></span>
|
||||
<span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"Klebsiella"</span>, <span class="st">"Escherichia"</span><span class="op">)</span>,</span>
|
||||
<span> <span class="st">"ampicillin"</span></span>
|
||||
<span><span class="op">)</span></span>
|
||||
<span><span class="co">#> [1] TRUE FALSE</span></span>
|
||||
<span></span>
|
||||
<span><span class="fu"><a href="../reference/mo_property.html">mo_is_intrinsic_resistant</a></span><span class="op">(</span></span>
|
||||
<span> <span class="st">"Klebsiella"</span>,</span>
|
||||
<span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"ampicillin"</span>, <span class="st">"kanamycin"</span><span class="op">)</span></span>
|
||||
<span><span class="op">)</span></span>
|
||||
<span><span class="co">#> [1] TRUE FALSE</span></span></code></pre></div>
|
||||
<p>EUCAST rules can not only be used for correction, they can also be
|
||||
used for filling in known resistance and susceptibility based on results
|
||||
of other antimicrobials drugs. This process is called <em>interpretive
|
||||
reading</em>, is basically a form of imputation, and is part of the
|
||||
<code><a href="../reference/eucast_rules.html">eucast_rules()</a></code> function as well:</p>
|
||||
<div class="sourceCode" id="cb3"><pre class="downlit sourceCode r">
|
||||
<code class="sourceCode R"><span><span class="va">data</span> <span class="op"><-</span> <span class="fu"><a href="https://rdrr.io/r/base/data.frame.html" class="external-link">data.frame</a></span><span class="op">(</span></span>
|
||||
<span> mo <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span></span>
|
||||
<span> <span class="st">"Staphylococcus aureus"</span>,</span>
|
||||
<span> <span class="st">"Enterococcus faecalis"</span>,</span>
|
||||
<span> <span class="st">"Escherichia coli"</span>,</span>
|
||||
<span> <span class="st">"Klebsiella pneumoniae"</span>,</span>
|
||||
<span> <span class="st">"Pseudomonas aeruginosa"</span></span>
|
||||
<span> <span class="op">)</span>,</span>
|
||||
<span> VAN <span class="op">=</span> <span class="st">"-"</span>, <span class="co"># Vancomycin</span></span>
|
||||
<span> AMX <span class="op">=</span> <span class="st">"-"</span>, <span class="co"># Amoxicillin</span></span>
|
||||
<span> COL <span class="op">=</span> <span class="st">"-"</span>, <span class="co"># Colistin</span></span>
|
||||
<span> CAZ <span class="op">=</span> <span class="st">"-"</span>, <span class="co"># Ceftazidime</span></span>
|
||||
<span> CXM <span class="op">=</span> <span class="st">"-"</span>, <span class="co"># Cefuroxime</span></span>
|
||||
<span> PEN <span class="op">=</span> <span class="st">"S"</span>, <span class="co"># Benzylenicillin</span></span>
|
||||
<span> FOX <span class="op">=</span> <span class="st">"S"</span>, <span class="co"># Cefoxitin</span></span>
|
||||
<span> stringsAsFactors <span class="op">=</span> <span class="cn">FALSE</span></span>
|
||||
<span><span class="op">)</span></span></code></pre></div>
|
||||
<div class="sourceCode" id="cb4"><pre class="downlit sourceCode r">
|
||||
<code class="sourceCode R"><span><span class="va">data</span></span></code></pre></div>
|
||||
<table class="table">
|
||||
<thead><tr class="header">
|
||||
<th align="left">mo</th>
|
||||
<th align="center">VAN</th>
|
||||
<th align="center">AMX</th>
|
||||
<th align="center">COL</th>
|
||||
<th align="center">CAZ</th>
|
||||
<th align="center">CXM</th>
|
||||
<th align="center">PEN</th>
|
||||
<th align="center">FOX</th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<tr class="odd">
|
||||
<td align="left">Staphylococcus aureus</td>
|
||||
<td align="center">-</td>
|
||||
<td align="center">-</td>
|
||||
<td align="center">-</td>
|
||||
<td align="center">-</td>
|
||||
<td align="center">-</td>
|
||||
<td align="center">S</td>
|
||||
<td align="center">S</td>
|
||||
</tr>
|
||||
<tr class="even">
|
||||
<td align="left">Enterococcus faecalis</td>
|
||||
<td align="center">-</td>
|
||||
<td align="center">-</td>
|
||||
<td align="center">-</td>
|
||||
<td align="center">-</td>
|
||||
<td align="center">-</td>
|
||||
<td align="center">S</td>
|
||||
<td align="center">S</td>
|
||||
</tr>
|
||||
<tr class="odd">
|
||||
<td align="left">Escherichia coli</td>
|
||||
<td align="center">-</td>
|
||||
<td align="center">-</td>
|
||||
<td align="center">-</td>
|
||||
<td align="center">-</td>
|
||||
<td align="center">-</td>
|
||||
<td align="center">S</td>
|
||||
<td align="center">S</td>
|
||||
</tr>
|
||||
<tr class="even">
|
||||
<td align="left">Klebsiella pneumoniae</td>
|
||||
<td align="center">-</td>
|
||||
<td align="center">-</td>
|
||||
<td align="center">-</td>
|
||||
<td align="center">-</td>
|
||||
<td align="center">-</td>
|
||||
<td align="center">S</td>
|
||||
<td align="center">S</td>
|
||||
</tr>
|
||||
<tr class="odd">
|
||||
<td align="left">Pseudomonas aeruginosa</td>
|
||||
<td align="center">-</td>
|
||||
<td align="center">-</td>
|
||||
<td align="center">-</td>
|
||||
<td align="center">-</td>
|
||||
<td align="center">-</td>
|
||||
<td align="center">S</td>
|
||||
<td align="center">S</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="sourceCode" id="cb5"><pre class="downlit sourceCode r">
|
||||
<code class="sourceCode R"><span><span class="fu"><a href="../reference/eucast_rules.html">eucast_rules</a></span><span class="op">(</span><span class="va">data</span><span class="op">)</span></span></code></pre></div>
|
||||
<table class="table">
|
||||
<thead><tr class="header">
|
||||
<th align="left">mo</th>
|
||||
<th align="center">VAN</th>
|
||||
<th align="center">AMX</th>
|
||||
<th align="center">COL</th>
|
||||
<th align="center">CAZ</th>
|
||||
<th align="center">CXM</th>
|
||||
<th align="center">PEN</th>
|
||||
<th align="center">FOX</th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<tr class="odd">
|
||||
<td align="left">Staphylococcus aureus</td>
|
||||
<td align="center">-</td>
|
||||
<td align="center">S</td>
|
||||
<td align="center">R</td>
|
||||
<td align="center">S</td>
|
||||
<td align="center">S</td>
|
||||
<td align="center">S</td>
|
||||
<td align="center">S</td>
|
||||
</tr>
|
||||
<tr class="even">
|
||||
<td align="left">Enterococcus faecalis</td>
|
||||
<td align="center">-</td>
|
||||
<td align="center">-</td>
|
||||
<td align="center">R</td>
|
||||
<td align="center">R</td>
|
||||
<td align="center">R</td>
|
||||
<td align="center">S</td>
|
||||
<td align="center">R</td>
|
||||
</tr>
|
||||
<tr class="odd">
|
||||
<td align="left">Escherichia coli</td>
|
||||
<td align="center">R</td>
|
||||
<td align="center">-</td>
|
||||
<td align="center">-</td>
|
||||
<td align="center">-</td>
|
||||
<td align="center">-</td>
|
||||
<td align="center">R</td>
|
||||
<td align="center">S</td>
|
||||
</tr>
|
||||
<tr class="even">
|
||||
<td align="left">Klebsiella pneumoniae</td>
|
||||
<td align="center">R</td>
|
||||
<td align="center">R</td>
|
||||
<td align="center">-</td>
|
||||
<td align="center">-</td>
|
||||
<td align="center">-</td>
|
||||
<td align="center">R</td>
|
||||
<td align="center">S</td>
|
||||
</tr>
|
||||
<tr class="odd">
|
||||
<td align="left">Pseudomonas aeruginosa</td>
|
||||
<td align="center">R</td>
|
||||
<td align="center">R</td>
|
||||
<td align="center">-</td>
|
||||
<td align="center">-</td>
|
||||
<td align="center">R</td>
|
||||
<td align="center">R</td>
|
||||
<td align="center">R</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</main><aside class="col-md-3"><nav id="toc"><h2>On this page</h2>
|
||||
</nav></aside>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<footer><div class="pkgdown-footer-left">
|
||||
<p></p>
|
||||
<p><code>AMR</code> (for R). Free and open-source, licenced under the <a target="_blank" href="https://github.com/msberends/AMR/blob/main/LICENSE" class="external-link">GNU General Public License version 2.0 (GPL-2)</a>.<br>Developed at the <a target="_blank" href="https://www.rug.nl" class="external-link">University of Groningen</a> and <a target="_blank" href="https://www.umcg.nl" class="external-link">University Medical Center Groningen</a> in The Netherlands.</p>
|
||||
</div>
|
||||
|
||||
<div class="pkgdown-footer-right">
|
||||
<p></p>
|
||||
<p><a target="_blank" href="https://www.rug.nl" class="external-link"><img src="https://github.com/msberends/AMR/raw/main/pkgdown/logos/logo_rug.svg" style="max-width: 150px;"></a><a target="_blank" href="https://www.umcg.nl" class="external-link"><img src="https://github.com/msberends/AMR/raw/main/pkgdown/logos/logo_umcg.svg" style="max-width: 150px;"></a></p>
|
||||
</div>
|
||||
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,505 @@
|
||||
<!DOCTYPE html>
|
||||
<!-- Generated by pkgdown: do not edit by hand --><html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<meta name="description" content="AMR">
|
||||
<title>How to determine multi-drug resistance (MDR) • AMR (for R)</title>
|
||||
<!-- favicons --><link rel="icon" type="image/png" sizes="16x16" href="../favicon-16x16.png">
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="../favicon-32x32.png">
|
||||
<link rel="apple-touch-icon" type="image/png" sizes="180x180" href="../apple-touch-icon.png">
|
||||
<link rel="apple-touch-icon" type="image/png" sizes="120x120" href="../apple-touch-icon-120x120.png">
|
||||
<link rel="apple-touch-icon" type="image/png" sizes="76x76" href="../apple-touch-icon-76x76.png">
|
||||
<link rel="apple-touch-icon" type="image/png" sizes="60x60" href="../apple-touch-icon-60x60.png">
|
||||
<script src="../deps/jquery-3.6.0/jquery-3.6.0.min.js"></script><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<link href="../deps/bootstrap-5.2.2/bootstrap.min.css" rel="stylesheet">
|
||||
<script src="../deps/bootstrap-5.2.2/bootstrap.bundle.min.js"></script><link href="../deps/Fira_Code-0.4.5/font.css" rel="stylesheet">
|
||||
<!-- Font Awesome icons --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css" integrity="sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk=" crossorigin="anonymous">
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/v4-shims.min.css" integrity="sha256-wZjR52fzng1pJHwx4aV2AO3yyTOXrcDW7jBpJtTwVxw=" crossorigin="anonymous">
|
||||
<!-- bootstrap-toc --><script src="https://cdn.jsdelivr.net/gh/afeld/bootstrap-toc@v1.0.1/dist/bootstrap-toc.min.js" integrity="sha256-4veVQbu7//Lk5TSmc7YV48MxtMy98e26cf5MrgZYnwo=" crossorigin="anonymous"></script><!-- headroom.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/headroom.min.js" integrity="sha256-AsUX4SJE1+yuDu5+mAVzJbuYNPHj/WroHuZ8Ir/CkE0=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/jQuery.headroom.min.js" integrity="sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4=" crossorigin="anonymous"></script><!-- clipboard.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js" integrity="sha256-inc5kl9MA1hkeYUt+EC3BhlIgyp/2jDIyBLS6k3UxPI=" crossorigin="anonymous"></script><!-- search --><script src="https://cdnjs.cloudflare.com/ajax/libs/fuse.js/6.4.6/fuse.js" integrity="sha512-zv6Ywkjyktsohkbp9bb45V6tEMoWhzFzXis+LrMehmJZZSys19Yxf1dopHx7WzIKxr5tK2dVcYmaCk2uqdjF4A==" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/autocomplete.js/0.38.0/autocomplete.jquery.min.js" integrity="sha512-GU9ayf+66Xx2TmpxqJpliWbT5PiGYxpaG8rfnBEk1LL8l1KGkRShhngwdXK1UgqhAzWpZHSiYPc09/NwDQIGyg==" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mark.js/8.11.1/mark.min.js" integrity="sha512-5CYOlHXGh6QpOFA/TeTylKLWfB3ftPsde7AnmhuitiTX4K5SqCLBeKro6sPS8ilsz1Q4NRx3v8Ko2IBiszzdww==" crossorigin="anonymous"></script><!-- pkgdown --><script src="../pkgdown.js"></script><link href="../extra.css" rel="stylesheet">
|
||||
<script src="../extra.js"></script><meta property="og:title" content="How to determine multi-drug resistance (MDR)">
|
||||
<meta property="og:description" content="AMR">
|
||||
<meta property="og:image" content="https://msberends.github.io/AMR/logo.svg">
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
<meta name="twitter:creator" content="@msberends">
|
||||
<meta name="twitter:site" content="@msberends">
|
||||
<!-- mathjax --><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script><!--[if lt IE 9]>
|
||||
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
|
||||
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
|
||||
<![endif]-->
|
||||
</head>
|
||||
<body>
|
||||
<a href="#main" class="visually-hidden-focusable">Skip to contents</a>
|
||||
|
||||
|
||||
<nav class="navbar fixed-top navbar-dark navbar-expand-lg bg-primary"><div class="container">
|
||||
|
||||
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
|
||||
|
||||
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">1.8.2.9139</small>
|
||||
|
||||
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<div id="navbar" class="collapse navbar-collapse ms-3">
|
||||
<ul class="navbar-nav me-auto">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="../index.html">
|
||||
<span class="fa fa-home"></span>
|
||||
|
||||
Home
|
||||
</a>
|
||||
</li>
|
||||
<li class="active nav-item dropdown">
|
||||
<a href="#" class="nav-link dropdown-toggle" data-bs-toggle="dropdown" role="button" aria-expanded="false" aria-haspopup="true" id="dropdown--how-to">
|
||||
<span class="fa fa-question-circle"></span>
|
||||
|
||||
How to
|
||||
</a>
|
||||
<div class="dropdown-menu" aria-labelledby="dropdown--how-to">
|
||||
<a class="dropdown-item" href="../reference/AMR-options.html">
|
||||
<span class="fa fa-gear"></span>
|
||||
|
||||
User- Or Team-specific Package Settings
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/AMR.html">
|
||||
<span class="fa fa-directions"></span>
|
||||
|
||||
Conduct AMR Analysis
|
||||
</a>
|
||||
<a class="dropdown-item" href="../reference/antibiogram.html">
|
||||
<span class="fa fa-file-prescription"></span>
|
||||
|
||||
Generate Antibiogram (Trad./Syndromic/WISCA)
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/resistance_predict.html">
|
||||
<span class="fa fa-dice"></span>
|
||||
|
||||
Predict Antimicrobial Resistance
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/datasets.html">
|
||||
<span class="fa fa-database"></span>
|
||||
|
||||
Data Sets for Download / Own Use
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/PCA.html">
|
||||
<span class="fa fa-compress"></span>
|
||||
|
||||
Conduct Principal Component Analysis for AMR
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/MDR.html">
|
||||
<span class="fa fa-skull-crossbones"></span>
|
||||
|
||||
Determine Multi-Drug Resistance (MDR)
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/WHONET.html">
|
||||
<span class="fa fa-globe-americas"></span>
|
||||
|
||||
Work with WHONET Data
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/SPSS.html">
|
||||
<span class="fa fa-file-upload"></span>
|
||||
|
||||
Import Data From SPSS/SAS/Stata
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/EUCAST.html">
|
||||
<span class="fa fa-exchange-alt"></span>
|
||||
|
||||
Apply Eucast Rules
|
||||
</a>
|
||||
<a class="dropdown-item" href="../reference/mo_property.html">
|
||||
<span class="fa fa-bug"></span>
|
||||
|
||||
Get Taxonomy of a Microorganism
|
||||
</a>
|
||||
<a class="dropdown-item" href="../reference/ab_property.html">
|
||||
<span class="fa fa-capsules"></span>
|
||||
|
||||
Get Properties of an Antibiotic Drug
|
||||
</a>
|
||||
<a class="dropdown-item" href="../reference/av_property.html">
|
||||
<span class="fa fa-capsules"></span>
|
||||
|
||||
Get Properties of an Antiviral Drug
|
||||
</a>
|
||||
</div>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="../reference/index.html">
|
||||
<span class="fa fa-book-open"></span>
|
||||
|
||||
Manual
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="../authors.html">
|
||||
<span class="fa fa-users"></span>
|
||||
|
||||
Authors
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="../news/index.html">
|
||||
<span class="far fa far fa-newspaper"></span>
|
||||
|
||||
Changelog
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
<form class="form-inline my-2 my-lg-0" role="search">
|
||||
<input type="search" class="form-control me-sm-2" aria-label="Toggle navigation" name="search-input" data-search-index="../search.json" id="search-input" placeholder="Search for" autocomplete="off">
|
||||
</form>
|
||||
|
||||
<ul class="navbar-nav">
|
||||
<li class="nav-item">
|
||||
<a class="external-link nav-link" href="https://github.com/msberends/AMR">
|
||||
<span class="fab fa fab fa-github"></span>
|
||||
|
||||
Source Code
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</nav><div class="container template-article">
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="row">
|
||||
<main id="main" class="col-md-9"><div class="page-header">
|
||||
<img src="../logo.svg" class="logo" alt=""><h1>How to determine multi-drug resistance (MDR)</h1>
|
||||
|
||||
|
||||
<small class="dont-index">Source: <a href="https://github.com/msberends/AMR/blob/HEAD/vignettes/MDR.Rmd" class="external-link"><code>vignettes/MDR.Rmd</code></a></small>
|
||||
<div class="d-none name"><code>MDR.Rmd</code></div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<p>With the function <code><a href="../reference/mdro.html">mdro()</a></code>, you can determine which
|
||||
micro-organisms are multi-drug resistant organisms (MDRO).</p>
|
||||
<div class="section level3">
|
||||
<h3 id="type-of-input">Type of input<a class="anchor" aria-label="anchor" href="#type-of-input"></a>
|
||||
</h3>
|
||||
<p>The <code><a href="../reference/mdro.html">mdro()</a></code> function takes a data set as input, such as a
|
||||
regular <code>data.frame</code>. It tries to automatically determine the
|
||||
right columns for info about your isolates, such as the name of the
|
||||
species and all columns with results of antimicrobial agents. See the
|
||||
help page for more info about how to set the right settings for your
|
||||
data with the command <code><a href="../reference/mdro.html">?mdro</a></code>.</p>
|
||||
<p>For WHONET data (and most other data), all settings are automatically
|
||||
set correctly.</p>
|
||||
</div>
|
||||
<div class="section level3">
|
||||
<h3 id="guidelines">Guidelines<a class="anchor" aria-label="anchor" href="#guidelines"></a>
|
||||
</h3>
|
||||
<p>The <code><a href="../reference/mdro.html">mdro()</a></code> function support multiple guidelines. You can
|
||||
select a guideline with the <code>guideline</code> parameter. Currently
|
||||
supported guidelines are (case-insensitive):</p>
|
||||
<ul>
|
||||
<li>
|
||||
<p><code>guideline = "CMI2012"</code> (default)</p>
|
||||
<p>Magiorakos AP, Srinivasan A <em>et al.</em> “Multidrug-resistant,
|
||||
extensively drug-resistant and pandrug-resistant bacteria: an
|
||||
international expert proposal for interim standard definitions for
|
||||
acquired resistance.” Clinical Microbiology and Infection (2012) (<a href="https://www.clinicalmicrobiologyandinfection.com/article/S1198-743X(14)61632-3/fulltext" class="external-link">link</a>)</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><code>guideline = "EUCAST3.2"</code> (or simply
|
||||
<code>guideline = "EUCAST"</code>)</p>
|
||||
<p>The European international guideline - EUCAST Expert Rules Version
|
||||
3.2 “Intrinsic Resistance and Unusual Phenotypes” (<a href="https://www.eucast.org/fileadmin/src/media/PDFs/EUCAST_files/Expert_Rules/2020/Intrinsic_Resistance_and_Unusual_Phenotypes_Tables_v3.2_20200225.pdf" class="external-link">link</a>)</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><code>guideline = "EUCAST3.1"</code></p>
|
||||
<p>The European international guideline - EUCAST Expert Rules Version
|
||||
3.1 “Intrinsic Resistance and Exceptional Phenotypes Tables” (<a href="https://www.eucast.org/fileadmin/src/media/PDFs/EUCAST_files/Expert_Rules/Expert_rules_intrinsic_exceptional_V3.1.pdf" class="external-link">link</a>)</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><code>guideline = "TB"</code></p>
|
||||
<p>The international guideline for multi-drug resistant tuberculosis -
|
||||
World Health Organization “Companion handbook to the WHO guidelines for
|
||||
the programmatic management of drug-resistant tuberculosis” (<a href="https://www.who.int/tb/publications/pmdt_companionhandbook/en/" class="external-link">link</a>)</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><code>guideline = "MRGN"</code></p>
|
||||
<p>The German national guideline - Mueller <em>et al.</em> (2015)
|
||||
Antimicrobial Resistance and Infection Control 4:7. DOI:
|
||||
10.1186/s13756-015-0047-6</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><code>guideline = "BRMO"</code></p>
|
||||
<p>The Dutch national guideline - Rijksinstituut voor Volksgezondheid en
|
||||
Milieu “WIP-richtlijn BRMO (Bijzonder Resistente Micro-Organismen)
|
||||
(ZKH)” (<a href="https://www.rivm.nl/wip-richtlijn-brmo-bijzonder-resistente-micro-organismen-zkh" class="external-link">link</a>)</p>
|
||||
</li>
|
||||
</ul>
|
||||
<p>Please suggest your own (country-specific) guidelines by letting us
|
||||
know: <a href="https://github.com/msberends/AMR/issues/new" class="external-link uri">https://github.com/msberends/AMR/issues/new</a>.</p>
|
||||
<div class="section level4">
|
||||
<h4 id="custom-guidelines">Custom Guidelines<a class="anchor" aria-label="anchor" href="#custom-guidelines"></a>
|
||||
</h4>
|
||||
<p>You can also use your own custom guideline. Custom guidelines can be
|
||||
set with the <code><a href="../reference/mdro.html">custom_mdro_guideline()</a></code> function. This is of
|
||||
great importance if you have custom rules to determine MDROs in your
|
||||
hospital, e.g., rules that are dependent on ward, state of contact
|
||||
isolation or other variables in your data.</p>
|
||||
<p>If you are familiar with <code><a href="https://dplyr.tidyverse.org/reference/case_when.html" class="external-link">case_when()</a></code> of the
|
||||
<code>dplyr</code> package, you will recognise the input method to set
|
||||
your own rules. Rules must be set using what R considers to be the
|
||||
‘formula notation’:</p>
|
||||
<div class="sourceCode" id="cb1"><pre class="downlit sourceCode r">
|
||||
<code class="sourceCode R"><span><span class="va">custom</span> <span class="op"><-</span> <span class="fu"><a href="../reference/mdro.html">custom_mdro_guideline</a></span><span class="op">(</span></span>
|
||||
<span> <span class="va">CIP</span> <span class="op">==</span> <span class="st">"R"</span> <span class="op">&</span> <span class="va">age</span> <span class="op">></span> <span class="fl">60</span> <span class="op">~</span> <span class="st">"Elderly Type A"</span>,</span>
|
||||
<span> <span class="va">ERY</span> <span class="op">==</span> <span class="st">"R"</span> <span class="op">&</span> <span class="va">age</span> <span class="op">></span> <span class="fl">60</span> <span class="op">~</span> <span class="st">"Elderly Type B"</span></span>
|
||||
<span><span class="op">)</span></span></code></pre></div>
|
||||
<p>If a row/an isolate matches the first rule, the value after the first
|
||||
<code>~</code> (in this case <em>‘Elderly Type A’</em>) will be set as
|
||||
MDRO value. Otherwise, the second rule will be tried and so on. The
|
||||
maximum number of rules is unlimited.</p>
|
||||
<p>You can print the rules set in the console for an overview. Colours
|
||||
will help reading it if your console supports colours.</p>
|
||||
<div class="sourceCode" id="cb2"><pre class="downlit sourceCode r">
|
||||
<code class="sourceCode R"><span><span class="va">custom</span></span>
|
||||
<span><span class="co">#> A set of custom MDRO rules:</span></span>
|
||||
<span><span class="co">#> 1. If CIP is "R" and age is higher than 60 then: Elderly Type A</span></span>
|
||||
<span><span class="co">#> 2. If ERY is "R" and age is higher than 60 then: Elderly Type B</span></span>
|
||||
<span><span class="co">#> 3. Otherwise: Negative</span></span>
|
||||
<span><span class="co">#> </span></span>
|
||||
<span><span class="co">#> Unmatched rows will return NA.</span></span>
|
||||
<span><span class="co">#> Results will be of class 'factor', with ordered levels: Negative < Elderly Type A < Elderly Type B</span></span></code></pre></div>
|
||||
<p>The outcome of the function can be used for the
|
||||
<code>guideline</code> argument in the <code><a href="../reference/mdro.html">mdro()</a></code> function:</p>
|
||||
<div class="sourceCode" id="cb3"><pre class="downlit sourceCode r">
|
||||
<code class="sourceCode R"><span><span class="va">x</span> <span class="op"><-</span> <span class="fu"><a href="../reference/mdro.html">mdro</a></span><span class="op">(</span><span class="va">example_isolates</span>, guideline <span class="op">=</span> <span class="va">custom</span><span class="op">)</span></span>
|
||||
<span><span class="fu"><a href="https://rdrr.io/r/base/table.html" class="external-link">table</a></span><span class="op">(</span><span class="va">x</span><span class="op">)</span></span>
|
||||
<span><span class="co">#> x</span></span>
|
||||
<span><span class="co">#> Negative Elderly Type A Elderly Type B </span></span>
|
||||
<span><span class="co">#> 1070 198 732</span></span></code></pre></div>
|
||||
<p>The rules set (the <code>custom</code> object in this case) could be
|
||||
exported to a shared file location using <code><a href="https://rdrr.io/r/base/readRDS.html" class="external-link">saveRDS()</a></code> if you
|
||||
collaborate with multiple users. The custom rules set could then be
|
||||
imported using <code><a href="https://rdrr.io/r/base/readRDS.html" class="external-link">readRDS()</a></code>.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section level3">
|
||||
<h3 id="examples">Examples<a class="anchor" aria-label="anchor" href="#examples"></a>
|
||||
</h3>
|
||||
<p>The <code><a href="../reference/mdro.html">mdro()</a></code> function always returns an ordered
|
||||
<code>factor</code> for predefined guidelines. For example, the output
|
||||
of the default guideline by Magiorakos <em>et al.</em> returns a
|
||||
<code>factor</code> with levels ‘Negative’, ‘MDR’, ‘XDR’ or ‘PDR’ in
|
||||
that order.</p>
|
||||
<p>The next example uses the <code>example_isolates</code> data set.
|
||||
This is a data set included with this package and contains full
|
||||
antibiograms of 2,000 microbial isolates. It reflects reality and can be
|
||||
used to practise AMR data analysis. If we test the MDR/XDR/PDR guideline
|
||||
on this data set, we get:</p>
|
||||
<div class="sourceCode" id="cb4"><pre class="downlit sourceCode r">
|
||||
<code class="sourceCode R"><span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://dplyr.tidyverse.org" class="external-link">dplyr</a></span><span class="op">)</span> <span class="co"># to support pipes: %>%</span></span>
|
||||
<span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://msberends.github.io/cleaner/" class="external-link">cleaner</a></span><span class="op">)</span> <span class="co"># to create frequency tables</span></span></code></pre></div>
|
||||
<div class="sourceCode" id="cb5"><pre class="downlit sourceCode r">
|
||||
<code class="sourceCode R"><span><span class="va">example_isolates</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%>%</a></span></span>
|
||||
<span> <span class="fu"><a href="../reference/mdro.html">mdro</a></span><span class="op">(</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%>%</a></span></span>
|
||||
<span> <span class="fu"><a href="https://msberends.github.io/cleaner/reference/freq.html" class="external-link">freq</a></span><span class="op">(</span><span class="op">)</span> <span class="co"># show frequency table of the result</span></span>
|
||||
<span><span class="co">#> Warning: in mdro(): NA introduced for isolates where the available percentage of</span></span>
|
||||
<span><span class="co">#> antimicrobial classes was below 50% (set with pct_required_classes)</span></span></code></pre></div>
|
||||
<p>(16 isolates had no test results)</p>
|
||||
<p><strong>Frequency table</strong></p>
|
||||
<p>Class: factor > ordered (numeric)<br>
|
||||
Length: 2,000<br>
|
||||
Levels: 4: Negative < Multi-drug-resistant (MDR) < Extensively
|
||||
drug-resistant …<br>
|
||||
Available: 1,729 (86.45%, NA: 271 = 13.55%)<br>
|
||||
Unique: 2</p>
|
||||
<table style="width:100%;" class="table">
|
||||
<colgroup>
|
||||
<col width="4%">
|
||||
<col width="38%">
|
||||
<col width="9%">
|
||||
<col width="12%">
|
||||
<col width="16%">
|
||||
<col width="19%">
|
||||
</colgroup>
|
||||
<thead><tr class="header">
|
||||
<th align="left"></th>
|
||||
<th align="left">Item</th>
|
||||
<th align="right">Count</th>
|
||||
<th align="right">Percent</th>
|
||||
<th align="right">Cum. Count</th>
|
||||
<th align="right">Cum. Percent</th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<tr class="odd">
|
||||
<td align="left">1</td>
|
||||
<td align="left">Negative</td>
|
||||
<td align="right">1601</td>
|
||||
<td align="right">92.6%</td>
|
||||
<td align="right">1601</td>
|
||||
<td align="right">92.6%</td>
|
||||
</tr>
|
||||
<tr class="even">
|
||||
<td align="left">2</td>
|
||||
<td align="left">Multi-drug-resistant (MDR)</td>
|
||||
<td align="right">128</td>
|
||||
<td align="right">7.4%</td>
|
||||
<td align="right">1729</td>
|
||||
<td align="right">100.0%</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p>For another example, I will create a data set to determine multi-drug
|
||||
resistant TB:</p>
|
||||
<div class="sourceCode" id="cb6"><pre class="downlit sourceCode r">
|
||||
<code class="sourceCode R"><span><span class="co"># random_sir() is a helper function to generate</span></span>
|
||||
<span><span class="co"># a random vector with values S, I and R</span></span>
|
||||
<span><span class="va">my_TB_data</span> <span class="op"><-</span> <span class="fu"><a href="https://rdrr.io/r/base/data.frame.html" class="external-link">data.frame</a></span><span class="op">(</span></span>
|
||||
<span> rifampicin <span class="op">=</span> <span class="fu"><a href="../reference/random.html">random_sir</a></span><span class="op">(</span><span class="fl">5000</span><span class="op">)</span>,</span>
|
||||
<span> isoniazid <span class="op">=</span> <span class="fu"><a href="../reference/random.html">random_sir</a></span><span class="op">(</span><span class="fl">5000</span><span class="op">)</span>,</span>
|
||||
<span> gatifloxacin <span class="op">=</span> <span class="fu"><a href="../reference/random.html">random_sir</a></span><span class="op">(</span><span class="fl">5000</span><span class="op">)</span>,</span>
|
||||
<span> ethambutol <span class="op">=</span> <span class="fu"><a href="../reference/random.html">random_sir</a></span><span class="op">(</span><span class="fl">5000</span><span class="op">)</span>,</span>
|
||||
<span> pyrazinamide <span class="op">=</span> <span class="fu"><a href="../reference/random.html">random_sir</a></span><span class="op">(</span><span class="fl">5000</span><span class="op">)</span>,</span>
|
||||
<span> moxifloxacin <span class="op">=</span> <span class="fu"><a href="../reference/random.html">random_sir</a></span><span class="op">(</span><span class="fl">5000</span><span class="op">)</span>,</span>
|
||||
<span> kanamycin <span class="op">=</span> <span class="fu"><a href="../reference/random.html">random_sir</a></span><span class="op">(</span><span class="fl">5000</span><span class="op">)</span></span>
|
||||
<span><span class="op">)</span></span></code></pre></div>
|
||||
<p>Because all column names are automatically verified for valid drug
|
||||
names or codes, this would have worked exactly the same way:</p>
|
||||
<div class="sourceCode" id="cb7"><pre class="downlit sourceCode r">
|
||||
<code class="sourceCode R"><span><span class="va">my_TB_data</span> <span class="op"><-</span> <span class="fu"><a href="https://rdrr.io/r/base/data.frame.html" class="external-link">data.frame</a></span><span class="op">(</span></span>
|
||||
<span> RIF <span class="op">=</span> <span class="fu"><a href="../reference/random.html">random_sir</a></span><span class="op">(</span><span class="fl">5000</span><span class="op">)</span>,</span>
|
||||
<span> INH <span class="op">=</span> <span class="fu"><a href="../reference/random.html">random_sir</a></span><span class="op">(</span><span class="fl">5000</span><span class="op">)</span>,</span>
|
||||
<span> GAT <span class="op">=</span> <span class="fu"><a href="../reference/random.html">random_sir</a></span><span class="op">(</span><span class="fl">5000</span><span class="op">)</span>,</span>
|
||||
<span> ETH <span class="op">=</span> <span class="fu"><a href="../reference/random.html">random_sir</a></span><span class="op">(</span><span class="fl">5000</span><span class="op">)</span>,</span>
|
||||
<span> PZA <span class="op">=</span> <span class="fu"><a href="../reference/random.html">random_sir</a></span><span class="op">(</span><span class="fl">5000</span><span class="op">)</span>,</span>
|
||||
<span> MFX <span class="op">=</span> <span class="fu"><a href="../reference/random.html">random_sir</a></span><span class="op">(</span><span class="fl">5000</span><span class="op">)</span>,</span>
|
||||
<span> KAN <span class="op">=</span> <span class="fu"><a href="../reference/random.html">random_sir</a></span><span class="op">(</span><span class="fl">5000</span><span class="op">)</span></span>
|
||||
<span><span class="op">)</span></span></code></pre></div>
|
||||
<p>The data set now looks like this:</p>
|
||||
<div class="sourceCode" id="cb8"><pre class="downlit sourceCode r">
|
||||
<code class="sourceCode R"><span><span class="fu"><a href="https://rdrr.io/r/utils/head.html" class="external-link">head</a></span><span class="op">(</span><span class="va">my_TB_data</span><span class="op">)</span></span>
|
||||
<span><span class="co">#> rifampicin isoniazid gatifloxacin ethambutol pyrazinamide moxifloxacin</span></span>
|
||||
<span><span class="co">#> 1 R S S S I S</span></span>
|
||||
<span><span class="co">#> 2 I R S R I S</span></span>
|
||||
<span><span class="co">#> 3 I R R I S R</span></span>
|
||||
<span><span class="co">#> 4 R R S R S I</span></span>
|
||||
<span><span class="co">#> 5 S S S S I S</span></span>
|
||||
<span><span class="co">#> 6 R I I S S I</span></span>
|
||||
<span><span class="co">#> kanamycin</span></span>
|
||||
<span><span class="co">#> 1 I</span></span>
|
||||
<span><span class="co">#> 2 I</span></span>
|
||||
<span><span class="co">#> 3 S</span></span>
|
||||
<span><span class="co">#> 4 S</span></span>
|
||||
<span><span class="co">#> 5 S</span></span>
|
||||
<span><span class="co">#> 6 I</span></span></code></pre></div>
|
||||
<p>We can now add the interpretation of MDR-TB to our data set. You can
|
||||
use:</p>
|
||||
<div class="sourceCode" id="cb9"><pre class="downlit sourceCode r">
|
||||
<code class="sourceCode R"><span><span class="fu"><a href="../reference/mdro.html">mdro</a></span><span class="op">(</span><span class="va">my_TB_data</span>, guideline <span class="op">=</span> <span class="st">"TB"</span><span class="op">)</span></span></code></pre></div>
|
||||
<p>or its shortcut <code><a href="../reference/mdro.html">mdr_tb()</a></code>:</p>
|
||||
<div class="sourceCode" id="cb10"><pre class="downlit sourceCode r">
|
||||
<code class="sourceCode R"><span><span class="va">my_TB_data</span><span class="op">$</span><span class="va">mdr</span> <span class="op"><-</span> <span class="fu"><a href="../reference/mdro.html">mdr_tb</a></span><span class="op">(</span><span class="va">my_TB_data</span><span class="op">)</span></span>
|
||||
<span><span class="co">#> ℹ No column found as input for col_mo, assuming all rows contain</span></span>
|
||||
<span><span class="co">#> Mycobacterium tuberculosis.</span></span></code></pre></div>
|
||||
<p>Create a frequency table of the results:</p>
|
||||
<div class="sourceCode" id="cb11"><pre class="downlit sourceCode r">
|
||||
<code class="sourceCode R"><span><span class="fu"><a href="https://msberends.github.io/cleaner/reference/freq.html" class="external-link">freq</a></span><span class="op">(</span><span class="va">my_TB_data</span><span class="op">$</span><span class="va">mdr</span><span class="op">)</span></span></code></pre></div>
|
||||
<p><strong>Frequency table</strong></p>
|
||||
<p>Class: factor > ordered (numeric)<br>
|
||||
Length: 5,000<br>
|
||||
Levels: 5: Negative < Mono-resistant < Poly-resistant <
|
||||
Multi-drug-resistant <…<br>
|
||||
Available: 5,000 (100%, NA: 0 = 0%)<br>
|
||||
Unique: 5</p>
|
||||
<table style="width:100%;" class="table">
|
||||
<colgroup>
|
||||
<col width="4%">
|
||||
<col width="38%">
|
||||
<col width="9%">
|
||||
<col width="12%">
|
||||
<col width="16%">
|
||||
<col width="19%">
|
||||
</colgroup>
|
||||
<thead><tr class="header">
|
||||
<th align="left"></th>
|
||||
<th align="left">Item</th>
|
||||
<th align="right">Count</th>
|
||||
<th align="right">Percent</th>
|
||||
<th align="right">Cum. Count</th>
|
||||
<th align="right">Cum. Percent</th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<tr class="odd">
|
||||
<td align="left">1</td>
|
||||
<td align="left">Mono-resistant</td>
|
||||
<td align="right">3221</td>
|
||||
<td align="right">64.42%</td>
|
||||
<td align="right">3221</td>
|
||||
<td align="right">64.42%</td>
|
||||
</tr>
|
||||
<tr class="even">
|
||||
<td align="left">2</td>
|
||||
<td align="left">Negative</td>
|
||||
<td align="right">985</td>
|
||||
<td align="right">19.70%</td>
|
||||
<td align="right">4206</td>
|
||||
<td align="right">84.12%</td>
|
||||
</tr>
|
||||
<tr class="odd">
|
||||
<td align="left">3</td>
|
||||
<td align="left">Multi-drug-resistant</td>
|
||||
<td align="right">437</td>
|
||||
<td align="right">8.74%</td>
|
||||
<td align="right">4643</td>
|
||||
<td align="right">92.86%</td>
|
||||
</tr>
|
||||
<tr class="even">
|
||||
<td align="left">4</td>
|
||||
<td align="left">Poly-resistant</td>
|
||||
<td align="right">252</td>
|
||||
<td align="right">5.04%</td>
|
||||
<td align="right">4895</td>
|
||||
<td align="right">97.90%</td>
|
||||
</tr>
|
||||
<tr class="odd">
|
||||
<td align="left">5</td>
|
||||
<td align="left">Extensively drug-resistant</td>
|
||||
<td align="right">105</td>
|
||||
<td align="right">2.10%</td>
|
||||
<td align="right">5000</td>
|
||||
<td align="right">100.00%</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</main><aside class="col-md-3"><nav id="toc"><h2>On this page</h2>
|
||||
</nav></aside>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<footer><div class="pkgdown-footer-left">
|
||||
<p></p>
|
||||
<p><code>AMR</code> (for R). Free and open-source, licenced under the <a target="_blank" href="https://github.com/msberends/AMR/blob/main/LICENSE" class="external-link">GNU General Public License version 2.0 (GPL-2)</a>.<br>Developed at the <a target="_blank" href="https://www.rug.nl" class="external-link">University of Groningen</a> and <a target="_blank" href="https://www.umcg.nl" class="external-link">University Medical Center Groningen</a> in The Netherlands.</p>
|
||||
</div>
|
||||
|
||||
<div class="pkgdown-footer-right">
|
||||
<p></p>
|
||||
<p><a target="_blank" href="https://www.rug.nl" class="external-link"><img src="https://github.com/msberends/AMR/raw/main/pkgdown/logos/logo_rug.svg" style="max-width: 150px;"></a><a target="_blank" href="https://www.umcg.nl" class="external-link"><img src="https://github.com/msberends/AMR/raw/main/pkgdown/logos/logo_umcg.svg" style="max-width: 150px;"></a></p>
|
||||
</div>
|
||||
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,346 @@
|
||||
<!DOCTYPE html>
|
||||
<!-- Generated by pkgdown: do not edit by hand --><html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<meta name="description" content="AMR">
|
||||
<title>How to conduct principal component analysis (PCA) for AMR • AMR (for R)</title>
|
||||
<!-- favicons --><link rel="icon" type="image/png" sizes="16x16" href="../favicon-16x16.png">
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="../favicon-32x32.png">
|
||||
<link rel="apple-touch-icon" type="image/png" sizes="180x180" href="../apple-touch-icon.png">
|
||||
<link rel="apple-touch-icon" type="image/png" sizes="120x120" href="../apple-touch-icon-120x120.png">
|
||||
<link rel="apple-touch-icon" type="image/png" sizes="76x76" href="../apple-touch-icon-76x76.png">
|
||||
<link rel="apple-touch-icon" type="image/png" sizes="60x60" href="../apple-touch-icon-60x60.png">
|
||||
<script src="../deps/jquery-3.6.0/jquery-3.6.0.min.js"></script><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<link href="../deps/bootstrap-5.2.2/bootstrap.min.css" rel="stylesheet">
|
||||
<script src="../deps/bootstrap-5.2.2/bootstrap.bundle.min.js"></script><link href="../deps/Fira_Code-0.4.5/font.css" rel="stylesheet">
|
||||
<!-- Font Awesome icons --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css" integrity="sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk=" crossorigin="anonymous">
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/v4-shims.min.css" integrity="sha256-wZjR52fzng1pJHwx4aV2AO3yyTOXrcDW7jBpJtTwVxw=" crossorigin="anonymous">
|
||||
<!-- bootstrap-toc --><script src="https://cdn.jsdelivr.net/gh/afeld/bootstrap-toc@v1.0.1/dist/bootstrap-toc.min.js" integrity="sha256-4veVQbu7//Lk5TSmc7YV48MxtMy98e26cf5MrgZYnwo=" crossorigin="anonymous"></script><!-- headroom.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/headroom.min.js" integrity="sha256-AsUX4SJE1+yuDu5+mAVzJbuYNPHj/WroHuZ8Ir/CkE0=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/jQuery.headroom.min.js" integrity="sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4=" crossorigin="anonymous"></script><!-- clipboard.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js" integrity="sha256-inc5kl9MA1hkeYUt+EC3BhlIgyp/2jDIyBLS6k3UxPI=" crossorigin="anonymous"></script><!-- search --><script src="https://cdnjs.cloudflare.com/ajax/libs/fuse.js/6.4.6/fuse.js" integrity="sha512-zv6Ywkjyktsohkbp9bb45V6tEMoWhzFzXis+LrMehmJZZSys19Yxf1dopHx7WzIKxr5tK2dVcYmaCk2uqdjF4A==" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/autocomplete.js/0.38.0/autocomplete.jquery.min.js" integrity="sha512-GU9ayf+66Xx2TmpxqJpliWbT5PiGYxpaG8rfnBEk1LL8l1KGkRShhngwdXK1UgqhAzWpZHSiYPc09/NwDQIGyg==" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mark.js/8.11.1/mark.min.js" integrity="sha512-5CYOlHXGh6QpOFA/TeTylKLWfB3ftPsde7AnmhuitiTX4K5SqCLBeKro6sPS8ilsz1Q4NRx3v8Ko2IBiszzdww==" crossorigin="anonymous"></script><!-- pkgdown --><script src="../pkgdown.js"></script><link href="../extra.css" rel="stylesheet">
|
||||
<script src="../extra.js"></script><meta property="og:title" content="How to conduct principal component analysis (PCA) for AMR">
|
||||
<meta property="og:description" content="AMR">
|
||||
<meta property="og:image" content="https://msberends.github.io/AMR/logo.svg">
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
<meta name="twitter:creator" content="@msberends">
|
||||
<meta name="twitter:site" content="@msberends">
|
||||
<!-- mathjax --><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script><!--[if lt IE 9]>
|
||||
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
|
||||
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
|
||||
<![endif]-->
|
||||
</head>
|
||||
<body>
|
||||
<a href="#main" class="visually-hidden-focusable">Skip to contents</a>
|
||||
|
||||
|
||||
<nav class="navbar fixed-top navbar-dark navbar-expand-lg bg-primary"><div class="container">
|
||||
|
||||
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
|
||||
|
||||
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">1.8.2.9139</small>
|
||||
|
||||
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<div id="navbar" class="collapse navbar-collapse ms-3">
|
||||
<ul class="navbar-nav me-auto">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="../index.html">
|
||||
<span class="fa fa-home"></span>
|
||||
|
||||
Home
|
||||
</a>
|
||||
</li>
|
||||
<li class="active nav-item dropdown">
|
||||
<a href="#" class="nav-link dropdown-toggle" data-bs-toggle="dropdown" role="button" aria-expanded="false" aria-haspopup="true" id="dropdown--how-to">
|
||||
<span class="fa fa-question-circle"></span>
|
||||
|
||||
How to
|
||||
</a>
|
||||
<div class="dropdown-menu" aria-labelledby="dropdown--how-to">
|
||||
<a class="dropdown-item" href="../reference/AMR-options.html">
|
||||
<span class="fa fa-gear"></span>
|
||||
|
||||
User- Or Team-specific Package Settings
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/AMR.html">
|
||||
<span class="fa fa-directions"></span>
|
||||
|
||||
Conduct AMR Analysis
|
||||
</a>
|
||||
<a class="dropdown-item" href="../reference/antibiogram.html">
|
||||
<span class="fa fa-file-prescription"></span>
|
||||
|
||||
Generate Antibiogram (Trad./Syndromic/WISCA)
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/resistance_predict.html">
|
||||
<span class="fa fa-dice"></span>
|
||||
|
||||
Predict Antimicrobial Resistance
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/datasets.html">
|
||||
<span class="fa fa-database"></span>
|
||||
|
||||
Data Sets for Download / Own Use
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/PCA.html">
|
||||
<span class="fa fa-compress"></span>
|
||||
|
||||
Conduct Principal Component Analysis for AMR
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/MDR.html">
|
||||
<span class="fa fa-skull-crossbones"></span>
|
||||
|
||||
Determine Multi-Drug Resistance (MDR)
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/WHONET.html">
|
||||
<span class="fa fa-globe-americas"></span>
|
||||
|
||||
Work with WHONET Data
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/SPSS.html">
|
||||
<span class="fa fa-file-upload"></span>
|
||||
|
||||
Import Data From SPSS/SAS/Stata
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/EUCAST.html">
|
||||
<span class="fa fa-exchange-alt"></span>
|
||||
|
||||
Apply Eucast Rules
|
||||
</a>
|
||||
<a class="dropdown-item" href="../reference/mo_property.html">
|
||||
<span class="fa fa-bug"></span>
|
||||
|
||||
Get Taxonomy of a Microorganism
|
||||
</a>
|
||||
<a class="dropdown-item" href="../reference/ab_property.html">
|
||||
<span class="fa fa-capsules"></span>
|
||||
|
||||
Get Properties of an Antibiotic Drug
|
||||
</a>
|
||||
<a class="dropdown-item" href="../reference/av_property.html">
|
||||
<span class="fa fa-capsules"></span>
|
||||
|
||||
Get Properties of an Antiviral Drug
|
||||
</a>
|
||||
</div>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="../reference/index.html">
|
||||
<span class="fa fa-book-open"></span>
|
||||
|
||||
Manual
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="../authors.html">
|
||||
<span class="fa fa-users"></span>
|
||||
|
||||
Authors
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="../news/index.html">
|
||||
<span class="far fa far fa-newspaper"></span>
|
||||
|
||||
Changelog
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
<form class="form-inline my-2 my-lg-0" role="search">
|
||||
<input type="search" class="form-control me-sm-2" aria-label="Toggle navigation" name="search-input" data-search-index="../search.json" id="search-input" placeholder="Search for" autocomplete="off">
|
||||
</form>
|
||||
|
||||
<ul class="navbar-nav">
|
||||
<li class="nav-item">
|
||||
<a class="external-link nav-link" href="https://github.com/msberends/AMR">
|
||||
<span class="fab fa fab fa-github"></span>
|
||||
|
||||
Source Code
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</nav><div class="container template-article">
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="row">
|
||||
<main id="main" class="col-md-9"><div class="page-header">
|
||||
<img src="../logo.svg" class="logo" alt=""><h1>How to conduct principal component analysis (PCA) for AMR</h1>
|
||||
|
||||
|
||||
<small class="dont-index">Source: <a href="https://github.com/msberends/AMR/blob/HEAD/vignettes/PCA.Rmd" class="external-link"><code>vignettes/PCA.Rmd</code></a></small>
|
||||
<div class="d-none name"><code>PCA.Rmd</code></div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<p><strong>NOTE: This page will be updated soon, as the pca() function
|
||||
is currently being developed.</strong></p>
|
||||
<div class="section level2">
|
||||
<h2 id="introduction">Introduction<a class="anchor" aria-label="anchor" href="#introduction"></a>
|
||||
</h2>
|
||||
</div>
|
||||
<div class="section level2">
|
||||
<h2 id="transforming">Transforming<a class="anchor" aria-label="anchor" href="#transforming"></a>
|
||||
</h2>
|
||||
<p>For PCA, we need to transform our AMR data first. This is what the
|
||||
<code>example_isolates</code> data set in this package looks like:</p>
|
||||
<div class="sourceCode" id="cb1"><pre class="downlit sourceCode r">
|
||||
<code class="sourceCode R"><span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://msberends.github.io/AMR/">AMR</a></span><span class="op">)</span></span>
|
||||
<span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://dplyr.tidyverse.org" class="external-link">dplyr</a></span><span class="op">)</span></span>
|
||||
<span><span class="fu"><a href="https://pillar.r-lib.org/reference/glimpse.html" class="external-link">glimpse</a></span><span class="op">(</span><span class="va">example_isolates</span><span class="op">)</span></span>
|
||||
<span><span class="co">#> Rows: 2,000</span></span>
|
||||
<span><span class="co">#> Columns: 46</span></span>
|
||||
<span><span class="co">#> $ date <span style="color: #949494; font-style: italic;"><date></span> 2002-01-02, 2002-01-03, 2002-01-07, 2002-01-07, 2002-01-13, 2…</span></span>
|
||||
<span><span class="co">#> $ patient <span style="color: #949494; font-style: italic;"><chr></span> "A77334", "A77334", "067927", "067927", "067927", "067927", "4…</span></span>
|
||||
<span><span class="co">#> $ age <span style="color: #949494; font-style: italic;"><dbl></span> 65, 65, 45, 45, 45, 45, 78, 78, 45, 79, 67, 67, 71, 71, 75, 50…</span></span>
|
||||
<span><span class="co">#> $ gender <span style="color: #949494; font-style: italic;"><chr></span> "F", "F", "F", "F", "F", "F", "M", "M", "F", "F", "M", "M", "M…</span></span>
|
||||
<span><span class="co">#> $ ward <span style="color: #949494; font-style: italic;"><chr></span> "Clinical", "Clinical", "ICU", "ICU", "ICU", "ICU", "Clinical"…</span></span>
|
||||
<span><span class="co">#> $ mo <span style="color: #949494; font-style: italic;"><mo></span> "B_ESCHR_COLI", "B_ESCHR_COLI", "B_STPHY_EPDR", "B_STPHY_EPDR",…</span></span>
|
||||
<span><span class="co">#> $ PEN <span style="color: #949494; font-style: italic;"><sir></span> R, R, R, R, R, R, R, R, R, R, R, R, R, R, R, R, R, R, R, R, S,…</span></span>
|
||||
<span><span class="co">#> $ OXA <span style="color: #949494; font-style: italic;"><sir></span> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA…</span></span>
|
||||
<span><span class="co">#> $ FLC <span style="color: #949494; font-style: italic;"><sir></span> NA, NA, R, R, R, R, S, S, R, S, S, S, NA, NA, NA, NA, NA, R, R…</span></span>
|
||||
<span><span class="co">#> $ AMX <span style="color: #949494; font-style: italic;"><sir></span> NA, NA, NA, NA, NA, NA, R, R, NA, NA, NA, NA, NA, NA, R, NA, N…</span></span>
|
||||
<span><span class="co">#> $ AMC <span style="color: #949494; font-style: italic;"><sir></span> I, I, NA, NA, NA, NA, S, S, NA, NA, S, S, I, I, R, I, I, NA, N…</span></span>
|
||||
<span><span class="co">#> $ AMP <span style="color: #949494; font-style: italic;"><sir></span> NA, NA, NA, NA, NA, NA, R, R, NA, NA, NA, NA, NA, NA, R, NA, N…</span></span>
|
||||
<span><span class="co">#> $ TZP <span style="color: #949494; font-style: italic;"><sir></span> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA…</span></span>
|
||||
<span><span class="co">#> $ CZO <span style="color: #949494; font-style: italic;"><sir></span> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, R, NA,…</span></span>
|
||||
<span><span class="co">#> $ FEP <span style="color: #949494; font-style: italic;"><sir></span> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA…</span></span>
|
||||
<span><span class="co">#> $ CXM <span style="color: #949494; font-style: italic;"><sir></span> I, I, R, R, R, R, S, S, R, S, S, S, S, S, NA, S, S, R, R, S, S…</span></span>
|
||||
<span><span class="co">#> $ FOX <span style="color: #949494; font-style: italic;"><sir></span> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, R, NA,…</span></span>
|
||||
<span><span class="co">#> $ CTX <span style="color: #949494; font-style: italic;"><sir></span> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, S, S, NA, S, S…</span></span>
|
||||
<span><span class="co">#> $ CAZ <span style="color: #949494; font-style: italic;"><sir></span> NA, NA, R, R, R, R, R, R, R, R, R, R, NA, NA, NA, S, S, R, R, …</span></span>
|
||||
<span><span class="co">#> $ CRO <span style="color: #949494; font-style: italic;"><sir></span> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, S, S, NA, S, S…</span></span>
|
||||
<span><span class="co">#> $ GEN <span style="color: #949494; font-style: italic;"><sir></span> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA…</span></span>
|
||||
<span><span class="co">#> $ TOB <span style="color: #949494; font-style: italic;"><sir></span> NA, NA, NA, NA, NA, NA, S, S, NA, NA, NA, NA, S, S, NA, NA, NA…</span></span>
|
||||
<span><span class="co">#> $ AMK <span style="color: #949494; font-style: italic;"><sir></span> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA…</span></span>
|
||||
<span><span class="co">#> $ KAN <span style="color: #949494; font-style: italic;"><sir></span> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA…</span></span>
|
||||
<span><span class="co">#> $ TMP <span style="color: #949494; font-style: italic;"><sir></span> R, R, S, S, R, R, R, R, S, S, NA, NA, S, S, S, S, S, R, R, R, …</span></span>
|
||||
<span><span class="co">#> $ SXT <span style="color: #949494; font-style: italic;"><sir></span> R, R, S, S, NA, NA, NA, NA, S, S, NA, NA, S, S, S, S, S, NA, N…</span></span>
|
||||
<span><span class="co">#> $ NIT <span style="color: #949494; font-style: italic;"><sir></span> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, R,…</span></span>
|
||||
<span><span class="co">#> $ FOS <span style="color: #949494; font-style: italic;"><sir></span> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA…</span></span>
|
||||
<span><span class="co">#> $ LNZ <span style="color: #949494; font-style: italic;"><sir></span> R, R, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, R, R, R, R, R, N…</span></span>
|
||||
<span><span class="co">#> $ CIP <span style="color: #949494; font-style: italic;"><sir></span> NA, NA, NA, NA, NA, NA, NA, NA, S, S, NA, NA, NA, NA, NA, S, S…</span></span>
|
||||
<span><span class="co">#> $ MFX <span style="color: #949494; font-style: italic;"><sir></span> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA…</span></span>
|
||||
<span><span class="co">#> $ VAN <span style="color: #949494; font-style: italic;"><sir></span> R, R, S, S, S, S, S, S, S, S, NA, NA, R, R, R, R, R, S, S, S, …</span></span>
|
||||
<span><span class="co">#> $ TEC <span style="color: #949494; font-style: italic;"><sir></span> R, R, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, R, R, R, R, R, N…</span></span>
|
||||
<span><span class="co">#> $ TCY <span style="color: #949494; font-style: italic;"><sir></span> R, R, S, S, S, S, S, S, S, I, S, S, NA, NA, I, R, R, S, I, R, …</span></span>
|
||||
<span><span class="co">#> $ TGC <span style="color: #949494; font-style: italic;"><sir></span> NA, NA, S, S, S, S, S, S, S, NA, S, S, NA, NA, NA, R, R, S, NA…</span></span>
|
||||
<span><span class="co">#> $ DOX <span style="color: #949494; font-style: italic;"><sir></span> NA, NA, S, S, S, S, S, S, S, NA, S, S, NA, NA, NA, R, R, S, NA…</span></span>
|
||||
<span><span class="co">#> $ ERY <span style="color: #949494; font-style: italic;"><sir></span> R, R, R, R, R, R, S, S, R, S, S, S, R, R, R, R, R, R, R, R, S,…</span></span>
|
||||
<span><span class="co">#> $ CLI <span style="color: #949494; font-style: italic;"><sir></span> R, R, NA, NA, NA, R, NA, NA, NA, NA, NA, NA, R, R, R, R, R, NA…</span></span>
|
||||
<span><span class="co">#> $ AZM <span style="color: #949494; font-style: italic;"><sir></span> R, R, R, R, R, R, S, S, R, S, S, S, R, R, R, R, R, R, R, R, S,…</span></span>
|
||||
<span><span class="co">#> $ IPM <span style="color: #949494; font-style: italic;"><sir></span> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, S, S, NA, S, S…</span></span>
|
||||
<span><span class="co">#> $ MEM <span style="color: #949494; font-style: italic;"><sir></span> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA…</span></span>
|
||||
<span><span class="co">#> $ MTR <span style="color: #949494; font-style: italic;"><sir></span> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA…</span></span>
|
||||
<span><span class="co">#> $ CHL <span style="color: #949494; font-style: italic;"><sir></span> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA…</span></span>
|
||||
<span><span class="co">#> $ COL <span style="color: #949494; font-style: italic;"><sir></span> NA, NA, R, R, R, R, R, R, R, R, R, R, NA, NA, NA, R, R, R, R, …</span></span>
|
||||
<span><span class="co">#> $ MUP <span style="color: #949494; font-style: italic;"><sir></span> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA…</span></span>
|
||||
<span><span class="co">#> $ RIF <span style="color: #949494; font-style: italic;"><sir></span> R, R, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, R, R, R, R, R, N…</span></span></code></pre></div>
|
||||
<p>Now to transform this to a data set with only resistance percentages
|
||||
per taxonomic order and genus:</p>
|
||||
<div class="sourceCode" id="cb2"><pre class="downlit sourceCode r">
|
||||
<code class="sourceCode R"><span><span class="va">resistance_data</span> <span class="op"><-</span> <span class="va">example_isolates</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%>%</a></span></span>
|
||||
<span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/group_by.html" class="external-link">group_by</a></span><span class="op">(</span></span>
|
||||
<span> order <span class="op">=</span> <span class="fu"><a href="../reference/mo_property.html">mo_order</a></span><span class="op">(</span><span class="va">mo</span><span class="op">)</span>, <span class="co"># group on anything, like order</span></span>
|
||||
<span> genus <span class="op">=</span> <span class="fu"><a href="../reference/mo_property.html">mo_genus</a></span><span class="op">(</span><span class="va">mo</span><span class="op">)</span></span>
|
||||
<span> <span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%>%</a></span> <span class="co"># and genus as we do here</span></span>
|
||||
<span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/summarise_all.html" class="external-link">summarise_if</a></span><span class="op">(</span><span class="va">is.sir</span>, <span class="va">resistance</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%>%</a></span> <span class="co"># then get resistance of all drugs</span></span>
|
||||
<span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/select.html" class="external-link">select</a></span><span class="op">(</span></span>
|
||||
<span> <span class="va">order</span>, <span class="va">genus</span>, <span class="va">AMC</span>, <span class="va">CXM</span>, <span class="va">CTX</span>,</span>
|
||||
<span> <span class="va">CAZ</span>, <span class="va">GEN</span>, <span class="va">TOB</span>, <span class="va">TMP</span>, <span class="va">SXT</span></span>
|
||||
<span> <span class="op">)</span> <span class="co"># and select only relevant columns</span></span>
|
||||
<span></span>
|
||||
<span><span class="fu"><a href="https://rdrr.io/r/utils/head.html" class="external-link">head</a></span><span class="op">(</span><span class="va">resistance_data</span><span class="op">)</span></span>
|
||||
<span><span class="co">#> <span style="color: #949494;"># A tibble: 6 × 10</span></span></span>
|
||||
<span><span class="co">#> <span style="color: #949494;"># Groups: order [5]</span></span></span>
|
||||
<span><span class="co">#> order genus AMC CXM CTX CAZ GEN TOB TMP SXT</span></span>
|
||||
<span><span class="co">#> <span style="color: #949494; font-style: italic;"><chr></span> <span style="color: #949494; font-style: italic;"><chr></span> <span style="color: #949494; font-style: italic;"><dbl></span> <span style="color: #949494; font-style: italic;"><dbl></span> <span style="color: #949494; font-style: italic;"><dbl></span> <span style="color: #949494; font-style: italic;"><dbl></span> <span style="color: #949494; font-style: italic;"><dbl></span> <span style="color: #949494; font-style: italic;"><dbl></span> <span style="color: #949494; font-style: italic;"><dbl></span> <span style="color: #949494; font-style: italic;"><dbl></span></span></span>
|
||||
<span><span class="co">#> <span style="color: #BCBCBC;">1</span> (unknown order) (unknown ge… <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span></span></span>
|
||||
<span><span class="co">#> <span style="color: #BCBCBC;">2</span> Actinomycetales Schaalia <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span></span></span>
|
||||
<span><span class="co">#> <span style="color: #BCBCBC;">3</span> Bacteroidales Bacteroides <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span></span></span>
|
||||
<span><span class="co">#> <span style="color: #BCBCBC;">4</span> Campylobacterales Campylobact… <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span></span></span>
|
||||
<span><span class="co">#> <span style="color: #BCBCBC;">5</span> Caryophanales Gemella <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span></span></span>
|
||||
<span><span class="co">#> <span style="color: #BCBCBC;">6</span> Caryophanales Listeria <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span></span></span></code></pre></div>
|
||||
</div>
|
||||
<div class="section level2">
|
||||
<h2 id="perform-principal-component-analysis">Perform principal component analysis<a class="anchor" aria-label="anchor" href="#perform-principal-component-analysis"></a>
|
||||
</h2>
|
||||
<p>The new <code><a href="../reference/pca.html">pca()</a></code> function will automatically filter on rows
|
||||
that contain numeric values in all selected variables, so we now only
|
||||
need to do:</p>
|
||||
<div class="sourceCode" id="cb3"><pre class="downlit sourceCode r">
|
||||
<code class="sourceCode R"><span><span class="va">pca_result</span> <span class="op"><-</span> <span class="fu"><a href="../reference/pca.html">pca</a></span><span class="op">(</span><span class="va">resistance_data</span><span class="op">)</span></span>
|
||||
<span><span class="co">#> ℹ Columns selected for PCA: "AMC", "CAZ", "CTX", "CXM", "GEN", "SXT",</span></span>
|
||||
<span><span class="co">#> "TMP", and "TOB". Total observations available: 7.</span></span></code></pre></div>
|
||||
<p>The result can be reviewed with the good old <code><a href="https://rdrr.io/r/base/summary.html" class="external-link">summary()</a></code>
|
||||
function:</p>
|
||||
<div class="sourceCode" id="cb4"><pre class="downlit sourceCode r">
|
||||
<code class="sourceCode R"><span><span class="fu"><a href="https://rdrr.io/r/base/summary.html" class="external-link">summary</a></span><span class="op">(</span><span class="va">pca_result</span><span class="op">)</span></span>
|
||||
<span><span class="co">#> Groups (n=4, named as 'order'):</span></span>
|
||||
<span><span class="co">#> [1] "Caryophanales" "Enterobacterales" "Lactobacillales" "Pseudomonadales"</span></span>
|
||||
<span><span class="co">#> Importance of components:</span></span>
|
||||
<span><span class="co">#> PC1 PC2 PC3 PC4 PC5 PC6 PC7</span></span>
|
||||
<span><span class="co">#> Standard deviation 2.1539 1.6807 0.6138 0.33879 0.20808 0.03140 9.577e-17</span></span>
|
||||
<span><span class="co">#> Proportion of Variance 0.5799 0.3531 0.0471 0.01435 0.00541 0.00012 0.000e+00</span></span>
|
||||
<span><span class="co">#> Cumulative Proportion 0.5799 0.9330 0.9801 0.99446 0.99988 1.00000 1.000e+00</span></span></code></pre></div>
|
||||
<pre><code><span><span class="co">#> Groups (n=4, named as 'order'):</span></span>
|
||||
<span><span class="co">#> [1] "Caryophanales" "Enterobacterales" "Lactobacillales" "Pseudomonadales"</span></span></code></pre>
|
||||
<p>Good news. The first two components explain a total of 93.3% of the
|
||||
variance (see the PC1 and PC2 values of the <em>Proportion of
|
||||
Variance</em>. We can create a so-called biplot with the base R
|
||||
<code><a href="https://rdrr.io/r/stats/biplot.html" class="external-link">biplot()</a></code> function, to see which antimicrobial resistance
|
||||
per drug explain the difference per microorganism.</p>
|
||||
</div>
|
||||
<div class="section level2">
|
||||
<h2 id="plotting-the-results">Plotting the results<a class="anchor" aria-label="anchor" href="#plotting-the-results"></a>
|
||||
</h2>
|
||||
<div class="sourceCode" id="cb6"><pre class="downlit sourceCode r">
|
||||
<code class="sourceCode R"><span><span class="fu"><a href="https://rdrr.io/r/stats/biplot.html" class="external-link">biplot</a></span><span class="op">(</span><span class="va">pca_result</span><span class="op">)</span></span></code></pre></div>
|
||||
<p><img src="PCA_files/figure-html/unnamed-chunk-5-1.png" width="750"></p>
|
||||
<p>But we can’t see the explanation of the points. Perhaps this works
|
||||
better with our new <code><a href="../reference/ggplot_pca.html">ggplot_pca()</a></code> function, that
|
||||
automatically adds the right labels and even groups:</p>
|
||||
<div class="sourceCode" id="cb7"><pre class="downlit sourceCode r">
|
||||
<code class="sourceCode R"><span><span class="fu"><a href="../reference/ggplot_pca.html">ggplot_pca</a></span><span class="op">(</span><span class="va">pca_result</span><span class="op">)</span></span></code></pre></div>
|
||||
<p><img src="PCA_files/figure-html/unnamed-chunk-6-1.png" width="750"></p>
|
||||
<p>You can also print an ellipse per group, and edit the appearance:</p>
|
||||
<div class="sourceCode" id="cb8"><pre class="downlit sourceCode r">
|
||||
<code class="sourceCode R"><span><span class="fu"><a href="../reference/ggplot_pca.html">ggplot_pca</a></span><span class="op">(</span><span class="va">pca_result</span>, ellipse <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span> <span class="op">+</span></span>
|
||||
<span> <span class="fu">ggplot2</span><span class="fu">::</span><span class="fu"><a href="https://ggplot2.tidyverse.org/reference/labs.html" class="external-link">labs</a></span><span class="op">(</span>title <span class="op">=</span> <span class="st">"An AMR/PCA biplot!"</span><span class="op">)</span></span></code></pre></div>
|
||||
<p><img src="PCA_files/figure-html/unnamed-chunk-7-1.png" width="750"></p>
|
||||
</div>
|
||||
</main><aside class="col-md-3"><nav id="toc"><h2>On this page</h2>
|
||||
</nav></aside>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<footer><div class="pkgdown-footer-left">
|
||||
<p></p>
|
||||
<p><code>AMR</code> (for R). Free and open-source, licenced under the <a target="_blank" href="https://github.com/msberends/AMR/blob/main/LICENSE" class="external-link">GNU General Public License version 2.0 (GPL-2)</a>.<br>Developed at the <a target="_blank" href="https://www.rug.nl" class="external-link">University of Groningen</a> and <a target="_blank" href="https://www.umcg.nl" class="external-link">University Medical Center Groningen</a> in The Netherlands.</p>
|
||||
</div>
|
||||
|
||||
<div class="pkgdown-footer-right">
|
||||
<p></p>
|
||||
<p><a target="_blank" href="https://www.rug.nl" class="external-link"><img src="https://github.com/msberends/AMR/raw/main/pkgdown/logos/logo_rug.svg" style="max-width: 150px;"></a><a target="_blank" href="https://www.umcg.nl" class="external-link"><img src="https://github.com/msberends/AMR/raw/main/pkgdown/logos/logo_umcg.svg" style="max-width: 150px;"></a></p>
|
||||
</div>
|
||||
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
After Width: | Height: | Size: 50 KiB |
|
After Width: | Height: | Size: 93 KiB |
|
After Width: | Height: | Size: 93 KiB |
@@ -0,0 +1,512 @@
|
||||
<!DOCTYPE html>
|
||||
<!-- Generated by pkgdown: do not edit by hand --><html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<meta name="description" content="AMR">
|
||||
<title>How to import data from SPSS / SAS / Stata • AMR (for R)</title>
|
||||
<!-- favicons --><link rel="icon" type="image/png" sizes="16x16" href="../favicon-16x16.png">
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="../favicon-32x32.png">
|
||||
<link rel="apple-touch-icon" type="image/png" sizes="180x180" href="../apple-touch-icon.png">
|
||||
<link rel="apple-touch-icon" type="image/png" sizes="120x120" href="../apple-touch-icon-120x120.png">
|
||||
<link rel="apple-touch-icon" type="image/png" sizes="76x76" href="../apple-touch-icon-76x76.png">
|
||||
<link rel="apple-touch-icon" type="image/png" sizes="60x60" href="../apple-touch-icon-60x60.png">
|
||||
<script src="../deps/jquery-3.6.0/jquery-3.6.0.min.js"></script><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<link href="../deps/bootstrap-5.2.2/bootstrap.min.css" rel="stylesheet">
|
||||
<script src="../deps/bootstrap-5.2.2/bootstrap.bundle.min.js"></script><link href="../deps/Fira_Code-0.4.5/font.css" rel="stylesheet">
|
||||
<!-- Font Awesome icons --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css" integrity="sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk=" crossorigin="anonymous">
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/v4-shims.min.css" integrity="sha256-wZjR52fzng1pJHwx4aV2AO3yyTOXrcDW7jBpJtTwVxw=" crossorigin="anonymous">
|
||||
<!-- bootstrap-toc --><script src="https://cdn.jsdelivr.net/gh/afeld/bootstrap-toc@v1.0.1/dist/bootstrap-toc.min.js" integrity="sha256-4veVQbu7//Lk5TSmc7YV48MxtMy98e26cf5MrgZYnwo=" crossorigin="anonymous"></script><!-- headroom.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/headroom.min.js" integrity="sha256-AsUX4SJE1+yuDu5+mAVzJbuYNPHj/WroHuZ8Ir/CkE0=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/jQuery.headroom.min.js" integrity="sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4=" crossorigin="anonymous"></script><!-- clipboard.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js" integrity="sha256-inc5kl9MA1hkeYUt+EC3BhlIgyp/2jDIyBLS6k3UxPI=" crossorigin="anonymous"></script><!-- search --><script src="https://cdnjs.cloudflare.com/ajax/libs/fuse.js/6.4.6/fuse.js" integrity="sha512-zv6Ywkjyktsohkbp9bb45V6tEMoWhzFzXis+LrMehmJZZSys19Yxf1dopHx7WzIKxr5tK2dVcYmaCk2uqdjF4A==" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/autocomplete.js/0.38.0/autocomplete.jquery.min.js" integrity="sha512-GU9ayf+66Xx2TmpxqJpliWbT5PiGYxpaG8rfnBEk1LL8l1KGkRShhngwdXK1UgqhAzWpZHSiYPc09/NwDQIGyg==" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mark.js/8.11.1/mark.min.js" integrity="sha512-5CYOlHXGh6QpOFA/TeTylKLWfB3ftPsde7AnmhuitiTX4K5SqCLBeKro6sPS8ilsz1Q4NRx3v8Ko2IBiszzdww==" crossorigin="anonymous"></script><!-- pkgdown --><script src="../pkgdown.js"></script><link href="../extra.css" rel="stylesheet">
|
||||
<script src="../extra.js"></script><meta property="og:title" content="How to import data from SPSS / SAS / Stata">
|
||||
<meta property="og:description" content="AMR">
|
||||
<meta property="og:image" content="https://msberends.github.io/AMR/logo.svg">
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
<meta name="twitter:creator" content="@msberends">
|
||||
<meta name="twitter:site" content="@msberends">
|
||||
<!-- mathjax --><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script><!--[if lt IE 9]>
|
||||
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
|
||||
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
|
||||
<![endif]-->
|
||||
</head>
|
||||
<body>
|
||||
<a href="#main" class="visually-hidden-focusable">Skip to contents</a>
|
||||
|
||||
|
||||
<nav class="navbar fixed-top navbar-dark navbar-expand-lg bg-primary"><div class="container">
|
||||
|
||||
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
|
||||
|
||||
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">1.8.2.9139</small>
|
||||
|
||||
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<div id="navbar" class="collapse navbar-collapse ms-3">
|
||||
<ul class="navbar-nav me-auto">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="../index.html">
|
||||
<span class="fa fa-home"></span>
|
||||
|
||||
Home
|
||||
</a>
|
||||
</li>
|
||||
<li class="active nav-item dropdown">
|
||||
<a href="#" class="nav-link dropdown-toggle" data-bs-toggle="dropdown" role="button" aria-expanded="false" aria-haspopup="true" id="dropdown--how-to">
|
||||
<span class="fa fa-question-circle"></span>
|
||||
|
||||
How to
|
||||
</a>
|
||||
<div class="dropdown-menu" aria-labelledby="dropdown--how-to">
|
||||
<a class="dropdown-item" href="../reference/AMR-options.html">
|
||||
<span class="fa fa-gear"></span>
|
||||
|
||||
User- Or Team-specific Package Settings
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/AMR.html">
|
||||
<span class="fa fa-directions"></span>
|
||||
|
||||
Conduct AMR Analysis
|
||||
</a>
|
||||
<a class="dropdown-item" href="../reference/antibiogram.html">
|
||||
<span class="fa fa-file-prescription"></span>
|
||||
|
||||
Generate Antibiogram (Trad./Syndromic/WISCA)
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/resistance_predict.html">
|
||||
<span class="fa fa-dice"></span>
|
||||
|
||||
Predict Antimicrobial Resistance
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/datasets.html">
|
||||
<span class="fa fa-database"></span>
|
||||
|
||||
Data Sets for Download / Own Use
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/PCA.html">
|
||||
<span class="fa fa-compress"></span>
|
||||
|
||||
Conduct Principal Component Analysis for AMR
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/MDR.html">
|
||||
<span class="fa fa-skull-crossbones"></span>
|
||||
|
||||
Determine Multi-Drug Resistance (MDR)
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/WHONET.html">
|
||||
<span class="fa fa-globe-americas"></span>
|
||||
|
||||
Work with WHONET Data
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/SPSS.html">
|
||||
<span class="fa fa-file-upload"></span>
|
||||
|
||||
Import Data From SPSS/SAS/Stata
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/EUCAST.html">
|
||||
<span class="fa fa-exchange-alt"></span>
|
||||
|
||||
Apply Eucast Rules
|
||||
</a>
|
||||
<a class="dropdown-item" href="../reference/mo_property.html">
|
||||
<span class="fa fa-bug"></span>
|
||||
|
||||
Get Taxonomy of a Microorganism
|
||||
</a>
|
||||
<a class="dropdown-item" href="../reference/ab_property.html">
|
||||
<span class="fa fa-capsules"></span>
|
||||
|
||||
Get Properties of an Antibiotic Drug
|
||||
</a>
|
||||
<a class="dropdown-item" href="../reference/av_property.html">
|
||||
<span class="fa fa-capsules"></span>
|
||||
|
||||
Get Properties of an Antiviral Drug
|
||||
</a>
|
||||
</div>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="../reference/index.html">
|
||||
<span class="fa fa-book-open"></span>
|
||||
|
||||
Manual
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="../authors.html">
|
||||
<span class="fa fa-users"></span>
|
||||
|
||||
Authors
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="../news/index.html">
|
||||
<span class="far fa far fa-newspaper"></span>
|
||||
|
||||
Changelog
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
<form class="form-inline my-2 my-lg-0" role="search">
|
||||
<input type="search" class="form-control me-sm-2" aria-label="Toggle navigation" name="search-input" data-search-index="../search.json" id="search-input" placeholder="Search for" autocomplete="off">
|
||||
</form>
|
||||
|
||||
<ul class="navbar-nav">
|
||||
<li class="nav-item">
|
||||
<a class="external-link nav-link" href="https://github.com/msberends/AMR">
|
||||
<span class="fab fa fab fa-github"></span>
|
||||
|
||||
Source Code
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</nav><div class="container template-article">
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="row">
|
||||
<main id="main" class="col-md-9"><div class="page-header">
|
||||
<img src="../logo.svg" class="logo" alt=""><h1>How to import data from SPSS / SAS / Stata</h1>
|
||||
<h4 data-toc-skip class="author">Dr. Matthijs
|
||||
Berends</h4>
|
||||
|
||||
<h4 data-toc-skip class="date">22 February 2023</h4>
|
||||
|
||||
<small class="dont-index">Source: <a href="https://github.com/msberends/AMR/blob/HEAD/vignettes/SPSS.Rmd" class="external-link"><code>vignettes/SPSS.Rmd</code></a></small>
|
||||
<div class="d-none name"><code>SPSS.Rmd</code></div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div class="section level2">
|
||||
<h2 id="spss-sas-stata">SPSS / SAS / Stata<a class="anchor" aria-label="anchor" href="#spss-sas-stata"></a>
|
||||
</h2>
|
||||
<p>SPSS (Statistical Package for the Social Sciences) is probably the
|
||||
most well-known software package for statistical analysis. SPSS is
|
||||
easier to learn than R, because in SPSS you only have to click a menu to
|
||||
run parts of your analysis. Because of its user-friendliness, it is
|
||||
taught at universities and particularly useful for students who are new
|
||||
to statistics. From my experience, I would guess that pretty much all
|
||||
(bio)medical students know it at the time they graduate. SAS and Stata
|
||||
are comparable statistical packages popular in big industries.</p>
|
||||
</div>
|
||||
<div class="section level2">
|
||||
<h2 id="compared-to-r">Compared to R<a class="anchor" aria-label="anchor" href="#compared-to-r"></a>
|
||||
</h2>
|
||||
<p>As said, SPSS is easier to learn than R. But SPSS, SAS and Stata come
|
||||
with major downsides when comparing it with R:</p>
|
||||
<ul>
|
||||
<li>
|
||||
<p><strong>R is highly modular.</strong></p>
|
||||
<p>The <a href="https://cran.r-project.org/" class="external-link">official R network
|
||||
(CRAN)</a> features more than 16,000 packages at the time of writing,
|
||||
our <code>AMR</code> package being one of them. All these packages were
|
||||
peer-reviewed before publication. Aside from this official channel,
|
||||
there are also developers who choose not to submit to CRAN, but rather
|
||||
keep it on their own public repository, like GitHub. So there may even
|
||||
be a lot more than 14,000 packages out there.</p>
|
||||
<p>Bottom line is, you can really extend it yourself or ask somebody to
|
||||
do this for you. Take for example our <code>AMR</code> package. Among
|
||||
other things, it adds reliable reference data to R to help you with the
|
||||
data cleaning and analysis. SPSS, SAS and Stata will never know what a
|
||||
valid MIC value is or what the Gram stain of <em>E. coli</em> is. Or
|
||||
that all species of <em>Klebiella</em> are resistant to amoxicillin and
|
||||
that Floxapen<sup>®</sup> is a trade name of flucloxacillin. These facts
|
||||
and properties are often needed to clean existing data, which would be
|
||||
very inconvenient in a software package without reliable reference data.
|
||||
See below for a demonstration.</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><strong>R is extremely flexible.</strong></p>
|
||||
<p>Because you write the syntax yourself, you can do anything you want.
|
||||
The flexibility in transforming, arranging, grouping and summarising
|
||||
data, or drawing plots, is endless - with SPSS, SAS or Stata you are
|
||||
bound to their algorithms and format styles. They may be a bit flexible,
|
||||
but you can probably never create that very specific publication-ready
|
||||
plot without using other (paid) software. If you sometimes write
|
||||
syntaxes in SPSS to run a complete analysis or to ‘automate’ some of
|
||||
your work, you could do this a lot less time in R. You will notice that
|
||||
writing syntaxes in R is a lot more nifty and clever than in SPSS.
|
||||
Still, as working with any statistical package, you will have to have
|
||||
knowledge about what you are doing (statistically) and what you are
|
||||
willing to accomplish.</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><strong>R can be easily automated.</strong></p>
|
||||
<p>Over the last years, <a href="https://rmarkdown.rstudio.com/" class="external-link">R
|
||||
Markdown</a> has really made an interesting development. With R
|
||||
Markdown, you can very easily produce reports, whether the format has to
|
||||
be Word, PowerPoint, a website, a PDF document or just the raw data to
|
||||
Excel. It even allows the use of a reference file containing the layout
|
||||
style (e.g. fonts and colours) of your organisation. I use this a lot to
|
||||
generate weekly and monthly reports automatically. Just write the code
|
||||
once and enjoy the automatically updated reports at any interval you
|
||||
like.</p>
|
||||
<p>For an even more professional environment, you could create <a href="https://shiny.rstudio.com/" class="external-link">Shiny apps</a>: live manipulation of
|
||||
data using a custom made website. The webdesign knowledge needed
|
||||
(JavaScript, CSS, HTML) is almost <em>zero</em>.</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><strong>R has a huge community.</strong></p>
|
||||
<p>Many R users just ask questions on websites like <a href="https://stackoverflow.com" class="external-link">StackOverflow.com</a>, the largest
|
||||
online community for programmers. At the time of writing, <a href="https://stackoverflow.com/questions/tagged/r?sort=votes" class="external-link">481 631
|
||||
R-related questions</a> have already been asked on this platform (that
|
||||
covers questions and answers for any programming language). In my own
|
||||
experience, most questions are answered within a couple of
|
||||
minutes.</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><strong>R understands any data type, including
|
||||
SPSS/SAS/Stata.</strong></p>
|
||||
<p>And that’s not vice versa I’m afraid. You can import data from any
|
||||
source into R. For example from SPSS, SAS and Stata (<a href="https://haven.tidyverse.org/" class="external-link">link</a>), from Minitab, Epi Info
|
||||
and EpiData (<a href="https://cran.r-project.org/package=foreign" class="external-link">link</a>), from Excel
|
||||
(<a href="https://readxl.tidyverse.org/" class="external-link">link</a>), from flat files like
|
||||
CSV, TXT or TSV (<a href="https://readr.tidyverse.org/" class="external-link">link</a>), or
|
||||
directly from databases and datawarehouses from anywhere on the world
|
||||
(<a href="https://dbplyr.tidyverse.org/" class="external-link">link</a>). You can even scrape
|
||||
websites to download tables that are live on the internet (<a href="https://github.com/hadley/rvest" class="external-link">link</a>) or get the results of
|
||||
an API call and transform it into data in only one command (<a href="https://github.com/Rdatatable/data.table/wiki/Convenience-features-of-fread" class="external-link">link</a>).</p>
|
||||
<p>And the best part - you can export from R to most data formats as
|
||||
well. So you can import an SPSS file, do your analysis neatly in R and
|
||||
export the resulting tables to Excel files for sharing.</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><strong>R is completely free and open-source.</strong></p>
|
||||
<p>No strings attached. It was created and is being maintained by
|
||||
volunteers who believe that (data) science should be open and publicly
|
||||
available to everybody. SPSS, SAS and Stata are quite expensive. IBM
|
||||
SPSS Staticstics only comes with subscriptions nowadays, varying <a href="https://www.ibm.com/products/spss-statistics/pricing" class="external-link">between USD
|
||||
1,300 and USD 8,500</a> per user <em>per year</em>. SAS Analytics Pro
|
||||
costs <a href="https://www.sas.com/store/products-solutions/sas-analytics-pro/prodPERSANL.html" class="external-link">around
|
||||
USD 10,000</a> per computer. Stata also has a business model with
|
||||
subscription fees, varying <a href="https://www.stata.com/order/new/bus/single-user-licenses/dl/" class="external-link">between
|
||||
USD 600 and USD 2,800</a> per computer per year, but lower prices come
|
||||
with a limitation of the number of variables you can work with. And
|
||||
still they do not offer the above benefits of R.</p>
|
||||
<p>If you are working at a midsized or small company, you can save it
|
||||
tens of thousands of dollars by using R instead of e.g. SPSS - gaining
|
||||
even more functions and flexibility. And all R enthousiasts can do as
|
||||
much PR as they want (like I do here), because nobody is officially
|
||||
associated with or affiliated by R. It is really free.</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><strong>R is (nowadays) the preferred analysis software in
|
||||
academic papers.</strong></p>
|
||||
<p>At present, R is among the world most powerful statistical languages,
|
||||
and it is generally very popular in science (Bollmann <em>et al.</em>,
|
||||
2017). For all the above reasons, the number of references to R as an
|
||||
analysis method in academic papers <a href="https://r4stats.com/2014/08/20/r-passes-spss-in-scholarly-use-stata-growing-rapidly/" class="external-link">is
|
||||
rising continuously</a> and has even surpassed SPSS for academic use
|
||||
(Muenchen, 2014).</p>
|
||||
<p>I believe that the thing with SPSS is, that it has always had a great
|
||||
user interface which is very easy to learn and use. Back when they
|
||||
developed it, they had very little competition, let alone from R. R
|
||||
didn’t even had a professional user interface until the last decade
|
||||
(called RStudio, see below). How people used R between the nineties and
|
||||
2010 is almost completely incomparable to how R is being used now. The
|
||||
language itself <a href="https://www.tidyverse.org/packages/" class="external-link">has been
|
||||
restyled completely</a> by volunteers who are dedicated professionals in
|
||||
the field of data science. SPSS was great when there was nothing else
|
||||
that could compete. But now in 2023, I don’t see any reason why SPSS
|
||||
would be of any better use than R.</p>
|
||||
</li>
|
||||
</ul>
|
||||
<p>To demonstrate the first point:</p>
|
||||
<div class="sourceCode" id="cb1"><pre class="downlit sourceCode r">
|
||||
<code class="sourceCode R"><span><span class="co"># not all values are valid MIC values:</span></span>
|
||||
<span><span class="fu"><a href="../reference/as.mic.html">as.mic</a></span><span class="op">(</span><span class="fl">0.125</span><span class="op">)</span></span>
|
||||
<span><span class="co">#> Class 'mic'</span></span>
|
||||
<span><span class="co">#> [1] 0.125</span></span>
|
||||
<span><span class="fu"><a href="../reference/as.mic.html">as.mic</a></span><span class="op">(</span><span class="st">"testvalue"</span><span class="op">)</span></span>
|
||||
<span><span class="co">#> Class 'mic'</span></span>
|
||||
<span><span class="co">#> [1] <NA></span></span>
|
||||
<span></span>
|
||||
<span><span class="co"># the Gram stain is available for all bacteria:</span></span>
|
||||
<span><span class="fu"><a href="../reference/mo_property.html">mo_gramstain</a></span><span class="op">(</span><span class="st">"E. coli"</span><span class="op">)</span></span>
|
||||
<span><span class="co">#> [1] "Gram-negative"</span></span>
|
||||
<span></span>
|
||||
<span><span class="co"># Klebsiella is intrinsic resistant to amoxicillin, according to EUCAST:</span></span>
|
||||
<span><span class="va">klebsiella_test</span> <span class="op"><-</span> <span class="fu"><a href="https://rdrr.io/r/base/data.frame.html" class="external-link">data.frame</a></span><span class="op">(</span></span>
|
||||
<span> mo <span class="op">=</span> <span class="st">"klebsiella"</span>,</span>
|
||||
<span> amox <span class="op">=</span> <span class="st">"S"</span>,</span>
|
||||
<span> stringsAsFactors <span class="op">=</span> <span class="cn">FALSE</span></span>
|
||||
<span><span class="op">)</span></span>
|
||||
<span><span class="va">klebsiella_test</span> <span class="co"># (our original data)</span></span>
|
||||
<span><span class="co">#> mo amox</span></span>
|
||||
<span><span class="co">#> 1 klebsiella S</span></span>
|
||||
<span><span class="fu"><a href="../reference/eucast_rules.html">eucast_rules</a></span><span class="op">(</span><span class="va">klebsiella_test</span>, info <span class="op">=</span> <span class="cn">FALSE</span><span class="op">)</span> <span class="co"># (the edited data by EUCAST rules)</span></span>
|
||||
<span><span class="co">#> mo amox</span></span>
|
||||
<span><span class="co">#> 1 klebsiella R</span></span>
|
||||
<span></span>
|
||||
<span><span class="co"># hundreds of trade names can be translated to a name, trade name or an ATC code:</span></span>
|
||||
<span><span class="fu"><a href="../reference/ab_property.html">ab_name</a></span><span class="op">(</span><span class="st">"floxapen"</span><span class="op">)</span></span>
|
||||
<span><span class="co">#> [1] "Flucloxacillin"</span></span>
|
||||
<span><span class="fu"><a href="../reference/ab_property.html">ab_tradenames</a></span><span class="op">(</span><span class="st">"floxapen"</span><span class="op">)</span></span>
|
||||
<span><span class="co">#> [1] "culpen" "floxacillin" "floxacillin sodium" </span></span>
|
||||
<span><span class="co">#> [4] "floxapen" "floxapen sodium salt" "fluclox" </span></span>
|
||||
<span><span class="co">#> [7] "flucloxacilina" "flucloxacillin" "flucloxacilline" </span></span>
|
||||
<span><span class="co">#> [10] "flucloxacillinum" "fluorochloroxacillin" "staphylex"</span></span>
|
||||
<span><span class="fu"><a href="../reference/ab_property.html">ab_atc</a></span><span class="op">(</span><span class="st">"floxapen"</span><span class="op">)</span></span>
|
||||
<span><span class="co">#> [1] "J01CF05"</span></span></code></pre></div>
|
||||
</div>
|
||||
<div class="section level2">
|
||||
<h2 id="import-data-from-spsssasstata">Import data from SPSS/SAS/Stata<a class="anchor" aria-label="anchor" href="#import-data-from-spsssasstata"></a>
|
||||
</h2>
|
||||
<div class="section level3">
|
||||
<h3 id="rstudio">RStudio<a class="anchor" aria-label="anchor" href="#rstudio"></a>
|
||||
</h3>
|
||||
<p>To work with R, probably the best option is to use <a href="https://www.rstudio.com/products/rstudio/" class="external-link">RStudio</a>. It is an
|
||||
open-source and free desktop environment which not only allows you to
|
||||
run R code, but also supports project management, version management,
|
||||
package management and convenient import menus to work with other data
|
||||
sources. You can also install <a href="https://www.rstudio.com/products/rstudio/" class="external-link">RStudio Server</a> on a
|
||||
private or corporate server, which brings nothing less than the complete
|
||||
RStudio software to you as a website (at home or at work).</p>
|
||||
<p>To import a data file, just click <em>Import Dataset</em> in the
|
||||
Environment tab:</p>
|
||||
<p><img src="https://github.com/msberends/AMR/raw/main/docs/import1.png"></p>
|
||||
<p>If additional packages are needed, RStudio will ask you if they
|
||||
should be installed on beforehand.</p>
|
||||
<p>In the the window that opens, you can define all options (parameters)
|
||||
that should be used for import and you’re ready to go:</p>
|
||||
<p><img src="https://github.com/msberends/AMR/raw/main/docs/import2.png"></p>
|
||||
<p>If you want named variables to be imported as factors so it resembles
|
||||
SPSS more, use <code>as_factor()</code>.</p>
|
||||
<p>The difference is this:</p>
|
||||
<div class="sourceCode" id="cb2"><pre class="downlit sourceCode r">
|
||||
<code class="sourceCode R"><span><span class="va">SPSS_data</span></span>
|
||||
<span><span class="co"># # A tibble: 4,203 x 4</span></span>
|
||||
<span><span class="co"># v001 sex status statusage</span></span>
|
||||
<span><span class="co"># <dbl> <dbl+lbl> <dbl+lbl> <dbl></span></span>
|
||||
<span><span class="co"># 1 10002 1 1 76.6</span></span>
|
||||
<span><span class="co"># 2 10004 0 1 59.1</span></span>
|
||||
<span><span class="co"># 3 10005 1 1 54.5</span></span>
|
||||
<span><span class="co"># 4 10006 1 1 54.1</span></span>
|
||||
<span><span class="co"># 5 10007 1 1 57.7</span></span>
|
||||
<span><span class="co"># 6 10008 1 1 62.8</span></span>
|
||||
<span><span class="co"># 7 10010 0 1 63.7</span></span>
|
||||
<span><span class="co"># 8 10011 1 1 73.1</span></span>
|
||||
<span><span class="co"># 9 10017 1 1 56.7</span></span>
|
||||
<span><span class="co"># 10 10018 0 1 66.6</span></span>
|
||||
<span><span class="co"># # ... with 4,193 more rows</span></span>
|
||||
<span></span>
|
||||
<span><span class="fu">as_factor</span><span class="op">(</span><span class="va">SPSS_data</span><span class="op">)</span></span>
|
||||
<span><span class="co"># # A tibble: 4,203 x 4</span></span>
|
||||
<span><span class="co"># v001 sex status statusage</span></span>
|
||||
<span><span class="co"># <dbl> <fct> <fct> <dbl></span></span>
|
||||
<span><span class="co"># 1 10002 Male alive 76.6</span></span>
|
||||
<span><span class="co"># 2 10004 Female alive 59.1</span></span>
|
||||
<span><span class="co"># 3 10005 Male alive 54.5</span></span>
|
||||
<span><span class="co"># 4 10006 Male alive 54.1</span></span>
|
||||
<span><span class="co"># 5 10007 Male alive 57.7</span></span>
|
||||
<span><span class="co"># 6 10008 Male alive 62.8</span></span>
|
||||
<span><span class="co"># 7 10010 Female alive 63.7</span></span>
|
||||
<span><span class="co"># 8 10011 Male alive 73.1</span></span>
|
||||
<span><span class="co"># 9 10017 Male alive 56.7</span></span>
|
||||
<span><span class="co"># 10 10018 Female alive 66.6</span></span>
|
||||
<span><span class="co"># # ... with 4,193 more rows</span></span></code></pre></div>
|
||||
</div>
|
||||
<div class="section level3">
|
||||
<h3 id="base-r">Base R<a class="anchor" aria-label="anchor" href="#base-r"></a>
|
||||
</h3>
|
||||
<p>To import data from SPSS, SAS or Stata, you can use the <a href="https://haven.tidyverse.org/" class="external-link">great <code>haven</code> package</a>
|
||||
yourself:</p>
|
||||
<div class="sourceCode" id="cb3"><pre class="downlit sourceCode r">
|
||||
<code class="sourceCode R"><span><span class="co"># download and install the latest version:</span></span>
|
||||
<span><span class="fu"><a href="https://rdrr.io/r/utils/install.packages.html" class="external-link">install.packages</a></span><span class="op">(</span><span class="st">"haven"</span><span class="op">)</span></span>
|
||||
<span><span class="co"># load the package you just installed:</span></span>
|
||||
<span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://haven.tidyverse.org" class="external-link">haven</a></span><span class="op">)</span></span></code></pre></div>
|
||||
<p>You can now import files as follows:</p>
|
||||
<div class="section level4">
|
||||
<h4 id="spss">SPSS<a class="anchor" aria-label="anchor" href="#spss"></a>
|
||||
</h4>
|
||||
<p>To read files from SPSS into R:</p>
|
||||
<div class="sourceCode" id="cb4"><pre class="downlit sourceCode r">
|
||||
<code class="sourceCode R"><span><span class="co"># read any SPSS file based on file extension (best way):</span></span>
|
||||
<span><span class="fu">read_spss</span><span class="op">(</span>file <span class="op">=</span> <span class="st">"path/to/file"</span><span class="op">)</span></span>
|
||||
<span></span>
|
||||
<span><span class="co"># read .sav or .zsav file:</span></span>
|
||||
<span><span class="fu">read_sav</span><span class="op">(</span>file <span class="op">=</span> <span class="st">"path/to/file"</span><span class="op">)</span></span>
|
||||
<span></span>
|
||||
<span><span class="co"># read .por file:</span></span>
|
||||
<span><span class="fu">read_por</span><span class="op">(</span>file <span class="op">=</span> <span class="st">"path/to/file"</span><span class="op">)</span></span></code></pre></div>
|
||||
<p>Do not forget about <code>as_factor()</code>, as mentioned above.</p>
|
||||
<p>To export your R objects to the SPSS file format:</p>
|
||||
<div class="sourceCode" id="cb5"><pre class="downlit sourceCode r">
|
||||
<code class="sourceCode R"><span><span class="co"># save as .sav file:</span></span>
|
||||
<span><span class="fu">write_sav</span><span class="op">(</span>data <span class="op">=</span> <span class="va">yourdata</span>, path <span class="op">=</span> <span class="st">"path/to/file"</span><span class="op">)</span></span>
|
||||
<span></span>
|
||||
<span><span class="co"># save as compressed .zsav file:</span></span>
|
||||
<span><span class="fu">write_sav</span><span class="op">(</span>data <span class="op">=</span> <span class="va">yourdata</span>, path <span class="op">=</span> <span class="st">"path/to/file"</span>, compress <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span></span></code></pre></div>
|
||||
</div>
|
||||
<div class="section level4">
|
||||
<h4 id="sas">SAS<a class="anchor" aria-label="anchor" href="#sas"></a>
|
||||
</h4>
|
||||
<p>To read files from SAS into R:</p>
|
||||
<div class="sourceCode" id="cb6"><pre class="downlit sourceCode r">
|
||||
<code class="sourceCode R"><span><span class="co"># read .sas7bdat + .sas7bcat files:</span></span>
|
||||
<span><span class="fu">read_sas</span><span class="op">(</span>data_file <span class="op">=</span> <span class="st">"path/to/file"</span>, catalog_file <span class="op">=</span> <span class="cn">NULL</span><span class="op">)</span></span>
|
||||
<span></span>
|
||||
<span><span class="co"># read SAS transport files (version 5 and version 8):</span></span>
|
||||
<span><span class="fu">read_xpt</span><span class="op">(</span>file <span class="op">=</span> <span class="st">"path/to/file"</span><span class="op">)</span></span></code></pre></div>
|
||||
<p>To export your R objects to the SAS file format:</p>
|
||||
<div class="sourceCode" id="cb7"><pre class="downlit sourceCode r">
|
||||
<code class="sourceCode R"><span><span class="co"># save as regular SAS file:</span></span>
|
||||
<span><span class="fu">write_sas</span><span class="op">(</span>data <span class="op">=</span> <span class="va">yourdata</span>, path <span class="op">=</span> <span class="st">"path/to/file"</span><span class="op">)</span></span>
|
||||
<span></span>
|
||||
<span><span class="co"># the SAS transport format is an open format</span></span>
|
||||
<span><span class="co"># (required for submission of the data to the FDA)</span></span>
|
||||
<span><span class="fu">write_xpt</span><span class="op">(</span>data <span class="op">=</span> <span class="va">yourdata</span>, path <span class="op">=</span> <span class="st">"path/to/file"</span>, version <span class="op">=</span> <span class="fl">8</span><span class="op">)</span></span></code></pre></div>
|
||||
</div>
|
||||
<div class="section level4">
|
||||
<h4 id="stata">Stata<a class="anchor" aria-label="anchor" href="#stata"></a>
|
||||
</h4>
|
||||
<p>To read files from Stata into R:</p>
|
||||
<div class="sourceCode" id="cb8"><pre class="downlit sourceCode r">
|
||||
<code class="sourceCode R"><span><span class="co"># read .dta file:</span></span>
|
||||
<span><span class="fu">read_stata</span><span class="op">(</span>file <span class="op">=</span> <span class="st">"/path/to/file"</span><span class="op">)</span></span>
|
||||
<span></span>
|
||||
<span><span class="co"># works exactly the same:</span></span>
|
||||
<span><span class="fu">read_dta</span><span class="op">(</span>file <span class="op">=</span> <span class="st">"/path/to/file"</span><span class="op">)</span></span></code></pre></div>
|
||||
<p>To export your R objects to the Stata file format:</p>
|
||||
<div class="sourceCode" id="cb9"><pre class="downlit sourceCode r">
|
||||
<code class="sourceCode R"><span><span class="co"># save as .dta file, Stata version 14:</span></span>
|
||||
<span><span class="co"># (supports Stata v8 until v15 at the time of writing)</span></span>
|
||||
<span><span class="fu">write_dta</span><span class="op">(</span>data <span class="op">=</span> <span class="va">yourdata</span>, path <span class="op">=</span> <span class="st">"/path/to/file"</span>, version <span class="op">=</span> <span class="fl">14</span><span class="op">)</span></span></code></pre></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main><aside class="col-md-3"><nav id="toc"><h2>On this page</h2>
|
||||
</nav></aside>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<footer><div class="pkgdown-footer-left">
|
||||
<p></p>
|
||||
<p><code>AMR</code> (for R). Free and open-source, licenced under the <a target="_blank" href="https://github.com/msberends/AMR/blob/main/LICENSE" class="external-link">GNU General Public License version 2.0 (GPL-2)</a>.<br>Developed at the <a target="_blank" href="https://www.rug.nl" class="external-link">University of Groningen</a> and <a target="_blank" href="https://www.umcg.nl" class="external-link">University Medical Center Groningen</a> in The Netherlands.</p>
|
||||
</div>
|
||||
|
||||
<div class="pkgdown-footer-right">
|
||||
<p></p>
|
||||
<p><a target="_blank" href="https://www.rug.nl" class="external-link"><img src="https://github.com/msberends/AMR/raw/main/pkgdown/logos/logo_rug.svg" style="max-width: 150px;"></a><a target="_blank" href="https://www.umcg.nl" class="external-link"><img src="https://github.com/msberends/AMR/raw/main/pkgdown/logos/logo_umcg.svg" style="max-width: 150px;"></a></p>
|
||||
</div>
|
||||
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,436 @@
|
||||
<!DOCTYPE html>
|
||||
<!-- Generated by pkgdown: do not edit by hand --><html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<meta name="description" content="AMR">
|
||||
<title>How to work with WHONET data • AMR (for R)</title>
|
||||
<!-- favicons --><link rel="icon" type="image/png" sizes="16x16" href="../favicon-16x16.png">
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="../favicon-32x32.png">
|
||||
<link rel="apple-touch-icon" type="image/png" sizes="180x180" href="../apple-touch-icon.png">
|
||||
<link rel="apple-touch-icon" type="image/png" sizes="120x120" href="../apple-touch-icon-120x120.png">
|
||||
<link rel="apple-touch-icon" type="image/png" sizes="76x76" href="../apple-touch-icon-76x76.png">
|
||||
<link rel="apple-touch-icon" type="image/png" sizes="60x60" href="../apple-touch-icon-60x60.png">
|
||||
<script src="../deps/jquery-3.6.0/jquery-3.6.0.min.js"></script><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<link href="../deps/bootstrap-5.2.2/bootstrap.min.css" rel="stylesheet">
|
||||
<script src="../deps/bootstrap-5.2.2/bootstrap.bundle.min.js"></script><link href="../deps/Fira_Code-0.4.5/font.css" rel="stylesheet">
|
||||
<!-- Font Awesome icons --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css" integrity="sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk=" crossorigin="anonymous">
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/v4-shims.min.css" integrity="sha256-wZjR52fzng1pJHwx4aV2AO3yyTOXrcDW7jBpJtTwVxw=" crossorigin="anonymous">
|
||||
<!-- bootstrap-toc --><script src="https://cdn.jsdelivr.net/gh/afeld/bootstrap-toc@v1.0.1/dist/bootstrap-toc.min.js" integrity="sha256-4veVQbu7//Lk5TSmc7YV48MxtMy98e26cf5MrgZYnwo=" crossorigin="anonymous"></script><!-- headroom.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/headroom.min.js" integrity="sha256-AsUX4SJE1+yuDu5+mAVzJbuYNPHj/WroHuZ8Ir/CkE0=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/jQuery.headroom.min.js" integrity="sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4=" crossorigin="anonymous"></script><!-- clipboard.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js" integrity="sha256-inc5kl9MA1hkeYUt+EC3BhlIgyp/2jDIyBLS6k3UxPI=" crossorigin="anonymous"></script><!-- search --><script src="https://cdnjs.cloudflare.com/ajax/libs/fuse.js/6.4.6/fuse.js" integrity="sha512-zv6Ywkjyktsohkbp9bb45V6tEMoWhzFzXis+LrMehmJZZSys19Yxf1dopHx7WzIKxr5tK2dVcYmaCk2uqdjF4A==" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/autocomplete.js/0.38.0/autocomplete.jquery.min.js" integrity="sha512-GU9ayf+66Xx2TmpxqJpliWbT5PiGYxpaG8rfnBEk1LL8l1KGkRShhngwdXK1UgqhAzWpZHSiYPc09/NwDQIGyg==" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mark.js/8.11.1/mark.min.js" integrity="sha512-5CYOlHXGh6QpOFA/TeTylKLWfB3ftPsde7AnmhuitiTX4K5SqCLBeKro6sPS8ilsz1Q4NRx3v8Ko2IBiszzdww==" crossorigin="anonymous"></script><!-- pkgdown --><script src="../pkgdown.js"></script><link href="../extra.css" rel="stylesheet">
|
||||
<script src="../extra.js"></script><meta property="og:title" content="How to work with WHONET data">
|
||||
<meta property="og:description" content="AMR">
|
||||
<meta property="og:image" content="https://msberends.github.io/AMR/logo.svg">
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
<meta name="twitter:creator" content="@msberends">
|
||||
<meta name="twitter:site" content="@msberends">
|
||||
<!-- mathjax --><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script><!--[if lt IE 9]>
|
||||
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
|
||||
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
|
||||
<![endif]-->
|
||||
</head>
|
||||
<body>
|
||||
<a href="#main" class="visually-hidden-focusable">Skip to contents</a>
|
||||
|
||||
|
||||
<nav class="navbar fixed-top navbar-dark navbar-expand-lg bg-primary"><div class="container">
|
||||
|
||||
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
|
||||
|
||||
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">1.8.2.9139</small>
|
||||
|
||||
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<div id="navbar" class="collapse navbar-collapse ms-3">
|
||||
<ul class="navbar-nav me-auto">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="../index.html">
|
||||
<span class="fa fa-home"></span>
|
||||
|
||||
Home
|
||||
</a>
|
||||
</li>
|
||||
<li class="active nav-item dropdown">
|
||||
<a href="#" class="nav-link dropdown-toggle" data-bs-toggle="dropdown" role="button" aria-expanded="false" aria-haspopup="true" id="dropdown--how-to">
|
||||
<span class="fa fa-question-circle"></span>
|
||||
|
||||
How to
|
||||
</a>
|
||||
<div class="dropdown-menu" aria-labelledby="dropdown--how-to">
|
||||
<a class="dropdown-item" href="../reference/AMR-options.html">
|
||||
<span class="fa fa-gear"></span>
|
||||
|
||||
User- Or Team-specific Package Settings
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/AMR.html">
|
||||
<span class="fa fa-directions"></span>
|
||||
|
||||
Conduct AMR Analysis
|
||||
</a>
|
||||
<a class="dropdown-item" href="../reference/antibiogram.html">
|
||||
<span class="fa fa-file-prescription"></span>
|
||||
|
||||
Generate Antibiogram (Trad./Syndromic/WISCA)
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/resistance_predict.html">
|
||||
<span class="fa fa-dice"></span>
|
||||
|
||||
Predict Antimicrobial Resistance
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/datasets.html">
|
||||
<span class="fa fa-database"></span>
|
||||
|
||||
Data Sets for Download / Own Use
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/PCA.html">
|
||||
<span class="fa fa-compress"></span>
|
||||
|
||||
Conduct Principal Component Analysis for AMR
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/MDR.html">
|
||||
<span class="fa fa-skull-crossbones"></span>
|
||||
|
||||
Determine Multi-Drug Resistance (MDR)
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/WHONET.html">
|
||||
<span class="fa fa-globe-americas"></span>
|
||||
|
||||
Work with WHONET Data
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/SPSS.html">
|
||||
<span class="fa fa-file-upload"></span>
|
||||
|
||||
Import Data From SPSS/SAS/Stata
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/EUCAST.html">
|
||||
<span class="fa fa-exchange-alt"></span>
|
||||
|
||||
Apply Eucast Rules
|
||||
</a>
|
||||
<a class="dropdown-item" href="../reference/mo_property.html">
|
||||
<span class="fa fa-bug"></span>
|
||||
|
||||
Get Taxonomy of a Microorganism
|
||||
</a>
|
||||
<a class="dropdown-item" href="../reference/ab_property.html">
|
||||
<span class="fa fa-capsules"></span>
|
||||
|
||||
Get Properties of an Antibiotic Drug
|
||||
</a>
|
||||
<a class="dropdown-item" href="../reference/av_property.html">
|
||||
<span class="fa fa-capsules"></span>
|
||||
|
||||
Get Properties of an Antiviral Drug
|
||||
</a>
|
||||
</div>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="../reference/index.html">
|
||||
<span class="fa fa-book-open"></span>
|
||||
|
||||
Manual
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="../authors.html">
|
||||
<span class="fa fa-users"></span>
|
||||
|
||||
Authors
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="../news/index.html">
|
||||
<span class="far fa far fa-newspaper"></span>
|
||||
|
||||
Changelog
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
<form class="form-inline my-2 my-lg-0" role="search">
|
||||
<input type="search" class="form-control me-sm-2" aria-label="Toggle navigation" name="search-input" data-search-index="../search.json" id="search-input" placeholder="Search for" autocomplete="off">
|
||||
</form>
|
||||
|
||||
<ul class="navbar-nav">
|
||||
<li class="nav-item">
|
||||
<a class="external-link nav-link" href="https://github.com/msberends/AMR">
|
||||
<span class="fab fa fab fa-github"></span>
|
||||
|
||||
Source Code
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</nav><div class="container template-article">
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="row">
|
||||
<main id="main" class="col-md-9"><div class="page-header">
|
||||
<img src="../logo.svg" class="logo" alt=""><h1>How to work with WHONET data</h1>
|
||||
|
||||
|
||||
<small class="dont-index">Source: <a href="https://github.com/msberends/AMR/blob/HEAD/vignettes/WHONET.Rmd" class="external-link"><code>vignettes/WHONET.Rmd</code></a></small>
|
||||
<div class="d-none name"><code>WHONET.Rmd</code></div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div class="section level3">
|
||||
<h3 id="import-of-data">Import of data<a class="anchor" aria-label="anchor" href="#import-of-data"></a>
|
||||
</h3>
|
||||
<p>This tutorial assumes you already imported the WHONET data with
|
||||
e.g. the <a href="https://readxl.tidyverse.org/" class="external-link"><code>readxl</code>
|
||||
package</a>. In RStudio, this can be done using the menu button ‘Import
|
||||
Dataset’ in the tab ‘Environment’. Choose the option ‘From Excel’ and
|
||||
select your exported file. Make sure date fields are imported
|
||||
correctly.</p>
|
||||
<p>An example syntax could look like this:</p>
|
||||
<div class="sourceCode" id="cb1"><pre class="downlit sourceCode r">
|
||||
<code class="sourceCode R"><span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://readxl.tidyverse.org" class="external-link">readxl</a></span><span class="op">)</span></span>
|
||||
<span><span class="va">data</span> <span class="op"><-</span> <span class="fu"><a href="https://readxl.tidyverse.org/reference/read_excel.html" class="external-link">read_excel</a></span><span class="op">(</span>path <span class="op">=</span> <span class="st">"path/to/your/file.xlsx"</span><span class="op">)</span></span></code></pre></div>
|
||||
<p>This package comes with an <a href="https://msberends.github.io/AMR/reference/WHONET.html">example
|
||||
data set <code>WHONET</code></a>. We will use it for this analysis.</p>
|
||||
</div>
|
||||
<div class="section level3">
|
||||
<h3 id="preparation">Preparation<a class="anchor" aria-label="anchor" href="#preparation"></a>
|
||||
</h3>
|
||||
<p>First, load the relevant packages if you did not yet did this. I use
|
||||
the tidyverse for all of my analyses. All of them. If you don’t know it
|
||||
yet, I suggest you read about it on their website: <a href="https://www.tidyverse.org/" class="external-link uri">https://www.tidyverse.org/</a>.</p>
|
||||
<div class="sourceCode" id="cb2"><pre class="downlit sourceCode r">
|
||||
<code class="sourceCode R"><span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://dplyr.tidyverse.org" class="external-link">dplyr</a></span><span class="op">)</span> <span class="co"># part of tidyverse</span></span>
|
||||
<span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://ggplot2.tidyverse.org" class="external-link">ggplot2</a></span><span class="op">)</span> <span class="co"># part of tidyverse</span></span>
|
||||
<span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://msberends.github.io/AMR/">AMR</a></span><span class="op">)</span> <span class="co"># this package</span></span>
|
||||
<span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://msberends.github.io/cleaner/" class="external-link">cleaner</a></span><span class="op">)</span> <span class="co"># to create frequency tables</span></span></code></pre></div>
|
||||
<p>We will have to transform some variables to simplify and automate the
|
||||
analysis:</p>
|
||||
<ul>
|
||||
<li>Microorganisms should be transformed to our own microorganism codes
|
||||
(called an <code>mo</code>) using <a href="https://msberends.github.io/AMR/reference/catalogue_of_life">our
|
||||
Catalogue of Life reference data set</a>, which contains all ~70,000
|
||||
microorganisms from the taxonomic kingdoms Bacteria, Fungi and Protozoa.
|
||||
We do the tranformation with <code><a href="../reference/as.mo.html">as.mo()</a></code>. This function also
|
||||
recognises almost all WHONET abbreviations of microorganisms.</li>
|
||||
<li>Antimicrobial results or interpretations have to be clean and valid.
|
||||
In other words, they should only contain values <code>"S"</code>,
|
||||
<code>"I"</code> or <code>"R"</code>. That is exactly where the
|
||||
<code><a href="../reference/as.sir.html">as.sir()</a></code> function is for.</li>
|
||||
</ul>
|
||||
<div class="sourceCode" id="cb3"><pre class="downlit sourceCode r">
|
||||
<code class="sourceCode R"><span><span class="co"># transform variables</span></span>
|
||||
<span><span class="va">data</span> <span class="op"><-</span> <span class="va">WHONET</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%>%</a></span></span>
|
||||
<span> <span class="co"># get microbial ID based on given organism</span></span>
|
||||
<span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/mutate.html" class="external-link">mutate</a></span><span class="op">(</span>mo <span class="op">=</span> <span class="fu"><a href="../reference/as.mo.html">as.mo</a></span><span class="op">(</span><span class="va">Organism</span><span class="op">)</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%>%</a></span></span>
|
||||
<span> <span class="co"># transform everything from "AMP_ND10" to "CIP_EE" to the new `sir` class</span></span>
|
||||
<span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/mutate_all.html" class="external-link">mutate_at</a></span><span class="op">(</span><span class="fu"><a href="https://dplyr.tidyverse.org/reference/vars.html" class="external-link">vars</a></span><span class="op">(</span><span class="va">AMP_ND10</span><span class="op">:</span><span class="va">CIP_EE</span><span class="op">)</span>, <span class="va">as.sir</span><span class="op">)</span></span></code></pre></div>
|
||||
<p>No errors or warnings, so all values are transformed succesfully.</p>
|
||||
<p>We also created a package dedicated to data cleaning and checking,
|
||||
called the <code>cleaner</code> package. Its <code><a href="https://msberends.github.io/cleaner/reference/freq.html" class="external-link">freq()</a></code>
|
||||
function can be used to create frequency tables.</p>
|
||||
<p>So let’s check our data, with a couple of frequency tables:</p>
|
||||
<div class="sourceCode" id="cb4"><pre class="downlit sourceCode r">
|
||||
<code class="sourceCode R"><span><span class="co"># our newly created `mo` variable, put in the mo_name() function</span></span>
|
||||
<span><span class="va">data</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%>%</a></span> <span class="fu"><a href="https://msberends.github.io/cleaner/reference/freq.html" class="external-link">freq</a></span><span class="op">(</span><span class="fu"><a href="../reference/mo_property.html">mo_name</a></span><span class="op">(</span><span class="va">mo</span><span class="op">)</span>, nmax <span class="op">=</span> <span class="fl">10</span><span class="op">)</span></span></code></pre></div>
|
||||
<p><strong>Frequency table</strong></p>
|
||||
<p>Class: character<br>
|
||||
Length: 500<br>
|
||||
Available: 500 (100%, NA: 0 = 0%)<br>
|
||||
Unique: 38</p>
|
||||
<p>Shortest: 11<br>
|
||||
Longest: 40</p>
|
||||
<table class="table">
|
||||
<colgroup>
|
||||
<col width="4%">
|
||||
<col width="47%">
|
||||
<col width="7%">
|
||||
<col width="10%">
|
||||
<col width="13%">
|
||||
<col width="15%">
|
||||
</colgroup>
|
||||
<thead><tr class="header">
|
||||
<th align="left"></th>
|
||||
<th align="left">Item</th>
|
||||
<th align="right">Count</th>
|
||||
<th align="right">Percent</th>
|
||||
<th align="right">Cum. Count</th>
|
||||
<th align="right">Cum. Percent</th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<tr class="odd">
|
||||
<td align="left">1</td>
|
||||
<td align="left">Escherichia coli</td>
|
||||
<td align="right">245</td>
|
||||
<td align="right">49.0%</td>
|
||||
<td align="right">245</td>
|
||||
<td align="right">49.0%</td>
|
||||
</tr>
|
||||
<tr class="even">
|
||||
<td align="left">2</td>
|
||||
<td align="left">Coagulase-negative Staphylococcus (CoNS)</td>
|
||||
<td align="right">74</td>
|
||||
<td align="right">14.8%</td>
|
||||
<td align="right">319</td>
|
||||
<td align="right">63.8%</td>
|
||||
</tr>
|
||||
<tr class="odd">
|
||||
<td align="left">3</td>
|
||||
<td align="left">Staphylococcus epidermidis</td>
|
||||
<td align="right">38</td>
|
||||
<td align="right">7.6%</td>
|
||||
<td align="right">357</td>
|
||||
<td align="right">71.4%</td>
|
||||
</tr>
|
||||
<tr class="even">
|
||||
<td align="left">4</td>
|
||||
<td align="left">Streptococcus pneumoniae</td>
|
||||
<td align="right">31</td>
|
||||
<td align="right">6.2%</td>
|
||||
<td align="right">388</td>
|
||||
<td align="right">77.6%</td>
|
||||
</tr>
|
||||
<tr class="odd">
|
||||
<td align="left">5</td>
|
||||
<td align="left">Staphylococcus hominis hominis</td>
|
||||
<td align="right">21</td>
|
||||
<td align="right">4.2%</td>
|
||||
<td align="right">409</td>
|
||||
<td align="right">81.8%</td>
|
||||
</tr>
|
||||
<tr class="even">
|
||||
<td align="left">6</td>
|
||||
<td align="left">Proteus mirabilis</td>
|
||||
<td align="right">9</td>
|
||||
<td align="right">1.8%</td>
|
||||
<td align="right">418</td>
|
||||
<td align="right">83.6%</td>
|
||||
</tr>
|
||||
<tr class="odd">
|
||||
<td align="left">7</td>
|
||||
<td align="left">Enterococcus faecium</td>
|
||||
<td align="right">8</td>
|
||||
<td align="right">1.6%</td>
|
||||
<td align="right">426</td>
|
||||
<td align="right">85.2%</td>
|
||||
</tr>
|
||||
<tr class="even">
|
||||
<td align="left">8</td>
|
||||
<td align="left">Staphylococcus capitis</td>
|
||||
<td align="right">8</td>
|
||||
<td align="right">1.6%</td>
|
||||
<td align="right">434</td>
|
||||
<td align="right">86.8%</td>
|
||||
</tr>
|
||||
<tr class="odd">
|
||||
<td align="left">9</td>
|
||||
<td align="left">Enterobacter cloacae</td>
|
||||
<td align="right">5</td>
|
||||
<td align="right">1.0%</td>
|
||||
<td align="right">439</td>
|
||||
<td align="right">87.8%</td>
|
||||
</tr>
|
||||
<tr class="even">
|
||||
<td align="left">10</td>
|
||||
<td align="left">Enterococcus columbae</td>
|
||||
<td align="right">4</td>
|
||||
<td align="right">0.8%</td>
|
||||
<td align="right">443</td>
|
||||
<td align="right">88.6%</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p>(omitted 28 entries, n = 57 [11.4%])</p>
|
||||
<div class="sourceCode" id="cb5"><pre class="downlit sourceCode r">
|
||||
<code class="sourceCode R"><span><span class="co"># our transformed antibiotic columns</span></span>
|
||||
<span><span class="co"># amoxicillin/clavulanic acid (J01CR02) as an example</span></span>
|
||||
<span><span class="va">data</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%>%</a></span> <span class="fu"><a href="https://msberends.github.io/cleaner/reference/freq.html" class="external-link">freq</a></span><span class="op">(</span><span class="va">AMC_ND2</span><span class="op">)</span></span></code></pre></div>
|
||||
<p><strong>Frequency table</strong></p>
|
||||
<p>Class: factor > ordered > sir (numeric)<br>
|
||||
Length: 500<br>
|
||||
Levels: 3: S < I < R<br>
|
||||
Available: 481 (96.2%, NA: 19 = 3.8%)<br>
|
||||
Unique: 3</p>
|
||||
<p>Drug: Amoxicillin/clavulanic acid (AMC, J01CR02)<br>
|
||||
Drug group: Beta-lactams/penicillins<br>
|
||||
%SI: 78.59%</p>
|
||||
<table class="table">
|
||||
<thead><tr class="header">
|
||||
<th align="left"></th>
|
||||
<th align="left">Item</th>
|
||||
<th align="right">Count</th>
|
||||
<th align="right">Percent</th>
|
||||
<th align="right">Cum. Count</th>
|
||||
<th align="right">Cum. Percent</th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<tr class="odd">
|
||||
<td align="left">1</td>
|
||||
<td align="left">S</td>
|
||||
<td align="right">356</td>
|
||||
<td align="right">74.01%</td>
|
||||
<td align="right">356</td>
|
||||
<td align="right">74.01%</td>
|
||||
</tr>
|
||||
<tr class="even">
|
||||
<td align="left">2</td>
|
||||
<td align="left">R</td>
|
||||
<td align="right">103</td>
|
||||
<td align="right">21.41%</td>
|
||||
<td align="right">459</td>
|
||||
<td align="right">95.43%</td>
|
||||
</tr>
|
||||
<tr class="odd">
|
||||
<td align="left">3</td>
|
||||
<td align="left">I</td>
|
||||
<td align="right">22</td>
|
||||
<td align="right">4.57%</td>
|
||||
<td align="right">481</td>
|
||||
<td align="right">100.00%</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="section level3">
|
||||
<h3 id="a-first-glimpse-at-results">A first glimpse at results<a class="anchor" aria-label="anchor" href="#a-first-glimpse-at-results"></a>
|
||||
</h3>
|
||||
<p>An easy <code>ggplot</code> will already give a lot of information,
|
||||
using the included <code><a href="../reference/ggplot_sir.html">ggplot_sir()</a></code> function:</p>
|
||||
<div class="sourceCode" id="cb6"><pre class="downlit sourceCode r">
|
||||
<code class="sourceCode R"><span><span class="va">data</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%>%</a></span></span>
|
||||
<span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/group_by.html" class="external-link">group_by</a></span><span class="op">(</span><span class="va">Country</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%>%</a></span></span>
|
||||
<span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/select.html" class="external-link">select</a></span><span class="op">(</span><span class="va">Country</span>, <span class="va">AMP_ND2</span>, <span class="va">AMC_ED20</span>, <span class="va">CAZ_ED10</span>, <span class="va">CIP_ED5</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%>%</a></span></span>
|
||||
<span> <span class="fu"><a href="../reference/ggplot_sir.html">ggplot_sir</a></span><span class="op">(</span>translate_ab <span class="op">=</span> <span class="st">"ab"</span>, facet <span class="op">=</span> <span class="st">"Country"</span>, datalabels <span class="op">=</span> <span class="cn">FALSE</span><span class="op">)</span></span></code></pre></div>
|
||||
<p><img src="WHONET_files/figure-html/unnamed-chunk-7-1.png" width="720"></p>
|
||||
</div>
|
||||
</main><aside class="col-md-3"><nav id="toc"><h2>On this page</h2>
|
||||
</nav></aside>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<footer><div class="pkgdown-footer-left">
|
||||
<p></p>
|
||||
<p><code>AMR</code> (for R). Free and open-source, licenced under the <a target="_blank" href="https://github.com/msberends/AMR/blob/main/LICENSE" class="external-link">GNU General Public License version 2.0 (GPL-2)</a>.<br>Developed at the <a target="_blank" href="https://www.rug.nl" class="external-link">University of Groningen</a> and <a target="_blank" href="https://www.umcg.nl" class="external-link">University Medical Center Groningen</a> in The Netherlands.</p>
|
||||
</div>
|
||||
|
||||
<div class="pkgdown-footer-right">
|
||||
<p></p>
|
||||
<p><a target="_blank" href="https://www.rug.nl" class="external-link"><img src="https://github.com/msberends/AMR/raw/main/pkgdown/logos/logo_rug.svg" style="max-width: 150px;"></a><a target="_blank" href="https://www.umcg.nl" class="external-link"><img src="https://github.com/msberends/AMR/raw/main/pkgdown/logos/logo_umcg.svg" style="max-width: 150px;"></a></p>
|
||||
</div>
|
||||
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
After Width: | Height: | Size: 73 KiB |
@@ -0,0 +1,184 @@
|
||||
<!DOCTYPE html>
|
||||
<!-- Generated by pkgdown: do not edit by hand --><html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"><title>Articles • AMR (for R)</title><!-- favicons --><link rel="icon" type="image/png" sizes="16x16" href="../favicon-16x16.png"><link rel="icon" type="image/png" sizes="32x32" href="../favicon-32x32.png"><link rel="apple-touch-icon" type="image/png" sizes="180x180" href="../apple-touch-icon.png"><link rel="apple-touch-icon" type="image/png" sizes="120x120" href="../apple-touch-icon-120x120.png"><link rel="apple-touch-icon" type="image/png" sizes="76x76" href="../apple-touch-icon-76x76.png"><link rel="apple-touch-icon" type="image/png" sizes="60x60" href="../apple-touch-icon-60x60.png"><script src="../deps/jquery-3.6.0/jquery-3.6.0.min.js"></script><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"><link href="../deps/bootstrap-5.2.2/bootstrap.min.css" rel="stylesheet"><script src="../deps/bootstrap-5.2.2/bootstrap.bundle.min.js"></script><link href="../deps/Fira_Code-0.4.5/font.css" rel="stylesheet"><!-- Font Awesome icons --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css" integrity="sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk=" crossorigin="anonymous"><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/v4-shims.min.css" integrity="sha256-wZjR52fzng1pJHwx4aV2AO3yyTOXrcDW7jBpJtTwVxw=" crossorigin="anonymous"><!-- bootstrap-toc --><script src="https://cdn.jsdelivr.net/gh/afeld/bootstrap-toc@v1.0.1/dist/bootstrap-toc.min.js" integrity="sha256-4veVQbu7//Lk5TSmc7YV48MxtMy98e26cf5MrgZYnwo=" crossorigin="anonymous"></script><!-- headroom.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/headroom.min.js" integrity="sha256-AsUX4SJE1+yuDu5+mAVzJbuYNPHj/WroHuZ8Ir/CkE0=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/jQuery.headroom.min.js" integrity="sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4=" crossorigin="anonymous"></script><!-- clipboard.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js" integrity="sha256-inc5kl9MA1hkeYUt+EC3BhlIgyp/2jDIyBLS6k3UxPI=" crossorigin="anonymous"></script><!-- search --><script src="https://cdnjs.cloudflare.com/ajax/libs/fuse.js/6.4.6/fuse.js" integrity="sha512-zv6Ywkjyktsohkbp9bb45V6tEMoWhzFzXis+LrMehmJZZSys19Yxf1dopHx7WzIKxr5tK2dVcYmaCk2uqdjF4A==" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/autocomplete.js/0.38.0/autocomplete.jquery.min.js" integrity="sha512-GU9ayf+66Xx2TmpxqJpliWbT5PiGYxpaG8rfnBEk1LL8l1KGkRShhngwdXK1UgqhAzWpZHSiYPc09/NwDQIGyg==" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mark.js/8.11.1/mark.min.js" integrity="sha512-5CYOlHXGh6QpOFA/TeTylKLWfB3ftPsde7AnmhuitiTX4K5SqCLBeKro6sPS8ilsz1Q4NRx3v8Ko2IBiszzdww==" crossorigin="anonymous"></script><!-- pkgdown --><script src="../pkgdown.js"></script><link href="../extra.css" rel="stylesheet"><script src="../extra.js"></script><meta property="og:title" content="Articles"><meta property="og:image" content="https://msberends.github.io/AMR/logo.svg"><meta name="twitter:card" content="summary_large_image"><meta name="twitter:creator" content="@msberends"><meta name="twitter:site" content="@msberends"><!-- mathjax --><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script><!--[if lt IE 9]>
|
||||
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
|
||||
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
|
||||
<![endif]--></head><body>
|
||||
<a href="#main" class="visually-hidden-focusable">Skip to contents</a>
|
||||
|
||||
|
||||
<nav class="navbar fixed-top navbar-dark navbar-expand-lg bg-primary"><div class="container">
|
||||
|
||||
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
|
||||
|
||||
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">1.8.2.9139</small>
|
||||
|
||||
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<div id="navbar" class="collapse navbar-collapse ms-3">
|
||||
<ul class="navbar-nav me-auto"><li class="nav-item">
|
||||
<a class="nav-link" href="../index.html">
|
||||
<span class="fa fa-home"></span>
|
||||
|
||||
Home
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item dropdown">
|
||||
<a href="#" class="nav-link dropdown-toggle" data-bs-toggle="dropdown" role="button" aria-expanded="false" aria-haspopup="true" id="dropdown--how-to">
|
||||
<span class="fa fa-question-circle"></span>
|
||||
|
||||
How to
|
||||
</a>
|
||||
<div class="dropdown-menu" aria-labelledby="dropdown--how-to">
|
||||
<a class="dropdown-item" href="../reference/AMR-options.html">
|
||||
<span class="fa fa-gear"></span>
|
||||
|
||||
User- Or Team-specific Package Settings
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/AMR.html">
|
||||
<span class="fa fa-directions"></span>
|
||||
|
||||
Conduct AMR Analysis
|
||||
</a>
|
||||
<a class="dropdown-item" href="../reference/antibiogram.html">
|
||||
<span class="fa fa-file-prescription"></span>
|
||||
|
||||
Generate Antibiogram (Trad./Syndromic/WISCA)
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/resistance_predict.html">
|
||||
<span class="fa fa-dice"></span>
|
||||
|
||||
Predict Antimicrobial Resistance
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/datasets.html">
|
||||
<span class="fa fa-database"></span>
|
||||
|
||||
Data Sets for Download / Own Use
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/PCA.html">
|
||||
<span class="fa fa-compress"></span>
|
||||
|
||||
Conduct Principal Component Analysis for AMR
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/MDR.html">
|
||||
<span class="fa fa-skull-crossbones"></span>
|
||||
|
||||
Determine Multi-Drug Resistance (MDR)
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/WHONET.html">
|
||||
<span class="fa fa-globe-americas"></span>
|
||||
|
||||
Work with WHONET Data
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/SPSS.html">
|
||||
<span class="fa fa-file-upload"></span>
|
||||
|
||||
Import Data From SPSS/SAS/Stata
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/EUCAST.html">
|
||||
<span class="fa fa-exchange-alt"></span>
|
||||
|
||||
Apply Eucast Rules
|
||||
</a>
|
||||
<a class="dropdown-item" href="../reference/mo_property.html">
|
||||
<span class="fa fa-bug"></span>
|
||||
|
||||
Get Taxonomy of a Microorganism
|
||||
</a>
|
||||
<a class="dropdown-item" href="../reference/ab_property.html">
|
||||
<span class="fa fa-capsules"></span>
|
||||
|
||||
Get Properties of an Antibiotic Drug
|
||||
</a>
|
||||
<a class="dropdown-item" href="../reference/av_property.html">
|
||||
<span class="fa fa-capsules"></span>
|
||||
|
||||
Get Properties of an Antiviral Drug
|
||||
</a>
|
||||
</div>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="../reference/index.html">
|
||||
<span class="fa fa-book-open"></span>
|
||||
|
||||
Manual
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="../authors.html">
|
||||
<span class="fa fa-users"></span>
|
||||
|
||||
Authors
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="../news/index.html">
|
||||
<span class="far fa far fa-newspaper"></span>
|
||||
|
||||
Changelog
|
||||
</a>
|
||||
</li>
|
||||
</ul><form class="form-inline my-2 my-lg-0" role="search">
|
||||
<input type="search" class="form-control me-sm-2" aria-label="Toggle navigation" name="search-input" data-search-index="../search.json" id="search-input" placeholder="Search for" autocomplete="off"></form>
|
||||
|
||||
<ul class="navbar-nav"><li class="nav-item">
|
||||
<a class="external-link nav-link" href="https://github.com/msberends/AMR">
|
||||
<span class="fab fa fab fa-github"></span>
|
||||
|
||||
Source Code
|
||||
</a>
|
||||
</li>
|
||||
</ul></div>
|
||||
|
||||
|
||||
</div>
|
||||
</nav><div class="container template-article-index">
|
||||
<div class="row">
|
||||
<main id="main" class="col-md-9"><div class="page-header">
|
||||
<img src="../logo.svg" class="logo" alt=""><h1>Articles</h1>
|
||||
</div>
|
||||
|
||||
<div class="section ">
|
||||
<h3>All vignettes</h3>
|
||||
<p class="section-desc"></p>
|
||||
|
||||
<dl><dt><a href="AMR.html">How to conduct AMR data analysis</a></dt>
|
||||
<dd>
|
||||
</dd><dt><a href="EUCAST.html">How to apply EUCAST rules</a></dt>
|
||||
<dd>
|
||||
</dd><dt><a href="MDR.html">How to determine multi-drug resistance (MDR)</a></dt>
|
||||
<dd>
|
||||
</dd><dt><a href="PCA.html">How to conduct principal component analysis (PCA) for AMR</a></dt>
|
||||
<dd>
|
||||
</dd><dt><a href="SPSS.html">How to import data from SPSS / SAS / Stata</a></dt>
|
||||
<dd>
|
||||
</dd><dt><a href="WHONET.html">How to work with WHONET data</a></dt>
|
||||
<dd>
|
||||
</dd><dt><a href="datasets.html">Data sets for download / own use</a></dt>
|
||||
<dd>
|
||||
</dd><dt><a href="resistance_predict.html">How to predict antimicrobial resistance</a></dt>
|
||||
<dd>
|
||||
</dd><dt><a href="welcome_to_AMR.html">Welcome to the `AMR` package</a></dt>
|
||||
<dd>
|
||||
</dd></dl></div>
|
||||
</main></div>
|
||||
|
||||
|
||||
<footer><div class="pkgdown-footer-left">
|
||||
<p></p><p><code>AMR</code> (for R). Free and open-source, licenced under the <a target="_blank" href="https://github.com/msberends/AMR/blob/main/LICENSE" class="external-link">GNU General Public License version 2.0 (GPL-2)</a>.<br>Developed at the <a target="_blank" href="https://www.rug.nl" class="external-link">University of Groningen</a> and <a target="_blank" href="https://www.umcg.nl" class="external-link">University Medical Center Groningen</a> in The Netherlands.</p>
|
||||
</div>
|
||||
|
||||
<div class="pkgdown-footer-right">
|
||||
<p></p><p><a target="_blank" href="https://www.rug.nl" class="external-link"><img src="https://github.com/msberends/AMR/raw/main/pkgdown/logos/logo_rug.svg" style="max-width: 150px;"></a><a target="_blank" href="https://www.umcg.nl" class="external-link"><img src="https://github.com/msberends/AMR/raw/main/pkgdown/logos/logo_umcg.svg" style="max-width: 150px;"></a></p>
|
||||
</div>
|
||||
|
||||
</footer></div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</body></html>
|
||||
|
||||
@@ -0,0 +1,379 @@
|
||||
<!DOCTYPE html>
|
||||
<!-- Generated by pkgdown: do not edit by hand --><html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<meta name="description" content="AMR">
|
||||
<title>How to predict antimicrobial resistance • AMR (for R)</title>
|
||||
<!-- favicons --><link rel="icon" type="image/png" sizes="16x16" href="../favicon-16x16.png">
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="../favicon-32x32.png">
|
||||
<link rel="apple-touch-icon" type="image/png" sizes="180x180" href="../apple-touch-icon.png">
|
||||
<link rel="apple-touch-icon" type="image/png" sizes="120x120" href="../apple-touch-icon-120x120.png">
|
||||
<link rel="apple-touch-icon" type="image/png" sizes="76x76" href="../apple-touch-icon-76x76.png">
|
||||
<link rel="apple-touch-icon" type="image/png" sizes="60x60" href="../apple-touch-icon-60x60.png">
|
||||
<script src="../deps/jquery-3.6.0/jquery-3.6.0.min.js"></script><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<link href="../deps/bootstrap-5.2.2/bootstrap.min.css" rel="stylesheet">
|
||||
<script src="../deps/bootstrap-5.2.2/bootstrap.bundle.min.js"></script><link href="../deps/Fira_Code-0.4.5/font.css" rel="stylesheet">
|
||||
<!-- Font Awesome icons --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css" integrity="sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk=" crossorigin="anonymous">
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/v4-shims.min.css" integrity="sha256-wZjR52fzng1pJHwx4aV2AO3yyTOXrcDW7jBpJtTwVxw=" crossorigin="anonymous">
|
||||
<!-- bootstrap-toc --><script src="https://cdn.jsdelivr.net/gh/afeld/bootstrap-toc@v1.0.1/dist/bootstrap-toc.min.js" integrity="sha256-4veVQbu7//Lk5TSmc7YV48MxtMy98e26cf5MrgZYnwo=" crossorigin="anonymous"></script><!-- headroom.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/headroom.min.js" integrity="sha256-AsUX4SJE1+yuDu5+mAVzJbuYNPHj/WroHuZ8Ir/CkE0=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/jQuery.headroom.min.js" integrity="sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4=" crossorigin="anonymous"></script><!-- clipboard.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js" integrity="sha256-inc5kl9MA1hkeYUt+EC3BhlIgyp/2jDIyBLS6k3UxPI=" crossorigin="anonymous"></script><!-- search --><script src="https://cdnjs.cloudflare.com/ajax/libs/fuse.js/6.4.6/fuse.js" integrity="sha512-zv6Ywkjyktsohkbp9bb45V6tEMoWhzFzXis+LrMehmJZZSys19Yxf1dopHx7WzIKxr5tK2dVcYmaCk2uqdjF4A==" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/autocomplete.js/0.38.0/autocomplete.jquery.min.js" integrity="sha512-GU9ayf+66Xx2TmpxqJpliWbT5PiGYxpaG8rfnBEk1LL8l1KGkRShhngwdXK1UgqhAzWpZHSiYPc09/NwDQIGyg==" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mark.js/8.11.1/mark.min.js" integrity="sha512-5CYOlHXGh6QpOFA/TeTylKLWfB3ftPsde7AnmhuitiTX4K5SqCLBeKro6sPS8ilsz1Q4NRx3v8Ko2IBiszzdww==" crossorigin="anonymous"></script><!-- pkgdown --><script src="../pkgdown.js"></script><link href="../extra.css" rel="stylesheet">
|
||||
<script src="../extra.js"></script><meta property="og:title" content="How to predict antimicrobial resistance">
|
||||
<meta property="og:description" content="AMR">
|
||||
<meta property="og:image" content="https://msberends.github.io/AMR/logo.svg">
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
<meta name="twitter:creator" content="@msberends">
|
||||
<meta name="twitter:site" content="@msberends">
|
||||
<!-- mathjax --><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script><!--[if lt IE 9]>
|
||||
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
|
||||
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
|
||||
<![endif]-->
|
||||
</head>
|
||||
<body>
|
||||
<a href="#main" class="visually-hidden-focusable">Skip to contents</a>
|
||||
|
||||
|
||||
<nav class="navbar fixed-top navbar-dark navbar-expand-lg bg-primary"><div class="container">
|
||||
|
||||
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
|
||||
|
||||
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">1.8.2.9139</small>
|
||||
|
||||
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<div id="navbar" class="collapse navbar-collapse ms-3">
|
||||
<ul class="navbar-nav me-auto">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="../index.html">
|
||||
<span class="fa fa-home"></span>
|
||||
|
||||
Home
|
||||
</a>
|
||||
</li>
|
||||
<li class="active nav-item dropdown">
|
||||
<a href="#" class="nav-link dropdown-toggle" data-bs-toggle="dropdown" role="button" aria-expanded="false" aria-haspopup="true" id="dropdown--how-to">
|
||||
<span class="fa fa-question-circle"></span>
|
||||
|
||||
How to
|
||||
</a>
|
||||
<div class="dropdown-menu" aria-labelledby="dropdown--how-to">
|
||||
<a class="dropdown-item" href="../reference/AMR-options.html">
|
||||
<span class="fa fa-gear"></span>
|
||||
|
||||
User- Or Team-specific Package Settings
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/AMR.html">
|
||||
<span class="fa fa-directions"></span>
|
||||
|
||||
Conduct AMR Analysis
|
||||
</a>
|
||||
<a class="dropdown-item" href="../reference/antibiogram.html">
|
||||
<span class="fa fa-file-prescription"></span>
|
||||
|
||||
Generate Antibiogram (Trad./Syndromic/WISCA)
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/resistance_predict.html">
|
||||
<span class="fa fa-dice"></span>
|
||||
|
||||
Predict Antimicrobial Resistance
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/datasets.html">
|
||||
<span class="fa fa-database"></span>
|
||||
|
||||
Data Sets for Download / Own Use
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/PCA.html">
|
||||
<span class="fa fa-compress"></span>
|
||||
|
||||
Conduct Principal Component Analysis for AMR
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/MDR.html">
|
||||
<span class="fa fa-skull-crossbones"></span>
|
||||
|
||||
Determine Multi-Drug Resistance (MDR)
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/WHONET.html">
|
||||
<span class="fa fa-globe-americas"></span>
|
||||
|
||||
Work with WHONET Data
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/SPSS.html">
|
||||
<span class="fa fa-file-upload"></span>
|
||||
|
||||
Import Data From SPSS/SAS/Stata
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/EUCAST.html">
|
||||
<span class="fa fa-exchange-alt"></span>
|
||||
|
||||
Apply Eucast Rules
|
||||
</a>
|
||||
<a class="dropdown-item" href="../reference/mo_property.html">
|
||||
<span class="fa fa-bug"></span>
|
||||
|
||||
Get Taxonomy of a Microorganism
|
||||
</a>
|
||||
<a class="dropdown-item" href="../reference/ab_property.html">
|
||||
<span class="fa fa-capsules"></span>
|
||||
|
||||
Get Properties of an Antibiotic Drug
|
||||
</a>
|
||||
<a class="dropdown-item" href="../reference/av_property.html">
|
||||
<span class="fa fa-capsules"></span>
|
||||
|
||||
Get Properties of an Antiviral Drug
|
||||
</a>
|
||||
</div>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="../reference/index.html">
|
||||
<span class="fa fa-book-open"></span>
|
||||
|
||||
Manual
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="../authors.html">
|
||||
<span class="fa fa-users"></span>
|
||||
|
||||
Authors
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="../news/index.html">
|
||||
<span class="far fa far fa-newspaper"></span>
|
||||
|
||||
Changelog
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
<form class="form-inline my-2 my-lg-0" role="search">
|
||||
<input type="search" class="form-control me-sm-2" aria-label="Toggle navigation" name="search-input" data-search-index="../search.json" id="search-input" placeholder="Search for" autocomplete="off">
|
||||
</form>
|
||||
|
||||
<ul class="navbar-nav">
|
||||
<li class="nav-item">
|
||||
<a class="external-link nav-link" href="https://github.com/msberends/AMR">
|
||||
<span class="fab fa fab fa-github"></span>
|
||||
|
||||
Source Code
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</nav><div class="container template-article">
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="row">
|
||||
<main id="main" class="col-md-9"><div class="page-header">
|
||||
<img src="../logo.svg" class="logo" alt=""><h1>How to predict antimicrobial resistance</h1>
|
||||
|
||||
|
||||
<small class="dont-index">Source: <a href="https://github.com/msberends/AMR/blob/HEAD/vignettes/resistance_predict.Rmd" class="external-link"><code>vignettes/resistance_predict.Rmd</code></a></small>
|
||||
<div class="d-none name"><code>resistance_predict.Rmd</code></div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div class="section level2">
|
||||
<h2 id="needed-r-packages">Needed R packages<a class="anchor" aria-label="anchor" href="#needed-r-packages"></a>
|
||||
</h2>
|
||||
<p>As with many uses in R, we need some additional packages for AMR data
|
||||
analysis. Our package works closely together with the <a href="https://www.tidyverse.org" class="external-link">tidyverse packages</a> <a href="https://dplyr.tidyverse.org/" class="external-link"><code>dplyr</code></a> and <a href="https://ggplot2.tidyverse.org" class="external-link"><code>ggplot2</code></a>. The
|
||||
tidyverse tremendously improves the way we conduct data science - it
|
||||
allows for a very natural way of writing syntaxes and creating beautiful
|
||||
plots in R.</p>
|
||||
<p>Our <code>AMR</code> package depends on these packages and even
|
||||
extends their use and functions.</p>
|
||||
<div class="sourceCode" id="cb1"><pre class="downlit sourceCode r">
|
||||
<code class="sourceCode R"><span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://dplyr.tidyverse.org" class="external-link">dplyr</a></span><span class="op">)</span></span>
|
||||
<span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://ggplot2.tidyverse.org" class="external-link">ggplot2</a></span><span class="op">)</span></span>
|
||||
<span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://msberends.github.io/AMR/">AMR</a></span><span class="op">)</span></span>
|
||||
<span></span>
|
||||
<span><span class="co"># (if not yet installed, install with:)</span></span>
|
||||
<span><span class="co"># install.packages(c("tidyverse", "AMR"))</span></span></code></pre></div>
|
||||
</div>
|
||||
<div class="section level2">
|
||||
<h2 id="prediction-analysis">Prediction analysis<a class="anchor" aria-label="anchor" href="#prediction-analysis"></a>
|
||||
</h2>
|
||||
<p>Our package contains a function <code><a href="../reference/resistance_predict.html">resistance_predict()</a></code>,
|
||||
which takes the same input as functions for <a href="./AMR.html">other
|
||||
AMR data analysis</a>. Based on a date column, it calculates cases per
|
||||
year and uses a regression model to predict antimicrobial
|
||||
resistance.</p>
|
||||
<p>It is basically as easy as:</p>
|
||||
<div class="sourceCode" id="cb2"><pre class="downlit sourceCode r">
|
||||
<code class="sourceCode R"><span><span class="co"># resistance prediction of piperacillin/tazobactam (TZP):</span></span>
|
||||
<span><span class="fu"><a href="../reference/resistance_predict.html">resistance_predict</a></span><span class="op">(</span>tbl <span class="op">=</span> <span class="va">example_isolates</span>, col_date <span class="op">=</span> <span class="st">"date"</span>, col_ab <span class="op">=</span> <span class="st">"TZP"</span>, model <span class="op">=</span> <span class="st">"binomial"</span><span class="op">)</span></span>
|
||||
<span></span>
|
||||
<span><span class="co"># or:</span></span>
|
||||
<span><span class="va">example_isolates</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%>%</a></span></span>
|
||||
<span> <span class="fu"><a href="../reference/resistance_predict.html">resistance_predict</a></span><span class="op">(</span></span>
|
||||
<span> col_ab <span class="op">=</span> <span class="st">"TZP"</span>,</span>
|
||||
<span> model <span class="op">=</span> <span class="st">"binomial"</span></span>
|
||||
<span> <span class="op">)</span></span>
|
||||
<span></span>
|
||||
<span><span class="co"># to bind it to object 'predict_TZP' for example:</span></span>
|
||||
<span><span class="va">predict_TZP</span> <span class="op"><-</span> <span class="va">example_isolates</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%>%</a></span></span>
|
||||
<span> <span class="fu"><a href="../reference/resistance_predict.html">resistance_predict</a></span><span class="op">(</span></span>
|
||||
<span> col_ab <span class="op">=</span> <span class="st">"TZP"</span>,</span>
|
||||
<span> model <span class="op">=</span> <span class="st">"binomial"</span></span>
|
||||
<span> <span class="op">)</span></span></code></pre></div>
|
||||
<p>The function will look for a date column itself if
|
||||
<code>col_date</code> is not set.</p>
|
||||
<p>When running any of these commands, a summary of the regression model
|
||||
will be printed unless using
|
||||
<code>resistance_predict(..., info = FALSE)</code>.</p>
|
||||
<p>This text is only a printed summary - the actual result (output) of
|
||||
the function is a <code>data.frame</code> containing for each year: the
|
||||
number of observations, the actual observed resistance, the estimated
|
||||
resistance and the standard error below and above the estimation:</p>
|
||||
<div class="sourceCode" id="cb3"><pre class="downlit sourceCode r">
|
||||
<code class="sourceCode R"><span><span class="va">predict_TZP</span></span>
|
||||
<span><span class="co">#> <span style="color: #949494;"># A tibble: 32 × 7</span></span></span>
|
||||
<span><span class="co">#> year value se_min se_max observations observed estimated</span></span>
|
||||
<span><span class="co">#> <span style="color: #BCBCBC;">*</span> <span style="color: #949494; font-style: italic;"><dbl></span> <span style="color: #949494; font-style: italic;"><dbl></span> <span style="color: #949494; font-style: italic;"><dbl></span> <span style="color: #949494; font-style: italic;"><dbl></span> <span style="color: #949494; font-style: italic;"><int></span> <span style="color: #949494; font-style: italic;"><dbl></span> <span style="color: #949494; font-style: italic;"><dbl></span></span></span>
|
||||
<span><span class="co">#> <span style="color: #BCBCBC;"> 1</span> <span style="text-decoration: underline;">2</span>002 0.2 <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> 15 0.2 0.056<span style="text-decoration: underline;">2</span></span></span>
|
||||
<span><span class="co">#> <span style="color: #BCBCBC;"> 2</span> <span style="text-decoration: underline;">2</span>003 0.062<span style="text-decoration: underline;">5</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> 32 0.062<span style="text-decoration: underline;">5</span> 0.061<span style="text-decoration: underline;">6</span></span></span>
|
||||
<span><span class="co">#> <span style="color: #BCBCBC;"> 3</span> <span style="text-decoration: underline;">2</span>004 0.085<span style="text-decoration: underline;">4</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> 82 0.085<span style="text-decoration: underline;">4</span> 0.067<span style="text-decoration: underline;">6</span></span></span>
|
||||
<span><span class="co">#> <span style="color: #BCBCBC;"> 4</span> <span style="text-decoration: underline;">2</span>005 0.05 <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> 60 0.05 0.074<span style="text-decoration: underline;">1</span></span></span>
|
||||
<span><span class="co">#> <span style="color: #BCBCBC;"> 5</span> <span style="text-decoration: underline;">2</span>006 0.050<span style="text-decoration: underline;">8</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> 59 0.050<span style="text-decoration: underline;">8</span> 0.081<span style="text-decoration: underline;">2</span></span></span>
|
||||
<span><span class="co">#> <span style="color: #BCBCBC;"> 6</span> <span style="text-decoration: underline;">2</span>007 0.121 <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> 66 0.121 0.088<span style="text-decoration: underline;">9</span></span></span>
|
||||
<span><span class="co">#> <span style="color: #BCBCBC;"> 7</span> <span style="text-decoration: underline;">2</span>008 0.041<span style="text-decoration: underline;">7</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> 72 0.041<span style="text-decoration: underline;">7</span> 0.097<span style="text-decoration: underline;">2</span></span></span>
|
||||
<span><span class="co">#> <span style="color: #BCBCBC;"> 8</span> <span style="text-decoration: underline;">2</span>009 0.016<span style="text-decoration: underline;">4</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> 61 0.016<span style="text-decoration: underline;">4</span> 0.106 </span></span>
|
||||
<span><span class="co">#> <span style="color: #BCBCBC;"> 9</span> <span style="text-decoration: underline;">2</span>010 0.056<span style="text-decoration: underline;">6</span> <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> 53 0.056<span style="text-decoration: underline;">6</span> 0.116 </span></span>
|
||||
<span><span class="co">#> <span style="color: #BCBCBC;">10</span> <span style="text-decoration: underline;">2</span>011 0.183 <span style="color: #BB0000;">NA</span> <span style="color: #BB0000;">NA</span> 93 0.183 0.127 </span></span>
|
||||
<span><span class="co">#> <span style="color: #949494;"># … with 22 more rows</span></span></span></code></pre></div>
|
||||
<p>The function <code>plot</code> is available in base R, and can be
|
||||
extended by other packages to depend the output based on the type of
|
||||
input. We extended its function to cope with resistance predictions:</p>
|
||||
<div class="sourceCode" id="cb4"><pre class="downlit sourceCode r">
|
||||
<code class="sourceCode R"><span><span class="fu"><a href="../reference/plot.html">plot</a></span><span class="op">(</span><span class="va">predict_TZP</span><span class="op">)</span></span></code></pre></div>
|
||||
<p><img src="resistance_predict_files/figure-html/unnamed-chunk-4-1.png" width="720"></p>
|
||||
<p>This is the fastest way to plot the result. It automatically adds the
|
||||
right axes, error bars, titles, number of available observations and
|
||||
type of model.</p>
|
||||
<p>We also support the <code>ggplot2</code> package with our custom
|
||||
function <code><a href="../reference/resistance_predict.html">ggplot_sir_predict()</a></code> to create more appealing
|
||||
plots:</p>
|
||||
<div class="sourceCode" id="cb5"><pre class="downlit sourceCode r">
|
||||
<code class="sourceCode R"><span><span class="fu"><a href="../reference/resistance_predict.html">ggplot_sir_predict</a></span><span class="op">(</span><span class="va">predict_TZP</span><span class="op">)</span></span></code></pre></div>
|
||||
<p><img src="resistance_predict_files/figure-html/unnamed-chunk-5-1.png" width="720"></p>
|
||||
<div class="sourceCode" id="cb6"><pre class="downlit sourceCode r">
|
||||
<code class="sourceCode R"><span></span>
|
||||
<span><span class="co"># choose for error bars instead of a ribbon</span></span>
|
||||
<span><span class="fu"><a href="../reference/resistance_predict.html">ggplot_sir_predict</a></span><span class="op">(</span><span class="va">predict_TZP</span>, ribbon <span class="op">=</span> <span class="cn">FALSE</span><span class="op">)</span></span></code></pre></div>
|
||||
<p><img src="resistance_predict_files/figure-html/unnamed-chunk-5-2.png" width="720"></p>
|
||||
<div class="section level3">
|
||||
<h3 id="choosing-the-right-model">Choosing the right model<a class="anchor" aria-label="anchor" href="#choosing-the-right-model"></a>
|
||||
</h3>
|
||||
<p>Resistance is not easily predicted; if we look at vancomycin
|
||||
resistance in Gram-positive bacteria, the spread (i.e. standard error)
|
||||
is enormous:</p>
|
||||
<div class="sourceCode" id="cb7"><pre class="downlit sourceCode r">
|
||||
<code class="sourceCode R"><span><span class="va">example_isolates</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%>%</a></span></span>
|
||||
<span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/filter.html" class="external-link">filter</a></span><span class="op">(</span><span class="fu"><a href="../reference/mo_property.html">mo_gramstain</a></span><span class="op">(</span><span class="va">mo</span>, language <span class="op">=</span> <span class="cn">NULL</span><span class="op">)</span> <span class="op">==</span> <span class="st">"Gram-positive"</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%>%</a></span></span>
|
||||
<span> <span class="fu"><a href="../reference/resistance_predict.html">resistance_predict</a></span><span class="op">(</span>col_ab <span class="op">=</span> <span class="st">"VAN"</span>, year_min <span class="op">=</span> <span class="fl">2010</span>, info <span class="op">=</span> <span class="cn">FALSE</span>, model <span class="op">=</span> <span class="st">"binomial"</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%>%</a></span></span>
|
||||
<span> <span class="fu"><a href="../reference/resistance_predict.html">ggplot_sir_predict</a></span><span class="op">(</span><span class="op">)</span></span></code></pre></div>
|
||||
<p><img src="resistance_predict_files/figure-html/unnamed-chunk-6-1.png" width="720"></p>
|
||||
<p>Vancomycin resistance could be 100% in ten years, but might remain
|
||||
very low.</p>
|
||||
<p>You can define the model with the <code>model</code> parameter. The
|
||||
model chosen above is a generalised linear regression model using a
|
||||
binomial distribution, assuming that a period of zero resistance was
|
||||
followed by a period of increasing resistance leading slowly to more and
|
||||
more resistance.</p>
|
||||
<p>Valid values are:</p>
|
||||
<table class="table">
|
||||
<colgroup>
|
||||
<col width="32%">
|
||||
<col width="25%">
|
||||
<col width="42%">
|
||||
</colgroup>
|
||||
<thead><tr class="header">
|
||||
<th>Input values</th>
|
||||
<th>Function used by R</th>
|
||||
<th>Type of model</th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<tr class="odd">
|
||||
<td>
|
||||
<code>"binomial"</code> or <code>"binom"</code> or
|
||||
<code>"logit"</code>
|
||||
</td>
|
||||
<td><code>glm(..., family = binomial)</code></td>
|
||||
<td>Generalised linear model with binomial distribution</td>
|
||||
</tr>
|
||||
<tr class="even">
|
||||
<td>
|
||||
<code>"loglin"</code> or <code>"poisson"</code>
|
||||
</td>
|
||||
<td><code>glm(..., family = poisson)</code></td>
|
||||
<td>Generalised linear model with poisson distribution</td>
|
||||
</tr>
|
||||
<tr class="odd">
|
||||
<td>
|
||||
<code>"lin"</code> or <code>"linear"</code>
|
||||
</td>
|
||||
<td><code><a href="https://rdrr.io/r/stats/lm.html" class="external-link">lm()</a></code></td>
|
||||
<td>Linear model</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p>For the vancomycin resistance in Gram-positive bacteria, a linear
|
||||
model might be more appropriate:</p>
|
||||
<div class="sourceCode" id="cb8"><pre class="downlit sourceCode r">
|
||||
<code class="sourceCode R"><span><span class="va">example_isolates</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%>%</a></span></span>
|
||||
<span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/filter.html" class="external-link">filter</a></span><span class="op">(</span><span class="fu"><a href="../reference/mo_property.html">mo_gramstain</a></span><span class="op">(</span><span class="va">mo</span>, language <span class="op">=</span> <span class="cn">NULL</span><span class="op">)</span> <span class="op">==</span> <span class="st">"Gram-positive"</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%>%</a></span></span>
|
||||
<span> <span class="fu"><a href="../reference/resistance_predict.html">resistance_predict</a></span><span class="op">(</span>col_ab <span class="op">=</span> <span class="st">"VAN"</span>, year_min <span class="op">=</span> <span class="fl">2010</span>, info <span class="op">=</span> <span class="cn">FALSE</span>, model <span class="op">=</span> <span class="st">"linear"</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%>%</a></span></span>
|
||||
<span> <span class="fu"><a href="../reference/resistance_predict.html">ggplot_sir_predict</a></span><span class="op">(</span><span class="op">)</span></span></code></pre></div>
|
||||
<p><img src="resistance_predict_files/figure-html/unnamed-chunk-7-1.png" width="720"></p>
|
||||
<p>The model itself is also available from the object, as an
|
||||
<code>attribute</code>:</p>
|
||||
<div class="sourceCode" id="cb9"><pre class="downlit sourceCode r">
|
||||
<code class="sourceCode R"><span><span class="va">model</span> <span class="op"><-</span> <span class="fu"><a href="https://rdrr.io/r/base/attributes.html" class="external-link">attributes</a></span><span class="op">(</span><span class="va">predict_TZP</span><span class="op">)</span><span class="op">$</span><span class="va">model</span></span>
|
||||
<span></span>
|
||||
<span><span class="fu"><a href="https://rdrr.io/r/base/summary.html" class="external-link">summary</a></span><span class="op">(</span><span class="va">model</span><span class="op">)</span><span class="op">$</span><span class="va">family</span></span>
|
||||
<span><span class="co">#> </span></span>
|
||||
<span><span class="co">#> Family: binomial </span></span>
|
||||
<span><span class="co">#> Link function: logit</span></span>
|
||||
<span></span>
|
||||
<span><span class="fu"><a href="https://rdrr.io/r/base/summary.html" class="external-link">summary</a></span><span class="op">(</span><span class="va">model</span><span class="op">)</span><span class="op">$</span><span class="va">coefficients</span></span>
|
||||
<span><span class="co">#> Estimate Std. Error z value Pr(>|z|)</span></span>
|
||||
<span><span class="co">#> (Intercept) -200.67944891 46.17315349 -4.346237 1.384932e-05</span></span>
|
||||
<span><span class="co">#> year 0.09883005 0.02295317 4.305725 1.664395e-05</span></span></code></pre></div>
|
||||
</div>
|
||||
</div>
|
||||
</main><aside class="col-md-3"><nav id="toc"><h2>On this page</h2>
|
||||
</nav></aside>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<footer><div class="pkgdown-footer-left">
|
||||
<p></p>
|
||||
<p><code>AMR</code> (for R). Free and open-source, licenced under the <a target="_blank" href="https://github.com/msberends/AMR/blob/main/LICENSE" class="external-link">GNU General Public License version 2.0 (GPL-2)</a>.<br>Developed at the <a target="_blank" href="https://www.rug.nl" class="external-link">University of Groningen</a> and <a target="_blank" href="https://www.umcg.nl" class="external-link">University Medical Center Groningen</a> in The Netherlands.</p>
|
||||
</div>
|
||||
|
||||
<div class="pkgdown-footer-right">
|
||||
<p></p>
|
||||
<p><a target="_blank" href="https://www.rug.nl" class="external-link"><img src="https://github.com/msberends/AMR/raw/main/pkgdown/logos/logo_rug.svg" style="max-width: 150px;"></a><a target="_blank" href="https://www.umcg.nl" class="external-link"><img src="https://github.com/msberends/AMR/raw/main/pkgdown/logos/logo_umcg.svg" style="max-width: 150px;"></a></p>
|
||||
</div>
|
||||
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
After Width: | Height: | Size: 50 KiB |
|
After Width: | Height: | Size: 73 KiB |
|
After Width: | Height: | Size: 71 KiB |
|
After Width: | Height: | Size: 76 KiB |
|
After Width: | Height: | Size: 68 KiB |
@@ -0,0 +1,301 @@
|
||||
<!DOCTYPE html>
|
||||
<!-- Generated by pkgdown: do not edit by hand --><html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<meta name="description" content="AMR">
|
||||
<title>Welcome to the `AMR` package • AMR (for R)</title>
|
||||
<!-- favicons --><link rel="icon" type="image/png" sizes="16x16" href="../favicon-16x16.png">
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="../favicon-32x32.png">
|
||||
<link rel="apple-touch-icon" type="image/png" sizes="180x180" href="../apple-touch-icon.png">
|
||||
<link rel="apple-touch-icon" type="image/png" sizes="120x120" href="../apple-touch-icon-120x120.png">
|
||||
<link rel="apple-touch-icon" type="image/png" sizes="76x76" href="../apple-touch-icon-76x76.png">
|
||||
<link rel="apple-touch-icon" type="image/png" sizes="60x60" href="../apple-touch-icon-60x60.png">
|
||||
<script src="../deps/jquery-3.6.0/jquery-3.6.0.min.js"></script><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<link href="../deps/bootstrap-5.2.2/bootstrap.min.css" rel="stylesheet">
|
||||
<script src="../deps/bootstrap-5.2.2/bootstrap.bundle.min.js"></script><link href="../deps/Fira_Code-0.4.5/font.css" rel="stylesheet">
|
||||
<!-- Font Awesome icons --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css" integrity="sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk=" crossorigin="anonymous">
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/v4-shims.min.css" integrity="sha256-wZjR52fzng1pJHwx4aV2AO3yyTOXrcDW7jBpJtTwVxw=" crossorigin="anonymous">
|
||||
<!-- bootstrap-toc --><script src="https://cdn.jsdelivr.net/gh/afeld/bootstrap-toc@v1.0.1/dist/bootstrap-toc.min.js" integrity="sha256-4veVQbu7//Lk5TSmc7YV48MxtMy98e26cf5MrgZYnwo=" crossorigin="anonymous"></script><!-- headroom.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/headroom.min.js" integrity="sha256-AsUX4SJE1+yuDu5+mAVzJbuYNPHj/WroHuZ8Ir/CkE0=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/jQuery.headroom.min.js" integrity="sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4=" crossorigin="anonymous"></script><!-- clipboard.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js" integrity="sha256-inc5kl9MA1hkeYUt+EC3BhlIgyp/2jDIyBLS6k3UxPI=" crossorigin="anonymous"></script><!-- search --><script src="https://cdnjs.cloudflare.com/ajax/libs/fuse.js/6.4.6/fuse.js" integrity="sha512-zv6Ywkjyktsohkbp9bb45V6tEMoWhzFzXis+LrMehmJZZSys19Yxf1dopHx7WzIKxr5tK2dVcYmaCk2uqdjF4A==" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/autocomplete.js/0.38.0/autocomplete.jquery.min.js" integrity="sha512-GU9ayf+66Xx2TmpxqJpliWbT5PiGYxpaG8rfnBEk1LL8l1KGkRShhngwdXK1UgqhAzWpZHSiYPc09/NwDQIGyg==" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mark.js/8.11.1/mark.min.js" integrity="sha512-5CYOlHXGh6QpOFA/TeTylKLWfB3ftPsde7AnmhuitiTX4K5SqCLBeKro6sPS8ilsz1Q4NRx3v8Ko2IBiszzdww==" crossorigin="anonymous"></script><!-- pkgdown --><script src="../pkgdown.js"></script><link href="../extra.css" rel="stylesheet">
|
||||
<script src="../extra.js"></script><meta property="og:title" content="Welcome to the `AMR` package">
|
||||
<meta property="og:description" content="AMR">
|
||||
<meta property="og:image" content="https://msberends.github.io/AMR/logo.svg">
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
<meta name="twitter:creator" content="@msberends">
|
||||
<meta name="twitter:site" content="@msberends">
|
||||
<!-- mathjax --><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script><!--[if lt IE 9]>
|
||||
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
|
||||
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
|
||||
<![endif]-->
|
||||
</head>
|
||||
<body>
|
||||
<a href="#main" class="visually-hidden-focusable">Skip to contents</a>
|
||||
|
||||
|
||||
<nav class="navbar fixed-top navbar-dark navbar-expand-lg bg-primary"><div class="container">
|
||||
|
||||
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
|
||||
|
||||
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">1.8.2.9139</small>
|
||||
|
||||
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<div id="navbar" class="collapse navbar-collapse ms-3">
|
||||
<ul class="navbar-nav me-auto">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="../index.html">
|
||||
<span class="fa fa-home"></span>
|
||||
|
||||
Home
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item dropdown">
|
||||
<a href="#" class="nav-link dropdown-toggle" data-bs-toggle="dropdown" role="button" aria-expanded="false" aria-haspopup="true" id="dropdown--how-to">
|
||||
<span class="fa fa-question-circle"></span>
|
||||
|
||||
How to
|
||||
</a>
|
||||
<div class="dropdown-menu" aria-labelledby="dropdown--how-to">
|
||||
<a class="dropdown-item" href="../reference/AMR-options.html">
|
||||
<span class="fa fa-gear"></span>
|
||||
|
||||
User- Or Team-specific Package Settings
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/AMR.html">
|
||||
<span class="fa fa-directions"></span>
|
||||
|
||||
Conduct AMR Analysis
|
||||
</a>
|
||||
<a class="dropdown-item" href="../reference/antibiogram.html">
|
||||
<span class="fa fa-file-prescription"></span>
|
||||
|
||||
Generate Antibiogram (Trad./Syndromic/WISCA)
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/resistance_predict.html">
|
||||
<span class="fa fa-dice"></span>
|
||||
|
||||
Predict Antimicrobial Resistance
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/datasets.html">
|
||||
<span class="fa fa-database"></span>
|
||||
|
||||
Data Sets for Download / Own Use
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/PCA.html">
|
||||
<span class="fa fa-compress"></span>
|
||||
|
||||
Conduct Principal Component Analysis for AMR
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/MDR.html">
|
||||
<span class="fa fa-skull-crossbones"></span>
|
||||
|
||||
Determine Multi-Drug Resistance (MDR)
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/WHONET.html">
|
||||
<span class="fa fa-globe-americas"></span>
|
||||
|
||||
Work with WHONET Data
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/SPSS.html">
|
||||
<span class="fa fa-file-upload"></span>
|
||||
|
||||
Import Data From SPSS/SAS/Stata
|
||||
</a>
|
||||
<a class="dropdown-item" href="../articles/EUCAST.html">
|
||||
<span class="fa fa-exchange-alt"></span>
|
||||
|
||||
Apply Eucast Rules
|
||||
</a>
|
||||
<a class="dropdown-item" href="../reference/mo_property.html">
|
||||
<span class="fa fa-bug"></span>
|
||||
|
||||
Get Taxonomy of a Microorganism
|
||||
</a>
|
||||
<a class="dropdown-item" href="../reference/ab_property.html">
|
||||
<span class="fa fa-capsules"></span>
|
||||
|
||||
Get Properties of an Antibiotic Drug
|
||||
</a>
|
||||
<a class="dropdown-item" href="../reference/av_property.html">
|
||||
<span class="fa fa-capsules"></span>
|
||||
|
||||
Get Properties of an Antiviral Drug
|
||||
</a>
|
||||
</div>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="../reference/index.html">
|
||||
<span class="fa fa-book-open"></span>
|
||||
|
||||
Manual
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="../authors.html">
|
||||
<span class="fa fa-users"></span>
|
||||
|
||||
Authors
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="../news/index.html">
|
||||
<span class="far fa far fa-newspaper"></span>
|
||||
|
||||
Changelog
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
<form class="form-inline my-2 my-lg-0" role="search">
|
||||
<input type="search" class="form-control me-sm-2" aria-label="Toggle navigation" name="search-input" data-search-index="../search.json" id="search-input" placeholder="Search for" autocomplete="off">
|
||||
</form>
|
||||
|
||||
<ul class="navbar-nav">
|
||||
<li class="nav-item">
|
||||
<a class="external-link nav-link" href="https://github.com/msberends/AMR">
|
||||
<span class="fab fa fab fa-github"></span>
|
||||
|
||||
Source Code
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</nav><div class="container template-article">
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="row">
|
||||
<main id="main" class="col-md-9"><div class="page-header">
|
||||
<img src="../logo.svg" class="logo" alt=""><h1>Welcome to the `AMR` package</h1>
|
||||
|
||||
|
||||
<small class="dont-index">Source: <a href="https://github.com/msberends/AMR/blob/HEAD/vignettes/welcome_to_AMR.Rmd" class="external-link"><code>vignettes/welcome_to_AMR.Rmd</code></a></small>
|
||||
<div class="d-none name"><code>welcome_to_AMR.Rmd</code></div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<p>Note: to keep the package size as small as possible, we only included
|
||||
this vignette on CRAN. You can read more vignettes on our website about
|
||||
how to conduct AMR data analysis, determine MDROs, find explanation of
|
||||
EUCAST rules, and much more: <a href="https://msberends.github.io/AMR/articles/" class="uri">https://msberends.github.io/AMR/articles/</a>.</p>
|
||||
<hr>
|
||||
<p>The <code>AMR</code> package is a <a href="https://msberends.github.io/AMR/#copyright">free and
|
||||
open-source</a> R package with <a href="https://en.wikipedia.org/wiki/Dependency_hell" class="external-link">zero
|
||||
dependencies</a> to simplify the analysis and prediction of
|
||||
Antimicrobial Resistance (AMR) and to work with microbial and
|
||||
antimicrobial data and properties, by using evidence-based methods.
|
||||
<strong>Our aim is to provide a standard</strong> for clean and
|
||||
reproducible AMR data analysis, that can therefore empower
|
||||
epidemiological analyses to continuously enable surveillance and
|
||||
treatment evaluation in any setting.</p>
|
||||
<p>This work was published in the Journal of Statistical Software
|
||||
(Volume 104(3); <a href="https://doi.org/10.18637/jss.v104.i03" class="external-link">DOI
|
||||
10.18637/jss.v104.i03</a>) and formed the basis of two PhD theses (<a href="https://doi.org/10.33612/diss.177417131" class="external-link">DOI
|
||||
10.33612/diss.177417131</a> and <a href="https://doi.org/10.33612/diss.192486375" class="external-link">DOI
|
||||
10.33612/diss.192486375</a>).</p>
|
||||
<p>After installing this package, R knows ~52 000 distinct microbial
|
||||
species and all ~600 antibiotic, antimycotic and antiviral drugs by name
|
||||
and code (including ATC, EARS-Net, ASIARS-Net, PubChem, LOINC and SNOMED
|
||||
CT), and knows all about valid SIR and MIC values. The integral
|
||||
breakpoint guidelines from CLSI and EUCAST are included from the last 10
|
||||
years. It supports and can read any data format, including WHONET
|
||||
data.</p>
|
||||
<p>The <code>AMR</code> package is available in English, Chinese,
|
||||
Danish, Dutch, French, German, Greek, Italian, Japanese, Polish,
|
||||
Portuguese, Russian, Spanish, Swedish, Turkish and Ukrainian.
|
||||
Antimicrobial drug (group) names and colloquial microorganism names are
|
||||
provided in these languages.</p>
|
||||
<p>This package is fully independent of any other R package and works on
|
||||
Windows, macOS and Linux with all versions of R since R-3.0 (April
|
||||
2013). <strong>It was designed to work in any setting, including those
|
||||
with very limited resources</strong>. Since its first public release in
|
||||
early 2018, this package has been downloaded from more than 175
|
||||
countries.</p>
|
||||
<p>This package can be used for:</p>
|
||||
<ul>
|
||||
<li>Reference for the taxonomy of microorganisms, since the package
|
||||
contains all microbial (sub)species from the List of Prokaryotic names
|
||||
with Standing in Nomenclature (LPSN) and the Global Biodiversity
|
||||
Information Facility (GBIF)</li>
|
||||
<li>Interpreting raw MIC and disk diffusion values, based on the latest
|
||||
CLSI or EUCAST guidelines</li>
|
||||
<li>Retrieving antimicrobial drug names, doses and forms of
|
||||
administration from clinical health care records</li>
|
||||
<li>Determining first isolates to be used for AMR data analysis</li>
|
||||
<li>Calculating antimicrobial resistance</li>
|
||||
<li>Determining multi-drug resistance (MDR) / multi-drug resistant
|
||||
organisms (MDRO)</li>
|
||||
<li>Calculating (empirical) susceptibility of both mono therapy and
|
||||
combination therapies</li>
|
||||
<li>Predicting future antimicrobial resistance using regression
|
||||
models</li>
|
||||
<li>Getting properties for any microorganism (like Gram stain, species,
|
||||
genus or family)</li>
|
||||
<li>Getting properties for any antibiotic (like name, code of
|
||||
EARS-Net/ATC/LOINC/PubChem, defined daily dose or trade name)</li>
|
||||
<li>Plotting antimicrobial resistance</li>
|
||||
<li>Applying EUCAST expert rules</li>
|
||||
<li>Getting SNOMED codes of a microorganism, or getting properties of a
|
||||
microorganism based on a SNOMED code</li>
|
||||
<li>Getting LOINC codes of an antibiotic, or getting properties of an
|
||||
antibiotic based on a LOINC code</li>
|
||||
<li>Machine reading the EUCAST and CLSI guidelines from 2011-2020 to
|
||||
translate MIC values and disk diffusion diameters to SIR</li>
|
||||
<li>Principal component analysis for AMR</li>
|
||||
</ul>
|
||||
<p>All reference data sets (about microorganisms, antibiotics, SIR
|
||||
interpretation, EUCAST rules, etc.) in this <code>AMR</code> package are
|
||||
publicly and freely available. We continually export our data sets to
|
||||
formats for use in R, SPSS, SAS, Stata and Excel. We also supply flat
|
||||
files that are machine-readable and suitable for input in any software
|
||||
program, such as laboratory information systems. Please find <a href="https://msberends.github.io/AMR/articles/datasets.html">all
|
||||
download links on our website</a>, which is automatically updated with
|
||||
every code change.</p>
|
||||
<p>This R package was created for both routine data analysis and
|
||||
academic research at the Faculty of Medical Sciences of the <a href="https://www.rug.nl" class="external-link">University of Groningen</a>, in collaboration
|
||||
with non-profit organisations <a href="https://www.certe.nl" class="external-link">Certe
|
||||
Medical Diagnostics and Advice Foundation</a> and <a href="https://www.umcg.nl" class="external-link">University Medical Center Groningen</a>, and
|
||||
is being <a href="./news">actively and durably maintained</a> by two
|
||||
public healthcare organisations in the Netherlands.</p>
|
||||
<hr>
|
||||
<p><small> This AMR package for R is free, open-source software and
|
||||
licensed under the <a href="https://msberends.github.io/AMR/LICENSE-text.html">GNU General
|
||||
Public License v2.0 (GPL-2)</a>. These requirements are consequently
|
||||
legally binding: modifications must be released under the same license
|
||||
when distributing the package, changes made to the code must be
|
||||
documented, source code must be made available when the package is
|
||||
distributed, and a copy of the license and copyright notice must be
|
||||
included with the package. </small></p>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<footer><div class="pkgdown-footer-left">
|
||||
<p></p>
|
||||
<p><code>AMR</code> (for R). Free and open-source, licenced under the <a target="_blank" href="https://github.com/msberends/AMR/blob/main/LICENSE" class="external-link">GNU General Public License version 2.0 (GPL-2)</a>.<br>Developed at the <a target="_blank" href="https://www.rug.nl" class="external-link">University of Groningen</a> and <a target="_blank" href="https://www.umcg.nl" class="external-link">University Medical Center Groningen</a> in The Netherlands.</p>
|
||||
</div>
|
||||
|
||||
<div class="pkgdown-footer-right">
|
||||
<p></p>
|
||||
<p><a target="_blank" href="https://www.rug.nl" class="external-link"><img src="https://github.com/msberends/AMR/raw/main/pkgdown/logos/logo_rug.svg" style="max-width: 150px;"></a><a target="_blank" href="https://www.umcg.nl" class="external-link"><img src="https://github.com/msberends/AMR/raw/main/pkgdown/logos/logo_umcg.svg" style="max-width: 150px;"></a></p>
|
||||
</div>
|
||||
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,275 @@
|
||||
<!DOCTYPE html>
|
||||
<!-- Generated by pkgdown: do not edit by hand --><html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"><title>Authors and Citation • AMR (for R)</title><!-- favicons --><link rel="icon" type="image/png" sizes="16x16" href="favicon-16x16.png"><link rel="icon" type="image/png" sizes="32x32" href="favicon-32x32.png"><link rel="apple-touch-icon" type="image/png" sizes="180x180" href="apple-touch-icon.png"><link rel="apple-touch-icon" type="image/png" sizes="120x120" href="apple-touch-icon-120x120.png"><link rel="apple-touch-icon" type="image/png" sizes="76x76" href="apple-touch-icon-76x76.png"><link rel="apple-touch-icon" type="image/png" sizes="60x60" href="apple-touch-icon-60x60.png"><script src="deps/jquery-3.6.0/jquery-3.6.0.min.js"></script><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"><link href="deps/bootstrap-5.2.2/bootstrap.min.css" rel="stylesheet"><script src="deps/bootstrap-5.2.2/bootstrap.bundle.min.js"></script><link href="deps/Fira_Code-0.4.5/font.css" rel="stylesheet"><!-- Font Awesome icons --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css" integrity="sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk=" crossorigin="anonymous"><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/v4-shims.min.css" integrity="sha256-wZjR52fzng1pJHwx4aV2AO3yyTOXrcDW7jBpJtTwVxw=" crossorigin="anonymous"><!-- bootstrap-toc --><script src="https://cdn.jsdelivr.net/gh/afeld/bootstrap-toc@v1.0.1/dist/bootstrap-toc.min.js" integrity="sha256-4veVQbu7//Lk5TSmc7YV48MxtMy98e26cf5MrgZYnwo=" crossorigin="anonymous"></script><!-- headroom.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/headroom.min.js" integrity="sha256-AsUX4SJE1+yuDu5+mAVzJbuYNPHj/WroHuZ8Ir/CkE0=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/jQuery.headroom.min.js" integrity="sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4=" crossorigin="anonymous"></script><!-- clipboard.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js" integrity="sha256-inc5kl9MA1hkeYUt+EC3BhlIgyp/2jDIyBLS6k3UxPI=" crossorigin="anonymous"></script><!-- search --><script src="https://cdnjs.cloudflare.com/ajax/libs/fuse.js/6.4.6/fuse.js" integrity="sha512-zv6Ywkjyktsohkbp9bb45V6tEMoWhzFzXis+LrMehmJZZSys19Yxf1dopHx7WzIKxr5tK2dVcYmaCk2uqdjF4A==" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/autocomplete.js/0.38.0/autocomplete.jquery.min.js" integrity="sha512-GU9ayf+66Xx2TmpxqJpliWbT5PiGYxpaG8rfnBEk1LL8l1KGkRShhngwdXK1UgqhAzWpZHSiYPc09/NwDQIGyg==" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mark.js/8.11.1/mark.min.js" integrity="sha512-5CYOlHXGh6QpOFA/TeTylKLWfB3ftPsde7AnmhuitiTX4K5SqCLBeKro6sPS8ilsz1Q4NRx3v8Ko2IBiszzdww==" crossorigin="anonymous"></script><!-- pkgdown --><script src="pkgdown.js"></script><link href="extra.css" rel="stylesheet"><script src="extra.js"></script><meta property="og:title" content="Authors and Citation"><meta property="og:image" content="https://msberends.github.io/AMR/logo.svg"><meta name="twitter:card" content="summary_large_image"><meta name="twitter:creator" content="@msberends"><meta name="twitter:site" content="@msberends"><!-- mathjax --><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script><!--[if lt IE 9]>
|
||||
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
|
||||
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
|
||||
<![endif]--></head><body>
|
||||
<a href="#main" class="visually-hidden-focusable">Skip to contents</a>
|
||||
|
||||
|
||||
<nav class="navbar fixed-top navbar-dark navbar-expand-lg bg-primary"><div class="container">
|
||||
|
||||
<a class="navbar-brand me-2" href="index.html">AMR (for R)</a>
|
||||
|
||||
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">1.8.2.9139</small>
|
||||
|
||||
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<div id="navbar" class="collapse navbar-collapse ms-3">
|
||||
<ul class="navbar-nav me-auto"><li class="nav-item">
|
||||
<a class="nav-link" href="index.html">
|
||||
<span class="fa fa-home"></span>
|
||||
|
||||
Home
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item dropdown">
|
||||
<a href="#" class="nav-link dropdown-toggle" data-bs-toggle="dropdown" role="button" aria-expanded="false" aria-haspopup="true" id="dropdown--how-to">
|
||||
<span class="fa fa-question-circle"></span>
|
||||
|
||||
How to
|
||||
</a>
|
||||
<div class="dropdown-menu" aria-labelledby="dropdown--how-to">
|
||||
<a class="dropdown-item" href="reference/AMR-options.html">
|
||||
<span class="fa fa-gear"></span>
|
||||
|
||||
User- Or Team-specific Package Settings
|
||||
</a>
|
||||
<a class="dropdown-item" href="articles/AMR.html">
|
||||
<span class="fa fa-directions"></span>
|
||||
|
||||
Conduct AMR Analysis
|
||||
</a>
|
||||
<a class="dropdown-item" href="reference/antibiogram.html">
|
||||
<span class="fa fa-file-prescription"></span>
|
||||
|
||||
Generate Antibiogram (Trad./Syndromic/WISCA)
|
||||
</a>
|
||||
<a class="dropdown-item" href="articles/resistance_predict.html">
|
||||
<span class="fa fa-dice"></span>
|
||||
|
||||
Predict Antimicrobial Resistance
|
||||
</a>
|
||||
<a class="dropdown-item" href="articles/datasets.html">
|
||||
<span class="fa fa-database"></span>
|
||||
|
||||
Data Sets for Download / Own Use
|
||||
</a>
|
||||
<a class="dropdown-item" href="articles/PCA.html">
|
||||
<span class="fa fa-compress"></span>
|
||||
|
||||
Conduct Principal Component Analysis for AMR
|
||||
</a>
|
||||
<a class="dropdown-item" href="articles/MDR.html">
|
||||
<span class="fa fa-skull-crossbones"></span>
|
||||
|
||||
Determine Multi-Drug Resistance (MDR)
|
||||
</a>
|
||||
<a class="dropdown-item" href="articles/WHONET.html">
|
||||
<span class="fa fa-globe-americas"></span>
|
||||
|
||||
Work with WHONET Data
|
||||
</a>
|
||||
<a class="dropdown-item" href="articles/SPSS.html">
|
||||
<span class="fa fa-file-upload"></span>
|
||||
|
||||
Import Data From SPSS/SAS/Stata
|
||||
</a>
|
||||
<a class="dropdown-item" href="articles/EUCAST.html">
|
||||
<span class="fa fa-exchange-alt"></span>
|
||||
|
||||
Apply Eucast Rules
|
||||
</a>
|
||||
<a class="dropdown-item" href="reference/mo_property.html">
|
||||
<span class="fa fa-bug"></span>
|
||||
|
||||
Get Taxonomy of a Microorganism
|
||||
</a>
|
||||
<a class="dropdown-item" href="reference/ab_property.html">
|
||||
<span class="fa fa-capsules"></span>
|
||||
|
||||
Get Properties of an Antibiotic Drug
|
||||
</a>
|
||||
<a class="dropdown-item" href="reference/av_property.html">
|
||||
<span class="fa fa-capsules"></span>
|
||||
|
||||
Get Properties of an Antiviral Drug
|
||||
</a>
|
||||
</div>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="reference/index.html">
|
||||
<span class="fa fa-book-open"></span>
|
||||
|
||||
Manual
|
||||
</a>
|
||||
</li>
|
||||
<li class="active nav-item">
|
||||
<a class="nav-link" href="authors.html">
|
||||
<span class="fa fa-users"></span>
|
||||
|
||||
Authors
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="news/index.html">
|
||||
<span class="far fa far fa-newspaper"></span>
|
||||
|
||||
Changelog
|
||||
</a>
|
||||
</li>
|
||||
</ul><form class="form-inline my-2 my-lg-0" role="search">
|
||||
<input type="search" class="form-control me-sm-2" aria-label="Toggle navigation" name="search-input" data-search-index="search.json" id="search-input" placeholder="Search for" autocomplete="off"></form>
|
||||
|
||||
<ul class="navbar-nav"><li class="nav-item">
|
||||
<a class="external-link nav-link" href="https://github.com/msberends/AMR">
|
||||
<span class="fab fa fab fa-github"></span>
|
||||
|
||||
Source Code
|
||||
</a>
|
||||
</li>
|
||||
</ul></div>
|
||||
|
||||
|
||||
</div>
|
||||
</nav><div class="container template-citation-authors">
|
||||
<div class="row">
|
||||
<main id="main" class="col-md-9"><div class="page-header">
|
||||
<img src="logo.svg" class="logo" alt=""><h1>Authors and Citation</h1>
|
||||
</div>
|
||||
|
||||
<div class="section level2 citation">
|
||||
<h2>Authors</h2>
|
||||
|
||||
<ul class="list-unstyled"><li>
|
||||
<p><strong>Matthijs S. Berends</strong>. Author, maintainer. <a href="https://orcid.org/0000-0001-7620-1800" target="orcid.widget" aria-label="ORCID" class="external-link"><span class="fab fa-orcid orcid" aria-hidden="true"></span></a>
|
||||
</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><strong>Christian F. Luz</strong>. Author, contributor. <a href="https://orcid.org/0000-0001-5809-5995" target="orcid.widget" aria-label="ORCID" class="external-link"><span class="fab fa-orcid orcid" aria-hidden="true"></span></a>
|
||||
</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><strong>Dennis Souverein</strong>. Author, contributor. <a href="https://orcid.org/0000-0003-0455-0336" target="orcid.widget" aria-label="ORCID" class="external-link"><span class="fab fa-orcid orcid" aria-hidden="true"></span></a>
|
||||
</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><strong>Erwin E. A. Hassing</strong>. Author, contributor.
|
||||
</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><strong>Casper J. Albers</strong>. Thesis advisor. <a href="https://orcid.org/0000-0002-9213-6743" target="orcid.widget" aria-label="ORCID" class="external-link"><span class="fab fa-orcid orcid" aria-hidden="true"></span></a>
|
||||
</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><strong>Peter Dutey-Magni</strong>. Contributor. <a href="https://orcid.org/0000-0002-8942-9836" target="orcid.widget" aria-label="ORCID" class="external-link"><span class="fab fa-orcid orcid" aria-hidden="true"></span></a>
|
||||
</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><strong>Judith M. Fonville</strong>. Contributor.
|
||||
</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><strong>Alex W. Friedrich</strong>. Thesis advisor. <a href="https://orcid.org/0000-0003-4881-038X" target="orcid.widget" aria-label="ORCID" class="external-link"><span class="fab fa-orcid orcid" aria-hidden="true"></span></a>
|
||||
</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><strong>Corinna Glasner</strong>. Thesis advisor. <a href="https://orcid.org/0000-0003-1241-1328" target="orcid.widget" aria-label="ORCID" class="external-link"><span class="fab fa-orcid orcid" aria-hidden="true"></span></a>
|
||||
</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><strong>Eric H. L. C. M. Hazenberg</strong>. Contributor.
|
||||
</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><strong>Gwen Knight</strong>. Contributor. <a href="https://orcid.org/0000-0002-7263-9896" target="orcid.widget" aria-label="ORCID" class="external-link"><span class="fab fa-orcid orcid" aria-hidden="true"></span></a>
|
||||
</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><strong>Annick Lenglet</strong>. Contributor. <a href="https://orcid.org/0000-0003-2013-8405" target="orcid.widget" aria-label="ORCID" class="external-link"><span class="fab fa-orcid orcid" aria-hidden="true"></span></a>
|
||||
</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><strong>Bart C. Meijer</strong>. Contributor.
|
||||
</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><strong>Dmytro Mykhailenko</strong>. Contributor.
|
||||
</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><strong>Anton Mymrikov</strong>. Contributor.
|
||||
</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><strong>Andrew P. Norgan</strong>. Contributor. <a href="https://orcid.org/0000-0002-2955-2066" target="orcid.widget" aria-label="ORCID" class="external-link"><span class="fab fa-orcid orcid" aria-hidden="true"></span></a>
|
||||
</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><strong>Sofia Ny</strong>. Contributor. <a href="https://orcid.org/0000-0002-2017-1363" target="orcid.widget" aria-label="ORCID" class="external-link"><span class="fab fa-orcid orcid" aria-hidden="true"></span></a>
|
||||
</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><strong>Jonas Salm</strong>. Contributor.
|
||||
</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><strong>Rogier P. Schade</strong>. Contributor.
|
||||
</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><strong>Bhanu N. M. Sinha</strong>. Thesis advisor. <a href="https://orcid.org/0000-0003-1634-0010" target="orcid.widget" aria-label="ORCID" class="external-link"><span class="fab fa-orcid orcid" aria-hidden="true"></span></a>
|
||||
</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><strong>Anthony Underwood</strong>. Contributor. <a href="https://orcid.org/0000-0002-8547-4277" target="orcid.widget" aria-label="ORCID" class="external-link"><span class="fab fa-orcid orcid" aria-hidden="true"></span></a>
|
||||
</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><strong>Anita Williams</strong>. Contributor. <a href="https://orcid.org/0000-0002-5295-8451" target="orcid.widget" aria-label="ORCID" class="external-link"><span class="fab fa-orcid orcid" aria-hidden="true"></span></a>
|
||||
</p>
|
||||
</li>
|
||||
</ul></div>
|
||||
|
||||
<div class="section level2 citation">
|
||||
<h2 id="citation">Citation</h2>
|
||||
<p><small class="dont-index">Source: <a href="https://github.com/msberends/AMR/blob/HEAD/inst/CITATION" class="external-link"><code>inst/CITATION</code></a></small></p>
|
||||
|
||||
<p>Berends MS, Luz CF, Friedrich AW, Sinha BNM, Albers CJ, Glasner C (2022).
|
||||
“AMR: An R Package for Working with Antimicrobial Resistance Data.”
|
||||
<em>Journal of Statistical Software</em>, <b>104</b>(3), 1–31.
|
||||
<a href="https://doi.org/10.18637/jss.v104.i03" class="external-link">doi:10.18637/jss.v104.i03</a>.
|
||||
</p>
|
||||
<pre>@Article{,
|
||||
title = {{AMR}: An {R} Package for Working with Antimicrobial Resistance Data},
|
||||
author = {Matthijs S. Berends and Christian F. Luz and Alexander W. Friedrich and Bhanu N. M. Sinha and Casper J. Albers and Corinna Glasner},
|
||||
journal = {Journal of Statistical Software},
|
||||
year = {2022},
|
||||
volume = {104},
|
||||
number = {3},
|
||||
pages = {1--31},
|
||||
doi = {10.18637/jss.v104.i03},
|
||||
}</pre>
|
||||
</div>
|
||||
</main><aside class="col-md-3"><nav id="toc"><h2>On this page</h2>
|
||||
</nav></aside></div>
|
||||
|
||||
|
||||
<footer><div class="pkgdown-footer-left">
|
||||
<p></p><p><code>AMR</code> (for R). Free and open-source, licenced under the <a target="_blank" href="https://github.com/msberends/AMR/blob/main/LICENSE" class="external-link">GNU General Public License version 2.0 (GPL-2)</a>.<br>Developed at the <a target="_blank" href="https://www.rug.nl" class="external-link">University of Groningen</a> and <a target="_blank" href="https://www.umcg.nl" class="external-link">University Medical Center Groningen</a> in The Netherlands.</p>
|
||||
</div>
|
||||
|
||||
<div class="pkgdown-footer-right">
|
||||
<p></p><p><a target="_blank" href="https://www.rug.nl" class="external-link"><img src="https://github.com/msberends/AMR/raw/main/pkgdown/logos/logo_rug.svg" style="max-width: 150px;"></a><a target="_blank" href="https://www.umcg.nl" class="external-link"><img src="https://github.com/msberends/AMR/raw/main/pkgdown/logos/logo_umcg.svg" style="max-width: 150px;"></a></p>
|
||||
</div>
|
||||
|
||||
</footer></div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</body></html>
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<browserconfig>
|
||||
<msapplication>
|
||||
<tile>
|
||||
<square150x150logo src="/mstile-150x150.png?v=2"/>
|
||||
<square310x310logo src="/mstile-310x310.png?v=2"/>
|
||||
<TileColor>#eeeeee</TileColor>
|
||||
</tile>
|
||||
</msapplication>
|
||||
</browserconfig>
|
||||
@@ -1,20 +0,0 @@
|
||||
codecov:
|
||||
notify:
|
||||
require_ci_to_pass: no
|
||||
ci:
|
||||
- !appveyor # ignore CI builds by AppVeyor
|
||||
|
||||
comment: no
|
||||
|
||||
coverage:
|
||||
precision: 1
|
||||
round: up
|
||||
range: "0...100"
|
||||
status:
|
||||
project: no
|
||||
patch: no
|
||||
changes: no
|
||||
|
||||
ignore:
|
||||
- "R/atc_online.R"
|
||||
- "R/mo_source.R"
|
||||
|
After Width: | Height: | Size: 78 KiB |
|
After Width: | Height: | Size: 1.2 MiB |