1
0
mirror of https://github.com/msberends/AMR.git synced 2025-07-09 17:41:59 +02:00

first inclusion of ITIS data

This commit is contained in:
2018-09-24 23:33:29 +02:00
parent df5d82fff3
commit 9c566585b0
29 changed files with 734 additions and 466 deletions

View File

@ -2,16 +2,16 @@ context("count.R")
test_that("counts work", {
# amox resistance in `septic_patients`
expect_equal(count_R(septic_patients$amox), 659)
expect_equal(count_R(septic_patients$amox), 662)
expect_equal(count_I(septic_patients$amox), 3)
expect_equal(count_S(septic_patients$amox), 336)
expect_equal(count_S(septic_patients$amox), 335)
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))
expect_equal(septic_patients %>% count_S(amcl), 1056)
expect_equal(septic_patients %>% count_S(amcl, gent), 1385)
expect_equal(septic_patients %>% count_S(amcl), 1057)
expect_equal(septic_patients %>% count_S(amcl, gent), 1396)
# count of cases
expect_equal(septic_patients %>%
@ -20,7 +20,7 @@ test_that("counts work", {
genta = count_S(gent),
combination = count_S(cipr, gent)) %>%
pull(combination),
c(192, 440, 184, 474))
c(192, 446, 184, 474))
expect_equal(septic_patients %>% select(amox, cipr) %>% count_df(translate_ab = "official") %>% nrow(),
6)

View File

