We are hiring ! See our job offers.
https://github.com/cran/emplik
Raw File
Tip revision: 31d32093eee1aa45b156c2a215f600da3894af7f authored by Mai Zhou on 26 December 2006, 00:00:00 UTC
version 0.9-3-1
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[1] != 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)
}
back to top