Setting Up the Hazard and Survival Curve Estimation in the `Hypothetical' Survival Data Example of Problem 4.7 =================================================== 10/13/03 > Fram4.7 = cbind.data.frame(Entr.age = c(58,58,59,60,60,61,61,62,62,62,63,63,64,66,66,67,67,67,68,69, 69,69,70,70,70,71,72,72,73,73), Exit.age = c(60,63,69,62,65,72,69,73,66,65,68,74,71,68,69,70,77,69,72,79, 72,70,76,71,78,79,76,73,80,74), Dth=c(1,1,0,1,1,0,0,0,1,1,1, 0,1,1,1,1,1,1,1,0,1,1,0,1,0,0,1,1,0,1)) ### This had to be entered by hand: it is not on the book webpage. ## Now we need to create a data-frame consisting of unique ## death-times, deaths, and numbers-at-risk for the LEFT-TRUNCATED ## dataset where each individual is left-truncated at "Entry Age" ## and dies or is censored at "Exit age". ## We are treating discrete-time survival here, since we have no information about exposure-times within years of age. So we act as though entry and exit, including death, can occur only on an individual's birthday in a given year of age. > ages4.7 = sort(unique(Fram4.7[Fram4.7$Dth==1,2])) dths4.7 = tapply(rep(1,sum(Fram4.7$Dth==1)), Fram4.7[Fram4.7$Dth==1,2],sum) atrsk4.7T = numeric(length(ages4.7)) > for(i in 1:length(ages4.7)) atrsk4.7T[i] = sum(Fram4.7[,2] >= ages4.7[i] & Fram4.7[,1] < ages4.7[i]) ## Now, for example, an analogue of the Nelson-Aalen estimator ## is obtained by cumulatively summing up dths/atrsk, and the ## standard error formula is essentially as before. > Fram4.7T = cbind.data.frame(ages = ages4.7, dths = dths4.7, atrsk = atrsk4.7T, CumHaz = round(cumsum(dths4.7/atrsk4.7T),3), Haz.SE = round(sqrt(cumsum(dths4.7/atrsk4.7T^2)),3)) ### You can verify this by hand !! > Fram4.7T ages dths atrsk CumHaz Haz.SE 60 60 1 3 0.333 0.333 62 62 1 6 0.500 0.373 63 63 1 8 0.625 0.393 65 65 2 10 0.825 0.418 66 66 1 8 0.950 0.436 68 68 2 12 1.117 0.452 69 69 2 11 1.298 0.470 70 70 2 10 1.498 0.490 71 71 2 11 1.680 0.507 72 72 2 10 1.880 0.526 73 73 1 9 1.991 0.538 74 74 1 9 2.103 0.549 76 76 1 7 2.245 0.568 77 77 1 5 2.445 0.602 ### Now we could estimate survival function directly ### for the increasing ages as given in Fram4.7T. ### (Cannot use survfit directly because there are ### multiple deaths at some times ... > Scurv = cumprod(1- Fram4.7T$dths/Fram4.7T$atrsk) round(Scurv,3) 60 62 63 65 66 68 69 70 71 0.667 0.556 0.486 0.389 0.340 0.284 0.232 0.186 0.152 72 73 74 76 77 0.121 0.108 0.096 0.082 0.066