[R] problem with predict()
Czerminski, Ryszard
ryszard at arqule.com
Fri Jun 21 16:21:21 CEST 2002
>From Liaw, Andy:
> It's probably easier to do the following:
> ## Put training data in a data frame.
> train <- data.frame(y=yr, x=xr)
> ## Put test data in a data frame.
> test <- data.frame(y=ys, x=xs)
>
> myfit <- lm(y ~ x, train)
> test.pred <- predict(myfit, test)
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
R
Ryszard Czerminski phone: (781)994-0479
ArQule, Inc. email:ryszard at arqule.com
19 Presidential Way http://www.arqule.com
Woburn, MA 01801 fax: (781)994-0679
-----Original Message-----
From: Liaw, Andy [mailto:andy_liaw at merck.com]
Sent: Friday, June 21, 2002 8:34 AM
To: 'Czerminski, Ryszard'
Cc: r-help at stat.math.ethz.ch
Subject: RE: [R] problem with predict()
The second argument to predict.lm, `newdata', is suppose to be a data frame
containing variables that were used to fit the model. Thus if in your lm
object the predictor is a variable named `xr', the predict method will be
looking for `xr', and ignored `xs' that you passed in.
It's probably easier to do the following:
## Put training data in a data frame.
train <- data.frame(y=yr, x=xr)
## Put test data in a data frame.
test <- data.frame(y=ys, x=xs)
myfit <- lm(y ~ x, train)
test.pred <- predict(myfit, test)
Hope this helps,
Andy
> -----Original Message-----
> From: Czerminski, Ryszard [mailto:ryszard at arqule.com]
> Sent: Friday, June 21, 2002 8:10 AM
> To: 'Peter Dalgaard BSA'; Czerminski, Ryszard
> Cc: r-help at stat.math.ethz.ch
> Subject: RE: [R] problem with predict()
>
>
> > Does xs contain a variable called xr?
>
> No - it does not.
>
> I was expecting that if I use model built using
> (yr,xr) data with 164 cases and 118 variables
> to predict on a test data (xs) with 35 cases
> > # dim(xr) = 164 118 ; dim(xs) = 35 118
> I should get vector of 35 responses from predict(),
> but I am getting instead 164 responses.
> > # length(ys) = 35 ; length(ps) = 164
>
> If I go through example provided with help(predict.lm)
> I get expected number of responses (13).
> This is however only 1D example.
>
> I am sure I am missing something and probably not using
> predict() correctly, but I am at loss what it is...
>
> R
>
> Ryszard Czerminski phone: (781)994-0479
> ArQule, Inc. email:ryszard at arqule.com
> 19 Presidential Way http://www.arqule.com
> Woburn, MA 01801 fax: (781)994-0679
>
>
> -----Original Message-----
> From: Peter Dalgaard BSA [mailto:p.dalgaard at biostat.ku.dk]
> Sent: Thursday, June 20, 2002 5:10 PM
> To: Czerminski, Ryszard
> Cc: r-help at stat.math.ethz.ch
> Subject: Re: [R] problem with predict()
>
>
> "Czerminski, Ryszard" <ryszard at arqule.com> writes:
>
> > pr <- predict(model, as.data.frame(xr))
> > ps <- predict(model, xs)
> >
> > cat("length(yr) =", length(yr), "; length(pr) =", length(pr),"\n")
> > cat("dim(xr) =", dim(xr), "; dim(xs) =", dim(xs),"\n")
> > cat("length(ys) =", length(ys), "; length(ps) =", length(ps), "\n")
> > cat("why length(ps) != length(ys) ???\n")
> >
> > # my output:
> > #
> > # length(yr) = 164 ; length(pr) = 164
> > # dim(xr) = 164 118 ; dim(xs) = 35 118
> > # length(ys) = 35 ; length(ps) = 164
> > # why length(ps) != length(ys) ???
>
> Does xs contain a variable called xr?
>
> --
> 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
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
> _._._._._._._.
> _._
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
> -.-.-.-.-.-.-.-.-
> 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
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
> _._._._._._._._._
>
----------------------------------------------------------------------------
--
Notice: This e-mail message, together with any attachments, contains
information of Merck & Co., Inc. (Whitehouse Station, New Jersey, USA) that
may be confidential, proprietary copyrighted and/or legally privileged, and
is intended solely for the use of the individual or entity named on this
message. If you are not the intended recipient, and have received this
message in error, please immediately return this by e-mail and then delete
it.
============================================================================
==
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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