Linear Regression Calculator
Calculate the least-squares regression line, Pearson correlation coefficient, coefficient of determination, residual error, and an optional prediction from paired data.
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 values | Y values | Result |
|---|---|---|
| 1, 2, 3 | 2, 4, 6 | ŷ=2x; r=1; R²=1 |
| 0, 1, 2 | 1, 3, 5 | ŷ=1+2x; r=1 |
| 1, 2, 3 | 3, 2, 1 | ŷ=4−x; r=−1 |
| 1, 2, 3 | 1, 2, 2 | ŷ≈0.6667+0.5x; R²=0.75 |
| 1, 2, 3, 4, 5 | 2, 4, 5, 4, 5 | ŷ=2.2+0.6x; r≈0.7746; R²=0.6 |
| −2, −1, 0, 1 | 5, 3, 1, −1 | ŷ=1−2x; r=−1 |
How to use the calculator
- Enter the X observations and their corresponding Y observations in the same order.
- Optionally enter an X value for a predicted Y value on the fitted line.
- Select Calculate regression.
- 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.