[R] poly regression

Gabor Grothendieck ggrothendieck at gmail.com
Wed Jun 10 12:37:17 CEST 2009


They have different coefficients because their model matrices
are different but they both lead to the same predictions:

> fitted(lm(y~1+x+I(x^2)))
  1   2   3   4   5   6   7   8   9  10
  1   4   9  16  25  36  49  64  81 100

> fitted(lm(y~poly(x,2)))
  1   2   3   4   5   6   7   8   9  10
  1   4   9  16  25  36  49  64  81 100


On Wed, Jun 10, 2009 at 1:41 AM, Ning Ma<pningma at gmail.com> wrote:
> hi,
>
> I want to do a polynomial regression of y on x of degree 2, as following
>
>> x<-1:10
>> y<-x^2
>> lm(y~poly(x,2))
>
> Call:
> lm(formula = y ~ poly(x, 2))
>
> Coefficients:
> (Intercept)  poly(x, 2)1  poly(x, 2)2
>      38.50        99.91        22.98
>
> Which is not what i had expected.
>
> If I wrote the expression in an explicit form, y~1+x+I(x^2), I could
> get the expected result:
>
>> lm(y~1+x+I(x^2))
>
> Call:
> lm(formula = y ~ 1 + x + I(x^2))
>
> Coefficients:
> (Intercept)            x       I(x^2)
>          0            0            1
>
> What is the diff between them?
>
> ______________________________________________
> 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.
>




More information about the R-help mailing list