btvarCP2=function(time,cens,t1,t2,nbt,s0=0,alpha=0.05) { ############################################## # bootstrap time and cens to obtain # # an estimate of the variance # # and the confidence intervals for the # # probability to fail beetween t1 and t2 # # from the event coded as 1 in cens # # knowing that the patient is free # # of any event at time t1 # # time=time to first failure # # cens=1 for event of interest # # 2 for competing risk # # 0 for no event # # t1 and t2 the time window for which # # the conditional probability is calculated# # nbt=number of bootstrap repetitions # # s0=the seed (for exact repliaction) # ############################################## n=length(time) bt=function() { idx=sample(c(1:n),size=n,replace=T) tbt=time[idx] cbt=cens[idx] fitbt=cuminc(tbt,cbt) sumbt=timepoints(fitbt,times=c(t1,t2)) cp2=(sumbt$est[1,2]-sumbt$est[1,1])/(1-sumbt$est[2,1]-sumbt$est[1,1]) return(cp2) } CP2=vector("numeric",nbt) set.seed(s0) for (i in 1:nbt) CP2[i]=bt() varCP2=var(CP2) fit=cuminc(time,cens) sumfit=timepoints(fit,times=c(t1,t2)) cpw=(sumfit$est[1,2]-sumfit$est[1,1])/(1-sumfit$est[2,1]-sumfit$est[1,1]) z=qnorm(1-alpha/2) A=z*sqrt(varCP2)/(cpw*log(cpw)) loA=exp(-A) upA=exp(A) lo=cpw^loA up=cpw^upA r=data.frame(CPw=cpw,varCPw=varCP2,"L95%CI"=lo,"U95%CI"=up) row.names(r)="" return(r) }