I am trying to use InterpolatingPolynomial
to fit a polynomial to a given set of points representing a relationship between two variables. I would like to find a measure between 0
and 1
of how much the polynomial represents the points, 1
being a perfect fit. Consequently, the measure will reflect a polynomial relationship between the two points. I am not sure how to extract this measure from the polynomial. Any ideas are appreciated.
1 Answer
While polynomial models fit in Mathematica can be relatively easy to transfer to other languages, you might want to consider a more modern method such as @AntonAntonov 's
Quantile Regression package. (It would be very nice if Mathematica offered additional nonparametric regression functions such as generalized additive models.)
If you really have to have a polynomial with just enough terms to obtain a desired fit, you should consider something like the following approach:
- Set some value for a desired root mean square error. This is the standard deviation for a single observation.
- Try multiple models where you calculate
AICc
for each polynomial model. (If the output ofLinearModelFit
orNonlinearModelFit
isnlm
, then you getAICc
withnlm["AICc"]
.) - Choose the model with the smallest
AICc
. - If the best model has a root mean square error smaller than what you set for the desired root mean square error, then you're done.
The above model selection process is not the best or most consistent way to go. So asking this question on CrossValidated is recommended then implementing that advice in Mathematica.
InterpolatingPolynomial
will, if possible, find the (likely minimal) polynomial which exactly passes through the provided points. Thus, I'm not sure I understand your question. If you were fitting with a fixed length polynomial (e.g. usingLinearModelFit
), then you could use values such asRSquared
orAdjustedRSquared
for this purpose readily enough. $\endgroup$InterpolatingPolynomial
is the best choice though. $\endgroup$