Skip to content
LunaCalc

Statistics

Linear Regression Calculator

Fit a simple linear regression with least squares and report R².

Calculator

About this calculator

This linear regression calculator fits the least-squares line y = ax + b through paired data and reports the fit quality.

Formula notes

slope a = Σ((xᵢ−x̄)(yᵢ−ȳ)) / Σ(xᵢ−x̄)²; intercept b = ȳ − a·x̄; r² measures fit.

Worked examples

  1. Example: x = 1,2,3,4,5 and y = 2,4,5,4,5 give y = 0.6x + 2.2 with r² = 0.6.
  2. For points (1,2), (2,3), (3,5), and (4,6), least squares gives a positive slope near 1.4 and an intercept near 0.5.

How to use it

  1. Enter paired x and y lists of equal length.
  2. Read the fitted equation.
  3. Use r² to judge how well the line explains the data.

Frequently asked questions

What does the slope 0.6 mean here?

Each one-unit increase in x is associated with a 0.6-unit increase in predicted y.

Can I use the equation to predict new x values?

Yes, within the observed range; extrapolating far beyond the data is unreliable.

Limits and interpretation

  • Simple linear regression assumes a linear mean relationship and requires residual diagnostics for variance, independence, and unusual observations.
  • Extrapolating beyond the observed x range can be unreliable, and a high R2 does not prove causation or model correctness.

References