Linear Regression Calculator
Linear regression finds the straight line that best fits a set of data points, by making the squared vertical distances to the line as small as possible. This calculator works out the slope and intercept with exact arithmetic, the correlation coefficient r and r², and draws a scatter plot with the line.
How to use the linear regression calculator
- Enter the x values, separated by commas.
- Enter the matching y values in the same order.
- Press Calculate to see the line, r and the scatter plot.
Formula
Worked example: Six points
- x values: 1, 2, 3, 4, 5, 6
- y values: 2.1, 3.9, 6.2, 7.8, 10.1, 12.2
✓ Answer checked
- Slope m
- Intercept c
- Correlation r
- r² (fit)
- 0.998211 — a very strong positive linear relationship
Step-by-step working (4 steps)
Add up the data
There are 6 points.
Slope Least squares
Use the least-squares formula for the slope.
Intercept
The line passes through the mean point (x̄, ȳ).
Correlation Pearson's r
r measures how closely the points follow a straight line, from −1 to 1.
Formulas used
How this was checked
- ✓ The residuals add to exactly 0, and so do the residuals times x (the least-squares conditions).
Frequently asked questions
What does r tell me?
r measures how closely the points follow a straight line, from −1 (perfect negative) through 0 (none) to 1 (perfect positive).
What is r²?
The share of the variation in y explained by the line. An r² of 0.95 means the line explains 95% of it.
Does a strong correlation prove cause and effect?
No. Two things can move together because of a third factor or by chance.
Related calculators
Mean, Median & Mode Calculator
Find the mean, median, mode and range of a data set.
Standard Deviation Calculator
Calculate the standard deviation and variance of a data set, for a sample or a population, with the deviations table and every step shown.
Slope Calculator
Find the slope (gradient) of a line through two points, plus its equation y = mx + c, angle and perpendicular slope.
