Re: [R] Puzzling coefficients for linear fitting to polynom

From: Ted Harding <Ted.Harding_at_manchester.ac.uk>
Date: Fri, 07 Mar 2008 08:40:50 +0000 (GMT)


On 07-Mar-08 08:16:06, Firas Swidan, PhD wrote:
> Hi,
> I can not comprehend the linear fitting results of polynoms.
> For example, given the following data (representing y = x^2):
>

>> x <- 1:3
>> y <- c(1, 4, 9)

>
> performing a linear fit
>
>> f <- lm(y ~ poly(x, 2))

>
> gives weird coefficients:
>
>> coefficients(f)

> (Intercept) poly(x, 2)1 poly(x, 2)2
> 4.6666667 5.6568542 0.8164966
>
> However the fitted() result makes sense:
>
>> fitted(f)

> 1 2 3
> 1 4 9
>
> This is very confusing. How should one understand the result of
> coefficients()?
>
> Thanks for any tips,
> Firas.

Have a look at the values returned by poly(x,2). The coefficients you are getting are the results of fitting

  y = a + b1*poly(x,2)[,1] + b2*poly(x,2)[,2]

where

  poly(x, 2)[,1]
# [1] -7.071068e-01 -9.073264e-17 7.071068e-01   poly(x, 2)[,2]
# [1] 0.4082483 -0.8164966 0.4082483

which is probably not what you may have thought you were doing!

It is certainly not the same as fitting

  y = a + b1*x + b2*(x^2)

though of course the fitted values will be the same.

Best wishes,
Ted.



E-Mail: (Ted Harding) <Ted.Harding_at_manchester.ac.uk> Fax-to-email: +44 (0)870 094 0861
Date: 07-Mar-08                                       Time: 08:40:46
------------------------------ XFMail ------------------------------

______________________________________________
R-help_at_r-project.org 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. Received on Fri 07 Mar 2008 - 08:44:32 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 07 Mar 2008 - 09:30:19 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive