## Polynomial Regression

The relationship between *y* and *x* often turns out not to be a straight line. However, Occam's razor requires that we fit a straight-line model unless a non-linear relationship is significantly better at describing the data. So this begs the question: how do we assess the significance of departures from linearity? One of the simplest ways is to use polynomial regression.

The idea of polynomial regression is straightforward. As before, we have just one continuous explanatory variable, *x*, but we can fit higher powers of *x*, such as *x*^{2} and *x*^{3}, to the model in addition to *x* to explain curvature in the relationship between *y* and *x*. It is useful to experiment with the kinds of curves that can be generated with very simple models. Even if we restrict ourselves to the inclusion of a quadratic term, *x*^{2}, there are many curves we can describe, depending upon the signs of the linear and quadratic terms:

In the top left-hand panel, there is a curve with positive but declining slope, with no hint of a hump (*y* = 4 + 2*x* − 0.1*x*^{2}). The top right-hand graph shows a curve with a clear maximum (*y* = 4 + 2*x* − 0.2*x*^{2}), and at bottom left we have a curve with a clear minimum (*y* = 12 − 4*x* + 0.35*x*^{2}). The bottom right-hand curve shows a positive association between *y* and *x* with the slope increasing as *x* increases (*y* = 4 + 0.5*x* + 0.1*x*^{2}). So you can see that a simple quadratic model with three parameters (an intercept, a slope for *x*, and a slope for *x*^{2}) is capable of describing a wide range ...

Get *The R Book* now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.