BYTETOOLS

Linear Regression Calculator

Fit y = mx + b to paired data by ordinary least squares. Get slope, intercept, r², residuals and a scatter plot with the best-fit line drawn on canvas.

0.6
Slope (m)
2.2
Intercept (b)
0.7746
r
0.6

Best-fit line: ŷ = 0.6x + 2.2

Predict ŷ for an x value

5.8
Predicted ŷ

This x is outside your data range (1 to 5) — extrapolated predictions are less reliable.

Residuals (y − ŷ)

xyŷResidual
122.8-0.8
243.40.6
3541
444.6-0.6
555.2-0.2

What is the Linear Regression Calculator?

The ByteTools Linear Regression Calculator fits a straight line y = mx + b to paired x/y data using ordinary least squares: the slope is m = Sxy / Sxx and the intercept is b = ȳ − m·x̄.

  • Ordinary least squares fit: slope, intercept and equation
  • r and r² goodness-of-fit statistics
  • Residual table for every data point
  • Canvas scatter plot with best-fit line, axes and gridlines
  • Prediction box for any x value
  • PNG chart download — all 100% in-browser

How to use the Linear Regression Calculator

  1. 1

    Enter your data as one x, y pair per line (comma, space or tab separated).

  2. 2

    Read the fitted equation y = mx + b, plus r and r².

  3. 3

    Inspect the scatter plot and best-fit line on the chart.

  4. 4

    Enter any x value to predict ŷ from the fitted line.

  5. 5

    Download the chart as a PNG or copy the numeric summary.

About the Linear Regression Calculator

The ByteTools Linear Regression Calculator fits a straight line y = mx + b to paired x/y data using ordinary least squares: the slope is m = Sxy / Sxx and the intercept is b = ȳ − m·x̄. You get the fitted equation, the correlation coefficient r, the coefficient of determination r², and a residual for every point.

A scatter plot with the best-fit line is drawn directly on an HTML canvas — axes, ticks and gridlines included — so you can see at a glance how well the line describes your data. A prediction box lets you plug any x into the fitted equation, and the chart can be downloaded as a PNG.

Everything runs 100% locally in your browser: paste pairs from a spreadsheet, and neither your data nor the chart ever leaves your device. Ideal for statistics coursework, lab reports and quick trend checks.

Frequently asked questions

How is the line of best fit calculated?

By ordinary least squares, which minimises the sum of squared vertical distances from the points to the line. The slope is m = Σ(x−x̄)(y−ȳ) / Σ(x−x̄)² and the intercept is b = ȳ − m·x̄. For x = 1…5, y = 2, 4, 5, 4, 5 the fit is y = 0.6x + 2.2.

What does r² tell me about the regression?

r² is the fraction of the variation in y explained by the linear relationship with x. r² = 0.9 means 90% of the variability follows the line; r² near 0 means the line explains almost nothing. It does not prove the relationship is linear — always look at the scatter plot.

What is a residual?

A residual is the vertical gap between an observed point and the fitted line: residual = y − ŷ. Small, randomly scattered residuals suggest a good linear fit, while a curved pattern in the residuals signals that a straight line is the wrong model.

How many data points do I need for linear regression?

Mathematically two points define a line, but a meaningful fit needs more — this tool requires at least 3 pairs and statisticians usually want 10 or more before trusting slope estimates. More points make the slope, intercept and r² far more stable.

Can I use the regression line to predict beyond my data range?

You can, but extrapolation is risky: the linear pattern may not continue outside the observed x range. Predictions inside the data range (interpolation) are much more reliable. The tool flags predictions that fall outside your data's x range.

Related tools