# Standard single-event transformation
tumor[1:3, ]
tumor[1:3, ] %>% as_ped(Surv(days, status) ~ age + sex, cut = c(0, 500, 1000))
tumor[1:3, ] %>% as_ped(Surv(days, status) ~ age + sex)
# Competing risks: stacked data set (combine = TRUE, default)
# Suitable for cause-specific hazards models with shared effects,
# estimated via interaction terms e.g. s(tend, by = cause)
if (FALSE) {
data("fourD", package = "etm")
ped_stacked <- fourD %>%
as_ped(Surv(time, status) ~ ., id = "id")
head(ped_stacked)
# Competing risks: list output (combine = FALSE)
# Suitable for cause-specific hazards models without shared effects
ped_list <- fourD %>%
as_ped(Surv(time, status) ~ ., id = "id", combine = FALSE)
# ped_list[[1]]: data for cause 1 (cardiovascular death)
# ped_list[[2]]: data for cause 2 (death from other causes)
head(ped_list[[1]])
head(ped_list[[2]])
# Multi-state: illness-death model on calendar timescale
# Uses the prothr data (liver cirrhosis patients, n = 488) from mstate.
# Patients can transition between normal (1) and abnormal (2) prothrombin
# levels and death (3): transitions 1->2, 1->3, 2->1, 2->3.
# Calendar timescale is used because hazards depend on overall disease
# duration, not time since last transition.
data("prothr", package = "mstate")
ped_msm <- prothr %>%
filter(Tstart != Tstop) %>%
as_ped(
formula = Surv(Tstart, Tstop, status) ~ .,
transition = "trans",
id = "id",
timescale = "calendar",
)
head(ped_msm)
}
if (FALSE) {
data("cgd", package = "frailtyHL")
cgd2 <- cgd %>%
select(id, tstart, tstop, enum, status, age) %>%
filter(enum %in% c(1:2))
ped_re <- as_ped_multistate(
formula = Surv(tstart, tstop, status) ~ age + enum,
data = cgd2,
transition = "enum",
timescale = "calendar")
}
Run the code above in your browser using DataLab