[R] Predictably puzzled.
David Carlson
dc@r|@on @end|ng |rom t@mu@edu
Sat Nov 20 05:41:37 CET 2021
All you need is predict(fit, data.frame(x)) or if you had started with
a data frame:
xy <- data.frame(x, y)
fit <- lm(y~x, xy)
predict(fit, xy)
David
Professor Emeritus of Anthropology
Texas A&M University
College Station, TX
On Fri, Nov 19, 2021 at 8:45 PM Rolf Turner <r.turner using auckland.ac.nz> wrote:
>
> On Fri, 19 Nov 2021 18:35:23 -0800 Bert Gunter <bgunter.4567 using gmail.com> wrote: > ?predict.lm says: > > "predict.lm produces predicted values, obtained by evaluating the > regression function in the frame newdata (which defaults ZjQcmQRYFpfptBannerStart
> This Message Is From an External Sender
> This message came from outside your organization.
> ZjQcmQRYFpfptBannerEnd
>
> On Fri, 19 Nov 2021 18:35:23 -0800
> Bert Gunter <bgunter.4567 using gmail.com> wrote:
>
> > ?predict.lm says:
> >
> > "predict.lm produces predicted values, obtained by evaluating the
> > regression function in the frame newdata (which defaults to
> > model.frame(object)). "
> >
> > model.frame(fit) is:
> > 1 1.37095845 -0.30663859
> > 2 -0.56469817 -1.78130843
> > 4 0.63286260 1.21467470
> > 6 -0.10612452 -0.43046913
> > 7 1.51152200 -0.25726938
> > 8 -0.09465904 -1.76316309
> > 9 2.01842371 0.46009735
> > 10 -0.06271410 -0.63999488
> > 11 1.30486965 0.45545012
> > 12 2.28664539 0.70483734
> > 13 -1.38886070 1.03510352
> > 16 0.63595040 -1.71700868
> > 17 -0.28425292 -0.78445901
> > 18 -2.65645542 -0.85090759
> > 19 -2.44046693 -2.41420765
> > 20 1.32011335 0.03612261
> >
> > i.e. only the rows that are used to fit the model are present.
>
> Thanks Bert.
>
> cheers,
>
> Rolf
>
> --
> Honorary Research Fellow
> Department of Statistics
> University of Auckland
> Phone: +64-9-373-7599 ext. 88276
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://urldefense.com/v3/__https://stat.ethz.ch/mailman/listinfo/r-help__;!!KwNVnqRv!R8gcoKKn3_N6bslUa-yWNuKT1RXSxRK4elKMjRMNiG5UMpKepjljcSmRwlnuGig$
> PLEASE do read the posting guide https://urldefense.com/v3/__http://www.R-project.org/posting-guide.html__;!!KwNVnqRv!R8gcoKKn3_N6bslUa-yWNuKT1RXSxRK4elKMjRMNiG5UMpKepjljcSmRToGDBWQ$
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list