Linear Regression Calculator: Line of Best Fit, Correlation and R²

Linear Regression Calculator

Calculate the least-squares regression line, Pearson correlation coefficient, coefficient of determination, residual error, and an optional prediction from paired data.

Enter the same number of X and Y values. Separate values with commas, semicolons, spaces, or new lines. Use a period for decimals; commas are separators, not thousands marks. Maximum: 10,000 pairs.


Linear regression formulas

For paired observations (xᵢ,yᵢ), the least-squares line is ŷ = b₀ + b₁x. The slope is b₁ = Σ[(xᵢ−x̄)(yᵢ−ȳ)] / Σ(xᵢ−x̄)², and the intercept is b₀ = ȳ−b₁x̄.

Pearson's correlation is r = Sxy / √(Sxx·Syy), while R² = r² for simple linear regression with an intercept. SSE is the sum of squared residuals. RMSE uses √(SSE/n), and residual standard error uses √[SSE/(n−2)] when at least three pairs are available.

Checked examples

X valuesY valuesResult
1, 2, 32, 4, 6ŷ=2x; r=1; R²=1
0, 1, 21, 3, 5ŷ=1+2x; r=1
1, 2, 33, 2, 1ŷ=4−x; r=−1
1, 2, 31, 2, 2ŷ≈0.6667+0.5x; R²=0.75
1, 2, 3, 4, 52, 4, 5, 4, 5ŷ=2.2+0.6x; r≈0.7746; R²=0.6
−2, −1, 0, 15, 3, 1, −1ŷ=1−2x; r=−1

How to use the calculator

  1. Enter the X observations and their corresponding Y observations in the same order.
  2. Optionally enter an X value for a predicted Y value on the fitted line.
  3. Select Calculate regression.
  4. Review the regression equation, correlation, R², residual measures, and prediction.

Limits and interpretation

  • Use 2 to 10,000 pairs of finite values. X must contain at least two distinct values.
  • Periods are decimal points. Commas, semicolons, spaces, and line breaks separate observations.
  • Results use double-precision arithmetic and display approximately 12 significant digits.
  • Correlation and R² are undefined when all Y values are equal.
  • A strong correlation does not establish causation. Predictions far beyond the observed X range are extrapolations and may be unreliable.
  • This calculator fits one explanatory variable with an intercept; it does not perform multiple or nonlinear regression.

Frequently asked questions

What is the line of best fit?

It is the straight line that minimizes the sum of squared vertical residuals between observed and predicted Y values.

What does R² mean?

R² is the share of variation in Y explained by the fitted straight-line relationship, from 0 to 1 when an intercept is included.

Are Pearson r and the regression slope the same?

No. Pearson r is unitless and limited to −1 through 1. The slope carries Y-units per X-unit and changes when the measurement scale changes.

Can I use unequal list lengths?

No. Every X value must correspond to exactly one Y value.

Related calculators

Use the Standard Deviation Calculator for one-variable spread and variance, or the Average Calculator for mean, median, mode, and range.