Linear & Polynomial Regression
See Also: Multiple
Linear Regression Nonlinear Regression Data Table
Polymath can fit a polynomial of degree n with the general form:
P(x) = a0 + a1*x + a2*x^2 + . . . + an*x^n
or a linear equation when the equivalent first degree polynomial is specified
P(x) = a0 + a1*x
where a0, a1, ..., an are regression parameters to a set of N tabulated values of x (a
single independent variable) versus y (a single dependent variable). The highest degree allowed for a polynomial is N - 1 (thus n >= N - 1). The program calculates the coefficients
a0, a1, ..., an by minimizing the sum of squares of the deviations between the calculated y or P(x)
and the data for y.
The Data Table window for Example 3 is shown below where the tabs for
'Regression' and for 'Linear & Polynomial' have been selected.

The options available in this window are the following:
Dependent Variable:
Select the dependent variable for regression.
Independent Variable:
Select the independent variable for regression (indicated by 'x' in the regression equation above).
Polynomial Degree:
Select the degree of the polynomial (indicated by 'n' in equation above), select the
'1 Linear' polynomial for linear regression.
Through origin:
If this option is marked, the free parameter is set to zero in the regression model (a0=0).
Polynomial Integration:
If this parameter is marked, the integral of the polynomial between the specified boundaries is calculated.
Polynomial Differentiation:
If this parameter is marked, the derivative of the polynomial at the specified point is calculated.
Export to Excel:
Click on this icon to automatically transfer this problem to Excel and to
carry out the regression and the requested calculations.
Solve
(pink arrow):
Click on this icon to carry out the regression and the requested calculations.
Graph:
If this option is marked, a graph showing the calculated curve (or points) and the data points is prepared and displayed.
Residuals:
If this option is marked, a graph showing the deviation between the data and the calculated values of the dependent variable (error, residuals)
points is prepared and displayed.
Store Model in Column:
Store the regression model and the calculated parameters in the next available empty column.
Report:
If this option is marked, a report showing the regression model the numerical values and confidence intervals of the parameters and some additional statistical and other information are presented and displayed.
Linear and Polynomial Regression
To carry out a linear or polynomial regression, select the column name of the independent variable and the column name of the dependent variable and the order of the polynomial you wish to fit. If you know that the physical model represented by the data requires that a straight line or the polynomial should pass through the origin (i.e., if the independent variable's value is 0.0, then the dependent variable must also be 0.0), mark the "Through origin" cell. To obtain a plot of the calculated polynomial and the data points versus the independent variable, mark the "Graph" option. To obtain a residual plot, mark the "Residuals" option.
Note that you are allowed to mark several polynomial orders at once. In such case several reports, graphs etc. will be generated for the various order polynomials. For selecting the polynomial, which represents the data best see, the section of "Assessing the quality of regression models".
Example 1: Fitting Polynomial of Degree 1 - Heat Capacity Data of Solid Hydrogen Bromide.
Consider the data set shown below that is from
Example 3 - "Heat capacity"
in the Polymath REG Regression Program. The data
set may be obtained within the Polymath REG program by clicking on the Examples
button and holding until Example 3 : Heat capacity is highlighted. This
should bring the data into the Polymath Data Table.

Then verify that the "Regression" tab and the "Linear & Regression" tab are
selected. Indicate the Dependent Variable: Cp, Independent Variable: T,
Polynomial Degree: 1 Linear, and check only Report. Press the purple arrow
to achieve a Polymath Report of the
Polynomial Degrees (Linear Regression) solution that is shown below:
| POLYMATH Report | Heat capacity of Hydrogen Bromide |
| Linear Regression | 28-Sep-2004 |
Model: Cp = a0 + a1*T
| Variable | Value | 95% confidence |
| a0 | 8.13858 | 0.402096 |
| a1 | 0.0216109 | 0.0027439 |
General
Regression including a free parameter
Number of observations = 18
Statistics
| R^2 | 0.9457227 |
| R^2adj | 0.9423303 |
| Rmsd | 0.0245012 |
| Variance | 0.0121562 |
Source data points and calculated data points
| T | Cp | Cp calc | Delta Cp | |
| 1 | 118.99 | 10.79 | 10.710059 | 0.0799412 |
| 2 | 120.76 | 10.8 | 10.74831 | 0.05168994 |
| 3 | 122.71 | 10.86 | 10.790451 | 0.06954872 |
| 4 | 125.48 | 10.93 | 10.850313 | 0.07968658 |
| 5 | 127.31 | 10.99 | 10.889861 | 0.10013866 |
| 6 | 130.06 | 10.96 | 10.949291 | 0.01070873 |
| 7 | 132.41 | 10.98 | 11.000077 | -0.02007684 |
| 8 | 135.89 | 11.03 | 11.075283 | -0.04528271 |
| 9 | 139.02 | 11.08 | 11.142925 | -0.06292477 |
| 10 | 140.25 | 11.1 | 11.169506 | -0.06950615 |
| 11 | 145.61 | 11.19 | 11.28534 | -0.09534048 |
| 12 | 153.45 | 11.25 | 11.45477 | -0.2047698 |
| 13 | 158.03 | 11.4 | 11.553748 | -0.15374764 |
| 14 | 162.72 | 11.61 | 11.655103 | -0.04510268 |
| 15 | 167.67 | 11.69 | 11.762077 | -0.07207654 |
| 16 | 172.86 | 11.91 | 11.874237 | 0.03576298 |
| 17 | 177.52 | 12.07 | 11.974944 | 0.09505627 |
| 18 | 182.09 | 12.32 | 12.073705 | 0.24629454 |
Consider the data set from Example 3 - "Heat capacity" in the Polymath REG Regression Program. The data set may be obtained within the Polymath REG program by clicking on the Examples button and holding until Example 3 : Heat capacity is highlighted. This should bring the data into the Polymath Data Table. For this example, please click on the Regression tab at the bottom of the Data Table and select Dependent Variable: Cp, Independent Variable: T, Polynomial Degree: 2, and check Graph, Residuals, and Report. The solution will result in three separate windows that can be easily observed if the Windows button is clicked and Cascade selected. The front window given the Polymath Regression Report for the 2nd degree polynomial as shown below:

Polymath Regression Graph
The Polymath Regression Graph window output, given below, presents a scaled plot of the 2nd degree polynomial as a solid curve and the actual data points that were used in the filling of the polynomial as the circles. The allows you to visually determine the goodness of fit for the polynomial.

Polymath Regression Residuals Plot
The Polymath Regression Residuals Plot, given below, presents a scaled plot of the difference between the dependent variable, Cp in this case, for each of the input data points for the 2nd degree polynomial. It is desirable for the residuals to appear to be randomly placed about the zero line. This allows you to visually determine the goodness of fit for the polynomial.

Example 3: Fitting Polynomial of Degree 3 (with Integration and Differentiation) - Heat Capacity Data of Solid Hydrogen Bromide.
Consider the data set from Example 3 - "Heat capacity" in the Polymath REG Regression Program. The data set may be obtained within the Polymath REG program by clicking on the Examples button and holding until Example 3 : Heat capacity is highlighted. This should bring the data into the Polymath Data Table. A Polymath solution as indicated in the Input window shown below. Note that the "Regression" and "Linear & Polynomial" tabs have been pressed.

For this Example, please select the following options:
"Report" gives the problem results.
"Store Model in column" stores the calculated values for the polynomial in the Data Table under the selected column heading C03.
"Dependent Variable" allows selection of Cp.
"Independent Variable" allows selection of T.
"Polynomial Degree" allows section of 3.
"Through origin" eliminates the constant from the regression of the polynomial.
"Polynomial Integration" integrates the dependent variable T from T1 = 120 to T2 = 200 using the 3rd degree polynomial.
"Polynomial Derivative" calculates the derivation value when the independent variable T = 150 using the 3rd degree polynomial.
The Polymath Report for this problem gives the integration and differentiation results as reproduced below:
| POLYMATH Report | Heat capacity of Hydrogen Bromide |
| Polynomial Regression | 22-Nov-2004 |
Model: Cp = a1*T + a2*T^2 + a3*T^3
| Variable | Value | 95% confidence |
| a1 | 0.2314379 | 0.0082055 |
| a2 | -0.0017116 | 0.0001102 |
| a3 | 4.459E-06 | 3.64E-07 |
Analytical polynomial integration
Cp = 0.2314379*T -0.0017116*T^2 + 4.459E-06*T^3
Integ(Cp,T1,T2) = 0.115719 *T^2 -0.0005705*T^3 + 1.115E-06*T^4
T(1) = 120
T(2) = 200
Integ(Cp,T1,T2) = 936.3613
Analytical polynomial derivative
Cp = 0.2314379*T -0.0017116*T^2 + 4.459E-06*T^3
d(Cp)/d(T) = 0.2314379 -0.0034231*T + 1.338E-05*T^2
T = 150
d(Cp)/d(T) = 0.0189173
| T | d(Cp)/d(T) |
| 118.99 | 0.013498 |
| 120.76 | 0.0131151 |
| 122.71 | 0.0127902 |
| 125.48 | 0.0125037 |
| 127.31 | 0.012427 |
| 130.06 | 0.0124801 |
| 132.41 | 0.0126859 |
| 135.89 | 0.0132619 |
| 139.02 | 0.0140568 |
| 140.25 | 0.0144408 |
| 145.61 | 0.016587 |
| 153.45 | 0.0211104 |
| 158.03 | 0.0245138 |
| 162.72 | 0.0285804 |
| 167.67 | 0.0335107 |
| 172.86 | 0.039384 |
| 177.52 | 0.0452715 |
| 182.09 | 0.0516094 |
General
Degree of polynomial = 3
Regression not including a free parameter
Number of observations = 18
Statistics
| R^2 | 0.994862 |
| R^2adj | 0.994177 |
| Rmsd | 0.0075383 |
| Variance | 0.0012274 |
Source data points and calculated data points
| T | Cp | Cp calc | Delta Cp | |
| 1 | 118.99 | 10.79 | 10.816737 | -0.02673712 |
| 2 | 120.76 | 10.8 | 10.840277 | -0.04027734 |
| 3 | 122.71 | 10.86 | 10.865518 | -0.00551848 |
| 4 | 125.48 | 10.93 | 10.900503 | 0.02949683 |
| 5 | 127.31 | 10.99 | 10.923301 | 0.06669898 |
| 6 | 130.06 | 10.96 | 10.957502 | 0.00249811 |
| 7 | 132.41 | 10.98 | 10.987043 | -0.00704301 |
| 8 | 135.89 | 11.03 | 11.032098 | -0.00209822 |
| 9 | 139.02 | 11.08 | 11.074784 | 0.0052164 |
| 10 | 140.25 | 11.1 | 11.092305 | 0.00769451 |
| 11 | 145.61 | 11.19 | 11.175117 | 0.01488307 |
| 12 | 153.45 | 11.25 | 11.321817 | -0.07181677 |
| 13 | 158.03 | 11.4 | 11.426082 | -0.02608211 |
| 14 | 162.72 | 11.61 | 11.550358 | 0.05964194 |
| 15 | 167.67 | 11.69 | 11.703763 | -0.01376327 |
| 16 | 172.86 | 11.91 | 11.892613 | 0.01738653 |
| 17 | 177.52 | 12.07 | 12.089635 | -0.01963513 |
| 18 | 182.09 | 12.32 | 12.310795 | 0.00920485 |
The Data Table has been updated with column C03 which contains the calculated Cp
from the 3rd degree polynomial:

Simultaneous Polynomial Degrees
You can request treatment of several polynomial degrees by holding down the "CNTR" key and at the same time clicking on the desired
degrees with the left button of the mouse. You may
also check the "Residual" and "Graph" options to obtain the desired plots
for all selected degrees, and then
press the pink arrow to solve. A report containing the numerical results for the
selected polynomials will be obtained along with separate graphs and residual plots for each polynomial.
Additional Useful Information