Skip to content
ENExplore Calculators

Linear Regression Calculator

Fit a least-squares line y = mx + b to paired data and report slope, intercept and R².

About Linear Regression Calculator

Simple linear regression finds the best-fit line y = mx + b that minimises the sum of squared residuals. The slope m is the change in y per unit change in x, and R² indicates what fraction of y's variance is explained by x.

Formulas

Slope

m = Σ(xᵢ−x̄)(yᵢ−ȳ) / Σ(xᵢ−x̄)²

xᵢ,yᵢ
Data pairs
x̄,ȳ
Means

Intercept

b = ȳ − m×x̄

ȳ
Mean of Y
x̄
Mean of X
m
Slope

Worked example

With the default values below, Linear Regression Calculator returns Slope (m) of 1.990000. Change any input above and every figure here is recalculated in your browser.

Inputs used

X values (comma separated)
1, 2, 3, 4, 5
Y values (comma separated)
2.1, 3.9, 6.2, 7.8, 10.1

Results

Slope (m)
1.990000
Intercept (b)
0.050000
R²
0.997305
Correlation (r)
0.998652

Step by step

  1. 1Values used
  2. 2Slope
  3. 3Intercept
  4. 4Slope (m)= 1.990000
  5. 5Intercept (b)= 0.050000
  6. 6R²= 0.997305
  7. 7Correlation (r)= 0.998652

Assumptions and limits

  • The result is derived only from the 2 inputs listed above. Anything not among them is not part of the calculation.
  • In particular, this calculator does not take inflation, tax, fees or charges or compounding frequency into account.
  • Figures are rounded for display to 6 decimal places, so totals built from several rounded parts can differ slightly from the unrounded arithmetic.

How these calculators are built and tested is described on the Methodology page. If a figure looks wrong, please report it.

Frequently Asked Questions

What does R² = 1 mean?

It means all data points lie exactly on the line — x perfectly predicts y with no residual error.

Can the slope be negative?

Yes. A negative slope means y decreases as x increases, indicating a negative linear relationship.

Linear Regression Calculator | Calcrivo