First things first, load goodies and set up a theme.

It is rare that a relationship between variables will be completely linear. It would be great to have a linear relationship like this equation \(y = x +3 \) with the chart like this.

But, in practice, the relationship may be more like \(y = 3x^3+x^2+x-15\).

Using polynomial regression, in such case, could result in better predictive power. We will use diamonds data from the GGPLOT2 library to demonstrate the polynomial.

We can see that the relationship between price and x is not precisely linear. It is polynomial.

Let’s try GGPLOT2’s geom_smooth()  function to fit models.

We can see that quadratic and cubic fits are much better than the linear fit. We can also use lm()  to get the R-Squared.

Then we extract only Adjusted R-Squared and plot the chart.