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.

  • $\begingroup$ It seems that 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. using LinearModelFit), then you could use values such as RSquared or AdjustedRSquared for this purpose readily enough. $\endgroup$
    – eyorble
    Sep 11, 2019 at 22:51
  • $\begingroup$ The Properties & Relations section of the documentation says The interpolating polynomial always goes through the data points. $\endgroup$ Sep 11, 2019 at 22:52
  • $\begingroup$ @eyorble I am trying to establish a measure of a nonlinear relationship between two variables, something like the covariance but nonlinear, if this makes any sense.. $\endgroup$
    – Bran
    Sep 11, 2019 at 23:04
  • $\begingroup$ But if the polynomial is guaranteed to perfectly match the points, how are we to estimate the error? As I understand it, all of the degrees of freedom from the data are already used to constrain the polynomial, and none remain to check the validity of the solution. Thus, I don't think such a measure can even exist with the interpolating polynomial. $\endgroup$
    – eyorble
    Sep 11, 2019 at 23:19
  • $\begingroup$ The points form a cloud with many equally spaced so the polynomial will not fit them perfectly, I am looking for an optimal fit with a polynomial, so I am not sure if InterpolatingPolynomial is the best choice though. $\endgroup$
    – Bran
    Sep 11, 2019 at 23:34

1 Answer 1


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:

  1. Set some value for a desired root mean square error. This is the standard deviation for a single observation.
  2. Try multiple models where you calculate AICc for each polynomial model. (If the output of LinearModelFit or NonlinearModelFit is nlm, then you get AICc with nlm["AICc"].)
  3. Choose the model with the smallest AICc.
  4. 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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.