[R] problem with predict()

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Fri Jun 21 19:02:36 CEST 2002


"Liaw, Andy" <andy_liaw at merck.com> writes:

> You still don't get the point.  Please read Peter Dalgaard's reply and the
> help page for predict.lm carefully, and try to understand the `Detail'
> section.  See the example below:
[snip]

> > This looks promissing; however I get an error:
> > 
> > > train <- data.frame(y=yr, x=xr)
> > > test <- data.frame(y=ys, x=xs)
> > > myfit <- lm(y ~ x, train)
> > Error in eval(expr, envir, enclos) : Object "x" not found

But there's nothing wrong with that code as far as I can see?? I don't
get an error from it:

> xr <- rnorm(10)
> yr <- rnorm(10)
> ys <- rnorm(5)
> xs <- rnorm(5)
> train <- data.frame(y=yr, x=xr)
>  test <- data.frame(y=ys, x=xs)
> myfit <- lm(y ~ x, train)
> predict(myfit,test)
          1           2           3           4           5 
-0.03809295  0.11422384  0.35570765  0.55436954  0.22979523 


Something must have gone wrong with the creation of "train".

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list