diff --git a/.github/workflows/check-current-testthat.yaml b/.github/workflows/check-current-testthat.yaml index 9b02589e2..a33ddb311 100644 --- a/.github/workflows/check-current-testthat.yaml +++ b/.github/workflows/check-current-testthat.yaml @@ -63,10 +63,10 @@ jobs: - {os: ubuntu-latest, r: 'release', allowfail: false} # older versions (see also check-old-tinytest.yaml for even older versions): - - {os: ubuntu-latest, r: 'oldrel', allowfail: false} - {os: ubuntu-latest, r: 'oldrel-1', allowfail: false} - {os: ubuntu-latest, r: 'oldrel-2', allowfail: false} - {os: ubuntu-latest, r: 'oldrel-3', allowfail: false} + - {os: ubuntu-latest, r: 'oldrel-4', allowfail: false} env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} diff --git a/PythonPackage/AMR/AMR/datasets.py b/PythonPackage/AMR/AMR/datasets.py index 546f74d6a..880f14f7c 100644 --- a/PythonPackage/AMR/AMR/datasets.py +++ b/PythonPackage/AMR/AMR/datasets.py @@ -21,7 +21,6 @@ utils = importr('utils') base.options(warn = -1) # Override R library paths globally for the session -robjects.r(f'.Library <- "{r_lib_path}"') # Replace default library robjects.r(f'.Library.site <- "{r_lib_path}"') # Replace site-specific library base._libPaths(r_lib_path) # Override .libPaths() as well diff --git a/PythonPackage/AMR/dist/AMR-2.1.1.9133-py3-none-any.whl b/PythonPackage/AMR/dist/AMR-2.1.1.9133-py3-none-any.whl index 8fc5e165d..0928d1fea 100644 Binary files a/PythonPackage/AMR/dist/AMR-2.1.1.9133-py3-none-any.whl and b/PythonPackage/AMR/dist/AMR-2.1.1.9133-py3-none-any.whl differ diff --git a/PythonPackage/AMR/dist/amr-2.1.1.9133.tar.gz b/PythonPackage/AMR/dist/amr-2.1.1.9133.tar.gz index 5347ec49e..d14fbcce2 100644 Binary files a/PythonPackage/AMR/dist/amr-2.1.1.9133.tar.gz and b/PythonPackage/AMR/dist/amr-2.1.1.9133.tar.gz differ diff --git a/R/antibiogram.R b/R/antibiogram.R index a57592524..3a362fa15 100755 --- a/R/antibiogram.R +++ b/R/antibiogram.R @@ -195,48 +195,26 @@ #' You can also use functions from specific 'table reporting' packages to transform the output of [antibiogram()] to your needs, e.g. with `flextable::as_flextable()` or `gt::gt()`. #' #' @section Why Use WISCA?: -#' WISCA, as outlined by Barbieri *et al.* (\doi{10.1186/s13756-021-00939-2}), stands for -#' Weighted-Incidence Syndromic Combination Antibiogram, which estimates the probability -#' of adequate empirical antimicrobial regimen coverage for specific infection syndromes. -#' This method leverages a Bayesian hierarchical logistic regression framework with random -#' effects for pathogens and regimens, enabling robust estimates in the presence of sparse -#' data. +#' +#' WISCA, as outlined by Barbieri *et al.* (\doi{10.1186/s13756-021-00939-2}), stands for Weighted-Incidence Syndromic Combination Antibiogram, which estimates the probability of adequate empirical antimicrobial regimen coverage for specific infection syndromes. This method leverages a Bayesian hierarchical logistic regression framework with random effects for pathogens and regimens, enabling robust estimates in the presence of sparse data. #' -#' The Bayesian model assumes conjugate priors for parameter estimation. For example, the -#' coverage probability \ifelse{latex}{\deqn{$theta$}}{$theta$} for a given antimicrobial regimen -#' is modeled using a Beta distribution as a prior: +#' The Bayesian model assumes conjugate priors for parameter estimation. For example, the coverage probability \eqn{\theta} for a given antimicrobial regimen is modelled using a Beta distribution as a prior: #' -#' \ifelse{latex}{\deqn{$theta$ \sim \text{Beta}($alpha$_0, $beta$_0)}}{ -#' \ifelse{html}{\figure{beta_prior.png}{options: width="300" alt="Beta prior"}}{$theta$ ~ Beta($alpha$_0, $beta$_0)}} +#' \deqn{\theta \sim \text{Beta}(\alpha_0, \beta_0)} #' -#' where \eqn{$alpha$_0} and \eqn{$beta$_0} represent prior successes and failures, respectively, -#' informed by expert knowledge or weakly informative priors (e.g., \eqn{$alpha$_0 = 1, $beta$_0 = 1}). -#' -#' The likelihood function is constructed based on observed data, where the number of covered -#' cases for a regimen follows a binomial distribution: +#' where \eqn{\alpha_0} and \eqn{\beta_0} represent prior successes and failures, respectively, informed by expert knowledge or weakly informative priors (e.g., \eqn{\alpha_0 = 1, \beta_0 = 1}). The likelihood function is constructed based on observed data, where the number of covered cases for a regimen follows a binomial distribution: #' -#' \ifelse{latex}{\deqn{y \sim \text{Binomial}(n, $theta$)}}{ -#' \ifelse{html}{\figure{binomial_likelihood.png}{options: width="300" alt="Binomial likelihood"}}{y ~ Binomial(n, $theta$)}} +#' \deqn{y \sim \text{Binomial}(n, \theta)} #' -#' Posterior parameter estimates are obtained by combining the prior and likelihood using -#' Bayes' theorem. The posterior distribution of \eqn{$theta$} is also a Beta distribution: +#' Posterior parameter estimates are obtained by combining the prior and likelihood using Bayes' theorem. The posterior distribution of \eqn{\theta} is also a Beta distribution: #' -#' \ifelse{latex}{\deqn{$theta$ | y \sim \text{Beta}($alpha$_0 + y, $beta$_0 + n - y)}}{ -#' \ifelse{html}{\figure{posterior_beta.png}{options: width="300" alt="Beta posterior"}}{$theta$ | y ~ Beta($alpha$_0 + y, $beta$_0 + n - y)}} +#' \deqn{\theta | y \sim \text{Beta}(\alpha_0 + y, \beta_0 + n - y)} #' -#' For hierarchical modeling, pathogen-level effects (e.g., differences in resistance -#' patterns) and regimen-level effects are modelled using Gaussian priors on log-odds. -#' This hierarchical structure ensures partial pooling of estimates across groups, -#' improving stability in strata with small sample sizes. The model is implemented using -#' Hamiltonian Monte Carlo (HMC) sampling. +#' For hierarchical modelling, pathogen-level effects (e.g., differences in resistance patterns) and regimen-level effects are modelled using Gaussian priors on log-odds. This hierarchical structure ensures partial pooling of estimates across groups, improving stability in strata with small sample sizes. The model is implemented using Hamiltonian Monte Carlo (HMC) sampling. #' -#' Stratified results are provided based on covariates such as age, sex, and clinical -#' complexity (e.g., prior antimicrobial treatments or renal/urological comorbidities). -#' For example, posterior odds ratios (ORs) are derived to quantify the effect of these -#' covariates on coverage probabilities: +#' Stratified results can be provided based on covariates such as age, sex, and clinical complexity (e.g., prior antimicrobial treatments or renal/urological comorbidities) using `dplyr`'s [group_by()] as a pre-processing step before running [wisca()]. In this case, posterior odds ratios (ORs) are derived to quantify the effect of these covariates on coverage probabilities: #' -#' \ifelse{latex}{\deqn{\text{OR}_{\text{covariate}} = \frac{\exp($beta$_{\text{covariate}})}{\exp($beta$_0)}}}{ -#' \ifelse{html}{\figure{odds_ratio.png}{options: width="300" alt="Odds ratio formula"}}{OR_covariate = exp(beta_covariate) / exp(beta_0)}} +#' \deqn{\text{OR}_{\text{covariate}} = \frac{\exp(\beta_{\text{covariate}})}{\exp(\beta_0)}} #' #' By combining empirical data with prior knowledge, WISCA overcomes the limitations #' of traditional combination antibiograms, offering disease-specific, patient-stratified @@ -249,6 +227,7 @@ #' * Klinker KP *et al.* (2021). **Antimicrobial stewardship and antibiograms: importance of moving beyond traditional antibiograms**. *Therapeutic Advances in Infectious Disease*, May 5;8:20499361211011373; \doi{10.1177/20499361211011373} #' * Barbieri E *et al.* (2021). **Development of a Weighted-Incidence Syndromic Combination Antibiogram (WISCA) to guide the choice of the empiric antibiotic treatment for urinary tract infection in paediatric patients: a Bayesian approach** *Antimicrobial Resistance & Infection Control* May 1;10(1):74; \doi{10.1186/s13756-021-00939-2} #' * **M39 Analysis and Presentation of Cumulative Antimicrobial Susceptibility Test Data, 5th Edition**, 2022, *Clinical and Laboratory Standards Institute (CLSI)*. . +#' @author Implementation: Dr. Larisse Bolton and Dr. Matthijs Berends #' @rdname antibiogram #' @name antibiogram #' @export @@ -331,7 +310,8 @@ #' #' ureido <- antibiogram(example_isolates, #' antibiotics = ureidopenicillins(), -#' ab_transform = "name" +#' ab_transform = "name", +#' wisca = TRUE #' ) #' #' # in an Rmd file, you would just need to return `ureido` in a chunk, diff --git a/R/mo_matching_score.R b/R/mo_matching_score.R index 6a7b24c12..3bec4339d 100755 --- a/R/mo_matching_score.R +++ b/R/mo_matching_score.R @@ -38,9 +38,7 @@ #' @section Matching Score for Microorganisms: #' With ambiguous user input in [as.mo()] and all the [`mo_*`][mo_property()] functions, the returned results are chosen based on their matching score using [mo_matching_score()]. This matching score \eqn{m}, is calculated as: #' -#' \ifelse{latex}{\deqn{m_{(x, n)} = \frac{l_{n} - 0.5 \cdot \min \begin{cases}l_{n} \\ \textrm{lev}(x, n)\end{cases}}{l_{n} \cdot p_{n} \cdot k_{n}}}}{ -#' -#' \ifelse{html}{\figure{mo_matching_score.png}{options: width="300" alt="mo matching score"}}{m(x, n) = ( l_n * min(l_n, lev(x, n) ) ) / ( l_n * p_n * k_n )}} +#' \deqn{m_{(x, n)} = \frac{l_{n} - 0.5 \cdot \min \begin{cases}l_{n} \\ \textrm{lev}(x, n)\end{cases}}{l_{n} \cdot p_{n} \cdot k_{n}}} #' #' where: #' diff --git a/_pkgdown.yml b/_pkgdown.yml index 93b476bda..8b2ba6d85 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -32,6 +32,11 @@ url: "https://msberends.github.io/AMR/" template: bootstrap: 5 + includes: # support for mathematical formulas, from https://github.com/r-lib/pkgdown/issues/2704#issuecomment-2307055568 + in_header: | + + + bootswatch: "flatly" assets: "pkgdown/logos" # use logos in this folder bslib: diff --git a/data-raw/_generate_python_wrapper.sh b/data-raw/_generate_python_wrapper.sh index 87da6e854..e337c8638 100644 --- a/data-raw/_generate_python_wrapper.sh +++ b/data-raw/_generate_python_wrapper.sh @@ -65,7 +65,6 @@ utils = importr('utils') base.options(warn = -1) # Override R library paths globally for the session -robjects.r(f'.Library <- "{r_lib_path}"') # Replace default library robjects.r(f'.Library.site <- "{r_lib_path}"') # Replace site-specific library base._libPaths(r_lib_path) # Override .libPaths() as well diff --git a/data-raw/antibiograms.Rmd b/data-raw/antibiograms.Rmd deleted file mode 100644 index d515f1523..000000000 --- a/data-raw/antibiograms.Rmd +++ /dev/null @@ -1,54 +0,0 @@ ---- -title: "Generating antibiograms with the AMR package" -author: "AMR package developers" -date: "`r Sys.Date()`" -output: pdf_document ---- - -```{r setup, include=FALSE} -knitr::opts_chunk$set(echo = TRUE, message = FALSE) -library(AMR) -``` - -This is an example R Markdown file to show the use of `antibiogram()` of the AMR package. - -For starters, this is what our `example_isolates` data set looks like: - -```{r} -example_isolates -``` - - -### Traditional Antibiogram - -```{r trad} -antibiogram(example_isolates, - antibiotics = c(aminoglycosides(), carbapenems())) -``` - -### Combined Antibiogram - -```{r comb} -antibiogram(example_isolates, - antibiotics = c("TZP", "TZP+TOB", "TZP+GEN")) -``` - -### Syndromic Antibiogram - -```{r synd} -antibiogram(example_isolates, - antibiotics = c(aminoglycosides(), carbapenems()), - syndromic_group = "ward") -``` - -### Weighted-Incidence Syndromic Combination Antibiogram (WISCA) - -```{r wisca} -antibiogram(example_isolates, - antibiotics = c("AMC", "AMC+CIP", "TZP", "TZP+TOB"), - mo_transform = "gramstain", - minimum = 10, # this should be >= 30, but now just as example - syndromic_group = ifelse(example_isolates$age >= 65 & - example_isolates$gender == "M", - "WISCA Group 1", "WISCA Group 2")) -``` diff --git a/data-raw/antibiograms.html b/data-raw/antibiograms.html deleted file mode 100644 index 989da0ac6..000000000 --- a/data-raw/antibiograms.html +++ /dev/null @@ -1,850 +0,0 @@ - - - - - - - - - - - - - - - -Generating antibiograms with the AMR package - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - -

This is an example R Markdown file to show the use of -antibiogram() of the AMR package.

-

For starters, this is what our example_isolates data set -looks like:

-
example_isolates
-
## # A tibble: 2,000 × 46
-##    date       patient   age gender ward     mo           PEN   OXA   FLC   AMX  
-##    <date>     <chr>   <dbl> <chr>  <chr>    <mo>         <sir> <sir> <sir> <sir>
-##  1 2002-01-02 A77334     65 F      Clinical B_ESCHR_COLI R     NA    NA    NA   
-##  2 2002-01-03 A77334     65 F      Clinical B_ESCHR_COLI R     NA    NA    NA   
-##  3 2002-01-07 067927     45 F      ICU      B_STPHY_EPDR R     NA    R     NA   
-##  4 2002-01-07 067927     45 F      ICU      B_STPHY_EPDR R     NA    R     NA   
-##  5 2002-01-13 067927     45 F      ICU      B_STPHY_EPDR R     NA    R     NA   
-##  6 2002-01-13 067927     45 F      ICU      B_STPHY_EPDR R     NA    R     NA   
-##  7 2002-01-14 462729     78 M      Clinical B_STPHY_AURS R     NA    S     R    
-##  8 2002-01-14 462729     78 M      Clinical B_STPHY_AURS R     NA    S     R    
-##  9 2002-01-16 067927     45 F      ICU      B_STPHY_EPDR R     NA    R     NA   
-## 10 2002-01-17 858515     79 F      ICU      B_STPHY_EPDR R     NA    S     NA   
-## # … with 1,990 more rows, and 36 more variables: AMC <sir>, AMP <sir>,
-## #   TZP <sir>, CZO <sir>, FEP <sir>, CXM <sir>, FOX <sir>, CTX <sir>,
-## #   CAZ <sir>, CRO <sir>, GEN <sir>, TOB <sir>, AMK <sir>, KAN <sir>,
-## #   TMP <sir>, SXT <sir>, NIT <sir>, FOS <sir>, LNZ <sir>, CIP <sir>,
-## #   MFX <sir>, VAN <sir>, TEC <sir>, TCY <sir>, TGC <sir>, DOX <sir>,
-## #   ERY <sir>, CLI <sir>, AZM <sir>, IPM <sir>, MEM <sir>, MTR <sir>,
-## #   CHL <sir>, COL <sir>, MUP <sir>, RIF <sir>
-
-

