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

在R中基于区间删失生存数据检验两条Kaplan-Meier生存曲线的差异

Comparing Interval-Censored Survival Curves in R

Great question—you're right that survdiff() doesn't support interval-censored survival objects (the Surv(time1, time2, event) format), since it's built for right-censored data. To compare your two NPMLE (non-parametric maximum likelihood estimate) survival curves (the interval-censored equivalent of Kaplan-Meier), you'll need methods tailored to this data type. Here are two reliable approaches:


First: Fix Your Data Preparation

Let's correct your data setup to ensure numeric columns stay numeric (your original cbind() converts everything to characters/factors) and align event coding with survival package conventions:

# Sample data
e <- c(1, 0 ,1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 1)
t1 <- c(35, 35, 34, 35, 35, 35, 34, 35, 35, 35, 34, 35, 35, 35, 34, 35)
t2 <- c(36, 37, 37, 36, 36,37, 35, 36, 36, 37, 37, 36, 36, 37, 35, 36)
g <- c("F","F","F","F","F","F","F","F","M","M","M","M","M","M","M","M")

# Create data frame with correct types and event coding
data <- data.frame(
  Gender = factor(g),
  time_1 = as.numeric(t1),
  time_2 = as.numeric(t2),
  # Recode event: 1 = interval-censored (event between t1/t2), 2 = right-censored (event after t2)
  event = ifelse(e == 0, 2, 1)
)

This ensures the Surv() object is interpreted correctly as interval-censored.


Approach 1: Non-Parametric Test (Generalized Log-Rank) with icenReg

The icenReg package specializes in interval-censored survival analysis and includes a non-parametric test equivalent to the log-rank test for this data type.

Step 1: Install and Load the Package

install.packages("icenReg")
library(icenReg)

Step 2: Fit Models and Compare

We'll fit two models: a null model (no gender effect) and a model with gender, then use a likelihood ratio test to compare them:

# Null model (no gender effect)
null_model <- npar(Surv(time_1, time_2, event) ~ 1, data = data, model = "cox")

# Model with gender as a predictor
gender_model <- npar(Surv(time_1, time_2, event) ~ Gender, data = data, model = "cox")

# Likelihood ratio test for equality of survival curves
anova(null_model, gender_model)

The output will give you a chi-squared statistic and p-value, testing whether the survival curves differ significantly by gender.


Approach 2: Parametric/Semi-Parametric Test with survival Package

If you're open to parametric assumptions, you can use survreg() from the base survival package to fit a model (e.g., Weibull) and perform a likelihood ratio test:

library(survival)

# Null parametric model
null_survreg <- survreg(Surv(time_1, time_2, event, type = "interval") ~ 1, data = data, dist = "weibull")

# Parametric model including gender
gender_survreg <- survreg(Surv(time_1, time_2, event, type = "interval") ~ Gender, data = data, dist = "weibull")

# Likelihood ratio test
anova(null_survreg, gender_survreg)

This tests whether gender has a significant effect on the survival distribution under your chosen parametric model.


Key Note

Your original km2 model using Surv(time2, event) treats all observations as right-censored at time2, which ignores critical interval information (the event could have occurred between time1 and time2). That's why it produces incorrect results—always use the interval-censored Surv() syntax for this type of data.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.30 17:07:50