File: factor2.Rout.save

package info (click to toggle)
survival 2.36-14-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 3,500 kB
  • sloc: asm: 7,352; ansic: 5,369; makefile: 2
file content (52 lines) | stat: -rw-r--r-- 1,833 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

R version 2.14.0 (2011-10-31)
Copyright (C) 2011 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: i686-pc-linux-gnu (32-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)
Loading required package: splines
> 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.39518177 -0.02634168  0.52120527  1.81279848 
> predict(fit3, type='lp', newdata=tdata)
       1        2        3        4 
6.399571 6.142938 5.770523 4.916993 
>