File: expected2.Rout.save

package info (click to toggle)
survival 3.8-6-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 15,496 kB
  • sloc: ansic: 8,088; makefile: 77
file content (89 lines) | stat: -rw-r--r-- 3,387 bytes parent folder | download | duplicates (5)
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

R Under development (unstable) (2018-04-09 r74565) -- "Unsuffered Consequences"
Copyright (C) 2018 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.

> library(survival)
> #
> # A Cox model with a factor, followed by survexp.  
> #
> pfit2 <- coxph(Surv(time, status > 0) ~ trt + log(bili) +
+           log(protime) + age + platelet + sex, data = pbc)
> esurv <- survexp(~ trt, ratetable = pfit2, data = pbc)
> 
> temp <- pbc
> temp$sex2 <- factor(as.numeric(pbc$sex), levels=2:0,
+                     labels=c("f", "m", "unknown"))
> esurv2 <- survexp(~ trt, ratetable = pfit2, data = temp, 
+                   rmap=list(sex=sex2))
> 
> # The call components won't match, which happen to be first
> all.equal(unclass(esurv)[-1], unclass(esurv2)[-1])
[1] TRUE
> 
> 
> # Check that the ratetableDate function is okay
> #
> Datedate <- function(x) {
+     # Dates have an origin of 1/1/1970, dates of 1/1/1960
+     offset <- as.numeric(as.Date("1970-01-01") - as.Date("1960-01-01")) 
+     y <- as.numeric(x) + offset
+     class(y) <- "date"
+     y
+ }
> as.data.frame.date <- as.data.frame.vector # needed to make the functions work
> 
> n <- nrow(lung)
> tdata <- data.frame(age=lung$age + (1:n)/365.25,
+                     sex = c('male', 'female')[lung$sex],
+                     ph.ecog = lung$ph.ecog,
+                     time = lung$time*3, 
+                     status = lung$status,
+                     entry = as.Date("1940/01/01") + (n:1)*50)
> tdata$entry2 <- as.POSIXct(tdata$entry)
> tdata$entry3 <- Datedate(tdata$entry)
> 
> p1 <- pyears(Surv(time, status) ~ ph.ecog, data=tdata, ratetable=survexp.us,
+              rmap= list(age=age*365.25, sex=sex, year=entry))
> p2 <- pyears(Surv(time, status) ~ ph.ecog, data=tdata, ratetable=survexp.us,
+              rmap= list(age=age*365.25, sex=sex, year=entry2))
> p3 <- pyears(Surv(time, status) ~ ph.ecog, data=tdata, ratetable=survexp.us,
+              rmap= list(age=age*365.25, sex=sex, year=entry3))
> 
> all.equal(p1$expected, p2$expected)
[1] TRUE
> all.equal(p1$expected, p3$expected)
[1] TRUE
> 
> 
> # Now a ratetable with ordinary dates rather than US census style year
> trate <- survexp.us
> attr(trate, 'type') <- c(2,1,3)
> p4 <- pyears(Surv(time, status) ~ ph.ecog, data=tdata, ratetable=trate,
+              rmap= list(age=age*365.25, sex=sex, year=entry))
> p5 <- pyears(Surv(time, status) ~ ph.ecog, data=tdata, ratetable=trate,
+              rmap= list(age=age*365.25, sex=sex, year=entry2))
> p6 <- pyears(Surv(time, status) ~ ph.ecog, data=tdata, ratetable=trate,
+              rmap= list(age=age*365.25, sex=sex, year=entry3))
> 
> #all.equal(p1$expected, p4$expected) # this won't be true, US special is special
> all.equal(p4$expected, p5$expected)
[1] TRUE
> all.equal(p5$expected, p6$expected)
[1] TRUE
> 
> proc.time()
   user  system elapsed 
  0.756   0.036   0.790