Linear Regression Calculator
Linear regression models the linear relationship between two variables by fitting a straight line through the data. This calculator computes the slope (m), intercept (b), regression equation, and R-squared value. You can also predict y values for new x inputs using the fitted equation. Linear regression is fundamental for forecasting, understanding relationships, and making predictions based on data.
Linear regression formulas
Slope: m = [n*Σ(xy) - Σ(x)*Σ(y)] / [n*Σ(x²) - (Σ(x))²]
Intercept: b = mean(y) - m * mean(x)
Equation: y = mx + b
R² = 1 - Σ(residuals²) / Σ(y - mean(y))²
Interpreting results
- Slope: Change in y for one-unit increase in x.
- Intercept: Value of y when x = 0.
- R-squared: Higher values (closer to 1) indicate better fit.
- Predictions: Reliable near the data range, less reliable for extrapolation.
Linear regression: frequently asked questions
What is linear regression?
Linear regression fits a straight line through data points to model the relationship between x and y. The line minimizes the sum of squared distances from points to the line. Formula: y = mx + b, where m is slope and b is intercept.
What is the slope?
The slope (m) indicates how much y changes for each unit increase in x. Positive slope means y increases with x. Negative slope means y decreases with x.
What is R-squared?
R-squared measures how well the regression line fits the data, ranging from 0 to 1. R^2 = 0.8 means 80% of y variation is explained by x. Higher R^2 indicates better fit.
Can I use this to predict new values?
Yes. Enter a new x value and the calculator predicts y using: y = slope * x + intercept. Predictions are most reliable near the range of original data.
Official sources
- NIST/SEMATECH e-Handbook: NIST Handbook.
Reviewed by the CalculatorHub team, edited by James Graham, 14 June 2026. See our methodology.