File: factor2.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 (53 lines) | stat: -rw-r--r-- 1,880 bytes parent folder | download | duplicates (3)
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

R Under development (unstable) (2021-01-28 r79896) -- "Unsuffered Consequences"
Copyright (C) 2021 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)
> aeq <- function(x,y) all.equal(as.vector(x), as.vector(y))
> options(na.action=na.exclude)
> #
> # More tests of factors in prediction, using a new data set
> #
> fit <- coxph(Surv(time, status) ~  factor(ph.ecog), lung)
> 
> tdata <- data.frame(ph.ecog = factor(0:3))
> p1 <- predict(fit, newdata=tdata, type='lp')
> p2 <- predict(fit, type='lp')
> aeq(p1, p2[match(0:3, lung$ph.ecog)])
[1] TRUE
> 
> fit2 <- coxph(Surv(time, status) ~ factor(ph.ecog) + factor(sex), lung)
> tdata <- expand.grid(ph.ecog = factor(0:3), sex=factor(1:2))
> p1 <- predict(fit2, newdata=tdata, type='risk')
> 
> xdata <- expand.grid(ph.ecog=factor(1:3), sex=factor(1:2))
> p2 <- predict(fit2, newdata=xdata, type='risk')
> all.equal(p2, p1[c(2:4, 6:8)], check.attributes=FALSE)
[1] TRUE
> 
> 
> fit3 <- survreg(Surv(time, status) ~ factor(ph.ecog) + age, lung)
> tdata <- data.frame(ph.ecog=factor(0:3), age=50)
> predict(fit, type='lp', newdata=tdata)
        1         2         3         4 
0.0000000 0.3688401 0.9163870 2.2079803 
> predict(fit3, type='lp', newdata=tdata)
       1        2        3        4 
6.399571 6.142938 5.770523 4.916993 
> 
> proc.time()
   user  system elapsed 
  0.873   0.036   0.905