# MODIFIED ON : Monday, February 23, 2009 at 11:23 # AUTHOR : HUIXIA JUDY WANG and LAN WANG # AFFILIATION : DEPARTMENT OF STATISTICS, NORTH CAROLINA STATE UNIVERSITY AND DEPARTMENT OF STATISTICS, UNIVERSITY OF MINNESOTA # EMAIL : WANG@STAT.NCSU.EDU # FUNCTION : LOCALLY WEIGHTED CENSORED QUANTILE REGRESSION ESTIMATOR ################################################################################### ## tauhat.func: Generalized Kaplan-Meier estimator (Gonzalez-Manteiga and Cadarso-Suarez, 1994) ## Note: this is equiavlent to Beran's estimator (1981) ## Z=min(Y,C), delta=I(Y<=C) ## we are estimating P(Y<=y0|x=x0) #################################################################################### Bnk.func = function(x0, x, h) { # the kernel weight function Bnk(x0, x), where x0 is a scalar, and x is a vector # returns a vector # h is the bandwidth xx<-(x-x0)/h xx[abs(xx)>=1]<-1 w<-15*(1-xx^2)^2/16 #biquadratic kernel w<-w/sum(w) return(w) } tauhat.func <- function(y0, x0, z, x, delta,h) { # tau0(y0, x0) = F(T=1) { for(i in 1:length(ind)) { x0 = x[ind[i]] y0 = y[ind[i]] tau.star = tauhat.func(y0,x0, y, x, delta,h=h) if (tau>tau.star) w[ind[i]] = (tau-tau.star)/(1-tau.star) } # pseudo observations ind2 = which(w!=1) y.pse = rep(max(y)+100, length(ind2)) x.pse = x[ind2] yy = c(y, y.pse) xx = c(x, x.pse) ww = c(w, 1-w[ind2]) } else { yy=y; xx=x; ww=w } rq1 = rq(yy~xx, weights=ww, tau=tau) result<- rq1$coeff result } # a simulated data set (generated under the global linearity assumption) for demonstration #library(quantreg) #set.seed(123456) #tau=0.5; n=200 #x=runif(n,0,1) #b0=3 #b1=5 #ystar = b0 + x*b1 + rnorm(n)-qnorm(tau) #ct=runif(n,0,26) #y = pmin(ystar, ct) #delta = 1*(y==ystar) #LCRQ(y, x, delta, tau=tau, h=0.05) #(naive = rq(y~x, tau=tau)$coef) #fit <- crq(Surv(y, delta)~x, method = "Por") #summary(fit, c(tau, tau))[[1]]$coef