在生存模型中使用时间依赖性协变量的预测

时间:2015-01-27 17:47:44

标签: r

简单的问题,在寻找预测时,如何在newdata提供的data.frame中指定时间相关的协变量?

换句话说,我适合具有时间依赖协变量的模型:

cfit <- coxph(Surv(tstart, tstop, status) ~ treat + sex + age +
            inherit + cluster(id), data=cgd)

现在,我想为患者创建预测,但使用该患者的更新数据。换句话说,考虑到我们观察到某些时间间隔内某些协变量的变化,它们的生存概率是多少?

我可以预测患者的生存情况,如下所示:

survfit(cfit, newdata=data.frame(treat = "placebo", age = 12, sex ="male", inherit = "X-linked"))$surv

但这不允许我随着患者观察开始的时间过去更新预测,允许纳入更新的协变量。

2 个答案:

答案 0 :(得分:2)

详情请参阅帮助页面?survfit.coxph的详细信息部分的第2段。基本上,您需要一个id列来显示哪些行属于同一个人,然后对于每一行,您需要开始时间,结束时间以及该时间段内协变量的值。预测个体的每个时间段在newdata中都有自己的行(因此时间段不应重叠)。

答案 1 :(得分:0)

R在我上面的评论中有一个可复制的示例:

## Install package that has a dataset with data applicable for this problem
install.packages("ipw")
library(ipw)

## Load data
head(haartdat,n=100)

## Fit model, with time varying covariate cd4.sqrt
model.2 <- coxph(Surv(tstart, fuptime, event) ~ sex + age + cd4.sqrt + cluster(patient), data = haartdat)

## Create dataframe of variables (one row)
covs <- data.frame(age = 25,sex = 1,cd4.sqrt = 24)
covs
## Get survival probabilities for these variables at baseline
summary(survfit(model.2, newdata = covs, type = "aalen"))


## Now create two 'newdata' sets of covariates, for time points up to 1900
## covs.2 the data is same at all 20 time points
covs.2 <- cbind(rep(1,20),rbind(covs,covs,covs,covs,covs,covs,covs,covs,covs,covs,covs,covs,covs,covs,covs,covs,covs,covs,covs,covs))
colnames(covs.2)[1] <- "patient"
covs.2 <- data.frame(covs.2)
covs.2$tstart <- seq(-100,1800,100)
covs.2$fuptime <- seq(0,1900,100)
covs.2$event <- rep(0,20)

## covs.3 has varying cd4.sqrt
covs.3 <- cbind(rep(2,20),rbind(covs,covs,covs,covs,covs,covs,covs,covs,covs,covs,covs,covs,covs,covs,covs,covs,covs,covs,covs,covs))
colnames(covs.3)[1] <- "patient"
covs.3 <- data.frame(covs.3)
covs.3$tstart <- seq(-100,1800,100)
covs.3$fuptime <- seq(0,1900,100)
covs.3$event <- rep(0,20)
covs.3$cd4.sqrt <- seq(20.25,25,0.25)

## Combine into one dataset
covs.4 <- rbind(covs.2,covs.3)
covs.4

## Create survival probabilities, with the id = argument
summary(survfit(model.2, newdata = covs.4, type = "aalen", id = patient))