Traditional Antibiogram

-
antibiogram(example_isolates,
-            antibiotics = c(aminoglycosides(), carbapenems()))
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Pathogen (N min-max)AMKGENIPMKANMEMTOB
CoNS (43-309)0865205222
E. coli (0-462)1009810010097
E. faecalis (0-39)0010000
K. pneumoniae (0-58)9010010090
P. aeruginosa (17-30)1000100
P. mirabilis (0-34)949494
S. aureus (2-233)9998
S. epidermidis (8-163)079051
S. hominis (3-80)9285
S. pneumoniae (11-117)0000
-
-
-

Combined Antibiogram

-
antibiogram(example_isolates,
-            antibiotics = c("TZP", "TZP+TOB", "TZP+GEN"))
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Pathogen (N min-max)TZPTZP + GENTZP + TOB
CoNS (29-274)3097
E. coli (416-461)9410099
K. pneumoniae (53-58)899393
P. aeruginosa (27-30)100100
P. mirabilis (27-34)100100
S. aureus (7-231)100100
S. epidermidis (5-128)100100
S. hominis (0-74)100100
S. pneumoniae (112-112)100100100
-
-
-

Syndromic Antibiogram

-
antibiogram(example_isolates,
-             antibiotics = c(aminoglycosides(), carbapenems()),
-             syndromic_group = "ward")
- ---------- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Syndromic GroupPathogen (N min-max)AMKGENIPMKANMEMTOB
ClinicalCoNS (23-205)89575726
ICUCoNS (10-73)79
OutpatientCoNS (3-31)84
ClinicalE. coli (0-299)1009810010098
ICUE. coli (0-137)1009910010096
ClinicalK. pneumoniae (0-51)9210010092
ClinicalP. mirabilis (0-30)100100
ClinicalS. aureus (2-150)9997
ICUS. aureus (0-66)100
ClinicalS. epidermidis (4-79)8255
ICUS. epidermidis (4-75)7241
ClinicalS. hominis (1-45)9694
ClinicalS. pneumoniae (5-78)0000
ICUS. pneumoniae (5-30)0000
-
-
-

