[R] predict()

Ivo Shterev idc318 at yahoo.com
Wed Apr 13 18:06:19 CEST 2011


Hi,

I am experimenting with the function predict() in two versions of R and the R extension package "survival".

library(survival)

set.seed(123)
testdat=data.frame(otime=rexp(10),event=rep(0:1,each=5),x=rnorm(10))
testfm=as.formula('Surv(otime,event)~x')

testfun=function(dat,fm)
  {
    predict(coxph(fm,data=dat),type='lp',newdata=dat)
  }



# Under R 2.11.1 and survival_2.35-8
testfun(testdat,testfm)
> testfun(testdat,testfm)
          [,1]
1  -0.34786190
2   0.53622182
3   0.07861553
4   0.10030148
5  -0.05329258
6  -0.40619876
7   0.83422564
8   0.15170217
9  -1.15316613
10  0.25945273


> sessionInfo()
R version 2.11.1 (2010-05-31) 
x86_64-pc-linux-gnu 

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=C              LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] splines   stats     graphics  grDevices utils     datasets  methods  
[8] base     

other attached packages:
[1] survival_2.35-8

# Under R 2.12.2 and survival_2.36-5
> testfun(testdat,testfm)
Error in model.frame(formula = fm, data = dat) : object 'fm' not found
> sessionInfo()
R version 2.12.2 (2011-02-25)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=C              LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] splines   stats     graphics  grDevices utils     datasets  methods  
[8] base     

other attached packages:
[1] survival_2.36-5


Any enlightenment on what might be causing the different performance?

Regards
Ivo



More information about the R-help mailing list