mirror of
https://github.com/msberends/AMR.git
synced 2024-12-25 18:06:12 +01:00
small fixes
This commit is contained in:
parent
498e88b5cf
commit
feab1cad6b
@ -1,6 +1,6 @@
|
||||
Package: AMR
|
||||
Version: 0.2.0.9017
|
||||
Date: 2018-07-25
|
||||
Date: 2018-07-28
|
||||
Title: Antimicrobial Resistance Analysis
|
||||
Authors@R: c(
|
||||
person(
|
||||
|
@ -111,6 +111,7 @@ importFrom(dplyr,arrange)
|
||||
importFrom(dplyr,arrange_at)
|
||||
importFrom(dplyr,as_tibble)
|
||||
importFrom(dplyr,between)
|
||||
importFrom(dplyr,case_when)
|
||||
importFrom(dplyr,desc)
|
||||
importFrom(dplyr,filter)
|
||||
importFrom(dplyr,filter_at)
|
||||
|
@ -60,6 +60,7 @@ globalVariables(c('abname',
|
||||
'septic_patients',
|
||||
'species',
|
||||
'umcg',
|
||||
'value',
|
||||
'values',
|
||||
'View',
|
||||
'y',
|
||||
|
@ -429,7 +429,7 @@ rsi_df <- function(tbl,
|
||||
#' @return \code{data.frame} with columns:
|
||||
#' \itemize{
|
||||
#' \item{\code{year}}
|
||||
#' \item{\code{resistance}, the same as \code{estimated} when \code{preserve_measurements = FALSE}, and a combination of \code{observed} and \code{estimated} otherwise}
|
||||
#' \item{\code{value}, the same as \code{estimated} when \code{preserve_measurements = FALSE}, and a combination of \code{observed} and \code{estimated} otherwise}
|
||||
#' \item{\code{se_min}, the lower bound of the standard error with a minimum of \code{0}}
|
||||
#' \item{\code{se_max} the upper bound of the standard error with a maximum of \code{1}}
|
||||
#' \item{\code{observations}, the total number of observations, i.e. S + I + R}
|
||||
@ -440,7 +440,7 @@ rsi_df <- function(tbl,
|
||||
#' @rdname resistance_predict
|
||||
#' @export
|
||||
#' @importFrom stats predict glm lm
|
||||
#' @importFrom dplyr %>% pull mutate group_by_at summarise filter n_distinct arrange
|
||||
#' @importFrom dplyr %>% pull mutate group_by_at summarise filter n_distinct arrange case_when
|
||||
# @importFrom tidyr spread
|
||||
#' @examples
|
||||
#' \dontrun{
|
||||
@ -493,7 +493,7 @@ rsi_df <- function(tbl,
|
||||
#'
|
||||
#' ggplot(data,
|
||||
#' aes(x = year)) +
|
||||
#' geom_col(aes(y = resistance),
|
||||
#' geom_col(aes(y = value),
|
||||
#' fill = "grey75") +
|
||||
#' geom_errorbar(aes(ymin = se_min,
|
||||
#' ymax = se_max),
|
||||
@ -626,13 +626,13 @@ resistance_predict <- function(tbl,
|
||||
}
|
||||
|
||||
# prepare the output dataframe
|
||||
prediction <- data.frame(year = years_predict, resistance = prediction, stringsAsFactors = FALSE)
|
||||
prediction <- data.frame(year = years_predict, value = prediction, stringsAsFactors = FALSE)
|
||||
|
||||
prediction$se_min <- prediction$resistance - se
|
||||
prediction$se_max <- prediction$resistance + se
|
||||
prediction$se_min <- prediction$value - se
|
||||
prediction$se_max <- prediction$value + se
|
||||
|
||||
if (model == 'loglin') {
|
||||
prediction$resistance <- prediction$resistance %>%
|
||||
prediction$value <- prediction$value %>%
|
||||
format(scientific = FALSE) %>%
|
||||
as.integer()
|
||||
prediction$se_min <- prediction$se_min %>% as.integer()
|
||||
@ -653,12 +653,12 @@ resistance_predict <- function(tbl,
|
||||
if (!'I' %in% colnames(df)) {
|
||||
df$I <- 0
|
||||
}
|
||||
df$resistance <- df$R / rowSums(df[, c('R', 'S', 'I')])
|
||||
df$value <- df$R / rowSums(df[, c('R', 'S', 'I')])
|
||||
} else {
|
||||
df$resistance <- df$R / rowSums(df[, c('R', 'S')])
|
||||
df$value <- df$R / rowSums(df[, c('R', 'S')])
|
||||
}
|
||||
measurements <- data.frame(year = df$year,
|
||||
resistance = df$resistance,
|
||||
value = df$value,
|
||||
se_min = NA,
|
||||
se_max = NA,
|
||||
observations = df$total,
|
||||
@ -668,16 +668,18 @@ resistance_predict <- function(tbl,
|
||||
total <- rbind(measurements,
|
||||
prediction %>% filter(!year %in% df$year))
|
||||
if (model %in% c('binomial', 'binom', 'logit')) {
|
||||
total <- total %>% mutate(observed = ifelse(is.na(observations), NA, resistance),
|
||||
estimated = prediction$resistance)
|
||||
total <- total %>% mutate(observed = ifelse(is.na(observations), NA, value),
|
||||
estimated = prediction$value)
|
||||
}
|
||||
}
|
||||
|
||||
try(
|
||||
total$resistance[which(total$resistance > 1)] <- 1,
|
||||
total$resistance[which(total$resistance < 0)] <- 0,
|
||||
silent = TRUE
|
||||
)
|
||||
if ("value" %in% colnames(total)) {
|
||||
total <- total %>%
|
||||
mutate(value = case_when(value > 1 ~ 1,
|
||||
value < 0 ~ 0,
|
||||
TRUE ~ value))
|
||||
}
|
||||
|
||||
total %>% arrange(year)
|
||||
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ rsi_predict(tbl, col_ab, col_date, year_min = NULL, year_max = NULL,
|
||||
\code{data.frame} with columns:
|
||||
\itemize{
|
||||
\item{\code{year}}
|
||||
\item{\code{resistance}, the same as \code{estimated} when \code{preserve_measurements = FALSE}, and a combination of \code{observed} and \code{estimated} otherwise}
|
||||
\item{\code{value}, the same as \code{estimated} when \code{preserve_measurements = FALSE}, and a combination of \code{observed} and \code{estimated} otherwise}
|
||||
\item{\code{se_min}, the lower bound of the standard error with a minimum of \code{0}}
|
||||
\item{\code{se_max} the upper bound of the standard error with a maximum of \code{1}}
|
||||
\item{\code{observations}, the total number of observations, i.e. S + I + R}
|
||||
@ -102,7 +102,7 @@ if (!require(ggplot2)) {
|
||||
|
||||
ggplot(data,
|
||||
aes(x = year)) +
|
||||
geom_col(aes(y = resistance),
|
||||
geom_col(aes(y = value),
|
||||
fill = "grey75") +
|
||||
geom_errorbar(aes(ymin = se_min,
|
||||
ymax = se_max),
|
||||
|
@ -1,20 +1,22 @@
|
||||
context("atc.R")
|
||||
|
||||
test_that("atc_property works", {
|
||||
expect_equal(tolower(atc_property("J01CA04", property = "Name")), "amoxicillin")
|
||||
expect_equal(atc_property("J01CA04", property = "unit"), "g")
|
||||
if (!is.null(curl::nslookup("www.whocc.no", error = FALSE))) {
|
||||
expect_equal(tolower(atc_property("J01CA04", property = "Name")), "amoxicillin")
|
||||
expect_equal(atc_property("J01CA04", property = "unit"), "g")
|
||||
|
||||
expect_equal(atc_property("J01CA04", property = "DDD"),
|
||||
atc_ddd("J01CA04"))
|
||||
expect_equal(atc_property("J01CA04", property = "DDD"),
|
||||
atc_ddd("J01CA04"))
|
||||
|
||||
expect_identical(atc_property("J01CA04", property = "Groups"),
|
||||
atc_groups("J01CA04"))
|
||||
expect_identical(atc_property("J01CA04", property = "Groups"),
|
||||
atc_groups("J01CA04"))
|
||||
|
||||
expect_warning(atc_property("ABCDEFG", property = "DDD"))
|
||||
expect_warning(atc_property("ABCDEFG", property = "DDD"))
|
||||
|
||||
expect_error(atc_property("J01CA04", property = c(1:5)))
|
||||
expect_error(atc_property("J01CA04", property = "test"))
|
||||
expect_error(atc_property("J01CA04", property = "test", administration = c(1:5)))
|
||||
expect_error(atc_property("J01CA04", property = c(1:5)))
|
||||
expect_error(atc_property("J01CA04", property = "test"))
|
||||
expect_error(atc_property("J01CA04", property = "test", administration = c(1:5)))
|
||||
}
|
||||
})
|
||||
|
||||
test_that("abname works", {
|
||||
|
@ -86,7 +86,7 @@ test_that("prediction of rsi works", {
|
||||
col_date = "date",
|
||||
minimum = 10,
|
||||
info = TRUE) %>%
|
||||
pull("resistance")
|
||||
pull("value")
|
||||
# amox resistance will increase according to data set `septic_patients`
|
||||
expect_true(amox_R[3] < amox_R[20])
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user