gizmobench
BrowseDaily

Linear Regression Calculator

Paste paired x and y values to fit y = a + bx by ordinary least squares. Read the slope, intercept, Pearson r, R-squared and SSE, then inspect the scatter, residual plot, table and calculation steps. Prediction stays inside the supplied x range; up to 5,000 points are read.

5 pointsLeast squaresPredict at x = 4.5
x          1       2       3       4       5y          2       4       5       4       7y = 1.400 + 1.000xr = 0.8704      R^2 = 0.7576      n = 5residuals  -0.4    +0.6    +0.6    -1.4    +0.6predict    x = 4.5  ->  y = 5.900   (inside the fitted range)
Slope
1.000
Intercept
1.400
r
0.8704
R-squared
0.7576
SSE
3.2

5 points, least squares line y = 1.400 + 1.000x, r 0.8704, R-squared 0.7576, residual standard error 1.0328.

A comma, a space or a tab separates the x from the y, so two columns copied from a spreadsheet paste straight in. Bracketed pairs work too, and so do two labelled rows, the x values over the y values. Up to 5,000 points at a time. Nothing you type leaves this browser.

Calculation steps
  1. Find rounded means of 5 paired points: x base = 3, y base = 4.4. Let dx = x - x base and dy = y - y base. Keep remaining mean offsets separately: cx = sum(dx) / n = 0, cy = sum(dy) / n = -3.552714e-16.
  2. Correct the centred sums: Sxx = sum(dx^2) - sum(dx)^2 / n = 10 - (0^2 / 5) = 10; Sxy = sum(dx * dy) - sum(dx) * sum(dy) / n = 10 - (0 * -1.776357e-15 / 5) = 10.
  3. Slope b = Sxy / Sxx = 10 / 10 = 1.
  4. Keep the line near a supplied point: x0 = 1, y0 = 2; u = x - x0, v = y - y0; a0 = mean(v - b * u) = 0.4. Ordinary intercept a = y0 + a0 - b * x0 = 2 + 0.4 - 1 * 1 = 1.4. The fitted line is y = 1.400 + 1.000x.
  5. Evaluate in translated coordinates to retain small differences: fitted y = y0 + a0 + b * u; residual = v - a0 - b * u, the observed y minus fitted y. SSE = sum(residual^2) = 3.2.
  6. Residual standard error = sqrt(SSE / (n - 2)) = sqrt(3.2 / 3) = 1.032796.

Residual plot

Observed y minus fitted y, against x. The horizontal line is zero; values above it are positive and values below it are negative.

1.40-1.415x

Horizontal range: 1 to 5. Residuals use y units. All 5 residuals are drawn.

Residuals

Each row is one of your points, the value the fitted line gives at that x, and the gap between them. The residuals of a least squares line with an intercept add up to zero, so this column is worth reading for its pattern rather than for its total.

xyFittedResidual
122.4-0.4
243.4+0.6
354.4+0.6
445.4-1.4
576.4+0.6

Three cases, worked

Every line below is computed by the code that answers the calculator above, so an example and the tool cannot disagree.

  • (1,3) (2,5) (3,7)a perfect line
    slope 2.000, intercept 1.000, R-squared 1.0000
  • The five points drawnleast squares
    y = 1.400 + 1.000x
  • Every x the sameno spread in x
    Every x in those rows is 2, so the points sit on a vertical line and the slope has no denominator: the spread in x is zero. Give the x values some spread, or swap x and y if x is the value you want to predict.
What R-squared is. It is the square of Pearson r, and on your points it is the share of the variation in y that the fitted line accounts for. It is not a test of whether a straight line is the right shape for the data. Take x = 1 to 10 with y = x squared: ten points that sit exactly on a curve, and not on a line at all. The least squares fit through them is y = -22.000 + 11.000x with R-squared 0.9498, and their residuals run +12 +4 -2 -6 -8 -8 -6 -2 +4 +12, down and back up, a pattern rather than scatter. R-squared also says nothing about how many points produced it, since two points with different y values give 1, nothing about whether the slope would hold on new data, and nothing about which variable moves which.
Why the sums are centred. The raw-sums formula divides one difference of raw sums by another, and on values far from zero those sums lose the digits the answer was made of. Take four points at x near 100,000,000 whose y rises by exactly one: the raw-sums formula returns a slope of 0.625, while this page subtracts the mean first and returns 1.000. Both are the same algebra. Only one survives the arithmetic.
Accuracy. Ordinary least squares computed from centred sums, which keeps the arithmetic stable when the values sit far from zero. R-squared is the square of Pearson r and says how much of the variation in y the line accounts for, and nothing more: a fit here describes these points, it is not evidence that x causes y, and a prediction is only offered inside the x range you supplied.

