Education

Linear Regression Calculator

Last updated: June 19, 2026

Blake Boege
Written by Blake Boege · Founder, Calculator Answers

A linear regression calculator is a statistical analysis tool that models the relationship between an independent variable and a dependent variable. The calculator processes a set of data pairs to compute the line of best fit using the least squares method, outputting the regression equation in the form y equals ax plus b. It also calculates the correlation coefficient, the coefficient of determination (R-squared), and residuals. Data analysts and researchers use this tool to predict future trends and verify mathematical models.

Add paired x and y values and the calculator returns the best-fit line y = mx + b, the slope and intercept, the Pearson r and r squared, and an optional predicted y for a chosen x.

Quick Answer

Find the line of best fit for your data points. Enter your coordinate pairs to calculate the linear regression equation and regression metrics.

xy

Leave blank to skip the prediction. · e.g. 6

Need at least two distinct x values. The slope is undefined if every x is the same (zero variance in x).

Linear regression

5 pairs · r² = 0.9971

y = 1.47x + 0.53

At x = 0, predicted y = 0.53

Slope1.47
Intercept0.53
r0.9985
0.9971
Mean x · mean y3 · 4.94
Predicted y at x = 00.53
Was this helpful?

Examples

Pairs (1,2), (2,3.5), (3,5), (4,6.2), (5,8)

y ≈ 1.46x + 0.58, r² ≈ 0.991

Pairs (10,20), (20,30), (30,40), (40,50)

y = x + 10 exactly, r = 1

Pairs (1,5), (2,4), (3,6), (4,5), (5,7)

y = 0.5x + 4.1, r² ≈ 0.625

How it works

Find the means of x and y. Compute the deviations from each mean for every pair. The slope is the sum of cross-products divided by the sum of squared x-deviations. The intercept comes from the means.

Slope (m) · Σ((x − x̄)(y − ȳ)) ÷ Σ(x − x̄)²

Intercept (b) · ȳ − m × x̄

Prediction · ŷ = mx + b

r² is the proportion of variance in y explained by the line.

Related statistics calculators

Frequently asked questions

Simple linear regression fits a straight line y = mx + b to a set of paired observations of x and y. The line is chosen to minimize the sum of squared vertical distances from each point to the line (the 'least squares' criterion). The slope m says how much y changes for each one-unit increase in x. The intercept b is the y value when x equals zero.

Compute the mean of x and mean of y. For each pair, compute the deviations from those means. The slope is the sum of the products of those deviations divided by the sum of squared x-deviations. The intercept is the mean of y minus the slope times the mean of x. The formula is m = Σ((x − x̄)(y − ȳ)) ÷ Σ(x − x̄)² and b = ȳ − m × x̄.

r squared is the proportion of variance in y that is explained by a linear fit to x. r squared = 0.85 means the line captures 85 percent of the variation in y. The rest is unexplained noise or non-linear structure. Higher r squared means a tighter fit but does not guarantee the line is the right model for predictions outside the data range.

Plug the x into the regression equation: y = mx + b. The calculator does this automatically when you fill the optional prediction field. Be careful predicting outside the range of x values in the data (extrapolation); the relationship may not hold beyond what you observed.

The slope is undefined when every x value is the same (zero variance in x). The fitting formula divides by Σ(x − x̄)², which is zero in that case. Add some variation in the x column and try again. A vertical line cannot be expressed as y = mx + b.

Use it for educational, planning, and quick-check work. It does not return standard errors of the coefficients, confidence intervals, residual plots, or diagnostic tests for the regression assumptions (linearity, independence, normality of residuals, equal variance). For formal research, use R, Python, SPSS, Stata, or another tool that reports those diagnostics.