Linear Regression Calculator with Step-by-Step Working

By the DeepestFeelings Editorial Team · Last updated
Quick answer Paste your paired x and y values below and press Calculate. You get the least-squares regression line ŷ = b₀ + b₁x, the slope and intercept, the correlation coefficient r, R², the standard error of the estimate, and the t-statistic and p-value for the slope. Every step of the arithmetic is worked out below the results, so you can check it or copy the method into your homework.

Calculator

Separate x and y with a comma, tab, space or semicolon. You can paste two columns straight from Excel or Google Sheets. Rows containing text, such as headers, are skipped.

Results

Enter data and press Calculate.

Scatter plot and regression line

The chart appears after you calculate.

Step-by-step working

The full working appears after you calculate.

How the least-squares method works

Simple linear regression fits a straight line through a cloud of points. For each point, the vertical gap between the actual y and the line's prediction ŷ is called the residual. The least-squares line is the one line that makes the sum of the squared residuals as small as possible. Squaring stops positive and negative gaps from cancelling out, and it penalises large misses more heavily than small ones.

The calculation uses three sums of squares built from deviations around the means x̄ and ȳ:

Sxx = Σ(x − x̄)²    Syy = Σ(y − ȳ)²    Sxy = Σ(x − x̄)(y − ȳ)

The slope and intercept then follow directly:

b1 = Sxy / Sxx     b0 = ȳ − b1x̄

Because b₀ = ȳ − b₁x̄, the fitted line always passes through the point (x̄, ȳ). The strength of the fit comes from the same sums:

r = Sxy / √(Sxx · Syy)     R² = 1 − SSE / SST, where SST = Syy

SSE is the sum of squared residuals, Σ(y − ŷ)². The standard error of the estimate, s = √(SSE / (n − 2)), is the typical size of a residual in the units of y. Dividing the slope by its own standard error, SE(b₁) = s / √Sxx, gives a t-statistic with n − 2 degrees of freedom, which produces the p-value.

How to read the results

Slope (b₁)

The expected change in y for each one-unit increase in x. A slope of 3.5 means y rises by about 3.5 units, on average, every time x goes up by 1.

Intercept (b₀)

The predicted y when x is zero. It only has a practical meaning if x = 0 is realistic and lies within, or close to, the range of your data.

Correlation coefficient (r)

Runs from −1 to +1. The sign gives the direction of the relationship and the size gives its strength. Values near ±1 mean the points sit close to a straight line; values near 0 mean little linear relationship.

R² (coefficient of determination)

The share of the variation in y explained by the line. An R² of 0.85 means 85% of the variation in y is accounted for by its linear relationship with x.

Standard error of the estimate (s)

The typical distance between the actual points and the line, measured in y's units. Smaller is better, and it is often more useful than R² when you need to know how accurate a prediction will be.

t-statistic and p-value for the slope

These test whether the slope differs from zero. A p-value below your chosen significance level, often 0.05, is evidence of a linear relationship. A significant slope is not necessarily a large or useful one.

Assumptions to check

Frequently asked questions

What does a linear regression calculator do?

It finds the straight line ŷ = b₀ + b₁x that best fits a set of paired x and y values by minimising the sum of squared vertical distances between the points and the line. This calculator also reports r, R², the standard error of the estimate, and the t-statistic and p-value for the slope, and shows each step of the arithmetic.

What is the difference between r and R²?

r is the correlation coefficient. It runs from −1 to +1 and shows the direction and strength of the linear relationship. R² is the coefficient of determination. It runs from 0 to 1 and gives the share of the variation in y that the regression line explains. In simple linear regression with one x variable, R² equals r squared.

How many data points do I need?

Two points are enough to draw a line, but the standard error, t-statistic and p-value need at least three points because they use n − 2 degrees of freedom. More data points give more reliable estimates.

What does the p-value for the slope mean?

It tests the null hypothesis that the true slope is zero, meaning no linear relationship between x and y. A small p-value, commonly below 0.05, suggests the observed slope would be unlikely if there were no linear relationship. It does not measure how large or important the effect is.

Does a high R² mean that x causes y?

No. R² measures how well a straight line fits the data, not cause and effect. Two variables can move together because of a third factor, by coincidence, or because y influences x. Establishing causation needs a suitable study design, such as a controlled experiment.

Can I paste data from Excel or Google Sheets?

Yes. Copy two adjacent columns, with x on the left and y on the right, and paste them into the data box. Each row becomes one x,y pair. Commas, tabs, spaces and semicolons are all accepted as separators, and header rows that contain text are skipped.

Editorial note: this calculator runs entirely in your browser and your data is not sent anywhere. Results use standard ordinary least-squares formulas and are computed at full floating-point precision; the decimal-places setting only affects how numbers are displayed.