mirror of
https://github.com/msberends/AMR.git
synced 2025-07-09 04:02:19 +02:00
count_all and some fixes
This commit is contained in:
42
man/count.Rd
42
man/count.Rd
@ -7,6 +7,8 @@
|
||||
\alias{count_I}
|
||||
\alias{count_SI}
|
||||
\alias{count_S}
|
||||
\alias{count_all}
|
||||
\alias{n_rsi}
|
||||
\alias{count_df}
|
||||
\title{Count isolates}
|
||||
\source{
|
||||
@ -23,11 +25,15 @@ count_SI(...)
|
||||
|
||||
count_S(...)
|
||||
|
||||
count_all(...)
|
||||
|
||||
n_rsi(...)
|
||||
|
||||
count_df(data, translate_ab = getOption("get_antibiotic_names",
|
||||
"official"))
|
||||
}
|
||||
\arguments{
|
||||
\item{...}{one or more vectors (or columns) with antibiotic interpretations. They will be transformed internally with \code{\link{as.rsi}} if needed. Use multiple columns to calculate (the lack of) co-resistance: the probability where one of two drugs have a resistant or susceptible result. See Examples.}
|
||||
\item{...}{one or more vectors (or columns) with antibiotic interpretations. They will be transformed internally with \code{\link{as.rsi}} if needed.}
|
||||
|
||||
\item{data}{a \code{data.frame} containing columns with class \code{rsi} (see \code{\link{as.rsi}})}
|
||||
|
||||
@ -42,10 +48,10 @@ These functions can be used to count resistant/susceptible microbial isolates. A
|
||||
\code{count_R} and \code{count_IR} can be used to count resistant isolates, \code{count_S} and \code{count_SI} can be used to count susceptible isolates.\cr
|
||||
}
|
||||
\details{
|
||||
\strong{Remember that you should filter your table to let it contain only first isolates!} Use \code{\link{first_isolate}} to determine them in your data set.
|
||||
|
||||
These functions are meant to count isolates. Use the \code{\link{portion}_*} functions to calculate microbial resistance.
|
||||
|
||||
\code{n_rsi} is an alias of \code{count_all}. They can be used to count all available isolates, i.e. where all input antibiotics have an available result (S, I or R). Their use is equal to \code{\link{n_distinct}}. Their function is equal to \code{count_S(...) + count_IR(...)}.
|
||||
|
||||
\code{count_df} takes any variable from \code{data} that has an \code{"rsi"} class (created with \code{\link{as.rsi}}) and counts the amounts of R, I and S. The resulting \emph{tidy data} (see Source) \code{data.frame} will have three rows (S/I/R) and a column for each variable with class \code{"rsi"}.
|
||||
}
|
||||
\examples{
|
||||
@ -60,6 +66,10 @@ count_IR(septic_patients$amox)
|
||||
count_S(septic_patients$amox)
|
||||
count_SI(septic_patients$amox)
|
||||
|
||||
# Count all available isolates
|
||||
count_all(septic_patients$amox)
|
||||
n_rsi(septic_patients$amox)
|
||||
|
||||
# Since n_rsi counts available isolates, you can
|
||||
# calculate back to count e.g. non-susceptible isolates.
|
||||
# This results in the same:
|
||||
@ -69,24 +79,25 @@ portion_IR(septic_patients$amox) * n_rsi(septic_patients$amox)
|
||||
library(dplyr)
|
||||
septic_patients \%>\%
|
||||
group_by(hospital_id) \%>\%
|
||||
summarise(R = count_R(cipr),
|
||||
I = count_I(cipr),
|
||||
S = count_S(cipr),
|
||||
n = n_rsi(cipr), # the actual total; sum of all three
|
||||
total = n()) # NOT the amount of tested isolates!
|
||||
summarise(R = count_R(cipr),
|
||||
I = count_I(cipr),
|
||||
S = count_S(cipr),
|
||||
n1 = count_all(cipr), # the actual total; sum of all three
|
||||
n2 = n_rsi(cipr), # same - analogous to n_distinct
|
||||
total = n()) # NOT the amount of tested isolates!
|
||||
|
||||
# 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_S` calculates percentages right away instead.
|
||||
count_S(septic_patients$amcl) # S = 1056 (67.3\%)
|
||||
n_rsi(septic_patients$amcl) # n = 1570
|
||||
count_S(septic_patients$amcl) # S = 1057 (67.1\%)
|
||||
count_all(septic_patients$amcl) # n = 1576
|
||||
|
||||
count_S(septic_patients$gent) # S = 1363 (74.0\%)
|
||||
n_rsi(septic_patients$gent) # n = 1842
|
||||
count_S(septic_patients$gent) # S = 1372 (74.0\%)
|
||||
count_all(septic_patients$gent) # n = 1855
|
||||
|
||||
with(septic_patients,
|
||||
count_S(amcl, gent)) # S = 1385 (92.1\%)
|
||||
with(septic_patients, # n = 1504
|
||||
count_S(amcl, gent)) # S = 1396 (92.0\%)
|
||||
with(septic_patients, # n = 1517
|
||||
n_rsi(amcl, gent))
|
||||
|
||||
# Get portions S/I/R immediately of all rsi columns
|
||||
@ -102,8 +113,7 @@ septic_patients \%>\%
|
||||
|
||||
}
|
||||
\seealso{
|
||||
\code{\link{portion}_*} to calculate microbial resistance and susceptibility.\cr
|
||||
\code{\link{n_rsi}} to count all cases where antimicrobial results are available.
|
||||
\code{\link{portion}_*} to calculate microbial resistance and susceptibility.
|
||||
}
|
||||
\keyword{antibiotics}
|
||||
\keyword{isolate}
|
||||
|
@ -68,7 +68,7 @@ At default, the names of antibiotics will be shown on the plots using \code{\lin
|
||||
|
||||
\code{scale_y_percent} transforms the y axis to a 0 to 100\% range using \code{\link[ggplot2]{scale_continuous}}.
|
||||
|
||||
\code{scale_rsi_colours} sets colours to the bars: green for S, yellow for I and red for R, using \code{\link[ggplot2]{scale_colour_brewer}}.
|
||||
\code{scale_rsi_colours} sets colours to the bars: green for S, yellow for I and red for R, using \code{\link[ggplot2]{scale_brewer}}.
|
||||
|
||||
\code{theme_rsi} is a \code{ggplot \link[ggplot2]{theme}} with minimal distraction.
|
||||
|
||||
|
29
man/join.Rd
29
man/join.Rd
@ -11,22 +11,22 @@
|
||||
\alias{anti_join_microorganisms}
|
||||
\title{Join a table with \code{microorganisms}}
|
||||
\usage{
|
||||
inner_join_microorganisms(x, by = "mo", suffix = c("2", ""), ...)
|
||||
inner_join_microorganisms(x, by = NULL, suffix = c("2", ""), ...)
|
||||
|
||||
left_join_microorganisms(x, by = "mo", suffix = c("2", ""), ...)
|
||||
left_join_microorganisms(x, by = NULL, suffix = c("2", ""), ...)
|
||||
|
||||
right_join_microorganisms(x, by = "mo", suffix = c("2", ""), ...)
|
||||
right_join_microorganisms(x, by = NULL, suffix = c("2", ""), ...)
|
||||
|
||||
full_join_microorganisms(x, by = "mo", suffix = c("2", ""), ...)
|
||||
full_join_microorganisms(x, by = NULL, suffix = c("2", ""), ...)
|
||||
|
||||
semi_join_microorganisms(x, by = "mo", ...)
|
||||
semi_join_microorganisms(x, by = NULL, ...)
|
||||
|
||||
anti_join_microorganisms(x, by = "mo", ...)
|
||||
anti_join_microorganisms(x, by = NULL, ...)
|
||||
}
|
||||
\arguments{
|
||||
\item{x}{existing table to join, also supports character vectors}
|
||||
\item{x}{existing table to join, or character vector}
|
||||
|
||||
\item{by}{a variable to join by - could be a column name of \code{x} with values that exist in \code{microorganisms$mo} (like \code{by = "bacteria_id"}), or another column in \code{\link{microorganisms}} (but then it should be named, like \code{by = c("my_genus_species" = "fullname")})}
|
||||
\item{by}{a variable to join by - if left empty will search for a column with class \code{mo} (created with \code{\link{as.mo}}) or will be \code{"mo"} if that column name exists in \code{x}, could otherwise be a column name of \code{x} with values that exist in \code{microorganisms$mo} (like \code{by = "bacteria_id"}), or another column in \code{\link{microorganisms}} (but then it should be named, like \code{by = c("my_genus_species" = "fullname")})}
|
||||
|
||||
\item{suffix}{if there are non-joined duplicate variables in \code{x} and \code{y}, these suffixes will be added to the output to disambiguate them. Should be a character vector of length 2.}
|
||||
|
||||
@ -36,10 +36,11 @@ anti_join_microorganisms(x, by = "mo", ...)
|
||||
Join the dataset \code{\link{microorganisms}} easily to an existing table or character vector.
|
||||
}
|
||||
\details{
|
||||
As opposed to the \code{\link[dplyr]{join}} functions of \code{dplyr}, characters vectors are supported and at default existing columns will get a suffix \code{"2"} and the newly joined columns will not get a suffix. See \code{\link[dplyr]{join}} for more information.
|
||||
\strong{Note:} As opposed to the \code{\link[dplyr]{join}} functions of \code{dplyr}, characters vectors are supported and at default existing columns will get a suffix \code{"2"} and the newly joined columns will not get a suffix. See \code{\link[dplyr]{join}} for more information.
|
||||
}
|
||||
\examples{
|
||||
left_join_microorganisms("STAAUR")
|
||||
left_join_microorganisms(as.mo("K. pneumoniae"))
|
||||
left_join_microorganisms("B_KLBSL_PNE")
|
||||
|
||||
library(dplyr)
|
||||
septic_patients \%>\% left_join_microorganisms()
|
||||
@ -47,10 +48,10 @@ septic_patients \%>\% left_join_microorganisms()
|
||||
df <- data.frame(date = seq(from = as.Date("2018-01-01"),
|
||||
to = as.Date("2018-01-07"),
|
||||
by = 1),
|
||||
bacteria_id = c("STAAUR", "STAAUR", "STAAUR", "STAAUR",
|
||||
"ESCCOL", "ESCCOL", "ESCCOL"),
|
||||
bacteria = as.mo(c("S. aureus", "MRSA", "MSSA", "STAAUR",
|
||||
"E. coli", "E. coli", "E. coli")),
|
||||
stringsAsFactors = FALSE)
|
||||
colnames(df)
|
||||
df2 <- left_join_microorganisms(df, "bacteria_id")
|
||||
colnames(df2)
|
||||
df_joined <- left_join_microorganisms(df, "bacteria")
|
||||
colnames(df_joined)
|
||||
}
|
||||
|
30
man/n_rsi.Rd
30
man/n_rsi.Rd
@ -1,30 +0,0 @@
|
||||
% Generated by roxygen2: do not edit by hand
|
||||
% Please edit documentation in R/n_rsi.R
|
||||
\name{n_rsi}
|
||||
\alias{n_rsi}
|
||||
\title{Count cases with antimicrobial results}
|
||||
\usage{
|
||||
n_rsi(...)
|
||||
}
|
||||
\arguments{
|
||||
\item{...}{one or more vectors (or columns) with antibiotic interpretations. They will be transformed internally with \code{\link{as.rsi}} if needed. Use multiple columns to calculate (the lack of) co-resistance: the probability where one of two drugs have a resistant or susceptible result. See Examples.}
|
||||
}
|
||||
\description{
|
||||
This counts all cases where antimicrobial interpretations are available. The way it can be used is equal to \code{\link{n_distinct}}. Its function is equal to \code{count_S(...) + count_IR(...)}.
|
||||
}
|
||||
\examples{
|
||||
library(dplyr)
|
||||
|
||||
septic_patients \%>\%
|
||||
group_by(hospital_id) \%>\%
|
||||
summarise(cipro_p = portion_S(cipr, as_percent = TRUE),
|
||||
cipro_n = n_rsi(cipr),
|
||||
genta_p = portion_S(gent, as_percent = TRUE),
|
||||
genta_n = n_rsi(gent),
|
||||
combination_p = portion_S(cipr, gent, as_percent = TRUE),
|
||||
combination_n = n_rsi(cipr, gent))
|
||||
}
|
||||
\seealso{
|
||||
\code{\link[AMR]{count}_*} to count resistant and susceptibile isolates per interpretation type.\cr
|
||||
\code{\link{portion}_*} to calculate microbial resistance and susceptibility.
|
||||
}
|
@ -31,7 +31,7 @@ portion_df(data, translate_ab = getOption("get_antibiotic_names",
|
||||
\arguments{
|
||||
\item{...}{one or more vectors (or columns) with antibiotic interpretations. They will be transformed internally with \code{\link{as.rsi}} if needed. Use multiple columns to calculate (the lack of) co-resistance: the probability where one of two drugs have a resistant or susceptible result. See Examples.}
|
||||
|
||||
\item{minimum}{minimal amount of available isolates. Any number lower than \code{minimum} will return \code{NA}. The default number of \code{30} isolates is advised by the CLSI as best practice, see Source.}
|
||||
\item{minimum}{minimal amount of available isolates. Any number 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{as_percent}{logical to indicate whether the output must be returned as a hundred fold with \% sign (a character). A value of \code{0.123456} will then be returned as \code{"12.3\%"}.}
|
||||
|
||||
@ -104,24 +104,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_S(amcl) # S = 67.3\%
|
||||
septic_patients \%>\% n_rsi(amcl) # n = 1570
|
||||
septic_patients \%>\% portion_S(amcl) # S = 67.1\%
|
||||
septic_patients \%>\% count_all(amcl) # n = 1576
|
||||
|
||||
septic_patients \%>\% portion_S(gent) # S = 74.0\%
|
||||
septic_patients \%>\% n_rsi(gent) # n = 1842
|
||||
septic_patients \%>\% count_all(gent) # n = 1855
|
||||
|
||||
septic_patients \%>\% portion_S(amcl, gent) # S = 92.1\%
|
||||
septic_patients \%>\% n_rsi(amcl, gent) # n = 1504
|
||||
septic_patients \%>\% portion_S(amcl, gent) # S = 92.0\%
|
||||
septic_patients \%>\% count_all(amcl, gent) # n = 1517
|
||||
|
||||
|
||||
septic_patients \%>\%
|
||||
group_by(hospital_id) \%>\%
|
||||
summarise(cipro_p = portion_S(cipr, as_percent = TRUE),
|
||||
cipro_n = n_rsi(cipr),
|
||||
cipro_n = count_all(cipr),
|
||||
genta_p = portion_S(gent, as_percent = TRUE),
|
||||
genta_n = n_rsi(gent),
|
||||
genta_n = count_all(gent),
|
||||
combination_p = portion_S(cipr, gent, as_percent = TRUE),
|
||||
combination_n = n_rsi(cipr, gent))
|
||||
combination_n = count_all(cipr, gent))
|
||||
|
||||
# Get portions S/I/R immediately of all rsi columns
|
||||
septic_patients \%>\%
|
||||
@ -142,12 +142,11 @@ my_table \%>\%
|
||||
filter(first_isolate == TRUE,
|
||||
genus == "Helicobacter") \%>\%
|
||||
summarise(p = portion_S(amox, metr), # amoxicillin with metronidazole
|
||||
n = n_rsi(amox, metr))
|
||||
n = count_all(amox, metr))
|
||||
}
|
||||
}
|
||||
\seealso{
|
||||
\code{\link[AMR]{count}_*} to count resistant and susceptibile isolates.\cr
|
||||
\code{\link{n_rsi}} to count all cases where antimicrobial results are available.
|
||||
\code{\link[AMR]{count}_*} to count resistant and susceptibile isolates.
|
||||
}
|
||||
\keyword{antibiotics}
|
||||
\keyword{isolate}
|
||||
|
@ -12,7 +12,7 @@ rsi(ab1, ab2 = NULL, interpretation = "IR", minimum = 30,
|
||||
|
||||
\item{interpretation}{antimicrobial interpretation to check for}
|
||||
|
||||
\item{minimum}{minimal amount of available isolates. Any number lower than \code{minimum} will return \code{NA}. The default number of \code{30} isolates is advised by the CLSI as best practice, see Source.}
|
||||
\item{minimum}{minimal amount of available isolates. Any number 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{as_percent}{logical to indicate whether the output must be returned as a hundred fold with \% sign (a character). A value of \code{0.123456} will then be returned as \code{"12.3\%"}.}
|
||||
|
||||
|
Reference in New Issue
Block a user