
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 
