You need to set the raw
argument to TRUE of you don't want to use orthogonal polynomial
which is the default
set.seed(101)
N <- 100
x <- rnorm(N, 10, 3)
epsilon <- rnorm(N)
y <- 7 + 3 * x + x^2 + epsilon
coef(lm(y ~ poly(x, 2, raw = TRUE)))
## (Intercept) poly(x, 2, raw = TRUE)1
## 7.8104 2.7538
## poly(x, 2, raw = TRUE)2
## 1.0150
From the help of the poly
function you have
Description:
Returns or evaluates orthogonal polynomials of degree 1 to
‘degree’ over the specified set of points ‘x’. These are all
orthogonal to the constant polynomial of degree 0. Alternatively,
evaluate raw polynomials.
And
raw: if true, use raw and not orthogonal polynomials.
But you can also use what Ferdinand proposed, it works.
coef(lm(y ~ x + I(x^2)))
## (Intercept) x I(x^2)
## 7.8104 2.7538 1.0150