1
0
mirror of https://github.com/msberends/AMR.git synced 2024-12-26 23:26:12 +01:00
AMR/man/as.sir.Rd

419 lines
25 KiB
Plaintext
Raw Normal View History

2018-02-21 11:52:31 +01:00
% Generated by roxygen2: do not edit by hand
2023-01-21 23:47:20 +01:00
% Please edit documentation in R/sir.R
\docType{data}
2023-01-21 23:47:20 +01:00
\name{as.sir}
\alias{as.sir}
\alias{sir}
\alias{NA_sir_}
\alias{is.sir}
\alias{is_sir_eligible}
2024-05-20 15:27:04 +02:00
\alias{as.sir.default}
2023-01-21 23:47:20 +01:00
\alias{as.sir.mic}
\alias{as.sir.disk}
\alias{as.sir.data.frame}
\alias{sir_interpretation_history}
\title{Translate MIC and Disk Diffusion to SIR, or Clean Existing SIR Data}
2022-10-22 22:00:15 +02:00
\source{
For interpretations of minimum inhibitory concentration (MIC) values and disk diffusion diameters:
\itemize{
\item \strong{CLSI M39: Analysis and Presentation of Cumulative Antimicrobial Susceptibility Test Data}, 2011-2024, \emph{Clinical and Laboratory Standards Institute} (CLSI). \url{https://clsi.org/standards/products/microbiology/documents/m39/}.
\item \strong{CLSI M100: Performance Standard for Antimicrobial Susceptibility Testing}, 2011-2024, \emph{Clinical and Laboratory Standards Institute} (CLSI). \url{https://clsi.org/standards/products/microbiology/documents/m100/}.
2024-09-19 11:46:17 +02:00
\item \strong{CLSI VET01: Performance Standards for Antimicrobial Disk and Dilution Susceptibility Tests for Bacteria Isolated From Animals}, 2019-2024, \emph{Clinical and Laboratory Standards Institute} (CLSI). \url{https://clsi.org/standards/products/veterinary-medicine/documents/vet01/}.
\item \strong{CLSI VET09: Understanding Susceptibility Test Data as a Component of Antimicrobial Stewardship in Veterinary Settings}, 2019-2024, \emph{Clinical and Laboratory Standards Institute} (CLSI). \url{https://clsi.org/standards/products/veterinary-medicine/documents/vet09/}.
\item \strong{EUCAST Breakpoint tables for interpretation of MICs and zone diameters}, 2011-2024, \emph{European Committee on Antimicrobial Susceptibility Testing} (EUCAST). \url{https://www.eucast.org/clinical_breakpoints}.
2024-06-17 22:26:05 +02:00
\item \strong{WHONET} as a source for machine-reading the clinical breakpoints (\href{https://msberends.github.io/AMR/reference/clinical_breakpoints.html#imported-from-whonet}{read more here}), 1989-2024, \emph{WHO Collaborating Centre for Surveillance of Antimicrobial Resistance}. \url{https://whonet.org/}.
2022-10-22 22:00:15 +02:00
}
}
2018-02-21 11:52:31 +01:00
\usage{
2023-01-21 23:47:20 +01:00
as.sir(x, ...)
2019-05-10 16:44:59 +02:00
2023-01-21 23:47:20 +01:00
NA_sir_
2023-01-21 23:47:20 +01:00
is.sir(x)
2020-07-29 13:48:50 +02:00
2023-01-21 23:47:20 +01:00
is_sir_eligible(x, threshold = 0.05)
2020-07-29 13:48:50 +02:00
2024-05-20 15:27:04 +02:00
\method{as.sir}{default}(
x,
S = "^(S|U)+$",
I = "^(I)+$",
2024-05-20 15:27:04 +02:00
R = "^(R)+$",
NI = "^(N|NI|V)+$",
SDD = "^(SDD|D|H)+$",
2024-05-20 15:27:04 +02:00
...
)
2023-01-21 23:47:20 +01:00
\method{as.sir}{mic}(
2020-02-20 13:19:23 +01:00
x,
mo = NULL,
2020-02-20 13:19:23 +01:00
ab = deparse(substitute(x)),
2022-11-24 20:29:00 +01:00
guideline = getOption("AMR_guideline", "EUCAST"),
2022-10-29 14:15:23 +02:00
uti = NULL,
conserve_capped_values = FALSE,
add_intrinsic_resistance = FALSE,
2023-01-21 23:47:20 +01:00
reference_data = AMR::clinical_breakpoints,
2023-02-12 15:09:54 +01:00
include_screening = getOption("AMR_include_screening", FALSE),
2023-01-23 20:07:57 +01:00
include_PKPD = getOption("AMR_include_PKPD", TRUE),
breakpoint_type = getOption("AMR_breakpoint_type", "human"),
host = NULL,
verbose = FALSE,
2020-02-20 13:19:23 +01:00
...
)
2023-01-21 23:47:20 +01:00
\method{as.sir}{disk}(
2020-02-20 13:19:23 +01:00
x,
mo = NULL,
2020-02-20 13:19:23 +01:00
ab = deparse(substitute(x)),
2022-11-24 20:29:00 +01:00
guideline = getOption("AMR_guideline", "EUCAST"),
2022-10-29 14:15:23 +02:00
uti = NULL,
add_intrinsic_resistance = FALSE,
2023-01-21 23:47:20 +01:00
reference_data = AMR::clinical_breakpoints,
2023-02-12 15:09:54 +01:00
include_screening = getOption("AMR_include_screening", FALSE),
2023-01-23 20:07:57 +01:00
include_PKPD = getOption("AMR_include_PKPD", TRUE),
breakpoint_type = getOption("AMR_breakpoint_type", "human"),
host = NULL,
verbose = FALSE,
2020-02-20 13:19:23 +01:00
...
)
2023-01-21 23:47:20 +01:00
\method{as.sir}{data.frame}(
x,
2020-09-24 12:38:13 +02:00
...,
col_mo = NULL,
2022-11-24 20:29:00 +01:00
guideline = getOption("AMR_guideline", "EUCAST"),
uti = NULL,
conserve_capped_values = FALSE,
add_intrinsic_resistance = FALSE,
2023-01-23 20:07:57 +01:00
reference_data = AMR::clinical_breakpoints,
2023-02-12 15:09:54 +01:00
include_screening = getOption("AMR_include_screening", FALSE),
include_PKPD = getOption("AMR_include_PKPD", TRUE),
breakpoint_type = getOption("AMR_breakpoint_type", "human"),
host = NULL,
verbose = FALSE
)
2022-09-01 15:20:57 +02:00
2023-01-21 23:47:20 +01:00
sir_interpretation_history(clean = FALSE)
2018-02-21 11:52:31 +01:00
}
\arguments{
2021-05-12 18:15:03 +02:00
\item{x}{vector of values (for class \code{\link{mic}}: MIC values in mg/L, for class \code{\link{disk}}: a disk diffusion radius in millimetres)}
2019-05-10 16:44:59 +02:00
2023-01-21 23:47:20 +01:00
\item{...}{for using on a \link{data.frame}: names of columns to apply \code{\link[=as.sir]{as.sir()}} on (supports tidy selection such as \code{column1:column4}). Otherwise: arguments passed on to methods.}
2019-05-10 16:44:59 +02:00
\item{threshold}{maximum fraction of invalid antimicrobial interpretations of \code{x}, see \emph{Examples}}
2020-07-29 13:48:50 +02:00
\item{S, I, R, NI, SDD}{a case-independent \link[base:regex]{regular expression} to translate input to this result. This regular expression will be run \emph{after} all non-letters and whitespaces are removed from the input.}
2024-05-20 15:27:04 +02:00
\item{mo}{a vector (or column name) with \link{character}s that can be coerced to valid microorganism codes with \code{\link[=as.mo]{as.mo()}}, can be left empty to determine it automatically}
2019-05-10 16:44:59 +02:00
\item{ab}{a vector (or column name) with \link{character}s that can be coerced to a valid antimicrobial drug code with \code{\link[=as.ab]{as.ab()}}}
2019-05-10 16:44:59 +02:00
\item{guideline}{defaults to EUCAST 2024 (the latest implemented EUCAST guideline in the \link{clinical_breakpoints} data set), but can be set with the package option \code{\link[=AMR-options]{AMR_guideline}}. Currently supports EUCAST (2011-2024) and CLSI (2011-2024), see \emph{Details}.}
2019-05-10 16:44:59 +02:00
2024-05-31 21:24:35 +02:00
\item{uti}{(Urinary Tract Infection) a vector (or column name) with \link{logical}s (\code{TRUE} or \code{FALSE}) to specify whether a UTI specific interpretation from the guideline should be chosen. For using \code{\link[=as.sir]{as.sir()}} on a \link{data.frame}, this can also be a column containing \link{logical}s or when left blank, the data set will be searched for a column 'specimen', and rows within this column containing 'urin' (such as 'urine', 'urina') will be regarded isolates from a UTI. See \emph{Examples}.}
2020-02-20 13:19:23 +01:00
2021-05-12 18:15:03 +02:00
\item{conserve_capped_values}{a \link{logical} to indicate that MIC values starting with \code{">"} (but not \code{">="}) must always return "R" , and that MIC values starting with \code{"<"} (but not \code{"<="}) must always return "S"}
\item{add_intrinsic_resistance}{\emph{(only useful when using a EUCAST guideline)} a \link{logical} to indicate whether intrinsic antibiotic resistance must also be considered for applicable bug-drug combinations, meaning that e.g. ampicillin will always return "R" in \emph{Klebsiella} species. Determination is based on the \link{intrinsic_resistant} data set, that itself is based on \href{https://www.eucast.org/expert_rules_and_expected_phenotypes}{'EUCAST Expert Rules' and 'EUCAST Intrinsic Resistance and Unusual Phenotypes' v3.3} (2021).}
2023-01-21 23:47:20 +01:00
\item{reference_data}{a \link{data.frame} to be used for interpretation, which defaults to the \link{clinical_breakpoints} data set. Changing this argument allows for using own interpretation guidelines. This argument must contain a data set that is equal in structure to the \link{clinical_breakpoints} data set (same column names and column types). Please note that the \code{guideline} argument will be ignored when \code{reference_data} is manually set.}
\item{include_screening}{a \link{logical} to indicate that clinical breakpoints for screening are allowed - the default is \code{FALSE}. Can also be set with the package option \code{\link[=AMR-options]{AMR_include_screening}}.}
2023-02-12 15:09:54 +01:00
\item{include_PKPD}{a \link{logical} to indicate that PK/PD clinical breakpoints must be applied as a last resort - the default is \code{TRUE}. Can also be set with the package option \code{\link[=AMR-options]{AMR_include_PKPD}}.}
2023-01-23 20:07:57 +01:00
\item{breakpoint_type}{the type of breakpoints to use, either "ECOFF", "animal", or "human". ECOFF stands for Epidemiological Cut-Off values. The default is \code{"human"}, which can also be set with the package option \code{\link[=AMR-options]{AMR_breakpoint_type}}. If \code{host} is set to values of veterinary species, this will automatically be set to \code{"animal"}.}
\item{host}{a vector (or column name) with \link{character}s to indicate the host. Only useful for veterinary breakpoints, as it requires \code{breakpoint_type = "animal"}. The values can be any text resembling the animal species, even in any of the 20 supported languages of this package. For foreign languages, be sure to set the language with \code{\link[=set_AMR_locale]{set_AMR_locale()}} (though it will be automatically guessed based on the system language).}
\item{verbose}{a \link{logical} to indicate that all notes should be printed during interpretation of MIC values or disk diffusion values.}
\item{col_mo}{column name of the names or codes of the microorganisms (see \code{\link[=as.mo]{as.mo()}}) - the default is the first column of class \code{\link{mo}}. Values will be coerced using \code{\link[=as.mo]{as.mo()}}.}
2022-09-01 15:20:57 +02:00
\item{clean}{a \link{logical} to indicate whether previously stored results should be forgotten after returning the 'logbook' with results}
2018-02-21 11:52:31 +01:00
}
\value{
2023-01-21 23:47:20 +01:00
Ordered \link{factor} with new class \code{sir}
2018-02-21 11:52:31 +01:00
}
\description{
Clean up existing SIR values, or interpret minimum inhibitory concentration (MIC) values and disk diffusion diameters according to EUCAST or CLSI. \code{\link[=as.sir]{as.sir()}} transforms the input to a new class \code{\link{sir}}, which is an ordered \link{factor} containing the levels \code{S}, \code{SDD}, \code{I}, \code{R}, \code{NI}.
2023-02-12 15:09:54 +01:00
2024-05-31 21:24:35 +02:00
These breakpoints are currently implemented:
\itemize{
\item For \strong{clinical microbiology}: EUCAST 2011-2024 and CLSI 2011-2024;
\item For \strong{veterinary microbiology}: EUCAST 2021-2024 and CLSI 2019-2024;
2024-09-19 11:46:17 +02:00
\item For \strong{ECOFFs} (Epidemiological Cut-off Values): EUCAST 2020-2024 and CLSI 2022-2024.
}
2023-06-26 13:52:02 +02:00
2024-05-20 15:27:04 +02:00
All breakpoints used for interpretation are available in our \link{clinical_breakpoints} data set.
2018-02-21 11:52:31 +01:00
}
2018-08-22 00:02:26 +02:00
\details{
\emph{Note: The clinical breakpoints in this package were validated through, and imported from, \href{https://whonet.org}{WHONET}. The public use of this \code{AMR} package has been endorsed by both CLSI and EUCAST. See \link{clinical_breakpoints} for more information.}
\subsection{How it Works}{
The \code{\link[=as.sir]{as.sir()}} function can work in four ways:
\enumerate{
\item For \strong{cleaning raw / untransformed data}. The data will be cleaned to only contain valid values, namely: \strong{S} for susceptible, \strong{I} for intermediate or 'susceptible, increased exposure', \strong{R} for resistant, \strong{NI} for non-interpretable, and \strong{SDD} for susceptible dose-dependent. Each of these can be set using a \link[base:regex]{regular expression}. Furthermore, \code{\link[=as.sir]{as.sir()}} will try its best to clean with some intelligence. For example, mixed values with SIR interpretations and MIC values such as \code{"<0.25; S"} will be coerced to \code{"S"}. Combined interpretations for multiple test methods (as seen in laboratory records) such as \code{"S; S"} will be coerced to \code{"S"}, but a value like \code{"S; I"} will return \code{NA} with a warning that the input is invalid.
2020-12-22 00:51:17 +01:00
\item For \strong{interpreting minimum inhibitory concentration (MIC) values} according to EUCAST or CLSI. You must clean your MIC values first using \code{\link[=as.mic]{as.mic()}}, that also gives your columns the new data class \code{\link{mic}}. Also, be sure to have a column with microorganism names or codes. It will be found automatically, but can be set manually using the \code{mo} argument.
\itemize{
2023-01-21 23:47:20 +01:00
\item Using \code{dplyr}, SIR interpretation can be done very easily with either:
2024-05-31 21:24:35 +02:00
\if{html}{\out{<div class="sourceCode r">}}\preformatted{your_data \%>\% mutate_if(is.mic, as.sir)
2023-01-21 23:47:20 +01:00
your_data \%>\% mutate(across(where(is.mic), as.sir))
2024-05-31 21:24:35 +02:00
your_data \%>\% mutate_if(is.mic, as.sir, ab = "column_with_antibiotics", mo = "column_with_microorganisms")
your_data \%>\% mutate_if(is.mic, as.sir, ab = c("cipro", "ampicillin", ...), mo = c("E. coli", "K. pneumoniae", ...))
# for veterinary breakpoints, also set `host`:
2024-09-19 11:46:17 +02:00
your_data \%>\% mutate_if(is.mic, as.sir, host = "column_with_animal_species", guideline = "CLSI")
}\if{html}{\out{</div>}}
\item Operators like "<=" will be stripped before interpretation. When using \code{conserve_capped_values = TRUE}, an MIC value of e.g. ">2" will always return "R", even if the breakpoint according to the chosen guideline is ">=4". This is to prevent that capped values from raw laboratory data would not be treated conservatively. The default behaviour (\code{conserve_capped_values = FALSE}) considers ">2" to be lower than ">=4" and might in this case return "S" or "I".
}
2020-12-22 00:51:17 +01:00
\item For \strong{interpreting disk diffusion diameters} according to EUCAST or CLSI. You must clean your disk zones first using \code{\link[=as.disk]{as.disk()}}, that also gives your columns the new data class \code{\link{disk}}. Also, be sure to have a column with microorganism names or codes. It will be found automatically, but can be set manually using the \code{mo} argument.
\itemize{
2023-01-21 23:47:20 +01:00
\item Using \code{dplyr}, SIR interpretation can be done very easily with either:
2024-05-31 21:24:35 +02:00
\if{html}{\out{<div class="sourceCode r">}}\preformatted{your_data \%>\% mutate_if(is.disk, as.sir)
2023-01-21 23:47:20 +01:00
your_data \%>\% mutate(across(where(is.disk), as.sir))
2024-05-31 21:24:35 +02:00
your_data \%>\% mutate_if(is.disk, as.sir, ab = "column_with_antibiotics", mo = "column_with_microorganisms")
your_data \%>\% mutate_if(is.disk, as.sir, ab = c("cipro", "ampicillin", ...), mo = c("E. coli", "K. pneumoniae", ...))
# for veterinary breakpoints, also set `host`:
2024-09-19 11:46:17 +02:00
your_data \%>\% mutate_if(is.disk, as.sir, host = "column_with_animal_species", guideline = "CLSI")
}\if{html}{\out{</div>}}
}
2023-01-21 23:47:20 +01:00
\item For \strong{interpreting a complete data set}, with automatic determination of MIC values, disk diffusion diameters, microorganism names or codes, and antimicrobial test results. This is done very simply by running \code{as.sir(your_data)}.
}
2022-09-01 15:20:57 +02:00
2023-01-23 15:01:21 +01:00
\strong{For points 2, 3 and 4: Use \code{\link[=sir_interpretation_history]{sir_interpretation_history()}}} to retrieve a \link{data.frame} (or \link[tibble:tibble]{tibble} if the \code{tibble} package is installed) with all results of the last \code{\link[=as.sir]{as.sir()}} call.
}
2020-05-16 13:05:47 +02:00
\subsection{Supported Guidelines}{
For interpreting MIC values as well as disk diffusion diameters, currently implemented guidelines are for \strong{clinical microbiology}: EUCAST 2011-2024 and CLSI 2011-2024, and for \strong{veterinary microbiology}: EUCAST 2021-2024 and CLSI 2019-2024.
Thus, the \code{guideline} argument must be set to e.g., \code{"EUCAST 2024"} or \code{"CLSI 2024"}. By simply using \code{"EUCAST"} (the default) or \code{"CLSI"} as input, the latest included version of that guideline will automatically be selected. You can set your own data set using the \code{reference_data} argument. The \code{guideline} argument will then be ignored.
2022-11-24 20:29:00 +01:00
You can set the default guideline with the package option \code{\link[=AMR-options]{AMR_guideline}} (e.g. in your \code{.Rprofile} file), such as:
2022-11-24 20:29:00 +01:00
\if{html}{\out{<div class="sourceCode">}}\preformatted{ options(AMR_guideline = "CLSI")
options(AMR_guideline = "CLSI 2018")
options(AMR_guideline = "EUCAST 2020")
# or to reset:
options(AMR_guideline = NULL)
}\if{html}{\out{</div>}}
For veterinary guidelines, these might be the best options:
\if{html}{\out{<div class="sourceCode">}}\preformatted{ options(AMR_guideline = "CLSI")
options(AMR_breakpoint_type = "animal")
}\if{html}{\out{</div>}}
2024-09-19 11:46:17 +02:00
When applying veterinary breakpoints (by setting \code{host} or by setting \code{breakpoint_type = "animal"}), the \href{https://clsi.org/standards/products/veterinary-medicine/documents/vet09/}{CLSI VET09 guideline} will be applied to cope with missing animal species-specific breakpoints.
}
\subsection{After Interpretation}{
2023-01-21 23:47:20 +01:00
After using \code{\link[=as.sir]{as.sir()}}, you can use the \code{\link[=eucast_rules]{eucast_rules()}} defined by EUCAST to (1) apply inferred susceptibility and resistance based on results of other antimicrobials and (2) apply intrinsic resistance based on taxonomic properties of a microorganism.
2024-09-19 11:46:17 +02:00
To determine which isolates are multi-drug resistant, be sure to run \code{\link[=mdro]{mdro()}} (which applies the MDR/PDR/XDR guideline from 2012 at default) on a data set that contains S/I/R values. Read more about \link[=mdro]{interpreting multidrug-resistant organisms here}.
}
2023-02-12 15:09:54 +01:00
\subsection{Machine-Readable Clinical Breakpoints}{
The repository of this package \href{https://github.com/msberends/AMR/blob/main/data-raw/clinical_breakpoints.txt}{contains a machine-readable version} of all guidelines. This is a CSV file consisting of 34 063 rows and 14 columns. This file is machine-readable, since it contains one row for every unique combination of the test method (MIC or disk diffusion), the antimicrobial drug and the microorganism. \strong{This allows for easy implementation of these rules in laboratory information systems (LIS)}. Note that it only contains interpretation guidelines for humans - interpretation guidelines from CLSI for animals were removed.
}
2019-04-09 14:59:17 +02:00
\subsection{Other}{
2019-05-10 16:44:59 +02:00
2023-01-21 23:47:20 +01:00
The function \code{\link[=is.sir]{is.sir()}} detects if the input contains class \code{sir}. If the input is a \link{data.frame}, it iterates over all columns and returns a \link{logical} vector.
The base R function \code{\link[=as.double]{as.double()}} can be used to retrieve quantitative values from a \code{sir} object: \code{"S"} = 1, \code{"I"}/\code{"SDD"} = 2, \code{"R"} = 3. All other values are rendered \code{NA} . \strong{Note:} Do not use \code{as.integer()}, since that (because of how R works internally) will return the factor level indices, and not these aforementioned quantitative values.
The function \code{\link[=is_sir_eligible]{is_sir_eligible()}} returns \code{TRUE} when a column contains at most 5\% invalid antimicrobial interpretations (not S and/or I and/or R and/or NI and/or SDD), and \code{FALSE} otherwise. The threshold of 5\% can be set with the \code{threshold} argument. If the input is a \link{data.frame}, it iterates over all columns and returns a \link{logical} vector.
2018-08-22 00:02:26 +02:00
}
2023-01-21 23:47:20 +01:00
\code{NA_sir_} is a missing value of the new \code{sir} class, analogous to e.g. base \R's \code{\link[base:NA]{NA_character_}}.
}
2023-01-21 23:47:20 +01:00
\section{Interpretation of SIR}{
2019-05-13 10:10:16 +02:00
2023-07-10 13:41:52 +02:00
In 2019, the European Committee on Antimicrobial Susceptibility Testing (EUCAST) has decided to change the definitions of susceptibility testing categories S, I, and R as shown below (\url{https://www.eucast.org/newsiandr}):
2019-05-13 10:10:16 +02:00
\itemize{
2023-01-21 23:47:20 +01:00
\item \strong{S - Susceptible, standard dosing regimen}\cr
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} \emph{\cr
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.
2019-11-29 19:43:23 +01:00
\item \strong{R = Resistant}\cr
2023-01-21 23:47:20 +01:00
A microorganism is categorised as "Resistant" when there is a high likelihood of therapeutic failure even when there is increased exposure.
\itemize{
\item \emph{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.
}
2019-05-13 10:10:16 +02:00
}
2022-11-13 13:44:25 +01:00
This AMR package honours this insight. Use \code{\link[=susceptibility]{susceptibility()}} (equal to \code{\link[=proportion_SI]{proportion_SI()}}) to determine antimicrobial susceptibility and \code{\link[=count_susceptible]{count_susceptible()}} (equal to \code{\link[=count_SI]{count_SI()}}) to count susceptible isolates.
2019-05-13 10:10:16 +02:00
}
\section{Reference Data Publicly Available}{
2020-08-21 11:40:13 +02:00
All data sets in this \code{AMR} package (about microorganisms, antibiotics, SIR interpretation, EUCAST rules, etc.) are publicly and freely available for download in the following formats: R, MS Excel, Apache Feather, Apache Parquet, SPSS, and Stata. We also provide tab-separated plain text files that are machine-readable and suitable for input in any software program, such as laboratory information systems. Please visit \href{https://msberends.github.io/AMR/articles/datasets.html}{our website for the download links}. The actual files are of course available on \href{https://github.com/msberends/AMR/tree/main/data-raw}{our GitHub repository}.
2020-08-21 11:40:13 +02:00
}
2018-02-21 11:52:31 +01:00
\examples{
2022-08-21 16:37:20 +02:00
example_isolates
2023-01-21 23:47:20 +01:00
summary(example_isolates) # see all SIR results at a glance
2022-08-21 16:37:20 +02:00
# For INTERPRETING disk diffusion and MIC values -----------------------
2022-08-28 10:31:50 +02:00
2024-06-17 13:52:02 +02:00
# example data sets, with combined MIC values and disk zones
df_wide <- data.frame(
microorganism = "Escherichia coli",
amoxicillin = as.mic(8),
cipro = as.mic(0.256),
tobra = as.disk(16),
genta = as.disk(18),
2024-06-17 13:52:02 +02:00
ERY = "R"
)
df_long <- data.frame(
2024-06-17 14:36:40 +02:00
bacteria = rep("Escherichia coli", 4),
2024-06-17 13:52:02 +02:00
antibiotic = c("amoxicillin", "cipro", "tobra", "genta"),
mics = as.mic(c(0.01, 1, 4, 8)),
disks = as.disk(c(6, 10, 14, 18))
)
\donttest{
## Using dplyr -------------------------------------------------
if (require("dplyr")) {
# approaches that all work without additional arguments:
2024-06-17 13:52:02 +02:00
df_wide \%>\% mutate_if(is.mic, as.sir)
df_wide \%>\% mutate_if(function(x) is.mic(x) | is.disk(x), as.sir)
df_wide \%>\% mutate(across(where(is.mic), as.sir))
df_wide \%>\% mutate_at(vars(amoxicillin:tobra), as.sir)
df_wide \%>\% mutate(across(amoxicillin:tobra, as.sir))
# approaches that all work with additional arguments:
2024-06-17 13:52:02 +02:00
df_long \%>\%
# given a certain data type, e.g. MIC values
mutate_if(is.mic, as.sir,
mo = "bacteria",
ab = "antibiotic",
guideline = "CLSI")
df_long \%>\%
mutate(across(where(is.mic),
function(x) as.sir(x,
mo = "bacteria",
ab = "antibiotic",
guideline = "CLSI")))
df_wide \%>\%
2024-06-17 14:52:18 +02:00
# given certain columns, e.g. from 'cipro' to 'genta'
mutate_at(vars(cipro:genta), as.sir,
2024-06-17 13:52:02 +02:00
mo = "bacteria",
guideline = "CLSI")
df_wide \%>\%
2024-06-17 14:52:18 +02:00
mutate(across(cipro:genta,
2024-06-17 13:52:02 +02:00
function(x) as.sir(x,
mo = "bacteria",
guideline = "CLSI")))
# for veterinary breakpoints, add 'host':
2024-06-17 13:52:02 +02:00
df_long$animal_species <- c("cats", "dogs", "horses", "cattle")
df_long \%>\%
# given a certain data type, e.g. MIC values
mutate_if(is.mic, as.sir,
mo = "bacteria",
ab = "antibiotic",
host = "animal_species",
guideline = "CLSI")
df_long \%>\%
mutate(across(where(is.mic),
function(x) as.sir(x,
mo = "bacteria",
ab = "antibiotic",
host = "animal_species",
guideline = "CLSI")))
df_wide \%>\%
2024-06-17 14:52:18 +02:00
mutate_at(vars(cipro:genta), as.sir,
2024-06-17 13:52:02 +02:00
mo = "bacteria",
ab = "antibiotic",
host = "animal_species",
guideline = "CLSI")
df_wide \%>\%
2024-06-17 14:52:18 +02:00
mutate(across(cipro:genta,
2024-06-17 13:52:02 +02:00
function(x) as.sir(x,
mo = "bacteria",
host = "animal_species",
guideline = "CLSI")))
# to include information about urinary tract infections (UTI)
data.frame(mo = "E. coli",
nitrofuratoin = c("<= 2", 32),
from_the_bladder = c(TRUE, FALSE)) \%>\%
as.sir(uti = "from_the_bladder")
data.frame(mo = "E. coli",
nitrofuratoin = c("<= 2", 32),
specimen = c("urine", "blood")) \%>\%
as.sir() # automatically determines urine isolates
2024-06-17 13:52:02 +02:00
df_wide \%>\%
2024-06-17 14:52:18 +02:00
mutate_at(vars(cipro:genta), as.sir, mo = "E. coli", uti = TRUE)
}
## Using base R ------------------------------------------------
2024-06-17 13:52:02 +02:00
as.sir(df_wide)
2018-06-19 10:05:38 +02:00
2022-09-01 15:20:57 +02:00
# return a 'logbook' about the results:
2023-01-21 23:47:20 +01:00
sir_interpretation_history()
2022-09-01 15:20:57 +02:00
2020-02-20 13:19:23 +01:00
# for single values
2023-01-21 23:47:20 +01:00
as.sir(
2022-08-28 10:31:50 +02:00
x = as.mic(2),
mo = as.mo("S. pneumoniae"),
ab = "AMP",
guideline = "EUCAST"
)
2020-02-14 19:54:13 +01:00
2023-01-21 23:47:20 +01:00
as.sir(
2022-08-28 10:31:50 +02:00
x = as.disk(18),
mo = "Strep pneu", # `mo` will be coerced with as.mo()
ab = "ampicillin", # and `ab` with as.ab()
guideline = "EUCAST"
)
2023-01-21 23:47:20 +01:00
# For CLEANING existing SIR values ------------------------------------
2019-05-10 16:44:59 +02:00
as.sir(c("S", "SDD", "I", "R", "NI", "A", "B", "C"))
2023-01-21 23:47:20 +01:00
as.sir("<= 0.002; S") # will return "S"
sir_data <- as.sir(c(rep("S", 474), rep("I", 36), rep("R", 370)))
is.sir(sir_data)
plot(sir_data) # for percentages
barplot(sir_data) # for frequencies
2018-08-22 00:02:26 +02:00
# as common in R, you can use as.integer() to return factor indices:
as.integer(as.sir(c("S", "SDD", "I", "R", "NI", NA)))
# but for computational use, as.double() will return 1 for S, 2 for I/SDD, and 3 for R:
as.double(as.sir(c("S", "SDD", "I", "R", "NI", NA)))
# the dplyr way
if (require("dplyr")) {
example_isolates \%>\%
2023-01-21 23:47:20 +01:00
mutate_at(vars(PEN:RIF), as.sir)
2022-08-28 10:31:50 +02:00
# same:
example_isolates \%>\%
2023-01-21 23:47:20 +01:00
as.sir(PEN:RIF)
2022-08-28 10:31:50 +02:00
2023-01-21 23:47:20 +01:00
# fastest way to transform all columns with already valid AMR results to class `sir`:
example_isolates \%>\%
2023-01-21 23:47:20 +01:00
mutate_if(is_sir_eligible, as.sir)
2022-08-28 10:31:50 +02:00
# since dplyr 1.0.0, this can also be:
# example_isolates \%>\%
2023-01-21 23:47:20 +01:00
# mutate(across(where(is_sir_eligible), as.sir))
}
2018-02-21 11:52:31 +01:00
}
2020-05-16 21:40:50 +02:00
}
\seealso{
\code{\link[=as.mic]{as.mic()}}, \code{\link[=as.disk]{as.disk()}}, \code{\link[=as.mo]{as.mo()}}
}
\keyword{datasets}