Menu

First, load libraries.

We will use diamonds dataset as an example.

Manual
Let’s say we want to fit a quadratic polynomial. We can manually fit by adding \(carat^2\) in the data.

I() Function
But manually adding a new variable may not be the best. Suppose we want to fit 50 predictors manually adding would be a bit too much work. We can use I()  within lm() .

Please notice that the results from fit_manual and fit_I are the same.

The semi-manual method is better. But if we want to fit the cubic term for ten variables, that will still be too much work.

Poly() Function

Yep, the results of those methods are the same.

Raw VS Orthogonal
Using poly()  without raw = TRUE will yield a different result. The default value is FALSE , which will calculate orthogonal polynomial.

Long story short, an orthogonal polynomial is better. To interpret the orthogonal, polynomial doesn’t need all the predictors and can unveil subtle relationship between predictors. Professor Archim Zeileis has well explained the difference here.