Statistics & data

Linear regression

Fit a straight line to paired measurements.

Your measurements

Number formats & units

Use decimal dots in datasets. Single values also accept decimal commas and scientific notation such as 1.2e-3 or 1.2 × 10⁻³.

Linear Regression Calculator with Graph inputs
One x–y pair per line. Spaces, tabs or commas separate columns. Omit headers.

Calculated locally. No account or uploads.

Result & working

Example

The calculator is loading. You can read the worked example below.

Copy & export

Formula & example

The relationship

m=SxySxxm=\frac{S_{xy}}{S_{xx}}c=yˉ−mxˉc=\bar y-m\bar x
r=SxySxxSyyr=\frac{S_{xy}}{\sqrt{S_{xx}S_{yy}}}R2=1−SSESyyR^2=1-\frac{\mathrm{SSE}}{S_{yy}}
se=SSEn−2s_e=\sqrt{\frac{\mathrm{SSE}}{n-2}}
SE(m)=seSxx\mathrm{SE}(m)=\frac{s_e}{\sqrt{S_{xx}}}SE(c)=se1n+xˉ2Sxx\mathrm{SE}(c)=s_e\sqrt{\frac1n+\frac{\bar x^2}{S_{xx}}}
What the variables mean
SymbolMeaning
Sxx,  SyyS_{xx},\;S_{yy}Sums of squared deviations of x and y from their means.
SxyS_{xy}Sum of products (xᵢ − x̄)(yᵢ − ȳ).
SSE\mathrm{SSE}Sum of squared residuals Σ(yᵢ − ŷᵢ)².
m,  cm,\;cSlope and intercept. Slope units are y-units divided by x-units.
r,  R2r,\;R^{2}Signed linear correlation and coefficient of determination.

Worked example

Data entry
Two columns: x then y
Two-column data
1 2 2 4 3 5 4 4 5 5

y = 0.6x + 2.2

Follow the example steps
  1. n = 5; x̄ = 3; ȳ = 4
  2. Sxx = Σ(xᵢ − x̄)² = 10
  3. Syy = Σ(yᵢ − ȳ)² = 6
  4. Sxy = Σ(xᵢ − x̄)(yᵢ − ȳ) = 6
  5. m = Sxy / Sxx = 6 / 10 = 0.6
  6. c = ȳ − mx̄ = 4 − (0.6) × 3 = 2.2
  7. SSE = Σ(yᵢ − ŷᵢ)² = 2.4
  8. r = Sxy / √(Sxx Syy) = 0.7745967; R² = 1 − SSE / Syy = 1 − 2.4 / 6 = 0.6
  9. Residual SD sₑ = √(SSE / (n − 2)) = √(2.4 / 3) = 0.8944272
  10. SE(m) = sₑ / √Sxx = 0.8944272 / √10 = 0.2828427
  11. SE(c) = sₑ √(1/n + x̄²/Sxx) = 0.8944272 × √(1/5 + (3)²/10) = 0.9380832

Common mistakes

Keep each x paired with the y measured with it.

Incorrect approach

Original pairs (1, 5), (2, 3): sort y alone to get (1, 3), (2, 5).

Correct approach

Keep (1, 5), (2, 3): the fitted gradient is −2.

More checks before you submit
  • A fitted intercept is not automatically evidence of a calibration error.
  • A high R² can hide curvature or outliers; inspect the graph.
  • Keep each x paired with its original y.
  • Do not confuse a regression standard error with the max/min-gradient method.
Method notes

Ordinary least squares chooses the line that minimizes squared vertical residuals. It treats x as known and fits an intercept; it does not force the line through the origin or account for x uncertainty.

Coefficient standard errors need at least three points and assume independent errors with constant variance. Confidence intervals require further assumptions and an appropriate t multiplier. Constant y gives a horizontal fitted line, but r and R² are undefined because y has no variation.