@ -10,9 +10,9 @@ test_that("first isolates work", {
col_mo = "mo",
info = TRUE),
na.rm = TRUE),
1330)
1315)
# septic_patients contains 1426 out of 2000 first *weighted* isolates
# septic_patients contains 1411 out of 2000 first *weighted* isolates
expect_equal(
suppressWarnings(
sum(
@ -24,8 +24,8 @@ test_that("first isolates work", {
type = "keyantibiotics",
info = TRUE),
na.rm = TRUE)),
1425)
# and 1449 when not ignoring I
1411)
# and 1435 when not ignoring I
expect_equal(
suppressWarnings(
sum(
@ -38,8 +38,8 @@ test_that("first isolates work", {
type = "keyantibiotics",
info = TRUE),
na.rm = TRUE)),
1448)
# and 1430 when using points
1435)
# and 1416 when using points
expect_equal(
suppressWarnings(
sum(
@ -51,9 +51,9 @@ test_that("first isolates work", {
type = "points",
info = TRUE),
na.rm = TRUE)),
1430)
1416)
# septic_patients contains 1176 out of 2000 first non-ICU isolates
# septic_patients contains 1161 out of 2000 first non-ICU isolates
expect_equal(
sum(
first_isolate(septic_patients,
@ -64,7 +64,7 @@ test_that("first isolates work", {
info = TRUE,
icu_exclude = TRUE),
na.rm = TRUE),
1175)
1161)
# set 1500 random observations to be of specimen type 'Urine'
random_rows <- sample(x = 1:2000, size = 1500, replace = FALSE)

View File

@ -6,8 +6,8 @@ test_that("frequency table works", {
expect_equal(nrow(freq(c(1, 1, 2, 2, 3, 3, 4, 4, 5, 5))), 5)
expect_equal(nrow(frequency_tbl(c(1, 1, 2, 2, 3, 3, 4, 4, 5, 5))), 5)
# date column of septic_patients should contain 1151 unique dates
expect_equal(nrow(freq(septic_patients$date)), 1151)
# date column of septic_patients should contain 1140 unique dates
expect_equal(nrow(freq(septic_patients$date)), 1140)
expect_equal(nrow(freq(septic_patients$date)),
length(unique(septic_patients$date)))
@ -24,7 +24,7 @@ test_that("frequency table works", {
# character
expect_output(print(freq(septic_patients$mo)))
expect_output(print(freq(microorganisms$fullname)))
expect_output(suppressWarnings(print(freq(microorganisms$fullname))))
# integer
expect_output(print(freq(septic_patients$age)))
# date

View File

@ -24,17 +24,17 @@ test_that("joins work", {
expect_true(nrow(unjoined) < nrow(full))
expect_equal(nrow(inner_join_microorganisms("ESCCOL")), 1)
expect_equal(nrow(inner_join_microorganisms("ESCCOL", by = c("mo" = "mo"))), 1)
expect_equal(nrow(inner_join_microorganisms("B_ESCHR_COL")), 1)
expect_equal(nrow(inner_join_microorganisms("B_ESCHR_COL", by = c("mo" = "mo"))), 1)
expect_warning(inner_join_microorganisms("Escherichia", by = c("mo" = "genus")))
expect_equal(nrow(left_join_microorganisms("ESCCOL")), 1)
expect_equal(nrow(left_join_microorganisms("B_ESCHR_COL")), 1)
expect_warning(left_join_microorganisms("Escherichia", by = c("mo" = "genus")))
expect_equal(nrow(semi_join_microorganisms("ESCCOL")), 1)
expect_equal(nrow(anti_join_microorganisms("ESCCOL")), 0)
expect_equal(nrow(semi_join_microorganisms("B_ESCHR_COL")), 1)
expect_equal(nrow(anti_join_microorganisms("B_ESCHR_COL")), 0)
expect_warning(right_join_microorganisms("ESCCOL"))
expect_warning(full_join_microorganisms("ESCCOL"))
expect_warning(right_join_microorganisms("B_ESCHR_COL"))
expect_warning(full_join_microorganisms("B_ESCHR_COL"))
})

View File

@ -2,6 +2,7 @@ context("key_antibiotics.R")
test_that("keyantibiotics work", {
expect_equal(length(key_antibiotics(septic_patients, warnings = FALSE)), nrow(septic_patients))
expect_false(all(is.na(key_antibiotics(septic_patients))))
expect_true(key_antibiotics_equal("SSS", "SSS"))
expect_false(key_antibiotics_equal("SSS", "SRS"))
expect_true(key_antibiotics_equal("SSS", "SIS", ignore_I = TRUE))

View File

@ -2,12 +2,12 @@ context("kurtosis.R")
test_that("kurtosis works", {
expect_equal(kurtosis(septic_patients$age),
3.57781,
3.549319,
tolerance = 0.00001)
expect_equal(unname(kurtosis(data.frame(septic_patients$age))),
3.57781,
3.549319,
tolerance = 0.00001)
expect_equal(kurtosis(matrix(septic_patients$age)),
3.57781,
3.549319,
tolerance = 0.00001)
})

View File

@ -8,50 +8,50 @@ test_that("as.mo works", {
expect_identical(
as.character(as.mo(c("E. coli", "H. influenzae"))),
c("ESCCOL", "HAEINF"))
c("B_ESCHR_COL", "B_HMPHL_INF"))
expect_equal(as.character(as.mo("Escherichia coli")), "ESCCOL")
expect_equal(as.character(as.mo("Escherichia coli")), "ESCCOL")
expect_equal(as.character(as.mo("Escherichia species")), "ESCSPP")
expect_equal(as.character(as.mo("Escherichia")), "ESCSPP")
expect_equal(as.character(as.mo(" ESCCOL ")), "ESCCOL")
expect_equal(as.character(as.mo("coli")), "ESCCOL") # not Campylobacter
expect_equal(as.character(as.mo("klpn")), "KLEPNE")
expect_equal(as.character(as.mo("Klebsiella")), "KLESPP")
expect_equal(as.character(as.mo("K. pneu rhino")), "KLEPNERH") # K. pneumoniae subspp. rhinoscleromatis
expect_equal(as.character(as.mo("Bartonella")), "BARSPP")
expect_equal(as.character(as.mo("C. difficile")), "CLODIF")
expect_equal(as.character(as.mo("L. pneumophila")), "LEGPNE")
expect_equal(as.character(as.mo("L. non pneumophila")), "LEGNON")
expect_equal(as.character(as.mo("S. beta-haemolytic")), "STCHAE")
expect_equal(as.character(as.mo("Strepto")), "STCSPP")
expect_equal(as.character(as.mo("Streptococcus")), "STCSPP") # not Peptostreptoccus
expect_equal(as.character(as.mo("Escherichia coli")), "B_ESCHR_COL")
expect_equal(as.character(as.mo("Escherichia coli")), "B_ESCHR_COL")
expect_equal(as.character(as.mo("Escherichia species")), "B_ESCHR")
expect_equal(as.character(as.mo("Escherichia")), "B_ESCHR")
expect_equal(as.character(as.mo(" B_ESCHR_COL ")), "B_ESCHR_COL")
#expect_equal(as.character(as.mo("coli")), "B_ESCHR_COL") # not Campylobacter
expect_equal(as.character(as.mo("klpn")), "B_KLBSL_PNE")
expect_equal(as.character(as.mo("Klebsiella")), "B_KLBSL")
expect_equal(as.character(as.mo("K. pneu rhino")), "B_KLBSL_PNE_RHI") # K. pneumoniae subspp. rhinoscleromatis
expect_equal(as.character(as.mo("Bartonella")), "B_BRTNL")
expect_equal(as.character(as.mo("C. difficile")), "B_CTRDM_DIF")
expect_equal(as.character(as.mo("L. pneumophila")), "B_LGNLL_PNE")
# expect_equal(as.character(as.mo("L. non pneumophila")), "LEGNON")
# expect_equal(as.character(as.mo("S. beta-haemolytic")), "STCHAE")
expect_equal(as.character(as.mo("Strepto")), "B_STRPTC")
expect_equal(as.character(as.mo("Streptococcus")), "B_STRPTC") # not Peptostreptoccus
expect_equal(as.character(as.mo(c("GAS", "GBS"))), c("STCGRA", "STCGRB"))
expect_equal(as.character(as.mo(c("GAS", "GBS"))), c("B_STRPTC_GRA", "B_STRPTC_GRB"))
expect_equal(as.character(as.mo("S. pyo")), "STCPYO") # not Actinomyces pyogenes
expect_equal(as.character(as.mo("S. pyo")), "B_STRPTC_PYO") # not Actinomyces pyogenes
expect_equal(as.character(as.mo("P. aer")), "PSEAER") # not Pasteurella aerogenes
expect_equal(as.character(as.mo("P. aer")), "B_PDMNS_AER") # not Pasteurella aerogenes
expect_equal(as.character(as.mo("Negative rods")), "GNR")
expect_equal(as.character(as.mo("Gram negative rods")), "GNR")
# expect_equal(as.character(as.mo("Negative rods")), "GNR")
# expect_equal(as.character(as.mo("Gram negative rods")), "GNR")
# GLIMS
expect_equal(as.character(as.mo("bctfgr")), "BACFRA")
expect_equal(as.character(as.mo("bctfgr")), "B_BCTRD_FRA")
expect_equal(as.character(as.mo("MRSE")), "STAEPI")
expect_equal(as.character(as.mo("VRE")), "ENCSPP")
expect_equal(as.character(as.mo("MRPA")), "PSEAER")
expect_equal(as.character(as.mo("PISP")), "STCPNE")
expect_equal(as.character(as.mo("PRSP")), "STCPNE")
expect_equal(as.character(as.mo("VISP")), "STCPNE")
expect_equal(as.character(as.mo("VRSP")), "STCPNE")
expect_equal(as.character(as.mo("MRSE")), "B_STPHY_EPI")
expect_equal(as.character(as.mo("VRE")), "B_ENTRC")
expect_equal(as.character(as.mo("MRPA")), "B_PDMNS_AER")
expect_equal(as.character(as.mo("PISP")), "B_STRPTC_PNE")
expect_equal(as.character(as.mo("PRSP")), "B_STRPTC_PNE")
expect_equal(as.character(as.mo("VISP")), "B_STRPTC_PNE")
expect_equal(as.character(as.mo("VRSP")), "B_STRPTC_PNE")
expect_equal(as.character(as.mo("CNS")), "STACNS")
expect_equal(as.character(as.mo("CoNS")), "STACNS")
expect_equal(as.character(as.mo("CPS")), "STACPS")
expect_equal(as.character(as.mo("CoPS")), "STACPS")
expect_equal(as.character(as.mo("CNS")), "B_STPHY_CNS")
expect_equal(as.character(as.mo("CoNS")), "B_STPHY_CNS")
expect_equal(as.character(as.mo("CPS")), "B_STPHY_CPS")
expect_equal(as.character(as.mo("CoPS")), "B_STPHY_CPS")
expect_identical(
as.character(
@ -63,39 +63,39 @@ test_that("as.mo works", {
"Staphylococcus aureus",
"MRSA",
"VISA"))),
rep("STAAUR", 8))
rep("B_STPHY_AUR", 8))
# check for Becker classification
expect_identical(as.character(guess_mo("S. epidermidis", Becker = FALSE)), "STAEPI")
expect_identical(as.character(guess_mo("S. epidermidis", Becker = TRUE)), "STACNS")
expect_identical(as.character(guess_mo("STAEPI", Becker = TRUE)), "STACNS")
expect_identical(as.character(guess_mo("S. intermedius", Becker = FALSE)), "STCINT") # Strep (!) intermedius
expect_identical(as.character(guess_mo("Sta intermedius",Becker = FALSE)), "STAINT")
expect_identical(as.character(guess_mo("Sta intermedius",Becker = TRUE)), "STACPS")
expect_identical(as.character(guess_mo("STAINT", Becker = TRUE)), "STACPS")
expect_identical(as.character(guess_mo("S. epidermidis", Becker = FALSE)), "B_STPHY_EPI")
expect_identical(as.character(guess_mo("S. epidermidis", Becker = TRUE)), "B_STPHY_CNS")
expect_identical(as.character(guess_mo("STAEPI", Becker = TRUE)), "B_STPHY_CNS")
expect_identical(as.character(guess_mo("S. intermedius", Becker = FALSE)), "B_STRPTC_INT") # Strep (!) intermedius
expect_identical(as.character(guess_mo("Sta intermedius",Becker = FALSE)), "B_STPHY_INT")
expect_identical(as.character(guess_mo("Sta intermedius",Becker = TRUE)), "B_STPHY_CPS")
expect_identical(as.character(guess_mo("STAINT", Becker = TRUE)), "B_STPHY_CPS")
# aureus must only be influenced if Becker = "all"
expect_identical(as.character(guess_mo("STAAUR", Becker = FALSE)), "STAAUR")
expect_identical(as.character(guess_mo("STAAUR", Becker = TRUE)), "STAAUR")
expect_identical(as.character(guess_mo("STAAUR", Becker = "all")), "STACPS")
expect_identical(as.character(guess_mo("STAAUR", Becker = FALSE)), "B_STPHY_AUR")
expect_identical(as.character(guess_mo("STAAUR", Becker = TRUE)), "B_STPHY_AUR")
expect_identical(as.character(guess_mo("STAAUR", Becker = "all")), "B_STPHY_CPS")
# check for Lancefield classification
expect_identical(as.character(guess_mo("S. pyogenes", Lancefield = FALSE)), "STCPYO")
expect_identical(as.character(guess_mo("S. pyogenes", Lancefield = TRUE)), "STCGRA")
expect_identical(as.character(guess_mo("STCPYO", Lancefield = TRUE)), "STCGRA") # group A
expect_identical(as.character(guess_mo("S. agalactiae", Lancefield = FALSE)), "STCAGA")
expect_identical(as.character(guess_mo("S. agalactiae", Lancefield = TRUE)), "STCGRB") # group B
expect_identical(as.character(guess_mo("S. equisimilis", Lancefield = FALSE)), "STCEQS")
expect_identical(as.character(guess_mo("S. equisimilis", Lancefield = TRUE)), "STCGRC") # group C
expect_identical(as.character(guess_mo("S. pyogenes", Lancefield = FALSE)), "B_STRPTC_PYO")
expect_identical(as.character(guess_mo("S. pyogenes", Lancefield = TRUE)), "B_STRPTC_GRA")
expect_identical(as.character(guess_mo("STCPYO", Lancefield = TRUE)), "B_STRPTC_GRA") # group A
expect_identical(as.character(guess_mo("S. agalactiae", Lancefield = FALSE)), "B_STRPTC_AGA")
expect_identical(as.character(guess_mo("S. agalactiae", Lancefield = TRUE)), "B_STRPTC_GRB") # group B
expect_identical(as.character(guess_mo("S. equisimilis", Lancefield = FALSE)), "B_STRPTC_DYS_EQU")
expect_identical(as.character(guess_mo("S. equisimilis", Lancefield = TRUE)), "B_STRPTC_GRC") # group C
# Enterococci must only be influenced if Lancefield = "all"
expect_identical(as.character(guess_mo("E. faecium", Lancefield = FALSE)), "ENCFAC")
expect_identical(as.character(guess_mo("E. faecium", Lancefield = TRUE)), "ENCFAC")
expect_identical(as.character(guess_mo("E. faecium", Lancefield = "all")), "STCGRD") # group D
expect_identical(as.character(guess_mo("S. anginosus", Lancefield = FALSE)), "STCANG")
expect_identical(as.character(guess_mo("S. anginosus", Lancefield = TRUE)), "STCGRF") # group F
expect_identical(as.character(guess_mo("S. sanguis", Lancefield = FALSE)), "STCSAN")
expect_identical(as.character(guess_mo("S. sanguis", Lancefield = TRUE)), "STCGRH") # group H
expect_identical(as.character(guess_mo("S. salivarius", Lancefield = FALSE)), "STCSAL")
expect_identical(as.character(guess_mo("S. salivarius", Lancefield = TRUE)), "STCGRK") # group K
expect_identical(as.character(guess_mo("E. faecium", Lancefield = FALSE)), "B_ENTRC_IUM")
expect_identical(as.character(guess_mo("E. faecium", Lancefield = TRUE)), "B_ENTRC_IUM")
expect_identical(as.character(guess_mo("E. faecium", Lancefield = "all")), "B_STRPTC_GRD") # group D
expect_identical(as.character(guess_mo("S. anginosus", Lancefield = FALSE)), "B_STRPTC_ANG")
expect_identical(as.character(guess_mo("S. anginosus", Lancefield = TRUE)), "B_STRPTC_GRF") # group F
expect_identical(as.character(guess_mo("S. sanguinis", Lancefield = FALSE)), "B_STRPTC_SAN")
expect_identical(as.character(guess_mo("S. sanguinis", Lancefield = TRUE)), "B_STRPTC_GRH") # group H
expect_identical(as.character(guess_mo("S. salivarius", Lancefield = FALSE)), "B_STRPTC_SAL")
expect_identical(as.character(guess_mo("S. salivarius", Lancefield = TRUE)), "B_STRPTC_GRK") # group K
library(dplyr)
@ -106,9 +106,8 @@ test_that("as.mo works", {
select(genus) %>%
as.mo() %>%
as.character(),
paste0(c("ESC", "ESC", "STA", "STA", "STA",
"STA", "STA", "STA", "STA", "STA"),
"SPP"))
c("B_ESCHR", "B_ESCHR", "B_STPHY", "B_STPHY", "B_STPHY",
"B_STPHY", "B_STPHY", "B_STPHY", "B_STPHY", "B_STPHY"))
# select with two columns
expect_identical(
@ -127,18 +126,18 @@ test_that("as.mo works", {
expect_error(septic_patients %>% select(1:3) %>% as.mo())
# print
expect_output(print(as.mo(c("ESCCOL", NA))))
expect_output(print(as.mo(c("B_ESCHR_COL", NA))))
# helper function
expect_identical(as.mo("ESCCOL"),
guess_mo("ESCCOL"))
expect_identical(as.mo("B_ESCHR_COL"),
guess_mo("B_ESCHR_COL"))
# test pull
expect_equal(nrow(septic_patients %>% mutate(mo = as.mo(mo))),
2000)
# test data.frame
expect_equal(nrow(data.frame(test = as.mo("ESCCOL"))),
expect_equal(nrow(data.frame(test = as.mo("B_ESCHR_COL"))),
1)
# check empty values

View File

@ -1,6 +1,7 @@
context("mo_property.R")
test_that("mo_property works", {
expect_equal(mo_subkingdom("E. coli"), "Negibacteria")
expect_equal(mo_phylum("E. coli"), "Proteobacteria")
expect_equal(mo_class("E. coli"), "Gammaproteobacteria")
expect_equal(mo_order("E. coli"), "Enterobacteriales")
@ -10,8 +11,7 @@ test_that("mo_property works", {
expect_equal(mo_subspecies("E. coli"), "")
expect_equal(mo_fullname("E. coli"), "Escherichia coli")
expect_equal(mo_type("E. coli", language = "en"), "Bacteria")
expect_equal(mo_gramstain("E. coli", language = "en"), "Negative rods")
expect_equal(mo_aerobic("E. coli"), TRUE)
expect_equal(mo_gramstain("E. coli", language = "en"), "Gram negative")
expect_equal(class(mo_taxonomy("E. coli")), "list")
expect_equal(mo_shortname("MRSA"), "S. aureus")
@ -22,30 +22,16 @@ test_that("mo_property works", {
# test integrity
library(dplyr)
MOs <- AMR::microorganisms %>% filter(!is.na(mo), nchar(mo) > 3)
rnd <- sample(1:nrow(AMR::microorganisms), 500, replace = FALSE) # random 500 rows
MOs <- AMR::microorganisms %>% filter(!is.na(mo),
species != "species",
dplyr::row_number() %in% rnd)
expect_identical(MOs$fullname, mo_fullname(MOs$fullname, language = "en"))
mo_clean <- MOs$mo
mo_from_shortname <- as.mo(mo_shortname(mo_clean))
mo_clean <- mo_clean[nchar(mo_from_shortname) == 6 &
!is.na(mo_from_shortname) &
!mo_from_shortname %like% "...SPP"]
mo_from_shortname <- mo_from_shortname[nchar(mo_from_shortname) == 6 &
!is.na(mo_from_shortname) &
!mo_from_shortname %like% "...SPP"]
tb <- tibble(a = substr(mo_clean, 1, 6),
b = mo_from_shortname,
c = a == b,
d = mo_shortname(a),
e = mo_shortname(b),
f = d == e)
expect_gt(sum(tb$c) / nrow(tb), 0.9) # more than 90% of MO code should be identical
expect_identical(sum(tb$f), nrow(tb)) # all shortnames should be identical
# check languages
expect_equal(mo_type("E. coli", language = "de"), "Bakterium")
expect_equal(mo_type("E. coli", language = "nl"), "Bacterie")
expect_equal(mo_gramstain("E. coli", language = "nl"), "Negatieve staven")
expect_equal(mo_type("E. coli", language = "de"), "Bakterien")
expect_equal(mo_type("E. coli", language = "nl"), "Bacteri\u00ebn")
expect_equal(mo_gramstain("E. coli", language = "nl"), "Gram-negatief")
expect_output(print(mo_gramstain("E. coli", language = "en")))
expect_output(print(mo_gramstain("E. coli", language = "de")))

View File

@ -2,8 +2,8 @@ context("portion.R")
test_that("portions works", {
# amox resistance in `septic_patients`
expect_equal(portion_R(septic_patients$amox), 0.6603, tolerance = 0.0001)
expect_equal(portion_I(septic_patients$amox), 0.0030, tolerance = 0.0001)
expect_equal(portion_R(septic_patients$amox), 0.662, tolerance = 0.0001)
expect_equal(portion_I(septic_patients$amox), 0.003, 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),
@ -12,17 +12,17 @@ test_that("portions works", {
portion_SI(septic_patients$amox))
expect_equal(septic_patients %>% portion_S(amcl),
0.673,
0.6706853,
tolerance = 0.001)
expect_equal(septic_patients %>% portion_S(amcl, gent),
0.921,
0.9202373,
tolerance = 0.001)
# amcl+genta susceptibility around 92.1%
expect_equal(suppressWarnings(rsi(septic_patients$amcl,
septic_patients$gent,
interpretation = "S")),
0.9208777,
0.9202373,
tolerance = 0.000001)
# percentages
@ -35,7 +35,7 @@ test_that("portions works", {
total = n()) %>%
pull(n) %>%
sum(),
1404)
1409)
# count of cases
expect_equal(septic_patients %>%
@ -47,7 +47,7 @@ test_that("portions works", {
combination_p = portion_S(cipr, gent, as_percent = TRUE),
combination_n = n_rsi(cipr, gent)) %>%
pull(combination_n),
c(202, 482, 201, 499))
c(202, 488, 201, 499))
expect_warning(portion_R(as.character(septic_patients$amcl)))
expect_warning(portion_S(as.character(septic_patients$amcl)))
@ -57,7 +57,7 @@ test_that("portions works", {
septic_patients$gent)))
expect_equal(suppressWarnings(n_rsi(as.character(septic_patients$amcl,
septic_patients$gent))),
1570)
1576)
# check for errors
expect_error(portion_IR("test", minimum = "test"))
@ -84,15 +84,15 @@ test_that("portions works", {
test_that("old rsi works", {
# amox resistance in `septic_patients` should be around 66.33%
expect_equal(suppressWarnings(rsi(septic_patients$amox)), 0.6633, tolerance = 0.0001)
expect_equal(suppressWarnings(rsi(septic_patients$amox, interpretation = "S")), 1 - 0.6633, tolerance = 0.0001)
expect_equal(suppressWarnings(rsi(septic_patients$amox)), 0.665, tolerance = 0.0001)
expect_equal(suppressWarnings(rsi(septic_patients$amox, interpretation = "S")), 1 - 0.665, tolerance = 0.0001)
# pita+genta susceptibility around 98.09%
expect_equal(suppressWarnings(rsi(septic_patients$pita,
septic_patients$gent,
interpretation = "S",
info = TRUE)),
0.9535,
0.9540412,
tolerance = 0.0001)
# count of cases
@ -108,7 +108,7 @@ test_that("old rsi works", {
as_percent = TRUE, warning = FALSE)),
combination_n = n_rsi(cipr, gent)) %>%
pull(combination_n),
c(202, 482, 201, 499))
c(202, 488, 201, 499))
# portion_df
expect_equal(
@ -122,7 +122,7 @@ test_that("old rsi works", {
test_that("prediction of rsi works", {
amox_R <- septic_patients %>%
filter(mo == "ESCCOL") %>%
filter(mo == "B_ESCHR_COL") %>%
rsi_predict(col_ab = "amox",
col_date = "date",
minimum = 10,
@ -131,37 +131,37 @@ test_that("prediction of rsi works", {
# amox resistance will increase according to data set `septic_patients`
expect_true(amox_R[3] < amox_R[20])
expect_output(rsi_predict(tbl = filter(septic_patients, mo == "ESCCOL"),
expect_output(rsi_predict(tbl = filter(septic_patients, mo == "B_ESCHR_COL"),
model = "binomial",
col_ab = "amox",
col_date = "date",
info = TRUE))
expect_output(rsi_predict(tbl = filter(septic_patients, mo == "ESCCOL"),
expect_output(rsi_predict(tbl = filter(septic_patients, mo == "B_ESCHR_COL"),
model = "loglin",
col_ab = "amox",
col_date = "date",
info = TRUE))
expect_output(rsi_predict(tbl = filter(septic_patients, mo == "ESCCOL"),
expect_output(rsi_predict(tbl = filter(septic_patients, mo == "B_ESCHR_COL"),
model = "lin",
col_ab = "amox",
col_date = "date",
info = TRUE))
expect_error(rsi_predict(tbl = filter(septic_patients, mo == "ESCCOL"),
expect_error(rsi_predict(tbl = filter(septic_patients, mo == "B_ESCHR_COL"),
model = "INVALID MODEL",
col_ab = "amox",
col_date = "date",
info = TRUE))
expect_error(rsi_predict(tbl = filter(septic_patients, mo == "ESCCOL"),
expect_error(rsi_predict(tbl = filter(septic_patients, mo == "B_ESCHR_COL"),
col_ab = "NOT EXISTING COLUMN",
col_date = "date",
info = TRUE))
expect_error(rsi_predict(tbl = filter(septic_patients, mo == "ESCCOL"),
expect_error(rsi_predict(tbl = filter(septic_patients, mo == "B_ESCHR_COL"),
col_ab = "amox",
col_date = "NOT EXISTING COLUMN",
info = TRUE))
# almost all E. coli are mero S in the Netherlands :)
expect_error(resistance_predict(tbl = filter(septic_patients, mo == "ESCCOL"),
expect_error(resistance_predict(tbl = filter(septic_patients, mo == "B_ESCHR_COL"),
col_ab = "mero",
col_date = "date",
info = TRUE))

View File

@ -2,12 +2,12 @@ context("skewness.R")
test_that("skewness works", {
expect_equal(skewness(septic_patients$age),
-0.90624,
-0.8958019,
tolerance = 0.00001)
expect_equal(unname(skewness(data.frame(septic_patients$age))),
-0.90624,
-0.8958019,
tolerance = 0.00001)
expect_equal(skewness(matrix(septic_patients$age)),
-0.90624,
-0.8958019,
tolerance = 0.00001)
})