Sunteți pe pagina 1din 8

Methods II: R Code for Survival Analysis

First we read-in the bladder tumor data and create a censored outcome for the
first recurrence time.
library(survival)
D <- read.table("btumor.txt", header=T)
D$stop <- pmin(D$futime, D$t1, na.rm=T)
D$delta <- as.numeric(!is.na(D$t1))
Kaplan-Meier survival estimates are computed as follows.
S.KM <- survfit( Surv(stop, delta) , data=D, type="kaplan");
# estimate survival at specified times
print(summary(S.KM, times=c(5, 10, 30)));
Call: survfit(formula = Surv(stop, delta), data = D, type =
"kaplan")
time n.risk n.event survival std.err lower 95% CI upper 95% CI
5
60
24
0.708 0.0503
0.616
0.813
10
48
8
0.607 0.0542
0.510
0.724
30
19
13
0.408 0.0589
0.307
0.541
# plot a Kaplan-Meier survival curve with pointwise 95% CIs
plot(S.KM, xlab="Follow-Up Time", ylab="Fraction Surviving",
main="Kaplan-Meier Survival Estimate");
Survival can be estimated separately in each treatment group.
S.KM2 <- survfit( Surv(stop, delta) ~ Group , data=D,
type="kaplan");
# plot Kaplan-Meier survival curves for two groups, plotted with a legend
plot(S.KM2, xlab="Follow-Up Time", ylab="Fraction Surviving",
main="Kaplan-Meier Survival Estimates", lty=c(1, 2),
legend.text=c("Group 1", "Group 2"));
# estimate survival at specified times in each group
print(summary(S.KM2, times=c(5, 10, 30)));
Call: survfit(formula = Surv(stop, delta) ~ Group, data = D, type =
"kaplan")
Group=1
time n.risk n.event survival std.err lower 95% CI upper 95% CI
5
33
14
0.695 0.0681
0.573
0.842
1

10
30

25
8

6
8

0.558
0.342

0.0742
0.0760

0.430
0.221

0.724
0.528

Group=2
time n.risk n.event survival std.err lower 95% CI upper 95% CI
5
27
10
0.724 0.0743
0.593
0.886
10
23
2
0.669 0.0783
0.532
0.841
30
11
5
0.491 0.0902
0.343
0.704
The Nelson-Aalen estimate of the cumulative hazard is obtained as follows.
# The Nelson-Aalen estimate of the cumulative hazard can be obtained
by # transforming the Fleming-Harrington estimate of survival S.FH
<- survfit( Surv(stop, delta) , data=D, type="fleming");
plot(S.FH$time, -log(S.FH$surv), xlab="Follow-Up Time",
ylab="Fraction Surviving",
main="Nelson-Aalen Estimate of Cumulative Hazard",
ylim=c(0,1.4), type="b");
lines(S.FH$time, -log(S.FH$upper), lty=3);
lines(S.FH$time, -log(S.FH$lower), lty=3);
Its more accurate to draw the estimated cumulative hazard as a step function.
# R provides a function to conveniently draw step functions:
postscript("NA.step.ps");
par(cex.lab=1.5, cex.main=1.5);
plot(stepfun(S.FH$time, c(0, -log(S.FH$surv))), xlab="Follow-Up Time",
ylab="Fraction Surviving", main="Nelson-Aalen Estimate of Cumulative Hazard",
ylim=c(0,1.4));
lines(stepfun(S.FH$time, c(0, -log(S.FH$upper))), lty=3, do.points=F);
lines(stepfun(S.FH$time, c(0, -log(S.FH$lower))), lty=3, do.points=F);
The N-A estimate can also be computed directly from the contents of a
survfit object.
na <- cumsum(S.FH$n.event/S.FH$n.risk)
t <- S.FH$time;
points(t, na, pch="+")
dev.off();

Methods II: SAS Code for Survival Analysis


The tumor data, once read into sas in the usual way, can be prepared for survival
analysis as follows.
data survdata;
set tumor;
2

if rt1 =. then censor=0; else censor = 1;


if rt1 =. then stop = futime; else stop = rt1;
run;
The Kaplan-Meier estimate can now be computed and plotted using
proc lifetest data=survdata outsurv=tumorsurv timelist=5,10,30
plots=(s(name=surv),h(name=haz));
time stop*censor(0);
run;
Pointwise confidence intervals for the estimated survivor function can be
found in the tumorsurv dataset created by the above commands.
proc print data=tumorsurv; run;
Note that SAS compute confidence limits for the KM estimate without the
preferred log transformation used by default in R. Also, SAS has no built-in
functions to compute the Nelson-Aalen estimate of the cumulative hazard, but
it can be directly computed following the example available at
http://www.ats.ucla.edu/stat/sas/examples/asa/asa2.htm.

0.6
0.4
0.0

0.2

Fraction Surviving

0.8

1.0

KaplanMeier Survival Estimate

10

20

30

40

50

60

FollowUp Time

Figure 1: The KM estimate from R, with pointwise 95% CIs computed using
the log-transform.

0.6
0.4
0.2

Group 1
Group 2

0.0

Fraction Surviving

0.8

1.0

KaplanMeier Survival Estimates

10

20

30

40

50

FollowUp Time

Figure 2: KM estimates from R for each treatment group.

60

0.8
0.6
0.4
0.2
0.0

Fraction Surviving

1.0

1.2

1.4

NelsenAalen Estimate of Cumulative Hazard

10

20

30

40

FollowUp Time

Figure 3: The NA estimate from R.

50

60

+++

++

+++
+

+ +

0.8

+
+

0.6

+
+++
+

++

0.4

++
+
+

0.2

+
+
0.0

Fraction Surviving

1.0

1.2

1.4

NelsenAalen Estimate of Cumulative Hazard

+
0

10

20

30

40

50

FollowUp Time

Figure 4: The NA estimate plotted as a step function in R.

60

Figure 5: The KM estimate from SAS.

S-ar putea să vă placă și