Skip to content

Commit

Permalink
survival POC
Browse files Browse the repository at this point in the history
  • Loading branch information
DanChaltiel committed Aug 24, 2024
1 parent 56103c2 commit 725a325
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/testthat/_snaps/quick_surv.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# survival POC

Code
df = data.frame(time = c(71.1, 75.7, 78.7, 79, 95.1, 108, 120.1, 120.3, 121,
140.8, 145, 146.7, 160, 160, 167.6, 167.6, 225, 258, 275.8, 275.8, 275.8, 301,
304, 318, 350, 351, 360, 360, 400, 440, 460, 472), event = rep(rep(c(1, 0), 6),
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$surv = survival::Surv(df$time, df$event)
fit = survival::survfit(surv ~ group, data = df)
times = sort(fit$time)
a = summary(fit, times = times, extend = TRUE, data.frame = TRUE)
a %>% dplyr::filter(strata == "group=B") %>% dplyr::filter(time > 120 & time <
150) %>% dplyr::select(strata, time, n.risk, n.event, surv)
Output
strata time n.risk n.event surv
1 group=B 120.1 18 0 0.7500000
2 group=B 120.3 17 1 0.7058824
3 group=B 121.0 16 1 0.6617647
4 group=B 140.8 15 1 0.6617647
5 group=B 145.0 15 1 0.6176471
6 group=B 146.7 14 1 0.6176471

41 changes: 41 additions & 0 deletions tests/testthat/test-quick_surv.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
test_that("survival POC", {

# mtcars3 %>%
# transmute(time=as.numeric(disp), event=as.numeric(factor(am))-1,
# group=ifelse(is.na(dummy2), "A", "B")) %>%
# arrange(time) %>% as.data.frame() %>%
# # filter(time<150) %>%
# constructive::construct()

expect_snapshot({

df = data.frame(
time = c(71.1, 75.7, 78.7, 79, 95.1, 108, 120.1, 120.3, 121, 140.8, 145, 146.7, 160,
160, 167.6, 167.6, 225, 258, 275.8, 275.8, 275.8, 301, 304, 318, 350, 351,
360, 360, 400, 440, 460, 472),
event = rep(rep(c(1, 0), 6), 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$surv = survival::Surv(df$time, df$event)
fit = survival::survfit(surv~group, data=df)
times = sort(fit$time)

a = summary(fit, times=times, extend=TRUE, data.frame=TRUE)
a %>%
dplyr::filter(strata=="group=B") %>%
dplyr::filter(time>120 & time<150) %>%
dplyr::select(strata, time, n.risk, n.event, surv)

})


#t=140.8
#on local 4.3 : 1/15
#on local 4.4 : 1/15
#on ubuntu-devel : 1/15
#on 4.4.1 : 0/15
#on release : 0/15

})

0 comments on commit 725a325

Please sign in to comment.