Edwin Vivek N
Edwin Vivek N

Reputation: 564

Calculate the Survival prediction using Cox Proportional Hazard model in R

I'm trying to calculate the Survival prediction using Cox Proportional Hazard model in R.

    library(survival)
    data(lung)
    model<-coxph(Surv(time,status ==2)~age + sex + ph.karno + wt.loss, data=lung)
    predict(model, data=lung, type ="expected")

When I use the above code, I get the Cumulative hazard's prediction corresponding to the formula

    h^i(t)=h^0(t)exp(x′iβ^)

But my concern is all about predicting the Survival corresponding to the formula,

    S^i(t)=S^0(t)exp(x′iβ^)

How do I predict the Survival in R? Thanks in Advance.

Upvotes: 4

Views: 8543

Answers (1)

IRTFM
IRTFM

Reputation: 263342

You can use either predict or survfit. With predict you need to give the newdata argument a list with values for all the variables in the model:

predict(model, 
      newdata=list(time=100,status=1,age=60,sex=1, ph.karno=60,wt.loss=15),
      type ="expected")
[1] 0.2007497

There's a plot method for survfit objects:

?survreg
png(); plot(survfit(model)); dev.off()

enter image description here

Upvotes: 1

Related Questions