mirror of
https://github.com/msberends/AMR.git
synced 2025-07-08 16:42:10 +02:00
sort sir history
This commit is contained in:
@ -58,8 +58,9 @@ mo_name("Enterobacter asburiae/cloacae")
|
||||
# now add a custom entry - it will be considered by as.mo() and
|
||||
# all mo_*() functions
|
||||
add_custom_microorganisms(
|
||||
data.frame(genus = "Enterobacter",
|
||||
species = "asburiae/cloacae"
|
||||
data.frame(
|
||||
genus = "Enterobacter",
|
||||
species = "asburiae/cloacae"
|
||||
)
|
||||
)
|
||||
|
||||
@ -81,8 +82,10 @@ mo_info("Enterobacter asburiae/cloacae")
|
||||
|
||||
# the function tries to be forgiving:
|
||||
add_custom_microorganisms(
|
||||
data.frame(GENUS = "BACTEROIDES / PARABACTEROIDES SLASHLINE",
|
||||
SPECIES = "SPECIES")
|
||||
data.frame(
|
||||
GENUS = "BACTEROIDES / PARABACTEROIDES SLASHLINE",
|
||||
SPECIES = "SPECIES"
|
||||
)
|
||||
)
|
||||
mo_name("BACTEROIDES / PARABACTEROIDES")
|
||||
mo_rank("BACTEROIDES / PARABACTEROIDES")
|
||||
@ -93,9 +96,11 @@ mo_family("Bacteroides/Parabacteroides")
|
||||
|
||||
# for groups and complexes, set them as species or subspecies:
|
||||
add_custom_microorganisms(
|
||||
data.frame(genus = "Citrobacter",
|
||||
species = c("freundii", "braakii complex"),
|
||||
subspecies = c("complex", ""))
|
||||
data.frame(
|
||||
genus = "Citrobacter",
|
||||
species = c("freundii", "braakii complex"),
|
||||
subspecies = c("complex", "")
|
||||
)
|
||||
)
|
||||
mo_name(c("C. freundii complex", "C. braakii complex"))
|
||||
mo_species(c("C. freundii complex", "C. braakii complex"))
|
||||
|
@ -214,20 +214,17 @@ example_isolates[, ab_selector(oral_ddd > 1 & oral_units == "g")]
|
||||
# dplyr -------------------------------------------------------------------
|
||||
\donttest{
|
||||
if (require("dplyr")) {
|
||||
|
||||
# get AMR for all aminoglycosides e.g., per ward:
|
||||
example_isolates \%>\%
|
||||
group_by(ward) \%>\%
|
||||
summarise(across(aminoglycosides(), resistance))
|
||||
}
|
||||
if (require("dplyr")) {
|
||||
|
||||
# You can combine selectors with '&' to be more specific:
|
||||
example_isolates \%>\%
|
||||
select(penicillins() & administrable_per_os())
|
||||
}
|
||||
if (require("dplyr")) {
|
||||
|
||||
# get AMR for only drugs that matter - no intrinsic resistance:
|
||||
example_isolates \%>\%
|
||||
filter(mo_genus() \%in\% c("Escherichia", "Klebsiella")) \%>\%
|
||||
@ -235,7 +232,6 @@ if (require("dplyr")) {
|
||||
summarise(across(not_intrinsic_resistant(), resistance))
|
||||
}
|
||||
if (require("dplyr")) {
|
||||
|
||||
# get susceptibility for antibiotics whose name contains "trim":
|
||||
example_isolates \%>\%
|
||||
filter(first_isolate()) \%>\%
|
||||
@ -243,19 +239,16 @@ if (require("dplyr")) {
|
||||
summarise(across(ab_selector(name \%like\% "trim"), susceptibility))
|
||||
}
|
||||
if (require("dplyr")) {
|
||||
|
||||
# this will select columns 'IPM' (imipenem) and 'MEM' (meropenem):
|
||||
example_isolates \%>\%
|
||||
select(carbapenems())
|
||||
}
|
||||
if (require("dplyr")) {
|
||||
|
||||
# this will select columns 'mo', 'AMK', 'GEN', 'KAN' and 'TOB':
|
||||
example_isolates \%>\%
|
||||
select(mo, aminoglycosides())
|
||||
}
|
||||
if (require("dplyr")) {
|
||||
|
||||
# any() and all() work in dplyr's filter() too:
|
||||
example_isolates \%>\%
|
||||
filter(
|
||||
@ -264,25 +257,21 @@ if (require("dplyr")) {
|
||||
)
|
||||
}
|
||||
if (require("dplyr")) {
|
||||
|
||||
# also works with c():
|
||||
example_isolates \%>\%
|
||||
filter(any(c(carbapenems(), aminoglycosides()) == "R"))
|
||||
}
|
||||
if (require("dplyr")) {
|
||||
|
||||
# not setting any/all will automatically apply all():
|
||||
example_isolates \%>\%
|
||||
filter(aminoglycosides() == "R")
|
||||
}
|
||||
if (require("dplyr")) {
|
||||
|
||||
# this will select columns 'mo' and all antimycobacterial drugs ('RIF'):
|
||||
example_isolates \%>\%
|
||||
select(mo, ab_class("mycobact"))
|
||||
}
|
||||
if (require("dplyr")) {
|
||||
|
||||
# get bug/drug combinations for only glycopeptides in Gram-positives:
|
||||
example_isolates \%>\%
|
||||
filter(mo_is_gram_positive()) \%>\%
|
||||
@ -298,7 +287,6 @@ if (require("dplyr")) {
|
||||
select(penicillins()) # only the 'J01CA01' column will be selected
|
||||
}
|
||||
if (require("dplyr")) {
|
||||
|
||||
# with recent versions of dplyr this is all equal:
|
||||
x <- example_isolates[carbapenems() == "R", ]
|
||||
y <- example_isolates \%>\% filter(carbapenems() == "R")
|
||||
|
@ -91,7 +91,6 @@ ab_name("eryt")
|
||||
|
||||
\donttest{
|
||||
if (require("dplyr")) {
|
||||
|
||||
# you can quickly rename 'sir' columns using set_ab_names() with dplyr:
|
||||
example_isolates \%>\%
|
||||
set_ab_names(where(is.sir), property = "atc")
|
||||
|
@ -125,7 +125,7 @@ your_data \%>\% mutate(across(where(is.disk), as.sir))
|
||||
\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)}.
|
||||
}
|
||||
|
||||
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.
|
||||
\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.
|
||||
}
|
||||
|
||||
\subsection{Supported Guidelines}{
|
||||
|
@ -179,13 +179,11 @@ if (require("dplyr")) {
|
||||
filter(first_isolate())
|
||||
}
|
||||
if (require("dplyr")) {
|
||||
|
||||
# short-hand version:
|
||||
example_isolates \%>\%
|
||||
filter_first_isolate(info = FALSE)
|
||||
}
|
||||
if (require("dplyr")) {
|
||||
|
||||
# flag the first isolates per group:
|
||||
example_isolates \%>\%
|
||||
group_by(ward) \%>\%
|
||||
|
@ -44,11 +44,12 @@ is_new_episode(df$date, episode_days = 60) # TRUE/FALSE
|
||||
df[which(get_episode(df$date, 60) == 3), ]
|
||||
|
||||
# the functions also work for less than a day, e.g. to include one per hour:
|
||||
get_episode(c(
|
||||
Sys.time(),
|
||||
Sys.time() + 60 * 60
|
||||
),
|
||||
episode_days = 1 / 24
|
||||
get_episode(
|
||||
c(
|
||||
Sys.time(),
|
||||
Sys.time() + 60 * 60
|
||||
),
|
||||
episode_days = 1 / 24
|
||||
)
|
||||
|
||||
\donttest{
|
||||
@ -85,7 +86,6 @@ if (require("dplyr")) {
|
||||
)
|
||||
}
|
||||
if (require("dplyr")) {
|
||||
|
||||
# grouping on patients and microorganisms leads to the same
|
||||
# results as first_isolate() when using 'episode-based':
|
||||
x <- df \%>\%
|
||||
@ -102,7 +102,6 @@ if (require("dplyr")) {
|
||||
identical(x, y)
|
||||
}
|
||||
if (require("dplyr")) {
|
||||
|
||||
# but is_new_episode() has a lot more flexibility than first_isolate(),
|
||||
# since you can now group on anything that seems relevant:
|
||||
df \%>\%
|
||||
|
@ -138,13 +138,11 @@ At default, the names of antibiotics will be shown on the plots using \code{\lin
|
||||
\examples{
|
||||
\donttest{
|
||||
if (require("ggplot2") && require("dplyr")) {
|
||||
|
||||
# get antimicrobial results for drugs against a UTI:
|
||||
ggplot(example_isolates \%>\% select(AMX, NIT, FOS, TMP, CIP)) +
|
||||
geom_sir()
|
||||
}
|
||||
if (require("ggplot2") && require("dplyr")) {
|
||||
|
||||
# prettify the plot using some additional functions:
|
||||
df <- example_isolates \%>\% select(AMX, NIT, FOS, TMP, CIP)
|
||||
ggplot(df) +
|
||||
@ -155,21 +153,18 @@ if (require("ggplot2") && require("dplyr")) {
|
||||
theme_sir()
|
||||
}
|
||||
if (require("ggplot2") && require("dplyr")) {
|
||||
|
||||
# or better yet, simplify this using the wrapper function - a single command:
|
||||
example_isolates \%>\%
|
||||
select(AMX, NIT, FOS, TMP, CIP) \%>\%
|
||||
ggplot_sir()
|
||||
}
|
||||
if (require("ggplot2") && require("dplyr")) {
|
||||
|
||||
# get only proportions and no counts:
|
||||
example_isolates \%>\%
|
||||
select(AMX, NIT, FOS, TMP, CIP) \%>\%
|
||||
ggplot_sir(datalabels = FALSE)
|
||||
}
|
||||
if (require("ggplot2") && require("dplyr")) {
|
||||
|
||||
# add other ggplot2 arguments as you like:
|
||||
example_isolates \%>\%
|
||||
select(AMX, NIT, FOS, TMP, CIP) \%>\%
|
||||
@ -182,14 +177,12 @@ if (require("ggplot2") && require("dplyr")) {
|
||||
)
|
||||
}
|
||||
if (require("ggplot2") && require("dplyr")) {
|
||||
|
||||
# you can alter the colours with colour names:
|
||||
example_isolates \%>\%
|
||||
select(AMX) \%>\%
|
||||
ggplot_sir(colours = c(SI = "yellow"))
|
||||
}
|
||||
if (require("ggplot2") && require("dplyr")) {
|
||||
|
||||
# but you can also use the built-in colour-blind friendly colours for
|
||||
# your plots, where "S" is green, "I" is yellow and "R" is red:
|
||||
data.frame(
|
||||
@ -202,7 +195,6 @@ if (require("ggplot2") && require("dplyr")) {
|
||||
scale_sir_colours(Value4 = "S", Value5 = "I", Value6 = "R")
|
||||
}
|
||||
if (require("ggplot2") && require("dplyr")) {
|
||||
|
||||
# resistance of ciprofloxacine per age group
|
||||
example_isolates \%>\%
|
||||
mutate(first_isolate = first_isolate()) \%>\%
|
||||
@ -216,14 +208,12 @@ if (require("ggplot2") && require("dplyr")) {
|
||||
ggplot_sir(x = "age_group")
|
||||
}
|
||||
if (require("ggplot2") && require("dplyr")) {
|
||||
|
||||
# a shorter version which also adjusts data label colours:
|
||||
example_isolates \%>\%
|
||||
select(AMX, NIT, FOS, TMP, CIP) \%>\%
|
||||
ggplot_sir(colours = FALSE)
|
||||
}
|
||||
if (require("ggplot2") && require("dplyr")) {
|
||||
|
||||
# it also supports groups (don't forget to use the group var on `x` or `facet`):
|
||||
example_isolates \%>\%
|
||||
filter(mo_is_gram_negative(), ward != "Outpatient") \%>\%
|
||||
|
@ -405,7 +405,6 @@ mo_species("EHEC")
|
||||
mo_fullname("K. pneu rh")
|
||||
mo_shortname("K. pneu rh")
|
||||
|
||||
|
||||
\donttest{
|
||||
# Becker classification, see ?as.mo ----------------------------------------
|
||||
|
||||
|
@ -204,7 +204,6 @@ if (require("dplyr")) {
|
||||
)
|
||||
}
|
||||
if (require("dplyr")) {
|
||||
|
||||
# scoped dplyr verbs with antibiotic selectors
|
||||
# (you could also use across() of course)
|
||||
example_isolates \%>\%
|
||||
|
Reference in New Issue
Block a user