How this calculator works
- Step 1Meansx̄, ȳThe line passes through both.
- Step 2SlopeΣ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)²Least squares.
- Step 3Fitr and r²How closely the points follow it.
The least-squares line is the one that makes the squared vertical distances from the points as small as possible. Its slope comes from how x and y vary together.
The correlation r runs from −1 to 1. r² is the share of the variation in y that the line explains.
Worked example: OpenStax 12.3
- Line
ŷ = a + b x
- Slope b4.8274
- Intercept a-173.5134
- r0.6631
- r²0.4397
- Predicted final at 73178.89
OpenStax gives ŷ = −173.51 + 4.83x, r = 0.6631 and r² = 0.4397.
Read the result
- °C to °Fŷ = 1.8000x + 32.0000Perfect fit: r = 1. Predicts 212 at 100 °C.
- A loose patternr = 0.8000Still a trend, with scatter around it.
In the exam data r² = 0.4397: the third exam explains about 44% of the variation in final scores.
Assumptions and limits
- Straight-line patternCheck a scatter plot first.
- Not causationCorrelation alone does not show cause.
- OutliersOne extreme point can swing the line.
- ExtrapolationPredictions beyond the data are risky.
Related statistics tools
A regression line summarises how two variables move together.
For the slope between just two points, use the slope calculator. The standard deviation calculator measures the spread of each variable, and the t-test calculator compares two group means.
Common mistakes
Mistake: Swapping x and y.
Instead: Put the predictor first; y on x and x on y differ.
Mistake: Reading r = 0.66 as 66% accuracy.
Instead: r² = 0.44 is the share of variation explained.
Checking the method
A separate script solves the normal equations by Cramer’s rule in exact fractions and reproduces OpenStax’s line, r and r².
Read how we test our calculators, or browse more maths calculators.