
R version 2.10.0 (2009-10-26)
Copyright (C) 2009 The R Foundation for Statistical Computing
ISBN 3-900051-07-0

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.

> options(na.action=na.exclude) # preserve missings
> options(contrasts=c('contr.treatment', 'contr.poly')) #ensure constrast type
> library(survival)
Loading required package: splines
> 
> # Create a "counting process" version of the simplest test data set
> #
> test1 <- data.frame(time=  c(9, 3,1,1,6,6,8),
+                     status=c(1,NA,1,0,1,1,0),
+                     x=     c(0, 2,1,1,1,0,0))
> 
> test1b<- list(start= c(0, 3,  0,  0, 5,  0, 6,14,  0,  0, 10,20,30, 0),
+ 	      stop = c(3,10, 10,  5,20,  6,14,20, 30,  10,20,30,40, 10),
+ 	      status=c(0, 1,  0,  0, 1,  0, 0, 1,  0,   0, 0, 0, 1,  0),
+ 	      x=     c(1, 1,  1,  1, 1,  0, 0, 0,  0,   0, 0, 0, 0,  NA),
+ 	      id =   c(3, 3,  4,  5, 5,  6, 6, 6,  7,   1, 1, 1, 1,   2))
> 
> aeq <- function(x,y) all.equal(as.vector(x), as.vector(y))
> #
> #  Check out the various residuals under an Efron approximation
> #
> fit0 <- coxph(Surv(time, status)~ x, test1, iter=0)
> fit  <- coxph(Surv(time, status) ~x, test1)
> fit0b <- coxph(Surv(start, stop, status) ~ x, test1b, iter=0)
> fitb  <- coxph(Surv(start, stop, status) ~x, test1b)
> fitc  <- coxph(Surv(time, status) ~ offset(fit$coef*x), test1)
> fitd  <- coxph(Surv(start, stop, status) ~ offset(fit$coef*x), test1b)
> 
> aeq(fit0b$coef, fit0$coef)
[1] TRUE
> 
> aeq(resid(fit0), resid(fit0b, collapse=test1b$id))
[1] TRUE
> aeq(resid(fit), resid(fitb, collapse=test1b$id))
[1] TRUE
> aeq(resid(fitc), resid(fitd, collapse=test1b$id))
[1] TRUE
> aeq(resid(fitc), resid(fit))
[1] TRUE
> 
> aeq(resid(fit0, type='score'), resid(fit0b, type='score', collapse=test1b$id))
[1] TRUE
> aeq(resid(fit, type='score'), resid(fitb, type='score', collapse=test1b$id))
[1] TRUE
> 
> aeq(resid(fit0, type='scho'), resid(fit0b, type='scho', collapse=test1b$id))
[1] TRUE
> aeq(resid(fit, type='scho'), resid(fitb, type='scho', collapse=test1b$id))
[1] TRUE
> 
> # The two survivals will have different censoring times
> #  nrisk, nevent, surv, and std should be the same
> temp1 <- survfit(fit, list(x=1), censor=FALSE)
> temp2 <- survfit(fitb, list(x=1), censor=FALSE)
> all.equal(unclass(temp1)[c(3,4,6,8)], unclass(temp2)[c(3,4,6,8)])
[1] TRUE
> 
> 
> 
