Non-parametric estimators

Nelson-Aalen estimator

library(survival)
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.5.1     ✔ tibble    3.2.1
✔ lubridate 1.9.3     ✔ tidyr     1.3.1
✔ purrr     1.0.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors

In the period 1962-77 a total of \(205\) patients with malignant melanoma (cancer of the skin) were operated at Odense University hospital in Denmark. A number of covariates were recorded at operation, and the patients were followed up until death or censoring at the end of the study at December 31, 1977. We will study death from malignant melanoma considering death from other causes as censorings. (Source: Andersen, Borgan, Gill & Keiding, Springer, 1993.)

You may read the data into R by the command:

melanoma = read.table("https://www.med.uio.no/imb/english/research/centres/ocbe/courses/imb9335/melanoma.txt",header=T) %>% 
  as_tibble()

The data are organized with one line for each of the 205 patients, and with the following variables in the seven columns:

  • status: status (1=death from disease, 2=censored, 4=death from other cause)
  • lifetime: life time from operation in years
  • ulcer: ulceration (1=present, 2=absent)
  • thickn: tumor thickness in mm
  • sex: 1=female, 2=male
  • age: age at operation in years
  • grthick: grouped tumor thickness [1: 0-1 mm (i.e. below 2 mm), 2: 2-4 mm (i.e. at least 2 mm, but below 5 mm) , 3: 5+ mm (i.e. 5 mm or more)]

The following commands provide a Nelson-Aalen plot for female melanoma patients. (The survival-library has to be loaded.)

surv.f = survival::survfit(Surv(lifetime,status==1) ~ 1, data = melanoma, 
  subset = (sex == 1), ctype = 1) # ctype = 1 means NA estimator
surv.m = survival::survfit(Surv(lifetime,status==1) ~ 1, data = melanoma, 
  subset = (sex == 2), ctype = 1)

plot(surv.f, fun="cumhaz", mark.time=FALSE, conf.type="plain", xlim=c(0,10), ylim=c(0,0.80), main="Females", xlab="Years since operation", ylab="Cumulative hazard")

plot(surv.m, fun="cumhaz", mark.time=FALSE, conf.type="plain", xlim=c(0,10), ylim=c(0,0.80), main="Males", xlab="Years since operation", ylab="Cumulative hazard")

  1. Perform the commands and interpret the Nelson-Aalen plot.

  2. Make a Nelson-Aalen plot for males and compare with the plot for females.

To plot the Nelson-Aalen estimates for both genders in the same figure, we may give the commands:

surv.sex = survival::survfit(Surv(lifetime,status==1) ~ strata(sex), data=melanoma, ctype=1)

plot(surv.sex, fun="cumhaz", mark.time=FALSE, lty=1:2, xlim=c(0,10), ylim=c(0,0.80), main="Gender", xlab="Years since operation", ylab="Cumulative hazard")

legend("topleft", c("Females","Males"), lty=1:2)

  1. Perform the commands and inspect the plot.
  • Straight slope => constant hazard independent of gender
  1. Make Nelson-Aalen plots for patients with ulceration present and absent and interpret the plots. (Ulceration is “present” if the surface of the tumor viewed in a microscope show signs of ulcers and “absent” otherwise.)
surv.ulcer = survival::survfit(Surv(lifetime,status==1) ~ strata(ulcer), data=melanoma, ctype=1)

plot(surv.ulcer, fun="cumhaz", mark.time=FALSE, lty=1:2, xlim=c(0,10), ylim=c(0,0.80), main="Ulceration", xlab="Years since operation", ylab="Cumulative hazard")

legend("topleft", c("Present","Absent"), lty=1:2)

  1. Make Nelson-Aalen plots for the three thickness groups 0-1 mm, 2-4 mm, 5+ mm and interpret the plots.
surv.grthick = survival::survfit(Surv(lifetime,status==1) ~ strata(grthick), data=melanoma, ctype=1)

plot(surv.grthick, fun="cumhaz", mark.time=FALSE, lty=1:3, xlim=c(0,10), 
  ylim=c(0,0.80), main="Tumor thickness", xlab="Years since operation", ylab="Cumulative hazard")

legend("topleft", c("0-1 mm","2-4 mm", "5+ mm"), lty=1:3)

Kaplan-Meier and log-rank test

In this exercise, we will use the Kaplan-Meier estimator and the log-rank test to study survival for the melanoma patients.

We will consider Kaplan-Meier estimates for the mortality from malignant melanoma treating death from other causes as censoring.

We may compute and plot the Kaplan-Meier estimate of the survival distribution for male patients by the commands (you need to load the survival-library)

fit.m=survfit(Surv(lifetime,status==1)~1,data=melanoma, subset=(sex==2), conf.type="plain")
plot(fit.m, mark.time=FALSE, xlab="Years after operation", main = "Males")
abline(h = 0.75, col="red")
abline(h = 0.5, col="blue")

To obtain a summary of the results, you may give the command:

#?quantile.survfit
summary(fit.m)
Call: survfit(formula = Surv(lifetime, status == 1) ~ 1, data = melanoma, 
    subset = (sex == 2), conf.type = "plain")

  time n.risk n.event survival std.err lower 95% CI upper 95% CI
 0.507     76       1    0.987  0.0131        0.961        1.000
 0.559     75       1    0.974  0.0184        0.938        1.000
 0.575     74       1    0.961  0.0223        0.917        1.000
 0.636     73       1    0.947  0.0256        0.897        0.998
 1.167     72       1    0.934  0.0284        0.878        0.990
 1.449     70       1    0.921  0.0310        0.860        0.982
 1.701     69       1    0.908  0.0333        0.842        0.973
 1.723     68       1    0.894  0.0354        0.825        0.964
 1.805     67       1    0.881  0.0373        0.808        0.954
 1.967     66       1    0.867  0.0390        0.791        0.944
 2.060     65       1    0.854  0.0407        0.774        0.934
 2.134     64       1    0.841  0.0422        0.758        0.923
 2.173     63       1    0.827  0.0435        0.742        0.913
 2.649     62       1    0.814  0.0448        0.726        0.902
 2.677     61       1    0.801  0.0461        0.710        0.891
 2.852     60       1    0.787  0.0472        0.695        0.880
 2.910     59       1    0.774  0.0482        0.680        0.869
 2.945     58       1    0.761  0.0492        0.664        0.857
 3.364     57       1    0.747  0.0501        0.649        0.846
 3.932     55       1    0.734  0.0510        0.634        0.834
 4.126     53       1    0.720  0.0519        0.618        0.822
 4.153     51       1    0.706  0.0528        0.602        0.809
 4.340     50       1    0.692  0.0536        0.587        0.797
 4.630     47       1    0.677  0.0544        0.570        0.784
 5.647     32       1    0.656  0.0567        0.545        0.767
 5.762     29       1    0.633  0.0591        0.517        0.749
 6.542     25       1    0.608  0.0619        0.487        0.729
 7.027     22       1    0.580  0.0650        0.453        0.708
 7.622     21       1    0.553  0.0675        0.420        0.685
  1. Perform these commands and interpret the Kaplan-Meier plot. Determine the lower quartile of the survival distribution for males with 95% confidence limits using the output from the summary-command. (Note that the lower quartile corresponds to 75% survival probability.)
  • Look at the first time the Survival probability falls below \(75\%\)
  1. We may obtain the quartiles of the survival distribution for males by the command
quantile(fit.m)
$quantile
      25       50       75 
3.364384       NA       NA 

$lower
      25       50       75 
2.172603 6.542466       NA 

$upper
      25       50       75 
5.761644       NA       NA 

Perform this command and compare with the result you obtained in a).

  1. Make a Kaplan-Meier plot for females, and determine the lower quartile for females with 95% confidence limits (if possible). Compare with the results for males.
fit.f=survfit(Surv(lifetime,status==1)~1,data=melanoma, subset=(sex==1), conf.type="plain")
plot(fit.f, mark.time=FALSE, xlab="Years after operation", main = "Females")

quantile(fit.f)
$quantile
      25       50       75 
8.334247       NA       NA 

$lower
     25      50      75 
5.29589      NA      NA 

$upper
25 50 75 
NA NA NA 
  1. Use the log-rank test to test the null hypothesis that males and females have the same mortality from malignant melanoma:
survdiff(Surv(lifetime,status==1) ~ sex,data=melanoma)
Call:
survdiff(formula = Surv(lifetime, status == 1) ~ sex, data = melanoma)

        N Observed Expected (O-E)^2/E (O-E)^2/V
sex=1 126       28     37.1      2.25      6.47
sex=2  79       29     19.9      4.21      6.47

 Chisq= 6.5  on 1 degrees of freedom, p= 0.01 

What may you conclude from the test?

  1. Make Kaplan-Meier plots for patients with ulceration present and absent and interpret the results. Is it possible to estimate the lower quartile for both ulceration groups? Estimate the lower quartile with confidence limits if possible. Is there a significant difference in cancer mortality for patients with ulceration present and absent?
plot(surv.ulcer, mark.time=FALSE, lty = 1:2, xlab="Years after operation", main = "Ulceration")
legend("bottomleft", c("Present","Absent"), lty=1:2)

quantile(surv.ulcer)
$quantile
                            25       50 75
strata(ulcer)=ulcer=1 2.690411 8.334247 NA
strata(ulcer)=ulcer=2       NA       NA NA

$lower
                            25       50 75
strata(ulcer)=ulcer=1 2.060274 4.728767 NA
strata(ulcer)=ulcer=2 7.621918       NA NA

$upper
                            25 50 75
strata(ulcer)=ulcer=1 4.126027 NA NA
strata(ulcer)=ulcer=2       NA NA NA
# NO STRATA IN THE FORMULA NEEDED!
survdiff(formula = Surv(lifetime, status == 1) ~ ulcer, data = melanoma)
Call:
survdiff(formula = Surv(lifetime, status == 1) ~ ulcer, data = melanoma)

          N Observed Expected (O-E)^2/E (O-E)^2/V
ulcer=1  90       41     21.2      18.5      29.6
ulcer=2 115       16     35.8      10.9      29.6

 Chisq= 29.6  on 1 degrees of freedom, p= 5e-08 
  1. Make Kaplan-Meier plots for the three thickness groups 0-1 mm, 2-4 mm, 5+ mm and interpret the plots. Estimate the lower quartile with confidence limits if possible. Is there a significant difference in cancer mortality between the three thickness groups?
  • Same procedure as above!!!