Common questions

How do I enter my data?
Put one x and one y on each row, separated by a comma, space or tab. Two columns from a spreadsheet can be pasted directly. Bracketed pairs such as (1,3) (2,5) (3,7), or two labelled rows such as x 1 2 3 over y 3 5 7, also work. Up to 5,000 points are read; a bad row is named rather than dropped. Commas separate columns, so remove thousands commas from numbers.
What do the slope and the intercept mean on this page?
The slope b is the fitted change in y for one unit of x; the intercept a is the line’s value at x = 0. The opening five-point example gives y = 1.400 + 1.000x. These coefficients describe a fitted line; they do not establish a causal relationship or justify a prediction outside the observed x range.
How can I see the linear regression calculation steps?
Open Calculation steps after entering valid points. The working shows x and y means, the corrected centred sums Sxx and Sxy, slope b = Sxy / Sxx, intercept a = y mean - b * x mean, residuals and SSE. It also derives residual standard error when there are more than two points. Copy carries these steps and every fitted/residual row.
What does the residual graph show?
Residual plot places x horizontally and observed y minus fitted y vertically. The horizontal reference is zero: positive residuals are above it and negative residuals below it. This is a separate view from the scatter with short lines to the fit. At most 1,000 points are drawn and any omission is stated; fitting and the copied report still use every row.
What are SSE and residual standard error?
SSE is the sum of squared residuals, also called the sum of squared errors. For the opening five points, SSE is 3.2 and residual standard error is sqrt(3.2 / 3) = 1.0328 when rounded to four decimals. Residual standard error uses n - 2 in the denominator and is undefined for two points. It is in y units; SSE is in squared y units.
What does R-squared tell me, and what does it not?
Report R-squared alongside the number of observations and residual standard error to show the sample size and error scale. R-squared has no units: converting all y values from metres to centimetres leaves it unchanged, even though the slope and residual sizes change. The worked callout's 0.9498 is a descriptive fit statistic, not a p-value. This calculator does not compute significance tests or adjusted R-squared.
Why does it refuse when every x is the same?
The slope divides the centred cross product by the spread in x. Identical x values make that denominator zero, so no finite slope can be fitted. The message names the shared x value. Y may be constant when x varies: then the line is flat, while Pearson r and R-squared are undefined because there is no y variation.
Can it predict a y beyond my x range?
No. Predict y at x evaluates the fitted line only between the smallest and largest supplied x, including both endpoints. An outside target is refused with the range stated. The tool does not extrapolate or produce a future-period forecasting workflow, prediction intervals or confidence bounds.
Is Pearson r the same as R-squared?
Pearson r retains direction and ranges from -1 to 1. R-squared is r multiplied by itself, so its sign is lost. On the opening five points, r is 0.8704 and R-squared is 0.7576. A rising line with r = 1 and a falling line with r = -1 both have R-squared 1, provided y varies.
Why are the regression sums centred?
Centred arithmetic cannot recover digits already lost when an input is converted to a browser number. Calculation steps show the corrections for rounded means; the calculation also uses compensated summation. The raw-sums value 0.625 belongs only to the comparison callout. The reported fit and copied results use the corrected centred calculation.
What happens if I only give it two points?
Two points with different x values determine a line, so both residuals are zero. If y also differs, r is 1 or -1 and R-squared is 1; if y is the same, r and R-squared are undefined. Two points leave no residual degrees of freedom, so residual standard error is undefined rather than reported as zero.
Which regression models and statistics are supported?
This page fits one predictor and one response with an intercept by ordinary least squares. It does not accept weights, multiple predictors, matrix input or only summary statistics. It does not calculate slope t tests, p-values, ANOVA, intervals, power or sample-size planning. The displayed residual standard error is distinct from an inferential test.
What is remembered in my browser?
Only an input you actually change is saved locally when browser storage is available. Opening a preset or restoring remembered inputs does not write them again. The fit, plots and copied report are computed in this tab, and the paired values are not uploaded. Calculations also work when storage is blocked.

Ordinary least squares computed from centred sums, which keeps the arithmetic stable when the values sit far from zero. R-squared is the square of Pearson r and says how much of the variation in y the line accounts for, and nothing more: a fit here describes these points, it is not evidence that x causes y, and a prediction is only offered inside the x range you supplied.