Skip to content

Commit

Permalink
(v2.1.1.9133) update math formulae
Browse files Browse the repository at this point in the history
  • Loading branch information
msberends committed Jan 27, 2025
1 parent 9520977 commit 2561494
Show file tree
Hide file tree
Showing 16 changed files with 55 additions and 1,025 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check-current-testthat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
1 change: 0 additions & 1 deletion PythonPackage/AMR/AMR/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
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

Expand Down
Binary file modified PythonPackage/AMR/dist/AMR-2.1.1.9133-py3-none-any.whl
Binary file not shown.
Binary file modified PythonPackage/AMR/dist/amr-2.1.1.9133.tar.gz
Binary file not shown.
48 changes: 14 additions & 34 deletions R/antibiogram.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)*. <https://clsi.org/standards/products/microbiology/documents/m39/>.
#' @author Implementation: Dr. Larisse Bolton and Dr. Matthijs Berends
#' @rdname antibiogram
#' @name antibiogram
#' @export
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions R/mo_matching_score.R
Original file line number Diff line number Diff line change
Expand Up @@ -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:
#'
Expand Down
5 changes: 5 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/katex.min.css" integrity="sha384-nB0miv6/jRmo5UMMR1wu3Gz6NLsoTkbqJghGIsx//Rlm+ZU03BU6SQNC66uf4l5+" crossorigin="anonymous">
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/katex.min.js" integrity="sha384-7zkQWkzuo3B5mTepMUcHkMB5jZaolc2xDwL6VFqjFALcbeS9Ggm/Yr2r3Dy4lfFg" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/contrib/auto-render.min.js" integrity="sha384-43gviWU0YVjaDtb/GhzOouOXtZMP/7XUzwPTstBeZFe/+rCMvRwr4yROQP43s0Xk" crossorigin="anonymous" onload="renderMathInElement(document.body);"></script>
bootswatch: "flatly"
assets: "pkgdown/logos" # use logos in this folder
bslib:
Expand Down
1 change: 0 additions & 1 deletion data-raw/_generate_python_wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
54 changes: 0 additions & 54 deletions data-raw/antibiograms.Rmd

This file was deleted.

850 changes: 0 additions & 850 deletions data-raw/antibiograms.html

This file was deleted.

Binary file removed data-raw/antibiograms.pdf
Binary file not shown.
56 changes: 17 additions & 39 deletions data-raw/gpt_training_text_v2.1.1.9133.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -2016,6 +1995,9 @@ plot(ab1)
plot(ab2)
}
}
\author{
Implementation: Dr. Larisse Bolton and Dr. Matthijs Berends
}



Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down
Loading

0 comments on commit 2561494

Please sign in to comment.