Skip to content
MasterMath

Linear Regression Calculator

The least-squares line that best fits your data, with the slope, the intercept, R squared and the prediction for whatever value of X you want.

Regression line

—

Regression line—
Slope—
Intercept—
R squared—
Prediction—
Standard error of the estimate—
#XYPredicted Y

How this was worked out

    The formula

    y = a + b·x, with b = Σ(x − x̄)(y − ȳ) / Σ(x − x̄)²

    What it means

    The regression line is the one that minimises the sum of the squared vertical distances between the points and the line. The slope says how much y changes when x rises by one unit, and the intercept where it crosses the axis. R² measures how much of y's variation x explains, and the standard error of the estimate says, in y's own units, how far off the line is on average.

    How to work it out by hand

    1. Work out the mean of x and the mean of y
    2. The slope is the covariance divided by the variance of x
    3. The intercept is the mean of y minus the slope times the mean of x
    4. To predict, substitute the value of x into y = a + b·x

    What is worth knowing

    Predicting outside the range of your data — extrapolating — is where regression fails, and it fails silently: the line hands back a perfectly formatted number for an x that looks nothing like anything you measured. The intercept suffers the same way: if your x values run from 20 to 50, the value at x = 0 is an extrapolation and often means nothing. Nor does a high R² guarantee the line is the right model: you have to look at the residuals.

    Frequently asked questions

    What does the slope mean?

    How much y changes, on average, when x goes up by one unit. That is almost always the interpretation you want.

    Can I predict outside my data range?

    You can, but do not trust it. The line was fitted to a particular range and beyond it nothing supports it.

    What is a good R squared?

    Entirely field-dependent: 0.3 can be excellent in social science and dismal in a laboratory assay.

    Why least squares and not something else?

    Because it has an exact solution and well-understood statistical properties. Other choices resist outliers better but are far less tractable.

    Does the intercept always mean something?

    No. If your data include no values near x = 0, the intercept is an extrapolation and often means nothing real.