2018-02-21 11:52:31 +01:00
% Generated by roxygen2: do not edit by hand
2018-08-10 15:01:05 +02:00
% Please edit documentation in R/resistance_predict.R
2018-07-13 17:23:46 +02:00
\name{resistance_predict}
\alias{resistance_predict}
2018-02-21 11:52:31 +01:00
\alias{rsi_predict}
2019-01-15 12:45:24 +01:00
\alias{plot.resistance_predict}
\alias{ggplot_rsi_predict}
2018-02-21 11:52:31 +01:00
\title{Predict antimicrobial resistance}
\usage{
2019-01-15 12:45:24 +01:00
resistance_predict(tbl, col_ab, col_date = NULL, year_min = NULL,
2018-08-11 21:30:00 +02:00
year_max = NULL, year_every = 1, minimum = 30,
model = "binomial", I_as_R = TRUE, preserve_measurements = TRUE,
info = TRUE)
2018-07-13 17:23:46 +02:00
2019-01-15 12:45:24 +01:00
rsi_predict(tbl, col_ab, col_date = NULL, year_min = NULL,
year_max = NULL, year_every = 1, minimum = 30,
model = "binomial", I_as_R = TRUE, preserve_measurements = TRUE,
info = TRUE)
\method{plot}{resistance_predict}(x,
main = paste("Resistance prediction of", attributes(x)$ab), ...)
ggplot_rsi_predict(x, main = paste("Resistance prediction of",
attributes(x)$ab), ...)
2018-02-21 11:52:31 +01:00
}
\arguments{
2018-07-26 16:30:42 +02:00
\item{tbl}{a \code{data.frame} containing isolates.}
2018-02-21 11:52:31 +01:00
2018-07-26 16:30:42 +02:00
\item{col_ab}{column name of \code{tbl} with antimicrobial interpretations (\code{R}, \code{I} and \code{S})}
2018-02-21 11:52:31 +01:00
2019-01-15 12:45:24 +01:00
\item{col_date}{column name of the date, will be used to calculate years if this column doesn't consist of years already, defaults to the first column of with a date class}
2018-02-21 11:52:31 +01:00
2019-01-12 19:31:30 +01:00
\item{year_min}{lowest year to use in the prediction model, dafaults to the lowest year in \code{col_date}}
2018-07-26 16:30:42 +02:00
2019-01-12 19:31:30 +01:00
\item{year_max}{highest year to use in the prediction model, defaults to 10 years after today}
2018-02-21 11:52:31 +01:00
\item{year_every}{unit of sequence between lowest year found in the data and \code{year_max}}
2018-07-26 16:30:42 +02:00
\item{minimum}{minimal amount of available isolates per year to include. Years containing less observations will be estimated by the model.}
2019-01-15 12:45:24 +01:00
\item{model}{the statistical model of choice. Valid values are \code{"binomial"} (or \code{"binom"} or \code{"logit"}) or \code{"loglin"} (or \code{"poisson"}) or \code{"linear"} (or \code{"lin"}).}
2018-02-21 11:52:31 +01:00
2019-01-12 19:31:30 +01:00
\item{I_as_R}{a logical to indicate whether values \code{I} should be treated as \code{R}}
2018-02-21 11:52:31 +01:00
2019-01-12 19:31:30 +01:00
\item{preserve_measurements}{a logical to indicate whether predictions of years that are actually available in the data should be overwritten by the original data. The standard errors of those years will be \code{NA}.}
2018-02-21 11:52:31 +01:00
2019-01-12 19:31:30 +01:00
\item{info}{a logical to indicate whether textual analysis should be printed with the name and \code{\link{summary}} of the statistical model.}
2019-01-15 12:45:24 +01:00
\item{x}{the coordinates of points in the plot. Alternatively, a
single plotting structure, function or \emph{any \R object with a
\code{plot} method} can be provided.}
2019-01-15 16:38:54 +01:00
\item{main}{title of the plot}
2019-01-15 12:45:24 +01:00
\item{...}{parameters passed on to the \code{first_isolate} function}
2018-02-21 11:52:31 +01:00
}
\value{
2019-01-15 12:45:24 +01:00
\code{data.frame} with extra class \code{"resistance_predict"} with columns:
2018-07-26 16:30:42 +02:00
\itemize{
\item{\code{year}}
2018-07-28 09:34:03 +02:00
\item{\code{value}, the same as \code{estimated} when \code{preserve_measurements = FALSE}, and a combination of \code{observed} and \code{estimated} otherwise}
2019-01-12 19:31:30 +01:00
\item{\code{se_min}, the lower bound of the standard error with a minimum of \code{0} (so the standard error will never go below 0\%)}
\item{\code{se_max} the upper bound of the standard error with a maximum of \code{1} (so the standard error will never go above 100\%)}
\item{\code{observations}, the total number of available observations in that year, i.e. S + I + R}
\item{\code{observed}, the original observed resistant percentages}
\item{\code{estimated}, the estimated resistant percentages, calculated by the model}
2018-07-26 16:30:42 +02:00
}
2018-02-21 11:52:31 +01:00
}
\description{
2018-02-27 20:01:02 +01:00
Create a prediction model to predict antimicrobial resistance for the next years on statistical solid ground. Standard errors (SE) will be returned as columns \code{se_min} and \code{se_max}. See Examples for a real live example.
2018-02-21 11:52:31 +01:00
}
2019-01-02 23:24:07 +01:00
\section{Read more on our website!}{
\if{html}{\figure{logo.png}{options: height=40px style=margin-bottom:5px} \cr}
On our website \url{https://msberends.gitlab.io/AMR} you can find \href{https://msberends.gitlab.io/AMR/articles/AMR.html}{a omprehensive tutorial} about how to conduct AMR analysis and find \href{https://msberends.gitlab.io/AMR/reference}{the complete documentation of all functions}, which reads a lot easier than in R.
}
2018-02-21 11:52:31 +01:00
\examples{
2019-01-15 12:45:24 +01:00
x <- resistance_predict(septic_patients, col_ab = "amox", year_min = 2010)
plot(x)
ggplot_rsi_predict(x)
2018-04-02 16:05:09 +02:00
2019-01-15 12:45:24 +01:00
# use dplyr so you can actually read it:
2018-02-22 20:48:48 +01:00
library(dplyr)
2019-01-15 12:45:24 +01:00
x <- septic_patients \%>\%
filter_first_isolate() \%>\%
filter(mo_genus(mo) == "Staphylococcus") \%>\%
resistance_predict("peni")
plot(x)
2018-02-21 11:52:31 +01:00
2019-01-15 12:45:24 +01:00
# create nice plots with ggplot yourself
2018-07-26 16:30:42 +02:00
if (!require(ggplot2)) {
data <- septic_patients \%>\%
2018-12-22 22:39:34 +01:00
filter(mo == as.mo("E. coli")) \%>\%
2018-07-26 16:30:42 +02:00
resistance_predict(col_ab = "amox",
2018-12-22 22:39:34 +01:00
col_date = "date",
info = FALSE,
2019-01-15 12:45:24 +01:00
minimum = 15)
2018-07-26 16:30:42 +02:00
ggplot(data,
aes(x = year)) +
2018-07-28 09:34:03 +02:00
geom_col(aes(y = value),
2018-07-26 16:30:42 +02:00
fill = "grey75") +
geom_errorbar(aes(ymin = se_min,
ymax = se_max),
colour = "grey50") +
scale_y_continuous(limits = c(0, 1),
breaks = seq(0, 1, 0.1),
labels = paste0(seq(0, 100, 10), "\%")) +
labs(title = expression(paste("Forecast of amoxicillin resistance in ",
italic("E. coli"))),
y = "\%IR",
x = "Year") +
theme_minimal(base_size = 13)
}
2018-02-21 11:52:31 +01:00
}
\seealso{
2018-08-10 15:01:05 +02:00
The \code{\link{portion}} function to calculate resistance, \cr \code{\link{lm}} \code{\link{glm}}
2018-02-21 11:52:31 +01:00
}