We are hiring ! See our job offers.
https://github.com/cran/emplik
Raw File
Tip revision: e2f16b0adc0f6df124c7ee126345f66d8d2c7961 authored by Mai Zhou on 09 October 2011, 00:00:00 UTC
version 0.9-7
Tip revision: e2f16b0
DnR.R
DnR <- function(x, d, w, y=rep(-Inf, length(x)) )
{
# inputs should be from  Wdataclean2(), i.e. ordered and weighted.
# y is the truncation times, y do not have to be the same length
# as x, but should be length(y) = sum(w).

allrisk <- rev(cumsum(rev(w)))
posi <- d == 1
uncenx <- x[posi]
uncenw <- w[posi]
uncenR <- allrisk[posi]

if(any(y > -Inf)) { 
  inde <- function(u, v) { as.numeric(u >= v) }
  uuij <- outer(y, uncenx, FUN="inde")
  trunca <- as.vector( rowsum( uuij, group= rep(1, length(y))) ) 
  uncenR <- uncenR - trunca
}

list( times = uncenx, n.risk = uncenR, n.event = uncenw )
}

back to top