Académique Documents
Professionnel Documents
Culture Documents
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();
0.6
0.4
0.0
0.2
Fraction Surviving
0.8
1.0
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
10
20
30
40
50
FollowUp Time
60
0.8
0.6
0.4
0.2
0.0
Fraction Surviving
1.0
1.2
1.4
10
20
30
40
FollowUp Time
50
60
+++
++
+++
+
+ +
0.8
+
+
0.6
+
+++
+
++
0.4
++
+
+
0.2
+
+
0.0
Fraction Surviving
1.0
1.2
1.4
+
0
10
20
30
40
50
FollowUp Time
60