Survival Curve from Cox Regression I want to estimate the survival curve from Cox Regression. In another question I found the following formula:
$$\hat{H}_0(t)=\int_0^t\frac{dN(\tau)}{\sum_i \exp(\beta^T x_i)Y_i(\tau)}$$
(Estimating survival curves from Cox regression results)
I guess I am getting this terribly wrong, I am self studying and don't really grasp the meaning of the formula, but I tried:
If I have a dummy dataset like (From Thereneau Modeling Survival Data). I inserted how I would (my best guess) do the calculation for the estimated $\beta=2$.




time
event
x
denominator
numerator
$\hat H_0$




1
1
1
4
6
6/4


1
0
1
2
6
6/2


6
1
1
2
4
4/2


6
1
0
0
4
?


8
0
0
0
2



9
1
0
0
1





I would appreciate any help pointing me in the right direction.
 A: You started well, putting cases in order of event/censoring times, and choosing a short set of example data that illustrates the critical issues. Here's how to proceed, with my attempt at verbal descriptions of the symbols, which can be quite confusing at first.
Go time point by time point sequentially from first to last event time, stopping to do a calculation at each event time, and then adding the result to the previous results. Cumulative hazard at $t=0$ is 0.
At each event time $\tau$, the numerator $dN(\tau)$ is the number of cases having events at time $\tau$. So in your data, that's 1 at $\tau=1$, 2 at $\tau=6$, and 1 at $\tau=9$. There is no event at $\tau=8$, so $dN(8)=0$. No calculation needs to be done at that time, as only a 0 would be added.
The terminology in the denominator can be particularly confusing. The sum is over all cases $i$. $Y_i(\tau)$ is an indicator value, equal to 1 if case $i$ is at risk at time $\tau$, and 0 otherwise. What that means in practice is: just do the sum for the cases still at risk at time $\tau$, as all the others just provide values of 0. The $\exp(\beta^Tx_i)$ factor is the exponential of the linear predictor for case $i$. In your situation, for $x_i=0$ that's a value of 1; for $x_i=1$ and $\beta=2$ it's $\exp(2) \approx 7.389$. You sum those up over all cases at risk at time $\tau$ to get the denominator.
Now just go through the tedious task of putting it all together by hand. I'll do this out for all 3 event times here, as each makes a different point about the calculation.
At $\tau =1$, the numerator $dN(1)$ is 1. The denominator is the sum of exponentiated linear-predictor values for all cases at risk at $\tau =1$, or all cases. If these 6 were your only cases, then the sum in the denominator (with 3 having $x=0$ and three having $x=1$) would be 3*1 + 3*7.389, or 25.167. The ratio (1/25.167) is also the estimated cumulative baseline hazard through $t=1$.
At $\tau=6$, the numerator $dN(6)$ is 2. The denominator sum now only includes the 4 cases still at risk, 1 with $x=1$ and 3 with $x=0$. You have 3*1 + 1*7.389 in the denominator sum, or 10.389. The ratio (2/10.389) is the added contribution to cumulative hazard at $\tau=6$. You add that value to the prior value to get the cumulative hazard through $t=6$. (An integral over a discrete $dN(\tau)$ is just the sum over all the individual values.)
There is no event at $\tau=8$, so proceed to $\tau=9$. There is 1 event, so the numerator is 1. There is now only one case at risk, this case, with $x=0$ and thus a denominator of 1. That's the added contribution to cumulative hazard at $\tau=9$. Add that to the prior value of cumulative hazard and you have the cumulative hazard through the last event time, $t=9$. You have no more events, so you are done with your estimate of the baseline cumulative hazard.
This Aalen-Breslow baseline hazard estimate $\hat H_0(t)$ is for a linear-predictor value of 0, or $x=0$ in this case. For a different set of covariate values $x$, you multiply the baseline hazard by the corresponding hazard ratio to get, say, $\hat H_x(t)$. The estimated survival curves are then given by $S_0(t)=-\exp \hat H_0(t)$ and $S_x(t)=-\exp \hat H_x(t)$.
