Yok*_*oki 0 r cox-regression survival-analysis
我试图使用cox模型来预测一段时间后失败的概率(名为stop)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"))
Run Code Online (Sandbox Code Playgroud)
但是,预测函数的输出都不在0-1范围内.是否有任何功能或如何使用lp预测和基线危险函数来计算概率?
请阅读帮助页面predict.coxph.这些都不应该是概率.特定协变量集的线性预测因子是相对于假设(并且很可能不存在)情况的对数危险比,其具有所有预测值的均值."预期"与概率最接近,因为它是预测的事件数量,但它需要指定时间,然后除以观察开始时的风险数量.
对于该帮助页面上提供的示例predict,您可以看到预测事件的总和接近实际数字:
> sum(predict(fit,type="expected"), na.rm=TRUE)
[1] 163
> sum(lung$status==2)
[1] 165
Run Code Online (Sandbox Code Playgroud)
我怀疑你可能想要使用该survfit功能,因为事件的概率是1概率的生存.
?survfit.coxph
Run Code Online (Sandbox Code Playgroud)
类似问题的代码出现在这里,尽管与这个问题一样,它既没有被接受也没有被投票,所以有人想知道是否有人关心:在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
Run Code Online (Sandbox Code Playgroud)
这将作为列表以生存预测作为列表元素返回$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
Run Code Online (Sandbox Code Playgroud)