library(tidyverse)
library(gtsummary)
library(survival)
# Example 1 ----------------------------------
# 直接用survfit()擬合括丁,計(jì)算12及24個(gè)月的生存概率及可信區(qū)間
tbl_survfit_ex1 <- tbl_survfit(
survfit(Surv(ttdeath, death) ~ trt, data = trial),#擬合生存方程
times = c(12, 24),#時(shí)間點(diǎn)
label_header = "**{time} Month**"#時(shí)間單位顯示設(shè)定
)
# Example 2 ----------------------------------
# 計(jì)算多個(gè)分組的中位生存時(shí)間
tbl_survfit_ex2 <- tbl_survfit(
trial,#數(shù)據(jù)集
y = Surv(ttdeath, death),#生存對(duì)象
include = c(trt, grade),#分組變量,可以是多個(gè)
probs = 0.5,#計(jì)算中位生存時(shí)間至朗,也可以返回其他生存概率的時(shí)間點(diǎn)
label_header = "**Median Survival**"#題目顯示
)
tbl_survfit_ex2
# Example 3 ----------------------------------
# 可以利用surfit分別組成不對(duì)的對(duì)象后構(gòu)成列表進(jìn)行分析
tbl_survfit_ex3 <-
list(
survfit(Surv(ttdeath, death) ~ 1, trial),
survfit(Surv(ttdeath, death) ~ trt, trial)
) %>%
tbl_survfit(times = c(12, 24))
tbl_survfit_ex3
# Example 4 競(jìng)爭(zhēng)風(fēng)險(xiǎn)模型計(jì)算 ---------
# 構(gòu)建競(jìng)爭(zhēng)風(fēng)險(xiǎn)數(shù)據(jù)
trial2 <- trial %>%
mutate(
death_cr = case_when(
death == 0 ~ "censor",
runif(n()) < 0.5 ~ "death from cancer",
TRUE ~ "death other causes"
) %>% factor()
)
#計(jì)算結(jié)果并展示
survfit_cr_ex4 <-
survfit(Surv(ttdeath, death_cr) ~ grade, data = trial2) %>%
tbl_survfit(times = c(12, 24), label = "Tumor Grade")
trial2$death_cr
survfit_cr_ex4
競(jìng)爭(zhēng)風(fēng)險(xiǎn)模型展示
# Example 5 ----------------------------------
# 同時(shí)對(duì)競(jìng)爭(zhēng)分析模型的兩種結(jié)局?jǐn)M合并計(jì)算時(shí)間點(diǎn)生存率
tbl_survfit_ex3 <-
list(
survfit(Surv(ttdeath, death_cr == "death from cancer") ~ grade, data = trial2),
survfit(Surv(ttdeath, death_cr == "death other causes") ~ grade, data = trial2)
) %>%
tbl_survfit(times = c(12, 24))
tbl_survfit_ex3
腫瘤和其他原因的兩種時(shí)間點(diǎn)生存率