2

Data

library(survival)
kidney

enter image description here

Model

model = survreg(Surv(time, censored) ~ sex + age, data = kidney)

Call:
survreg(formula = Surv(time, censored) ~ sex + age, data = kidney)

Coefficients:
(Intercept)   sexfemale         age 
 8.44411429 -0.89481679 -0.02170266 

Scale= 1.653512 

Loglik(model)= -122.1   Loglik(intercept only)= -122.7
    Chisq= 1.21 on 2 degrees of freedom, p= 0.547 
n= 76 

How can I predict the survival (plus 95% CI) of both sexes for multiple time points (e.g. 30, 90, 182 days)?

Is there a trick for doing it in different scales (e.g. original time scale, probability)?

Sample code or an example will be much appreciated.

st4co4
  • 445
  • 3
  • 10
  • Probably this Stack Exchange answer will help: https://stats.stackexchange.com/a/159146 – yh6 Mar 04 '21 at 08:58

2 Answers2

1

The owner-accepted answer works only for the Kaplan-Meier estimator, which is not a parametric survival model (AFT). The OP asked how to predict survival rates from a survreg object in R. I had a similar question: how to predict survival rates, from a Weibull model, given discrete times to event?

The predict.survreg function in the survival package does not predict survival rates (probabilities) given discrete times to event (t = 1, 2, 3, ..., 48). Fortunately, for Weibull AFT Models, we could use the pweibull function or the cumulative hazard function to predict survival rates given t.

Method 1: pweibull()

library(survival)

model = survreg(Surv(time, status) ~ sex + age, data = kidney,
                dist="weibull")

time_days = c(30, 90, 182)

newdat <- data.frame(sex=1, age=44)

mu_hat <- predict(model, newdata=newdat, type="link")

surv_hat <- 1 - pweibull(time_days, 
                         shape=1/model$scale,
                         scale=exp(mu_hat))

surv_hat

Method 2: cumulative hazard

predict_survival_weibull <- function(object, newdata, t){
  mu_hat <- predict(object, newdata=newdata, type="link")
  
  cum_hazard <- (t / exp(mu_hat))^(1/object$scale)
  
  surv <- exp(-cum_hazard)
  
  return(surv)
}

predict_survival_weibull(model, newdat, t=time_days)
William Chiu
  • 388
  • 3
  • 19
0

You can use survminer package. Example:

library(survival)
library(survminer)

f1 <- survfit(Surv(time, status) ~ sex, data = kidney)

res.sum <- surv_summary(f1, data = kidney)

# define desired time points
times <- c(30, 90, 182)

summary(f1,times)

enter image description here

TarJae
  • 72,363
  • 6
  • 19
  • 66
  • Thank you! If you add "age" as a coviariate, this will give predictions for both sexes and all ages. Possible to get predictons for both sexes at mean/median age? – st4co4 Mar 04 '21 at 10:19
  • In my point of view: What you need is a cox regression. Here you can fit a model with more then one variable. And with the coefficients you can predict the impact of age and sex on survival on desired time points. With one Kaplan Meier analysis in my point of view there is no possibility to predict the impact of two variables on survival. This is a new question. Please accept this answer (if it solves your first problem) and start an new question with extension of this answer. – TarJae Mar 05 '21 at 02:32
  • the OP is using a Weibull AFT model (surveg), not Kaplan-Meier (survfit). – William Chiu May 16 '22 at 08:08