From ef5982f976760246ddd8ad00a21d15efc6482620 Mon Sep 17 00:00:00 2001 From: Emily de la Rua Date: Tue, 3 Sep 2024 16:10:19 -0400 Subject: [PATCH] Add test --- .../_snaps/estimate_incidence_rate.md | 17 +++++++++++++ tests/testthat/test-estimate_incidence_rate.R | 24 +++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/tests/testthat/_snaps/estimate_incidence_rate.md b/tests/testthat/_snaps/estimate_incidence_rate.md index ba28293ec4..7133820dea 100644 --- a/tests/testthat/_snaps/estimate_incidence_rate.md +++ b/tests/testthat/_snaps/estimate_incidence_rate.md @@ -101,6 +101,11 @@ attr(,"label") [1] "90% CI" + $n_rate + [1] 4.00000 44.15823 + attr(,"label") + [1] "Number of adverse events observed (AE rate per 100 patient-years)" + # estimate_incidence_rate works as expected with healthy input @@ -115,3 +120,15 @@ AE rate per 100 patient-years 26.20 57.23 90% CI (5.06, 135.73) (22.14, 147.94) +# estimate_incidence_rate `n_rate` statistic works as expected + + Code + res + Output + A B + (N=3) (N=3) + ————————————————————————————————————————————————————————————————————————————————————— + Number of adverse events observed 1 3 + AE rate per 100 patient-years 2.18 4.77 + Number of adverse events observed (AE rate per 100 patient-years) 1 (2.2) 3 (4.8) + diff --git a/tests/testthat/test-estimate_incidence_rate.R b/tests/testthat/test-estimate_incidence_rate.R index f83173e1a2..2befdfa96f 100644 --- a/tests/testthat/test-estimate_incidence_rate.R +++ b/tests/testthat/test-estimate_incidence_rate.R @@ -109,3 +109,27 @@ testthat::test_that("estimate_incidence_rate works as expected with healthy inpu res <- testthat::expect_silent(result) testthat::expect_snapshot(res) }) + +testthat::test_that("estimate_incidence_rate `n_rate` statistic works as expected", { + df <- data.frame( + USUBJID = as.character(seq(6)), + CNSR = c(0, 1, 1, 0, 0, 0), + AVAL = c(10.1, 20.4, 15.3, 20.8, 18.7, 23.4), + ARM = factor(c("A", "A", "A", "B", "B", "B")) + ) %>% + dplyr::mutate(is_event = CNSR == 0) %>% + dplyr::mutate(n_events = as.integer(is_event)) + + result <- basic_table() %>% + split_cols_by("ARM") %>% + add_colcounts() %>% + estimate_incidence_rate( + vars = "AVAL", + n_events = "n_events", + .stats = c("n_events", "rate", "n_rate") + ) %>% + build_table(df) + + res <- testthat::expect_silent(result) + testthat::expect_snapshot(res) +})