Linear Regression Calculator

Calculate simple linear regression equation y = mx + b from data points. Find slope, intercept, R² goodness of fit, and predicted values. Identify trends in your data.

📊 Statistics📐 y = mx + b (m = r × sy/sx)🔢 Math
Enter x values (comma-separated)
Enter y values (comma-separated)
Predict y at x = (optional)
Please enter valid values.

Formula & Reference

VariableSymbolFormulaUnits
Linear Regression Calculatory = mx + b (m = r × sy/sx)same as data units

Step-by-Step Examples

Example 1
Study Hours vs Test Score

x (hours): 1,2,3,4,5. y (score): 50,60,65,70,80.

  • mx = 3, my = 65
  • m = Σ(xi-mx)(yi-my)/Σ(xi-mx)² = 20/10 = 7
  • b = 65 - 7×3 = 44
  • Equation: y = 7x + 44
  • Each extra hour predicts 7 more points
✓ y = 7x + 44 (R² ≈ 0.94)
Example 2
House Size vs Price

x (sq ft): 1000,1200,1500,1800,2000. y ($k): 150,180,210,250,280.

  • Slope m ≈ 0.12 ($k per sq ft = $120/sq ft)
  • b ≈ 3.6 ($3,600 base)
  • Predict 1600 sq ft: y = 0.12×1600+3.6 = 195.6 ($196k)
  • R² ≈ 0.99: very strong linear fit
✓ y = 0.12x + 3.6, predict 1600 sqft → $196k
Example 3
Prediction from Regression

Same equation y=7x+44. Predict score for 8 hours studying.

  • y = 7(8) + 44 = 56 + 44 = 100
  • Predicted score = 100
  • But 8 hours is outside training data range (1-5 hrs)
  • Extrapolation beyond data range is risky!
✓ Predicted y(8) = 100 (be cautious: extrapolation)

Real-World Applications

Common Mistakes to Avoid

⚠️
Extrapolating beyond your data range

Predicting y for x values far outside your training data is unreliable. The relationship may be nonlinear outside the observed range.

⚠️
Ignoring residual plots

R² alone doesn't confirm a linear relationship is appropriate. Always check a residual plot for patterns — systematic curves indicate nonlinearity.

⚠️
Confusing regression with causation

Regression fits a line; it doesn't prove x causes y. Many strong regressions are spurious (ice cream sales predicting drownings — both caused by summer heat).

Frequently Asked Questions

What is simple linear regression?
Models the relationship between two variables as y = mx + b. m is the slope (change in y per unit change in x), b is the y-intercept. Minimizes the sum of squared residuals.
What is R²?
Proportion of variance in y explained by x. R²=0.80 means 80% of the variation in y is explained by x. The remaining 20% is unexplained (residual) variation.
What is the difference between regression and correlation?
Correlation (r): symmetric, just measures relationship strength. Regression: directional (predicts y from x), gives the equation, can make predictions. R² = r² for simple regression.
What are the assumptions of linear regression?
1) Linear relationship, 2) Independence of observations, 3) Homoscedasticity (constant variance of residuals), 4) Normality of residuals. Check with residual plots.
When should I use multiple regression?
When you have more than one predictor variable. y = b0 + b1x1 + b2x2 + ... Accounts for multiple factors simultaneously. Requires matrix algebra or statistical software.

Related Math Calculators

Formula Explorer connections

Interpretation: This formula summarizes data, models uncertainty or supports inference about a population or random process. Assumption: The sampling design and distribution assumptions must match the data. Independence, sample size, outliers and measurement quality can materially affect interpretation.

Margin of Error Calculator →Markov Chain Calculator →M/M/1 Queue Calculator →Math Formula Explorer →