Now we have a form that
lm
can 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 arey
times 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 ofy
in 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_pade
function below takes a dataframe withx
andy
values, fits anlm
model, and returns a function ofx
that uses the coefficents from the model to predicty
:
The lm function does more than just fit straight lines.