简体   繁体   中英

How to calculate survival probabilities in R?

I am trying to fit a parametric survival model. I think I managed to do so. However, I could not succeed in calculating the survival probabilities:

library(survival)
zaman  <- c(65,156,100,134,16,108,121,4,39,143,56,26,22,1,1,5,65,
56,65,17,7,16,22,3,4,2,3,8,4,3,30,4,43)
test <- c(rep(1,17),rep(0,16))
WBC <- c(2.3,0.75,4.3,2.6,6,10.5,10,17,5.4,7,9.4,32,35,100,
100,52,100,4.4,3,4,1.5,9,5.3,10,19,27,28,31,26,21,79,100,100)
status <- c(rep(1,33))
data <- data.frame(zaman,test,WBC)

surv3 <- Surv(zaman[test==1], status[test==1])
fit3 <- survreg( surv3 ~ log(WBC[test==1]),dist="w")

On the other hand, no problem at all while calculating the survival probabilities using the Kaplan-Meier Estimation:

fit2 <- survfit(Surv(zaman[test==0], status[test==0]) ~ 1)
summary(fit2)$surv

Any idea why?

You can get the predicted probabilities from a survreg object with predict :

predict(fit3)

If you're interested in combining this with the original data, and also in the residual and standard errors of the predictions, you can use the augment function in my broom package:

library(broom)
augment(fit3)

A full analysis might look something like:

library(survival)
library(broom)
data <- data.frame(zaman, test, WBC, status)
subdata <- data[data$test == 1, ]

fit3 <- survreg( Surv(zaman, status) ~ log(WBC), subdata, dist="w")
augment(fit3, subdata)

With the output:

   zaman test    WBC status   .fitted    .se.fit     .resid
1     65    1   2.30      1 115.46728  43.913188 -50.467281
2    156    1   0.75      1 197.05852 108.389586 -41.058516
3    100    1   4.30      1  85.67236  26.043277  14.327641
4    134    1   2.60      1 108.90836  39.624106  25.091636
5     16    1   6.00      1  73.08498  20.029707 -57.084979
6    108    1  10.50      1  55.96298  13.989099  52.037022
7    121    1  10.00      1  57.28065  14.350609  63.719348
8      4    1  17.00      1  44.47189  11.607368 -40.471888
9     39    1   5.40      1  76.85181  21.708514 -37.851810
10   143    1   7.00      1  67.90395  17.911170  75.096054
11    56    1   9.40      1  58.99643  14.848751  -2.996434
12    26    1  32.00      1  32.88935  10.333303  -6.889346
13    22    1  35.00      1  31.51314  10.219871  -9.513136
14     1    1 100.00      1  19.09922   8.963022 -18.099216
15     1    1 100.00      1  19.09922   8.963022 -18.099216
16     5    1  52.00      1  26.09034   9.763728 -21.090343
17    65    1 100.00      1  19.09922   8.963022  45.900784

In this case, the .fitted column is the predicted probabilities.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM