Mathematics & StatisticsLast updated: 2026-10-04

Least Squares Regression

Paste data points to fit a least-squares regression line y = ax + b with slope a and intercept b. See the sums (Σx, Σy, Σx², Σxy), Sxx and Sxy, the correlation r, R², a scatter plot with the fitted line, residuals and predictions from x — with the working shown.

Client-Side · Zero TelemetryPrivate & Secure

Comma, tab or space separated. e.g. 1, 3 or 1 3

Try an example

Enter data to fit a regression line.

ShareXfB!L

How to use

  1. 1

    Paste the data

    Enter one x, y pair per line, separated by commas, tabs or spaces.

  2. 2

    Check the line and metrics

    See the regression line y = ax + b, slope a, intercept b, correlation r, R² and the scatter plot.

  3. 3

    Predict and check

    Enter an x to get the predicted ŷ, and use the residual table to look for outliers.

Features

  • Fit a least-squares line y = ax + b from pasted data
  • See the sums (Σx, Σy, Σx², Σxy) and the working for Sxx, Sxy and Syy
  • Get the correlation r and coefficient of determination R² with a strength guide
  • View a scatter plot with the fitted line and a table of residuals (y − ŷ)
  • Predict ŷ from an x value, with an extrapolation warning outside the data range
  • Runs entirely in your browser; no sign-up and nothing uploaded

Use cases

Calibration curves in lab reports

Find the slope, intercept and R² of a calibration line and inspect residuals for outliers.

Spot the trend in data

Use the scatter plot and fitted line to see the relationship between two variables.

Check homework and reports

Verify a hand-computed slope, intercept and correlation against the working shown.

Details

Least squares finds the line that minimises the sum of squared residuals. Writing the regression line as y = ax + b, the slope a and intercept b follow from the sum of squared deviations Sxx and the sum of products Sxy: a = Sxy / Sxx and b = ȳ − a·x̄ (where x̄ and ȳ are the means).

Sxx = Σx² − (Σx)²/n and Sxy = Σxy − (Σx·Σy)/n let you compute everything from sums instead of subtracting the mean point by point. This tool shows the sums (Σx, Σy, Σx², Σxy), Sxx, Sxy, Syy and the coefficients with the working.

The correlation coefficient r = Sxy / √(Sxx·Syy) ranges from −1 to 1 and measures the strength of the linear relationship. The coefficient of determination R² = r² ranges from 0 to 1 and indicates how much of the variation in y the line explains.

Many statistics textbooks write the line as y = a + bx (a: intercept, b: slope), which swaps the letters used here. State clearly which letter is the slope and which is the intercept in your report. By convention x is the explanatory variable and y is the response variable.

FAQ

What is the least squares method?

It fits the line that minimises the sum of squared vertical differences (residuals) between the data points and the line. Squaring prevents positive and negative differences from cancelling out.

Why are the slope and intercept letters different from my textbook?

This tool follows the site convention y = ax + b (a: slope, b: intercept). Some statistics textbooks write y = a + bx (a: intercept, b: slope), which swaps the letters. State clearly which letter is the slope in your answer.

What is the difference between r and R²?

r measures the strength and direction of the linear relationship (−1 to 1), while R² = r² measures how much of the variation in y the line explains (0 to 1). If r = 0.7, then R² = 0.49, so the line explains about 49% of the variation.

How should I handle outliers?

Least squares is strongly affected by outliers. Check the residual table for points that deviate strongly, and consider whether a measurement error justifies excluding them. Do not remove inconvenient points without a reason.

Can I use it for curved relationships?

No, this tool fits straight lines only. For curved data a straight line gives a low r and R² and can mislead. Some curved relationships can be linearised with a log or other transformation.

How reliable are the predictions?

Predictions inside the range of the data (interpolation) are relatively stable, but predictions outside it (extrapolation) are less reliable; the tool warns you. Correlation also does not prove causation.

All processing happens in your browser. Your files are never uploaded.

Verified: Cross-checked against independent calculations (perfect line y=2x+1 with r=1, five scattered points giving a=0.6, b=2.2 and r=0.7746, negative correlation y=−2x+12 with r=−1, a five-point calibration giving a=0.99, b=0.08 and R²=0.9948, prediction at x=10 giving 21) plus error handling are covered by browser tests

Did you know?

Squaring the correlation coefficient r gives the coefficient of determination R²: if r = 0.7 then R² = 0.49, so the line explains about 49% of the variation in y. A strong correlation and accurate predictions are not the same thing.

Optional usage measurement settings

Only with your consent, a random browser ID and tool/learning events are sent to measure return visits. This is pseudonymous measurement. Inputs, answers, keys, files and search terms are excluded. Consent expires after 90 days. Declining does not limit any feature.

Measurement is off.

Retention and privacy