Linear Regression Calculator

Quick answer

The linear regression calculator fits the least-squares line y = mx + b to paired x and y data. It reports the slope, intercept, correlation, R², adjusted R², standard error and a residual table, draws the line through a scatter plot and predicts y for any x with a 95% prediction interval.

Same number of values as x, in the same order

Optional – leave empty to skip the prediction

Regression equation
y = 1.9x + 4.6
Scatter plot with the fitted curve
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
Residual standard error
1.75119
Overall F-test
F(1, 3) = 1,177.1739, p < 0.0001
Predicted y at the chosen x
118.6
95% prediction interval for a new y
110.5239 to 126.6761
95% confidence interval for the mean y
112.7549 to 124.4451
Interpolation or extrapolation?
x = 60 lies outside the data range (10 to 50) – this is an extrapolation, treat it with caution.
Coefficients with standard errors and t-tests
Term Coefficient Std. error t p-value ──────────────────────────────────────────────────────────── Intercept (a₀) 4.6 1.837 2.505 0.0874 x (a₁) 1.9 0.05538 34.31 < 0.0001
Fitted values and residuals
# x y ŷ (fitted) Residual y − ŷ Standardised ───────────────────────────────────────────────────────── 1 10 25 23.6 1.4 0.799 2 20 41 42.6 −1.6 −0.914 3 30 62 61.6 0.4 0.228 4 40 79 80.6 −1.6 −0.914 5 50 101 99.6 1.4 0.799
Sum of squared residuals (SSE)
9.2
Number of points
5

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

  1. x values (independent variable)
  2. y values (dependent variable): Same number of values as x, in the same order
  3. Predict y at x =: Optional, leave empty to skip the prediction
  4. 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.

Sources

  1. Penn State STAT 462: Applied Regression Analysis
  2. NIST/SEMATECH e-Handbook of Statistical Methods
  3. OpenStax: Introductory Statistics 2e

Cite this calculator

Speedy Calculator. (2026). Linear Regression Calculator. Speedy Calculator. https://speedycalculator.com/calculators/statistics/linear-regression/