InfyCalculator
📊

Linear Regression Calculator

Fit a least-squares line y = a + bx to paired X and Y data — with the slope, intercept, correlation r and r-squared.

X values
Y values
Loading calculator…

How it works

b = (nΣxy − ΣxΣy) ÷ (nΣx² − (Σx)²) · a = (Σy − bΣx) ÷ n · r = (nΣxy − ΣxΣy) ÷ √((nΣx² − (Σx)²)(nΣy² − (Σy)²))

Simple linear regression finds the straight line y = a + bx that comes closest to your points by minimising the sum of squared vertical distances (least squares). The slope b tells you how much Y changes for each one-unit increase in X, and the intercept a is where the line crosses the Y-axis. The correlation r and its square r² measure how well the line fits — r² is the share of Y’s variation that the line accounts for.

Worked example

For X = 1, 2, 3, 4, 5 and Y = 2, 4, 5, 4, 5: n = 5, Σx = 15, Σy = 20, Σxy = 66 and Σx² = 55. The slope is (5·66 − 15·20) ÷ (5·55 − 15²) = 30 ÷ 50 = 0.60, and the intercept is (20 − 0.60·15) ÷ 5 = 2.20. So the line is y = 2.20 + 0.60x, with r ≈ 0.775 and r² = 0.60.

Sources: Simple linear regression — Wikipedia

Frequently asked questions

What do the slope and intercept mean?

The slope is the predicted change in Y for each one-unit increase in X — the steepness and direction of the line. The intercept is the predicted Y when X is zero, where the line meets the vertical axis; it is only meaningful if X = 0 is within or near your data’s range.

What does r² tell me about the fit?

R-squared is the proportion of the variation in Y that the regression line explains, from 0 to 1. An r² of 0.60 means 60% of Y’s variability is accounted for by X; the remaining 40% is scatter the line does not capture.

Does a good fit mean X causes Y?

No. Regression describes an association and lets you predict Y from X, but it cannot establish causation. A high r² can arise from a lurking third variable or coincidence, so a strong fit is evidence to investigate further, not proof of cause and effect.

Related calculators

For education — check assumptions (sample size, distribution) before using statistics in real decisions.