[R] Problems using "lm" in combination with "predict"

Petr PIKAL petr.pikal at precheza.cz
Mon Aug 6 09:00:38 CEST 2007


Hi
r-help-bounces at stat.math.ethz.ch napsal dne 04.08.2007 15:04:56:

> Hi, 
> 
> I am sorry
> 
> 
> I meant:
> 
> 
>   mod <- lm(y~Worktime+Vacation+Illnes+Bankholidays)
> 
>   newdate=data.frame(x=c(324,123,0.9,0.1))

your data frame shall have correct column names (Worktime, Vacation, ...)

Regards
Petr

>   predict(mod,newdate)
> 
> And get this error.
> 
> Yours,
> 
> Maja
> 
> 
> 
> 
> -------- Original-Nachricht --------
> Datum: Sat, 4 Aug 2007 04:42:14 -0700 (PDT)
> Von: Stephen Tucker <brown_emu at yahoo.com>
> An: "Maja \\"Schröter\\"" <maja.schroeter at gmx.de>, 
r-help at stat.math.ethz.ch
> Betreff: Re: [R]  Problems using "lm" in combination with "predict"
> 
> > I think you need 
> > 
> > predict(mod,newdate)
> > 
> > instead of 
> > 
> > predict(y,newdate)
> > 
> > 
> > --- "Maja Schröter" <maja.schroeter at gmx.de> wrote:
> > 
> > > Hello everybody,
> > > 
> > > I'm trying to predict a linear regression model but it does not 
work.
> > > 
> > > My Model: y = Worktime + Vacation + Illnes + Bankholidays
> > > 
> > > My modelmatrix is of dimension  28x4
> > > 
> > > Then I want to make use of the function predict because there
> > > confidence.intervals are include.
> > > 
> > > My idea was:
> > > 
> > > mod <- lm(y~Worktime+Vacation+Illnes+Bankholidays)
> > > 
> > > newdate=data.frame(x=c(324,123,0.9,0.1))
> > > predict(y,newdate)
> > > 
> > > But I always get the message:
> > > 
> > > 
> > > 'newdata' had 1 rows but variable(s) found have 28 rows
> > > 
> > > 
> > > What can I do?
> > > 
> > > Yours, 
> > > 
> > > Maja
> > > 
> > > -- 
> > > Psssst! Schon vom neuen GMX MultiMessenger gehört?
> > > Der kanns mit allen: http://www.gmx.net/de/go/multimessenger
> > > 
> > > ______________________________________________
> > > R-help at stat.math.ethz.ch 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.
> > > 
> > 
> > 
> > 
> > 
> > 
____________________________________________________________________________________
> > Looking for a deal? Find great prices on flights and hotels with 
Yahoo!
> > FareChase.
> > http://farechase.yahoo.com/
> 
> -- 
> Psssst! Schon vom neuen GMX MultiMessenger gehört?
> Der kanns mit allen: http://www.gmx.net/de/go/multimessenger
> 
> ______________________________________________
> R-help at stat.math.ethz.ch 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.



More information about the R-help mailing list