Statistics Calculator › Linear Regression Calculator

Linear Regression Calculator

Enter paired X and Y values to get the least squares line of best fit, the correlation coefficient r and R², with a scatter plot and predictions.

What the line of best fit is

Linear regression finds the straight line ŷ = a + bx that keeps the squared vertical distances between the points and the line as small as possible (least squares). The slope b tells you how much y changes, on average, for each one unit increase in x.

b = Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)²
a = ȳ − b·x̄
r = Σ(x − x̄)(y − ȳ) ÷ √[Σ(x − x̄)² · Σ(y − ȳ)²]

Worked example

For hours studied 1 to 8 and scores 52, 55, 61, 64, 68, 70, 77, 79, the line is ŷ = 48.071 + 3.929x. Each extra hour is linked with about 3.93 more points. The correlation is r = 0.994 and R² = 0.989, so about 99% of the variation in scores is explained by hours studied.

Reading r and R²

|r|Usual description
0.7 to 1Strong
0.4 to 0.7Moderate
0.2 to 0.4Weak
below 0.2Very weak or none

The sign of r matches the direction of the line. R² is r squared and reads as the share of variation explained. These labels are rules of thumb; what counts as strong differs between fields.

Cautions

Formulas follow the NIST/SEMATECH e-Handbook of Statistical Methods: least squares.

Frequently asked questions

What is the difference between r and R²?

r is the correlation coefficient, from −1 to 1, and shows strength and direction. R² is r squared, from 0 to 1, and shows the share of the variation in y explained by the line.

How many points do I need?

At least three for the calculator, but a meaningful regression needs many more. With very few points, a high r can happen by chance.

Does it matter which variable is X?

Yes for the line: X should be the variable you use to predict, Y the one you predict. The correlation r is the same either way.

More statistics calculators