Skip to content

Commit

Permalink
inc_prop only returned ae=1 var=0 on certain platforms. (#22)
Browse files Browse the repository at this point in the history
* inc_prop only returned ae=1 var=0 on certain platforms. Issue is fixed now.

testthat has been updated to match structure of other tests

* Update R/inc_prop.R

Co-authored-by: Daniel Sabanes Bove <danielinteractive@users.noreply.github.com>

---------

Co-authored-by: Kuenzel <kuenzelt@emea.roche.com>
Co-authored-by: Daniel Sabanes Bove <danielinteractive@users.noreply.github.com>
  • Loading branch information
3 people authored Feb 7, 2024
1 parent 4d2d366 commit 1f86cc8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion R/inc_prop.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ inc_prop <- function(data,
assert_true(tau > 0)

n <- nrow(data)
ae <- nrow(data["type_of_event" == 1 & "time_to_event" <= tau]) / n
ae <- sum(data$type_of_event == 1 & data$time_to_event <= tau) / n
ae_prob_var <- ae * (1 - ae) / n

c("ae_prob" = ae, "ae_prob_var" = ae_prob_var)
Expand Down
20 changes: 10 additions & 10 deletions tests/testthat/test-inc_prop.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
test_that("inc_prop works as expected", {
set.seed(123)
result <- generate_data(
n = 10,
cens = c(0, 0.5),
haz_ae = 4.3,
haz_death = 5.3,
haz_soft = 1.2
set.seed(23)
df <- generate_data(
n = 25,
cens = c(0.2, 3),
haz_ae = 0.2,
haz_death = 0.3,
haz_soft = 0.5
)
ip <- inc_prop(data = result, tau = 4)
expect_vector(ip, size = 2)
expect_named(ip, c("ae_prob", "ae_prob_var"))
result <- inc_prop(data = df, tau = 4)
expected <- c(ae_prob = 0.2, ae_prob_var = 0.0064)
expect_equal(result, expected, tolerance = 1e-4)
})

0 comments on commit 1f86cc8

Please sign in to comment.