Linear Regression Calculator
Paste your x and y values to fit a straight line by least squares. You get the regression equation, slope, intercept, correlation r, r², predictions and a scatter plot with the best-fit line.
e.g. 1, 2.1 — commas, spaces or tabs. Paste two spreadsheet columns directly.
Separated by commas, spaces or new lines
Optional. One or more x values, separated by commas
How to use the Linear Regression Calculator
- Paste your data as x, y pairs (one per line) or as two lists.
- Enter x values to predict, if you want forecasts.
- Press Calculate: results also update as you type.
- Read the equation, slope, intercept, r and r².
- Check the scatter plot and residuals to see how well a straight line fits.
Least-squares regression formulas
For n data pairs (x, y) with means x̄ and ȳ:
- Sxx = Σ(x − x̄)², Syy = Σ(y − ȳ)², Sxy = Σ(x − x̄)(y − ȳ)
- Slope: b = Sxy / Sxx
- Intercept: a = ȳ − b·x̄
- Correlation: r = Sxy / √(Sxx·Syy), and r² is its square
- Standard error of estimate: s = √(Σ(y − ŷ)² / (n − 2))
Example: points (1, 2), (2, 4), (3, 5), (4, 4), (5, 5). x̄ = 3, ȳ = 4, Sxx = 10, Sxy = 6, so b = 0.6 and a = 4 − 0.6 × 3 = 2.2. The line is ŷ = 0.6x + 2.2, and r = 6 / √(10 × 6) ≈ 0.775.
Reading r²
| r² | |r| | What it suggests |
|---|---|---|
| 0.00 – 0.04 | 0 – 0.2 | Little or no linear relationship |
| 0.04 – 0.16 | 0.2 – 0.4 | Weak linear relationship |
| 0.16 – 0.36 | 0.4 – 0.6 | Moderate linear relationship |
| 0.36 – 0.64 | 0.6 – 0.8 | Strong linear relationship |
| 0.64 – 1.00 | 0.8 – 1.0 | Very strong linear relationship |
These bands are a common rule of thumb; what counts as "strong" depends on the field. A high r² does not prove that x causes y.
Frequently asked questions
What is linear regression?
Simple linear regression fits the straight line ŷ = a + bx that best describes how y changes with x. The least-squares method chooses the line that minimises the sum of squared vertical distances (residuals) between the points and the line.
How are the slope and intercept calculated?
Slope b = Σ(x − x̄)(y − ȳ) / Σ(x − x̄)², and intercept a = ȳ − b·x̄, where x̄ and ȳ are the means of x and y.
What does r² mean?
r² (the coefficient of determination) is the share of the variation in y explained by the line. r² = 0.81 means 81% of the variation in y is accounted for by its linear relationship with x.
What is the difference between r and r²?
r, the correlation coefficient, runs from −1 to 1 and shows the direction and strength of the linear relationship. r² is its square, from 0 to 1, and has no sign.
What are residuals?
A residual is the observed y minus the predicted ŷ. Residuals scattered randomly around zero suggest a straight line fits well; curved patterns suggest the relationship is not linear.
Can I use the line to predict values outside my data?
You can, but extrapolation is risky because the relationship may not continue beyond the observed range. The calculator flags predictions outside the range of your x values.
What does the p-value of the slope mean?
It tests whether the slope differs from zero. A p-value below 0.05 is usually taken as evidence of a real linear relationship rather than chance, assuming the residuals are roughly normal and independent.