1
0
mirror of https://github.com/msberends/AMR.git synced 2025-07-08 23:21:56 +02:00

(v1.3.0.9035) mdro() for EUCAST 3.2, examples cleanup

This commit is contained in:
2020-09-29 23:35:46 +02:00
parent 68e6e1e329
commit 4e0374af29
94 changed files with 1143 additions and 1165 deletions

View File

@ -1,39 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/deprecated.R
\name{AMR-deprecated}
\alias{AMR-deprecated}
\alias{portion_R}
\alias{portion_IR}
\alias{portion_I}
\alias{portion_SI}
\alias{portion_S}
\alias{portion_df}
\title{Deprecated functions}
\usage{
portion_R(...)
portion_IR(...)
portion_I(...)
portion_SI(...)
portion_S(...)
portion_df(...)
}
\description{
These functions are so-called '\link{Deprecated}'. They will be removed in a future release. Using the functions will give a warning with the name of the function it has been replaced by (if there is one).
}
\section{Retired lifecycle}{
\if{html}{\figure{lifecycle_retired.svg}{options: style=margin-bottom:5px} \cr}
The \link[=lifecycle]{lifecycle} of this function is \strong{retired}. A retired function is no longer under active development, and (if appropiate) a better alternative is available. No new arguments will be added, and only the most critical bugs will be fixed. In a future version, this function will be removed.
}
\section{Read more on our website!}{
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 analysis, the \href{https://msberends.github.io/AMR/reference}{complete documentation of all functions} (which reads a lot easier than here in R) and \href{https://msberends.github.io/AMR/articles/WHONET.html}{an example analysis using WHONET data}. As we would like to better understand the backgrounds and needs of our users, please \href{https://msberends.github.io/AMR/survey.html}{participate in our survey}!
}
\keyword{internal}

View File

@ -68,7 +68,7 @@ age_groups(ages, "children")
# same:
age_groups(ages, c(1, 2, 4, 6, 13, 17))
\dontrun{
\donttest{
# resistance of ciprofloxacine per age group
library(dplyr)
example_isolates \%>\%

View File

@ -68,8 +68,7 @@ On our website \url{https://msberends.github.io/AMR} you can find \href{https://
}
\examples{
\dontrun{
library(dplyr)
if (require("dplyr")) {
# this will select columns 'IPM' (imipenem) and 'MEM' (meropenem):
example_isolates \%>\%
@ -92,9 +91,9 @@ On our website \url{https://msberends.github.io/AMR} you can find \href{https://
format()
data.frame(irrelevant = "value",
data.frame(some_column = "some_value",
J01CA01 = "S") \%>\% # ATC code of ampicillin
select(penicillins()) # the 'J01CA01' column will be selected
select(penicillins()) # only the 'J01CA01' column will be selected
}
}

View File

@ -38,7 +38,7 @@ On our website \url{https://msberends.github.io/AMR} you can find \href{https://
}
\examples{
\dontrun{
\donttest{
# transform existing disk zones to the `disk` class
library(dplyr)
df <- data.frame(microorganism = "E. coli",
@ -46,8 +46,9 @@ df <- data.frame(microorganism = "E. coli",
CIP = 14,
GEN = 18,
TOB = 16)
df <- df \%>\% mutate_at(vars(AMP:TOB), as.disk)
df
df[, 2:5] <- lapply(df[, 2:5], as.disk)
# same with dplyr:
# df \%>\% mutate(across(AMP:TOB, as.disk))
# interpret disk values, see ?as.rsi
as.rsi(x = as.disk(18),

View File

@ -117,13 +117,7 @@ There are three helper functions that can be run after using the \code{\link[=as
\subsection{Microbial prevalence of pathogens in humans}{
The intelligent rules consider the prevalence of microorganisms in humans grouped into three groups, which is available as the \code{prevalence} columns in the \link{microorganisms} and \link{microorganisms.old} data sets. The grouping into prevalence groups is based on experience from several microbiological laboratories in the Netherlands in conjunction with international reports on pathogen prevalence.
Group 1 (most prevalent microorganisms) consists of all microorganisms where the taxonomic class is Gammaproteobacteria or where the taxonomic genus is \emph{Enterococcus}, \emph{Staphylococcus} or \emph{Streptococcus}. This group consequently contains all common Gram-negative bacteria, such as \emph{Klebsiella}, \emph{Pseudomonas} and \emph{Legionella}.
Group 2 consists of all microorganisms where the taxonomic phylum is Proteobacteria, Firmicutes, Actinobacteria or Sarcomastigophora, or where the taxonomic genus is \emph{Aspergillus}, \emph{Bacteroides}, \emph{Candida}, \emph{Capnocytophaga}, \emph{Chryseobacterium}, \emph{Cryptococcus}, \emph{Elisabethkingia}, \emph{Flavobacterium}, \emph{Fusobacterium}, \emph{Giardia}, \emph{Leptotrichia}, \emph{Mycoplasma}, \emph{Prevotella}, \emph{Rhodotorula}, \emph{Treponema}, \emph{Trichophyton} or \emph{Ureaplasma}. This group consequently contains all less common and rare human pathogens.
Group 3 (least prevalent microorganisms) consists of all other microorganisms. This group contains microorganisms most probably not found in humans.
The intelligent rules consider the prevalence of microorganisms in humans grouped into three groups, which is available as the \code{prevalence} columns in the \link{microorganisms} and \link{microorganisms.old} data sets. The grouping into human pathogenic prevalence is explained in the section \emph{Matching score for microorganisms} below.
}
}
\section{Source}{
@ -153,16 +147,16 @@ With ambiguous user input in \code{\link[=as.mo]{as.mo()}} and all the \code{\li
where:
\itemize{
\item \eqn{x} is the user input;
\item \eqn{n} is a taxonomic name (genus, species and subspecies) as found in \code{\link[=microorganisms]{microorganisms$fullname}};
\item \eqn{l_{n}}{l_n} is the length of \eqn{n};
\item \eqn{\operatorname{lev}}{lev} is the \href{https://en.wikipedia.org/wiki/Levenshtein_distance}{Levenshtein distance function};
\item \eqn{p_{n}}{p_n} is the human pathogenic prevalence of \eqn{n}, categorised into group \eqn{1}, \eqn{2} and \eqn{3} (see \emph{Details} in \code{?as.mo}), meaning that \eqn{p = \{1, 2 , 3\}}{p = {1, 2, 3}};
\item \eqn{k_{n}}{k_n} is the kingdom index of \eqn{n}, set as follows: Bacteria = \eqn{1}, Fungi = \eqn{2}, Protozoa = \eqn{3}, Archaea = \eqn{4}, and all others = \eqn{5}, meaning that \eqn{k = \{1, 2 , 3, 4, 5\}}{k = {1, 2, 3, 4, 5}}.
\item \eqn{n} is a taxonomic name (genus, species, and subspecies);
\item \eqn{l_n}{l_n} is the length of \eqn{n};
\item lev is the \href{https://en.wikipedia.org/wiki/Levenshtein_distance}{Levenshtein distance function}, which counts any insertion, deletion and substitution as 1 that is needed to change \eqn{x} into \eqn{n};
\item \eqn{p_n}{p_n} is the human pathogenic prevalence group of \eqn{n}, as described below;
\item \eqn{k_n}{p_n} is the taxonomic kingdom of \eqn{n}, set as Bacteria = 1, Fungi = 2, Protozoa = 3, Archaea = 4, others = 5.
}
This means that the user input \code{x = "E. coli"} gets for \emph{Escherichia coli} a matching score of 68.8\% and for \emph{Entamoeba coli} a matching score of 7.9\%.
The grouping into human pathogenic prevalence (\eqn{p}) is based on experience from several microbiological laboratories in the Netherlands in conjunction with international reports on pathogen prevalence. \strong{Group 1} (most prevalent microorganisms) consists of all microorganisms where the taxonomic class is Gammaproteobacteria or where the taxonomic genus is \emph{Enterococcus}, \emph{Staphylococcus} or \emph{Streptococcus}. This group consequently contains all common Gram-negative bacteria, such as \emph{Pseudomonas} and \emph{Legionella} and all species within the order Enterobacterales. \strong{Group 2} consists of all microorganisms where the taxonomic phylum is Proteobacteria, Firmicutes, Actinobacteria or Sarcomastigophora, or where the taxonomic genus is \emph{Absidia}, \emph{Acremonium}, \emph{Actinotignum}, \emph{Alternaria}, \emph{Anaerosalibacter}, \emph{Apophysomyces}, \emph{Arachnia}, \emph{Aspergillus}, \emph{Aureobacterium}, \emph{Aureobasidium}, \emph{Bacteroides}, \emph{Basidiobolus}, \emph{Beauveria}, \emph{Blastocystis}, \emph{Branhamella}, \emph{Calymmatobacterium}, \emph{Candida}, \emph{Capnocytophaga}, \emph{Catabacter}, \emph{Chaetomium}, \emph{Chryseobacterium}, \emph{Chryseomonas}, \emph{Chrysonilia}, \emph{Cladophialophora}, \emph{Cladosporium}, \emph{Conidiobolus}, \emph{Cryptococcus}, \emph{Curvularia}, \emph{Exophiala}, \emph{Exserohilum}, \emph{Flavobacterium}, \emph{Fonsecaea}, \emph{Fusarium}, \emph{Fusobacterium}, \emph{Hendersonula}, \emph{Hypomyces}, \emph{Koserella}, \emph{Lelliottia}, \emph{Leptosphaeria}, \emph{Leptotrichia}, \emph{Malassezia}, \emph{Malbranchea}, \emph{Mortierella}, \emph{Mucor}, \emph{Mycocentrospora}, \emph{Mycoplasma}, \emph{Nectria}, \emph{Ochroconis}, \emph{Oidiodendron}, \emph{Phoma}, \emph{Piedraia}, \emph{Pithomyces}, \emph{Pityrosporum}, \emph{Prevotella},\\\emph{Pseudallescheria}, \emph{Rhizomucor}, \emph{Rhizopus}, \emph{Rhodotorula}, \emph{Scolecobasidium}, \emph{Scopulariopsis}, \emph{Scytalidium},\emph{Sporobolomyces}, \emph{Stachybotrys}, \emph{Stomatococcus}, \emph{Treponema}, \emph{Trichoderma}, \emph{Trichophyton}, \emph{Trichosporon}, \emph{Tritirachium} or \emph{Ureaplasma}. \strong{Group 3} consists of all other microorganisms.
All matches are sorted descending on their matching score and for all user input values, the top match will be returned.
All matches are sorted descending on their matching score and for all user input values, the top match will be returned. This will lead to the effect that e.g., \code{"E. coli"} will return the microbial ID of \emph{Escherichia coli} (\eqn{m = 0.688}, a highly prevalent microorganism found in humans) and not \emph{Entamoeba coli} (\eqn{m = 0.079}, a less prevalent microorganism in humans), although the latter would alphabetically come first.
}
\section{Catalogue of Life}{
@ -219,25 +213,6 @@ as.mo("S. pyogenes", Lancefield = TRUE) # will not remain species: B_STRPT_GRPA
# All mo_* functions use as.mo() internally too (see ?mo_property):
mo_genus("E. coli") # returns "Escherichia"
mo_gramstain("E. coli") # returns "Gram negative"
}
\dontrun{
df$mo <- as.mo(df$microorganism_name)
# the select function of the Tidyverse is also supported:
library(dplyr)
df$mo <- df \%>\%
select(microorganism_name) \%>\%
as.mo()
# and can even contain 2 columns, which is convenient
# for genus/species combinations:
df$mo <- df \%>\%
select(genus, species) \%>\%
as.mo()
# although this works easier and does the same:
df <- df \%>\%
mutate(mo = as.mo(paste(genus, species)))
}
}
\seealso{

View File

@ -167,34 +167,6 @@ df <- data.frame(microorganism = "E. coli",
NIT = as.mic(32))
as.rsi(df)
\dontrun{
# the dplyr way
library(dplyr)
df \%>\% mutate_if(is.mic, as.rsi)
df \%>\% mutate_if(function(x) is.mic(x) | is.disk(x), as.rsi)
df \%>\% mutate(across(where(is.mic), as.rsi))
df \%>\% mutate_at(vars(AMP:TOB), as.rsi)
df \%>\% mutate(across(AMP:TOB), as.rsi)
df \%>\%
mutate_at(vars(AMP:TOB), as.rsi, mo = "E. coli")
# to include information about urinary tract infections (UTI)
data.frame(mo = "E. coli",
NIT = c("<= 2", 32),
from_the_bladder = c(TRUE, FALSE)) \%>\%
as.rsi(uti = "from_the_bladder")
data.frame(mo = "E. coli",
NIT = c("<= 2", 32),
specimen = c("urine", "blood")) \%>\%
as.rsi() # automatically determines urine isolates
df \%>\%
mutate_at(vars(AMP:NIT), as.rsi, mo = "E. coli", uti = TRUE)
}
# for single values
as.rsi(x = as.mic(2),
mo = as.mo("S. pneumoniae"),
@ -206,6 +178,32 @@ as.rsi(x = as.disk(18),
ab = "ampicillin", # and `ab` with as.ab()
guideline = "EUCAST")
\donttest{
# the dplyr way
if (require("dplyr")) {
df \%>\% mutate_if(is.mic, as.rsi)
df \%>\% mutate_if(function(x) is.mic(x) | is.disk(x), as.rsi)
df \%>\% mutate(across(where(is.mic), as.rsi))
df \%>\% mutate_at(vars(AMP:TOB), as.rsi)
df \%>\% mutate(across(AMP:TOB), as.rsi)
df \%>\%
mutate_at(vars(AMP:TOB), as.rsi, mo = "E. coli")
# to include information about urinary tract infections (UTI)
data.frame(mo = "E. coli",
NIT = c("<= 2", 32),
from_the_bladder = c(TRUE, FALSE)) \%>\%
as.rsi(uti = "from_the_bladder")
data.frame(mo = "E. coli",
NIT = c("<= 2", 32),
specimen = c("urine", "blood")) \%>\%
as.rsi() # automatically determines urine isolates
df \%>\%
mutate_at(vars(AMP:NIT), as.rsi, mo = "E. coli", uti = TRUE)
}
# For CLEANING existing R/SI values ------------------------------------
@ -216,25 +214,22 @@ is.rsi(rsi_data)
plot(rsi_data) # for percentages
barplot(rsi_data) # for frequencies
\dontrun{
library(dplyr)
example_isolates \%>\%
mutate_at(vars(PEN:RIF), as.rsi)
# same:
example_isolates \%>\%
as.rsi(PEN:RIF)
# fastest way to transform all columns with already valid AMR results to class `rsi`:
example_isolates \%>\%
mutate_if(is.rsi.eligible, as.rsi)
# note: from dplyr 1.0.0 on, this will be:
# example_isolates \%>\%
# mutate(across(is.rsi.eligible, as.rsi))
# default threshold of `is.rsi.eligible` is 5\%.
is.rsi.eligible(WHONET$`First name`) # fails, >80\% is invalid
is.rsi.eligible(WHONET$`First name`, threshold = 0.99) # succeeds
# the dplyr way
if (require("dplyr")) {
example_isolates \%>\%
mutate_at(vars(PEN:RIF), as.rsi)
# same:
example_isolates \%>\%
as.rsi(PEN:RIF)
# fastest way to transform all columns with already valid AMR results to class `rsi`:
example_isolates \%>\%
mutate_if(is.rsi.eligible, as.rsi)
# note: from dplyr 1.0.0 on, this will be:
# example_isolates \%>\%
# mutate(across(is.rsi.eligible, as.rsi))
}
}
}
\seealso{

View File

@ -80,16 +80,13 @@ On our website \url{https://msberends.github.io/AMR} you can find \href{https://
}
\examples{
\dontrun{
\donttest{
# oral DDD (Defined Daily Dose) of amoxicillin
atc_online_property("J01CA04", "DDD", "O")
# parenteral DDD (Defined Daily Dose) of amoxicillin
atc_online_property("J01CA04", "DDD", "P")
atc_online_property("J01CA04", property = "groups") # search hierarchical groups of amoxicillin
# [1] "ANTIINFECTIVES FOR SYSTEMIC USE"
# [2] "ANTIBACTERIALS FOR SYSTEMIC USE"
# [3] "BETA-LACTAM ANTIBACTERIALS, PENICILLINS"
# [4] "Penicillins with extended spectrum"
}
}

View File

@ -36,17 +36,10 @@ On our website \url{https://msberends.github.io/AMR} you can find \href{https://
\examples{
availability(example_isolates)
\dontrun{
library(dplyr)
example_isolates \%>\% availability()
example_isolates \%>\%
select_if(is.rsi) \%>\%
availability()
example_isolates \%>\%
filter(mo == as.mo("E. coli")) \%>\%
select_if(is.rsi) \%>\%
availability()
if (require("dplyr")) {
example_isolates \%>\%
filter(mo == as.mo("E. coli")) \%>\%
select_if(is.rsi) \%>\%
availability()
}
}

View File

@ -45,7 +45,7 @@ bug_drug_combinations(x, col_mo = NULL, FUN = mo_shortname, ...)
\item{add_ab_group}{logical to indicate where the group of the antimicrobials must be included as a first column}
\item{remove_intrinsic_resistant}{logical to indicate that rows with 100\% resistance for all tested antimicrobials must be removed from the table}
\item{remove_intrinsic_resistant}{logical to indicate that rows and columns with 100\% resistance for all tested antimicrobials must be removed from the table}
\item{decimal.mark}{the character to be used to indicate the numeric
decimal point.}
@ -83,12 +83,12 @@ x
format(x, translate_ab = "name (atc)")
# Use FUN to change to transformation of microorganism codes
x <- bug_drug_combinations(example_isolates,
FUN = mo_gramstain)
bug_drug_combinations(example_isolates,
FUN = mo_gramstain)
x <- bug_drug_combinations(example_isolates,
FUN = function(x) ifelse(x == as.mo("E. coli"),
"E. coli",
"Others"))
bug_drug_combinations(example_isolates,
FUN = function(x) ifelse(x == as.mo("E. coli"),
"E. coli",
"Others"))
}
}

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

View File

@ -71,40 +71,43 @@ If the unlying code needs breaking changes, they will occur gradually. For examp
}
\examples{
\dontrun{
library(dplyr)
filter_aminoglycosides(example_isolates)
# filter on isolates that have any result for any aminoglycoside
example_isolates \%>\% filter_ab_class("aminoglycoside")
example_isolates \%>\% filter_aminoglycosides()
\donttest{
if (require("dplyr")) {
# this is essentially the same as (but without determination of column names):
example_isolates \%>\%
filter_at(.vars = vars(c("GEN", "TOB", "AMK", "KAN")),
.vars_predicate = any_vars(. \%in\% c("S", "I", "R")))
# filter on isolates that have any result for any aminoglycoside
example_isolates \%>\% filter_aminoglycosides()
example_isolates \%>\% filter_ab_class("aminoglycoside")
# this is essentially the same as (but without determination of column names):
example_isolates \%>\%
filter_at(.vars = vars(c("GEN", "TOB", "AMK", "KAN")),
.vars_predicate = any_vars(. \%in\% c("S", "I", "R")))
# filter on isolates that show resistance to ANY aminoglycoside
example_isolates \%>\% filter_aminoglycosides("R", "any")
# filter on isolates that show resistance to ALL aminoglycosides
example_isolates \%>\% filter_aminoglycosides("R", "all")
# filter on isolates that show resistance to
# any aminoglycoside and any fluoroquinolone
example_isolates \%>\%
filter_aminoglycosides("R") \%>\%
filter_fluoroquinolones("R")
# filter on isolates that show resistance to
# all aminoglycosides and all fluoroquinolones
example_isolates \%>\%
filter_aminoglycosides("R", "all") \%>\%
filter_fluoroquinolones("R", "all")
# with dplyr 1.0.0 and higher (that adds 'across()'), this is equal:
example_isolates \%>\% filter_carbapenems("R", "all")
example_isolates \%>\% filter(across(carbapenems(), ~. == "R"))
# filter on isolates that show resistance to ANY aminoglycoside
example_isolates \%>\% filter_aminoglycosides("R", "any")
# filter on isolates that show resistance to ALL aminoglycosides
example_isolates \%>\% filter_aminoglycosides("R", "all")
# filter on isolates that show resistance to
# any aminoglycoside and any fluoroquinolone
example_isolates \%>\%
filter_aminoglycosides("R") \%>\%
filter_fluoroquinolones("R")
# filter on isolates that show resistance to
# all aminoglycosides and all fluoroquinolones
example_isolates \%>\%
filter_aminoglycosides("R", "all") \%>\%
filter_fluoroquinolones("R", "all")
# with dplyr 1.0.0 and higher (that adds 'across()'), this is equal:
example_isolates \%>\% filter_carbapenems("R", "all")
example_isolates \%>\% filter(across(carbapenems(), ~. == "R"))
}
}
}
\seealso{

View File

@ -98,15 +98,16 @@ To conduct an analysis of antimicrobial resistance, you should only include the
All isolates with a microbial ID of \code{NA} will be excluded as first isolate.
The functions \code{\link[=filter_first_isolate]{filter_first_isolate()}} and \code{\link[=filter_first_weighted_isolate]{filter_first_weighted_isolate()}} are helper functions to quickly filter on first isolates. The function \code{\link[=filter_first_isolate]{filter_first_isolate()}} is essentially equal to one of:\preformatted{ x \%>\% filter(first_isolate(., ...))
The functions \code{\link[=filter_first_isolate]{filter_first_isolate()}} and \code{\link[=filter_first_weighted_isolate]{filter_first_weighted_isolate()}} are helper functions to quickly filter on first isolates. The function \code{\link[=filter_first_isolate]{filter_first_isolate()}} is essentially equal to either:\preformatted{ x[first_isolate(x, ...), ]
x \%>\% filter(first_isolate(x, ...))
}
The function \code{\link[=filter_first_weighted_isolate]{filter_first_weighted_isolate()}} is essentially equal to:\preformatted{ x \%>\%
mutate(keyab = key_antibiotics(.)) \%>\%
mutate(only_weighted_firsts = first_isolate(x,
col_keyantibiotics = "keyab", ...)) \%>\%
filter(only_weighted_firsts == TRUE) \%>\%
select(-only_weighted_firsts, -keyab)
The function \code{\link[=filter_first_weighted_isolate]{filter_first_weighted_isolate()}} is essentially equal to:\preformatted{ x \%>\%
mutate(keyab = key_antibiotics(.)) \%>\%
mutate(only_weighted_firsts = first_isolate(x,
col_keyantibiotics = "keyab", ...)) \%>\%
filter(only_weighted_firsts == TRUE) \%>\%
select(-only_weighted_firsts, -keyab)
}
}
\section{Key antibiotics}{
@ -139,49 +140,40 @@ On our website \url{https://msberends.github.io/AMR} you can find \href{https://
# `example_isolates` is a dataset available in the AMR package.
# See ?example_isolates.
\dontrun{
library(dplyr)
# Filter on first isolates:
example_isolates \%>\%
mutate(first_isolate = first_isolate(.)) \%>\%
filter(first_isolate == TRUE)
# basic filtering on first isolates
example_isolates[first_isolate(example_isolates), ]
# 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 \%>\%
filter_first_weighted_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 3.7\% higher than
# when you (erroneously) would have used all isolates for analysis.
## OTHER EXAMPLES:
# Short-hand versions:
example_isolates \%>\%
filter_first_isolate()
\donttest{
if (require("dplyr")) {
# Filter on first isolates:
example_isolates \%>\%
mutate(first_isolate = first_isolate(.)) \%>\%
filter(first_isolate == TRUE)
# Short-hand versions:
example_isolates \%>\%
filter_first_isolate()
example_isolates \%>\%
filter_first_weighted_isolate()
example_isolates \%>\%
filter_first_weighted_isolate()
# set key antibiotics to a new variable
x$keyab <- key_antibiotics(x)
x$first_isolate <- first_isolate(x)
x$first_isolate_weighed <- first_isolate(x, col_keyantibiotics = 'keyab')
x$first_blood_isolate <- first_isolate(x, specimen_group = "Blood")
# 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 \%>\%
filter_first_weighted_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 3.7\% higher than
# when you (erroneously) would have used all isolates for analysis.
}
}
}
\seealso{

View File

@ -118,8 +118,7 @@ The \link[=lifecycle]{lifecycle} of this function is \strong{maturing}. The unly
# See ?example_isolates.
# See ?pca for more info about Principal Component Analysis (PCA).
\dontrun{
library(dplyr)
if (require("dplyr")) {
pca_model <- example_isolates \%>\%
filter(mo_genus(mo) == "Staphylococcus") \%>\%
group_by(species = mo_shortname(mo)) \%>\%

View File

@ -193,14 +193,14 @@ if (require("ggplot2") & require("dplyr")) {
}
\dontrun{
\donttest{
# resistance of ciprofloxacine per age group
example_isolates \%>\%
mutate(first_isolate = first_isolate(.)) \%>\%
filter(first_isolate == TRUE,
mo == as.mo("E. coli")) \%>\%
# `age_group` is also a function of this package:
# `age_groups` is also a function of this AMR package:
group_by(age_group = age_groups(age)) \%>\%
select(age_group,
CIP) \%>\%
@ -209,7 +209,8 @@ example_isolates \%>\%
# for colourblind mode, use divergent colours from the viridis package:
example_isolates \%>\%
select(AMX, NIT, FOS, TMP, CIP) \%>\%
ggplot_rsi() + scale_fill_viridis_d()
ggplot_rsi() +
scale_fill_viridis_d()
# a shorter version which also adjusts data label colours:
example_isolates \%>\%
select(AMX, NIT, FOS, TMP, CIP) \%>\%

View File

@ -57,18 +57,21 @@ On our website \url{https://msberends.github.io/AMR} you can find \href{https://
left_join_microorganisms(as.mo("K. pneumoniae"))
left_join_microorganisms("B_KLBSL_PNE")
\dontrun{
library(dplyr)
example_isolates \%>\% left_join_microorganisms()
df <- data.frame(date = seq(from = as.Date("2018-01-01"),
to = as.Date("2018-01-07"),
by = 1),
bacteria = as.mo(c("S. aureus", "MRSA", "MSSA", "STAAUR",
"E. coli", "E. coli", "E. coli")),
stringsAsFactors = FALSE)
colnames(df)
df_joined <- left_join_microorganisms(df, "bacteria")
colnames(df_joined)
\donttest{
if (require("dplyr")) {
example_isolates \%>\%
left_join_microorganisms() \%>\%
colnames()
df <- data.frame(date = seq(from = as.Date("2018-01-01"),
to = as.Date("2018-01-07"),
by = 1),
bacteria = as.mo(c("S. aureus", "MRSA", "MSSA", "STAAUR",
"E. coli", "E. coli", "E. coli")),
stringsAsFactors = FALSE)
colnames(df)
df_joined <- left_join_microorganisms(df, "bacteria")
colnames(df_joined)
}
}
}

View File

@ -136,32 +136,34 @@ On our website \url{https://msberends.github.io/AMR} you can find \href{https://
# `example_isolates` is a dataset available in the AMR package.
# See ?example_isolates.
\dontrun{
library(dplyr)
# set key antibiotics to a new variable
my_patients <- example_isolates \%>\%
mutate(keyab = key_antibiotics(.)) \%>\%
mutate(
# now calculate first isolates
first_regular = first_isolate(., col_keyantibiotics = FALSE),
# and first WEIGHTED isolates
first_weighted = first_isolate(., col_keyantibiotics = "keyab")
)
# Check the difference, in this data set it results in 7\% more isolates:
sum(my_patients$first_regular, na.rm = TRUE)
sum(my_patients$first_weighted, na.rm = TRUE)
}
# output of the `key_antibiotics` function could be like this:
strainA <- "SSSRR.S.R..S"
strainB <- "SSSIRSSSRSSS"
# can those strings can be compared with:
key_antibiotics_equal(strainA, strainB)
# TRUE, because I is ignored (as well as missing values)
key_antibiotics_equal(strainA, strainB, ignore_I = FALSE)
# FALSE, because I is not ignored and so the 4th value differs
\donttest{
if (require("dplyr")) {
# set key antibiotics to a new variable
my_patients <- example_isolates \%>\%
mutate(keyab = key_antibiotics(.)) \%>\%
mutate(
# now calculate first isolates
first_regular = first_isolate(., col_keyantibiotics = FALSE),
# and first WEIGHTED isolates
first_weighted = first_isolate(., col_keyantibiotics = "keyab")
)
# Check the difference, in this data set it results in 7\% more isolates:
sum(my_patients$first_regular, na.rm = TRUE)
sum(my_patients$first_weighted, na.rm = TRUE)
}
}
}
\seealso{
\code{\link[=first_isolate]{first_isolate()}}

View File

@ -68,10 +68,11 @@ a \%like\% b
#> TRUE TRUE TRUE
# get isolates whose name start with 'Ent' or 'ent'
\dontrun{
library(dplyr)
example_isolates \%>\%
filter(mo_name(mo) \%like\% "^ent")
\donttest{
if (require("dplyr")) {
example_isolates \%>\%
filter(mo_name(mo) \%like\% "^ent")
}
}
}
\seealso{

File diff suppressed because one or more lines are too long

View File

@ -23,21 +23,22 @@ With ambiguous user input in \code{\link[=as.mo]{as.mo()}} and all the \code{\li
where:
\itemize{
\item \eqn{x} is the user input;
\item \eqn{n} is a taxonomic name (genus, species and subspecies) as found in \code{\link[=microorganisms]{microorganisms$fullname}};
\item \eqn{l_{n}}{l_n} is the length of \eqn{n};
\item \eqn{\operatorname{lev}}{lev} is the \href{https://en.wikipedia.org/wiki/Levenshtein_distance}{Levenshtein distance function};
\item \eqn{p_{n}}{p_n} is the human pathogenic prevalence of \eqn{n}, categorised into group \eqn{1}, \eqn{2} and \eqn{3} (see \emph{Details} in \code{?as.mo}), meaning that \eqn{p = \{1, 2 , 3\}}{p = {1, 2, 3}};
\item \eqn{k_{n}}{k_n} is the kingdom index of \eqn{n}, set as follows: Bacteria = \eqn{1}, Fungi = \eqn{2}, Protozoa = \eqn{3}, Archaea = \eqn{4}, and all others = \eqn{5}, meaning that \eqn{k = \{1, 2 , 3, 4, 5\}}{k = {1, 2, 3, 4, 5}}.
\item \eqn{n} is a taxonomic name (genus, species, and subspecies);
\item \eqn{l_n}{l_n} is the length of \eqn{n};
\item lev is the \href{https://en.wikipedia.org/wiki/Levenshtein_distance}{Levenshtein distance function}, which counts any insertion, deletion and substitution as 1 that is needed to change \eqn{x} into \eqn{n};
\item \eqn{p_n}{p_n} is the human pathogenic prevalence group of \eqn{n}, as described below;
\item \eqn{k_n}{p_n} is the taxonomic kingdom of \eqn{n}, set as Bacteria = 1, Fungi = 2, Protozoa = 3, Archaea = 4, others = 5.
}
This means that the user input \code{x = "E. coli"} gets for \emph{Escherichia coli} a matching score of 68.8\% and for \emph{Entamoeba coli} a matching score of 7.9\%.
The grouping into human pathogenic prevalence (\eqn{p}) is based on experience from several microbiological laboratories in the Netherlands in conjunction with international reports on pathogen prevalence. \strong{Group 1} (most prevalent microorganisms) consists of all microorganisms where the taxonomic class is Gammaproteobacteria or where the taxonomic genus is \emph{Enterococcus}, \emph{Staphylococcus} or \emph{Streptococcus}. This group consequently contains all common Gram-negative bacteria, such as \emph{Pseudomonas} and \emph{Legionella} and all species within the order Enterobacterales. \strong{Group 2} consists of all microorganisms where the taxonomic phylum is Proteobacteria, Firmicutes, Actinobacteria or Sarcomastigophora, or where the taxonomic genus is \emph{Absidia}, \emph{Acremonium}, \emph{Actinotignum}, \emph{Alternaria}, \emph{Anaerosalibacter}, \emph{Apophysomyces}, \emph{Arachnia}, \emph{Aspergillus}, \emph{Aureobacterium}, \emph{Aureobasidium}, \emph{Bacteroides}, \emph{Basidiobolus}, \emph{Beauveria}, \emph{Blastocystis}, \emph{Branhamella}, \emph{Calymmatobacterium}, \emph{Candida}, \emph{Capnocytophaga}, \emph{Catabacter}, \emph{Chaetomium}, \emph{Chryseobacterium}, \emph{Chryseomonas}, \emph{Chrysonilia}, \emph{Cladophialophora}, \emph{Cladosporium}, \emph{Conidiobolus}, \emph{Cryptococcus}, \emph{Curvularia}, \emph{Exophiala}, \emph{Exserohilum}, \emph{Flavobacterium}, \emph{Fonsecaea}, \emph{Fusarium}, \emph{Fusobacterium}, \emph{Hendersonula}, \emph{Hypomyces}, \emph{Koserella}, \emph{Lelliottia}, \emph{Leptosphaeria}, \emph{Leptotrichia}, \emph{Malassezia}, \emph{Malbranchea}, \emph{Mortierella}, \emph{Mucor}, \emph{Mycocentrospora}, \emph{Mycoplasma}, \emph{Nectria}, \emph{Ochroconis}, \emph{Oidiodendron}, \emph{Phoma}, \emph{Piedraia}, \emph{Pithomyces}, \emph{Pityrosporum}, \emph{Prevotella},\\\emph{Pseudallescheria}, \emph{Rhizomucor}, \emph{Rhizopus}, \emph{Rhodotorula}, \emph{Scolecobasidium}, \emph{Scopulariopsis}, \emph{Scytalidium},\emph{Sporobolomyces}, \emph{Stachybotrys}, \emph{Stomatococcus}, \emph{Treponema}, \emph{Trichoderma}, \emph{Trichophyton}, \emph{Trichosporon}, \emph{Tritirachium} or \emph{Ureaplasma}. \strong{Group 3} consists of all other microorganisms.
All matches are sorted descending on their matching score and for all user input values, the top match will be returned.
All matches are sorted descending on their matching score and for all user input values, the top match will be returned. This will lead to the effect that e.g., \code{"E. coli"} will return the microbial ID of \emph{Escherichia coli} (\eqn{m = 0.688}, a highly prevalent microorganism found in humans) and not \emph{Entamoeba coli} (\eqn{m = 0.079}, a less prevalent microorganism in humans), although the latter would alphabetically come first.
}
\examples{
as.mo("E. coli")
mo_uncertainties()
mo_matching_score("E. coli", "Escherichia coli")
mo_matching_score(x = "E. coli",
n = c("Escherichia coli", "Entamoeba coli"))
}

View File

@ -133,16 +133,16 @@ With ambiguous user input in \code{\link[=as.mo]{as.mo()}} and all the \code{\li
where:
\itemize{
\item \eqn{x} is the user input;
\item \eqn{n} is a taxonomic name (genus, species and subspecies) as found in \code{\link[=microorganisms]{microorganisms$fullname}};
\item \eqn{l_{n}}{l_n} is the length of \eqn{n};
\item \eqn{\operatorname{lev}}{lev} is the \href{https://en.wikipedia.org/wiki/Levenshtein_distance}{Levenshtein distance function};
\item \eqn{p_{n}}{p_n} is the human pathogenic prevalence of \eqn{n}, categorised into group \eqn{1}, \eqn{2} and \eqn{3} (see \emph{Details} in \code{?as.mo}), meaning that \eqn{p = \{1, 2 , 3\}}{p = {1, 2, 3}};
\item \eqn{k_{n}}{k_n} is the kingdom index of \eqn{n}, set as follows: Bacteria = \eqn{1}, Fungi = \eqn{2}, Protozoa = \eqn{3}, Archaea = \eqn{4}, and all others = \eqn{5}, meaning that \eqn{k = \{1, 2 , 3, 4, 5\}}{k = {1, 2, 3, 4, 5}}.
\item \eqn{n} is a taxonomic name (genus, species, and subspecies);
\item \eqn{l_n}{l_n} is the length of \eqn{n};
\item lev is the \href{https://en.wikipedia.org/wiki/Levenshtein_distance}{Levenshtein distance function}, which counts any insertion, deletion and substitution as 1 that is needed to change \eqn{x} into \eqn{n};
\item \eqn{p_n}{p_n} is the human pathogenic prevalence group of \eqn{n}, as described below;
\item \eqn{k_n}{p_n} is the taxonomic kingdom of \eqn{n}, set as Bacteria = 1, Fungi = 2, Protozoa = 3, Archaea = 4, others = 5.
}
This means that the user input \code{x = "E. coli"} gets for \emph{Escherichia coli} a matching score of 68.8\% and for \emph{Entamoeba coli} a matching score of 7.9\%.
The grouping into human pathogenic prevalence (\eqn{p}) is based on experience from several microbiological laboratories in the Netherlands in conjunction with international reports on pathogen prevalence. \strong{Group 1} (most prevalent microorganisms) consists of all microorganisms where the taxonomic class is Gammaproteobacteria or where the taxonomic genus is \emph{Enterococcus}, \emph{Staphylococcus} or \emph{Streptococcus}. This group consequently contains all common Gram-negative bacteria, such as \emph{Pseudomonas} and \emph{Legionella} and all species within the order Enterobacterales. \strong{Group 2} consists of all microorganisms where the taxonomic phylum is Proteobacteria, Firmicutes, Actinobacteria or Sarcomastigophora, or where the taxonomic genus is \emph{Absidia}, \emph{Acremonium}, \emph{Actinotignum}, \emph{Alternaria}, \emph{Anaerosalibacter}, \emph{Apophysomyces}, \emph{Arachnia}, \emph{Aspergillus}, \emph{Aureobacterium}, \emph{Aureobasidium}, \emph{Bacteroides}, \emph{Basidiobolus}, \emph{Beauveria}, \emph{Blastocystis}, \emph{Branhamella}, \emph{Calymmatobacterium}, \emph{Candida}, \emph{Capnocytophaga}, \emph{Catabacter}, \emph{Chaetomium}, \emph{Chryseobacterium}, \emph{Chryseomonas}, \emph{Chrysonilia}, \emph{Cladophialophora}, \emph{Cladosporium}, \emph{Conidiobolus}, \emph{Cryptococcus}, \emph{Curvularia}, \emph{Exophiala}, \emph{Exserohilum}, \emph{Flavobacterium}, \emph{Fonsecaea}, \emph{Fusarium}, \emph{Fusobacterium}, \emph{Hendersonula}, \emph{Hypomyces}, \emph{Koserella}, \emph{Lelliottia}, \emph{Leptosphaeria}, \emph{Leptotrichia}, \emph{Malassezia}, \emph{Malbranchea}, \emph{Mortierella}, \emph{Mucor}, \emph{Mycocentrospora}, \emph{Mycoplasma}, \emph{Nectria}, \emph{Ochroconis}, \emph{Oidiodendron}, \emph{Phoma}, \emph{Piedraia}, \emph{Pithomyces}, \emph{Pityrosporum}, \emph{Prevotella},\\\emph{Pseudallescheria}, \emph{Rhizomucor}, \emph{Rhizopus}, \emph{Rhodotorula}, \emph{Scolecobasidium}, \emph{Scopulariopsis}, \emph{Scytalidium},\emph{Sporobolomyces}, \emph{Stachybotrys}, \emph{Stomatococcus}, \emph{Treponema}, \emph{Trichoderma}, \emph{Trichophyton}, \emph{Trichosporon}, \emph{Tritirachium} or \emph{Ureaplasma}. \strong{Group 3} consists of all other microorganisms.
All matches are sorted descending on their matching score and for all user input values, the top match will be returned.
All matches are sorted descending on their matching score and for all user input values, the top match will be returned. This will lead to the effect that e.g., \code{"E. coli"} will return the microbial ID of \emph{Escherichia coli} (\eqn{m = 0.688}, a highly prevalent microorganism found in humans) and not \emph{Entamoeba coli} (\eqn{m = 0.079}, a less prevalent microorganism in humans), although the latter would alphabetically come first.
}
\section{Catalogue of Life}{

View File

@ -17,6 +17,9 @@ Text
\description{
Return the symbol related to the p-value: 0 '\verb{***}' 0.001 '\verb{**}' 0.01 '\code{*}' 0.05 '\code{.}' 0.1 ' ' 1. Values above \code{p = 1} will return \code{NA}.
}
\details{
\strong{NOTE}: this function will be moved to the \code{cleaner} package when a new version is being published on CRAN.
}
\section{Questioning lifecycle}{
\if{html}{\figure{lifecycle_questioning.svg}{options: style=margin-bottom:5px} \cr}

View File

@ -69,21 +69,23 @@ The \link[=lifecycle]{lifecycle} of this function is \strong{maturing}. The unly
# `example_isolates` is a dataset available in the AMR package.
# See ?example_isolates.
\dontrun{
# calculate the resistance per group first
library(dplyr)
resistance_data <- example_isolates \%>\%
group_by(order = mo_order(mo), # group on anything, like order
genus = mo_genus(mo)) \%>\% # and genus as we do here
summarise_if(is.rsi, resistance) # then get resistance of all drugs
# now conduct PCA for certain antimicrobial agents
pca_result <- resistance_data \%>\%
pca(AMC, CXM, CTX, CAZ, GEN, TOB, TMP, SXT)
pca_result
summary(pca_result)
biplot(pca_result)
ggplot_pca(pca_result) # a new and convenient plot function
\donttest{
if (require("dplyr")) {
# calculate the resistance per group first
resistance_data <- example_isolates \%>\%
group_by(order = mo_order(mo), # group on anything, like order
genus = mo_genus(mo)) \%>\% # and genus as we do here
summarise_if(is.rsi, resistance) # then get resistance of all drugs
# now conduct PCA for certain antimicrobial agents
pca_result <- resistance_data \%>\%
pca(AMC, CXM, CTX, CAZ, GEN, TOB, TMP, SXT)
pca_result
summary(pca_result)
biplot(pca_result)
ggplot_pca(pca_result) # a new and convenient plot function
}
}
}

View File

@ -218,15 +218,6 @@ if (require("dplyr")) {
group_by(hospital_id) \%>\%
proportion_df(translate = FALSE)
}
\dontrun{
# calculate current empiric combination therapy of Helicobacter gastritis:
my_table \%>\%
filter(first_isolate == TRUE,
genus == "Helicobacter") \%>\%
summarise(p = susceptibility(AMX, MTR), # amoxicillin with metronidazole
n = count_all(AMX, MTR))
}
}
\seealso{
\code{\link[=count]{count()}} to count resistant and susceptible isolates.

View File

@ -150,9 +150,7 @@ if (require("dplyr")) {
}
# create nice plots with ggplot2 yourself
\dontrun{
library(dplyr)
library(ggplot2)
if (require("dplyr") & require("ggplot2")) {
data <- example_isolates \%>\%
filter(mo == as.mo("E. coli")) \%>\%