ask = function(){ eval(parse(prompt = paste(" Enter confidence coefficent", ": ", sep=""))) } conf.bands <- function(surv.object, conf.type='plain', type='ep', tL=NA, tU=NA){ s <- surv.object fit <- survfit(s ~ 1) n <- length(s)/2 time <- summary(fit)$time std.err <- summary(fit)$std.err surv <- summary(fit)$surv if(is.na(tL)){ t.L <- time[1] } else { temp <- time[time <= tL] t.L <- temp[length(temp)] } if(is.na(tU)){ t.U <- time[length(time)] } else { temp <- time[time <= tU] t.U <- temp[length(temp)] } t.L.pos <- which(time == t.L) t.U.pos <- which(time == t.U) sigma.2 <- ( std.err / surv )^2 a.L <- n*sigma.2[time == t.L]/(1+n*sigma.2[time == t.L]) a.U <- n*sigma.2[time == t.U]/(1+n*sigma.2[time == t.U]) cat(" a_L: ",a.L," | a_U: ", a.U, "\n", sep="") input <- ask() if(type == 'hall'){ m.fact <- input*(1+n*sigma.2)/sqrt(n) } else { m.fact <- input*sqrt(sigma.2) } CI <- matrix(NA, length(surv), 2) if(conf.type == 'log-log'){ theta <- exp(m.fact/log(surv)) CI[,1] <- (surv)^(1/theta) CI[,2] <- (surv)^(theta) } else if(conf.type == 'asin-sqrt'){ temp <- asin(sqrt(surv)) - 0.5*m.fact*sqrt(surv/(1-surv)) lower <- apply(cbind(rep(0, length(temp)), temp), 1, max) CI[,1] <- (sin(lower))^2 temp <- asin(sqrt(surv)) + 0.5*m.fact*sqrt(surv/(1-surv)) upper <- apply(cbind(rep(pi/2, length(temp)), temp), 1, min) CI[,2] <- (sin(upper))^2 } else { CI[,1] <- surv*(1-m.fact) CI[,2] <- surv*(1+m.fact) } CI[CI[,1] < 0, 1] <- 0 CI[CI[,2] > 1, 2] <- 1 list(time=time, lower=CI[,1], upper=CI[,2]) }