Numeric Forest logo

Polynomial Regression Calculator

Outlier Sensitivity:
Decimal Places:
Clear Random Data

Introduction

This polynomial regression calculator is designed to analyse non-linear relationships between two numeric datasets, X and Y. By fitting a polynomial of degree n to the observations, it allows researchers to model complex trends that simple linear models cannot capture, facilitating a deeper understanding of variable interactions within a scientific or academic framework.

What this calculator does

The tool performs a least-squares polynomial fit by constructing a Vandermonde matrix from the input coordinates. It requires two equal-length datasets and a specified polynomial degree. The process generates a regression equation, calculates the coefficients for each power of x, and determines the coefficient of determination R2 to evaluate the model fit. It also identifies potential outliers using modified Z-scores based on the median absolute deviation.

Formula used

The calculation utilises the normal equation to find the coefficient vector a. This involves the transpose of the design matrix XT, its inverse, and the dependent variable vector y. The model quality is assessed via the coefficient of determination R2, which compares the residual sum of squares SSres to the total sum of squares SStotal.

Normal Equation (Coefficients Vector a):

a=(XTX)-1XTy

Coefficient of Determination (R²):

R2=1-SSresSStotal

How to use this calculator

  1. Enter the independent values for Dataset X as comma-separated digits.
  2. Enter the dependent values for Dataset Y, ensuring the count matches Dataset X.
  3. Select the desired polynomial degree, outlier sensitivity, and decimal precision.
  4. Execute the calculation to view the regression equation, coefficients, and statistical fit analysis.

Example Calculation: Polynomial Regression

Scenario: A technical analysis maps a curved relationship between a specific independent variable and its output performance across five distinct testing intervals.

Inputs:

  • Dataset X: 1, 2, 3, 4, 5
  • Dataset Y: 2.1, 3.9, 9.2, 15.8, 25.1
  • Polynomial Degree (n): 2 (Quadratic)

Step 1 - Construct Vandermonde Matrix:

The system analyses 5 data points to construct the Vandermonde design matrix X, where each row represents [x0,x1,x2]:

  • Row 1 (x=1.000): [1.000, 1.000, 1.000]
  • Row 2 (x=2.000): [1.000, 2.000, 4.000]
  • Row 3 (x=3.000): [1.000, 3.000, 9.000]
  • Row 4 (x=4.000): [1.000, 4.000, 16.000]
  • Row 5 (x=5.000): [1.000, 5.000, 25.000]

Step 2 - Solve Normal Equations:

The model computes the normal equation: (XTX)a=XTy

Coefficients are calculated by inverting the matrix and solving for the vector: a=(XTX)-1XTy

Point-by-Point Predictions and Residuals:

X = 1 - y^=1.9686, Residual = 2.1000 - 1.9686 = 0.1314

X = 2 - y^=4.2657, Residual = 3.9000 - 4.2657 = -0.3657

X = 3 - y^=8.8914, Residual = 9.2000 - 8.8914 = 0.3086

X = 4 - y^=15.8457, Residual = 15.8000 - 15.8457 = -0.0457

X = 5 - y^=25.1286, Residual = 25.1000 - 25.1286 = -0.0286

Step 3 - Variance and Goodness-of-Fit:

Total Sum of Squares (SStotal) = 354.468

Residual Sum of Squares (SSres) = 0.249

Fit Calculation: R2=1-(0.249/354.468)=0.999

Results:

Intercept (a0) = 2.000

Linear Term (a1) = -1.196

Quadratic Term (a2) = 1.164

Regression Equation:

y=1.164x2-1.196x+2.000

Interpretation: The quadratic model demonstrates a strong, non-linear positive acceleration. The negative linear coefficient (a1=-1.196) initially dampens the output, but the dominant positive quadratic coefficient (a2=1.164) ensures that as X grows larger, the value of Y increases at an accelerating rate.

Conclusion: With an R2 value of 0.999, the 2nd-degree polynomial regression equation model accounts for 99.9% of the variance within this 5-point dataset, providing an exceptionally precise mathematical fit for the trend.

Understanding the result

The resulting regression equation provides the mathematical model for the data. The R2 value indicates the proportion of variance in Y explained by X; a value closer to 1.0 suggests a superior fit, while residuals help identify where the model deviates from actual observations.

Assumptions and limitations

The model assumes a non-linear relationship exists and that the number of unique data points exceeds the polynomial degree. High-degree polynomials may lead to overfitting, where the model describes noise rather than the underlying trend.

Common mistakes to avoid

Typical errors include using a polynomial degree that is too high for the sample size, which reduces the model's predictive reliability. Additionally, entering datasets of unequal lengths or including non-numeric characters will result in calculation failures.

Sensitivity and robustness

Polynomial regression is sensitive to outliers, as squared or higher-power terms can amplify the influence of extreme values. The tool provides sensitivity settings to identify these points, ensuring that researchers can assess whether specific data points are disproportionately affecting the calculated coefficients.

Troubleshooting

If the calculator reports a singular matrix, it indicates that the data points may be perfectly correlated or insufficient for the chosen degree. Ensure that the input contains distinct numeric values and that the degree is appropriate for the number of observations provided.

Frequently asked questions

What is the maximum number of data points?

The calculator accepts up to 1000 data points for processing.

What does a singular matrix error mean?

This occurs when the matrix cannot be inverted, often due to redundant data or a lack of unique values required for the selected polynomial degree.

How is the model fit evaluated?

The fit is evaluated using the R-squared value, which measures how well the regression line approximates the real data points.

Where this calculation is used

Polynomial regression is widely applied in educational and research settings to model phenomena that do not follow a straight line. In social research, it may be used to analyse population growth trends. In sports analysis, it helps in modelling projectile trajectories or athlete performance curves. Environmental studies often employ it to track fluctuations in chemical concentrations or temperature changes over time, providing a more nuanced descriptive statistics tool than standard linear models.

Results are based on standard mathematical and statistical methods and may involve rounding or approximation. If precise accuracy is required, please verify results independently. See full disclaimer.