8.3 Moving beyond linear models

We can also fit additional polynomial models such as the equation \(y = a + bx + cx^{2} + dx^{3} ...\) (estimated parameters \(a\), \(b\), \(c\), \(d\), …). There is a key distinction here: the equation is nonlinear in the variable \(x\), but linear with respect to the parameters. How we do that in R is pretty simple, it just depends on how we enter in the regression formula. Here are few templates:

Equation Regression Formula
\(y=a+bx\) y ~ 1 + x
\(y=a\) y ~ 1
\(y=bx\) y ~ -1+x
\(y=a+bx+cx^{2}\) y ~ 1 + x + I(x^2)
\(y=a+bx+cx^{2}+dx^{3}\) y~ 1 + x + I(x^2) + I(x^3)

Note: the structure I(..) is needed for R to signify a factor of the form \(x^{n}\).