Linear Regression Calculator
Fit a straight line to your data and predict y for any x, with the full working.
What simple linear regression does
Simple linear regression fits the straight line y = a + bx that best predicts y from x by least squares, which means it minimises the sum of the squared vertical distances from the points to the line. The slope b is how much y changes for each one-unit increase in x, and the intercept a is the predicted y when x = 0.
Worked example
Ten pairs, with x from 1 to 10 and y values of 2.1, 3.9, 6.2, 7.8, 10.1, 12.3, 13.8, 16.2, 18.1 and 19.7, give the equation y = 0.0867 + 1.9879x. The correlation is r = 0.9994 (R² = 0.9989), the slope’s p-value is 4.23e-13, and the 95% confidence interval for the slope is 1.9337 to 2.0420. At x = 11, the model predicts y = 21.95.
The formulas
- Slope: b = Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)²
- Intercept: a = ȳ − b × x̄
- R² is the share of the variation in y explained by x.
- Standard error of the slope = s ÷ √Σ(x − x̄)², where s is the standard error of the estimate. The test statistic is t = b ÷ SE, with n − 2 degrees of freedom.
Using the results well
- Predictions are reliable inside the range of your x values. Predicting far outside it (extrapolation) is risky.
- Look at the residuals in the table: they should look random. A pattern suggests the relationship is not a straight line.
- Regression shows association. It does not prove that x causes y.
For the strength of the relationship alone, use the correlation coefficient calculator.
How to cite this page
CalcPulse. (2026). Linear Regression Calculator. https://calcpulse.com/linear-regression-calculator/
Frequently asked questions
What is linear regression?
A method that finds the straight line that best fits the relationship between a predictor x and a response y.
What does the slope mean?
The average change in y for each one-unit increase in x.
What is R squared?
The proportion of the variation in y that the line explains, from 0 to 1.
How many data points do I need?
At least 3 to run the calculation, but more is much better. A handful of points gives wide uncertainty.
Can I predict outside my data?
You can, but the further outside the range of x you go, the less reliable the prediction.
Last updated