Linear Regression Calculator
Separate x and y with a space, comma or tab. Two columns pasted from a spreadsheet work as is.
Optional
Try an example
Best-fit line (least squares)
- Slope
- 4.131
- Intercept
- 47.7857
- Correlation r
- 0.9937
- R²
- 0.9874
8 points. y changes by 4.131 for each 1-unit increase in x; the line explains 98.7% of the variation in y (very strong positive relationship).
At x = 10: ŷ = 89.0952 (95% prediction interval 84.9895 to 93.201). This is outside the range of your data, so treat it with caution.
Scatter plot
Significance
| Estimate | Std. error | 95% CI | |
|---|---|---|---|
| Slope | 4.131 | 0.1906 | 3.6646 to 4.5973 |
| Intercept | 47.7857 | 0.9625 | 45.4306 to 50.1408 |
Residual standard error 1.2352 on 6 degrees of freedom. Slope t = 21.673, p < 0.0001: the relationship is statistically significant at the 5% level.
Ordinary least squares: slope = Σ(x − x̄)(y − ȳ) / Σ(x − x̄)², intercept = ȳ − slope·x̄. The significance figures assume the residuals are independent and roughly normal with constant spread.
Fit a least-squares regression line to x, y data pasted from a spreadsheet: slope, intercept, correlation r and R², a scatter plot with the fitted line, standard errors, confidence intervals and the slope's significance, plus a prediction with its 95% prediction interval.
Formula
Worked Example
Each extra hour adds about 4.1 points, and the line explains 98.7% of the variation in scores. The slope's t statistic of 21.7 on 6 degrees of freedom makes the relationship clearly significant. x = 10 lies outside the data, so the prediction is an extrapolation.
Frequently Asked Questions
What does R² tell me?
The share of the variation in y that the line explains, from 0 to 1. An R² of 0.987 means 98.7% of the differences in y line up with differences in x. A high R² does not prove that x causes y, and a low one can still come with a real, useful slope.
What is the difference between a confidence interval and a prediction interval?
A confidence interval brackets the average y at a given x; a prediction interval brackets a single new observation, which also varies around that average, so it is always wider.
When is linear regression the wrong tool?
When the relationship is curved, when a few outliers dominate the fit, or when the spread of the residuals grows with x. Look at the scatter plot first: a straight line through a curve still produces a slope and an R², but they mislead.