mirror of
https://github.com/msberends/AMR.git
synced 2025-07-08 16:42:10 +02:00
new antibiotics
This commit is contained in:
@ -19,27 +19,28 @@
|
||||
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
||||
# ==================================================================== #
|
||||
|
||||
context("atc.R")
|
||||
context("ab.R")
|
||||
|
||||
test_that("as.atc works", {
|
||||
expect_equal(suppressWarnings(as.character(as.atc(c("J01FA01",
|
||||
"Erythromycin",
|
||||
"eryt",
|
||||
"ERYT",
|
||||
"ERY",
|
||||
"Erythrocin",
|
||||
"Eryzole",
|
||||
"Pediamycin")))),
|
||||
rep("J01FA01", 8))
|
||||
test_that("as.ab works", {
|
||||
expect_equal(as.character(as.ab(c("J01FA01",
|
||||
"J 01 FA 01",
|
||||
"Erythromycin",
|
||||
"eryt",
|
||||
" eryt 123",
|
||||
"ERYT",
|
||||
"ERY",
|
||||
"erytromicine",
|
||||
"Erythrocin",
|
||||
"Romycin"))),
|
||||
rep("ERY", 10))
|
||||
|
||||
expect_identical(class(as.atc("amox")), "atc")
|
||||
expect_identical(class(pull(antibiotics, atc)), "atc")
|
||||
expect_identical(atc_trivial_nl("Cefmenoxim"), "Cefmenoxim")
|
||||
expect_identical(class(as.ab("amox")), "ab")
|
||||
expect_identical(class(pull(antibiotics, ab)), "ab")
|
||||
|
||||
expect_warning(as.atc("Z00ZZ00")) # not yet available in data set
|
||||
expect_warning(as.atc("UNKNOWN"))
|
||||
expect_warning(as.ab("Z00ZZ00")) # not yet available in data set
|
||||
expect_warning(as.ab("UNKNOWN"))
|
||||
|
||||
expect_output(print(as.atc("amox")))
|
||||
expect_output(print(as.ab("amox")))
|
||||
|
||||
# first 5 chars of official name
|
||||
expect_equal(as.character(as.atc(c("nitro", "cipro"))),
|
@ -19,19 +19,37 @@
|
||||
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
||||
# ==================================================================== #
|
||||
|
||||
context("atc_property.R")
|
||||
context("ab_property.R")
|
||||
|
||||
test_that("atc_property works", {
|
||||
expect_equal(atc_certe("amox"), "amox")
|
||||
expect_equal(atc_name("amox", language = "en"), "Amoxicillin")
|
||||
expect_equal(atc_name("amox", language = "nl"), "Amoxicilline")
|
||||
expect_equal(atc_official("amox", language = "en"), "Amoxicillin")
|
||||
expect_equal(atc_trivial_nl("amox"), "Amoxicilline")
|
||||
expect_equal(atc_umcg("amox"), "AMOX")
|
||||
expect_equal(class(atc_tradenames("amox")), "character")
|
||||
expect_equal(class(atc_tradenames(c("amox", "amox"))), "list")
|
||||
test_that("ab_property works", {
|
||||
|
||||
expect_error(atc_property("amox", "invalid property"))
|
||||
expect_error(atc_name("amox", language = "INVALID"))
|
||||
expect_output(print(atc_name("amox", language = NULL)))
|
||||
expect_identical(ab_name("AMX"), "Amoxicillin")
|
||||
expect_identical(as.character(ab_atc("AMX")), "J01CA04")
|
||||
expect_identical(ab_cid("AMX"), as.integer(33613))
|
||||
|
||||
expect_equal(class(ab_tradenames("AMX")), "character")
|
||||
expect_equal(class(ab_tradenames(c("AMX", "AMX"))), "list")
|
||||
|
||||
expect_identical(ab_group("AMX"), "Beta-lactams/penicillins")
|
||||
expect_identical(ab_atc_group1("AMX"), "Beta-lactam antibacterials, penicillins")
|
||||
expect_identical(ab_atc_group2("AMX"), "Penicillins with extended spectrum")
|
||||
|
||||
expect_identical(ab_name("Fluclox"), "Flucloxacillin")
|
||||
expect_identical(ab_name("fluklox"), "Flucloxacillin")
|
||||
expect_identical(ab_name("floxapen"), "Flucloxacillin")
|
||||
expect_identical(ab_name(21319) , "Flucloxacillin")
|
||||
expect_identical(ab_name("J01CF05"), "Flucloxacillin")
|
||||
|
||||
expect_identical(ab_ddd("AMX", "oral"), 1)
|
||||
expect_identical(ab_ddd("AMX", "oral", units = TRUE) , "g")
|
||||
expect_identical(ab_ddd("AMX", "iv"), 1)
|
||||
expect_identical(ab_ddd("AMX", "iv", units = TRUE) , "g")
|
||||
|
||||
expect_identical(ab_name(x = c("AMC", "PLB")), c("Amoxicillin/clavulanic acid", "Polymyxin B"))
|
||||
expect_identical(ab_name(x = c("AMC", "PLB"), tolower = TRUE),
|
||||
c("amoxicillin/clavulanic acid", "polymyxin B"))
|
||||
|
||||
expect_error(ab_property("amox", "invalid property"))
|
||||
expect_error(ab_name("amox", language = "INVALID"))
|
||||
expect_output(print(ab_name("amox", language = NULL)))
|
||||
})
|
@ -1,43 +0,0 @@
|
||||
# ==================================================================== #
|
||||
# TITLE #
|
||||
# Antimicrobial Resistance (AMR) Analysis #
|
||||
# #
|
||||
# SOURCE #
|
||||
# https://gitlab.com/msberends/AMR #
|
||||
# #
|
||||
# LICENCE #
|
||||
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
|
||||
# #
|
||||
# This R package is free software; you can freely use and distribute #
|
||||
# it for both personal and commercial purposes under the terms of the #
|
||||
# GNU General Public License version 2.0 (GNU GPL-2), as published by #
|
||||
# the Free Software Foundation. #
|
||||
# #
|
||||
# This R package was created for academic research and was publicly #
|
||||
# released in the hope that it will be useful, but it comes WITHOUT #
|
||||
# ANY WARRANTY OR LIABILITY. #
|
||||
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
||||
# ==================================================================== #
|
||||
|
||||
context("abname.R")
|
||||
|
||||
test_that("abname works", {
|
||||
expect_equal(abname("AMOX"), "Amoxicillin")
|
||||
expect_equal(abname(c("AMOX", "GENT")), c("Amoxicillin", "Gentamicin"))
|
||||
expect_equal(abname(c("AMOX+GENT")), "Amoxicillin + gentamicin")
|
||||
expect_equal(abname("AMOX", from = 'umcg'), "Amoxicillin")
|
||||
expect_equal(abname("amox", from = 'certe', tolower = TRUE), "amoxicillin")
|
||||
expect_equal(abname("J01CA04", from = 'atc'), "Amoxicillin")
|
||||
expect_equal(abname(c("amox", "J01CA04", "Trimox", "dispermox", "Amoxil")),
|
||||
rep("Amoxicillin", 5))
|
||||
expect_equal(abname("AMOX", to = 'atc'), "J01CA04")
|
||||
|
||||
expect_error(abname("AMOX", to = c(1:3)))
|
||||
expect_error(abname("AMOX", to = "test"))
|
||||
expect_warning(abname("NOTEXISTING
|
||||
"))
|
||||
expect_warning(abname("AMOX or GENT"))
|
||||
|
||||
# this one is being found with as.atc internally
|
||||
expect_equal(abname("flu_clox123"), "Flucloxacillin")
|
||||
})
|
@ -22,52 +22,52 @@
|
||||
context("count.R")
|
||||
|
||||
test_that("counts work", {
|
||||
# amox resistance in `septic_patients`
|
||||
expect_equal(count_R(septic_patients$amox), 683)
|
||||
expect_equal(count_I(septic_patients$amox), 3)
|
||||
expect_equal(count_S(septic_patients$amox), 543)
|
||||
expect_equal(count_R(septic_patients$amox) + count_I(septic_patients$amox),
|
||||
count_IR(septic_patients$amox))
|
||||
expect_equal(count_S(septic_patients$amox) + count_I(septic_patients$amox),
|
||||
count_SI(septic_patients$amox))
|
||||
# AMX resistance in `septic_patients`
|
||||
expect_equal(count_R(septic_patients$AMX), 683)
|
||||
expect_equal(count_I(septic_patients$AMX), 3)
|
||||
expect_equal(count_S(septic_patients$AMX), 543)
|
||||
expect_equal(count_R(septic_patients$AMX) + count_I(septic_patients$AMX),
|
||||
count_IR(septic_patients$AMX))
|
||||
expect_equal(count_S(septic_patients$AMX) + count_I(septic_patients$AMX),
|
||||
count_SI(septic_patients$AMX))
|
||||
|
||||
library(dplyr)
|
||||
expect_equal(septic_patients %>% count_S(amcl), 1342)
|
||||
expect_equal(septic_patients %>% count_S(amcl, gent), 1660)
|
||||
expect_equal(septic_patients %>% count_all(amcl, gent), 1798)
|
||||
expect_identical(septic_patients %>% count_all(amcl, gent),
|
||||
septic_patients %>% count_S(amcl, gent) +
|
||||
septic_patients %>% count_IR(amcl, gent))
|
||||
expect_equal(septic_patients %>% count_S(AMC), 1342)
|
||||
expect_equal(septic_patients %>% count_S(AMC, GEN), 1660)
|
||||
expect_equal(septic_patients %>% count_all(AMC, GEN), 1798)
|
||||
expect_identical(septic_patients %>% count_all(AMC, GEN),
|
||||
septic_patients %>% count_S(AMC, GEN) +
|
||||
septic_patients %>% count_IR(AMC, GEN))
|
||||
|
||||
# count of cases
|
||||
expect_equal(septic_patients %>%
|
||||
group_by(hospital_id) %>%
|
||||
summarise(cipro = count_S(cipr),
|
||||
genta = count_S(gent),
|
||||
combination = count_S(cipr, gent)) %>%
|
||||
summarise(cipro = count_S(CIP),
|
||||
genta = count_S(GEN),
|
||||
combination = count_S(CIP, GEN)) %>%
|
||||
pull(combination),
|
||||
c(192, 446, 184, 474))
|
||||
|
||||
# count_df
|
||||
expect_equal(
|
||||
septic_patients %>% select(amox) %>% count_df() %>% pull(Value),
|
||||
c(septic_patients$amox %>% count_S(),
|
||||
septic_patients$amox %>% count_I(),
|
||||
septic_patients$amox %>% count_R())
|
||||
septic_patients %>% select(AMX) %>% count_df() %>% pull(Value),
|
||||
c(septic_patients$AMX %>% count_S(),
|
||||
septic_patients$AMX %>% count_I(),
|
||||
septic_patients$AMX %>% count_R())
|
||||
)
|
||||
expect_equal(
|
||||
septic_patients %>% select(amox) %>% count_df(combine_IR = TRUE) %>% pull(Value),
|
||||
c(septic_patients$amox %>% count_S(),
|
||||
septic_patients$amox %>% count_IR())
|
||||
septic_patients %>% select(AMX) %>% count_df(combine_IR = TRUE) %>% pull(Value),
|
||||
c(septic_patients$AMX %>% count_S(),
|
||||
septic_patients$AMX %>% count_IR())
|
||||
)
|
||||
|
||||
# warning for speed loss
|
||||
expect_warning(count_R(as.character(septic_patients$amcl)))
|
||||
expect_warning(count_I(as.character(septic_patients$amcl)))
|
||||
expect_warning(count_S(as.character(septic_patients$amcl,
|
||||
septic_patients$gent)))
|
||||
expect_warning(count_S(septic_patients$amcl,
|
||||
as.character(septic_patients$gent)))
|
||||
expect_warning(count_R(as.character(septic_patients$AMC)))
|
||||
expect_warning(count_I(as.character(septic_patients$AMC)))
|
||||
expect_warning(count_S(as.character(septic_patients$AMC,
|
||||
septic_patients$GEN)))
|
||||
expect_warning(count_S(septic_patients$AMC,
|
||||
as.character(septic_patients$GEN)))
|
||||
|
||||
# check for errors
|
||||
expect_error(count_IR("test", minimum = "test"))
|
||||
|
@ -23,7 +23,7 @@ context("data.R")
|
||||
|
||||
test_that("data sets are valid", {
|
||||
# IDs should always be unique
|
||||
expect_identical(nrow(antibiotics), length(unique(antibiotics$atc)))
|
||||
expect_identical(nrow(antibiotics), length(unique(antibiotics$ab)))
|
||||
expect_identical(nrow(microorganisms), length(unique(microorganisms$mo)))
|
||||
|
||||
# there should be no diacritics (i.e. non ASCII) characters in the datasets
|
||||
|
@ -30,15 +30,11 @@ test_that("deprecated functions work", {
|
||||
expect_identical(suppressWarnings(ratio(c(772, 1611, 737), ratio = "1:2:1")), c(780, 1560, 780))
|
||||
expect_identical(suppressWarnings(ratio(c(1752, 1895), ratio = c(1, 1))), c(1823.5, 1823.5))
|
||||
|
||||
expect_warning(ab_property("amox"))
|
||||
expect_warning(ab_atc("amox"))
|
||||
expect_warning(atc_property("amox"))
|
||||
expect_warning(atc_official("amox"))
|
||||
expect_warning(ab_official("amox"))
|
||||
expect_warning(ab_name("amox"))
|
||||
expect_warning(ab_trivial_nl("amox"))
|
||||
expect_warning(ab_certe("amox"))
|
||||
expect_warning(ab_umcg("amox"))
|
||||
expect_warning(ab_tradenames("amox"))
|
||||
expect_warning(atc_ddd("amox"))
|
||||
expect_warning(atc_groups("amox"))
|
||||
expect_warning(atc_name("amox"))
|
||||
expect_warning(atc_trivial_nl("amox"))
|
||||
expect_warning(atc_tradenames("amox"))
|
||||
|
||||
})
|
||||
|
@ -52,11 +52,11 @@ test_that("EUCAST rules work", {
|
||||
|
||||
a <- data.frame(mo = c("Staphylococcus aureus",
|
||||
"Streptococcus group A"),
|
||||
coli = "-", # Colistin
|
||||
COL = "-", # Colistin
|
||||
stringsAsFactors = FALSE)
|
||||
b <- data.frame(mo = c("Staphylococcus aureus",
|
||||
"Streptococcus group A"),
|
||||
coli = "R", # Colistin
|
||||
COL = "R", # Colistin
|
||||
stringsAsFactors = FALSE)
|
||||
expect_equal(suppressWarnings(eucast_rules(a, "mo", info = FALSE)), b)
|
||||
|
||||
@ -64,30 +64,30 @@ test_that("EUCAST rules work", {
|
||||
library(dplyr)
|
||||
expect_equal(suppressWarnings(
|
||||
septic_patients %>%
|
||||
mutate(tica = as.rsi("R"),
|
||||
pipe = as.rsi("S")) %>%
|
||||
mutate(TIC = as.rsi("R"),
|
||||
PIP = as.rsi("S")) %>%
|
||||
eucast_rules(col_mo = "mo") %>%
|
||||
left_join_microorganisms() %>%
|
||||
filter(family == "Enterobacteriaceae") %>%
|
||||
pull(pipe) %>%
|
||||
pull(PIP) %>%
|
||||
unique() %>%
|
||||
as.character()),
|
||||
"R")
|
||||
|
||||
# azit and clar must be equal to eryt
|
||||
# Azithromicin and Clarythromycin must be equal to Erythromycin
|
||||
a <- suppressWarnings(
|
||||
septic_patients %>%
|
||||
transmute(mo,
|
||||
eryt,
|
||||
azit = as.rsi("R"),
|
||||
clar = as.rsi("R")) %>%
|
||||
ERY,
|
||||
AZM = as.rsi("R"),
|
||||
CLR = as.rsi("R")) %>%
|
||||
eucast_rules(col_mo = "mo") %>%
|
||||
pull(clar))
|
||||
pull(CLR))
|
||||
b <- suppressWarnings(
|
||||
septic_patients %>%
|
||||
select(mo, eryt) %>%
|
||||
select(mo, ERY) %>%
|
||||
eucast_rules(col_mo = "mo") %>%
|
||||
pull(eryt))
|
||||
pull(ERY))
|
||||
|
||||
expect_identical(a[!is.na(b)],
|
||||
b[!is.na(b)])
|
||||
@ -97,15 +97,15 @@ test_that("EUCAST rules work", {
|
||||
suppressWarnings(
|
||||
as.list(eucast_rules(
|
||||
data.frame(mo = as.mo("Kingella kingae"),
|
||||
peni = "S",
|
||||
amox = "-",
|
||||
PEN = "S",
|
||||
AMX = "-",
|
||||
stringsAsFactors = FALSE)
|
||||
, info = FALSE))$amox
|
||||
, info = FALSE))$AMX
|
||||
),
|
||||
"S")
|
||||
|
||||
# also test norf
|
||||
expect_output(suppressWarnings(eucast_rules(septic_patients %>% mutate(norf = "S", nali = "S"))))
|
||||
expect_output(suppressWarnings(eucast_rules(septic_patients %>% mutate(NOR = "S", NAL = "S"))))
|
||||
|
||||
# check verbose output
|
||||
expect_output(suppressWarnings(eucast_rules(septic_patients, verbose = TRUE)))
|
||||
|
@ -51,7 +51,7 @@ test_that("frequency table works", {
|
||||
# mo
|
||||
expect_output(print(freq(septic_patients$mo)))
|
||||
# rsi
|
||||
expect_output(print(freq(septic_patients$amox)))
|
||||
expect_output(print(freq(septic_patients$AMX)))
|
||||
# integer
|
||||
expect_output(print(freq(septic_patients$age)))
|
||||
# date
|
||||
@ -61,7 +61,7 @@ test_that("frequency table works", {
|
||||
# table
|
||||
expect_output(print(freq(table(septic_patients$gender, septic_patients$age))))
|
||||
# rsi
|
||||
expect_output(print(freq(septic_patients$amcl)))
|
||||
expect_output(print(freq(septic_patients$AMC)))
|
||||
# hms
|
||||
expect_output(suppressWarnings(print(freq(hms::as.hms(sample(c(0:86399), 50))))))
|
||||
# matrix
|
||||
@ -89,8 +89,8 @@ test_that("frequency table works", {
|
||||
|
||||
# grouping variable
|
||||
expect_output(print(septic_patients %>% group_by(gender) %>% freq(hospital_id)))
|
||||
expect_output(print(septic_patients %>% group_by(gender) %>% freq(amox, quote = TRUE)))
|
||||
expect_output(print(septic_patients %>% group_by(gender) %>% freq(amox, markdown = TRUE)))
|
||||
expect_output(print(septic_patients %>% group_by(gender) %>% freq(AMX, quote = TRUE)))
|
||||
expect_output(print(septic_patients %>% group_by(gender) %>% freq(AMX, markdown = TRUE)))
|
||||
|
||||
# quasiquotation
|
||||
expect_output(print(septic_patients %>% freq(mo_genus(mo))))
|
||||
@ -152,7 +152,7 @@ test_that("frequency table works", {
|
||||
|
||||
expect_error(septic_patients %>% freq(nonexisting))
|
||||
expect_error(septic_patients %>% select(1:10) %>% freq())
|
||||
expect_error(septic_patients %>% freq(peni, oxac, clox, amox, amcl,
|
||||
expect_error(septic_patients %>% freq(peni, oxac, clox, AMX, AMC,
|
||||
ampi, pita, czol, cfep, cfur))
|
||||
|
||||
# (un)select columns
|
||||
@ -163,15 +163,15 @@ test_that("frequency table works", {
|
||||
|
||||
# run diff
|
||||
expect_output(print(
|
||||
diff(freq(septic_patients$amcl),
|
||||
freq(septic_patients$amox))
|
||||
diff(freq(septic_patients$AMC),
|
||||
freq(septic_patients$AMX))
|
||||
))
|
||||
expect_output(print(
|
||||
diff(freq(septic_patients$age),
|
||||
freq(septic_patients$age)) # "No differences found."
|
||||
))
|
||||
expect_error(print(
|
||||
diff(freq(septic_patients$amcl),
|
||||
diff(freq(septic_patients$AMX),
|
||||
"Just a string") # not a freq tbl
|
||||
))
|
||||
|
||||
|
@ -30,36 +30,36 @@ test_that("ggplot_rsi works", {
|
||||
|
||||
# data should be equal
|
||||
expect_equal(
|
||||
(septic_patients %>% select(amcl, cipr) %>% ggplot_rsi())$data %>%
|
||||
(septic_patients %>% select(AMC, CIP) %>% ggplot_rsi())$data %>%
|
||||
summarise_all(portion_IR) %>% as.double(),
|
||||
septic_patients %>% select(amcl, cipr) %>%
|
||||
septic_patients %>% select(AMC, CIP) %>%
|
||||
summarise_all(portion_IR) %>% as.double()
|
||||
)
|
||||
|
||||
expect_equal(
|
||||
(septic_patients %>% select(amcl, cipr) %>% ggplot_rsi(x = "Interpretation", facet = "Antibiotic"))$data %>%
|
||||
(septic_patients %>% select(AMC, CIP) %>% ggplot_rsi(x = "Interpretation", facet = "Antibiotic"))$data %>%
|
||||
summarise_all(portion_IR) %>% as.double(),
|
||||
septic_patients %>% select(amcl, cipr) %>%
|
||||
septic_patients %>% select(AMC, CIP) %>%
|
||||
summarise_all(portion_IR) %>% as.double()
|
||||
)
|
||||
|
||||
expect_equal(
|
||||
(septic_patients %>% select(amcl, cipr) %>% ggplot_rsi(x = "Antibiotic", facet = "Interpretation"))$data %>%
|
||||
(septic_patients %>% select(AMC, CIP) %>% ggplot_rsi(x = "Antibiotic", facet = "Interpretation"))$data %>%
|
||||
summarise_all(portion_IR) %>% as.double(),
|
||||
septic_patients %>% select(amcl, cipr) %>%
|
||||
septic_patients %>% select(AMC, CIP) %>%
|
||||
summarise_all(portion_IR) %>% as.double()
|
||||
)
|
||||
|
||||
expect_equal(
|
||||
(septic_patients %>% select(amcl, cipr) %>% ggplot_rsi(x = "Antibiotic",
|
||||
(septic_patients %>% select(AMC, CIP) %>% ggplot_rsi(x = "Antibiotic",
|
||||
facet = "Interpretation",
|
||||
fun = count_df))$data %>%
|
||||
summarise_all(count_IR) %>% as.double(),
|
||||
septic_patients %>% select(amcl, cipr) %>%
|
||||
septic_patients %>% select(AMC, CIP) %>%
|
||||
summarise_all(count_IR) %>% as.double()
|
||||
)
|
||||
|
||||
expect_equal(colnames(getlbls(septic_patients %>% select(amcl, cipr))),
|
||||
expect_equal(colnames(getlbls(septic_patients %>% select(AMC, CIP))),
|
||||
c("Interpretation", "Antibiotic", "Value", "lbl"))
|
||||
|
||||
expect_error(ggplot_rsi(septic_patients, fun = "invalid"))
|
||||
|
@ -24,15 +24,15 @@ context("guess_ab_col.R")
|
||||
test_that("guess_ab_col works", {
|
||||
|
||||
expect_equal(guess_ab_col(septic_patients, "amox"),
|
||||
"amox")
|
||||
"AMX")
|
||||
expect_equal(guess_ab_col(septic_patients, "amoxicillin"),
|
||||
"amox")
|
||||
"AMX")
|
||||
expect_equal(guess_ab_col(septic_patients, "J01AA07"),
|
||||
"tetr")
|
||||
"TCY")
|
||||
expect_equal(guess_ab_col(septic_patients, "tetracycline"),
|
||||
"tetr")
|
||||
"TCY")
|
||||
expect_equal(guess_ab_col(septic_patients, "TETR"),
|
||||
"tetr")
|
||||
"TCY")
|
||||
|
||||
df <- data.frame(AMP_ND10 = "R",
|
||||
AMC_ED20 = "S")
|
||||
|
@ -22,40 +22,33 @@
|
||||
context("portion.R")
|
||||
|
||||
test_that("portions works", {
|
||||
# amox resistance in `septic_patients`
|
||||
expect_equal(portion_R(septic_patients$amox), 0.5557364, tolerance = 0.0001)
|
||||
expect_equal(portion_I(septic_patients$amox), 0.002441009, tolerance = 0.0001)
|
||||
expect_equal(1 - portion_R(septic_patients$amox) - portion_I(septic_patients$amox),
|
||||
portion_S(septic_patients$amox))
|
||||
expect_equal(portion_R(septic_patients$amox) + portion_I(septic_patients$amox),
|
||||
portion_IR(septic_patients$amox))
|
||||
expect_equal(portion_S(septic_patients$amox) + portion_I(septic_patients$amox),
|
||||
portion_SI(septic_patients$amox))
|
||||
# AMX resistance in `septic_patients`
|
||||
expect_equal(portion_R(septic_patients$AMX), 0.5557364, tolerance = 0.0001)
|
||||
expect_equal(portion_I(septic_patients$AMX), 0.002441009, tolerance = 0.0001)
|
||||
expect_equal(1 - portion_R(septic_patients$AMX) - portion_I(septic_patients$AMX),
|
||||
portion_S(septic_patients$AMX))
|
||||
expect_equal(portion_R(septic_patients$AMX) + portion_I(septic_patients$AMX),
|
||||
portion_IR(septic_patients$AMX))
|
||||
expect_equal(portion_S(septic_patients$AMX) + portion_I(septic_patients$AMX),
|
||||
portion_SI(septic_patients$AMX))
|
||||
|
||||
expect_equal(septic_patients %>% portion_S(amcl),
|
||||
expect_equal(septic_patients %>% portion_S(AMC),
|
||||
0.7142097,
|
||||
tolerance = 0.0001)
|
||||
expect_equal(septic_patients %>% portion_S(amcl, gent),
|
||||
expect_equal(septic_patients %>% portion_S(AMC, GEN),
|
||||
0.9232481,
|
||||
tolerance = 0.0001)
|
||||
expect_equal(septic_patients %>% portion_S(amcl, gent, also_single_tested = TRUE),
|
||||
expect_equal(septic_patients %>% portion_S(AMC, GEN, also_single_tested = TRUE),
|
||||
0.926045,
|
||||
tolerance = 0.0001)
|
||||
|
||||
# amcl+genta susceptibility around 92.3%
|
||||
expect_equal(suppressWarnings(rsi(septic_patients$amcl,
|
||||
septic_patients$gent,
|
||||
interpretation = "S")),
|
||||
0.9232481,
|
||||
tolerance = 0.000001)
|
||||
|
||||
# percentages
|
||||
expect_equal(septic_patients %>%
|
||||
group_by(hospital_id) %>%
|
||||
summarise(R = portion_R(cipr, as_percent = TRUE),
|
||||
I = portion_I(cipr, as_percent = TRUE),
|
||||
S = portion_S(cipr, as_percent = TRUE),
|
||||
n = n_rsi(cipr),
|
||||
summarise(R = portion_R(CIP, as_percent = TRUE),
|
||||
I = portion_I(CIP, as_percent = TRUE),
|
||||
S = portion_S(CIP, as_percent = TRUE),
|
||||
n = n_rsi(CIP),
|
||||
total = n()) %>%
|
||||
pull(n) %>%
|
||||
sum(),
|
||||
@ -64,23 +57,23 @@ test_that("portions works", {
|
||||
# count of cases
|
||||
expect_equal(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)) %>%
|
||||
summarise(CIPo_p = portion_S(CIP, as_percent = TRUE),
|
||||
CIPo_n = n_rsi(CIP),
|
||||
GENa_p = portion_S(GEN, as_percent = TRUE),
|
||||
GENa_n = n_rsi(GEN),
|
||||
combination_p = portion_S(CIP, GEN, as_percent = TRUE),
|
||||
combination_n = n_rsi(CIP, GEN)) %>%
|
||||
pull(combination_n),
|
||||
c(202, 488, 201, 499))
|
||||
|
||||
expect_warning(portion_R(as.character(septic_patients$amcl)))
|
||||
expect_warning(portion_S(as.character(septic_patients$amcl)))
|
||||
expect_warning(portion_S(as.character(septic_patients$amcl,
|
||||
septic_patients$gent)))
|
||||
expect_warning(n_rsi(as.character(septic_patients$amcl,
|
||||
septic_patients$gent)))
|
||||
expect_equal(suppressWarnings(n_rsi(as.character(septic_patients$amcl,
|
||||
septic_patients$gent))),
|
||||
expect_warning(portion_R(as.character(septic_patients$AMC)))
|
||||
expect_warning(portion_S(as.character(septic_patients$AMC)))
|
||||
expect_warning(portion_S(as.character(septic_patients$AMC,
|
||||
septic_patients$GEN)))
|
||||
expect_warning(n_rsi(as.character(septic_patients$AMC,
|
||||
septic_patients$GEN)))
|
||||
expect_equal(suppressWarnings(n_rsi(as.character(septic_patients$AMC,
|
||||
septic_patients$GEN))),
|
||||
1879)
|
||||
|
||||
# check for errors
|
||||
@ -93,59 +86,29 @@ test_that("portions works", {
|
||||
expect_error(portion_S("test", also_single_tested = "test"))
|
||||
|
||||
# check too low amount of isolates
|
||||
expect_identical(suppressWarnings(portion_R(septic_patients$amox, minimum = nrow(septic_patients) + 1)),
|
||||
expect_identical(suppressWarnings(portion_R(septic_patients$AMX, minimum = nrow(septic_patients) + 1)),
|
||||
NA)
|
||||
expect_identical(suppressWarnings(portion_I(septic_patients$amox, minimum = nrow(septic_patients) + 1)),
|
||||
expect_identical(suppressWarnings(portion_I(septic_patients$AMX, minimum = nrow(septic_patients) + 1)),
|
||||
NA)
|
||||
expect_identical(suppressWarnings(portion_S(septic_patients$amox, minimum = nrow(septic_patients) + 1)),
|
||||
expect_identical(suppressWarnings(portion_S(septic_patients$AMX, minimum = nrow(septic_patients) + 1)),
|
||||
NA)
|
||||
|
||||
# warning for speed loss
|
||||
expect_warning(portion_R(as.character(septic_patients$gent)))
|
||||
expect_warning(portion_I(as.character(septic_patients$gent)))
|
||||
expect_warning(portion_S(septic_patients$amcl, as.character(septic_patients$gent)))
|
||||
|
||||
})
|
||||
|
||||
test_that("old rsi works", {
|
||||
# amox resistance in `septic_patients` should be around 58.53%
|
||||
expect_equal(suppressWarnings(rsi(septic_patients$amox)), 0.5581774, tolerance = 0.0001)
|
||||
expect_equal(suppressWarnings(rsi(septic_patients$amox, interpretation = "S")), 1 - 0.5581774, tolerance = 0.0001)
|
||||
|
||||
# pita+genta susceptibility around 95.3%
|
||||
expect_equal(suppressWarnings(rsi(septic_patients$pita,
|
||||
septic_patients$gent,
|
||||
interpretation = "S",
|
||||
info = TRUE)),
|
||||
0.9526814,
|
||||
tolerance = 0.0001)
|
||||
|
||||
# count of cases
|
||||
expect_equal(septic_patients %>%
|
||||
group_by(hospital_id) %>%
|
||||
summarise(cipro_S = suppressWarnings(rsi(cipr, interpretation = "S",
|
||||
as_percent = TRUE, warning = FALSE)),
|
||||
cipro_n = n_rsi(cipr),
|
||||
genta_S = suppressWarnings(rsi(gent, interpretation = "S",
|
||||
as_percent = TRUE, warning = FALSE)),
|
||||
genta_n = n_rsi(gent),
|
||||
combination_S = suppressWarnings(rsi(cipr, gent, interpretation = "S",
|
||||
as_percent = TRUE, warning = FALSE)),
|
||||
combination_n = n_rsi(cipr, gent)) %>%
|
||||
pull(combination_n),
|
||||
c(202, 488, 201, 499))
|
||||
expect_warning(portion_R(as.character(septic_patients$GEN)))
|
||||
expect_warning(portion_I(as.character(septic_patients$GEN)))
|
||||
expect_warning(portion_S(septic_patients$AMC, as.character(septic_patients$GEN)))
|
||||
|
||||
# portion_df
|
||||
expect_equal(
|
||||
septic_patients %>% select(amox) %>% portion_df() %>% pull(Value),
|
||||
c(septic_patients$amox %>% portion_S(),
|
||||
septic_patients$amox %>% portion_I(),
|
||||
septic_patients$amox %>% portion_R())
|
||||
septic_patients %>% select(AMX) %>% portion_df() %>% pull(Value),
|
||||
c(septic_patients$AMX %>% portion_S(),
|
||||
septic_patients$AMX %>% portion_I(),
|
||||
septic_patients$AMX %>% portion_R())
|
||||
)
|
||||
expect_equal(
|
||||
septic_patients %>% select(amox) %>% portion_df(combine_IR = TRUE) %>% pull(Value),
|
||||
c(septic_patients$amox %>% portion_S(),
|
||||
septic_patients$amox %>% portion_IR())
|
||||
septic_patients %>% select(AMX) %>% portion_df(combine_IR = TRUE) %>% pull(Value),
|
||||
c(septic_patients$AMX %>% portion_S(),
|
||||
septic_patients$AMX %>% portion_IR())
|
||||
)
|
||||
|
||||
|
||||
|
@ -22,17 +22,17 @@
|
||||
context("portion.R")
|
||||
|
||||
test_that("prediction of rsi works", {
|
||||
amox_R <- septic_patients %>%
|
||||
AMX_R <- septic_patients %>%
|
||||
filter(mo == "B_ESCHR_COL") %>%
|
||||
rsi_predict(col_ab = "amox",
|
||||
rsi_predict(col_ab = "AMX",
|
||||
col_date = "date",
|
||||
minimum = 10,
|
||||
info = TRUE) %>%
|
||||
pull("value")
|
||||
# amox resistance will increase according to data set `septic_patients`
|
||||
expect_true(amox_R[3] < amox_R[20])
|
||||
# AMX resistance will increase according to data set `septic_patients`
|
||||
expect_true(AMX_R[3] < AMX_R[20])
|
||||
|
||||
x <- resistance_predict(septic_patients, col_ab = "amox", year_min = 2010)
|
||||
x <- resistance_predict(septic_patients, col_ab = "AMX", year_min = 2010)
|
||||
plot(x)
|
||||
ggplot_rsi_predict(x)
|
||||
expect_error(ggplot_rsi_predict(septic_patients))
|
||||
@ -41,23 +41,23 @@ test_that("prediction of rsi works", {
|
||||
|
||||
expect_output(rsi_predict(tbl = filter(septic_patients, mo == "B_ESCHR_COL"),
|
||||
model = "binomial",
|
||||
col_ab = "amox",
|
||||
col_ab = "AMX",
|
||||
col_date = "date",
|
||||
info = TRUE))
|
||||
expect_output(rsi_predict(tbl = filter(septic_patients, mo == "B_ESCHR_COL"),
|
||||
model = "loglin",
|
||||
col_ab = "amox",
|
||||
col_ab = "AMX",
|
||||
col_date = "date",
|
||||
info = TRUE))
|
||||
expect_output(rsi_predict(tbl = filter(septic_patients, mo == "B_ESCHR_COL"),
|
||||
model = "lin",
|
||||
col_ab = "amox",
|
||||
col_ab = "AMX",
|
||||
col_date = "date",
|
||||
info = TRUE))
|
||||
|
||||
expect_error(rsi_predict(tbl = filter(septic_patients, mo == "B_ESCHR_COL"),
|
||||
model = "INVALID MODEL",
|
||||
col_ab = "amox",
|
||||
col_ab = "AMX",
|
||||
col_date = "date",
|
||||
info = TRUE))
|
||||
expect_error(rsi_predict(tbl = filter(septic_patients, mo == "B_ESCHR_COL"),
|
||||
@ -65,12 +65,12 @@ test_that("prediction of rsi works", {
|
||||
col_date = "date",
|
||||
info = TRUE))
|
||||
expect_error(rsi_predict(tbl = filter(septic_patients, mo == "B_ESCHR_COL"),
|
||||
col_ab = "amox",
|
||||
col_ab = "AMX",
|
||||
col_date = "NOT EXISTING COLUMN",
|
||||
info = TRUE))
|
||||
# almost all E. coli are mero S in the Netherlands :)
|
||||
# almost all E. coli are MEM S in the Netherlands :)
|
||||
expect_error(resistance_predict(tbl = filter(septic_patients, mo == "B_ESCHR_COL"),
|
||||
col_ab = "mero",
|
||||
col_ab = "MEM",
|
||||
col_date = "date",
|
||||
info = TRUE))
|
||||
|
||||
|
@ -47,7 +47,7 @@ test_that("rsi works", {
|
||||
library(dplyr)
|
||||
# 40 rsi columns
|
||||
expect_equal(septic_patients %>%
|
||||
mutate_at(vars(peni:rifa), as.character) %>%
|
||||
mutate_at(vars(PEN:RIF), as.character) %>%
|
||||
lapply(is.rsi.eligible) %>%
|
||||
as.logical() %>%
|
||||
sum(),
|
||||
|
Reference in New Issue
Block a user