1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
R version 2.11.1 (2010-05-31)
Copyright (C) 2010 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
>
> #
> # Simple test of (start, stop] Kaplan-Meier curves, using the test2 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))
> test2 <- data.frame(start=c(1, 2, 5, 2, 1, 7, 3, 4, 8, 8),
+ stop =c(2, 3, 6, 7, 8, 9, 9, 9,14,17),
+ event=c(1, 1, 1, 1, 1, 1, 1, 0, 0, 0),
+ x =c(1, 0, 0, 1, 0, 1, 1, 1, 0, 0) )
> aeq <- function(x,y, ...) all.equal(as.vector(x), as.vector(y), ...)
>
> fit1 <- survfit(Surv(start, stop, event) ~1, test2, type='fh2',
+ error='tsiatis')
> fit2 <- survfit(Surv(start, stop, event) ~x, test2, start.time=3,
+ type='fh2')
>
> cfit1<- survfit(coxph(Surv(start, stop, event)~1, test2))
> cfit2<- survfit(coxph(Surv(start, stop, event) ~ strata(x), test2, subset=-1))
>
> deaths <- (fit1$n.event + fit1$n.censor)>0
> aeq(fit1$time[deaths], cfit1$time)
[1] TRUE
> aeq(fit1$n.risk[deaths], cfit1$n.risk)
[1] TRUE
> aeq(fit1$n.event[deaths], cfit1$n.event)
[1] TRUE
> aeq(fit1$surv[deaths], cfit1$surv)
[1] TRUE
> aeq(fit1$std.err[deaths], cfit1$std.err)
[1] TRUE
>
> deaths <- (fit2$n.event + fit2$n.censor)>0
> aeq(fit2$time[deaths], cfit2$time)
[1] TRUE
> aeq(fit2$n.risk[deaths], cfit2$n.risk)
[1] TRUE
> aeq(fit2$n.event[deaths], cfit2$n.event)
[1] TRUE
> aeq(fit2$surv[deaths], cfit2$surv)
[1] TRUE
>
> fit3 <- survfit(Surv(start, stop, event) ~1, test2) #Kaplan-Meier
> aeq(fit3$n, 10)
[1] TRUE
> aeq(fit3$time, c(1:9,14,17))
[1] TRUE
> aeq(fit3$n.risk, c(0,2,3,3,4,5,4,4,5,2,1))
[1] TRUE
> aeq(fit3$n.event,c(0,1,1,0,0,1,1,1,2,0,0))
[1] TRUE
> aeq(fit3$surv[fit3$n.event>0], c(.5, 1/3, 4/15, 1/5, 3/20, 9/100))
[1] TRUE
> #
> # Verify that both surv AND n.risk are right between time points.
> #
> fit <- survfit(Surv(time, status) ~1, test1)
> temp <- summary(fit, time=c(.5,1, 1.5, 6, 7.5, 8, 8.9, 9, 10), extend=TRUE)
>
> aeq(temp$n.risk, c(6,6,4,4,2,2,1,1,0))
[1] TRUE
> aeq(temp$surv, c(1, fit$surv[c(1,1,2,2,3,3,4,4)]))
[1] TRUE
> aeq(temp$n.event, c(0,1,0,2,0,0,0,1,0))
[1] TRUE
> aeq(temp$std.err, c(0, (fit$surv*fit$std.err)[c(1,1,2,2,3,3,4,4)]))
[1] TRUE
>
>
> fit <- survfit(Surv(start, stop, event) ~1, test2)
> temp <- summary(fit, times=c(.5, 1.5, 2.5, 3, 6.5, 14.5, 16.5))
> aeq(temp$surv, c(1, fit$surv[c(1,2,3,6, 10,10)]))
[1] TRUE
> aeq(temp$n.risk, c(0, 2, 3, 3, 4, 1,1))
[1] TRUE
>
|