mirror of
https://github.com/msberends/AMR.git
synced 2025-07-09 02:03:04 +02:00
Added function n_rsi
This commit is contained in:
@ -50,6 +50,7 @@ table with edited variables of antibiotics.
|
||||
Apply expert rules (like intrinsic resistance), as defined by the European Committee on Antimicrobial Susceptibility Testing (EUCAST, \url{http://eucast.org}), see \emph{Source}.
|
||||
}
|
||||
\examples{
|
||||
a <- EUCAST_rules(septic_patients)
|
||||
a <- data.frame(bactid = c("STAAUR", # Staphylococcus aureus
|
||||
"ENCFAE", # Enterococcus faecalis
|
||||
"ESCCOL", # Escherichia coli
|
||||
|
BIN
man/figures/combi_therapy_2.png
Normal file
BIN
man/figures/combi_therapy_2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.0 KiB |
BIN
man/figures/combi_therapy_3.png
Normal file
BIN
man/figures/combi_therapy_3.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.6 KiB |
BIN
man/figures/mono_therapy.png
Normal file
BIN
man/figures/mono_therapy.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.8 KiB |
99
man/rsi.Rd
99
man/rsi.Rd
@ -2,49 +2,106 @@
|
||||
% Please edit documentation in R/rsi_analysis.R
|
||||
\name{rsi}
|
||||
\alias{rsi}
|
||||
\alias{rsi_df}
|
||||
\alias{n_rsi}
|
||||
\title{Resistance of isolates}
|
||||
\usage{
|
||||
rsi(ab1, ab2 = NA, interpretation = "IR", minimum = 30, percent = FALSE,
|
||||
info = FALSE, warning = FALSE)
|
||||
rsi(ab1, ab2 = NA, interpretation = "IR", minimum = 30,
|
||||
as_percent = FALSE, info = FALSE, warning = TRUE)
|
||||
|
||||
rsi_df(tbl, ab, interpretation = "IR", minimum = 30, as_percent = FALSE,
|
||||
info = TRUE, warning = TRUE)
|
||||
|
||||
n_rsi(ab1, ab2 = NA)
|
||||
}
|
||||
\arguments{
|
||||
\item{ab1, ab2}{list with interpretations of an antibiotic}
|
||||
\item{ab1, ab2}{vector of antibiotic interpretations, they will be transformed internally with \code{\link{as.rsi}}}
|
||||
|
||||
\item{interpretation}{antimicrobial interpretation of which the portion must be calculated. Valid values are \code{"S"}, \code{"SI"}, \code{"I"}, \code{"IR"} or \code{"R"}.}
|
||||
|
||||
\item{minimum}{minimal amount of available isolates. Any number lower than \code{minimum} will return \code{NA} with a warning (when \code{warning = TRUE}).}
|
||||
|
||||
\item{percent}{return output as percent (text), will else (at default) be a double}
|
||||
\item{as_percent}{return output as percent (text), will else (at default) be a double}
|
||||
|
||||
\item{info}{calculate the amount of available isolates and print it, like \code{n = 423}}
|
||||
|
||||
\item{warning}{show a warning when the available amount of isolates is below \code{minimum}}
|
||||
|
||||
\item{tbl}{\code{data.frame} containing columns with antibiotic interpretations.}
|
||||
|
||||
\item{ab}{character vector with 1, 2 or 3 antibiotics that occur as column names in \code{tbl}, like \code{ab = c("amox", "amcl")}}
|
||||
}
|
||||
\value{
|
||||
Double or, when \code{percent = TRUE}, a character.
|
||||
Double or, when \code{as_percent = TRUE}, a character.
|
||||
}
|
||||
\description{
|
||||
This function can be used in \code{dplyr}s \code{\link[dplyr]{summarise}}, see \emph{Examples}. Calculate the percentage S, SI, I, IR or R of a vector of isolates.
|
||||
This functions can be used to calculate the (co-)resistance of isolates (i.e. percentage S, SI, I, IR or R [of a vector] of isolates). The functions \code{rsi} and \code{n_rsi} can be used in \code{dplyr}s \code{\link[dplyr]{summarise}} and support grouped variables, see \emph{Examples}.
|
||||
}
|
||||
\details{
|
||||
This function uses the \code{\link{rsi_df}} function internally.
|
||||
Remember that you should filter your table to let it contain \strong{only first isolates}!
|
||||
|
||||
To calculate the probability (\emph{p}) of susceptibility of one antibiotic, we use this formula:
|
||||
\if{html}{
|
||||
\out{<div style="text-align: center">}\figure{mono_therapy.png}\out{</div>}
|
||||
}
|
||||
\if{latex}{
|
||||
\deqn{p = \frac{\sum{ab1_S}}{\sum{ab1_{R|I|S}}}}
|
||||
}
|
||||
\cr
|
||||
To calculate the probability (\emph{p}) of susceptibility of more antibiotics a 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
|
||||
For two antibiotics:
|
||||
\if{html}{
|
||||
\out{<div style="text-align: center">}\figure{combi_therapy_2.png}\out{</div>}
|
||||
}
|
||||
\if{latex}{
|
||||
\deqn{p = \frac{\sum{ab1_S}\mid{ab2_S}}{\sum{ab1_{R|I|S},ab2_{R|I|S}}}}
|
||||
}
|
||||
\cr
|
||||
For three antibiotics:
|
||||
\if{html}{
|
||||
\out{<div style="text-align: center">}\figure{combi_therapy_3.png}\out{</div>}
|
||||
}
|
||||
\if{latex}{
|
||||
\deqn{p = \frac{\sum{ab1_S}\mid{ab2_S}\mid{ab3_S}}{\sum{ab1_{R|I|S},ab2_{R|I|S},ab3_{R|I|S}}}}
|
||||
}
|
||||
}
|
||||
\examples{
|
||||
library(dplyr)
|
||||
|
||||
septic_patients \%>\%
|
||||
group_by(hospital_id) \%>\%
|
||||
summarise(cipro_susceptibility = rsi(cipr, interpretation = "S"),
|
||||
n = n_rsi(cipr)) # n_rsi works like n_distinct in dplyr
|
||||
|
||||
septic_patients \%>\%
|
||||
group_by(hospital_id) \%>\%
|
||||
summarise(cipro_S = rsi(cipr, interpretation = "S",
|
||||
as_percent = TRUE, warning = FALSE),
|
||||
cipro_n = n_rsi(cipr),
|
||||
genta_S = rsi(gent, interpretation = "S",
|
||||
as_percent = TRUE, warning = FALSE),
|
||||
genta_n = n_rsi(gent),
|
||||
combination_S = rsi(cipr, gent, interpretation = "S",
|
||||
as_percent = TRUE, warning = FALSE),
|
||||
combination_n = n_rsi(cipr, gent))
|
||||
|
||||
# calculate resistance
|
||||
rsi(septic_patients$amox)
|
||||
# or susceptibility
|
||||
rsi(septic_patients$amox, interpretation = "S")
|
||||
|
||||
# calculate co-resistance between amoxicillin/clav acid and gentamicin,
|
||||
# so we can review that combination therapy does a lot more than mono therapy:
|
||||
septic_patients \%>\% rsi_df(ab = "amcl", interpretation = "S") # = 67.8\%
|
||||
septic_patients \%>\% rsi_df(ab = "gent", interpretation = "S") # = 69.1\%
|
||||
septic_patients \%>\% rsi_df(ab = c("amcl", "gent"), interpretation = "S") # = 90.6\%
|
||||
|
||||
\dontrun{
|
||||
tbl \%>\%
|
||||
group_by(hospital) \%>\%
|
||||
summarise(cipr = rsi(cipr))
|
||||
|
||||
tbl \%>\%
|
||||
group_by(year, hospital) \%>\%
|
||||
summarise(
|
||||
isolates = n(),
|
||||
cipro = rsi(cipr \%>\% as.rsi(), percent = TRUE),
|
||||
amoxi = rsi(amox \%>\% as.rsi(), percent = TRUE))
|
||||
|
||||
rsi(as.rsi(isolates$amox))
|
||||
|
||||
rsi(as.rsi(isolates$amcl), interpretation = "S")
|
||||
# calculate current empiric combination therapy of Helicobacter gastritis:
|
||||
my_table \%>\%
|
||||
filter(first_isolate == TRUE,
|
||||
genus == "Helicobacter") \%>\%
|
||||
rsi_df(ab = c("amox", "metr")) # amoxicillin with metronidazole
|
||||
}
|
||||
}
|
||||
\keyword{antibiotics}
|
||||
|
@ -1,54 +0,0 @@
|
||||
% Generated by roxygen2: do not edit by hand
|
||||
% Please edit documentation in R/rsi_analysis.R
|
||||
\name{rsi_df}
|
||||
\alias{rsi_df}
|
||||
\title{Resistance of isolates in data.frame}
|
||||
\usage{
|
||||
rsi_df(tbl, ab, interpretation = "IR", minimum = 30, percent = FALSE,
|
||||
info = TRUE, warning = TRUE)
|
||||
}
|
||||
\arguments{
|
||||
\item{tbl}{\code{data.frame} containing columns with antibiotic interpretations.}
|
||||
|
||||
\item{ab}{character vector with 1, 2 or 3 antibiotics that occur as column names in \code{tbl}, like \code{ab = c("amox", "amcl")}}
|
||||
|
||||
\item{interpretation}{antimicrobial interpretation of which the portion must be calculated. Valid values are \code{"S"}, \code{"SI"}, \code{"I"}, \code{"IR"} or \code{"R"}.}
|
||||
|
||||
\item{minimum}{minimal amount of available isolates. Any number lower than \code{minimum} will return \code{NA} with a warning (when \code{warning = TRUE}).}
|
||||
|
||||
\item{percent}{return output as percent (text), will else (at default) be a double}
|
||||
|
||||
\item{info}{calculate the amount of available isolates and print it, like \code{n = 423}}
|
||||
|
||||
\item{warning}{show a warning when the available amount of isolates is below \code{minimum}}
|
||||
}
|
||||
\value{
|
||||
Double or, when \code{percent = TRUE}, a character.
|
||||
}
|
||||
\description{
|
||||
\strong{NOTE: use \code{\link{rsi}} in dplyr functions like \code{\link[dplyr]{summarise}}.} \cr Calculate the percentage of S, SI, I, IR or R of a \code{data.frame} containing isolates.
|
||||
}
|
||||
\details{
|
||||
Remember that you should filter your table to let it contain \strong{only first isolates}!
|
||||
}
|
||||
\examples{
|
||||
\dontrun{
|
||||
rsi_df(tbl_with_bloodcultures, 'amcl')
|
||||
|
||||
rsi_df(tbl_with_bloodcultures, c('amcl', 'gent'), interpretation = 'IR')
|
||||
|
||||
library(dplyr)
|
||||
# calculate current empiric therapy of Helicobacter gastritis:
|
||||
my_table \%>\%
|
||||
filter(first_isolate == TRUE,
|
||||
genus == "Helicobacter") \%>\%
|
||||
rsi_df(ab = c("amox", "metr"))
|
||||
}
|
||||
}
|
||||
\seealso{
|
||||
\code{\link{rsi}} for the function that can be used with \code{\link[dplyr]{summarise}} directly.
|
||||
}
|
||||
\keyword{antibiotics}
|
||||
\keyword{isolate}
|
||||
\keyword{isolates}
|
||||
\keyword{rsi}
|
Reference in New Issue
Block a user