####################################################################### ### This code cleans the right censored data: remove the tie and ### generates the weight (duplicate index). It do not treat a tied ### censored obs. and an uncensored obs. as tie. ### In the future it should improve to take the input wt.(instead of all 1) ####################################################################### "dataclean"<-function(z, d, wt = rep(1, length(z)) ) { z0 <- sort(z[d==0]) if(length(z0) > 1) { z0.int<-match(z0,unique(z0)) z0ends<-c(diff(z0.int) !=0, T) wz0 <- diff(c(0,seq(along = z0)[z0ends])) newz0<-z0[z0ends] } else { newz0 <- z0; wz0 <- wt[d==0] } z1 <- sort(z[d==1]) if(length(z1) > 1) { z1.int<-match(z1,unique(z1)) z1ends<-c(diff(z1.int) !=0, T) wz1 <- diff(c(0,seq(along = z1)[z1ends])) newz1<-z1[z1ends] } else { newz1 <- z1; wz1 <- wt[d==1] } newz <- c(newz0, newz1) newd <- c(rep(0, length(newz0) ),rep(1, length(newz1))) neww <- c(wz0, wz1) ## neworder <- order(newz, -newd) ##do I really need to order them? ## newz <- newz[neworder] ##may be not. ## newd <- newd[neworder] ## neww <- neww[neworder] list(z = newz, d = newd, w = neww) }