计算 kaplan Meier 模型后,我得到下面的 km_fit 列表。现在如何提取 95% 置信区间值?
library(survminer)
sg1<-structure(list(`patient serial number` = c(1, 2, 3, 4, 6), `Time from breast cancer diagnosis to bone metastasis (months) (NA = unknown)` = c(28.37260274,
14.00547945, 75.02465753, 137.3260274, 34.15890411), `status (=1 as all pts have bone metastasis and BC)` = c(1,
1, 1, 1, 1), `Molecular type (0=hr+her2+, 1=hr+her2-, 2=hr-her2+, 3=TNBC)` = structure(c(1L,
2L, 2L, 1L, 1L), levels = c("HR+HER2-", "unknown", "HR-HER2+",
"HR+HER2+", "HR-HER2-"), class = "factor")), row.names = c(NA,
-5L), class = c("tbl_df", "tbl", "data.frame"))
# Plot Kaplan-Meier curves
sg1_survival <- Surv(
time = sg1$`Time from breast cancer diagnosis to bone metastasis (months) (NA = unknown)`,
event = sg1$`status (=1 as all pts have bone metastasis and BC)`
)
km_fit <- survfit(sg1_survival ~ sg1$`Molecular type (0=hr+her2+, 1=hr+her2-, 2=hr-her2+, 3=TNBC)`, data = sg1)
# Calculate 95% confidence intervals
ci <- confint(km_fit, level = 0.95)
km_fit <- survfit(sg1_survival ~ sg1$`Molecular type (0=hr+her2+, 1=hr+her2-, 2=hr-her2+, 3=TNBC)`, data = sg1)
sum <- summary(km_fit)
c <- data.frame(sum$time, sum$lower, sum$upper)
c
请尝试以下扫帚套餐并检查
conf.high & conf.low
new_km_fit <- broom::tidy(km_fit)
# A tibble: 5 × 9
time n.risk n.event n.censor estimate std.error conf.high conf.low strata
<dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <chr>
1 28.4 3 1 0 0.667 0.408 1 0.300 sg1$`Molecular type (0=hr+her2…
2 34.2 2 1 0 0.333 0.816 1 0.0673 sg1$`Molecular type (0=hr+her2…
3 137. 1 1 0 0 Inf NA NA sg1$`Molecular type (0=hr+her2…
4 14.0 2 1 0 0.5 0.707 1 0.125 sg1$`Molecular type (0=hr+her2…
5 75.0 1 1 0 0 Inf NA NA sg1$`Molecular type (0=hr+her2…