censem=function(y,z,t) { #In addition to the observed data y, this program requires censoring times t # and indicator vector z for the censored data. rn=length(y) sn <- length(z) ybar=mean(y) thetam=ybar diff <- 1 iter <- 0 #ehat is the vector of conditional means for the censored data given #the censoring mechanism. q is the conditional likelihood exp=exp(-t/thetam) oexp=exp/(1-exp) ehat=thetam+t*z-t*(1-z)*oexp q=-(rn+sn)*log(thetam)-rn*ybar/thetam-sum(ehat)/thetam while(abs(diff) > 1e-06 & iter < 1000) { thetam=(rn*ybar+sum(ehat))/(rn+sn) exp=exp(-t/thetam) oexp=exp/(1-exp) ehat=thetam+t*z-t*(1-z)*oexp qnew=-(rn+sn)*log(thetam)-rn*ybar/thetam-sum(ehat)/thetam diff <- abs(qnew - q)/max(abs(qnew), 1) q=qnew iter <- iter + 1 } out <- list(thetam,iter) names(out)=c("Theta","No. Iterations") out }