https://github.com/cran/emplik
Raw File
Tip revision: c114901d4e55bdab883d865939df2e13e83d37b1 authored by Mai Zhou on 13 August 2016, 11:01:31 UTC
version 1.0-3
Tip revision: c114901
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)
}
back to top