1
0
mirror of https://github.com/msberends/AMR.git synced 2025-07-08 18:41:58 +02:00

update to septic_patients, speed improvements

This commit is contained in:
2018-07-25 14:17:04 +02:00
parent 03a3cb397b
commit d9e204031d
26 changed files with 273 additions and 233 deletions

View File

@ -37,8 +37,8 @@ test_that("as.bactid works", {
select(genus) %>%
as.bactid() %>%
as.character(),
c("STC", "STC", "NEI", "STA", "STA",
"NEI", "ENT", "ENT", "ESC", "KLE"))
c("ESC", "ESC", "STA", "STA", "STA",
"STA", "STA", "STA", "STA", "STA"))
# select with two columns
expect_identical(

View File

@ -8,9 +8,9 @@ test_that("first isolates work", {
col_date = "date",
col_patient_id = "patient_id",
col_bactid = "bactid",
info = FALSE),
info = TRUE),
na.rm = TRUE),
1959)
1326)
# septic_patients contains 1962 out of 2000 first *weighted* isolates
expect_equal(
@ -24,8 +24,8 @@ test_that("first isolates work", {
type = "keyantibiotics",
info = TRUE),
na.rm = TRUE)),
1962)
# and 1997 when using points
1421)
# and 1961 when using points
expect_equal(
suppressWarnings(
sum(
@ -37,7 +37,7 @@ test_that("first isolates work", {
type = "points",
info = TRUE),
na.rm = TRUE)),
1997)
1425)
# septic_patients contains 1732 out of 2000 first non-ICU isolates
expect_equal(
@ -50,7 +50,7 @@ test_that("first isolates work", {
info = TRUE,
icu_exclude = TRUE),
na.rm = TRUE),
1732)
1171)
# set 1500 random observations to be of specimen type 'Urine'
random_rows <- sample(x = 1:2000, size = 1500, replace = FALSE)
@ -59,7 +59,7 @@ test_that("first isolates work", {
first_isolate(tbl = mutate(septic_patients,
specimen = if_else(row_number() %in% random_rows,
"Urine",
"Unknown")),
"Other")),
col_date = "date",
col_patient_id = "patient_id",
col_bactid = "bactid",
@ -74,7 +74,7 @@ test_that("first isolates work", {
first_isolate(tbl = mutate(septic_patients,
specimen = if_else(row_number() %in% random_rows,
"Urine",
"Unknown")),
"Other")),
col_date = "date",
col_patient_id = "patient_id",
col_bactid = "bactid",

View File

@ -4,8 +4,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 1662 unique dates
expect_equal(nrow(freq(septic_patients$date)), 1662)
# date column of septic_patients should contain 1151 unique dates
expect_equal(nrow(freq(septic_patients$date)), 1151)
expect_equal(nrow(freq(septic_patients$date)),
length(unique(septic_patients$date)))

View File

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

View File

@ -13,7 +13,8 @@ test_that("MDRO works", {
expect_equal(outcome %>% class(), c('ordered', 'factor'))
# septic_patients should have these finding using Dutch guidelines
expect_equal(outcome %>% freq() %>% pull(count), c(3, 21))
expect_equal(outcome %>% freq() %>% pull(count),
c(2, 14)) # 2 unconfirmed, 14 positive
expect_equal(BRMO(septic_patients, info = FALSE), MDRO(septic_patients, "nl", info = FALSE))

View File

@ -1,19 +1,19 @@
context("resistance.R")
test_that("resistance works", {
# amox resistance in `septic_patients` should be around 57.56%
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)
# amox resistance in `septic_patients` should be around 66.33%
expect_equal(resistance(septic_patients$amox, include_I = TRUE), 0.6633, tolerance = 0.0001)
expect_equal(susceptibility(septic_patients$amox, include_I = FALSE), 1 - 0.6633, tolerance = 0.0001)
# pita+genta susceptibility around 98.09%
expect_equal(susceptibility(septic_patients$pita,
septic_patients$gent),
0.9809,
0.9535,
tolerance = 0.0001)
expect_equal(suppressWarnings(rsi(septic_patients$pita,
septic_patients$gent,
interpretation = "S")),
0.9809,
0.9535,
tolerance = 0.0001)
# count of cases
@ -26,7 +26,7 @@ test_that("resistance works", {
combination_p = susceptibility(cipr, gent, as_percent = TRUE),
combination_n = n_rsi(cipr, gent)) %>%
pull(combination_n),
c(138, 474, 170, 464, 183))
c(202, 482, 201, 499))
expect_warning(resistance(as.character(septic_patients$amcl)))
expect_warning(susceptibility(as.character(septic_patients$amcl)))
@ -36,26 +36,26 @@ test_that("resistance works", {
})
test_that("old rsi works", {
# amox resistance in `septic_patients` should be around 53.86%
expect_equal(rsi(septic_patients$amox), 0.5756, tolerance = 0.0001)
expect_equal(rsi(septic_patients$amox), 0.5756, tolerance = 0.0001)
# amox resistance in `septic_patients` should be around 66.33%
expect_equal(rsi(septic_patients$amox), 0.6633, tolerance = 0.0001)
expect_equal(rsi(septic_patients$amox, interpretation = "S"), 1 - 0.6633, tolerance = 0.0001)
expect_equal(rsi_df(septic_patients,
ab = "amox",
info = TRUE),
0.5756,
0.6633,
tolerance = 0.0001)
# pita+genta susceptibility around 98.09%
expect_equal(rsi(septic_patients$pita,
septic_patients$gent,
interpretation = "S",
info = TRUE),
0.9809,
0.9535,
tolerance = 0.0001)
expect_equal(rsi_df(septic_patients,
ab = c("pita", "gent"),
interpretation = "S",
info = TRUE),
0.9809,
0.9535,
tolerance = 0.0001)
# more than 2 not allowed
expect_error(rsi_df(septic_patients,
@ -76,7 +76,7 @@ test_that("old rsi works", {
as_percent = TRUE, warning = FALSE),
combination_n = n_rsi(cipr, gent)) %>%
pull(combination_n),
c(138, 474, 170, 464, 183))
c(202, 482, 201, 499))
})
test_that("prediction of rsi works", {
@ -86,8 +86,8 @@ test_that("prediction of rsi works", {
col_date = "date",
info = TRUE) %>%
pull("probR")
# amox resistance will decrease using dataset `septic_patients`
expect_true(amox_R[2] > amox_R[20])
# 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, bactid == "ESCCOL"),
model = "binomial",

View File

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