AMR/man/first_isolate.Rd

225 lines
14 KiB
Plaintext
Raw Normal View History

2018-02-21 11:52:31 +01:00
% Generated by roxygen2: do not edit by hand
2018-07-23 14:14:03 +02:00
% Please edit documentation in R/first_isolate.R
2018-02-21 11:52:31 +01:00
\name{first_isolate}
\alias{first_isolate}
2018-12-22 22:39:34 +01:00
\alias{filter_first_isolate}
\title{Determine First Isolates}
2018-04-20 13:45:34 +02:00
\source{
2020-05-16 13:05:47 +02:00
Methodology of this function is strictly based on:
2021-04-29 17:16:30 +02:00
\itemize{
\item \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/}.
\item Hindler JF and Stelling J (2007). \strong{Analysis and Presentation of Cumulative Antibiograms: A New Consensus Guideline from the Clinical and Laboratory Standards Institute.} Clinical Infectious Diseases, 44(6), 867873. \doi{10.1086/511864}
}
2018-04-20 13:45:34 +02:00
}
2018-02-21 11:52:31 +01:00
\usage{
first_isolate(
x = NULL,
col_date = NULL,
col_patient_id = NULL,
col_mo = NULL,
col_testcode = NULL,
col_specimen = NULL,
col_icu = NULL,
col_keyantimicrobials = NULL,
episode_days = 365,
testcodes_exclude = NULL,
icu_exclude = FALSE,
specimen_group = NULL,
type = "points",
method = c("phenotype-based", "episode-based", "patient-based", "isolate-based"),
ignore_I = TRUE,
points_threshold = 2,
info = interactive(),
include_unknown = FALSE,
include_untested_rsi = TRUE,
...
)
filter_first_isolate(
x = NULL,
col_date = NULL,
col_patient_id = NULL,
col_mo = NULL,
2021-04-29 17:16:30 +02:00
episode_days = 365,
method = c("phenotype-based", "episode-based", "patient-based", "isolate-based"),
...
)
2018-02-21 11:52:31 +01:00
}
\arguments{
\item{x}{a \link{data.frame} containing isolates. Can be left blank for automatic determination, see \emph{Examples}.}
2018-02-21 11:52:31 +01:00
2020-11-17 16:57:41 +01:00
\item{col_date}{column name of the result date (or date that is was received on the lab), defaults to the first column with a date class}
2018-02-21 11:52:31 +01:00
2018-12-10 15:14:29 +01:00
\item{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)}
2018-02-21 11:52:31 +01:00
\item{col_mo}{column name of the IDs of the microorganisms (see \code{\link[=as.mo]{as.mo()}}), defaults to the first column of class \code{\link{mo}}. Values will be coerced using \code{\link[=as.mo]{as.mo()}}.}
2018-02-21 11:52:31 +01:00
2020-12-17 16:22:25 +01:00
\item{col_testcode}{column name of the test codes. Use \code{col_testcode = NULL} to \strong{not} exclude certain test codes (such as test codes for screening). In that case \code{testcodes_exclude} will be ignored.}
2018-02-21 11:52:31 +01:00
2018-04-02 11:11:21 +02:00
\item{col_specimen}{column name of the specimen type or group}
2018-02-21 11:52:31 +01:00
2018-04-02 11:11:21 +02:00
\item{col_icu}{column name of the logicals (\code{TRUE}/\code{FALSE}) whether a ward or department is an Intensive Care Unit (ICU)}
2018-02-21 11:52:31 +01:00
\item{col_keyantimicrobials}{(only useful when \code{method = "phenotype-based"}) column name of the key antimicrobials to determine first isolates, see \code{\link[=key_antimicrobials]{key_antimicrobials()}}. Defaults to the first column that starts with 'key' followed by 'ab' or 'antibiotics' or 'antimicrobials' (case insensitive). Use \code{col_keyantimicrobials = FALSE} to prevent this. Can also be the output of \code{\link[=key_antimicrobials]{key_antimicrobials()}}.}
2018-02-21 11:52:31 +01:00
\item{episode_days}{episode in days after which a genus/species combination will be determined as 'first isolate' again. The default of 365 days is based on the guideline by CLSI, see \emph{Source}.}
2018-02-21 11:52:31 +01:00
2021-05-12 18:15:03 +02:00
\item{testcodes_exclude}{a \link{character} vector with test codes that should be excluded (case-insensitive)}
2018-02-21 11:52:31 +01:00
2021-05-12 18:15:03 +02:00
\item{icu_exclude}{a \link{logical} to indicate whether ICU isolates should be excluded (rows with value \code{TRUE} in the column set with \code{col_icu})}
2018-02-21 11:52:31 +01:00
2020-12-22 00:51:17 +01:00
\item{specimen_group}{value in the column set with \code{col_specimen} to filter on}
2018-02-21 11:52:31 +01:00
\item{type}{type to determine weighed isolates; can be \code{"keyantimicrobials"} or \code{"points"}, see \emph{Details}}
2021-04-29 17:16:30 +02:00
\item{method}{the method to apply, either \code{"phenotype-based"}, \code{"episode-based"}, \code{"patient-based"} or \code{"isolate-based"} (can be abbreviated), see \emph{Details}. The default is \code{"phenotype-based"} if antimicrobial test results are present in the data, and \code{"episode-based"} otherwise.}
2021-05-12 18:15:03 +02:00
\item{ignore_I}{\link{logical} to indicate whether antibiotic interpretations with \code{"I"} will be ignored when \code{type = "keyantimicrobials"}, see \emph{Details}}
\item{points_threshold}{minimum number of points to require before differences in the antibiogram will lead to inclusion of an isolate when \code{type = "points"}, see \emph{Details}}
2018-02-21 11:52:31 +01:00
2021-04-23 16:13:26 +02:00
\item{info}{a \link{logical} to indicate info should be printed, defaults to \code{TRUE} only in interactive mode}
2021-05-12 18:15:03 +02:00
\item{include_unknown}{a \link{logical} to indicate whether 'unknown' microorganisms should be included too, i.e. microbial code \code{"UNKNOWN"}, which defaults to \code{FALSE}. For WHONET users, this means that all records with organism code \code{"con"} (\emph{contamination}) will be excluded at default. Isolates with a microbial ID of \code{NA} will always be excluded as first isolate.}
2021-05-12 18:15:03 +02:00
\item{include_untested_rsi}{a \link{logical} to indicate whether also rows without antibiotic results are still eligible for becoming a first isolate. Use \code{include_untested_rsi = FALSE} to always return \code{FALSE} for such rows. This checks the data set for columns of class \verb{<rsi>} and consequently requires transforming columns with antibiotic results using \code{\link[=as.rsi]{as.rsi()}} first.}
2021-04-29 17:16:30 +02:00
\item{...}{arguments passed on to \code{\link[=first_isolate]{first_isolate()}} when using \code{\link[=filter_first_isolate]{filter_first_isolate()}}, otherwise arguments passed on to \code{\link[=key_antimicrobials]{key_antimicrobials()}} (such as \code{universal}, \code{gram_negative}, \code{gram_positive})}
2018-02-21 11:52:31 +01:00
}
\value{
A \code{\link{logical}} vector
2018-02-21 11:52:31 +01:00
}
\description{
Determine first isolates of all microorganisms of every patient per episode and (if needed) per specimen type. These functions support all four methods as summarised by Hindler \emph{et al.} in 2007 (\doi{10.1086/511864}). To determine patient episodes not necessarily based on microorganisms, use \code{\link[=is_new_episode]{is_new_episode()}} that also supports grouping with the \code{dplyr} package.
2018-02-21 11:52:31 +01:00
}
\details{
2021-04-29 17:16:30 +02:00
To conduct epidemiological analyses on antimicrobial resistance data, only so-called first isolates should be included to prevent overestimation and underestimation of antimicrobial resistance. Different methods can be used to do so, see below.
2021-05-17 19:43:01 +02:00
These functions are context-aware. This means that the \code{x} argument can be left blank if used inside a \link{data.frame} call, see \emph{Examples}.
2020-11-23 21:50:27 +01:00
The \code{\link[=first_isolate]{first_isolate()}} function is a wrapper around the \code{\link[=is_new_episode]{is_new_episode()}} function, but more efficient for data sets containing microorganism codes or names.
2018-12-22 22:39:34 +01:00
All isolates with a microbial ID of \code{NA} will be excluded as first isolate.
2021-04-29 17:16:30 +02:00
\subsection{Different methods}{
2020-11-17 16:57:41 +01:00
2021-04-29 17:16:30 +02:00
According to Hindler \emph{et al.} (2007, \doi{10.1086/511864}), there are different methods (algorithms) to select first isolates with increasing reliability: isolate-based, patient-based, episode-based and phenotype-based. All methods select on a combination of the taxonomic genus and species (not subspecies).
2020-11-17 16:57:41 +01:00
2021-04-29 17:16:30 +02:00
All mentioned methods are covered in the \code{\link[=first_isolate]{first_isolate()}} function:\tabular{ll}{
\strong{Method} \tab \strong{Function to apply} \cr
\strong{Isolate-based} \tab \code{first_isolate(x, method = "isolate-based")} \cr
\emph{(= all isolates)} \tab \cr
\tab \cr
\tab \cr
2021-04-29 17:16:30 +02:00
\strong{Patient-based} \tab \code{first_isolate(x, method = "patient-based")} \cr
\emph{(= first isolate per patient)} \tab \cr
\tab \cr
\tab \cr
2021-04-29 17:16:30 +02:00
\strong{Episode-based} \tab \code{first_isolate(x, method = "episode-based")}, or: \cr
\emph{(= first isolate per episode)} \tab \cr
- 7-Day interval from initial isolate \tab - \code{first_isolate(x, method = "e", episode_days = 7)} \cr
- 30-Day interval from initial isolate \tab - \code{first_isolate(x, method = "e", episode_days = 30)} \cr
\tab \cr
\tab \cr
2021-04-29 17:16:30 +02:00
\strong{Phenotype-based} \tab \code{first_isolate(x, method = "phenotype-based")}, or: \cr
\emph{(= first isolate per phenotype)} \tab \cr
- Major difference in any antimicrobial result \tab - \code{first_isolate(x, type = "points")} \cr
- Any difference in key antimicrobial results \tab - \code{first_isolate(x, type = "keyantimicrobials")} \cr
}
\subsection{Isolate-based}{
2020-11-17 16:57:41 +01:00
2021-04-29 17:16:30 +02:00
This method does not require any selection, as all isolates should be included. It does, however, respect all arguments set in the \code{\link[=first_isolate]{first_isolate()}} function. For example, the default setting for \code{include_unknown} (\code{FALSE}) will omit selection of rows without a microbial ID.
2018-12-22 22:39:34 +01:00
}
\subsection{Patient-based}{
2021-04-29 17:16:30 +02:00
To include every genus-species combination per patient once, set the \code{episode_days} to \code{Inf}. Although often inappropriate, this method makes sure that no duplicate isolates are selected from the same patient. In a large longitudinal data set, this could mean that isolates are \emph{excluded} that were found years after the initial isolate.
2018-07-17 13:02:05 +02:00
}
\subsection{Episode-based}{
To include every genus-species combination per patient episode once, set the \code{episode_days} to a sensible number of days. Depending on the type of analysis, this could be 14, 30, 60 or 365. Short episodes are common for analysing specific hospital or ward data, long episodes are common for analysing regional and national data.
2021-04-29 17:16:30 +02:00
This is the most common method to correct for duplicate isolates. Patients are categorised into episodes based on their ID and dates (e.g., the date of specimen receipt or laboratory result). While this is a common method, it does not take into account antimicrobial test results. This means that e.g. a methicillin-resistant \emph{Staphylococcus aureus} (MRSA) isolate cannot be differentiated from a wildtype \emph{Staphylococcus aureus} isolate.
2020-11-17 16:57:41 +01:00
}
2018-07-17 13:02:05 +02:00
\subsection{Phenotype-based}{
2018-03-13 11:57:30 +01:00
2021-04-29 17:16:30 +02:00
This is a more reliable method, since it also \emph{weighs} the antibiogram (antimicrobial test results) yielding so-called 'first weighted isolates'. There are two different methods to weigh the antibiogram:
\enumerate{
\item Using \code{type = "points"} and argument \code{points_threshold} (default)
2018-07-17 13:02:05 +02:00
This method weighs \emph{all} antimicrobial agents available in the data set. Any difference from I to S or R (or vice versa) counts as \code{0.5} points, a difference from S to R (or vice versa) counts as \code{1} point. When the sum of points exceeds \code{points_threshold}, which defaults to \code{2}, an isolate will be selected as a first weighted isolate.
All antimicrobials are internally selected using the \code{\link[=all_antimicrobials]{all_antimicrobials()}} function. The output of this function does not need to be passed to the \code{\link[=first_isolate]{first_isolate()}} function.
\item Using \code{type = "keyantimicrobials"} and argument \code{ignore_I}
This method only weighs specific antimicrobial agents, called \emph{key antimicrobials}. Any difference from S to R (or vice versa) in these key antimicrobials will select an isolate as a first weighted isolate. With \code{ignore_I = FALSE}, also differences from I to S or R (or vice versa) will lead to this.
Key antimicrobials are internally selected using the \code{\link[=key_antimicrobials]{key_antimicrobials()}} function, but can also be added manually as a variable to the data and set in the \code{col_keyantimicrobials} argument. Another option is to pass the output of the \code{\link[=key_antimicrobials]{key_antimicrobials()}} function directly to the \code{col_keyantimicrobials} argument.
}
2021-04-29 17:16:30 +02:00
The default method is phenotype-based (using \code{type = "points"}) and episode-based (using \code{episode_days = 365}). This makes sure that every genus-species combination is selected per patient once per year, while taking into account all antimicrobial test results. If no antimicrobial test results are available in the data set, only the episode-based method is applied at default.
2018-02-21 11:52:31 +01:00
}
2018-07-17 13:02:05 +02:00
}
}
\section{Stable Lifecycle}{
2020-02-22 17:03:47 +01:00
\if{html}{\figure{lifecycle_stable.svg}{options: style=margin-bottom:5px} \cr}
2020-07-08 14:48:06 +02:00
The \link[=lifecycle]{lifecycle} of this function is \strong{stable}. In a stable function, major changes are unlikely. This means that the unlying code will generally evolve by adding new arguments; removing arguments or changing the meaning of existing arguments will be avoided.
2020-02-22 17:03:47 +01:00
If the unlying code needs breaking changes, they will occur gradually. For example, an argument will be deprecated and first continue to work, but will emit an message informing you of the change. Next, typically after at least one newly released version on CRAN, the message will be transformed to an error.
2020-02-22 17:03:47 +01:00
}
\section{Read more on Our Website!}{
2019-01-02 23:24:07 +01:00
2021-06-01 15:33:06 +02:00
On our website \url{https://msberends.github.io/AMR/} you can find \href{https://msberends.github.io/AMR/articles/AMR.html}{a comprehensive tutorial} about how to conduct AMR data analysis, the \href{https://msberends.github.io/AMR/reference/}{complete documentation of all functions} and \href{https://msberends.github.io/AMR/articles/WHONET.html}{an example analysis using WHONET data}.
2019-01-02 23:24:07 +01:00
}
2018-02-21 11:52:31 +01:00
\examples{
# `example_isolates` is a data set available in the AMR package.
# See ?example_isolates.
example_isolates[first_isolate(), ]
\donttest{
# get all first Gram-negatives
example_isolates[which(first_isolate() & mo_is_gram_negative()), ]
if (require("dplyr")) {
# filter on first isolates using dplyr:
example_isolates \%>\%
filter(first_isolate())
2021-04-29 17:16:30 +02:00
# short-hand version:
example_isolates \%>\%
filter_first_isolate()
# grouped determination of first isolates (also prints group names):
example_isolates \%>\%
group_by(hospital_id) \%>\%
mutate(first = first_isolate())
2020-04-15 11:30:28 +02:00
2020-11-17 16:57:41 +01:00
# now let's see if first isolates matter:
A <- example_isolates \%>\%
group_by(hospital_id) \%>\%
summarise(count = n_rsi(GEN), # gentamicin availability
resistance = resistance(GEN)) # gentamicin resistance
B <- example_isolates \%>\%
2021-04-29 17:16:30 +02:00
filter_first_isolate() \%>\% # the 1st isolate filter
group_by(hospital_id) \%>\%
summarise(count = n_rsi(GEN), # gentamicin availability
resistance = resistance(GEN)) # gentamicin resistance
# Have a look at A and B.
# B is more reliable because every isolate is counted only once.
# Gentamicin resistance in hospital D appears to be 4.2\% higher than
# when you (erroneously) would have used all isolates for analysis.
}
2018-02-21 11:52:31 +01:00
}
}
2018-07-17 13:02:05 +02:00
\seealso{
\code{\link[=key_antimicrobials]{key_antimicrobials()}}
2018-07-17 13:02:05 +02:00
}