We are hiring ! See our job offers.
##### https://github.com/cran/emplik
Tip revision: 31d3209
WRegEst.R
WRegEst <- function(x, y, delta, LS=TRUE, tau=0.5) {
# This R function computes the case weighted regression
# estimator for randomly right censored data. It can compute the
# least squares estimator or quantile regression estimator. In the
# later case you need to load the quantreg() package.
# Input:
# x is a matrix of N rows (covariates).
# y is the observed (censored) responses --- a vector of length N.
# delta is a vector of length N. delta =1 means (y) is not censored.
#           delta = 0 means y is right censored, i.e. the true
#        response is larger than y.
#
# Output:
# the estimate, \hat beta.

n <- length(y)
x <- as.matrix(x)
xdim <- dim(x)
if ( xdim != n ) stop("check dim of x")
if ( length(delta) != n ) stop("check length of delta")

temp <- WKM(x=y, d=delta, zc=1:n)
KMweight <- temp\$jump
norder <- order(y, -delta)
### the zero weights should be removed
Wplace <- which(KMweight > 0)
KMweight <- KMweight[Wplace]
ZZ <- y[norder]
ZZ <- ZZ[Wplace]
XX <- as.matrix(x[norder,])
xmat <- as.matrix(XX[Wplace,])
if(LS) estim <- coef(lm.wfit(x=xmat, y=ZZ, w=KMweight))
if(!LS) estim <- coef(rq.wfit(x=xmat, y=ZZ, weights=KMweight, tau=tau))
return(estim)
}