Now we have a form that
lmcan work with. We just need to specify a set of inputs that are powers ofx(as in a traditional polynomial fit), and a set of inputs that areytimes powers ofx. This may seem like a strange thing to do, because we are making a model where we would need to know the value ofyin order to predicty. But the trick here is that we will not try to use the fitted model to predict anything; we will just take the coefficients out and rearrange them in a function. Thefit_padefunction below takes a dataframe withxandyvalues, fits anlmmodel, and returns a function ofxthat uses the coefficents from the model to predicty:
The lm function does more than just fit straight lines.