# Get survival rates from a Cox regression in R

I am fairly new to survival analysis and am playing around in R. I have a fairly simple Cox model

library(survival)
data(kidney)
cox<-coxph(Surv(time, type)~delta, data=kidney)
baseline <- basehaz(cox , centered=FALSE)
cox.survfit<- survfit(cox)
plot(cox.survfit)


My question is how do i calculate the survival rates myself without calling the survfit function. I tried to look at this stackoverflow post which i kind of understand but am not exactly able to turn it into code.

I have the h0 from basehaz but I am not sure about the rest of the calculations. Any ideas?

EDIT:- Added the kidney dataset in csv format(in case you don't have the same columns in your kidney datset ) :-

"time","delta","type"
1.5,1,1
3.5,1,1
4.5,1,1
4.5,1,1
5.5,1,1
8.5,1,1
8.5,1,1
9.5,1,1
10.5,1,1
11.5,1,1
15.5,1,1
16.5,1,1
18.5,1,1
23.5,1,1
26.5,1,1
2.5,0,1
2.5,0,1
3.5,0,1
3.5,0,1
3.5,0,1
4.5,0,1
5.5,0,1
6.5,0,1
6.5,0,1
7.5,0,1
7.5,0,1
7.5,0,1
7.5,0,1
8.5,0,1
9.5,0,1
10.5,0,1
11.5,0,1
12.5,0,1
12.5,0,1
13.5,0,1
14.5,0,1
14.5,0,1
21.5,0,1
21.5,0,1
22.5,0,1
22.5,0,1
25.5,0,1
27.5,0,1
0.5,1,2
0.5,1,2
0.5,1,2
0.5,1,2
0.5,1,2
0.5,1,2
2.5,1,2
2.5,1,2
3.5,1,2
6.5,1,2
15.5,1,2
0.5,0,2
0.5,0,2
0.5,0,2
0.5,0,2
0.5,0,2
0.5,0,2
0.5,0,2
0.5,0,2
0.5,0,2
0.5,0,2
1.5,0,2
1.5,0,2
1.5,0,2
1.5,0,2
2.5,0,2
2.5,0,2
2.5,0,2
2.5,0,2
2.5,0,2
3.5,0,2
3.5,0,2
3.5,0,2
3.5,0,2
3.5,0,2
4.5,0,2
4.5,0,2
4.5,0,2
5.5,0,2
5.5,0,2
5.5,0,2
5.5,0,2
5.5,0,2
6.5,0,2
7.5,0,2
7.5,0,2
7.5,0,2
8.5,0,2
8.5,0,2
8.5,0,2
9.5,0,2
9.5,0,2
10.5,0,2
10.5,0,2
10.5,0,2
11.5,0,2
11.5,0,2
12.5,0,2
12.5,0,2
12.5,0,2
12.5,0,2
14.5,0,2
14.5,0,2
16.5,0,2
16.5,0,2
18.5,0,2
19.5,0,2
19.5,0,2
19.5,0,2
20.5,0,2
22.5,0,2
24.5,0,2
25.5,0,2
26.5,0,2
26.5,0,2
28.5,0,2

• The variable type and delta are not in the kidney data set I get from survival Jun 30 '15 at 17:56
• hmm interesting...i added my kidney dataset in the question... Jun 30 '15 at 18:29

basehaz does not actually give you $\hat{h}_0(t)$ but rather $\hat{H}_0(t)$, an estimate of the baseline cumulative hazard function. To get an estimate of the baseline hazard you need to take the differences or "jumps" in the cumulative hazard. Once you obtain this function you can then apply the standard Cox formula $\hat{h}_0(t) \exp(\beta^T x_i)$ to get an estimate of $\hat{h}_i(t)$.
• you are right but i wanted to create the survival curve ....which i was able to with the following "plot(baseline$time , exp(-baseline$hazard * exp(testdata\$delta * -0.2996697)))"......0.2996697 being the coeff of the column "delta" Jul 2 '15 at 22:06