Linear Regression Calculator

Least squares line, correlation, and fit quality from paired x and y data.

Math and PercentUpdated 2026-10-182 min read
Linear Regression Calculator
3 to 500 numbers, separated by commas or spaces, one pair per position.
Regression line
...
Slope...
Intercept...
Correlation r...
r squared...
Residual SD...
Pairs...

What it does

Draw the straight line that sits closest to a cloud of points, and you have the workhorse of applied statistics: the least squares regression line. It turns a relationship into a slope you can interpret and a fit you can judge.

The tool above takes two equal length lists, x and y, pairs them by position, and returns the fitted line, the slope and intercept, the correlation, r squared, and the residual standard deviation.

The defaults are Anscombe's celebrated first dataset: eleven pairs that fit y = 3 + 0.5x with a correlation of 0.816. Its three sister datasets, all with identical statistics, are the classic reminder to always plot your data before trusting a fit.

The formulas follow the NIST engineering statistics handbook least squares pages and its Anscombe case study: slopes and intercepts come from the sums of squared deviations, and the residual spread is the root of SSE over n minus 2.

How to use

  1. Paste the x values as one comma separated list.
  2. Paste the y values in the same order, so position i pairs.
  3. Keep both lists the same length, between 3 and 500 values.
  4. Press Calculate for the fitted line and fit statistics.
  5. Plot the points anyway; the numbers cannot see an outlier.

Formula

slope = Sxy / Sxx. intercept = y mean - slope x mean. r = Sxy / sqrt(Sxx x Syy). Residual SD = sqrt(SSE / (n - 2)).
Sxx
Sum of squared deviations of x from its mean.
Sxy
Sum of paired deviations, x from its mean times y from its mean.
Syy
Sum of squared deviations of y; total variation.
SSE
Syy minus slope times Sxy; the variation the line misses.

The line minimizes the sum of squared vertical misses, so vertical outliers pull hardest. Correlation r always sits between minus 1 and 1 regardless of units, while the slope carries units of y per x. Descriptive only: a regression cannot prove that x causes y.

Worked example

Example: Anscombe's first dataset

Eleven pairs, x from 4 to 14, y from 4.26 to 10.84.

  1. x mean 9, y mean 7.5.
  2. Sxx: 110; Sxy: 55.0.
  3. Slope: 55 / 110 = 0.5.
  4. Intercept: 7.5 - 0.5 x 9 = 3.
  5. Line: y = 3 + 0.5x; r = 0.816, r squared 0.667.
  6. SSE 13.76 over 9 df gives a residual SD of 1.237.

Reference table

What the fit statistics say
StatisticValue hereReading
Slope0.5Each +1 in x adds 0.5 to predicted y
Intercept3Predicted y when x is 0
r0.816Strong positive linear association
r squared0.667About 67 percent of y variation rides with x
Residual SD1.237Typical miss between point and line

Limits

  • Fits a straight line only.
  • Sensitive to outliers, especially vertical ones.
  • Correlation is not causation.
  • Extrapolation beyond the data range is unsafe.

Common mistakes

  • Trusting the fit without plotting the points.
  • Reading r squared as proof of a cause.
  • Mixing up which list is x and which is y.
  • Extrapolating far past the observed range.
  • Ignoring that Anscombe's four datasets share every statistic.

Try it yourself

Quick checks. Answers sit tucked under each question.

x = 1,2,3,4,5 and y = 2,4,6,8,10?

y = 0 + 2x, r = 1, residual SD 0.

Why not y = 3 + 0.5x exactly on Anscombe?

Rounding in the data; the fit lands within a thousandth.

What does a slope of 0.5 with r of 0.2 mean?

Weak association; the slope is real to the line but y scatters widely around it.

Questions

What is least squares?

The line that minimizes the sum of squared vertical distances from the points; it has the closed form slope and intercept this page uses.

What is a good r squared?

It depends on the field: physical lab work often runs above 0.95, social data can be useful near 0.3. It measures fit, not importance.

Can the slope be negative?

Yes; a falling line means y decreases as x rises, and the equation prints a minus sign.

How many points do I need?

Three is the mathematical floor here; real conclusions want enough points to see the shape and any outliers.

What is the residual SD?

The typical vertical miss of the data from the line, in the units of y.

Does r equal correlation?

Yes, Pearson's r for the paired samples, and its square is the share of y variance explained by the linear fit.

Sources

How this page was checked. The formula above was matched against the cited sources, and the worked example was run through the tool on this page before publishing. If you spot an error, contact us so we can fix it and note the correction.