Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
edelarua committed Sep 3, 2024
1 parent cfb4038 commit ef5982f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/testthat/_snaps/estimate_incidence_rate.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)

24 changes: 24 additions & 0 deletions tests/testthat/test-estimate_incidence_rate.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})

0 comments on commit ef5982f

Please sign in to comment.