Simple linear regression describes how one quantity changes, on average, as another one changes. Given n pairs (x, y), it finds the straight line y = mx + b that keeps the squared vertical distances between the points and the line as small as possible. The slope m is the expected change in y for a one-unit increase in x; the intercept b is the predicted y when x is zero.
Lines like this are everywhere: calibration curves in a lab, sales against advertising spend, fuel use against distance, exam scores against hours studied. Besides the line itself, the calculator tells you how good the line is. R² says what share of the variation in y the line explains, the residual standard error says how far typical points sit from the line, and the t-test on the slope tells you whether the trend could just be noise.
The prediction section uses the fitted line to estimate y at a new x. Because a single new observation scatters around the line, the 95% prediction interval is always wider than the interval for the average y at that x, and both widen as you move away from the centre of your data.
How to use the Linear Regression Calculator
- x values (independent variable)
- y values (dependent variable): Same number of values as x, in the same order
- Predict y at x =: Optional, leave empty to skip the prediction
- Precision (significant figures)
Everything is calculated in your browser, so results appear instantly and nothing you type is sent to a server.
How it works
The calculator solves the normal equations (XᵀX)β = Xᵀy for the intercept and slope, after centring x for numerical accuracy. Residuals e = y − ŷ give SSE, R², the residual standard error and the standard errors of the coefficients; t = coefficient ÷ standard error is compared with a t distribution with n − 2 degrees of freedom.
Worked example
Five measurements: x = 10, 20, 30, 40, 50 and y = 25, 41, 62, 79, 101. The means are x̄ = 30 and ȳ = 61.6. Sxy = Σ(x − x̄)(y − ȳ) = 1,900 and Sxx = Σ(x − x̄)² = 1,000, so the slope is m = 1.9 and the intercept b = 61.6 − 1.9 × 30 = 4.6, giving y = 1.9x + 4.6. The residuals are 1.4, −1.6, 0.4, −1.6 and 1.4, so SSE = 9.2, SST = 3,619.2 and R² = 1 − 9.2 ÷ 3,619.2 = 0.9975. The residual standard error is √(9.2 ÷ 3) = 1.751. At x = 60 the line predicts ŷ = 118.6, with a 95% prediction interval of about 110.5 to 126.7. This is an extrapolation, because 60 lies beyond the largest x.
How to read the output
- Slope p-value below 0.05: the upward or downward trend is unlikely to be chance.
- R² close to 1: points hug the line; close to 0: x tells you little about y.
- Residuals: should scatter randomly around zero. A U-shape or a funnel means the straight line or constant-spread assumption fails.
- Standardised residual beyond ±2: a point worth checking for a typing error or an unusual case.
Formula
m = Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)² · b = ȳ − m·x̄ · R² = 1 − SSE ÷ SST · SE = √(SSE ÷ (n − 2))
Worked example
Inputs: x values (independent variable): 10, 20, 30, 40, 50; y values (dependent variable): 25, 41, 62, 79, 101; Predict y at x =: 60; Precision (significant figures): 4.
Results: Regression equation = y = 1.9x + 4.6; Slope (m = a₁) = 1.9; Intercept (b = a₀) = 4.6; Correlation coefficient (r) = 0.99873; Coefficient of determination (R²) = 0.99746; Adjusted R² = 0.99661.
Key terms
- Least squares
- The fitting rule that minimises the sum of squared residuals.
- Slope (m)
- Average change in y for a one-unit increase in x.
- Intercept (b)
- Predicted y when x = 0.
- Residual
- Observed y minus fitted ŷ for a data point.
- Prediction interval
- Range likely to contain a single new observation at a given x.
Frequently asked questions
How do I calculate a linear regression by hand?
Find x̄ and ȳ, then m = Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)² and b = ȳ − m·x̄. For the default data Sxy = 1,900 and Sxx = 1,000, so m = 1.9 and b = 61.6 − 1.9 × 30 = 4.6.
What does R² tell me?
The share of the variance in y explained by the line. R² = 0.9975 means 99.75% of the variation in y is accounted for by x.
What is the difference between r and R²?
r is the correlation coefficient (−1 to 1) and carries the sign of the slope; in simple linear regression R² = r².
How many points do I need?
Two points define a line, but you need at least three to estimate the scatter, and ten or more for trustworthy standard errors.
What is the residual standard error?
√(SSE ÷ (n − 2)), the typical vertical distance between a point and the line, in the units of y.
Why is the prediction interval so much wider than the confidence interval?
The confidence interval covers the average y at that x; the prediction interval must also cover the scatter of a single new point around the line.
Is extrapolation reliable?
Predictions outside the observed x range assume the straight-line trend continues, which often fails. The calculator warns you when x is outside your data.
What if the points follow a curve?
Look at the residual table: a curved pattern means a straight line is the wrong model. Try quadratic, cubic or exponential regression.