I'm trying to replicate the results proc lifetestin the SAS using the function R ( survivaland survifit) - and especially calculate 95% confidence interval for the median survival time.
I know that SAS uses the following formula to calculate the confidence interval for the median:
*abs(g(S(t))-g(1-0.5)/g'(S(t))σ(S(t)))<=1.96*
with g '(x), which is the first derivative of g (x) and σ (S (t)), is the standard error of the survival curve, and the default conversion of g to SAS is g(x)=log(-log(x))
Thus, the formula inside the absolute becomes:
(log(-log(S(t)))-log(-log(0.5)))*S(t)*log(S(t))/σ(S(t))
Here is an example of using data kidneyfrom a package survival:
fit1 = survfit(Surv(kidney$time,kidney$status)~kidney$sex, data=kidney)
print(fit1)
BCinds<-abs((log(-log(fit1$surv))-log(-log(0.5)))*fit1$surv*log(fit1$surv)/fit1$std.err)<=1.96
when I run the code obtained from print(fit1):
n events median 0.95LCL 0.95UCL
kidney$sex=1 20 18 22 12 63
kidney$sex=2 56 40 130 66 190
, BCinds, CI (9, 154) = 1, = 2 CI - (39, 511).
sex=1 95%CI: (9, 154) sex=2 95%CI: (39, 511)
SAS :
ods graphics on;
proc lifetest data=work.test
plots=survival(nocensor cb=hw cl strata=panel);
strata sex/group=sex;
time time*status(0);
run;
ods graphics off;
:
sex=1: median=22 and 95%CI: (12, 30)
sex=2: median=130 and 95%CI: (58,185)
, ? , ? , , .
!