Linear Regression Calculator
Fit a straight line of best fit to your paired data and predict new values using least-squares regression.
Equation: y = 0.8x + 1.8
- 1
Mean of X (x̄)
sum of X ÷ 5 = 3 - 2
Mean of Y (ȳ)
sum of Y ÷ 5 = 4.2 - 3
Σ(x − x̄)(y − ȳ)
8Sum of cross-deviations; numerator of the slope formula. - 4
Σ(x − x̄)²
10Sum of squared x-deviations; denominator of the slope. - 5
Slope b = Σ(x−x̄)(y−ȳ) ÷ Σ(x−x̄)²
8 ÷ 10 = 0.8000
How does this calculator work?
Linear regression finds the least-squares line y = bx + a through your data. The slope b = Σ(x−x̄)(y−ȳ)/Σ(x−x̄)² and intercept a = ȳ − b·x̄. R² measures fit quality from 0 to 1, and ŷ = a + b·x predicts new values for any x you supply.
Formula
How this is calculated
Enter your X values and the matching Y values as comma- or space-separated lists; the two lists must have the same length and at least two points. Each X is paired with the Y at the same position to form the data set.
The slope b is computed as the sum of cross-deviation products Σ(x−x̄)(y−ȳ) divided by the sum of squared X-deviations Σ(x−x̄)². The intercept is then a = ȳ − b·x̄, placing the line through the mean point (x̄, ȳ). The correlation coefficient r = Σ(x−x̄)(y−ȳ) / √(Σ(x−x̄)²·Σ(y−ȳ)²), and R² = r² reports the fraction of Y variance explained by the line.
The optional prediction field evaluates ŷ = a + b·x₀ at any X you choose. Note that least squares assumes a roughly linear relationship and is sensitive to outliers; a vertical (zero X-variance) data set has no defined slope and returns no result. R² near 1 indicates a tight fit, while values near 0 indicate little linear relationship.
Frequently asked questions
R² (the coefficient of determination) is the square of the correlation coefficient and ranges from 0 to 1. It is the proportion of variation in Y explained by the fitted line; 1 is a perfect fit and 0 means no linear relationship.
At least two points are required to define a line. More points give a more reliable fit. The X and Y lists must contain the same number of values.
This happens if the lists have fewer than two matching values, contain non-numeric entries, or all X values are identical (zero variance), which makes the slope undefined.
Also known as
TG we-Calculate Editorial Team. (2026). Linear Regression Calculator [Online calculator]. TG we-Calculate. https://we-calculate.com/calculator/linear-regression-calculator
TG we-Calculate Editorial Team. "Linear Regression Calculator." TG we-Calculate. 2026. https://we-calculate.com/calculator/linear-regression-calculator.
TG we-Calculate Editorial Team, "Linear Regression Calculator," TG we-Calculate, 2026. [Online]. Available: https://we-calculate.com/calculator/linear-regression-calculator
@misc{wecalculate_linear_regression_calculator, title = {Linear Regression Calculator}, author = {{TG we-Calculate Editorial Team}}, howpublished = {\url{https://we-calculate.com/calculator/linear-regression-calculator}}, year = {2026}, note = {TG we-Calculate} }
Did this calculator help you?
