You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在R语言的竞争风险累积发病率图中添加删失标记?

为竞争风险累积发病率图添加删失标记的解决方案

由于cmprsk::cuminc()和survminer::ggcompetingrisks()没有直接添加删失标记的内置参数,我们可以通过手动提取删失观测或使用支持该功能的工具包来实现需求。以下是三种可行方法:

方法1:基础绘图(plot.cuminc)叠加删失标记

先绘制累积发病率曲线,再从原始数据中筛选出未发生任何事件的删失样本,用points()函数叠加标记:

library(survival)
library(cmprsk)

# 数据预处理(与你的示例一致)
df <- data.frame(ovarian)
df$fustat2 <- df$fustat
df[df$futime < 300,]$fustat2 <- 2
df$rx <- factor(df$rx, c(1, 2), labels=c('Rx1', 'Rx2'))

# 计算累积发病率
ci.cuminc <- cuminc(ftime = df$futime, fstatus= df$fustat2, group =  df$rx)

# 绘制累积发病率曲线
plot(ci.cuminc, lty=c(1, 1, 0, 0), wh=c(-1,-1), ylim=c(0, 0.45))

# 提取删失数据:未发生任何事件(fustat2 == 0)的样本
censored <- df[df$fustat2 == 0, ]

# 按分组叠加删失标记:Rx1用圆圈,Rx2用加号
points(censored[censored$rx == "Rx1", "futime"], 
       rep(0, nrow(censored[censored$rx == "Rx1", ])),
       pch = 1, col = "black")
points(censored[censored$rx == "Rx2", "futime"], 
       rep(0, nrow(censored[censored$rx == "Rx2", ])),
       pch = 3, col = "black")

方法2:ggplot2手动构建数据绘图

将cuminc()结果转换为数据框,结合删失数据用ggplot2灵活定制图形:

library(ggplot2)
library(broom)

# 数据预处理同上(略)

# 将cuminc结果转为 tidy 数据框
ci_tidy <- tidy(ci.cuminc)

# 筛选目标事件(示例为事件1)的累积发病率数据
ci_event1 <- ci_tidy[ci_tidy$event == 1, ]

# 提取删失数据并添加累积发病率标记值
censored <- df[df$fustat2 == 0, ]
censored$cum_inc <- 0

# 绘制图形
ggplot() +
  # 绘制累积发病率阶梯线
  geom_step(data = ci_event1, aes(x = time, y = estimate, color = group, linetype = group)) +
  # 添加删失标记
  geom_point(data = censored, aes(x = futime, y = cum_inc, shape = group), color = "black") +
  # 自定义样式
  scale_color_manual(values = c("Rx1" = "#000000", "Rx2" = "#E63946")) +
  scale_shape_manual(values = c("Rx1" = 1, "Rx2" = 3)) +
  labs(x = "随访时间", y = "事件1累积发病率", color = "治疗组", shape = "治疗组") +
  theme_bw()

方法3:使用ggsurvfit包(推荐)

ggsurvfit的ggcuminc()函数原生支持竞争风险累积发病率绘图,且可通过add_censor_mark()直接添加删失标记:

library(ggsurvfit)

# 数据预处理同上(略)

# 构建竞争风险Surv对象:0=删失,1=目标事件,2=竞争事件
surv_obj <- Surv(df$futime, df$fustat2, type = "mstate")

# 绘制带删失标记的累积发病率曲线
ggcuminc(surv_obj ~ rx, data = df, event = "1") +
  add_censor_mark(aes(shape = rx)) + # 按分组区分删失标记形状
  scale_shape_manual(values = c(1, 3)) +
  labs(x = "随访时间", y = "事件1累积发病率", shape = "治疗组") +
  theme_bw()

关键说明

竞争风险中的删失观测指既未发生目标事件、也未发生竞争事件的样本,上述方法均基于此定义提取数据。ggsurvfit方法最为简洁,且图形样式更易定制。

内容的提问来源于stack exchange,提问作者SIO

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 17:43:16