根据@ shadow的评论,参数估计的CI基于整个数据集,如果您需要年龄条件CI,则需要对数据进行子集化。相反,如果您希望以一组协变量(包括年龄)为条件生成预期的生存曲线,那么您就是这样做的:
# Create a dummy dataset df <- data.frame(sex = sample(c(T,F),100,T), age = 50 + rnorm(100)*10, foo = sample(c('a','b','c'),100,T), bar = sample(c('x','y','z'),100,T), status = sample(c(T,F),100,T), start = 0,# required for the survfit with `individual = TRUE` time = -log(runif(100))) # fit the A coxph model in your full dataset data cox <- coxph(Surv(start,time, status) ~ sex + age + foo + bar, data=df) # create a data.frame with all the variables used in the formula newData <- data.frame(sex = T, age = 55, foo = sample(c('a','b','c'),1), bar = sample(c('x','y','z'),1), status = T,# required but unused start = 0,# required but unused time = 1)# required but unused # get a prediction from the fitted model, specifiying 'individual = TRUE' pred <- survfit(cox, newdata=data.frame(newData),individual =TRUE) # plot the survival curves matplot(x = cbind(pred$"time"), y = cbind(pred$surv, pred$upper, pred$lower), type = 'l', lty= c(1,2,2), main = 'Predicted Survial with 95% CI')
你也可以去检查一下 unclass(pred) 和 summary(pred) 。
unclass(pred)
summary(pred)