Home | Mathematics | * Finance Calculator * Applied Mathematics * Calculus Primer * Is Mathematics a Science? * Maxima * Sage * Trigonometric Relations * Unit Conversions Area of an Irregular Polygon Binomial Probability Equities Myths Graphinity Graphitude Interactive LaTeX Editor Introduction to Statistics Mandelbrot Set Polygon Calculator Polynomial Regression Data Fit Polynomial Regression Data Fit (Java version) Prime Numbers Quadratic Equation Solver Randomness Signal Processing The Mathematics Behind Stopping a Car The Mathematics of Pi The Mathematics of Population Increase Share This Page

# Polynomial Regression Data Fit

P. LutusMessage Page

This is the JavaScript version of PolySolve (07.20.2013)

Background | The Program | Notes
References

Note: In this article, footnotes are marked with a light bulb over which one hovers.

Background

For a given data set of x,y pairs, a polynomial regression of this kind can be generated:

$\displaystyle f(x) = c_0 + c_1 \, x + c_2 \, x^2 + c_3 \, x^3 ...$

In which $c_0,c_1,c_2 \, ...$ represent coefficients created by a mathematical procedure described in detail here.

In this regression method, the choice of degree and the evaluation of the fit's quality depend on judgments that are left up to the user. It is well known about this class of regression method that an effort to squeeze more correlation out of the algorithm than the data can support will sometimes produce an out-of-control function that, although it matches the data points, wanders wherever it pleases between those points. Therefore, a "good" (approaching 1.0) correlation coefficient is not enough to assure a well-behaved or meaningful function. Decisions about a result's appropriateness is more a matter of judgment than mathematics.

A "perfect" fit (one in which all the data points are matched) can often be gotten by setting the degree of the regression to the number of data pairs minus one. But, depending on the nature of the data set, this can also sometimes produce the pathological result described above in which the function wanders freely between data points in order to match the data exactly.

For those seeking a standard two-element linear regression, select polynomial degree 1 below, and for the standard form —

$\displaystyle f(x) = mx + b$

— b corresponds to be the first parameter listed in the results window below, and m to the second.

This regression is provided by the JavaScript applet below. To enter new data, type data pairs into the upper window (or paste from the system clipboard by pressing Ctrl+V), then press "Solve." To change the degree of the equation, press one of the provided arrow buttons.

A technical note — when using double-precision variables (as this program does), polynomials of degree 80 and above begin to fail because of limited floating-point resolution. The only practical remedy for such a case is to decrease the polynomial degree, regardless of the size of the data set. But in general, for problems requiring more than 80 coefficient terms or that show unsatisfactory results using this method, there are alternative regression methods including splines, and for periodic data sets, Fourier methods often produce excellent results.

The Program

Data Entry Area: Select: Ctrl+A | Copy: Ctrl+C | Paste: Ctrl+V

 -1 -1 0 3 1 2.5 2 5 3 4 5 2 7 5 9 4 

Chart Area:

 Reverse Degree: 99

Results Area:Select: Ctrl+A | Copy: Ctrl+C | Paste: Ctrl+V

Table Generator:Select: Ctrl+A | Copy: Ctrl+C | Paste: Ctrl+V

 Start: End: Step: Decimals: Exponential
Notes

Each of the above data windows can deliver or receive data by way of the system clipboard:

• To paste from the system clipboard into a data window, click the window, press Ctrl+A (to overwrite existing content), then press Ctrl+V (paste).
• To copy from a data window, click the window, press Ctrl+A (to select all the data), then press Ctrl+C (copy).
• Having learned how to copy and paste to/from the system clipboatd, you can share this program's results with other programs, and other programs' data with this program.
• To acquire a graphic copy of the generated chart, press the "Graphic" button at the bottom of the chart display. This will create a graphic version of the chart in a separate window. Then right-click the graphic and choose "Save ..." or "Save as ..." or "Save Image as ...", depending on which browser is in use.

This JavaScript program replaces an earlier Java program with the same purpose. This recoding is meant to make this program more robust and portable. To use the earlier Java version, click here.

I have also written a Python command-line program that produces the same results. Click here to view the program. To use it, download it, rename it "polysolve.py", make it executable, and follow its instructions. Here's a test result that should agree with the above default result for a degree 5 polynomial:

\$ echo "5 -1 -1 0 3 1 2.5 2 5 3 4 5 2 7 5 9 4" | ./polyregress.py -

References

 Home | Mathematics | * Finance Calculator * Applied Mathematics * Calculus Primer * Is Mathematics a Science? * Maxima * Sage * Trigonometric Relations * Unit Conversions Area of an Irregular Polygon Binomial Probability Equities Myths Graphinity Graphitude Interactive LaTeX Editor Introduction to Statistics Mandelbrot Set Polygon Calculator Polynomial Regression Data Fit Polynomial Regression Data Fit (Java version) Prime Numbers Quadratic Equation Solver Randomness Signal Processing The Mathematics Behind Stopping a Car The Mathematics of Pi The Mathematics of Population Increase Share This Page