Marty Panama
Marty Panama

Reputation: 21

Compute probabilities after coxph

I'm trying to figure out how to calculate some probabilities after running survival analysis using coxph from the survival package. I've read a bunch of posts but I can't seem to find one that answers this particular question.

I have a model like

coxph(Surv(time, event) ~ x1 + x2)  

And I'm interested in computing the probability that an individual who has lived until time t will die before time t+1.

Is this possible? I think I just need to find the estimate of the hazard function at time t, but I'm wondering how to compute this. Thanks for any advice.

Upvotes: 0

Views: 985

Answers (1)

Saradamani
Saradamani

Reputation: 210

Yes this can be done by the following code:

cox.fit<- coxph(Surv(df$time,df$Status)~X1+X2+X3+X4))
summary(cox.fit)
predicted_cox.fit<-survfit(cox.fit)
Exp_Beta<- predict(predicted_cox.fit,type='lp')
basehaz_cox<-basehaz(cox.fit)

Predicted_probability_at_t1 <- as.data.frame((exp(-basehaz_cox(t1))^(exp(Exp_Beta))

Upvotes: -1

Related Questions