Skip to content

Commit

Permalink
survival POC
Browse files Browse the repository at this point in the history
  • Loading branch information
DanChaltiel committed Aug 25, 2024
1 parent fbe03a1 commit 2a9d75d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions tests/testthat/_snaps/quick_surv.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
c(6L, 1L, 2L, 1L, 1L, 1L, 2L, 7L, 1L, 3L, 1L, 6L)), group = rep(c("B", "A", "B",
"A", "B", "A", "B", "A", "B", "A", "B"), c(9L, 1L, 1L, 1L, 2L, 3L, 1L, 1L, 7L,
2L, 4L)))
df$time = round(df$time)
df$surv = survival::Surv(df$time, df$event)
fit = survival::survfit(surv ~ group, data = df)
times = sort(fit$time)
x = summary(fit, times = times, extend = TRUE)
a = data.frame(strata = x$strata, time = x$time, n.risk = x$n.risk, n.event = x$
n.event, surv = x$surv)
a %>% dplyr::filter(strata == "group=B") %>% dplyr::filter(time == 140.8)
a %>% dplyr::filter(strata == "group=B") %>% dplyr::filter(time == 141)
Output
strata time n.risk n.event surv
1 group=B 140.8 15 1 0.6617647
strata time n.risk n.event surv
1 group=B 141 15 1 0.6640625

4 changes: 2 additions & 2 deletions tests/testthat/test-quick_surv.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ test_that("survival POC", {
group = rep(c("B", "A", "B", "A", "B", "A", "B", "A", "B", "A", "B"),
c(9L, 1L, 1L, 1L, 2L, 3L, 1L, 1L, 7L, 2L, 4L))
)

df$time = round(df$time)
df$surv = survival::Surv(df$time, df$event)
fit = survival::survfit(surv~group, data=df)
times = sort(fit$time)
Expand All @@ -26,7 +26,7 @@ test_that("survival POC", {

a %>%
dplyr::filter(strata=="group=B") %>%
dplyr::filter(time==140.8)
dplyr::filter(time==141)
})


Expand Down

0 comments on commit 2a9d75d

Please sign in to comment.