AMR/tests/testthat/test-resistance.R

78 lines
3.4 KiB
R
Raw Normal View History

2018-07-13 17:23:46 +02:00
context("resistance.R")
test_that("resistance works", {
# amox resistance in `septic_patients` should be around 57.56%
2018-07-15 22:56:41 +02:00
expect_equal(resistance(septic_patients$amox, include_I = TRUE), 0.5756, tolerance = 0.0001)
expect_equal(susceptibility(septic_patients$amox, include_I = FALSE), 1 - 0.5756, tolerance = 0.0001)
2018-03-27 17:43:42 +02:00
2018-04-03 11:08:31 +02:00
# pita+genta susceptibility around 98.09%
2018-07-13 17:23:46 +02:00
expect_equal(susceptibility(septic_patients$pita,
septic_patients$gent),
2018-04-03 11:08:31 +02:00
0.9809,
tolerance = 0.0001)
2018-07-13 17:23:46 +02:00
expect_equal(suppressWarnings(rsi(septic_patients$pita,
septic_patients$gent,
interpretation = "S")),
2018-04-03 11:08:31 +02:00
0.9809,
tolerance = 0.0001)
2018-05-02 14:56:25 +02:00
# count of cases
expect_equal(septic_patients %>%
group_by(hospital_id) %>%
2018-07-13 17:23:46 +02:00
summarise(cipro_p = susceptibility(cipr, as_percent = TRUE),
2018-05-02 14:56:25 +02:00
cipro_n = n_rsi(cipr),
2018-07-13 17:23:46 +02:00
genta_p = susceptibility(gent, as_percent = TRUE),
2018-05-02 14:56:25 +02:00
genta_n = n_rsi(gent),
2018-07-13 17:23:46 +02:00
combination_p = susceptibility(cipr, gent, as_percent = TRUE),
2018-05-02 14:56:25 +02:00
combination_n = n_rsi(cipr, gent)) %>%
pull(combination_n),
c(138, 474, 170, 464, 183))
2018-07-17 10:32:26 +02:00
expect_warning(resistance(as.character(septic_patients$amcl)))
expect_warning(susceptibility(as.character(septic_patients$amcl)))
expect_warning(susceptibility(as.character(septic_patients$amcl,
septic_patients$gent)))
2018-03-27 17:43:42 +02:00
})
test_that("prediction of rsi works", {
2018-04-03 11:08:31 +02:00
amox_R <- septic_patients %>%
filter(bactid == "ESCCOL") %>%
rsi_predict(col_ab = "amox",
col_date = "date",
info = FALSE) %>%
pull("probR")
# amox resistance will decrease using dataset `septic_patients`
2018-03-27 17:43:42 +02:00
expect_true(amox_R[2] > amox_R[20])
2018-04-03 11:08:31 +02:00
expect_output(rsi_predict(tbl = filter(septic_patients, bactid == "ESCCOL"),
model = "binomial",
col_ab = "amox",
col_date = "date",
info = TRUE))
expect_output(rsi_predict(tbl = filter(septic_patients, bactid == "ESCCOL"),
model = "loglin",
col_ab = "amox",
col_date = "date",
info = TRUE))
expect_output(rsi_predict(tbl = filter(septic_patients, bactid == "ESCCOL"),
model = "lin",
col_ab = "amox",
col_date = "date",
info = TRUE))
expect_error(rsi_predict(tbl = filter(septic_patients, bactid == "ESCCOL"),
2018-03-27 17:43:42 +02:00
model = "INVALID MODEL",
col_ab = "amox",
col_date = "date",
info = FALSE))
2018-04-03 11:08:31 +02:00
expect_error(rsi_predict(tbl = filter(septic_patients, bactid == "ESCCOL"),
2018-03-27 17:43:42 +02:00
col_ab = "NOT EXISTING COLUMN",
col_date = "date",
info = FALSE))
2018-04-03 11:08:31 +02:00
expect_error(rsi_predict(tbl = filter(septic_patients, bactid == "ESCCOL"),
2018-03-27 17:43:42 +02:00
col_ab = "amox",
col_date = "NOT EXISTING COLUMN",
info = FALSE))
})