set.seed(123) # Create example data
x <- rnorm(100)
y <- rnorm(100) + x+x^2
Method 1
lm(y ~ x + I(x^2) + I(x^3) + I(x^4))
##
## Call:
## lm(formula = y ~ x + I(x^2) + I(x^3) + I(x^4))
##
## Coefficients:
## (Intercept) x I(x^2) I(x^3) I(x^4)
## 0.05304 0.93261 0.66503 0.01954 0.05998
Method 2
lm(y ~ poly(x, 4, raw = TRUE))
##
## Call:
## lm(formula = y ~ poly(x, 4, raw = TRUE))
##
## Coefficients:
## (Intercept) poly(x, 4, raw = TRUE)1 poly(x, 4, raw = TRUE)2
## 0.05304 0.93261 0.66503
## poly(x, 4, raw = TRUE)3 poly(x, 4, raw = TRUE)4
## 0.01954 0.05998