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.
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
- Introductory Statistics 2e, §12.3 The Regression Equation — OpenStax
- Introductory Statistics 2e, §12.2 Scatter Plots (correlation coefficient r) — OpenStax
- NIST/SEMATECH e-Handbook of Statistical Methods, 1.3.3.26 Scatter Plot — NIST
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