[R] How to use lm.predict to obtain fitted values?

Gabor Grothendieck ggrothendieck at gmail.com
Sat May 20 20:54:02 CEST 2006


On 5/20/06, Larry Howe <larry.howe at comjet.com> wrote:
> On Friday 19 May 2006 17:35, Peter Ehlers wrote:
> > Larry Howe wrote:
> > > I have had a similar issue recently, and looking at the archives of this
> > > list, I see other cases of it as well. It took me a while to figure out
> > > that the variable name in the data frame must be identical to the
> > > variable name in the model. I don't see this mentioned in the
> > > documentation of predict.lm, and R issues no warning in this case.
> > >
> > > How would I go about officially requesting that this is mentioned, either
> > > in the documentation, or as a warning?
> > >
> > > Sincerely,
> > > Larry Howe
> >
> > Here's what I would do before officially requesting anything: read
> > 'An Introduction to R', especially section 11.3:
> >
> >   predict(object, newdata=data.frame)
> >   The data frame supplied must have variables specified with the same
> >   labels as the original.
> >
> > Seems pretty explicit.
> >
> > As well, the predict.lm help page has, under Arguments:
> >
> >   newdata   An optional data frame in which to look for variables with
> >             which to predict.
> >
> > That, too, seems unambiguous; i.e. you can't predict with values of z
> > when z is not in your formula.
> >
> > Peter Ehlers
>
> My fault, I should have read ALL the manuals before posing my question. I only
> read the 2445 page Reference Manual. I also read Intro to R, but that was
> some time ago.
>
> "An optional data frame in which to look for variables with which to predict."
> means almost nothing to me. Specifically it doesn't translate to me, as an
> engineer and software developer, but not a statistician, that the names have
> to match, and furthermore if they don't match, R fails silently.
>
> Larry Howe

I have had offline conversations not related to this thread by others
who were also confused by this so I agree it would be worthwhile
to clarify it.



More information about the R-help mailing list