https://github.com/cran/emplik
Tip revision: e0c87611101332336f61f0dcb7062c3a309fa130 authored by Mai Zhou on 11 October 2013, 00:00:00 UTC
version 0.9-9
version 0.9-9
Tip revision: e0c8761
MMRtime.R
MMRtime <- function(x, d, age) {
#### estimate Mean/Median Residual lifetime over age.
temp <- WKM( x=x , d=d )
tivec <- temp$times
pivec <- temp$jump
if( age >= tivec[length(tivec)] ) stop("age too large")
if( age < tivec[1] ) warning("age smaller than first event time")
pivec[ tivec < age ] <- 0
Sage <- sum( pivec )
fenzi <- sum( (tivec - age)*pivec )
MRtime <- fenzi/Sage
Ptheta <- Sage/2
Cprob <- cumsum(pivec)
posi <- sum(Cprob < Ptheta)
theta <- tivec[posi+1]
list(MeanResidual = MRtime, MedianResidual = theta - age)
}