diff --git a/DESCRIPTION b/DESCRIPTION index b95d2456..af59cfc0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: AMR Version: 0.5.0.9017 -Date: 2019-02-08 +Date: 2019-02-09 Title: Antimicrobial Resistance Analysis Authors@R: c( person( diff --git a/NEWS.md b/NEWS.md index 16b6a055..096fbcc9 100755 --- a/NEWS.md +++ b/NEWS.md @@ -87,6 +87,7 @@ * New colours for `scale_rsi_colours()` * Summaries of class `mo` will now return the top 3 and the unique count, e.g. using `summary(mo)` * Small text updates to summaries of class `rsi` and `mic` +* Function `as.rsi()` now gives a warning when inputting MIC values * Frequency tables (`freq()` function): * Support for tidyverse quasiquotation! Now you can create frequency tables of function outcomes: ```r diff --git a/R/resistance_predict.R b/R/resistance_predict.R index caf0d217..2380b533 100755 --- a/R/resistance_predict.R +++ b/R/resistance_predict.R @@ -30,11 +30,17 @@ #' @param year_max highest year to use in the prediction model, defaults to 10 years after today #' @param year_every unit of sequence between lowest year found in the data and \code{year_max} #' @param minimum minimal amount of available isolates per year to include. Years containing less observations will be estimated by the model. -#' @param 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"}). +#' @param model the statistical model of choice. Defaults to a generalised linear regression model with binomial distribution, assuming that a period of zero resistance was followed by a period of increasing resistance leading slowly to more and more resistance. See Details for valid options. #' @param I_as_R a logical to indicate whether values \code{I} should be treated as \code{R} #' @param 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}. #' @param info a logical to indicate whether textual analysis should be printed with the name and \code{\link{summary}} of the statistical model. #' @param main title of the plot +#' @details Valid options for the statistical model are: +#' \itemize{ +#' \item{\code{"binomial"} or \code{"binom"} or \code{"logit"}: a generalised linear regression model with binomial distribution} +#' \item{\code{"loglin"} or \code{"poisson"}: a generalised log-linear regression model with poisson distribution} +#' \item{\code{"lin"} or \code{"linear"}: a linear regression model} +#' } #' @return \code{data.frame} with extra class \code{"resistance_predict"} with columns: #' \itemize{ #' \item{\code{year}} @@ -306,7 +312,9 @@ plot.resistance_predict <- function(x, main = paste("Resistance prediction of", ylab = paste0("Percentage (", ylab, ")"), xlab = "Year", main = main, - sub = paste0("(model: ", attributes(x)$model_title, ")")) + sub = paste0("(n = ", sum(x$observations, na.rm = TRUE), + ", model: ", attributes(x)$model_title, ")"), + cex.sub = 0.75) axis(side = 2, at = seq(0, 1, 0.1), labels = paste0(0:10 * 10, "%")) @@ -332,12 +340,13 @@ ggplot_rsi_predict <- function(x, main = paste("Resistance prediction of", attri } suppressWarnings( ggplot2::ggplot(x, ggplot2::aes(x = year, y = value)) + - ggplot2::geom_col() + - ggplot2::geom_errorbar(ggplot2::aes(ymin = se_min, ymax = se_max)) + - scale_y_percent() + + ggplot2::geom_point(size = 2) + + ggplot2::geom_errorbar(ggplot2::aes(ymin = se_min, ymax = se_max), na.rm = TRUE, width = 0.5) + + scale_y_percent(limits = c(0, 1)) + ggplot2::labs(title = main, y = paste0("Percentage (", ylab, ")"), x = "Year", - caption = paste0("(model: ", attributes(x)$model_title, ")")) + caption = paste0("(n = ", sum(x$observations, na.rm = TRUE), + ", model: ", attributes(x)$model_title, ")")) ) } diff --git a/R/rsi.R b/R/rsi.R index 7f8f4fc7..12b17b67 100755 --- a/R/rsi.R +++ b/R/rsi.R @@ -64,6 +64,9 @@ as.rsi <- function(x) { } else if (identical(levels(x), c("S", "I", "R"))) { structure(x, class = c('rsi', 'ordered', 'factor')) } else { + if (mic_like(x) > 0.5) { + warning("`as.rsi` is intended to clean antimicrobial interpretations - not to interpret MIC values.", call. = FALSE) + } x <- x %>% unlist() x.bak <- x @@ -103,6 +106,14 @@ as.rsi <- function(x) { } } +mic_like <- function(x) { + mic <- x %>% + gsub("[^0-9.,]+", "", .) %>% + unique() + mic_valid <- suppressWarnings(as.mic(mic)) + sum(!is.na(mic_valid)) / length(mic) +} + #' @rdname as.rsi #' @export is.rsi <- function(x) { diff --git a/README.md b/README.md index 73a6eb87..9415d705 100755 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ This is the latest **development version**. Although it may contain bugfixes and Development Test | Result | Reference --- | :---: | --- -All functions checked on Linux | [![pipeline status](https://gitlab.com/msberends/AMR/badges/master/pipeline.svg)](https://gitlab.com/msberends/AMR/commits/master) | GitLab CI [[ref 1]](https://gitlab.com/msberends/AMR/pipelines) +All functions checked on Linux | [![pipeline status](https://gitlab.com/msberends/AMR/badges/master/pipeline.svg)](https://gitlab.com/msberends/AMR/commits/master) | GitLab CI [[ref 1]](https://gitlab.com/msberends/AMR) All functions checked on Windows | [![AppVeyor_Build](https://ci.appveyor.com/api/projects/status/gitlab/msberends/AMR?branch=master&svg=true)](https://ci.appveyor.com/project/msberends/amr-svxon) | Appveyor Systems Inc. [[ref 2]](https://ci.appveyor.com/project/msberends/amr-svxon) Percentage of syntax lines checked | [![Code_Coverage](https://codecov.io/gl/msberends/AMR/branch/master/graph/badge.svg)](https://codecov.io/gl/msberends/AMR) | Codecov LLC [[ref 3]](https://codecov.io/gl/msberends/AMR) diff --git a/docs/articles/AMR.html b/docs/articles/AMR.html index bbce516b..66955ce3 100644 --- a/docs/articles/AMR.html +++ b/docs/articles/AMR.html @@ -40,7 +40,7 @@ AMR (for R) - 0.5.0.9016 + 0.5.0.9017 @@ -185,7 +185,7 @@

How to conduct AMR analysis

Matthijs S. Berends

-

08 February 2019

+

09 February 2019

@@ -194,7 +194,7 @@ -

Note: values on this page will change with every website update since they are based on randomly created values and the page was written in RMarkdown. However, the methodology remains unchanged. This page was generated on 08 February 2019.

+

Note: values on this page will change with every website update since they are based on randomly created values and the page was written in RMarkdown. However, the methodology remains unchanged. This page was generated on 09 February 2019.

Introduction

@@ -210,21 +210,21 @@ -2019-02-08 +2019-02-09 abcd Escherichia coli S S -2019-02-08 +2019-02-09 abcd Escherichia coli S R -2019-02-08 +2019-02-09 efgh Escherichia coli R @@ -313,70 +313,70 @@ -2010-10-06 -F7 +2012-10-05 +F3 Hospital D -Klebsiella pneumoniae -S +Escherichia coli +R S S S M -2015-07-29 -T1 +2012-11-18 +X7 Hospital A Escherichia coli -R +S S S S F -2017-10-20 -P2 +2012-04-27 +K2 Hospital B -Staphylococcus aureus -S +Escherichia coli +R S R S +M + + +2014-09-03 +M6 +Hospital A +Streptococcus pneumoniae +S +S +S +S +M + + +2015-09-13 +R4 +Hospital A +Escherichia coli +S +S +S +S F -2010-02-07 -Z6 -Hospital A -Klebsiella pneumoniae +2011-09-19 +D6 +Hospital B +Streptococcus pneumoniae +S I -R S S -F - - -2012-06-26 -V4 -Hospital A -Staphylococcus aureus -S -S -S -S -F - - -2016-02-08 -S2 -Hospital B -Escherichia coli -S -S -S -S -F +M @@ -396,8 +396,8 @@ # # Item Count Percent Cum. Count Cum. Percent # --- ----- ------ -------- ----------- ------------- -# 1 M 2,551 51.0% 2,551 51.0% -# 2 F 2,449 49.0% 5,000 100.0% +# 1 M 2,565 51.3% 2,565 51.3% +# 2 F 2,435 48.7% 5,000 100.0%

So, we can draw at least two conclusions immediately. From a data scientist perspective, the data looks clean: only values M and F. From a researcher perspective: there are slightly more men. Nothing we didn’t already know.

The data is already quite clean, but we still need to transform some variables. The bacteria column now consists of text, and we want to add more variables based on microbial IDs later on. So, we will transform this column to valid IDs. The mutate() function of the dplyr package makes this really easy:

data <- data %>%
@@ -428,10 +428,10 @@
 # Kingella kingae (no changes)
 # 
 # EUCAST Expert Rules, Intrinsic Resistance and Exceptional Phenotypes (v3.1, 2016)
-# Table 1:  Intrinsic resistance in Enterobacteriaceae (345 changes)
+# Table 1:  Intrinsic resistance in Enterobacteriaceae (306 changes)
 # Table 2:  Intrinsic resistance in non-fermentative Gram-negative bacteria (no changes)
 # Table 3:  Intrinsic resistance in other Gram-negative bacteria (no changes)
-# Table 4:  Intrinsic resistance in Gram-positive bacteria (673 changes)
+# Table 4:  Intrinsic resistance in Gram-positive bacteria (681 changes)
 # Table 8:  Interpretive rules for B-lactam agents and Gram-positive cocci (no changes)
 # Table 9:  Interpretive rules for B-lactam agents and Gram-negative rods (no changes)
 # Table 10: Interpretive rules for B-lactam agents and other Gram-negative bacteria (no changes)
@@ -447,9 +447,9 @@
 # Non-EUCAST: piperacillin/tazobactam = S where piperacillin = S (no changes)
 # Non-EUCAST: trimethoprim/sulfa = S where trimethoprim = S (no changes)
 # 
-# => EUCAST rules affected 1,814 out of 5,000 rows
+# => EUCAST rules affected 1,796 out of 5,000 rows
 #    -> added 0 test results
-#    -> changed 1,018 test results (0 to S; 0 to I; 1,018 to R)
+# -> changed 987 test results (0 to S; 0 to I; 987 to R)

@@ -474,8 +474,8 @@ # NOTE: Using column `bacteria` as input for `col_mo`. # NOTE: Using column `date` as input for `col_date`. # NOTE: Using column `patient_id` as input for `col_patient_id`. -# => Found 2,939 first isolates (58.8% of total)

-

So only 58.8% is suitable for resistance analysis! We can now filter on it with the filter() function, also from the dplyr package:

+# => Found 2,948 first isolates (59.0% of total) +

So only 59% is suitable for resistance analysis! We can now filter on it with the filter() function, also from the dplyr package:

data_1st <- data %>% 
   filter(first == TRUE)

For future use, the above two syntaxes can be shortened with the filter_first_isolate() function:

@@ -501,63 +501,85 @@ 1 -2010-04-03 -C3 +2010-05-12 +B4 B_ESCHR_COL -S -S +R +I S S TRUE 2 -2010-10-31 -C3 +2010-05-12 +B4 B_ESCHR_COL R S -S -S +R +R FALSE 3 -2010-11-12 -C3 +2010-07-18 +B4 B_ESCHR_COL +R S -S -S +R S FALSE 4 -2010-11-21 -C3 +2011-01-18 +B4 B_ESCHR_COL R -R -R +S +S S FALSE 5 -2010-12-01 -C3 +2011-11-20 +B4 B_ESCHR_COL S +R +S +S +TRUE + + +6 +2011-12-03 +B4 +B_ESCHR_COL +S +S +S +S +FALSE + + +7 +2012-09-09 +B4 +B_ESCHR_COL +R S S S FALSE -6 -2011-10-22 -C3 +8 +2013-01-24 +B4 B_ESCHR_COL S I @@ -566,52 +588,30 @@ TRUE -7 -2012-03-22 -C3 -B_ESCHR_COL -S -S -S -S -FALSE - - -8 -2012-05-14 -C3 -B_ESCHR_COL -R -R -S -S -FALSE - - 9 -2012-10-26 -C3 +2013-04-25 +B4 B_ESCHR_COL S S S S -TRUE +FALSE 10 -2013-06-13 -C3 +2014-02-01 +B4 B_ESCHR_COL S +S R S -S -FALSE +TRUE -

Only 3 isolates are marked as ‘first’ according to CLSI guideline. But when reviewing the antibiogram, it is obvious that some isolates are absolutely different strains and should be included too. This is why we weigh isolates, based on their antibiogram. The key_antibiotics() function adds a vector with 18 key antibiotics: 6 broad spectrum ones, 6 small spectrum for Gram negatives and 6 small spectrum for Gram positives. These can be defined by the user.

+

Only 4 isolates are marked as ‘first’ according to CLSI guideline. But when reviewing the antibiogram, it is obvious that some isolates are absolutely different strains and should be included too. This is why we weigh isolates, based on their antibiogram. The key_antibiotics() function adds a vector with 18 key antibiotics: 6 broad spectrum ones, 6 small spectrum for Gram negatives and 6 small spectrum for Gram positives. These can be defined by the user.

If a column exists with a name like ‘key(…)ab’ the first_isolate() function will automatically use it and determine the first weighted isolates. Mind the NOTEs in below output:

data <- data %>% 
   mutate(keyab = key_antibiotics(.)) %>% 
@@ -622,7 +622,7 @@
 # NOTE: Using column `patient_id` as input for `col_patient_id`.
 # NOTE: Using column `keyab` as input for `col_keyantibiotics`. Use col_keyantibiotics  = FALSE to prevent this.
 # [Criterion] Inclusion based on key antibiotics, ignoring I.
-# => Found 4,387 first weighted isolates (87.7% of total)
+# => Found 4,405 first weighted isolates (88.1% of total) @@ -639,11 +639,11 @@ - - + + - - + + @@ -651,46 +651,70 @@ - - + + - - + + - - + + + - - + - - + + - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -698,9 +722,9 @@ - - - + + + @@ -710,60 +734,36 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - + + - - + + + - - +
isolate
12010-04-03C32010-05-12B4 B_ESCHR_COLSSRI S S TRUE
22010-10-31C32010-05-12B4 B_ESCHR_COL R SSSRR FALSE TRUE
32010-11-12C32010-07-18B4 B_ESCHR_COLR SSSR S FALSE TRUE
42010-11-21C32011-01-18B4 B_ESCHR_COL RRRSS S FALSE TRUE
52010-12-01C32011-11-20B4 B_ESCHR_COL SRSSTRUETRUE
62011-12-03B4B_ESCHR_COLSSSSFALSETRUE
72012-09-09B4B_ESCHR_COLR S S STRUE
62011-10-22C382013-01-24B4 B_ESCHR_COL S ITRUE
72012-03-22C3B_ESCHR_COLSSSSFALSEFALSE
82012-05-14C3B_ESCHR_COLRRSSFALSETRUE
92012-10-26C32013-04-25B4 B_ESCHR_COL S S S STRUETRUEFALSEFALSE
102013-06-13C32014-02-01B4 B_ESCHR_COL SS R SSFALSETRUE TRUE
-

Instead of 3, now 9 isolates are flagged. In total, 87.7% of all isolates are marked ‘first weighted’ - 29% more than when using the CLSI guideline. In real life, this novel algorithm will yield 5-10% more isolates than the classic CLSI guideline.

+

Instead of 4, now 9 isolates are flagged. In total, 88.1% of all isolates are marked ‘first weighted’ - 29.1% more than when using the CLSI guideline. In real life, this novel algorithm will yield 5-10% more isolates than the classic CLSI guideline.

As with filter_first_isolate(), there’s a shortcut for this new algorithm too:

data_1st <- data %>% 
   filter_first_weighted_isolate()
-

So we end up with 4,387 isolates for analysis.

+

So we end up with 4,405 isolates for analysis.

We can remove unneeded columns:

data_1st <- data_1st %>% 
   select(-c(first, keyab))
@@ -788,28 +788,12 @@ -1 -2010-10-06 -F7 -Hospital D -B_KLBSL_PNE -R -S -S -S -M -Gram negative -Klebsiella -pneumoniae -TRUE - - 2 -2015-07-29 -T1 +2012-11-18 +X7 Hospital A B_ESCHR_COL -R +S S S S @@ -819,68 +803,84 @@ coli TRUE - + 3 -2017-10-20 -P2 +2012-04-27 +K2 Hospital B -B_STPHY_AUR -S +B_ESCHR_COL +R S R S -F +M +Gram negative +Escherichia +coli +TRUE + + +4 +2014-09-03 +M6 +Hospital A +B_STRPTC_PNE +S +S +S +R +M Gram positive -Staphylococcus -aureus +Streptococcus +pneumoniae TRUE -4 -2010-02-07 -Z6 +5 +2015-09-13 +R4 Hospital A -B_KLBSL_PNE -R -R +B_ESCHR_COL +S +S S S F Gram negative -Klebsiella -pneumoniae +Escherichia +coli TRUE 6 -2016-02-08 -S2 +2011-09-19 +D6 Hospital B -B_ESCHR_COL +B_STRPTC_PNE S +I S -S -S -F -Gram negative -Escherichia -coli +R +M +Gram positive +Streptococcus +pneumoniae TRUE -9 -2016-10-31 -H3 -Hospital C -B_STPHY_AUR +7 +2013-01-13 +Q3 +Hospital A +B_STRPTC_PNE R S -R S -M +R +F Gram positive -Staphylococcus -aureus +Streptococcus +pneumoniae TRUE @@ -900,9 +900,9 @@
freq(paste(data_1st$genus, data_1st$species))

Or can be used like the dplyr way, which is easier readable:

data_1st %>% freq(genus, species)
-

Frequency table of genus and species from a data.frame (4,387 x 13)
+

Frequency table of genus and species from a data.frame (4,405 x 13)
Columns: 2
-Length: 4,387 (of which NA: 0 = 0.00%)
+Length: 4,405 (of which NA: 0 = 0.00%)
Unique: 4

Shortest: 16
Longest: 24

@@ -919,33 +919,33 @@ Longest: 24

1 Escherichia coli -2,129 -48.5% -2,129 -48.5% +2,160 +49.0% +2,160 +49.0% 2 Staphylococcus aureus -1,098 -25.0% -3,227 -73.6% +1,109 +25.2% +3,269 +74.2% 3 Streptococcus pneumoniae -688 +690 15.7% -3,915 -89.2% +3,959 +89.9% 4 Klebsiella pneumoniae -472 -10.8% -4,387 +446 +10.1% +4,405 100.0% @@ -956,7 +956,7 @@ Longest: 24

Resistance percentages

The functions portion_R, portion_RI, portion_I, portion_IS and portion_S can be used to determine the portion of a specific antimicrobial outcome. They can be used on their own:

data_1st %>% portion_IR(amox)
-# [1] 0.4700251
+# [1] 0.4719637

Or can be used in conjuction with group_by() and summarise(), both from the dplyr package:

data_1st %>% 
   group_by(hospital) %>% 
@@ -969,19 +969,19 @@ Longest: 24

Hospital A -0.4544765 +0.4711316 Hospital B -0.4920107 +0.4910714 Hospital C -0.4686567 +0.4597701 Hospital D -0.4570792 +0.4488698 @@ -999,23 +999,23 @@ Longest: 24

Hospital A -0.4544765 -1318 +0.4711316 +1299 Hospital B -0.4920107 -1502 +0.4910714 +1568 Hospital C -0.4686567 -670 +0.4597701 +609 Hospital D -0.4570792 -897 +0.4488698 +929 @@ -1035,27 +1035,27 @@ Longest: 24

Escherichia -0.7491780 -0.9074683 -0.9798027 +0.7407407 +0.9000000 +0.9763889 Klebsiella -0.7521186 -0.9067797 -0.9745763 +0.7533632 +0.9147982 +0.9843049 Staphylococcus -0.7349727 -0.9171220 -0.9708561 +0.7303877 +0.9305681 +0.9819657 Streptococcus -0.7398256 +0.7173913 0.0000000 -0.7398256 +0.7173913 diff --git a/docs/articles/AMR_files/figure-html/plot 1-1.png b/docs/articles/AMR_files/figure-html/plot 1-1.png index a326ecf1..ba111e0e 100644 Binary files a/docs/articles/AMR_files/figure-html/plot 1-1.png and b/docs/articles/AMR_files/figure-html/plot 1-1.png differ diff --git a/docs/articles/AMR_files/figure-html/plot 3-1.png b/docs/articles/AMR_files/figure-html/plot 3-1.png index 25e8e77b..4302fee6 100644 Binary files a/docs/articles/AMR_files/figure-html/plot 3-1.png and b/docs/articles/AMR_files/figure-html/plot 3-1.png differ diff --git a/docs/articles/AMR_files/figure-html/plot 4-1.png b/docs/articles/AMR_files/figure-html/plot 4-1.png index c14b3797..f6efe027 100644 Binary files a/docs/articles/AMR_files/figure-html/plot 4-1.png and b/docs/articles/AMR_files/figure-html/plot 4-1.png differ diff --git a/docs/articles/AMR_files/figure-html/plot 5-1.png b/docs/articles/AMR_files/figure-html/plot 5-1.png index bae14fb0..61634b97 100644 Binary files a/docs/articles/AMR_files/figure-html/plot 5-1.png and b/docs/articles/AMR_files/figure-html/plot 5-1.png differ diff --git a/docs/articles/EUCAST.html b/docs/articles/EUCAST.html index b56a8d02..7cede9f4 100644 --- a/docs/articles/EUCAST.html +++ b/docs/articles/EUCAST.html @@ -40,7 +40,7 @@ AMR (for R) - 0.5.0.9016 + 0.5.0.9017
@@ -185,7 +185,7 @@

How to apply EUCAST rules

Matthijs S. Berends

-

08 February 2019

+

09 February 2019

diff --git a/docs/articles/G_test.html b/docs/articles/G_test.html index 7d982d3d..7e04b8c9 100644 --- a/docs/articles/G_test.html +++ b/docs/articles/G_test.html @@ -40,7 +40,7 @@ AMR (for R) - 0.5.0.9016 + 0.5.0.9017 @@ -185,7 +185,7 @@

How to use the G-test

Matthijs S. Berends

-

08 February 2019

+

09 February 2019

diff --git a/docs/articles/Predict.html b/docs/articles/Predict.html index f667f96d..8e0dfce6 100644 --- a/docs/articles/Predict.html +++ b/docs/articles/Predict.html @@ -40,7 +40,7 @@ AMR (for R) - 0.5.0.9016 + 0.5.0.9017 @@ -185,7 +185,7 @@

How to predict antimicrobial resistance

Matthijs S. Berends

-

08 February 2019

+

09 February 2019

@@ -194,10 +194,166 @@ -

(will be available soon)

+
+

+Needed R packages

+

As with many uses in R, we need some additional packages for AMR analysis. Our package works closely together with the tidyverse packages dplyr and ggplot2 by Dr Hadley Wickham. The tidyverse tremendously improves the way we conduct data science - it allows for a very natural way of writing syntaxes and creating beautiful plots in R.

+

Our AMR package depends on these packages and even extends their use and functions.

+ +
+
+

+Prediction analysis

+

Our package contains a function resistance_predict(), which takes the same input as functions for other AMR analysis. Based on a date column, it calculates cases per year and uses a regression model to predict antimicrobial resistance.

+

It is basically as easy as:

+ +
# NOTE: Using column `date` as input for `col_date`.
+# 
+# Logistic regression model (logit) with binomial distribution
+# ------------------------------------------------------------
+# 
+# Call:
+# glm(formula = df_matrix ~ year, family = binomial)
+# 
+# Deviance Residuals: 
+#     Min       1Q   Median       3Q      Max  
+# -2.9224  -1.3120   0.0170   0.7586   3.1932  
+# 
+# Coefficients:
+#               Estimate Std. Error z value Pr(>|z|)    
+# (Intercept) -222.92857   45.93922  -4.853 1.22e-06 ***
+# year           0.10994    0.02284   4.814 1.48e-06 ***
+# ---
+# Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
+# 
+# (Dispersion parameter for binomial family taken to be 1)
+# 
+#     Null deviance: 59.794  on 14  degrees of freedom
+# Residual deviance: 35.191  on 13  degrees of freedom
+# AIC: 93.464
+# 
+# Number of Fisher Scoring iterations: 4
+

The function will look for a data column itself if col_date is not set. The result is nothing more than a data.frame, containing the years, number of observations, actual observed resistance, the estimated resistance and the standard error below and above the estimation:

+
predict_pita
+#    year      value    se_min    se_max observations   observed  estimated
+# 1  2003 0.06250000        NA        NA           32 0.06250000 0.06177594
+# 2  2004 0.08536585        NA        NA           82 0.08536585 0.06846343
+# 3  2005 0.10000000        NA        NA           60 0.10000000 0.07581637
+# 4  2006 0.05084746        NA        NA           59 0.05084746 0.08388789
+# 5  2007 0.12121212        NA        NA           66 0.12121212 0.09273250
+# 6  2008 0.04166667        NA        NA           72 0.04166667 0.10240539
+# 7  2009 0.01639344        NA        NA           61 0.01639344 0.11296163
+# 8  2010 0.09433962        NA        NA           53 0.09433962 0.12445516
+# 9  2011 0.18279570        NA        NA           93 0.18279570 0.13693759
+# 10 2012 0.30769231        NA        NA           65 0.30769231 0.15045682
+# 11 2013 0.08620690        NA        NA           58 0.08620690 0.16505550
+# 12 2014 0.15254237        NA        NA           59 0.15254237 0.18076926
+# 13 2015 0.27272727        NA        NA           55 0.27272727 0.19762493
+# 14 2016 0.25000000        NA        NA           84 0.25000000 0.21563859
+# 15 2017 0.16279070        NA        NA           86 0.16279070 0.23481370
+# 16 2018 0.25513926 0.2228376 0.2874409           NA         NA 0.25513926
+# 17 2019 0.27658825 0.2386811 0.3144954           NA         NA 0.27658825
+# 18 2020 0.29911630 0.2551715 0.3430611           NA         NA 0.29911630
+# 19 2021 0.32266085 0.2723340 0.3729877           NA         NA 0.32266085
+# 20 2022 0.34714076 0.2901847 0.4040968           NA         NA 0.34714076
+# 21 2023 0.37245666 0.3087318 0.4361815           NA         NA 0.37245666
+# 22 2024 0.39849187 0.3279750 0.4690088           NA         NA 0.39849187
+# 23 2025 0.42511415 0.3479042 0.5023241           NA         NA 0.42511415
+# 24 2026 0.45217796 0.3684992 0.5358568           NA         NA 0.45217796
+# 25 2027 0.47952757 0.3897276 0.5693275           NA         NA 0.47952757
+# 26 2028 0.50700045 0.4115444 0.6024565           NA         NA 0.50700045
+# 27 2029 0.53443111 0.4338908 0.6349714           NA         NA 0.53443111
+

The function plot is available in base R, and can be extended by other packages to depend the output based on the type of input. We extended its function to cope with resistance predictions:

+
plot(predict_pita)
+

+

We also support the ggplot2 package with the function ggplot_rsi_predict():

+ +

+
+

+Choosing the right model

+

Resistance is not easily predicted; if we look at vancomycin resistance in Gram positives, the spread (i.e. standard error) is enormous:

+
septic_patients %>%
+  filter(mo_gramstain(mo) == "Gram positive") %>%
+  resistance_predict(col_ab = "vanc", year_min = 2010, info = FALSE) %>% 
+  plot()
+# NOTE: Using column `date` as input for `col_date`.
+

+

Vancomycin resistance could be 100% in ten years, but might also stay around 0%.

+

You can define the model with the model parameter. The default model is a generalised linear regression model using a binomial distribution, assuming that a period of zero resistance was followed by a period of increasing resistance leading slowly to more and more resistance.

+

Valid values are:

+ +++++ + + + + + + + + + + + + + + + + + + + + + + +
Input valuesFunction used by RType of model
+"binomial" or "binom" or "logit" +glm(..., family = binomial)Generalised linear model with binomial distribution
+"loglin" or "poisson" +glm(..., family = poisson)Generalised linear model with poisson distribution
+"lin" or "linear" +lm()Linear model
+

For the vancomycin resistance in Gram positive bacteria, a linear model might be more appropriate since no (left half of a) binomial distribution is to be expected based on observed years:

+
septic_patients %>%
+  filter(mo_gramstain(mo) == "Gram positive") %>%
+  resistance_predict(col_ab = "vanc", year_min = 2010, info = FALSE, model = "linear") %>% 
+  plot()
+# NOTE: Using column `date` as input for `col_date`.
+

+

This seems more likely, doesn’t it?

+
+
diff --git a/docs/articles/Predict_files/figure-html/unnamed-chunk-4-1.png b/docs/articles/Predict_files/figure-html/unnamed-chunk-4-1.png new file mode 100644 index 00000000..162864ce Binary files /dev/null and b/docs/articles/Predict_files/figure-html/unnamed-chunk-4-1.png differ diff --git a/docs/articles/Predict_files/figure-html/unnamed-chunk-5-1.png b/docs/articles/Predict_files/figure-html/unnamed-chunk-5-1.png new file mode 100644 index 00000000..5dbfa649 Binary files /dev/null and b/docs/articles/Predict_files/figure-html/unnamed-chunk-5-1.png differ diff --git a/docs/articles/Predict_files/figure-html/unnamed-chunk-6-1.png b/docs/articles/Predict_files/figure-html/unnamed-chunk-6-1.png new file mode 100644 index 00000000..5ee7a2ab Binary files /dev/null and b/docs/articles/Predict_files/figure-html/unnamed-chunk-6-1.png differ diff --git a/docs/articles/Predict_files/figure-html/unnamed-chunk-7-1.png b/docs/articles/Predict_files/figure-html/unnamed-chunk-7-1.png new file mode 100644 index 00000000..15a99fde Binary files /dev/null and b/docs/articles/Predict_files/figure-html/unnamed-chunk-7-1.png differ diff --git a/docs/articles/WHONET.html b/docs/articles/WHONET.html index 7442285a..73d65e61 100644 --- a/docs/articles/WHONET.html +++ b/docs/articles/WHONET.html @@ -40,7 +40,7 @@ AMR (for R) - 0.5.0.9016 + 0.5.0.9017 @@ -185,7 +185,7 @@

How to work with WHONET data

Matthijs S. Berends

-

08 February 2019

+

09 February 2019

@@ -227,10 +227,10 @@

Frequency table of mo from a data.frame (500 x 54)
Class: mo (character)
Length: 500 (of which NA: 0 = 0.00%)
-Unique: 56

-

Families: 14
-Genera: 23
-Species: 51

+Unique: 39

+

Families: 9
+Genera: 16
+Species: 36

@@ -244,86 +244,86 @@ Species: 51

- - - - + + + + - - - - + + + + - - - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
1 B_ESCHR_COL12725.4%12725.4%24549.0%24549.0%
2 B_STPHY_CNS8016.0%20741.4%7414.8%31963.8%
3B_STPHY_AUR5010.0%25751.4%B_STPHY_EPI387.6%35771.4%
4B_STPHY_EPI377.4%29458.8%
5 B_STRPTC_PNE 31 6.2%32565.0%
6B_STPHY_HOM234.6%34869.6%
7B_PROTS_MIR132.6%36172.2%
8B_KLBSL_PNE112.2%37274.4%
9B_PDMNS_AER81.6%38076.0%
10B_STPHY_CAP81.6% 388 77.6%
5B_STPHY_HOM214.2%40981.8%
6B_PROTS_MIR91.8%41883.6%
7B_ENTRC_IUM81.6%42685.2%
8B_STPHY_CAP81.6%43486.8%
9B_ENTRB_CLO51.0%43987.8%
10B_ENTRC40.8%44388.6%
-

(omitted 46 entries, n = 112 [22.4%])

+

(omitted 29 entries, n = 57 [11.4%])


 # our transformed antibiotic columns
 # amoxicillin/clavulanic acid (J01CR02) as an example
@@ -331,9 +331,9 @@ Species: 51

Frequency table of AMC_ND2 from a data.frame (500 x 54)
Class: factor > ordered > rsi (numeric)
Levels: S < I < R
-Length: 500 (of which NA: 41 = 8.20%)
+Length: 500 (of which NA: 19 = 3.80%)
Unique: 3

-

%IR: 28.98% (ratio S : IR = 1.0 : 0.4)

+

%IR: 25.99% (ratio S : IR = 1.0 : 0.4)

@@ -347,25 +347,25 @@ Unique: 3

- - - - + + + + - - - - + + + + - - + + diff --git a/docs/articles/ab_property.html b/docs/articles/ab_property.html index 8afb1d42..b0ab510d 100644 --- a/docs/articles/ab_property.html +++ b/docs/articles/ab_property.html @@ -40,7 +40,7 @@ AMR (for R) - 0.5.0.9016 + 0.5.0.9017 @@ -185,7 +185,7 @@

How to get properties of an antibiotic

Matthijs S. Berends

-

08 February 2019

+

09 February 2019

diff --git a/docs/articles/benchmarks.html b/docs/articles/benchmarks.html index d73a18fe..8d613930 100644 --- a/docs/articles/benchmarks.html +++ b/docs/articles/benchmarks.html @@ -40,7 +40,7 @@ AMR (for R) - 0.5.0.9016 + 0.5.0.9017 @@ -185,7 +185,7 @@

Benchmarks

Matthijs S. Berends

-

08 February 2019

+

09 February 2019

diff --git a/docs/articles/freq.html b/docs/articles/freq.html index 5bf39646..45f79d3f 100644 --- a/docs/articles/freq.html +++ b/docs/articles/freq.html @@ -40,7 +40,7 @@ AMR (for R) - 0.5.0.9016 + 0.5.0.9017 @@ -185,7 +185,7 @@

How to create frequency tables

Matthijs S. Berends

-

08 February 2019

+

09 February 2019

@@ -595,9 +595,9 @@ Unique: 4

Frequency table of amox from a data.frame (2,000 x 49)
Class: factor > ordered > rsi (numeric)
Levels: S < I < R
-Length: 2,000 (of which NA: 828 = 41.40%)
+Length: 2,000 (of which NA: 771 = 38.55%)
Unique: 3

-

%IR: 58.53% (ratio S : IR = 1.0 : 1.4)

+

%IR: 55.82% (ratio S : IR = 1.0 : 1.3)

1 S32671.0%32671.0%35674.0%35674.0%
2 R11124.2%43795.2%10321.4%45995.4%
3 I 224.8%4594.6%481 100.0%
@@ -612,24 +612,24 @@ Unique: 3

- + - + - - - - + + + + - - + + @@ -726,9 +726,9 @@ Median: 31 July 2009 (47.39%)

Frequency table of amox from a data.frame (2,000 x 49)
Class: factor > ordered > rsi (numeric)
Levels: S < I < R
-Length: 2,828 (of which NA: 828 = 29.28%)
+Length: 2,771 (of which NA: 771 = 27.82%)
Unique: 4

-

%IR: 34.30% (ratio S : IR = 1.0 : 1.4)

+

%IR: 34.30% (ratio S : IR = 1.0 : 1.3)

1 R 68358.3%55.6% 68358.3%55.6%
2 S48641.5%1,16999.7%54344.2%1,22699.8%
3 I 30.3%1,1720.2%1,229 100.0%
@@ -742,24 +742,24 @@ Unique: 4

- - - - + + + + - - + + - - + + diff --git a/docs/articles/mo_property.html b/docs/articles/mo_property.html index f4475ca1..c9423a29 100644 --- a/docs/articles/mo_property.html +++ b/docs/articles/mo_property.html @@ -40,7 +40,7 @@ AMR (for R) - 0.5.0.9016 + 0.5.0.9017 @@ -185,7 +185,7 @@

How to get properties of a microorganism

Matthijs S. Berends

-

08 February 2019

+

09 February 2019

diff --git a/docs/cover_r4ds.png b/docs/cover_r4ds.png new file mode 100644 index 00000000..a7150bdf Binary files /dev/null and b/docs/cover_r4ds.png differ diff --git a/docs/extra.css b/docs/extra.css index 362efd1e..7847e8ee 100644 --- a/docs/extra.css +++ b/docs/extra.css @@ -21,6 +21,16 @@ # ==================================================================== # */ +/* R for Data Science (r4ds) */ +#r4ds a { + display: inline; +} +#r4ds * { + text-align: center; + display: block; + margin: 0 auto; +} + /* class for footer */ .footer_logo { float: right; diff --git a/docs/extra.js b/docs/extra.js index dce09295..dc4be477 100644 --- a/docs/extra.js +++ b/docs/extra.js @@ -34,6 +34,16 @@ $( document ).ready(function() { window.location.replace(url_new); } + $('#sidebar').prepend( + '
' + + ' ' + + ' ' + + ' ' + + '

Learn R reading this great book!

' + + '

Or read it free online: r4ds.co.nz.

' + + '
' + + '
'); + $('footer').html( '
' + '

' + $('footer .copyright p').html().replace( diff --git a/docs/index.html b/docs/index.html index 64f43193..a931a8d1 100644 --- a/docs/index.html +++ b/docs/index.html @@ -195,7 +195,7 @@

This package can be used for:

  • Calculating antimicrobial resistance
  • -
  • Predicting empiric susceptibility of both mono therapy and combination therapy
  • +
  • Calculating empiric susceptibility of both mono therapy and combination therapy
  • Predicting future antimicrobial resistance using regression models
  • Getting properties for any microorganism (like Gram stain, species, genus or family)
  • Getting properties for any antibiotic (like name, ATC code, defined daily dose or trade name)
  • diff --git a/docs/news/index.html b/docs/news/index.html index c1b5e142..d91d6d45 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -342,6 +342,7 @@ These functions use as.atc()
  • Small text updates to summaries of class rsi and mic
  • +
  • Function as.rsi() now gives a warning when inputting MIC values
  • Frequency tables (freq() function):
    • diff --git a/docs/reference/AMR-deprecated.html b/docs/reference/AMR-deprecated.html index 9954eca1..fe2e50a2 100644 --- a/docs/reference/AMR-deprecated.html +++ b/docs/reference/AMR-deprecated.html @@ -80,7 +80,7 @@ AMR (for R) - 0.5.0.9016 + 0.5.0.9017
diff --git a/docs/reference/AMR.html b/docs/reference/AMR.html index 062871ee..cdb35b88 100644 --- a/docs/reference/AMR.html +++ b/docs/reference/AMR.html @@ -80,7 +80,7 @@ AMR (for R) - 0.5.0.9016 + 0.5.0.9017 diff --git a/docs/reference/ITIS.html b/docs/reference/ITIS.html index fefc8b29..e3d0f43a 100644 --- a/docs/reference/ITIS.html +++ b/docs/reference/ITIS.html @@ -80,7 +80,7 @@ AMR (for R) - 0.5.0.9016 + 0.5.0.9017 diff --git a/docs/reference/WHOCC.html b/docs/reference/WHOCC.html index 50c4ca47..bc9fad61 100644 --- a/docs/reference/WHOCC.html +++ b/docs/reference/WHOCC.html @@ -80,7 +80,7 @@ AMR (for R) - 0.5.0.9016 + 0.5.0.9017 diff --git a/docs/reference/WHONET.html b/docs/reference/WHONET.html index b7e6268a..ba9e5742 100644 --- a/docs/reference/WHONET.html +++ b/docs/reference/WHONET.html @@ -80,7 +80,7 @@ AMR (for R) - 0.5.0.9016 + 0.5.0.9017 diff --git a/docs/reference/abname.html b/docs/reference/abname.html index 5f1de2a5..ae38727e 100644 --- a/docs/reference/abname.html +++ b/docs/reference/abname.html @@ -80,7 +80,7 @@ AMR (for R) - 0.5.0.9016 + 0.5.0.9017 diff --git a/docs/reference/age.html b/docs/reference/age.html index 9b90ef49..e0a379ca 100644 --- a/docs/reference/age.html +++ b/docs/reference/age.html @@ -80,7 +80,7 @@ AMR (for R) - 0.5.0.9016 + 0.5.0.9017 diff --git a/docs/reference/age_groups.html b/docs/reference/age_groups.html index 50b50eee..be948266 100644 --- a/docs/reference/age_groups.html +++ b/docs/reference/age_groups.html @@ -80,7 +80,7 @@ AMR (for R) - 0.5.0.9016 + 0.5.0.9017 diff --git a/docs/reference/antibiotics.html b/docs/reference/antibiotics.html index ef4ea712..124556bb 100644 --- a/docs/reference/antibiotics.html +++ b/docs/reference/antibiotics.html @@ -80,7 +80,7 @@ AMR (for R) - 0.5.0.9016 + 0.5.0.9017 diff --git a/docs/reference/as.atc.html b/docs/reference/as.atc.html index ed3d6555..0cf85eb3 100644 --- a/docs/reference/as.atc.html +++ b/docs/reference/as.atc.html @@ -80,7 +80,7 @@ AMR (for R) - 0.5.0.9016 + 0.5.0.9017 diff --git a/docs/reference/as.mic.html b/docs/reference/as.mic.html index 77b94984..5a92422c 100644 --- a/docs/reference/as.mic.html +++ b/docs/reference/as.mic.html @@ -80,7 +80,7 @@ AMR (for R) - 0.5.0.9016 + 0.5.0.9017 diff --git a/docs/reference/as.mo.html b/docs/reference/as.mo.html index 9b2ce26a..59158283 100644 --- a/docs/reference/as.mo.html +++ b/docs/reference/as.mo.html @@ -80,7 +80,7 @@ AMR (for R) - 0.5.0.9016 + 0.5.0.9017 diff --git a/docs/reference/as.rsi.html b/docs/reference/as.rsi.html index 0e9a45aa..9d17eda5 100644 --- a/docs/reference/as.rsi.html +++ b/docs/reference/as.rsi.html @@ -80,7 +80,7 @@ AMR (for R) - 0.5.0.9016 + 0.5.0.9017 diff --git a/docs/reference/atc_online.html b/docs/reference/atc_online.html index dc84a671..d157add9 100644 --- a/docs/reference/atc_online.html +++ b/docs/reference/atc_online.html @@ -80,7 +80,7 @@ AMR (for R) - 0.5.0.9016 + 0.5.0.9017 diff --git a/docs/reference/atc_property.html b/docs/reference/atc_property.html index 81547501..af4bf8f1 100644 --- a/docs/reference/atc_property.html +++ b/docs/reference/atc_property.html @@ -80,7 +80,7 @@ AMR (for R) - 0.5.0.9016 + 0.5.0.9017 diff --git a/docs/reference/availability.html b/docs/reference/availability.html index 0176022c..f05cc130 100644 --- a/docs/reference/availability.html +++ b/docs/reference/availability.html @@ -80,7 +80,7 @@ AMR (for R) - 0.5.0.9016 + 0.5.0.9017 diff --git a/docs/reference/count.html b/docs/reference/count.html index 66044730..62dccb13 100644 --- a/docs/reference/count.html +++ b/docs/reference/count.html @@ -81,7 +81,7 @@ count_R and count_IR can be used to count resistant isolates, count_S and count_ AMR (for R) - 0.5.0.9016 + 0.5.0.9017 diff --git a/docs/reference/eucast_rules.html b/docs/reference/eucast_rules.html index d4a8578d..63ca46f3 100644 --- a/docs/reference/eucast_rules.html +++ b/docs/reference/eucast_rules.html @@ -80,7 +80,7 @@ AMR (for R) - 0.5.0.9016 + 0.5.0.9017 diff --git a/docs/reference/first_isolate.html b/docs/reference/first_isolate.html index 0ed7d132..2fa42e85 100644 --- a/docs/reference/first_isolate.html +++ b/docs/reference/first_isolate.html @@ -80,7 +80,7 @@ AMR (for R) - 0.5.0.9016 + 0.5.0.9017 diff --git a/docs/reference/freq.html b/docs/reference/freq.html index 4289a2d1..c3fba94b 100644 --- a/docs/reference/freq.html +++ b/docs/reference/freq.html @@ -81,7 +81,7 @@ top_freq can be used to get the top/bottom n items of a frequency table, with co AMR (for R) - 0.5.0.9016 + 0.5.0.9017 diff --git a/docs/reference/g.test.html b/docs/reference/g.test.html index 60f4d6a0..5ec01421 100644 --- a/docs/reference/g.test.html +++ b/docs/reference/g.test.html @@ -80,7 +80,7 @@ AMR (for R) - 0.5.0.9016 + 0.5.0.9017 diff --git a/docs/reference/get_locale.html b/docs/reference/get_locale.html index a287cb6b..00275c56 100644 --- a/docs/reference/get_locale.html +++ b/docs/reference/get_locale.html @@ -80,7 +80,7 @@ AMR (for R) - 0.5.0.9016 + 0.5.0.9017 diff --git a/docs/reference/ggplot_rsi.html b/docs/reference/ggplot_rsi.html index 232791e3..cf5b7f0d 100644 --- a/docs/reference/ggplot_rsi.html +++ b/docs/reference/ggplot_rsi.html @@ -80,7 +80,7 @@ AMR (for R) - 0.5.0.9016 + 0.5.0.9017 diff --git a/docs/reference/guess_ab_col.html b/docs/reference/guess_ab_col.html index 7f436264..c39fc7ff 100644 --- a/docs/reference/guess_ab_col.html +++ b/docs/reference/guess_ab_col.html @@ -80,7 +80,7 @@ AMR (for R) - 0.5.0.9016 + 0.5.0.9017 diff --git a/docs/reference/join.html b/docs/reference/join.html index a27493cc..05b5404e 100644 --- a/docs/reference/join.html +++ b/docs/reference/join.html @@ -80,7 +80,7 @@ AMR (for R) - 0.5.0.9016 + 0.5.0.9017 diff --git a/docs/reference/key_antibiotics.html b/docs/reference/key_antibiotics.html index 312e507e..5867bb58 100644 --- a/docs/reference/key_antibiotics.html +++ b/docs/reference/key_antibiotics.html @@ -80,7 +80,7 @@ AMR (for R) - 0.5.0.9016 + 0.5.0.9017 diff --git a/docs/reference/kurtosis.html b/docs/reference/kurtosis.html index 903dccb8..1b52aa61 100644 --- a/docs/reference/kurtosis.html +++ b/docs/reference/kurtosis.html @@ -80,7 +80,7 @@ AMR (for R) - 0.5.0.9016 + 0.5.0.9017 diff --git a/docs/reference/like.html b/docs/reference/like.html index 328da920..c6a2892a 100644 --- a/docs/reference/like.html +++ b/docs/reference/like.html @@ -80,7 +80,7 @@ AMR (for R) - 0.5.0.9016 + 0.5.0.9017 diff --git a/docs/reference/mdro.html b/docs/reference/mdro.html index a13074c9..b57fb00f 100644 --- a/docs/reference/mdro.html +++ b/docs/reference/mdro.html @@ -80,7 +80,7 @@ AMR (for R) - 0.5.0.9016 + 0.5.0.9017 diff --git a/docs/reference/microorganisms.old.html b/docs/reference/microorganisms.old.html index ef7e769b..03e7f329 100644 --- a/docs/reference/microorganisms.old.html +++ b/docs/reference/microorganisms.old.html @@ -80,7 +80,7 @@ AMR (for R) - 0.5.0.9016 + 0.5.0.9017 diff --git a/docs/reference/mo_property.html b/docs/reference/mo_property.html index 2167e526..69732bef 100644 --- a/docs/reference/mo_property.html +++ b/docs/reference/mo_property.html @@ -80,7 +80,7 @@ AMR (for R) - 0.5.0.9016 + 0.5.0.9017 diff --git a/docs/reference/mo_source.html b/docs/reference/mo_source.html index 0d7ffd42..23eb4857 100644 --- a/docs/reference/mo_source.html +++ b/docs/reference/mo_source.html @@ -80,7 +80,7 @@ AMR (for R) - 0.5.0.9016 + 0.5.0.9017 diff --git a/docs/reference/p.symbol.html b/docs/reference/p.symbol.html index 9e313d7d..3217086b 100644 --- a/docs/reference/p.symbol.html +++ b/docs/reference/p.symbol.html @@ -80,7 +80,7 @@ AMR (for R) - 0.5.0.9016 + 0.5.0.9017 diff --git a/docs/reference/portion.html b/docs/reference/portion.html index 59f096fe..c91a1b0c 100644 --- a/docs/reference/portion.html +++ b/docs/reference/portion.html @@ -81,7 +81,7 @@ portion_R and portion_IR can be used to calculate resistance, portion_S and port AMR (for R) - 0.5.0.9016 + 0.5.0.9017 diff --git a/docs/reference/read.4D.html b/docs/reference/read.4D.html index 7e7ac3b0..5fd56a25 100644 --- a/docs/reference/read.4D.html +++ b/docs/reference/read.4D.html @@ -80,7 +80,7 @@ AMR (for R) - 0.5.0.9016 + 0.5.0.9017 diff --git a/docs/reference/resistance_predict.html b/docs/reference/resistance_predict.html index b52f2173..ee0daa4f 100644 --- a/docs/reference/resistance_predict.html +++ b/docs/reference/resistance_predict.html @@ -80,7 +80,7 @@ AMR (for R) - 0.5.0.9016 + 0.5.0.9017 diff --git a/docs/reference/rsi.html b/docs/reference/rsi.html index f672a5de..ba849e6d 100644 --- a/docs/reference/rsi.html +++ b/docs/reference/rsi.html @@ -80,7 +80,7 @@ AMR (for R) - 0.5.0.9016 + 0.5.0.9017 diff --git a/docs/reference/septic_patients.html b/docs/reference/septic_patients.html index 4e8136ed..8a75c3d2 100644 --- a/docs/reference/septic_patients.html +++ b/docs/reference/septic_patients.html @@ -80,7 +80,7 @@ AMR (for R) - 0.5.0.9016 + 0.5.0.9017 diff --git a/docs/reference/skewness.html b/docs/reference/skewness.html index 9faacd29..cd672f49 100644 --- a/docs/reference/skewness.html +++ b/docs/reference/skewness.html @@ -81,7 +81,7 @@ When negative: the left tail is longer; the mass of the distribution is concentr AMR (for R) - 0.5.0.9016 + 0.5.0.9017 diff --git a/docs/reference/supplementary_data.html b/docs/reference/supplementary_data.html index f11c34e9..d48f3a70 100644 --- a/docs/reference/supplementary_data.html +++ b/docs/reference/supplementary_data.html @@ -80,7 +80,7 @@ AMR (for R) - 0.5.0.9016 + 0.5.0.9017 diff --git a/index.md b/index.md index f227ac56..8317461a 100644 --- a/index.md +++ b/index.md @@ -14,7 +14,7 @@ This R package is actively maintained and free software; you can freely use and This package can be used for: * Calculating antimicrobial resistance - * Predicting empiric susceptibility of both mono therapy and combination therapy + * Calculating empiric susceptibility of both mono therapy and combination therapy * Predicting future antimicrobial resistance using regression models * Getting properties for any microorganism (like Gram stain, species, genus or family) * Getting properties for any antibiotic (like name, ATC code, defined daily dose or trade name) diff --git a/man/resistance_predict.Rd b/man/resistance_predict.Rd index 46dde885..f27b6ce6 100644 --- a/man/resistance_predict.Rd +++ b/man/resistance_predict.Rd @@ -38,7 +38,7 @@ ggplot_rsi_predict(x, main = paste("Resistance prediction of", \item{minimum}{minimal amount of available isolates per year to include. Years containing less observations will be estimated by the model.} -\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"}).} +\item{model}{the statistical model of choice. Defaults to a generalised linear regression model with binomial distribution, assuming that a period of zero resistance was followed by a period of increasing resistance leading slowly to more and more resistance. See Details for valid options.} \item{I_as_R}{a logical to indicate whether values \code{I} should be treated as \code{R}} @@ -69,6 +69,14 @@ ggplot_rsi_predict(x, main = paste("Resistance prediction of", \description{ 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. } +\details{ +Valid options for the statistical model are: +\itemize{ + \item{\code{"binomial"} or \code{"binom"} or \code{"logit"}: a generalised linear regression model with binomial distribution} + \item{\code{"loglin"} or \code{"poisson"}: a generalised log-linear regression model with poisson distribution} + \item{\code{"lin"} or \code{"linear"}: a linear regression model} +} +} \section{Read more on our website!}{ \if{html}{\figure{logo.png}{options: height=40px style=margin-bottom:5px} \cr} diff --git a/pkgdown/extra.css b/pkgdown/extra.css index 362efd1e..7847e8ee 100644 --- a/pkgdown/extra.css +++ b/pkgdown/extra.css @@ -21,6 +21,16 @@ # ==================================================================== # */ +/* R for Data Science (r4ds) */ +#r4ds a { + display: inline; +} +#r4ds * { + text-align: center; + display: block; + margin: 0 auto; +} + /* class for footer */ .footer_logo { float: right; diff --git a/pkgdown/extra.js b/pkgdown/extra.js index dce09295..dc4be477 100644 --- a/pkgdown/extra.js +++ b/pkgdown/extra.js @@ -34,6 +34,16 @@ $( document ).ready(function() { window.location.replace(url_new); } + $('#sidebar').prepend( + '
' + + ' ' + + ' ' + + ' ' + + '

Learn R reading this great book!

' + + '

Or read it free online: r4ds.co.nz.

' + + '
' + + '
'); + $('footer').html( '
' + '

' + $('footer .copyright p').html().replace( diff --git a/pkgdown/logos/cover_r4ds.png b/pkgdown/logos/cover_r4ds.png new file mode 100644 index 00000000..a7150bdf Binary files /dev/null and b/pkgdown/logos/cover_r4ds.png differ diff --git a/vignettes/Predict.Rmd b/vignettes/Predict.Rmd index 56cdbac3..511e8410 100755 --- a/vignettes/Predict.Rmd +++ b/vignettes/Predict.Rmd @@ -16,8 +16,96 @@ editor_options: ```{r setup, include = FALSE, results = 'markup'} knitr::opts_chunk$set( collapse = TRUE, - comment = "#" + comment = "#", + fig.width = 7.5, + fig.height = 4.5 ) ``` -*(will be available soon)* +## Needed R packages +As with many uses in R, we need some additional packages for AMR analysis. Our package works closely together with the [tidyverse packages](https://www.tidyverse.org) [`dplyr`](https://dplyr.tidyverse.org/) and [`ggplot2`](https://ggplot2.tidyverse.org) by [Dr Hadley Wickham](https://www.linkedin.com/in/hadleywickham/). The tidyverse tremendously improves the way we conduct data science - it allows for a very natural way of writing syntaxes and creating beautiful plots in R. + +Our `AMR` package depends on these packages and even extends their use and functions. + +```{r lib packages, message = FALSE} +library(dplyr) +library(ggplot2) +library(AMR) + +# (if not yet installed, install with:) +# install.packages(c("tidyverse", "AMR")) +``` + +## Prediction analysis +Our package contains a function `resistance_predict()`, which takes the same input as functions for [other AMR analysis](./articles/AMR.html). Based on a date column, it calculates cases per year and uses a regression model to predict antimicrobial resistance. + +It is basically as easy as: +```{r, eval = FALSE} +# resistance prediction of piperacillin/tazobactam (pita): +resistance_predict(tbl = septic_patients, col_date = "date", col_ab = "pita") + +# or: +septic_patients %>% + resistance_predict(col_ab = "pita") + +# to bind it to object 'predict_pita' for example: +predict_pita <- septic_patients %>% + resistance_predict(col_ab = "pita") +``` + +```{r, echo = FALSE} +predict_pita <- septic_patients %>% + resistance_predict(col_ab = "pita") +``` + +The function will look for a data column itself if `col_date` is not set. The result is nothing more than a `data.frame`, containing the years, number of observations, actual observed resistance, the estimated resistance and the standard error below and above the estimation: +```{r} +predict_pita +``` + +The function `plot` is available in base R, and can be extended by other packages to depend the output based on the type of input. We extended its function to cope with resistance predictions: + +```{r} +plot(predict_pita) +``` + +We also support the `ggplot2` package with the function `ggplot_rsi_predict()`: + +```{r} +library(ggplot2) +ggplot_rsi_predict(predict_pita) +``` + +### Choosing the right model + +Resistance is not easily predicted; if we look at vancomycin resistance in Gram positives, the spread (i.e. standard error) is enormous: + +```{r} +septic_patients %>% + filter(mo_gramstain(mo) == "Gram positive") %>% + resistance_predict(col_ab = "vanc", year_min = 2010, info = FALSE) %>% + plot() +``` + +Vancomycin resistance could be 100% in ten years, but might also stay around 0%. + +You can define the model with the `model` parameter. The default model is a generalised linear regression model using a binomial distribution, assuming that a period of zero resistance was followed by a period of increasing resistance leading slowly to more and more resistance. + +Valid values are: + +| Input values | Function used by R | Type of model | +|----------------------------------------|-------------------------------|-----------------------------------------------------| +| `"binomial"` or `"binom"` or `"logit"` | `glm(..., family = binomial)` | Generalised linear model with binomial distribution | +| `"loglin"` or `"poisson"` | `glm(..., family = poisson)` | Generalised linear model with poisson distribution | +| `"lin"` or `"linear"` | `lm()` | Linear model | + +For the vancomycin resistance in Gram positive bacteria, a linear model might be more appropriate since no (left half of a) binomial distribution is to be expected based on observed years: + +```{r} +septic_patients %>% + filter(mo_gramstain(mo) == "Gram positive") %>% + resistance_predict(col_ab = "vanc", year_min = 2010, info = FALSE, model = "linear") %>% + plot() +``` + +This seems more likely, doesn't it?

1 (NA)82841.4%82841.4%77138.6%77138.6%
2 R 683 34.2%1,51175.6%1,45472.7%
3 S48624.3%54327.2% 1,997 99.9%