Re: [R] predict()

From: Ivo Shterev <idc318_at_yahoo.com>
Date: Thu, 14 Apr 2011 07:52:31 -0700 (PDT)


Dear Dr. Therneau,

Thank you for your response. Just to point out that we didn't experience any problems with the lm() function under R version 2.12.2 (2011-02-25):

> set.seed(123)
> testdat=data.frame(y=rexp(10),event=rep(0:1,each=5),x=rnorm(10))
> testfm=as.formula('y~x')
>
> testfun=function(dat,fm)

+   {
+     predict(lm(fm,data=dat),newdata=dat)
+   }

> testfun(testdat,testfm)
1 2 3 4 5 6 1.00414971 0.07061335 0.55381658 0.53091759 0.69310319 1.06574974 7 8 9 10
-0.24405980 0.47664172 1.85449993 0.36286396
> 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] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached): [1] tools_2.12.2
>

Regards
Ivo

> From: Terry Therneau <therneau_at_mayo.edu>
> Subject: Re: predict()
> To: "Ivo Shterev" <idc318_at_yahoo.com>
> Cc: r-help_at_r-project.org
> Date: Thursday, April 14, 2011, 2:59 PM
> --- begin included message ---
> 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)
>   }
>
> -- end inclusion ----
>
> The question was: this works under survival 2.35-8, but
> not survival
> 2.36-5
>
> Answer: The predict and underlying model.frame functions
> for coxph were
> brought into line with lm and other models.  The major
> advantage is that
> I now deal with factors and data dependent predictors like
> ns()
> correctly.
>   You've shown a disadvantage of which I was not
> aware.  Using your
> example but replacing coxph() by lm() with otime ~x as the
> model I get a
> similar failure.  I'd like to ask a wider audience of
> R-devel since it
> is bigger than coxph.
>
> Terry Therneau
>
>
>



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Thu 14 Apr 2011 - 15:44:27 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 15 Apr 2011 - 12:50:30 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive