"get.at.surv.times"<- function(surv.cens, times) { # # surv.cens is an object created by survfit # times is a vector of times at which you want # an estimate of the survival function # nt <- length(times) outs <- rep(0, nt) survv <- surv.cens$surv ns <- length(survv) timev <- surv.cens$time for(i in 1:nt) { if(times[i] < timev[1]) { outs[i] <- 1 } else if(times[i] >= timev[ns]) { outs[i] <- survv[ns] } else { outs[i] <- survv[timev == max(timev[timev <= times[i]]) ][1] } } no <- length(outs[outs == 0]) outs[outs == 0] <- rep(survv[ns - 1], no) return(outs) } "get.init.am"<- function(surv.cens, coeff.cox, w, delta, ttilde) { w <- ifelse(is.na(w),0,w) if(!is.matrix(w)){ w <- matrix(w,nrow=length(w),ncol=1) } nn <- length(ttilde) coeff.cox <- matrix(coeff.cox,nrow=length(coeff.cox),ncol=1) coeff.cox[is.na(coeff.cox)] <- 0 linpred <- w %*%coeff.cox sum.surv.cond <- surv.cens^(exp(linpred)) sum.surv.cond <- ifelse(sum.surv.cond<.2,.2,sum.surv.cond) if(is.na(min(sum.surv.cond))){ if(delta[is.na(sum.surv.cond)]==0){ sum.surv.cond[is.na(sum.surv.cond)] <- 1 } } B <- (delta)/sum.surv.cond return(B) }