Linear Regression & Correlation Calculator

Least-squares line of best fit from x and y data: slope, intercept, equation, correlation coefficient r, r², and a predicted y.

Use a point for decimals (1.5), no thousands separators, and separate numbers with spaces or a comma and a space.
Pair each y with the x in the same position. 2 to 500 pairs.

Results

Regression line
y = 4.82739x − 173.513
Slope (b)
4.8274
Intercept (a)
-173.51
Correlation coefficient (r)
0.6631
Coefficient of determination (r²)
0.4397
Number of pairs
11
Predicted y at x = 73
178.89

How it’s calculated

Linear regression finds the straight line ŷ = a + bx that minimizes the sum of the squared vertical distances to your points (the least-squares line). The correlation coefficient r measures how closely the points follow a line, from −1 (perfect downhill) through 0 (no linear relationship) to +1 (perfect uphill). The square, r², is the share of the variation in y that the line accounts for.

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

Example (OpenStax third-exam / final-exam data, 11 students): the line is ŷ = −173.51 + 4.83x (slope 4.8274 before rounding) with r = 0.6631 and r² = 0.4397. Predicting for a third-exam score of x = 73 gives ŷ = −173.513 + 4.82739 × 73 = 178.9.

Correlation is not causation, and a line should only be trusted for x values inside the range of your data.

Frequently asked questions

What is a good r value?

The closer |r| is to 1 the tighter the points hug the line. As a rough guide, |r| above 0.7 is a strong linear relationship, 0.3 to 0.7 moderate, and below 0.3 weak. Whether a value is “good enough” depends on the field and sample size.

What does r² mean?

It is the fraction of the variation in y explained by the straight-line relationship with x. An r² of 0.44 means about 44% of the variation in y is accounted for by x; the rest is unexplained.

Why is the slope undefined when all x are equal?

A vertical set of points has no single slope; the formula would divide by zero. You need at least two different x values.

Can I use this for a trendline over time?

Yes. Enter 1, 2, 3, … as the x values (periods) and your measurements as y. The slope is the average change per period.

Embed this calculator

Add this free calculator to your own website. Copy the code below into your page’s HTML:

Need this calculator branded, changed or built around your own prices?See custom business solutions →

Sources

Formulas are taken from the free public references above. Results are provided “as is” for informational and educational purposes only. See our disclaimer.

Added · Last updated · How we check our calculators

Spotted a mistake or missing option? Report a problem· Suggest a calculator