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@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.

Reply via email to