mirror of
https://github.com/msberends/AMR.git
synced 2025-12-15 12:30:22 +01:00
(v0.7.1.9063) septic_patients -> example_isolates
This commit is contained in:
@@ -22,28 +22,28 @@
|
||||
context("portion.R")
|
||||
|
||||
test_that("portions works", {
|
||||
# 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))
|
||||
# AMX resistance in `example_isolates`
|
||||
expect_equal(portion_R(example_isolates$AMX), 0.5557364, tolerance = 0.0001)
|
||||
expect_equal(portion_I(example_isolates$AMX), 0.002441009, tolerance = 0.0001)
|
||||
expect_equal(1 - portion_R(example_isolates$AMX) - portion_I(example_isolates$AMX),
|
||||
portion_S(example_isolates$AMX))
|
||||
expect_equal(portion_R(example_isolates$AMX) + portion_I(example_isolates$AMX),
|
||||
portion_IR(example_isolates$AMX))
|
||||
expect_equal(portion_S(example_isolates$AMX) + portion_I(example_isolates$AMX),
|
||||
portion_SI(example_isolates$AMX))
|
||||
|
||||
expect_equal(septic_patients %>% portion_SI(AMC),
|
||||
expect_equal(example_isolates %>% portion_SI(AMC),
|
||||
0.7626397,
|
||||
tolerance = 0.0001)
|
||||
expect_equal(septic_patients %>% portion_SI(AMC, GEN),
|
||||
expect_equal(example_isolates %>% portion_SI(AMC, GEN),
|
||||
0.9408,
|
||||
tolerance = 0.0001)
|
||||
expect_equal(septic_patients %>% portion_SI(AMC, GEN, only_all_tested = TRUE),
|
||||
expect_equal(example_isolates %>% portion_SI(AMC, GEN, only_all_tested = TRUE),
|
||||
0.9382647,
|
||||
tolerance = 0.0001)
|
||||
|
||||
# percentages
|
||||
expect_equal(septic_patients %>%
|
||||
expect_equal(example_isolates %>%
|
||||
group_by(hospital_id) %>%
|
||||
summarise(R = portion_R(CIP, as_percent = TRUE),
|
||||
I = portion_I(CIP, as_percent = TRUE),
|
||||
@@ -55,7 +55,7 @@ test_that("portions works", {
|
||||
1409)
|
||||
|
||||
# count of cases
|
||||
expect_equal(septic_patients %>%
|
||||
expect_equal(example_isolates %>%
|
||||
group_by(hospital_id) %>%
|
||||
summarise(cipro_p = portion_SI(CIP, as_percent = TRUE),
|
||||
cipro_n = n_rsi(CIP),
|
||||
@@ -66,14 +66,14 @@ test_that("portions works", {
|
||||
pull(combination_n),
|
||||
c(305, 617, 241, 711))
|
||||
|
||||
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))),
|
||||
expect_warning(portion_R(as.character(example_isolates$AMC)))
|
||||
expect_warning(portion_S(as.character(example_isolates$AMC)))
|
||||
expect_warning(portion_S(as.character(example_isolates$AMC,
|
||||
example_isolates$GEN)))
|
||||
expect_warning(n_rsi(as.character(example_isolates$AMC,
|
||||
example_isolates$GEN)))
|
||||
expect_equal(suppressWarnings(n_rsi(as.character(example_isolates$AMC,
|
||||
example_isolates$GEN))),
|
||||
1879)
|
||||
|
||||
# check for errors
|
||||
@@ -86,36 +86,36 @@ test_that("portions works", {
|
||||
expect_error(portion_S("test", also_single_tested = TRUE))
|
||||
|
||||
# check too low amount of isolates
|
||||
expect_identical(suppressWarnings(portion_R(septic_patients$AMX, minimum = nrow(septic_patients) + 1)),
|
||||
expect_identical(suppressWarnings(portion_R(example_isolates$AMX, minimum = nrow(example_isolates) + 1)),
|
||||
NA)
|
||||
expect_identical(suppressWarnings(portion_I(septic_patients$AMX, minimum = nrow(septic_patients) + 1)),
|
||||
expect_identical(suppressWarnings(portion_I(example_isolates$AMX, minimum = nrow(example_isolates) + 1)),
|
||||
NA)
|
||||
expect_identical(suppressWarnings(portion_S(septic_patients$AMX, minimum = nrow(septic_patients) + 1)),
|
||||
expect_identical(suppressWarnings(portion_S(example_isolates$AMX, minimum = nrow(example_isolates) + 1)),
|
||||
NA)
|
||||
|
||||
# warning for speed loss
|
||||
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)))
|
||||
expect_warning(portion_R(as.character(example_isolates$GEN)))
|
||||
expect_warning(portion_I(as.character(example_isolates$GEN)))
|
||||
expect_warning(portion_S(example_isolates$AMC, as.character(example_isolates$GEN)))
|
||||
|
||||
# portion_df
|
||||
expect_equal(
|
||||
septic_patients %>% select(AMX) %>% portion_df() %>% pull(value),
|
||||
c(septic_patients$AMX %>% portion_SI(),
|
||||
septic_patients$AMX %>% portion_R())
|
||||
example_isolates %>% select(AMX) %>% portion_df() %>% pull(value),
|
||||
c(example_isolates$AMX %>% portion_SI(),
|
||||
example_isolates$AMX %>% portion_R())
|
||||
)
|
||||
expect_equal(
|
||||
septic_patients %>% select(AMX) %>% portion_df(combine_IR = TRUE) %>% pull(value),
|
||||
c(septic_patients$AMX %>% portion_S(),
|
||||
septic_patients$AMX %>% portion_IR())
|
||||
example_isolates %>% select(AMX) %>% portion_df(combine_IR = TRUE) %>% pull(value),
|
||||
c(example_isolates$AMX %>% portion_S(),
|
||||
example_isolates$AMX %>% portion_IR())
|
||||
)
|
||||
expect_equal(
|
||||
septic_patients %>% select(AMX) %>% portion_df(combine_SI = FALSE) %>% pull(value),
|
||||
c(septic_patients$AMX %>% portion_S(),
|
||||
septic_patients$AMX %>% portion_I(),
|
||||
septic_patients$AMX %>% portion_R())
|
||||
example_isolates %>% select(AMX) %>% portion_df(combine_SI = FALSE) %>% pull(value),
|
||||
c(example_isolates$AMX %>% portion_S(),
|
||||
example_isolates$AMX %>% portion_I(),
|
||||
example_isolates$AMX %>% portion_R())
|
||||
)
|
||||
|
||||
expect_error(portion_df(c("A", "B", "C")))
|
||||
expect_error(portion_df(septic_patients[,"date"]))
|
||||
expect_error(portion_df(example_isolates[,"date"]))
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user