library(dplyr)
# Example 1: one-way treatment switching (control to active)
data <- immdef %>% mutate(rx = 1-xoyrs/progyrs)
fit1 <- ipe(
data, id = "id", time = "progyrs", event = "prog", treat = "imm",
rx = "rx", censor_time = "censyrs", aft_dist = "weibull",
boot = FALSE)
c(fit1$hr, fit1$hr_CI)
# Example 2: two-way treatment switching (illustration only)
# the eventual survival time
shilong1 <- shilong %>%
arrange(bras.f, id, tstop) %>%
group_by(bras.f, id) %>%
slice(n()) %>%
select(-c("ps", "ttc", "tran"))
shilong2 <- shilong1 %>%
mutate(rx = ifelse(co, ifelse(bras.f == "MTA", dco/ady,
1 - dco/ady),
ifelse(bras.f == "MTA", 1, 0)))
fit2 <- ipe(
shilong2, id = "id", time = "tstop", event = "event",
treat = "bras.f", rx = "rx", censor_time = "dcut",
base_cov = c("agerand", "sex.f", "tt_Lnum", "rmh_alea.c",
"pathway.f"),
aft_dist = "weibull", boot = FALSE)
c(fit2$hr, fit2$hr_CI)
Run the code above in your browser using DataLab