[R] poly regression

Ning Ma pningma at gmail.com
Wed Jun 10 07:41:40 CEST 2009


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?




More information about the R-help mailing list