BioF3 FigCode · SCI 绘图代码集

时间依赖 ROC(Time-dependent ROC)

导出日期:2026年6月27日

分类:生存分析 | 依赖包:timeROC

解决的生物学问题

我的预后 signature / risk score 在不同随访时间点的预测准确度有多高?

应用场景

输入数据格式

数据框:time, status, marker(risk score 或单基因表达)

关键参数

快速开始

1. 直接在线运行

打开 FigCode 在线绘图,点击本工具卡片的"在线绘图"按钮即可用内置示例数据出图,零环境配置。

2. 本地复现

下载脚本和示例数据,本地 RStudio 运行:

# 下载
curl -O https://<your-site>/figcode/scripts/time-roc.R
curl -O https://<your-site>/figcode/data/time-roc.csv

3. 安装依赖

# CRAN 包
install.packages(c("timeROC"))

# Bioconductor 包(如需)
# BiocManager::install(c())

完整代码

library(timeROC)

# --- Demo data ---
set.seed(42)
n <- 200
df <- data.frame(
  time   = rexp(n, 0.05),
  status = sample(0:1, n, replace = TRUE, prob = c(0.4, 0.6)),
  marker = rnorm(n)
)
# Make the marker informative
df$time <- pmax(df$time + 0.5 * df$marker, 0.1)

# --- Time-dependent ROC at 1, 3, 5 years (assuming time in years) ---
roc <- timeROC(
  T      = df$time,
  delta  = df$status,
  marker = df$marker,
  cause  = 1,
  times  = c(1, 3, 5),
  iid    = TRUE
)

# --- Plot ---
plot(roc, time = 1, col = "#dc2626", title = FALSE, lwd = 2)
plot(roc, time = 3, col = "#059669", add = TRUE, lwd = 2)
plot(roc, time = 5, col = "#2563eb", add = TRUE, lwd = 2)
legend("bottomright",
       legend = paste0(c("1 yr", "3 yr", "5 yr"), " AUC = ",
                       round(roc$AUC, 3)),
       col = c("#dc2626", "#059669", "#2563eb"),
       lwd = 2, bty = "n")
title("Time-dependent ROC")

替换为自己的数据

脚本中以 # --- Demo data --- 标注的段落是示例数据生成代码。替换为自己的数据时,保持列名一致即可:

延伸阅读