The R Project SVN R-packages

Rev

Rev 6302 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed


R version 2.15.0 (2012-03-30)
Copyright (C) 2012 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: x86_64-unknown-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> #
> # Test out the rescaling done for Surv objects
> #
> library(rpart)
> require(survival)
Loading required package: survival
Loading required package: splines
> 
> aeq <- function(x,y, ...) all.equal(as.vector(x), as.vector(y), ...)
> tdata <- data.frame(time=c(1,4,3,2,5,7,8,9,4), status=c(0,1,1,0,0,1,1,0,1),
+           x=1:9)
> fit2 <- rpart.exp(Surv(tdata$time, tdata$status), NULL, wt=rep(1,9))
> 
> #
> # Here is what it should be, in order
> #    for the intervals (0,3], (3,4], (4,7], (7,9]
> deaths <- c( 1, 2,  1, 1)
> pyears <- c(24, 6, 10, 3)
> rate   <- deaths/pyears
> cumhaz <- cumsum(c(0, rate*c(3,1,3,2)))
> 
> aeq(fit2$y[,2], tdata$status)
[1] TRUE
> aeq(fit2$y[,1], approx(c(0,3,4,7,9), cumhaz, tdata$time)$y)
[1] TRUE
> 
> 
> 
>  
> 
> 
> proc.time()
   user  system elapsed 
  0.260   0.063   0.387