HEX
Server: Apache/2.4.46 (Win64) OpenSSL/1.1.1j PHP/8.4.25
System: Windows NT DESKTOP-4TAV2RJ 10.0 build 19045 (Windows 10) AMD64
User: fred (0)
PHP: 8.4.25
Disabled: NONE
Upload Files
File: C:/Program Files/R/R-4.4.0/library/rpart/tests/rescale.Rout.save
R Under development (unstable) (2019-04-05 r76323) -- "Unsuffered Consequences"
Copyright (C) 2019 The R Foundation for Statistical Computing
Platform: x86_64-pc-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
> set.seed(10)
> 
> 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.690   0.044   0.730