```{r}
library(survival)
library(KMsurv)
```

```{r}
data(tongue)
attach(tongue)
surv <- Surv(time[type==1], delta[type == 1])
fit <- survfit(surv ~ 1, conf.type = "plain")
summary(fit)

#time n.risk n.event survival std.err lower 95% CI upper 95% CI
#3     51       2    0.942    0.0323       0.8789        1.000
(lower <- 0.942 - qnorm(0.975) * 0.0323)
(upper <- 0.942 + qnorm(0.975) * 0.0323)
detach(tongue)
```


```{r}
data(tongue)
attach(tongue)
surv <- Surv(time[type==1], delta[type == 1])
fit.loglog <- survfit(surv ~ 1, conf.type = "log-log")
summary(fit.loglog)
#time n.risk n.event survival std.err lower 95% CI upper 95% CI
#   3     51       2    0.942  0.0323       0.8317        0.981
L <- log(-log(0.942))
DL <- 0.0323^2 / (0.942 * log(0.942))^2
L.lower <- L - qnorm(0.975) * sqrt(DL)
L.upper <- L + qnorm(0.975) * sqrt(DL)

(S.lower <- exp(-exp(L.upper))) # 0.8317
(S.upper <- exp(-exp(L.lower))) # 0.981
detach(tongue)
```