########################################################################## #Compute the hazard function from a possibly right censored sample. #Using the method of estimating the sub-density f(t)[1-G(t)] (by kernal #function density() ); then devided by the estimate of [1-F(t)][1-G(t)] use #linearized empirical distribution (approx). Written by Mai Zhou, April 1999 #modified 3/2001 ########################################################################### hazard <- function(times,status,...){ samplesize <- length(times) if(length(status) != samplesize) stop("time and status must be of same length") if(any((status!=0)&(status!=1))) stop("status must be 0/1's for censor/not-censor") xd1 <- times[status==1] if(length(xd1)<2) stop("too few uncensored observations") fit2 <- density(xd1,...) fit2$y <- fit2$y*length(xd1)/samplesize fit1 <- approx(x=sort(times), y=(samplesize:1)/samplesize, xout=fit2$x, rule=1, f=0.5) ##### list(x=fit2$x,y=fit2$y/fit1$y) fit2$y<-fit2$y/fit1$y return(fit2) }