Math

Linear Regression Calculator

Calculate linear regression y = mx + b from two datasets.

CALCULATOR

Enter your numbers

Instant results

THE NUMORIX GUIDE

How to use the Linear Regression Calculator

Last reviewed September 14, 2026

What this calculator does

Center paired X and Y values, calculate slope m = sum((x-xbar)(y-ybar))/sum((x-xbar)^2), intercept b = ybar-m*xbar, then fit y = m*x+b.

Formula and method

Center paired X and Y values, calculate slope m = sum((x-xbar)(y-ybar))/sum((x-xbar)^2), intercept b = ybar-m*xbar, then fit y = m*x+b. The engine also reports Pearson r and R^2.

Variables and inputs

X Values and Y Values are comma-separated paired observations, with at least two values in each list. The default lists are 1,2,3,4,5 and 2,4,5,4,5.

Worked example

For x=1,2,3 and y=2,4,6: xbar=2 and ybar=4; centered-product sum=4 and centered-x-square sum=2, so m=2; b=4-2*2=0; fitted line is y=2x, r=1, R^2=1.

How to interpret the result

The slope is the predicted change in Y for one unit of X; the intercept is the predicted Y at X=0. These are descriptive line-fit quantities, not automatically causal effects.

Common mistakes to avoid

Do not swap X and Y, and do not extrapolate far outside the observed X range without a domain reason. Check residuals rather than relying only on R^2.

Assumptions and limitations

The engine uses ordinary least squares without uncertainty intervals, residual diagnostics, weighting, or outlier handling. A vertical relationship cannot be represented as y=m*x+b.

Practical use and checks

Linear Regression fits a line y = m*x + b to paired observations using ordinary least squares. Enter X values 1, 2, 3 and Y values 2, 4, 6 as a check; the slope should be 2, intercept 0, correlation 1, and R-squared 1. The line predicts y = 8 at x = 4, but that prediction is an extrapolation because 4 is outside the three entered X values. For a real dataset, compare predicted values with residuals rather than reading R-squared alone. The slope is the modeled change in Y for one unit of X, while the intercept is the modeled Y at X = 0. The intercept can be mathematically necessary but practically meaningless when zero is outside the observed range. Keep X and Y in their intended roles and make sure comma-separated entries stay paired. The calculator does not estimate slope uncertainty, confidence or prediction intervals, weighted fits, nonlinear terms, autocorrelation, or causal effects. A high R-squared can still reflect a spurious trend, omitted variable, or outlier. It also cannot represent a vertical relationship as y = m*x + b. Use interpolation cautiously, validate assumptions with a plot, and report the observed range with any prediction.

Sources and references

COMMON QUESTIONS

Frequently asked questions

What if x=0 is outside my data?

The intercept is still the mathematical line value at x=0, but it may have little practical meaning outside the observed range.

Can I use the line for prediction?

Yes for cautious interpolation when the relationship is appropriate; report uncertainty and be careful with extrapolation.