R

估計 R 中的生存概率

  • April 11, 2012

基於樣本生存時間,我想估計生存時間的概率, 對於某些特定的,使用 Kaplan-Meier 估計器。有可能做到這一點R嗎?請注意,不一定是事件時間。

您可以使用包中survfit函數的輸出survival並將其提供給stepfun.

km <- survfit(Surv(time, status)~1, data=veteran)
survest <- stepfun(km$time, c(1, km$surv))

Nowsurvest是一個可以隨時評估的函數。

> survest(0:100)
 [1] 1.0000000 0.9854015 0.9781022 0.9708029 0.9635036 0.9635036 0.9635036
 [8] 0.9416058 0.9124088 0.9124088 0.8978102 0.8905109 0.8759124 0.8613139
[15] 0.8613139 0.8467153 0.8394161 0.8394161 0.8175182 0.8029197 0.7883212
[22] 0.7737226 0.7664234 0.7664234 0.7518248 0.7299270 0.7299270 0.7225540
[29] 0.7225540 0.7151810 0.7004350 0.6856890 0.6856890 0.6783160 0.6783160
[36] 0.6709430 0.6635700 0.6635700 0.6635700 0.6635700 0.6635700 0.6635700
[43] 0.6561970 0.6488240 0.6414510 0.6340780 0.6340780 0.6340780 0.6267050
[50] 0.6193320 0.6193320 0.5972130 0.5750940 0.5677210 0.5529750 0.5529750
[57] 0.5456020 0.5456020 0.5456020 0.5382290 0.5382290 0.5308560 0.5308560
[64] 0.5234830 0.5234830 0.5234830 0.5234830 0.5234830 0.5234830 0.5234830
[71] 0.5234830 0.5234830 0.5161100 0.5087370 0.5087370 0.5087370 0.5087370
[78] 0.5087370 0.5087370 0.5087370 0.4939910 0.4939910 0.4866180 0.4866180
[85] 0.4791316 0.4791316 0.4791316 0.4716451 0.4716451 0.4716451 0.4640380
[92] 0.4640380 0.4564308 0.4564308 0.4564308 0.4412164 0.4412164 0.4412164
[99] 0.4412164 0.4257351 0.4179945

引用自:https://stats.stackexchange.com/questions/26247

comments powered by Disqus