我正在使用
survival
包进行竞争风险分析,并希望使用预测进行模拟。
我计划从[0,1]中随机抽取一个均匀的x,从与x相交的生存曲线中找出终止时间;然后从[0,hazard1+hazard2]中随机抽取另一个y,以决定选择哪个结束状态。
我可以提取生存曲线,但不知道每个竞争状态的危害是什么。我复制了
生存
包装如下:
data(mgus2)
cfit1 <- coxph(Surv(etime, event=="pcm") ~ age + sex + mspike, mgus2)
etime <- with(mgus2, ifelse(pstat==0, futime, ptime))
event <- with(mgus2, ifelse(pstat==0, 2*death, 1))
event <- factor(event, 0:2, labels=c("censor", "pcm", "death"))
cfit2 <- coxph(Surv(etime, event=="death") ~ age + sex + mspike, mgus2)
cfit1 <- coxph(Surv(etime, event=="pcm") ~ age + sex + mspike, mgus2)
newdata <- expand.grid(sex=c("F", "M"), age=c(60, 80), mspike=1.2)
newdata
temp <- matrix(list(), 3,3)
dimnames(temp) <- list(from=c("Entry", "PCM", "Death"),
to =c("Entry", "PCM", "Death"))
temp[1,2] <- list(survfit(cfit1, newdata, std.err=FALSE))
temp[1,3] <- list(survfit(cfit2, newdata, std.err=FALSE))
csurv <- survfit(temp, p0 =c(1,0,0))
看起来像是
csurv$pstate
包含生存曲线和累积危险。但我不理解他们的关系。我试图通过将两个累积危险相加来避免存活,并取下如下经验值,但结果与存活曲线不同。
exp(-(csurv$pstate[,2]+csurv$pstate[,3]))
csurv$pstate[,1]
它们之间有什么关系?如何使用它们进行模拟?