Index / Linear Regression

Linear Regression Calculator

Ordinary least squares with everything reported — slope, intercept, r, R², standard errors and a residual for every observation.

Least Squares Fit

idle
n pairs
Sxy
Sxx
Separate x and y with a comma, tab or space. One pair per line. Lines that do not contain two numbers are skipped.
Regression equation
Slope (b)
Intercept (a)
Correlation r
Std error of est.
SE of slope
t for slope
Predicted y
xyŷ (fitted)Residual

How to use it

Paste your paired data one observation per line, with x and y separated by a comma, tab or space. Two columns copied straight from a spreadsheet paste correctly. Lines that do not contain two parseable numbers are skipped and counted.

Set a prediction value to get a fitted y for any x. The residual table underneath shows every observation, its fitted value and the gap between them — which is where you look when the R² is good but the model is still wrong.

What least squares does

Ordinary least squares finds the single straight line that minimises the sum of squared vertical distances between the observed points and the line. Squaring means large misses count disproportionately, and it makes the solution unique and computable in closed form — no iteration required.

The fitted line
ŷ = a + bx
Slope
b = Sxy ÷ Sxx = Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)²
Intercept
a = ȳ − b·x̄

The intercept formula guarantees the line passes through the point (x̄, ȳ) — the centroid of the data. That is always true of a least squares fit and is a useful sanity check.

Reading the output

Slope

The slope is the practical result: the average change in y associated with a one-unit increase in x. It carries the units of y per unit of x, and it is the number to quote when describing what the model found. A slope of 2.01 on data measured in kilograms per year means roughly two kilograms gained per year.

Intercept

The fitted value of y when x = 0. Frequently meaningless, and that is fine. If x is a person's height in centimetres, the intercept describes a person of zero height. It exists to position the line correctly, not to be interpreted. Only read it substantively when x = 0 falls inside your observed range and is a physically sensible value.

Correlation coefficient, r

A number between −1 and +1 measuring the strength and direction of the linear association. Its sign always matches the slope's. Conventional bands:

|r|StrengthVariance explained
0.90 – 1.00Very strong0.81 – 1.0081% or more
0.70 – 0.89Strong0.49 – 0.8049% to 80%
0.50 – 0.69Moderate0.25 – 0.4825% to 48%
0.30 – 0.49Weak0.09 – 0.249% to 24%
0.00 – 0.29Negligible0.00 – 0.08Under 9%

These bands are conventions, not thresholds. In physics an r of 0.95 might indicate a problem with the apparatus; in social science 0.4 can be a substantial finding. Judge against what is normal in your field.

The coefficient of determination — simply r squared for a single-predictor model. It is the proportion of variance in y accounted for by x. An R² of 0.94 means 94% of the variation in y is explained by the linear relationship and 6% is not.

A high R² does not mean the model is right. Anscombe's quartet is four datasets with identical means, variances, correlations and regression lines — but one is a clean linear relationship, one is a perfect curve, one is a straight line dragged by a single outlier, and one is a vertical stack plus one distant point. Only a residual plot distinguishes them. Always look at the residual column: if residuals show a pattern rather than scattering randomly around zero, a straight line is the wrong model no matter what R² says.

Standard error of the estimate

The typical size of a residual — roughly how far a prediction is likely to be off, in the units of y. It is the standard deviation of the residuals, adjusted for the two parameters the model spent.

Standard error of the estimate
se = √( Σ(y − ŷ)² ÷ (n − 2) )

Standard error of the slope and the t statistic

The slope is itself an estimate from a sample, so it has its own uncertainty. Dividing the slope by its standard error gives a t statistic testing the null hypothesis that the true slope is zero — that x and y are unrelated. As a rough guide, |t| above about 2 with a reasonable sample size indicates a slope distinguishable from zero at the 5% level. For an exact p-value you need the t-distribution with n − 2 degrees of freedom.

A worked example

The default data set is ten points that rise almost linearly. Working the key quantities:

  • x̄ = 5.5, ȳ = 11.14
  • Sxx = Σ(x − x̄)² = 82.5
  • Sxy = Σ(x − x̄)(y − ȳ) = 164.7
  • Slope = 164.7 ÷ 82.5 = 1.9964
  • Intercept = 11.14 − 1.9964 × 5.5 = 0.1600
  • Equation: ŷ = 0.1600 + 1.9964x, with r = 0.9995 and R² = 0.9991

The slope of roughly 2 says y doubles x. The intercept near zero says the line passes almost through the origin. Predicting at x = 12 gives ŷ ≈ 24.12 — but note that 12 lies outside the observed range of 1 to 10, so the calculator flags it as an extrapolation.

Assumptions worth checking

  • Linearity. The relationship must actually be a straight line. Curved data fitted with a line produces residuals with a clear U or arch shape.
  • Independence. Observations must not be related to one another. Time series data usually violates this — consecutive measurements are correlated — and needs methods that account for it.
  • Constant variance. Residual spread should be similar across the range of x. Residuals that fan out as x grows indicate heteroscedasticity, which does not bias the slope but does invalidate the standard errors.
  • Roughly normal residuals. Needed for the t statistic and any p-value, though the slope estimate itself is unaffected.
  • No dominant outliers. A single point far from the rest, especially at an extreme x, can pull the entire line. Check whether removing it changes the slope materially; if it does, say so in your write-up.

Frequently asked questions

Does a strong correlation prove causation?
No, and this is the single most consequential error in applied statistics. A regression line describes association, nothing more. Three alternatives always remain: y might cause x, a third variable might drive both, or the association might be coincidence. Establishing causation requires an experimental design or careful causal inference, not a smaller p-value.
Which variable should be x?
x is the predictor, y the outcome — the variable you are trying to explain or forecast. The choice matters: regressing y on x gives a different line from regressing x on y. Put the variable you control, or that comes first in time, on the x axis.
Can I predict outside my data range?
You can compute it, and the calculator will warn you when you do. Whether to trust it is another matter. A relationship established between x = 1 and x = 10 carries no guarantee at x = 100 — real relationships routinely saturate, reverse or break down. Extrapolation is the most common way a technically correct regression produces a badly wrong answer.
How many data points do I need?
Three is the mathematical minimum for a meaningful residual. Twenty to thirty is a common practical minimum before the slope estimate is stable enough to rely on. With fewer than about ten pairs, a single unusual observation can dominate the fit entirely.
What if my data is curved?
Fitting a straight line to curved data gives a misleadingly poor R² and residuals with an obvious pattern. Options: transform a variable (logging x or y often straightens exponential or power relationships), fit a polynomial term, or use a non-linear model. Check the residual column first — the pattern usually tells you which transform to try.
Why is my intercept negative when all my data is positive?
Because the intercept is where the fitted line crosses x = 0, which may be far outside your data. It is a positioning parameter, not a prediction. If a negative intercept is physically impossible in your context, that is a sign x = 0 is outside the valid range of the model — not that the model is broken.
Is my data stored?
No. Everything runs in your browser. Nothing is transmitted to a server, logged or saved.

Next steps

The standard error of the estimate on this page is a standard deviation of residuals — the standard deviation calculator shows how that quantity is constructed. To judge whether an individual residual is unusually large, standardise it with the z-score calculator. To put an interval around a mean rather than a slope, use the confidence interval calculator.