[英]Predict probability from Cox PH model
我正在尝试使用Cox模型来预测一段时间后发生故障的概率(称为停止)3。
bladder1 <- bladder[bladder$enum < 5, ]
coxmodel = coxph(Surv(stop, event) ~ (rx + size + number) +
cluster(id), bladder1)
range(predict(coxmodel, bladder1, type = "lp"))
range(predict(coxmodel, bladder1, type = "risk"))
range(predict(coxmodel, bladder1, type = "terms"))
range(predict(coxmodel, bladder1, type = "expected"))
但是,预测函数的输出都不在0-1范围内。 有什么功能或如何使用lp预测和基线危害功能来计算概率?
请阅读帮助页面上的predict.coxph
。 这些都不应该是概率。 一组特定的协变量的线性预测因子是相对于假设(且很可能不存在)情况的对数风险比,其中所有预测因子均值。 “预期”最接近概率,因为它是事件的预计数量,但是它需要指定时间,然后在观察开始时将其除以处于风险中的数量。
对于该帮助页面上提供的predict
示例,您可以看到预测事件的总和接近实际数量:
> sum(predict(fit,type="expected"), na.rm=TRUE)
[1] 163
> sum(lung$status==2)
[1] 165
我怀疑您可能想使用survfit
函数,因为事件的概率为生存的1概率。
?survfit.coxph
一个类似问题的代码出现在这里: 在R中的Cox回归之后,将预测的危害比列添加到数据框中
由于您建议使用膀胱1数据集,因此这将是指定时间= 5的代码
summary(survfit(coxmodel), time=5)
#------------------
Call: survfit(formula = coxmodel)
time n.risk n.event survival std.err lower 95% CI upper 95% CI
5 302 26 0.928 0.0141 0.901 0.956
这将作为列表返回,而生存预测作为名为$surv
的列表元素:
> str(summary(survfit(coxmodel), time=5))
List of 14
$ n : int 340
$ time : num 5
$ n.risk : num 302
$ n.event : num 26
$ conf.int: num 0.95
$ type : chr "right"
$ table : Named num [1:7] 340 340 340 112 NA 51 NA
..- attr(*, "names")= chr [1:7] "records" "n.max" "n.start" "events" ...
$ n.censor: num 19
$ surv : num 0.928
$ std.err : num 0.0141
$ lower : num 0.901
$ upper : num 0.956
$ cumhaz : num 0.0744
$ call : language survfit(formula = coxmodel)
- attr(*, "class")= chr "summary.survfit"
> summary(survfit(coxmodel), time=5)$surv
[1] 0.9282944
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.