CalculatorVilla

Linear Regression Calculator

Fit a linear trend line (line of best fit) through bivariate paired data (X, Y) using the ordinary least squares (OLS) method. Computes the slope (m), intercept (b), Pearson correlation (r), and coefficient of determination (R²).

Regression Line Equation (y = mx + b): Insufficient Data (requires ≥2 pairs)

Predictor values X separated by commas or spaces

Response values Y matching each corresponding X in sequence

Regression Line Equation (y = mx + b)
Insufficient Data (requires ≥2 pairs)

How to Use This Calculator

  1. Enter independent X values separated by commas.
  2. Enter matching dependent Y values in the same sequential order.
  3. Inspect the line of best fit equation (y = mx + b) and R² goodness-of-fit.

Formula & Calculation Methodology

y = mx + b | m = [nΣxy − ΣxΣy] ÷ [nΣx² − (Σx)²] | b = (Σy − mΣx) ÷ n

Ordinary least squares minimizes the sum of squared vertical residuals (distances from observed points to the regression line). R² represents the square of Pearson’s r.

mSlope coefficient
bVertical axis intercept
R²Explained variance proportion
nNumber of coordinate pairs

Worked Example

Fitting pairs (1,2), (2,4), (3,5), (4,4), (5,5)

xValues: 1, 2, 3, 4, 5
yValues: 2, 4, 5, 4, 5
Result: y = 0.6x + 2.2 (R² = 0.6000, Slope = 0.6000, Intercept = 2.2000)

Perfect correlation (1, 10), (2, 20), (3, 30)

xValues: 1, 2, 3
yValues: 10, 20, 30
Result: y = 10x + 0 (R² = 1.0000, Slope = 10.0000)

Frequently Asked Questions

What does R² (R-squared) indicate?↓

R² ranges between 0.0 and 1.0. An R² of 0.85 means 85% of the variance in the dependent variable Y is explained by the linear relationship with X.

Does linear regression prove causation?↓

No. Correlation does not imply causation. Two variables may be strongly correlated due to a third confounding variable or coincidence.

What occurs if X and Y lists have different lengths?↓

The calculator truncates to the shorter length so that each point has a complete (X, Y) pair.

What is a limitation of simple linear regression?↓

It only detects straight-line relationships. If data follows a curve (such as an exponential or U-shaped parabola), linear regression will underestimate fit.

Related Calculators

Source Citation & Disclaimer

Informational tool only; not licensed tax, legal, or financial advice.