1
0
mirror of https://github.com/msberends/AMR.git synced 2025-07-08 14:01:55 +02:00

(v0.7.1.9063) septic_patients -> example_isolates

This commit is contained in:
2019-08-27 16:45:42 +02:00
parent 7a6fce4eb8
commit 93be16484b
92 changed files with 1143 additions and 818 deletions

View File

@ -37,7 +37,7 @@
WHONET
}
\description{
This example data set has the exact same structure as an export file from WHONET. Such files can be used with this package, as this example data set shows. The data itself was based on our \code{\link{septic_patients}} data set.
This example data set has the exact same structure as an export file from WHONET. Such files can be used with this package, as this example data set shows. The data itself was based on our \code{\link{example_isolates}} data set.
}
\section{Read more on our website!}{

View File

@ -60,7 +60,7 @@ age_groups(ages, c(1, 2, 4, 6, 13, 17))
# resistance of ciprofloxacine per age group
library(dplyr)
septic_patients \%>\%
example_isolates \%>\%
filter_first_isolate() \%>\%
filter(mo == as.mo("E. coli")) \%>\%
group_by(age_group = age_groups(age)) \%>\%

View File

@ -96,12 +96,12 @@ freq(rsi_data) # frequency table with informative header
# using dplyr's mutate
library(dplyr)
septic_patients \%>\%
example_isolates \%>\%
mutate_at(vars(PEN:RIF), as.rsi)
# fastest way to transform all columns with already valid AB results to class `rsi`:
septic_patients \%>\%
example_isolates \%>\%
mutate_if(is.rsi.eligible,
as.rsi)

View File

@ -26,16 +26,16 @@ On our website \url{https://msberends.gitlab.io/AMR} you can find \href{https://
}
\examples{
availability(septic_patients)
availability(example_isolates)
library(dplyr)
septic_patients \%>\% availability()
example_isolates \%>\% availability()
septic_patients \%>\%
example_isolates \%>\%
select_if(is.rsi) \%>\%
availability()
septic_patients \%>\%
example_isolates \%>\%
filter(mo == as.mo("E. coli")) \%>\%
select_if(is.rsi) \%>\%
availability()

View File

@ -15,10 +15,15 @@ bug_drug_combinations(x, col_mo = NULL, minimum = 30)
\item{col_mo}{column name of the unique IDs of the microorganisms (see \code{\link{mo}}), defaults to the first column of class \code{mo}. Values will be coerced using \code{\link{as.mo}}.}
\item{minimum}{the minimum allowed number of available (tested) isolates. Any isolate count lower than \code{minimum} will return \code{NA} with a warning. The default number of \code{30} isolates is advised by the Clinical and Laboratory Standards Institute (CLSI) as best practice, see Source.}
\item{combine_RI}{logical to indicate whether values R and I should be summed}
}
\description{
Determine antimicrobial resistance (AMR) of all bug-drug combinations in your data set where at least 30 (default) isolates are available per species. Use \code{format} on the result to prettify it to a printable format, see Examples.
}
\details{
The function \code{format} calculated the resistance per bug-drug combination. Use \code{combine_RI = FALSE} (default) to test R vs. S+I and \code{combine_RI = TRUE} to test R+I vs. S.
}
\section{Read more on our website!}{
On our website \url{https://msberends.gitlab.io/AMR} you can find \href{https://msberends.gitlab.io/AMR/articles/AMR.html}{a tutorial} about how to conduct AMR analysis, the \href{https://msberends.gitlab.io/AMR/reference}{complete documentation of all functions} (which reads a lot easier than here in R) and \href{https://msberends.gitlab.io/AMR/articles/WHONET.html}{an example analysis using WHONET data}.
@ -26,7 +31,7 @@ On our website \url{https://msberends.gitlab.io/AMR} you can find \href{https://
\examples{
\donttest{
x <- bug_drug_combinations(septic_patients)
x <- bug_drug_combinations(example_isolates)
x
format(x)
}

View File

@ -122,29 +122,29 @@ On our website \url{https://msberends.gitlab.io/AMR} you can find \href{https://
}
\examples{
# septic_patients is a data set available in the AMR package. It is true, genuine data.
?septic_patients
# example_isolates is a data set available in the AMR package.
?example_isolates
# Count resistant isolates
count_R(septic_patients$AMX)
count_IR(septic_patients$AMX)
count_R(example_isolates$AMX)
count_IR(example_isolates$AMX)
# Or susceptible isolates
count_S(septic_patients$AMX)
count_SI(septic_patients$AMX)
count_S(example_isolates$AMX)
count_SI(example_isolates$AMX)
# Count all available isolates
count_all(septic_patients$AMX)
n_rsi(septic_patients$AMX)
count_all(example_isolates$AMX)
n_rsi(example_isolates$AMX)
# Since n_rsi counts available isolates, you can
# calculate back to count e.g. non-susceptible isolates.
# This results in the same:
count_SI(septic_patients$AMX)
portion_SI(septic_patients$AMX) * n_rsi(septic_patients$AMX)
count_SI(example_isolates$AMX)
portion_SI(example_isolates$AMX) * n_rsi(example_isolates$AMX)
library(dplyr)
septic_patients \%>\%
example_isolates \%>\%
group_by(hospital_id) \%>\%
summarise(R = count_R(CIP),
I = count_I(CIP),
@ -156,24 +156,24 @@ septic_patients \%>\%
# Count co-resistance between amoxicillin/clav acid and gentamicin,
# so we can see that combination therapy does a lot more than mono therapy.
# Please mind that `portion_SI` calculates percentages right away instead.
count_SI(septic_patients$AMC) # 1433
count_all(septic_patients$AMC) # 1879
count_SI(example_isolates$AMC) # 1433
count_all(example_isolates$AMC) # 1879
count_SI(septic_patients$GEN) # 1399
count_all(septic_patients$GEN) # 1855
count_SI(example_isolates$GEN) # 1399
count_all(example_isolates$GEN) # 1855
with(septic_patients,
with(example_isolates,
count_SI(AMC, GEN)) # 1764
with(septic_patients,
with(example_isolates,
n_rsi(AMC, GEN)) # 1936
# Get portions S/I/R immediately of all rsi columns
septic_patients \%>\%
example_isolates \%>\%
select(AMX, CIP) \%>\%
count_df(translate = FALSE)
# It also supports grouping variables
septic_patients \%>\%
example_isolates \%>\%
select(hospital_id, AMX, CIP) \%>\%
group_by(hospital_id) \%>\%
count_df(translate = FALSE)

8
man/septic_patients.Rd → man/example_isolates.Rd Executable file → Normal file
View File

@ -1,8 +1,8 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/data.R
\docType{data}
\name{septic_patients}
\alias{septic_patients}
\name{example_isolates}
\alias{example_isolates}
\title{Data set with 2,000 blood culture isolates from septic patients}
\format{A \code{\link{data.frame}} with 2,000 observations and 49 variables:
\describe{
@ -18,10 +18,10 @@
\item{\code{peni:rifa}}{40 different antibiotics with class \code{rsi} (see \code{\link{as.rsi}}); these column names occur in \code{\link{antibiotics}} data set and can be translated with \code{\link{ab_name}}}
}}
\usage{
septic_patients
example_isolates
}
\description{
An anonymised data set containing 2,000 microbial blood culture isolates with their full antibiograms found in septic patients in 4 different hospitals in the Netherlands, between 2001 and 2017. It is true, genuine data. This \code{data.frame} can be used to practice AMR analysis. For examples, please read \href{https://msberends.gitlab.io/AMR/articles/AMR.html}{the tutorial on our website}.
An anonymised data set containing 2,000 microbial blood culture isolates with their full antibiograms found in septic patients in 4 different hospitals in the Netherlands, between 2001 and 2017. This \code{data.frame} can be used to practice AMR analysis. For examples, please read \href{https://msberends.gitlab.io/AMR/articles/AMR.html}{the tutorial on our website}.
}
\section{Read more on our website!}{

View File

@ -63,29 +63,29 @@ The \code{group} column in \code{\link{antibiotics}} data set will be searched f
library(dplyr)
# filter on isolates that have any result for any aminoglycoside
septic_patients \%>\% filter_aminoglycosides()
example_isolates \%>\% filter_aminoglycosides()
# this is essentially the same as (but without determination of column names):
septic_patients \%>\%
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
septic_patients \%>\% filter_aminoglycosides("R")
example_isolates \%>\% filter_aminoglycosides("R")
# filter on isolates that show resistance to ALL aminoglycosides
septic_patients \%>\% filter_aminoglycosides("R", "all")
example_isolates \%>\% filter_aminoglycosides("R", "all")
# filter on isolates that show resistance to
# any aminoglycoside and any fluoroquinolone
septic_patients \%>\%
example_isolates \%>\%
filter_aminoglycosides("R") \%>\%
filter_fluoroquinolones("R")
# filter on isolates that show resistance to
# all aminoglycosides and all fluoroquinolones
septic_patients \%>\%
example_isolates \%>\%
filter_aminoglycosides("R", "all") \%>\%
filter_fluoroquinolones("R", "all")
}

View File

@ -106,12 +106,12 @@ On our website \url{https://msberends.gitlab.io/AMR} you can find \href{https://
}
\examples{
# `septic_patients` is a dataset available in the AMR package. It is true, genuine data.
# See ?septic_patients.
# `example_isolates` is a dataset available in the AMR package.
# See ?example_isolates.
library(dplyr)
# Filter on first isolates:
septic_patients \%>\%
example_isolates \%>\%
mutate(first_isolate = first_isolate(.,
col_date = "date",
col_patient_id = "patient_id",
@ -119,19 +119,19 @@ septic_patients \%>\%
filter(first_isolate == TRUE)
# Which can be shortened to:
septic_patients \%>\%
example_isolates \%>\%
filter_first_isolate()
# or for first weighted isolates:
septic_patients \%>\%
example_isolates \%>\%
filter_first_weighted_isolate()
# Now let's see if first isolates matter:
A <- septic_patients \%>\%
A <- example_isolates \%>\%
group_by(hospital_id) \%>\%
summarise(count = n_rsi(GEN), # gentamicin availability
resistance = portion_IR(GEN)) # gentamicin resistance
B <- septic_patients \%>\%
B <- example_isolates \%>\%
filter_first_weighted_isolate() \%>\% # the 1st isolate filter
group_by(hospital_id) \%>\%
summarise(count = n_rsi(GEN), # gentamicin availability

View File

@ -114,11 +114,11 @@ library(dplyr)
library(ggplot2)
# get antimicrobial results for drugs against a UTI:
ggplot(septic_patients \%>\% select(AMX, NIT, FOS, TMP, CIP)) +
ggplot(example_isolates \%>\% select(AMX, NIT, FOS, TMP, CIP)) +
geom_rsi()
# prettify the plot using some additional functions:
df <- septic_patients \%>\% select(AMX, NIT, FOS, TMP, CIP)
df <- example_isolates \%>\% select(AMX, NIT, FOS, TMP, CIP)
ggplot(df) +
geom_rsi() +
scale_y_percent() +
@ -127,17 +127,17 @@ ggplot(df) +
theme_rsi()
# or better yet, simplify this using the wrapper function - a single command:
septic_patients \%>\%
example_isolates \%>\%
select(AMX, NIT, FOS, TMP, CIP) \%>\%
ggplot_rsi()
# get only portions and no counts:
septic_patients \%>\%
example_isolates \%>\%
select(AMX, NIT, FOS, TMP, CIP) \%>\%
ggplot_rsi(datalabels = FALSE)
# add other ggplot2 parameters as you like:
septic_patients \%>\%
example_isolates \%>\%
select(AMX, NIT, FOS, TMP, CIP) \%>\%
ggplot_rsi(width = 0.5,
colour = "black",
@ -145,12 +145,12 @@ septic_patients \%>\%
linetype = 2,
alpha = 0.25)
septic_patients \%>\%
example_isolates \%>\%
select(AMX) \%>\%
ggplot_rsi(colours = c(SI = "yellow"))
# resistance of ciprofloxacine per age group
septic_patients \%>\%
example_isolates \%>\%
mutate(first_isolate = first_isolate(.)) \%>\%
filter(first_isolate == TRUE,
mo == as.mo("E. coli")) \%>\%
@ -162,17 +162,17 @@ septic_patients \%>\%
\donttest{
# for colourblind mode, use divergent colours from the viridis package:
septic_patients \%>\%
example_isolates \%>\%
select(AMX, NIT, FOS, TMP, CIP) \%>\%
ggplot_rsi() + scale_fill_viridis_d()
# a shorter version which also adjusts data label colours:
septic_patients \%>\%
example_isolates \%>\%
select(AMX, NIT, FOS, TMP, CIP) \%>\%
ggplot_rsi(colours = FALSE)
# it also supports groups (don't forget to use the group var on `x` or `facet`):
septic_patients \%>\%
example_isolates \%>\%
select(hospital_id, AMX, NIT, FOS, TMP, CIP) \%>\%
group_by(hospital_id) \%>\%
ggplot_rsi(x = "hospital_id",
@ -183,7 +183,7 @@ septic_patients \%>\%
datalabels = FALSE)
# genuine analysis: check 3 most prevalent microorganisms
septic_patients \%>\%
example_isolates \%>\%
# create new bacterial ID's, with all CoNS under the same group (Becker et al.)
mutate(mo = as.mo(mo, Becker = TRUE)) \%>\%
# filter on top three bacterial ID's

View File

@ -48,7 +48,7 @@ left_join_microorganisms(as.mo("K. pneumoniae"))
left_join_microorganisms("B_KLBSL_PNE")
library(dplyr)
septic_patients \%>\% left_join_microorganisms()
example_isolates \%>\% left_join_microorganisms()
df <- data.frame(date = seq(from = as.Date("2018-01-01"),
to = as.Date("2018-01-07"),

View File

@ -82,12 +82,12 @@ On our website \url{https://msberends.gitlab.io/AMR} you can find \href{https://
}
\examples{
# `septic_patients` is a dataset available in the AMR package. It is true, genuine data.
# See ?septic_patients.
# `example_isolates` is a dataset available in the AMR package.
# See ?example_isolates.
library(dplyr)
# set key antibiotics to a new variable
my_patients <- septic_patients \%>\%
my_patients <- example_isolates \%>\%
mutate(keyab = key_antibiotics(.)) \%>\%
mutate(
# now calculate first isolates

View File

@ -57,7 +57,7 @@ a \%like\% b
# get frequencies of bacteria whose name start with 'Ent' or 'ent'
library(dplyr)
library(clean)
septic_patients \%>\%
example_isolates \%>\%
left_join_microorganisms() \%>\%
filter(genus \%like\% '^ent') \%>\%
freq(genus, species)

View File

@ -146,7 +146,7 @@ On our website \url{https://msberends.gitlab.io/AMR} you can find \href{https://
\examples{
library(dplyr)
septic_patients \%>\%
example_isolates \%>\%
mutate(EUCAST = mdro(.),
BRMO = brmo(.))
}

View File

@ -133,30 +133,30 @@ On our website \url{https://msberends.gitlab.io/AMR} you can find \href{https://
}
\examples{
# septic_patients is a data set available in the AMR package. It is true, genuine data.
?septic_patients
# example_isolates is a data set available in the AMR package.
?example_isolates
# Calculate resistance
portion_R(septic_patients$AMX)
portion_IR(septic_patients$AMX)
portion_R(example_isolates$AMX)
portion_IR(example_isolates$AMX)
# Or susceptibility
portion_S(septic_patients$AMX)
portion_SI(septic_patients$AMX)
portion_S(example_isolates$AMX)
portion_SI(example_isolates$AMX)
# Do the above with pipes:
library(dplyr)
septic_patients \%>\% portion_R(AMX)
septic_patients \%>\% portion_IR(AMX)
septic_patients \%>\% portion_S(AMX)
septic_patients \%>\% portion_SI(AMX)
example_isolates \%>\% portion_R(AMX)
example_isolates \%>\% portion_IR(AMX)
example_isolates \%>\% portion_S(AMX)
example_isolates \%>\% portion_SI(AMX)
septic_patients \%>\%
example_isolates \%>\%
group_by(hospital_id) \%>\%
summarise(p = portion_SI(CIP),
n = n_rsi(CIP)) # n_rsi works like n_distinct in dplyr
septic_patients \%>\%
example_isolates \%>\%
group_by(hospital_id) \%>\%
summarise(R = portion_R(CIP, as_percent = TRUE),
I = portion_I(CIP, as_percent = TRUE),
@ -167,24 +167,24 @@ septic_patients \%>\%
# Calculate co-resistance between amoxicillin/clav acid and gentamicin,
# so we can see that combination therapy does a lot more than mono therapy:
septic_patients \%>\% portion_SI(AMC) # \%SI = 76.3\%
septic_patients \%>\% count_all(AMC) # n = 1879
example_isolates \%>\% portion_SI(AMC) # \%SI = 76.3\%
example_isolates \%>\% count_all(AMC) # n = 1879
septic_patients \%>\% portion_SI(GEN) # \%SI = 75.4\%
septic_patients \%>\% count_all(GEN) # n = 1855
example_isolates \%>\% portion_SI(GEN) # \%SI = 75.4\%
example_isolates \%>\% count_all(GEN) # n = 1855
septic_patients \%>\% portion_SI(AMC, GEN) # \%SI = 94.1\%
septic_patients \%>\% count_all(AMC, GEN) # n = 1939
example_isolates \%>\% portion_SI(AMC, GEN) # \%SI = 94.1\%
example_isolates \%>\% count_all(AMC, GEN) # n = 1939
# See Details on how `only_all_tested` works. Example:
septic_patients \%>\%
example_isolates \%>\%
summarise(numerator = count_SI(AMC, GEN),
denominator = count_all(AMC, GEN),
portion = portion_SI(AMC, GEN))
# numerator denominator portion
# 1764 1936 0.9408
septic_patients \%>\%
example_isolates \%>\%
summarise(numerator = count_SI(AMC, GEN, only_all_tested = TRUE),
denominator = count_all(AMC, GEN, only_all_tested = TRUE),
portion = portion_SI(AMC, GEN, only_all_tested = TRUE))
@ -192,7 +192,7 @@ septic_patients \%>\%
# 1687 1798 0.9383
septic_patients \%>\%
example_isolates \%>\%
group_by(hospital_id) \%>\%
summarise(cipro_p = portion_SI(CIP, as_percent = TRUE),
cipro_n = count_all(CIP),
@ -202,12 +202,12 @@ septic_patients \%>\%
combination_n = count_all(CIP, GEN))
# Get portions S/I/R immediately of all rsi columns
septic_patients \%>\%
example_isolates \%>\%
select(AMX, CIP) \%>\%
portion_df(translate = FALSE)
# It also supports grouping variables
septic_patients \%>\%
example_isolates \%>\%
select(hospital_id, AMX, CIP) \%>\%
group_by(hospital_id) \%>\%
portion_df(translate = FALSE)

View File

@ -80,13 +80,13 @@ On our website \url{https://msberends.gitlab.io/AMR} you can find \href{https://
}
\examples{
x <- resistance_predict(septic_patients, col_ab = "AMX", year_min = 2010, model = "binomial")
x <- resistance_predict(example_isolates, col_ab = "AMX", year_min = 2010, model = "binomial")
plot(x)
ggplot_rsi_predict(x)
# use dplyr so you can actually read it:
library(dplyr)
x <- septic_patients \%>\%
x <- example_isolates \%>\%
filter_first_isolate() \%>\%
filter(mo_genus(mo) == "Staphylococcus") \%>\%
resistance_predict("PEN", model = "binomial")
@ -101,7 +101,7 @@ summary(mymodel)
# create nice plots with ggplot2 yourself
if (!require(ggplot2)) {
data <- septic_patients \%>\%
data <- example_isolates \%>\%
filter(mo == as.mo("E. coli")) \%>\%
resistance_predict(col_ab = "AMX",
col_date = "date",