Statistics

Linear Regression Calculator

Fit a straight line to paired X and Y data using ordinary least squares. Enter two equal-length lists and the tool returns the slope, the intercept, and the R-squared value that measures how well the line fits.

What this calculator does

The Linear Regression Calculator estimates your result instantly from the values you enter, using standard statistics formulas. Fit a straight line to paired X and Y data using ordinary least squares. Enter two equal-length lists and the tool returns the slope, the intercept, and the R-squared value that measures how well the line fits. Calculations run in your browser, so nothing you type is sent to a server, and the output is an estimate rather than a certified or official figure.

Linear Regression Calculator

Result

—
Slope (m)
—
Intercept (b)
—
R²

About Linear Regression Calculator

Paste a list of X values and an equal-length list of Y values, and this calculator fits the best straight line y = mx + b by ordinary least squares. It builds the slope from nΣxy − ΣxΣy over nΣx² − (Σx)², then derives the intercept, and computes the correlation coefficient r to report R².

The two lists must be the same length and contain at least two points, and the X values must vary (a flat X column has no line to fit).

Formula & Mathematical Calculation

Calculation Method

  1. Compute } d=n × sx2-sx × sx
  2. Compute } m=(n × sxy-sx × sy) ÷ d, b=(sy-m × sx) ÷ n
  3. Compute den=Math.sqrt((n × sx2-sx × sx) × (n × sy2-sy × sy)), r=den===0?0:(n × sxy-sx × sy) ÷ den

Calculation Example

Enter X = 1, 2, 3, 4 and Y = 2, 4, 5, 8:

  • Slope (m) = 1.9
  • Intercept (b) = 0
  • R² = 0.9627

The best-fit line reported is y = 1.9x + 0, with R² = 0.9627.

Key Benefits

  • Fits the least-squares line and returns slope, intercept, and R-squared together in one step
  • Reports R-squared so you can judge how closely the line follows your points
  • Checks that the X and Y lists are equal in length and have at least two points before fitting
  • Flags data with no variation in X, which has no defined slope; free and browser-based

How to Use this Calculator

  1. Enter the X values
    Type your independent-variable values into the X values field, comma-separated, e.g. 1, 2, 3, 4.
  2. Enter the Y values
    Type the matching dependent-variable values into the Y values field, keeping the same count and order.
  3. Calculate
    Press Calculate to fit the line.
  4. Read slope, intercept, and fit
    Read the Slope (m), Intercept (b), and R-squared boxes, and the equation shown below them.

Assumptions & Limitations

What the calculation assumes

  • Every value you enter is treated as an exact, known amount.
  • Any rate or interval you enter is assumed to hold for the whole period unless the form asks for it separately.
  • Results use standard published formulas and account only for the values entered above.
  • Rounding is applied for display; the underlying calculation uses your full precision.
  • Results are returned in the same units you enter, unless the tool states the output unit.

What it does not cover

  • Linear Regression Calculator produces a calculated result for reference and learning, not a certified or official measurement.
  • Real-world outcomes differ when tolerances, rounding rules or local standards apply.
  • Definitions and standards vary by region and change over time; verify the convention that applies to your case.
  • Figures are only as accurate as the inputs you supply — check them before acting on the result.
  • For work where the result carries real consequences, confirm it against an authoritative source.

Frequently Asked Questions

It is the square of the correlation coefficient r computed from your points, and it ranges from 0 to 1 to indicate how much of the variation in Y the fitted line explains.

Yes. The tool pairs the values position by position and will ask you to re-enter the data if the two lists differ in length or hold fewer than two points.

If every X is identical the denominator n(sum x squared) - (sum x) squared is zero, so no slope can be defined and the calculator stops with that message.

It uses ordinary least squares, minimizing the squared vertical distances between the points and the fitted line y = mx + b.

Free to use, no account needed. Calculations run in your browser, so nothing you type is sent to a server. Results are estimates — how we build and check our calculators.