Weighted-Incidence Syndromic Combination Antibiogram (WISCA)

-
antibiogram(example_isolates,
-            antibiotics = c("AMC", "AMC+CIP", "TZP", "TZP+TOB"),
-            mo_transform = "gramstain",
-            minimum = 10, # this should be >= 30, but now just as example
-            syndromic_group = ifelse(example_isolates$age >= 65 &
-                                       example_isolates$gender == "M",
-                                     "WISCA Group 1", "WISCA Group 2"))
- -------- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Syndromic GroupPathogen (N min-max)AMCAMC + CIPTZPTZP + TOB
WISCA Group 1Gram-negative (261-285)76958999
WISCA Group 2Gram-negative (380-442)76988898
WISCA Group 1Gram-positive (123-406)76898195
WISCA Group 2Gram-positive (222-732)76898895
-
- - - - -
- - - - - - - - - - - - - - - diff --git a/data-raw/antibiograms.pdf b/data-raw/antibiograms.pdf deleted file mode 100644 index cce88d05d..000000000 Binary files a/data-raw/antibiograms.pdf and /dev/null differ diff --git a/data-raw/gpt_training_text_v2.1.1.9133.txt b/data-raw/gpt_training_text_v2.1.1.9133.txt index 0e9ad65b3..fee431601 100644 --- a/data-raw/gpt_training_text_v2.1.1.9133.txt +++ b/data-raw/gpt_training_text_v2.1.1.9133.txt @@ -1854,48 +1854,26 @@ You can also use functions from specific 'table reporting' packages to transform } \section{Why Use WISCA?}{ -WISCA, as outlined by Barbieri \emph{et al.} (\doi{10.1186/s13756-021-00939-2}), stands for -Weighted-Incidence Syndromic Combination Antibiogram, which estimates the probability -of adequate empirical antimicrobial regimen coverage for specific infection syndromes. -This method leverages a Bayesian hierarchical logistic regression framework with random -effects for pathogens and regimens, enabling robust estimates in the presence of sparse -data. -The Bayesian model assumes conjugate priors for parameter estimation. For example, the -coverage probability \ifelse{latex}{\deqn{$theta$}}{$theta$} for a given antimicrobial regimen -is modeled using a Beta distribution as a prior: +WISCA, as outlined by Barbieri \emph{et al.} (\doi{10.1186/s13756-021-00939-2}), stands for Weighted-Incidence Syndromic Combination Antibiogram, which estimates the probability of adequate empirical antimicrobial regimen coverage for specific infection syndromes. This method leverages a Bayesian hierarchical logistic regression framework with random effects for pathogens and regimens, enabling robust estimates in the presence of sparse data. -\ifelse{latex}{\deqn{$theta$ \sim \text{Beta}($alpha$_0, $beta$_0)}}{ -\ifelse{html}{\figure{beta_prior.png}{options: width="300" alt="Beta prior"}}{$theta$ ~ Beta($alpha$_0, $beta$_0)}} +The Bayesian model assumes conjugate priors for parameter estimation. For example, the coverage probability \eqn{\theta} for a given antimicrobial regimen is modelled using a Beta distribution as a prior: -where \eqn{$alpha$_0} and \eqn{$beta$_0} represent prior successes and failures, respectively, -informed by expert knowledge or weakly informative priors (e.g., \eqn{$alpha$_0 = 1, $beta$_0 = 1}). +\deqn{\theta \sim \text{Beta}(\alpha_0, \beta_0)} -The likelihood function is constructed based on observed data, where the number of covered -cases for a regimen follows a binomial distribution: +where \eqn{\alpha_0} and \eqn{\beta_0} represent prior successes and failures, respectively, informed by expert knowledge or weakly informative priors (e.g., \eqn{\alpha_0 = 1, \beta_0 = 1}). The likelihood function is constructed based on observed data, where the number of covered cases for a regimen follows a binomial distribution: -\ifelse{latex}{\deqn{y \sim \text{Binomial}(n, $theta$)}}{ -\ifelse{html}{\figure{binomial_likelihood.png}{options: width="300" alt="Binomial likelihood"}}{y ~ Binomial(n, $theta$)}} +\deqn{y \sim \text{Binomial}(n, \theta)} -Posterior parameter estimates are obtained by combining the prior and likelihood using -Bayes' theorem. The posterior distribution of \eqn{$theta$} is also a Beta distribution: +Posterior parameter estimates are obtained by combining the prior and likelihood using Bayes' theorem. The posterior distribution of \eqn{\theta} is also a Beta distribution: -\ifelse{latex}{\deqn{$theta$ | y \sim \text{Beta}($alpha$_0 + y, $beta$_0 + n - y)}}{ -\ifelse{html}{\figure{posterior_beta.png}{options: width="300" alt="Beta posterior"}}{$theta$ | y ~ Beta($alpha$_0 + y, $beta$_0 + n - y)}} +\deqn{\theta | y \sim \text{Beta}(\alpha_0 + y, \beta_0 + n - y)} -For hierarchical modeling, pathogen-level effects (e.g., differences in resistance -patterns) and regimen-level effects are modelled using Gaussian priors on log-odds. -This hierarchical structure ensures partial pooling of estimates across groups, -improving stability in strata with small sample sizes. The model is implemented using -Hamiltonian Monte Carlo (HMC) sampling. +For hierarchical modelling, pathogen-level effects (e.g., differences in resistance patterns) and regimen-level effects are modelled using Gaussian priors on log-odds. This hierarchical structure ensures partial pooling of estimates across groups, improving stability in strata with small sample sizes. The model is implemented using Hamiltonian Monte Carlo (HMC) sampling. -Stratified results are provided based on covariates such as age, sex, and clinical -complexity (e.g., prior antimicrobial treatments or renal/urological comorbidities). -For example, posterior odds ratios (ORs) are derived to quantify the effect of these -covariates on coverage probabilities: +Stratified results can be provided based on covariates such as age, sex, and clinical complexity (e.g., prior antimicrobial treatments or renal/urological comorbidities) using \code{dplyr}'s \code{\link[=group_by]{group_by()}} as a pre-processing step before running \code{\link[=wisca]{wisca()}}. In this case, posterior odds ratios (ORs) are derived to quantify the effect of these covariates on coverage probabilities: -\ifelse{latex}{\deqn{\text{OR}_{\text{covariate}} = \frac{\exp($beta$_{\text{covariate}})}{\exp($beta$_0)}}}{ -\ifelse{html}{\figure{odds_ratio.png}{options: width="300" alt="Odds ratio formula"}}{OR_covariate = exp(beta_covariate) / exp(beta_0)}} +\deqn{\text{OR}_{\text{covariate}} = \frac{\exp(\beta_{\text{covariate}})}{\exp(\beta_0)}} By combining empirical data with prior knowledge, WISCA overcomes the limitations of traditional combination antibiograms, offering disease-specific, patient-stratified @@ -1982,7 +1960,8 @@ antibiogram(example_isolates, ureido <- antibiogram(example_isolates, antibiotics = ureidopenicillins(), - ab_transform = "name" + ab_transform = "name", + wisca = TRUE ) # in an Rmd file, you would just need to return `ureido` in a chunk, @@ -2016,6 +1995,9 @@ plot(ab1) plot(ab2) } } +\author{ +Implementation: Dr. Larisse Bolton and Dr. Matthijs Berends +} @@ -3099,9 +3081,7 @@ This is based on: With ambiguous user input in \code{\link[=as.mo]{as.mo()}} and all the \code{\link[=mo_property]{mo_*}} functions, the returned results are chosen based on their matching score using \code{\link[=mo_matching_score]{mo_matching_score()}}. This matching score \eqn{m}, is calculated as: -\ifelse{latex}{\deqn{m_{(x, n)} = \frac{l_{n} - 0.5 \cdot \min \begin{cases}l_{n} \\ \textrm{lev}(x, n)\end{cases}}{l_{n} \cdot p_{n} \cdot k_{n}}}}{ - -\ifelse{html}{\figure{mo_matching_score.png}{options: width="300" alt="mo matching score"}}{m(x, n) = ( l_n * min(l_n, lev(x, n) ) ) / ( l_n * p_n * k_n )}} +\deqn{m_{(x, n)} = \frac{l_{n} - 0.5 \cdot \min \begin{cases}l_{n} \\ \textrm{lev}(x, n)\end{cases}}{l_{n} \cdot p_{n} \cdot k_{n}}} where: \itemize{ @@ -6627,9 +6607,7 @@ Later, the work of Bartlett A \emph{et al.} about bacterial pathogens infecting With ambiguous user input in \code{\link[=as.mo]{as.mo()}} and all the \code{\link[=mo_property]{mo_*}} functions, the returned results are chosen based on their matching score using \code{\link[=mo_matching_score]{mo_matching_score()}}. This matching score \eqn{m}, is calculated as: -\ifelse{latex}{\deqn{m_{(x, n)} = \frac{l_{n} - 0.5 \cdot \min \begin{cases}l_{n} \\ \textrm{lev}(x, n)\end{cases}}{l_{n} \cdot p_{n} \cdot k_{n}}}}{ - -\ifelse{html}{\figure{mo_matching_score.png}{options: width="300" alt="mo matching score"}}{m(x, n) = ( l_n * min(l_n, lev(x, n) ) ) / ( l_n * p_n * k_n )}} +\deqn{m_{(x, n)} = \frac{l_{n} - 0.5 \cdot \min \begin{cases}l_{n} \\ \textrm{lev}(x, n)\end{cases}}{l_{n} \cdot p_{n} \cdot k_{n}}} where: \itemize{ diff --git a/man/antibiogram.Rd b/man/antibiogram.Rd index 8f2506c33..786314dc7 100644 --- a/man/antibiogram.Rd +++ b/man/antibiogram.Rd @@ -232,48 +232,26 @@ You can also use functions from specific 'table reporting' packages to transform } \section{Why Use WISCA?}{ -WISCA, as outlined by Barbieri \emph{et al.} (\doi{10.1186/s13756-021-00939-2}), stands for -Weighted-Incidence Syndromic Combination Antibiogram, which estimates the probability -of adequate empirical antimicrobial regimen coverage for specific infection syndromes. -This method leverages a Bayesian hierarchical logistic regression framework with random -effects for pathogens and regimens, enabling robust estimates in the presence of sparse -data. -The Bayesian model assumes conjugate priors for parameter estimation. For example, the -coverage probability \ifelse{latex}{\deqn{$theta$}}{$theta$} for a given antimicrobial regimen -is modeled using a Beta distribution as a prior: +WISCA, as outlined by Barbieri \emph{et al.} (\doi{10.1186/s13756-021-00939-2}), stands for Weighted-Incidence Syndromic Combination Antibiogram, which estimates the probability of adequate empirical antimicrobial regimen coverage for specific infection syndromes. This method leverages a Bayesian hierarchical logistic regression framework with random effects for pathogens and regimens, enabling robust estimates in the presence of sparse data. -\ifelse{latex}{\deqn{$theta$ \sim \text{Beta}($alpha$_0, $beta$_0)}}{ -\ifelse{html}{\figure{beta_prior.png}{options: width="300" alt="Beta prior"}}{$theta$ ~ Beta($alpha$_0, $beta$_0)}} +The Bayesian model assumes conjugate priors for parameter estimation. For example, the coverage probability \eqn{\theta} for a given antimicrobial regimen is modelled using a Beta distribution as a prior: -where \eqn{$alpha$_0} and \eqn{$beta$_0} represent prior successes and failures, respectively, -informed by expert knowledge or weakly informative priors (e.g., \eqn{$alpha$_0 = 1, $beta$_0 = 1}). +\deqn{\theta \sim \text{Beta}(\alpha_0, \beta_0)} -The likelihood function is constructed based on observed data, where the number of covered -cases for a regimen follows a binomial distribution: +where \eqn{\alpha_0} and \eqn{\beta_0} represent prior successes and failures, respectively, informed by expert knowledge or weakly informative priors (e.g., \eqn{\alpha_0 = 1, \beta_0 = 1}). The likelihood function is constructed based on observed data, where the number of covered cases for a regimen follows a binomial distribution: -\ifelse{latex}{\deqn{y \sim \text{Binomial}(n, $theta$)}}{ -\ifelse{html}{\figure{binomial_likelihood.png}{options: width="300" alt="Binomial likelihood"}}{y ~ Binomial(n, $theta$)}} +\deqn{y \sim \text{Binomial}(n, \theta)} -Posterior parameter estimates are obtained by combining the prior and likelihood using -Bayes' theorem. The posterior distribution of \eqn{$theta$} is also a Beta distribution: +Posterior parameter estimates are obtained by combining the prior and likelihood using Bayes' theorem. The posterior distribution of \eqn{\theta} is also a Beta distribution: -\ifelse{latex}{\deqn{$theta$ | y \sim \text{Beta}($alpha$_0 + y, $beta$_0 + n - y)}}{ -\ifelse{html}{\figure{posterior_beta.png}{options: width="300" alt="Beta posterior"}}{$theta$ | y ~ Beta($alpha$_0 + y, $beta$_0 + n - y)}} +\deqn{\theta | y \sim \text{Beta}(\alpha_0 + y, \beta_0 + n - y)} -For hierarchical modeling, pathogen-level effects (e.g., differences in resistance -patterns) and regimen-level effects are modelled using Gaussian priors on log-odds. -This hierarchical structure ensures partial pooling of estimates across groups, -improving stability in strata with small sample sizes. The model is implemented using -Hamiltonian Monte Carlo (HMC) sampling. +For hierarchical modelling, pathogen-level effects (e.g., differences in resistance patterns) and regimen-level effects are modelled using Gaussian priors on log-odds. This hierarchical structure ensures partial pooling of estimates across groups, improving stability in strata with small sample sizes. The model is implemented using Hamiltonian Monte Carlo (HMC) sampling. -Stratified results are provided based on covariates such as age, sex, and clinical -complexity (e.g., prior antimicrobial treatments or renal/urological comorbidities). -For example, posterior odds ratios (ORs) are derived to quantify the effect of these -covariates on coverage probabilities: +Stratified results can be provided based on covariates such as age, sex, and clinical complexity (e.g., prior antimicrobial treatments or renal/urological comorbidities) using \code{dplyr}'s \code{\link[=group_by]{group_by()}} as a pre-processing step before running \code{\link[=wisca]{wisca()}}. In this case, posterior odds ratios (ORs) are derived to quantify the effect of these covariates on coverage probabilities: -\ifelse{latex}{\deqn{\text{OR}_{\text{covariate}} = \frac{\exp($beta$_{\text{covariate}})}{\exp($beta$_0)}}}{ -\ifelse{html}{\figure{odds_ratio.png}{options: width="300" alt="Odds ratio formula"}}{OR_covariate = exp(beta_covariate) / exp(beta_0)}} +\deqn{\text{OR}_{\text{covariate}} = \frac{\exp(\beta_{\text{covariate}})}{\exp(\beta_0)}} By combining empirical data with prior knowledge, WISCA overcomes the limitations of traditional combination antibiograms, offering disease-specific, patient-stratified @@ -360,7 +338,8 @@ antibiogram(example_isolates, ureido <- antibiogram(example_isolates, antibiotics = ureidopenicillins(), - ab_transform = "name" + ab_transform = "name", + wisca = TRUE ) # in an Rmd file, you would just need to return `ureido` in a chunk, @@ -394,3 +373,6 @@ plot(ab1) plot(ab2) } } +\author{ +Implementation: Dr. Larisse Bolton and Dr. Matthijs Berends +} diff --git a/man/as.mo.Rd b/man/as.mo.Rd index a705d820f..988e733f1 100644 --- a/man/as.mo.Rd +++ b/man/as.mo.Rd @@ -169,9 +169,7 @@ This is based on: With ambiguous user input in \code{\link[=as.mo]{as.mo()}} and all the \code{\link[=mo_property]{mo_*}} functions, the returned results are chosen based on their matching score using \code{\link[=mo_matching_score]{mo_matching_score()}}. This matching score \eqn{m}, is calculated as: -\ifelse{latex}{\deqn{m_{(x, n)} = \frac{l_{n} - 0.5 \cdot \min \begin{cases}l_{n} \\ \textrm{lev}(x, n)\end{cases}}{l_{n} \cdot p_{n} \cdot k_{n}}}}{ - -\ifelse{html}{\figure{mo_matching_score.png}{options: width="300" alt="mo matching score"}}{m(x, n) = ( l_n * min(l_n, lev(x, n) ) ) / ( l_n * p_n * k_n )}} +\deqn{m_{(x, n)} = \frac{l_{n} - 0.5 \cdot \min \begin{cases}l_{n} \\ \textrm{lev}(x, n)\end{cases}}{l_{n} \cdot p_{n} \cdot k_{n}}} where: \itemize{ diff --git a/man/mo_matching_score.Rd b/man/mo_matching_score.Rd index b6d0f0bd6..85f2a226c 100644 --- a/man/mo_matching_score.Rd +++ b/man/mo_matching_score.Rd @@ -23,9 +23,7 @@ Later, the work of Bartlett A \emph{et al.} about bacterial pathogens infecting With ambiguous user input in \code{\link[=as.mo]{as.mo()}} and all the \code{\link[=mo_property]{mo_*}} functions, the returned results are chosen based on their matching score using \code{\link[=mo_matching_score]{mo_matching_score()}}. This matching score \eqn{m}, is calculated as: -\ifelse{latex}{\deqn{m_{(x, n)} = \frac{l_{n} - 0.5 \cdot \min \begin{cases}l_{n} \\ \textrm{lev}(x, n)\end{cases}}{l_{n} \cdot p_{n} \cdot k_{n}}}}{ - -\ifelse{html}{\figure{mo_matching_score.png}{options: width="300" alt="mo matching score"}}{m(x, n) = ( l_n * min(l_n, lev(x, n) ) ) / ( l_n * p_n * k_n )}} +\deqn{m_{(x, n)} = \frac{l_{n} - 0.5 \cdot \min \begin{cases}l_{n} \\ \textrm{lev}(x, n)\end{cases}}{l_{n} \cdot p_{n} \cdot k_{n}}} where: \itemize{ diff --git a/tests/testthat.R b/tests/testthat.R index 65458d15f..914f00994 100644 --- a/tests/testthat.R +++ b/tests/testthat.R @@ -37,9 +37,6 @@ expect_inherits <- function(x, y, ...) { ", required is class ", paste0(y, collapse = "/"))) } expect_stdout <- expect_output -if (getRversion() < "4.0.0") { - deparse1 <- AMR:::deparse1 -} # start unit tests test_check("AMR")