Eduard Szöcs

Data in Environmental Science and Eco(toxico-)logy

Quantitative Ecotoxicology, Page 39, Example 2.3, Kaplan–Meier estimates

Get the data from here and read it into R:

SULFATE <- read.table("p39.csv", header = TRUE, sep = ";")

Convert left to right censored data:

SULFATE$FLIP <- abs(SULFATE$SO4 - 8)
SULFATE
##    SO4 FLAG FLIP
## 1  7.9    1  0.1
## 2  7.7    1  0.3
## 3  7.1    1  0.9
## 4  6.9    1  1.1
## 5  6.5    1  1.5
## 6  6.2    1  1.8
## 7  6.1    1  1.9
## 8  5.7    1  2.3
## 9  5.6    1  2.4
## 10 5.2    1  2.8
## 11 4.5    1  3.5
## 12 4.1    1  3.9
## 13 4.0    1  4.0
## 14 3.6    1  4.4
## 15 3.5    1  4.5
## 16 3.5    1  4.5
## 17 3.3    1  4.7
## 18 2.6    1  5.4
## 19 2.5    0  5.5
## 20 2.5    0  5.5

The Kaplan-Meier estimates can be calculated using survfit() from the survival package:

require(survival)
fit <- survfit(Surv(FLIP, FLAG) ~ 1, data = SULFATE, conf.type = "plain")
fit
## Call: survfit(formula = Surv(FLIP, FLAG) ~ 1, data = SULFATE, conf.type = "plain")
## 
## records   n.max n.start  events  median 0.95LCL 0.95UCL 
##   20.00   20.00   20.00   18.00    3.15    1.80    4.50

I set conf.type=”plain” to be concordant with ‘CONFTYPE=LINEAR’ from SAS.

The median of 3.15, 95% CI [1.8, 4.5] is the same as with SAS.

Finally a quick plot:

plot(fit)

plot of chunk p39

Code and data are available at my github-repo under filename ‘p39’.

Written on December 1, 2012